aboutsummaryrefslogtreecommitdiff
path: root/src/cli.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-04-13 23:22:42 +0200
committer0neGal <mail@0negal.com>2022-04-13 23:28:24 +0200
commitcbcaafa35624c70e313c00232f78a366d05ef3a9 (patch)
treef537d951c54437b8d1a195348ef66f51112f6fcd /src/cli.js
parente48c5d92d0bd113c680e53aa307ff6d440794007 (diff)
downloadViper-cbcaafa35624c70e313c00232f78a366d05ef3a9.tar.gz
Viper-cbcaafa35624c70e313c00232f78a366d05ef3a9.zip
check to make sure gamepath exists
When Viper starts up it'll check to make sure the gamepath still exists, and throws errors if not, it also redirects you to the first page (the one where you can set the gamepath), and gives you an informative error. This could happen because the user unmounted the drive the gamepath is on, or it could happen if the user moved their game location.
Diffstat (limited to 'src/cli.js')
-rw-r--r--src/cli.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/cli.js b/src/cli.js
index dd043c5..58385f4 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -34,6 +34,21 @@ function exit(code) {
if (hasArgs()) {process.exit(code)}
}
+// Ensures the gamepath exists, it's called by options that require the
+// gamepath to be able to work.
+function gamepath() {
+ if (fs.existsSync("viper.json")) {
+ gamepath = JSON.parse(fs.readFileSync("viper.json", "utf8")).gamepath;
+
+ if (! fs.existsSync(gamepath)) {
+ console.error(`error: ${lang("cli.gamepath.lost")}`);
+ exit(1);
+ } else {
+ return true;
+ }
+ }
+}
+
// General CLI initialization
//
// A lot of the CLI is handled through events sent back to the main
@@ -62,9 +77,9 @@ async function init() {
}
// --update
- if (cli.hasSwitch("update")) {ipcMain.emit("update")}
+ if (gamepath() && cli.hasSwitch("update")) {ipcMain.emit("update")}
// --version
- if (cli.hasSwitch("version")) {ipcMain.emit("versioncli")}
+ if (gamepath() && cli.hasSwitch("version")) {ipcMain.emit("versioncli")}
// --setpath
if (cli.hasSwitch("setpath")) {
@@ -78,7 +93,7 @@ async function init() {
}
// --launch
- if (cli.hasSwitch("launch")) {
+ if (gamepath() && cli.hasSwitch("launch")) {
switch(cli.getSwitchValue("launch")) {
case "vanilla":
ipcMain.emit("launchVanilla");
@@ -90,12 +105,12 @@ async function init() {
}
// Mod related args, --installmod, --removemod, --togglemod
- 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 (gamepath() && cli.hasSwitch("installmod")) {ipcMain.emit("installmod")}
+ if (gamepath() && cli.hasSwitch("removemod")) {ipcMain.emit("removemod", "", cli.getSwitchValue("removemod"))}
+ if (gamepath() && cli.hasSwitch("togglemod")) {ipcMain.emit("togglemod", "", cli.getSwitchValue("togglemod"))}
// Prints out the list of mods
- if (cli.hasSwitch("mods")) {ipcMain.emit("getmods")}
+ if (gamepath() && cli.hasSwitch("mods")) {ipcMain.emit("getmods")}
}
module.exports = {