diff options
-rw-r--r-- | src/index.js | 2 | ||||
-rw-r--r-- | src/lang/en.json | 4 | ||||
-rw-r--r-- | src/utils.js | 48 |
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") { |