Skip to content

Commit 88202f0

Browse files
ComputerEliteComputerElite
authored andcommitted
Add running operation id to request, add delete running operation to remove errors from the list
1 parent fa41afe commit 88202f0

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

QuestAppVersionSwitcher/Mods/QAVSModManager.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class QAVSOperation
3535
{
3636
public QAVSOperationType type { get; set; } = QAVSOperationType.ModInstall;
3737
public string name { get; set; } = "";
38+
public int operationId { get; set; } = 0;
3839
}
3940

4041
public class QAVSModManager
@@ -100,7 +101,7 @@ public static void InstallFirstModFromQueue()
100101
installingMod = true;
101102
int operationId = operations;
102103
operations++;
103-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModInstall, name = "Installing " + installQueue[0].filename });
104+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModInstall, name = "Installing " + installQueue[0].filename, operationId = operationId});
104105

105106
if(!SupportsFormat(Path.GetExtension(installQueue[0].filename)))
106107
{
@@ -123,7 +124,7 @@ public static void InstallFirstModFromQueue()
123124
runningOperations.Remove(operationId);
124125
operationId = operations;
125126
operations++;
126-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error installing mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher" });
127+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error installing mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher", operationId = operationId });
127128
}
128129
modManager.ForceSave();
129130
installQueue.RemoveAt(0);
@@ -135,7 +136,7 @@ public static void InstallMod(string path, string fileName)
135136
{
136137
int operationId = operations;
137138
operations++;
138-
runningOperations.Add(operationId, new QAVSOperation {type = QAVSOperationType.Other, name = "Mod install queued: " + fileName});
139+
runningOperations.Add(operationId, new QAVSOperation {type = QAVSOperationType.Other, name = "Mod install queued: " + fileName, operationId = operationId});
139140
installQueue.Add(new QueuedMod(path, fileName, operationId));
140141
InstallFirstModFromQueue();
141142
}
@@ -144,7 +145,7 @@ public static void UninstallMod(string id)
144145
{
145146
int operationId = operations;
146147
operations++;
147-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModUninstall, name = "Unnstalling " + id });
148+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModUninstall, name = "Unnstalling " + id, operationId = operationId });
148149

149150
foreach (IMod m in modManager.AllMods)
150151
{
@@ -164,7 +165,7 @@ public static void DeleteMod(string id)
164165
{
165166
int operationId = operations;
166167
operations++;
167-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModDelete, name = "Deleting " + id });
168+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModDelete, name = "Deleting " + id, operationId = operationId });
168169
foreach (IMod m in modManager.AllMods)
169170
{
170171
if (m.Id == id)
@@ -186,7 +187,7 @@ public static void InstallModFromUrl(string url)
186187
DownloadManager m = new DownloadManager();
187188
int operationId = operations;
188189
operations++;
189-
runningOperations.Add(operationId, new QAVSOperation {type = QAVSOperationType.ModDownload, name = "Downloading mod: " + Path.GetFileName(url.Split('?')[0])});
190+
runningOperations.Add(operationId, new QAVSOperation {type = QAVSOperationType.ModDownload, name = "Downloading mod: " + Path.GetFileName(url.Split('?')[0]), operationId = operationId});
190191
m.DownloadFinishedEvent += (manager) =>
191192
{
192193
//CoreService.browser.EvaluateJavascript("ShowToast('Downloaded, now installing', '#FFFFFF', '#222222')", null);
@@ -210,7 +211,7 @@ public static void EnableMod(string id)
210211
{
211212
int operationId = operations;
212213
operations++;
213-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModInstall, name = "Installing " + id });
214+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModInstall, name = "Installing " + id, operationId = operationId });
214215

215216
foreach (IMod m in modManager.AllMods)
216217
{
@@ -226,7 +227,7 @@ public static void EnableMod(string id)
226227
runningOperations.Remove(operationId);
227228
operationId = operations;
228229
operations++;
229-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error enabling mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher" });
230+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error enabling mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher", operationId = operationId });
230231
}
231232
break;
232233
}

QuestAppVersionSwitcher/Mods/QPMod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private async Task PrepareDependency(Dependency dependency, List<string> install
247247
{
248248
int operationId = QAVSModManager.operations;
249249
QAVSModManager.operations++;
250-
QAVSModManager.runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.DependencyDownload, name = "Downloading Dependency " + dependency.Id });
250+
QAVSModManager.runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.DependencyDownload, name = "Downloading Dependency " + dependency.Id, operationId = operationId });
251251
Logger.Log($"Preparing dependency of {dependency.Id} version {dependency.VersionRange}");
252252
int existingIndex = installedInBranch.FindIndex(downloadedDep => downloadedDep == dependency.Id);
253253
if (existingIndex != -1)

QuestAppVersionSwitcher/WebServer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ public void Start()
205205
request.SendString(QAVSModManager.GetMods(), "application/json");
206206
return true;
207207
}));
208+
server.AddRoute("DELETE", "/mods/operation", new Func<ServerRequest, bool>(request =>
209+
{
210+
int operation = int.Parse(request.bodyString);
211+
if (!QAVSModManager.runningOperations.ContainsKey(operation))
212+
{
213+
request.SendString("A operation with the key " + operation + " does not exist", "text/plain", 400);
214+
return true;
215+
}
216+
217+
QAVSModManager.runningOperations.Remove(operation);
218+
request.SendString("Removed operation " + operation + " from running Operations", "application/json");
219+
return true;
220+
}));
208221
server.AddRoute("GET", "/patching/getpatchoptions", new Func<ServerRequest, bool>(request =>
209222
{
210223
request.SendString(JsonSerializer.Serialize(CoreService.coreVars.patchingPermissions), "application/json");

0 commit comments

Comments
 (0)