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/utils.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/utils.js') 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