aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-03 01:53:05 +0100
committer0neGal <mail@0negal.com>2022-01-03 01:53:05 +0100
commit34c93e9e7714322aa67fc427e3b9f03fea827229 (patch)
treeb86ee5958505cde4696d9a4c6bb2aa9287bcd3ad /src/utils.js
parent42e6f3b358bf4d569a0849f3d5c99bb58bf432ba (diff)
downloadViper-34c93e9e7714322aa67fc427e3b9f03fea827229.tar.gz
Viper-34c93e9e7714322aa67fc427e3b9f03fea827229.zip
we're now able to install archived mods
Lovely, only issue is for some reason both on Windows and Linux file dialogs can't select both directories and files, so either it's a folder or it's an archive, not both. So I guess we need to make some way to select it...
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/utils.js b/src/utils.js
index a34f91f..e54a2c1 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -223,7 +223,20 @@ const mods = {
return false;
},
install: (mod) => {
+ let notamod = () => {
+ winLog(lang("gui.mods.notamod"))
+ console.log("error: " + lang("cli.mods.notamod"))
+ cli.exit(1);
+ }
+
+ let installed = () => {
+ cli.exit();
+ winLog(lang("gui.mods.installedmod"))
+ ipcMain.emit("guigetmods");
+ }
+
if (fs.statSync(mod).isDirectory()) {
+ winLog(lang("gui.mods.installing"))
if (fs.existsSync(path.join(mod, "mod.json")) &&
fs.statSync(path.join(mod, "mod.json")).isFile()) {
@@ -232,8 +245,8 @@ const mods = {
cover: true,
utimes: true,
});
- cli.exit();
- ipcMain.emit("guigetmods");
+
+ installed();
return true;
} else {
files = fs.readdirSync(mod);
@@ -243,22 +256,33 @@ const mods = {
if (fs.existsSync(path.join(mod, files[i], "mod.json")) &&
fs.statSync(path.join(mod, files[i], "mod.json")).isFile()) {
- if (mods.install(path.join(mod, files[i]))) {return};
+ if (mods.install(path.join(mod, files[i]))) {return true};
}
}
}
- winAlert(lang("cli.mods.notamod"))
- console.log("error: " + lang("cli.mods.notamod"))
- cli.exit(1);
+
+ notamod();
return false;
}
- }
+ } else {
+ winLog(lang("gui.mods.extracting"))
+ let cache = path.join(app.getPath("userData"), "Archives");
+ if (fs.existsSync(cache)) {
+ fs.rmSync(cache, {recursive: true});
+ fs.mkdirSync(cache);
+ } else {
+ fs.mkdirSync(cache);
+ }
- fs.createReadStream(mod).pipe(unzip.Extract({path: modpath}))
- .on("finish", () => {
- cli.exit();
- ipcMain.emit("guigetmods");
- });
+ try {
+ fs.createReadStream(mod).pipe(unzip.Extract({path: cache}))
+ .on("finish", () => {
+ if (mods.install(cache)) {
+ installed();
+ } else {notamod();return false}
+ });
+ }catch(err) {notamod();return false}
+ }
},
remove: (mod) => {
if (mod == "allmods") {