aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-08 15:05:35 +0100
committer0neGal <mail@0negal.com>2022-01-08 15:13:07 +0100
commit1c12fb2e90d26e25be6206076ad6762fa92a5962 (patch)
tree89e0035a458948f58ccc9b4aa4cac7fccb523cd5 /src
parent927def020baf544a23140ba8cfa53dcef9f23aa8 (diff)
downloadViper-1c12fb2e90d26e25be6206076ad6762fa92a5962.tar.gz
Viper-1c12fb2e90d26e25be6206076ad6762fa92a5962.zip
added cli arguments for mods
This adds both the arguments themselves, but also their entries in the man page and help page.
Diffstat (limited to 'src')
-rw-r--r--src/cli.js27
-rw-r--r--src/index.js16
-rw-r--r--src/lang/en.json9
-rw-r--r--src/utils.js26
4 files changed, 63 insertions, 15 deletions
diff --git a/src/cli.js b/src/cli.js
index 55cee0e..d5ee3ad 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -16,7 +16,10 @@ function hasArgs() {
cli.hasSwitch("setpath") ||
cli.hasSwitch("version") ||
cli.hasSwitch("updatevp") ||
- cli.hasSwitch("gamepath")) {
+ cli.hasSwitch("gamepath") ||
+ cli.hasSwitch("togglemod") ||
+ cli.hasSwitch("removemod") ||
+ cli.hasSwitch("installmod")) {
return true;
} else {return false}
}
@@ -28,14 +31,18 @@ function exit(code) {
async function init() {
if (cli.hasSwitch("help")) {
console.log(`options:
- --help ${lang("cli.help.help")}
- --debug ${lang("cli.help.debug")}
- --version ${lang("cli.help.version")}
+ --help ${lang("cli.help.help")}
+ --debug ${lang("cli.help.debug")}
+ --version ${lang("cli.help.version")}
- --cli ${lang("cli.help.cli")}
- --update ${lang("cli.help.update")}
- --updatevp ${lang("cli.help.updatevp")}
- --setpath ${lang("cli.help.setpath")}`)
+ --cli ${lang("cli.help.cli")}
+ --update ${lang("cli.help.update")}
+ --updatevp ${lang("cli.help.updatevp")}
+ --setpath ${lang("cli.help.setpath")}
+
+ --installmod ${lang("cli.help.installmod")}
+ --removemod ${lang("cli.help.removemod")}
+ --togglemod ${lang("cli.help.togglemod")}`)
// In the future --setpath should be able to understand
// relative paths, instead of just absolute ones.
exit();
@@ -64,6 +71,10 @@ async function init() {
}
}
+ if (cli.hasSwitch("installmod")) {ipcMain.emit("installmod")}
+ if (cli.hasSwitch("removemod")) {ipcMain.emit("removemod", "", cli.getSwitchValue("removemod"))}
+ if (cli.hasSwitch("togglemod")) {ipcMain.emit("togglemod", "", cli.getSwitchValue("togglemod"))}
+
if (cli.hasSwitch("mods")) {ipcMain.emit("getmods")}
}
diff --git a/src/index.js b/src/index.js
index c03326c..09aa626 100644
--- a/src/index.js
+++ b/src/index.js
@@ -54,15 +54,20 @@ function start() {
ipcMain.on("updatenow", () => {
autoUpdater.quitAndInstall();
})
+}
- ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)})
- ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)})
- ipcMain.on("installmod", () => {
+ipcMain.on("installmod", () => {
+ if (cli.hasArgs()) {
+ utils.mods.install(cli.param("installmod"))
+ } else {
dialog.showOpenDialog({properties: ["openFile"]}).then(res => {
utils.mods.install(res.filePaths[0]);
}).catch(err => {console.error(err)})
- })
-}
+ }
+})
+
+ipcMain.on("removemod", (event, mod) => {utils.mods.remove(mod)})
+ipcMain.on("togglemod", (event, mod) => {utils.mods.toggle(mod)})
ipcMain.on("launch", (event) => {utils.launch()})
ipcMain.on("setlang", (event, lang) => {utils.setlang(lang)})
@@ -77,6 +82,7 @@ ipcMain.on("setpath", (event, value) => {
win.show();
}
});
+
ipcMain.on("newpath", (event, newpath) => {
if (newpath === false && !win.isVisible()) {
win.webContents.send("nopathselected");
diff --git a/src/lang/en.json b/src/lang/en.json
index 3f025a8..aa76cdf 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -6,6 +6,9 @@
"cli.help.update": "updates Northstar from your set game path",
"cli.help.setpath": "sets your game path",
"cli.help.updatevp": "updates Viper itself, if supported.",
+ "cli.help.installmod": "installs a mod, folder or zip",
+ "cli.help.removemod": "removes a mod",
+ "cli.help.togglemod": "toggles a mod",
"cli.setpath.noarg": "No argument provided for --setpath",
@@ -18,7 +21,13 @@
"cli.launch.linuxerror": "Launching the game is not currently supported on Linux",
+ "cli.mods.failed": "Failed to install mod!",
+ "cli.mods.removed": "Successfully removed mod!",
+ "cli.mods.toggled": "Successfully toggled mod",
+ "cli.mods.installed": "Successfully installed mod!",
+ "cli.mods.cantfind": "Can't find a mod with that name!",
"cli.mods.notamod": "Selected folder/file is not a mod",
+ "cli.mods.toggledall": "Successfully toggled all mods",
"cli.mods.improperjson": "%s's mod.json has formatting errors",
"gui.welcome": "Welcome to Viper!",
diff --git a/src/utils.js b/src/utils.js
index 18c52da..1e05fed 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -245,7 +245,9 @@ const mods = {
}
let installed = () => {
+ console.log(lang("cli.mods.installed"));
cli.exit();
+
winLog(lang("gui.mods.installedmod"))
ipcMain.emit("guigetmods");
}
@@ -314,6 +316,12 @@ const mods = {
}
let modName = mods.get(mod).FolderName;
+ if (! modName) {
+ console.log("error: " + lang("cli.mods.cantfind"))
+ cli.exit(1);
+ return;
+ }
+
let modPath = path.join(modpath, modName);
if (mods.get(mod).Disabled) {
@@ -322,18 +330,22 @@ const mods = {
if (fs.statSync(modPath).isDirectory()) {
fs.rmSync(modPath, {recursive: true});
+ console.log(lang("cli.mods.removed"));
cli.exit();
ipcMain.emit("guigetmods");
} else {
cli.exit(1);
}
},
- toggle: (mod) => {
+ toggle: (mod, fork) => {
if (mod == "allmods") {
let modlist = mods.list().all;
for (let i = 0; i < modlist.length; i++) {
- mods.toggle(modlist[i].Name)
+ mods.toggle(modlist[i].Name, true)
}
+
+ console.log(lang("cli.mods.toggledall"));
+ cli.exit(0);
return
}
@@ -343,6 +355,12 @@ const mods = {
}
let modName = mods.get(mod).FolderName;
+ if (! modName) {
+ console.log("error: " + lang("cli.mods.cantfind"))
+ cli.exit(1);
+ return;
+ }
+
let modPath = path.join(modpath, modName);
let dest = path.join(disabled, modName);
@@ -352,6 +370,10 @@ const mods = {
}
fs.moveSync(modPath, dest)
+ if (! fork) {
+ console.log(lang("cli.mods.toggled"));
+ cli.exit();
+ }
ipcMain.emit("guigetmods");
}
};