aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/app/main.js6
-rw-r--r--src/cli.js29
-rw-r--r--src/index.js8
-rw-r--r--src/lang/en.json3
-rw-r--r--src/utils.js24
5 files changed, 60 insertions, 10 deletions
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();
// <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;