From 63fb961c1a3b5df509ee96711b6d489b40efb330 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Thu, 24 Mar 2022 17:15:44 +0100 Subject: added --no-vp-updates This overwrites viper.json and disables Viper updates, this is useful when repackaging Viper for other formats we don't already support. --- src/cli.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/cli.js') diff --git a/src/cli.js b/src/cli.js index cef2295..dd043c5 100644 --- a/src/cli.js +++ b/src/cli.js @@ -43,18 +43,19 @@ 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(); -- cgit v1.2.3 From cbcaafa35624c70e313c00232f78a366d05ef3a9 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 13 Apr 2022 23:22:42 +0200 Subject: 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. --- src/app/main.js | 6 ++++++ src/cli.js | 29 ++++++++++++++++++++++------- src/index.js | 8 ++++++++ src/lang/en.json | 3 +++ src/utils.js | 24 +++++++++++++++++++++--- 5 files changed, 60 insertions(+), 10 deletions(-) (limited to 'src/cli.js') diff --git a/src/app/main.js b/src/app/main.js index 9218ec7..70d1b0c 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -83,11 +83,17 @@ function setButtons(state) { } } + disablearray(document.querySelectorAll(".playBtnContainer .playBtn")) disablearray(document.querySelectorAll("#nsMods .buttons.modbtns button")) disablearray(document.querySelectorAll("#browser #browserEntries .text button")) } ipcRenderer.on("setbuttons", (event, state) => {setButtons(state)}) +ipcRenderer.on("gamepathlost", (event, state) => { + page(0); + setButtons(false); + alert(lang("gui.gamepath.lost")); +}) // Frontend part of updating Northstar ipcRenderer.on("ns-update-event", (event, key) => { 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 = { diff --git a/src/index.js b/src/index.js index 752410e..b38b65d 100644 --- a/src/index.js +++ b/src/index.js @@ -53,6 +53,14 @@ function start() { ipcMain.on("installedmod", (event, modname) => {win.webContents.send("installedmod", modname)}); ipcMain.on("guigetmods", (event, ...args) => {win.webContents.send("mods", utils.mods.list())}); + let gamepathlost = false; + ipcMain.on("gamepathlost", (event, ...args) => { + if (! gamepathlost) { + gamepathlost = true; + win.webContents.send("gamepathlost"); + } + }); + ipcMain.on("savesettings", (event, obj) => {utils.saveSettings(obj)}) ipcMain.on("can-autoupdate", (event) => { diff --git a/src/lang/en.json b/src/lang/en.json index 501eadd..af388d8 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -31,6 +31,8 @@ "cli.launch.linuxerror": "Launching the game is not currently supported on Linux", + "cli.gamepath.lost": "Gamepath not found, make sure it's mounted!", + "cli.mods.failed": "Failed to install mod!", "cli.mods.removed": "Successfully removed mod!", "cli.mods.toggled": "Successfully toggled mod", @@ -116,6 +118,7 @@ "gui.selectpath": "Please select the path!", "gui.gamepath.must": "The game path must be set to start Viper.", "gui.gamepath.wrong": "This folder is not a valid game path.", + "gui.gamepath.lost": "Gamepath no longer exists/can't be found!\n\nMake sure your drive is mounted properly, or if you moved your game location that you update the game path.\n\nViper may not work properly until next restart!", "gui.toast.title.installed": "Mod installed!", "gui.toast.title.failed": "Failed to install", diff --git a/src/utils.js b/src/utils.js index 92197d1..19b0820 100644 --- a/src/utils.js +++ b/src/utils.js @@ -184,8 +184,10 @@ async function setpath(win, forcedialog) { // merge it together with the already existing settings function saveSettings(obj = {}) { settings = {...settings, ...obj}; - fs.writeFileSync(path.join(settings.gamepath, "ns_startup_args.txt"), settings.nsargs); fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings, ...obj})); + + if (! gamepathExists()) {return} + fs.writeFileSync(path.join(settings.gamepath, "ns_startup_args.txt"), settings.nsargs); } // Returns the current Northstar version @@ -196,7 +198,10 @@ function getNSVersion() { if (fs.existsSync(versionFilePath)) { return fs.readFileSync(versionFilePath, "utf8"); } else { - fs.writeFileSync(versionFilePath, "unknown"); + if (gamepathExists()) { + fs.writeFileSync(versionFilePath, "unknown"); + } + return "unknown"; } } @@ -239,6 +244,8 @@ restoreExcludedFiles(); // .excluded, then rename them back after the extraction. The // unzip module does not support excluding files directly. async function update() { + if (! gamepathExists()) {return} + ipcMain.emit("ns-update-event", "cli.update.checking"); console.log(lang("cli.update.checking")); var version = getNSVersion(); @@ -372,6 +379,12 @@ function winAlert(msg) { ipcMain.emit("winAlert", msg, msg); } +// Returns true/false depending on if the gamepath currently exists/is +// mounted, used to avoid issues... +function gamepathExists() { + return fs.existsSync(settings.gamepath); +} + // Used to manage mods. // // We can both get list of disabled mods, remove/install/toggle mods and @@ -768,7 +781,11 @@ const mods = { }; setInterval(() => { - ipcMain.emit("guigetmods"); + if (gamepathExists()) { + ipcMain.emit("guigetmods"); + } else { + ipcMain.emit("gamepathlost"); + } }, 1500) module.exports = { @@ -784,6 +801,7 @@ module.exports = { getNSVersion, getTF2Version, isGameRunning, + gamepathExists, handleNorthstarUpdating, setlang: (lang) => { settings.lang = lang; -- cgit v1.2.3