diff options
author | 0neGal <mail@0negal.com> | 2022-05-02 21:49:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 21:49:20 +0200 |
commit | c40e331bdc4b2375d3802a515c9b7a032118dea7 (patch) | |
tree | 77c8d84c0fc9d0fbb742cfeeb80efa4762784a9d /src/cli.js | |
parent | 9f2f77558238c28ceb8ff4fca2096602671779e5 (diff) | |
parent | 847a2178e7823749e3096daf24dfcd3df8b236cb (diff) | |
download | Viper-c40e331bdc4b2375d3802a515c9b7a032118dea7.tar.gz Viper-c40e331bdc4b2375d3802a515c9b7a032118dea7.zip |
Merge branch 'main' into enabledmods
Diffstat (limited to 'src/cli.js')
-rw-r--r-- | src/cli.js | 50 |
1 files changed, 33 insertions, 17 deletions
@@ -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 @@ -43,27 +58,28 @@ async function init() { // --help menu/argument 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")} + --no-vp-updates ${lang("cli.help.novpupdates")} - --installmod ${lang("cli.help.installmod")} - --removemod ${lang("cli.help.removemod")} - --togglemod ${lang("cli.help.togglemod")}`) + --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(); } // --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")) { @@ -77,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"); @@ -89,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 = { |