|
5 | 5 | using System.IO; |
6 | 6 | using System.Linq; |
7 | 7 | using System.Text.Json; |
| 8 | +using Org.BouncyCastle.Asn1.Pkcs; |
8 | 9 |
|
9 | 10 | namespace QuestAppVersionSwitcher.Mods |
10 | 11 | { |
@@ -71,33 +72,68 @@ public static void InstallMod(byte[] modBytes, string fileName) |
71 | 72 | InstallMod(f.Path, fileName); |
72 | 73 | } |
73 | 74 |
|
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 |
75 | 79 | { |
| 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; |
76 | 97 | int operationId = operations; |
77 | 98 | 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 }); |
79 | 100 |
|
80 | | - if(!SupportsFormat(Path.GetExtension(fileName))) |
| 101 | + if(!SupportsFormat(Path.GetExtension(installQueue[0].filename))) |
81 | 102 | { |
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; |
87 | 111 | } |
88 | 112 | 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); |
96 | 120 | 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 | + } |
100 | 124 | 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(); |
101 | 137 | } |
102 | 138 |
|
103 | 139 | public static void UninstallMod(string id) |
|
0 commit comments