aboutsummaryrefslogtreecommitdiff
path: root/src/utils.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/utils.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/utils.js')
-rw-r--r--src/utils.js24
1 files changed, 21 insertions, 3 deletions
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();
// <file>.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;