Skip to content

Commit 549f593

Browse files
ComputerEliteComputerElite
authored andcommitted
Add isDone variable instead of removing operations from running operations
1 parent 88202f0 commit 549f593

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ var otherPermissions = []
222222
function UpdateModsAndLibs() {
223223
fetch(`/mods/mods`).then(res => {
224224
res.json().then(res => {
225+
res.operations = res.operations.filter(x => !x.isDone)
225226
operationsOngoing = res.operations.length > 0
226227
var mods = ``
227228
if(!operationsOngoing) {

QuestAppVersionSwitcher/Mods/QAVSModManager.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class QAVSOperation
3636
public QAVSOperationType type { get; set; } = QAVSOperationType.ModInstall;
3737
public string name { get; set; } = "";
3838
public int operationId { get; set; } = 0;
39+
public bool isDone { get; set; } = false;
3940
}
4041

4142
public class QAVSModManager
@@ -97,7 +98,7 @@ public QueuedMod(string path, string filename, int operationId)
9798
public static void InstallFirstModFromQueue()
9899
{
99100
if (installingMod || installQueue.Count <= 0) return;
100-
runningOperations.Remove(installQueue[0].queuedOperationId);
101+
runningOperations[installQueue[0].queuedOperationId].isDone = true;
101102
installingMod = true;
102103
int operationId = operations;
103104
operations++;
@@ -108,7 +109,7 @@ public static void InstallFirstModFromQueue()
108109
File.Move(installQueue[0].path, Path.GetDirectoryName(installQueue[0].path) + Path.DirectorySeparatorChar + installQueue[0].filename);
109110
installQueue[0].path = Path.GetDirectoryName(installQueue[0].path) + Path.DirectorySeparatorChar + installQueue[0].filename;
110111
CoreVars.cosmetics.InstallCosmetic(CoreService.coreVars.currentApp, Path.GetExtension(installQueue[0].filename), installQueue[0].path, true);
111-
runningOperations.Remove(operationId);
112+
runningOperations[operationId].isDone = true;
112113
installQueue.RemoveAt(0);
113114
installingMod = false;
114115
InstallFirstModFromQueue();
@@ -118,10 +119,10 @@ public static void InstallFirstModFromQueue()
118119
{
119120
IMod mod = modManager.TryParseMod(installQueue[0].path).Result;
120121
mod.Install().Wait();
121-
runningOperations.Remove(operationId);
122+
runningOperations[operationId].isDone = true;
122123
} catch (Exception e)
123124
{
124-
runningOperations.Remove(operationId);
125+
runningOperations[operationId].isDone = true;
125126
operationId = operations;
126127
operations++;
127128
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error installing mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher", operationId = operationId });
@@ -158,7 +159,7 @@ public static void UninstallMod(string id)
158159
}
159160

160161
// {"success": true, "msg": "Success/Error: blah blah"}
161-
runningOperations.Remove(operationId);
162+
runningOperations[operationId].isDone = true;
162163
}
163164

164165
public static void DeleteMod(string id)
@@ -175,7 +176,7 @@ public static void DeleteMod(string id)
175176
break;
176177
}
177178
}
178-
runningOperations.Remove(operationId);
179+
runningOperations[operationId].isDone = true;
179180
}
180181

181182
public static void InstallModFromUrl(string url)
@@ -193,15 +194,15 @@ public static void InstallModFromUrl(string url)
193194
//CoreService.browser.EvaluateJavascript("ShowToast('Downloaded, now installing', '#FFFFFF', '#222222')", null);
194195
Thread t = new Thread(() =>
195196
{
196-
runningOperations.Remove(operationId);
197+
runningOperations[operationId].isDone = true;
197198
InstallMod(modPath, Path.GetFileName(modPath));
198199
FileManager.DeleteFileIfExisting(modPath);
199200
});
200201
t.Start();
201202
};
202203
m.DownloadCanceled += manager =>
203204
{
204-
runningOperations.Remove(operationId);
205+
runningOperations[operationId].isDone = true;
205206
};
206207
m.StartDownload(url, modPath);
207208
QAVSWebserver.managers.Add(m);
@@ -221,10 +222,10 @@ public static void EnableMod(string id)
221222
{
222223
m.Install().Wait();
223224
modManager.ForceSave();
224-
runningOperations.Remove(operationId);
225+
runningOperations[operationId].isDone = true;
225226
} catch(Exception e)
226227
{
227-
runningOperations.Remove(operationId);
228+
runningOperations[operationId].isDone = true;
228229
operationId = operations;
229230
operations++;
230231
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error enabling mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher", operationId = operationId });
@@ -243,6 +244,12 @@ public static string GetMods()
243244
operations = runningOperations.Values.ToList()
244245
});
245246
}
247+
248+
249+
public static string GetOperations()
250+
{
251+
return JsonSerializer.Serialize(runningOperations);
252+
}
246253

