diff options
author | 0neGal <mail@0negal.com> | 2022-02-07 23:02:49 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-02-07 23:02:49 +0100 |
commit | dbe50019e760d78e2f0749fd32ed1abbac739936 (patch) | |
tree | 3e0f6a706cab55e637b5eec962c698d78c525100 /src/utils.js | |
parent | a6aa28fa405b0ce1692e2b9ff7a42910ee948e77 (diff) | |
download | Viper-dbe50019e760d78e2f0749fd32ed1abbac739936.tar.gz Viper-dbe50019e760d78e2f0749fd32ed1abbac739936.zip |
all mods should now have proper install status
We now directly check the manifest file info as well therefore in all
cases even if the folder name for the mod is completely obscure, we
should now finally still get an installed status, both on removal and
install.
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/utils.js b/src/utils.js index 125a8d7..5016ef6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -352,6 +352,11 @@ const mods = { if (cli.hasArgs()) {console.log("error: " + lang("cli.mods.improperjson"), file)} mods.push({Name: file, FolderName: file, Version: "unknown", Disabled: false}) } + + let manifest = path.join(modpath, file, "manifest.json"); + if (fs.existsSync(manifest)) { + mods[mods.length - 1].ManifestName = require(manifest).name; + } } } }) @@ -372,6 +377,11 @@ const mods = { disabled.push({Name: file, FolderName: file, Version: "unknown", Disabled: true}) } } + + let manifest = path.join(modpath, file, "manifest.json"); + if (fs.existsSync(manifest)) { + mods[mods.length - 1].ManifestName = require(manifest).name; + } } }) @@ -412,7 +422,7 @@ const mods = { // Either a zip or folder is supported, we'll also try to search // inside the zip or folder to see if buried in another folder or // not, as sometimes that's the case. - install: (mod, destname) => { + install: (mod, destname, manifestfile) => { let modname = mod.replace(/^.*(\\|\/|\:)/, ""); if (getNSVersion() == "unknown") { @@ -462,6 +472,7 @@ const mods = { let copydest = path.join(modpath, modname); if (typeof destname == "string") {copydest = path.join(modpath, destname)} copy(mod, copydest) + copy(manifestfile, path.join(copydest, "manifest.json")) return installed(); } else { @@ -495,11 +506,12 @@ const mods = { fs.createReadStream(mod).pipe(unzip.Extract({path: cache})) .on("finish", () => { setTimeout(() => { - if (fs.existsSync(path.join(cache, "manifest.json"))) { + let manifest = path.join(cache, "manifest.json"); + if (fs.existsSync(manifest)) { files = fs.readdirSync(path.join(cache, "mods")); if (fs.existsSync(path.join(cache, "mods/mod.json"))) { - if (mods.install(path.join(cache, "mods"), require(path.join(cache, "manifest.json")).name)) { + if (mods.install(path.join(cache, "mods"), require(manifest).name, manifest)) { return true; } } else { @@ -507,7 +519,7 @@ const mods = { let mod = path.join(cache, "mods", files[i]); if (fs.statSync(mod).isDirectory()) { setTimeout(() => { - if (mods.install(mod)) {return true}; + if (mods.install(mod, false, manifest)) {return true}; }, 1000) } } @@ -602,11 +614,19 @@ const mods = { } if (fs.statSync(modPath).isDirectory()) { + let manifestname = null; + if (fs.existsSync(path.join(modPath, "manifest.json"))) { + manifestname = require(path.join(modPath, "manifest.json")).name; + } + fs.rmSync(modPath, {recursive: true}); console.log(lang("cli.mods.removed")); cli.exit(); ipcMain.emit("guigetmods"); - ipcMain.emit("removedmod", "", mod.replace(/^.*(\\|\/|\:)/, "")); + ipcMain.emit("removedmod", "", { + name: mod.replace(/^.*(\\|\/|\:)/, ""), + manifestname: manifestname + }); } else { cli.exit(1); } |