Skip to content

Commit 1babdaa

Browse files
ComputerEliteComputerElite
authored andcommitted
Allow multiple mods to be uploaded at the same time
1 parent b4740e0 commit 1babdaa

File tree

2 files changed

+63
-24
lines changed

2 files changed

+63
-24
lines changed

QuestAppVersionSwitcher/Assets/html/script.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,18 @@ function UpdateModsAndLibs() {
246246
function UploadMod() {
247247
var input = document.createElement('input');
248248
input.type = 'file';
249+
input.multiple = true;
249250
input.click();
250251
input.onchange = () => {
251252
if(input.files.length > 0) {
252-
fetch(`/mods/install?filename=${input.files[0].name}`, {
253-
method: "POST",
254-
body: input.files[0]
255-
}).then(res => {
256-
UpdateShownCosmetics()
257-
})
253+
for(const file of input.files) {
254+
fetch(`/mods/install?filename=${file.name}`, {
255+
method: "POST",
256+
body: file
257+
}).then(res => {
258+
UpdateShownCosmetics()
259+
})
260+
}
258261
}
259262
}
260263
}

QuestAppVersionSwitcher/Mods/QAVSModManager.cs

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Text.Json;
8+
using Org.BouncyCastle.Asn1.Pkcs;
89

910
namespace QuestAppVersionSwitcher.Mods
1011
{
@@ -71,33 +72,68 @@ public static void InstallMod(byte[] modBytes, string fileName)
7172
InstallMod(f.Path, fileName);
7273
}
7374

74-
public static void InstallMod(string path, string fileName)
75+
public static bool installingMod = false;
76+
public static List<QueuedMod> installQueue = new List<QueuedMod>();
77+
78+
public class QueuedMod
7579
{
80+
public string path;
81+
public string filename;
82+
public int queuedOperationId;
83+
84+
public QueuedMod(string path, string filename, int operationId)
85+
{
86+
this.path = path;
87+
this.filename = filename;
88+
queuedOperationId = operationId;
89+
}
90+
}
91+
92+
public static void InstallFirstModFromQueue()
93+
{
94+
if (installingMod || installQueue.Count <= 0) return;
95+
runningOperations.Remove(installQueue[0].queuedOperationId);
96+
installingMod = true;
7697
int operationId = operations;
7798
operations++;
78-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModInstall, name = "Installing " + fileName });
99+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.ModInstall, name = "Installing " + installQueue[0].filename });
79100

80-
if(!SupportsFormat(Path.GetExtension(fileName)))
101+
if(!SupportsFormat(Path.GetExtension(installQueue[0].filename)))
81102
{
82-
File.Move(path, Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + fileName);
83-
path = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + fileName;
84-
CoreVars.cosmetics.InstallCosmetic(CoreService.coreVars.currentApp, Path.GetExtension(fileName), path, true);
85-
runningOperations.Remove(operationId);
86-
return;
103+
File.Move(installQueue[0].path, Path.GetDirectoryName(installQueue[0].path) + Path.DirectorySeparatorChar + installQueue[0].filename);
104+
installQueue[0].path = Path.GetDirectoryName(installQueue[0].path) + Path.DirectorySeparatorChar + installQueue[0].filename;
105+
CoreVars.cosmetics.InstallCosmetic(CoreService.coreVars.currentApp, Path.GetExtension(installQueue[0].filename), installQueue[0].path, true);
106+
runningOperations.Remove(operationId);
107+
installQueue.RemoveAt(0);
108+
installingMod = false;
109+
InstallFirstModFromQueue();
110+
return;
87111
}
88112
try
89-
{
90-
IMod mod = modManager.TryParseMod(path).Result;
91-
mod.Install().Wait();
92-
runningOperations.Remove(operationId);
93-
} catch (Exception e)
94-
{
95-
runningOperations.Remove(operationId);
113+
{
114+
IMod mod = modManager.TryParseMod(installQueue[0].path).Result;
115+
mod.Install().Wait();
116+
runningOperations.Remove(operationId);
117+
} catch (Exception e)
118+
{
119+
runningOperations.Remove(operationId);
96120
operationId = operations;
97-
operations++;
98-
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error installing mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher" });
99-
}
121+
operations++;
122+
runningOperations.Add(operationId, new QAVSOperation { type = QAVSOperationType.Error, name = "Error installing mod: " + e.Message + "\n\nTo remove this message restart QuestAppVersionSwitcher" });
123+
}
100124
modManager.ForceSave();
125+
installQueue.RemoveAt(0);
126+
installingMod = false;
127+
InstallFirstModFromQueue();
128+
}
129+
130+
public static void InstallMod(string path, string fileName)
131+
{
132+
int operationId = operations;
133+
operations++;
134+
runningOperations.Add(operationId, new QAVSOperation {type = QAVSOperationType.Other, name = "Mod install queued: " + fileName});
135+
installQueue.Add(new QueuedMod(path, fileName, operationId));
136+
InstallFirstModFromQueue();
101137
}
102138

103139
public static void UninstallMod(string id)

0 commit comments

Comments
 (0)