aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-11-19 23:53:04 +0100
committer0neGal <mail@0negal.com>2022-11-19 23:52:33 +0100
commitacce3855ab1f99d5e1245696df0123240f7b9034 (patch)
treee395be469ca7e21f6ed2b9c82f372d75cf056a24
parent4fcbcb0091f2242cf9d5c1fbd86432da04f3658a (diff)
downloadViper-acce3855ab1f99d5e1245696df0123240f7b9034.tar.gz
Viper-acce3855ab1f99d5e1245696df0123240f7b9034.zip
ignore mod if mod.json isn't formatted correctly
If a mod has an incorrectly formatted mod.json it is ignored when trying to build/get the list of installed mods.
-rw-r--r--src/utils.js32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/utils.js b/src/utils.js
index b69c957..5f74f3d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -543,7 +543,12 @@ const mods = {
if (fs.statSync(path.join(modpath, file)).isDirectory()) {
let modjson = path.join(modpath, file, "mod.json");
if (fs.existsSync(modjson)) {
- let mod = JSON.parse(repair(fs.readFileSync(modjson, "utf8")));
+ let mod = {};
+ try {
+ mod = JSON.parse(repair(fs.readFileSync(modjson, "utf8")));
+ }catch(err) {
+ return;
+ }
let obj = {
Version: "unknown",
@@ -707,6 +712,7 @@ const mods = {
name: modname,
malformed: malformed,
});
+
ipcMain.emit("gui-getmods");
return true;
}
@@ -719,25 +725,35 @@ const mods = {
if (fs.existsSync(path.join(mod, "mod.json")) &&
fs.statSync(path.join(mod, "mod.json")).isFile()) {
+ try {
+ JSON.parse(fs.readFileSync(path.join(mod, "mod.json")));
+ }catch(err) {
+ console.log("json failed")
+ ipcMain.emit("failed-mod");
+ return notamod();
+ }
+
if (fs.existsSync(path.join(modpath, modname))) {
fs.rmSync(path.join(modpath, modname), {recursive: true});
}
+
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 {
- files = fs.readdirSync(mod);
+ mod_files = fs.readdirSync(mod);
- for (let i = 0; i < files.length; i++) {
- if (fs.statSync(path.join(mod, files[i])).isDirectory()) {
- if (fs.existsSync(path.join(mod, files[i], "mod.json")) &&
- fs.statSync(path.join(mod, files[i], "mod.json")).isFile()) {
+ for (let i = 0; i < mod_files.length; i++) {
+ if (fs.statSync(path.join(mod, mod_files[i])).isDirectory()) {
+ 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, files[i]));
- if (mods.install(path.join(mod, files[i]))) {return true};
+ mods.install(path.join(mod, mod_files[i]));
+ if (mods.install(path.join(mod, mod_files[i]))) {return true};
}
}
}