diff options
author | 0neGal <mail@0negal.com> | 2022-11-23 00:49:58 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-11-23 00:49:58 +0100 |
commit | a12c73e95f7de4167d4e20f77d5e942f1e12d179 (patch) | |
tree | f00e9b4b70617506c911840d258dbdfc7b286851 /src/utils.js | |
parent | acce3855ab1f99d5e1245696df0123240f7b9034 (diff) | |
download | Viper-a12c73e95f7de4167d4e20f77d5e942f1e12d179.tar.gz Viper-a12c73e95f7de4167d4e20f77d5e942f1e12d179.zip |
actually fix duplicate mods
If a mod has multiple mod folders inside it, however all with the same
name, they'll be merged together, this now fixes that, by adding
"(dupe)" to the end of it, along with displaying an error, however it
will install successfully.
This also happens to add some duplicate toast protection, however this
should be reworked, but I am not bothered to deal with it right now, and
I instead will be putting this on future me.
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/src/utils.js b/src/utils.js index 5f74f3d..890fc8c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -672,14 +672,30 @@ const mods = { }; }, + installing: [], + dupe_msg_sent: false, + // Installs mods from a file path // // 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, manifestfile, malformed = false) => { + install: (mod, opts ) => { let modname = mod.replace(/^.*(\\|\/|\:)/, ""); + opts = { + forked: false, + destname: false, + malformed: false, + manifest_file: false, + ...opts + } + + if (! opts.forked) { + mods.installing = []; + mods.dupe_msg_sent = false; + } + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")); console.log("error: " + lang("general.notinstalled")); @@ -710,7 +726,7 @@ const mods = { ipcMain.emit("installed-mod", "", { name: modname, - malformed: malformed, + malformed: opts.malformed, }); ipcMain.emit("gui-getmods"); @@ -728,7 +744,6 @@ const mods = { try { JSON.parse(fs.readFileSync(path.join(mod, "mod.json"))); }catch(err) { - console.log("json failed") ipcMain.emit("failed-mod"); return notamod(); } @@ -738,10 +753,12 @@ const mods = { } let copydest = path.join(modpath, modname); - if (typeof destname == "string") {copydest = path.join(modpath, destname)} + if (typeof opts.destname == "string") { + copydest = path.join(modpath, opts.destname) + } copy(mod, copydest); - copy(manifestfile, path.join(copydest, "manifest.json")); + copy(opts.manifest_file, path.join(copydest, "manifest.json")); return installed(); } else { @@ -752,8 +769,34 @@ const mods = { if (fs.existsSync(path.join(mod, mod_files[i], "mod.json")) && fs.statSync(path.join(mod, mod_files[i], "mod.json")).isFile()) { - mods.install(path.join(mod, mod_files[i])); - if (mods.install(path.join(mod, mod_files[i]))) {return true}; + let mod_name = mod_files[i]; + let use_mod_name = false; + + while (mods.installing.includes(mod_name)) { + if (! mods.dupe_msg_sent) { + mods.dupe_msg_sent = true; + ipcMain.emit("duped-mod", "", mod_name); + } + + use_mod_name = true; + mod_name = mod_name + " (dupe)"; + } + + mods.installing.push(mod_name); + + let install = false; + if (use_mod_name) { + install = mods.install(path.join(mod, mod_files[i]), { + forked: true, + destname: mod_name, + }) + } else { + install = mods.install(path.join(mod, mod_files[i]), { + forked: true + }) + } + + if (install) {return true}; } } } @@ -781,7 +824,13 @@ const mods = { 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(manifest).name, manifest, true)) { + if (mods.install(path.join(cache, "mods"), { + forked: true, + malformed: true, + manifest_file: manifest, + destname: require(manifest).name + })) { + return true; } } else { @@ -789,7 +838,14 @@ const mods = { let mod = path.join(cache, "mods", files[i]); if (fs.statSync(mod).isDirectory()) { setTimeout(() => { - if (mods.install(mod, false, manifest)) {return true}; + if (mods.install(mod, { + forked: true, + destname: false, + manifest_file: manifest + })) { + + return true + } }, 1000) } } @@ -803,7 +859,7 @@ const mods = { return notamod(); } - if (mods.install(cache)) { + if (mods.install(cache, { forked: true })) { installed(); } else {return notamod()} }, 1000) |