247254
public static byte[] GetModCover(string id)
248255
{

QuestAppVersionSwitcher/Mods/QPMod.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private async Task PrepareDependency(Dependency dependency, List<string> install
258258
dependMessage += $"{installedInBranch[i]} depends on ";
259259
}
260260
dependMessage += dependency.Id;
261-
QAVSModManager.runningOperations.Remove(operationId);
261+
QAVSModManager.runningOperations[operationId].isDone = true;
262262
throw new InstallationException($"Recursive dependency detected: {dependMessage}");
263263
}
264264

@@ -274,7 +274,7 @@ private async Task PrepareDependency(Dependency dependency, List<string> install
274274
Logger.Log($"Installing dependency {dependency.Id} . . .");
275275
await existing.Install(installedInBranch);
276276
}
277-
QAVSModManager.runningOperations.Remove(operationId);
277+
QAVSModManager.runningOperations[operationId].isDone = true;
278278
return;
279279
}
280280

@@ -284,13 +284,13 @@ private async Task PrepareDependency(Dependency dependency, List<string> install
284284
}
285285
else
286286
{
287-
QAVSModManager.runningOperations.Remove(operationId);
287+
QAVSModManager.runningOperations[operationId].isDone = true;
288288
throw new InstallationException($"Dependency with ID {dependency.Id} is already installed but with an incorrect version ({existing.Version} does not intersect {dependency.VersionRange}). Upgrading was not possible as there was no download link provided");
289289
}
290290
}
291291
else if (dependency.DownloadUrlString == null)
292292
{
293-
QAVSModManager.runningOperations.Remove(operationId);
293+
QAVSModManager.runningOperations[operationId].isDone = true;
294294
throw new InstallationException($"Dependency {dependency.Id} is not installed, and the mod depending on it does not specify a download path if missing");
295295
}
296296

@@ -304,7 +304,7 @@ private async Task PrepareDependency(Dependency dependency, List<string> install
304304
catch (WebException ex)
305305
{
306306
// Print a nicer error message
307-
QAVSModManager.runningOperations.Remove(operationId);
307+
QAVSModManager.runningOperations[operationId].isDone = true;
308308
throw new InstallationException($"Failed to download dependency from URL {dependency.DownloadIfMissing}: {ex.Message}", ex);
309309
}
310310

@@ -318,17 +318,17 @@ private async Task PrepareDependency(Dependency dependency, List<string> install
318318
if (dependency.Id != installedDependency.Id)
319319
{
320320
await _provider.DeleteMod(installedDependency);
321-
QAVSModManager.runningOperations.Remove(operationId);
321+
QAVSModManager.runningOperations[operationId].isDone = true;
322322
throw new InstallationException($"Downloaded dependency had ID {installedDependency.Id}, whereas the dependency stated ID {dependency.Id}");
323323
}
324324

325325
if (!dependency.VersionRange.IsSatisfied(installedDependency.Version))
326326
{
327327
await _provider.DeleteMod(installedDependency);
328-
QAVSModManager.runningOperations.Remove(operationId);
328+
QAVSModManager.runningOperations[operationId].isDone = true;
329329
throw new InstallationException($"Downloaded dependency {installedDependency.Id} v{installedDependency.Version} was not within the version range stated in the dependency info ({dependency.VersionRange})");
330330
}
331-
QAVSModManager.runningOperations.Remove(operationId);
331+
QAVSModManager.runningOperations[operationId].isDone = true;
332332
}
333333
}
334334
}

QuestAppVersionSwitcher/WebServer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ public void Start()
205205
request.SendString(QAVSModManager.GetMods(), "application/json");
206206
return true;
207207
}));
208+
server.AddRoute("GET", "/mods/operations", new Func<ServerRequest, bool>(request =>
209+
{
210+
request.SendString(QAVSModManager.GetOperations(), "application/json");
211+
return true;
212+
}));
208213
server.AddRoute("DELETE", "/mods/operation", new Func<ServerRequest, bool>(request =>
209214
{
210215
int operation = int.Parse(request.bodyString);

0 commit comments

Comments
 (0)