aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/index.js2
-rw-r--r--src/lang/en.json4
-rw-r--r--src/utils.js48
3 files changed, 41 insertions, 13 deletions
diff --git a/src/index.js b/src/index.js
index 45400a5..a723622 100644
--- a/src/index.js
+++ b/src/index.js
@@ -62,7 +62,7 @@ function start() {
ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)})
ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)})
ipcMain.on("installmod", () => {
- dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
+ dialog.showOpenDialog({properties: ["openFile"]}).then(res => {
utils.mods.install(res.filePaths[0]);
}).catch(err => {console.error(err)})
})
diff --git a/src/lang/en.json b/src/lang/en.json
index 7c68542..401e98f 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -38,6 +38,10 @@
"gui.mods.removeall": "Remove All",
"gui.mods.nothingselected": "You've not selected a mod.",
"gui.mods.removeall.confirm": "Removing all mods will usually require you to reinstall Northstar, are you sure?",
+ "gui.mods.notamod": "Not a mod!",
+ "gui.mods.extracting": "Extracting mod...",
+ "gui.mods.installing": "Installing mod...",
+ "gui.mods.installedmod": "Installed mod!",
"gui.update.downloading": "Downloading...",
"gui.update.extracting": "Extracting update...",
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") {