aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-02-07 21:46:04 +0100
committer0neGal <mail@0negal.com>2022-02-07 21:56:56 +0100
commit39d8f10c282c409d5fa2d62b0d39c33d183e90c8 (patch)
treea7c5c67b32068c91a4d0fd5c2c4595c7d712307c
parent7c2fe789d759bcbf69bdc5ca4f2ff0fede4d4883 (diff)
downloadViper-39d8f10c282c409d5fa2d62b0d39c33d183e90c8.tar.gz
Viper-39d8f10c282c409d5fa2d62b0d39c33d183e90c8.zip
added support for more obscure mod structure
If a developer for some reason decides to put their mod inside mods/ instead of putting it inside a folder in mods/, it used to fail the install, now that's fixed. However since there's no folder to directly copy the name from we take it from the manifest.json provided by Thunderstore. It of course also has the proper status in the browser UI (update/reinstall etc)
-rw-r--r--src/app/browser.js19
-rw-r--r--src/utils.js33
2 files changed, 44 insertions, 8 deletions
diff --git a/src/app/browser.js b/src/app/browser.js
index 7b67822..c266b41 100644
--- a/src/app/browser.js
+++ b/src/app/browser.js
@@ -77,10 +77,15 @@ var Browser = {
setTimeout(() => {
for (let i = 0; i < modsobj.all.length; i++) {
let modname = normalize(modsobj.all[i].Name);
+ let modfolder = normalize(modsobj.all[i].FolderName);
if (mod.includes(modname)) {
if (document.getElementById(modname)) {
Browser.setbutton(modname, string);
}
+ } else if (mod.includes(modfolder)) {
+ if (document.getElementById(modfolder)) {
+ Browser.setbutton(modfolder, string);
+ }
}
}
}, 1501)
@@ -137,6 +142,20 @@ function BrowserEl(properties) {
installstr = lang("gui.browser.update");
}
}
+ } else {
+ for (let i = 0; i < modsobj.all.length; i++) {
+ let title = normalize(properties.title);
+ let folder = normalize(modsobj.all[i].FolderName);
+ if (title.includes(folder)) {
+ installstr = lang("gui.browser.reinstall");
+
+ if (folder == title
+ && "v" + modsobj.all[i].Version != properties.version) {
+
+ installstr = lang("gui.browser.update");
+ }
+ }
+ }
}
browserEntries.innerHTML += `
diff --git a/src/utils.js b/src/utils.js
index 048e0e6..125a8d7 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -412,7 +412,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) => {
+ install: (mod, destname) => {
let modname = mod.replace(/^.*(\\|\/|\:)/, "");
if (getNSVersion() == "unknown") {
@@ -435,6 +435,14 @@ const mods = {
winLog(lang("gui.mods.installedmod"))
+ if (modname == "mods") {
+ let manifest = path.join(app.getPath("userData"), "Archives/manifest.json")
+
+ if (fs.existsSync(manifest)) {
+ modname = require(manifest).name;
+ }
+ }
+
ipcMain.emit("installedmod", "", modname);
ipcMain.emit("guigetmods");
return true;
@@ -451,7 +459,9 @@ const mods = {
if (fs.existsSync(path.join(modpath, modname))) {
fs.rmSync(path.join(modpath, modname), {recursive: true});
}
- copy(mod, path.join(modpath, modname))
+ let copydest = path.join(modpath, modname);
+ if (typeof destname == "string") {copydest = path.join(modpath, destname)}
+ copy(mod, copydest)
return installed();
} else {
@@ -488,14 +498,21 @@ const mods = {
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)
+ if (fs.existsSync(path.join(cache, "mods/mod.json"))) {
+ if (mods.install(path.join(cache, "mods"), require(path.join(cache, "manifest.json")).name)) {
+ return true;
+ }
+ } else {
+ 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();
}