aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
authorGitExample <git@example.com>2022-02-05 17:14:46 +0100
committerGitExample <git@example.com>2022-02-05 17:14:46 +0100
commit651c0b32d37dd03c581dc5c9cac8ec293816a636 (patch)
tree0905a44b87cc523c54cc5a1ca8b674bbdb2f2c24 /src/utils.js
parent633433e14f0e6d489090aac81cbb27d05284055c (diff)
downloadViper-651c0b32d37dd03c581dc5c9cac8ec293816a636.tar.gz
Viper-651c0b32d37dd03c581dc5c9cac8ec293816a636.zip
button now updates when mod is removed
I also fixed the archive not being extracted properly for some reason, the setTimeout() seems to solve it, no clue if it needs to be adjusted in the future or replaced with something that works 100% of the time, I'm not even quite sure why it happens in the first place.
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/utils.js b/src/utils.js
index 1456467..39e86be 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -413,6 +413,8 @@ const mods = {
// inside the zip or folder to see if buried in another folder or
// not, as sometimes that's the case.
install: (mod) => {
+ let modname = mod.replace(/^.*(\\|\/|\:)/, "");
+
if (getNSVersion() == "unknown") {
winLog(lang("general.notinstalled"))
console.log("error: " + lang("general.notinstalled"))
@@ -432,6 +434,8 @@ const mods = {
cli.exit();
winLog(lang("gui.mods.installedmod"))
+
+ ipcMain.emit("installedmod", "", modname);
ipcMain.emit("guigetmods");
return true;
}
@@ -444,9 +448,7 @@ const mods = {
if (fs.existsSync(path.join(mod, "mod.json")) &&
fs.statSync(path.join(mod, "mod.json")).isFile()) {
- let modname = mod.replace(/^.*(\\|\/|\:)/, "");
copy(mod, path.join(modpath, modname))
- ipcMain.emit("installedmod", "", modname);
return installed();
} else {
@@ -479,23 +481,25 @@ const mods = {
try {
fs.createReadStream(mod).pipe(unzip.Extract({path: cache}))
.on("finish", () => {
- if (fs.existsSync(path.join(cache, "manifest.json"))) {
- files = fs.readdirSync(path.join(cache, "mods"));
-
- for (let i = 0; i < files.length; i++) {
- let mod = path.join(cache, "mods", files[i]);
- if (fs.statSync(mod).isDirectory()) {
- setTimeout(() => {
- if (mods.install(mod)) {return true};
- }, 1000)
+ setTimeout(() => {
+ if (fs.existsSync(path.join(cache, "manifest.json"))) {
+ files = fs.readdirSync(path.join(cache, "mods"));
+
+ for (let i = 0; i < files.length; i++) {
+ let mod = path.join(cache, "mods", files[i]);
+ if (fs.statSync(mod).isDirectory()) {
+ setTimeout(() => {
+ if (mods.install(mod)) {return true};
+ }, 1000)
+ }
}
+ return notamod();
}
- return notamod();
- }
- if (mods.install(cache)) {
- installed();
- } else {return notamod()}
+ if (mods.install(cache)) {
+ installed();
+ } else {return notamod()}
+ }, 1000)
});
}catch(err) {return notamod()}
}
@@ -582,6 +586,7 @@ const mods = {
console.log(lang("cli.mods.removed"));
cli.exit();
ipcMain.emit("guigetmods");
+ ipcMain.emit("removedmod", "", mod.replace(/^.*(\\|\/|\:)/, ""));
} else {
cli.exit(1);
}