aboutsummaryrefslogtreecommitdiff
path: root/src/modules/gamepath.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-03-05 22:43:09 +0100
committer0neGal <mail@0negal.com>2023-03-05 22:43:09 +0100
commit7ef891c54e0e9b06efc09e0d5e328d900a31e958 (patch)
tree00cc2d7fe48dd558421f17a95002ad5d59a6e3f8 /src/modules/gamepath.js
parentcf61a55b1e490befa976d4240593b535777caf69 (diff)
downloadViper-7ef891c54e0e9b06efc09e0d5e328d900a31e958.tar.gz
Viper-7ef891c54e0e9b06efc09e0d5e328d900a31e958.zip
small cleanups and changes in comments
I've made some code return early instead of adding more nesting, on top of this I've added some more comments in some files, rephrased a few things, and so on...
Diffstat (limited to 'src/modules/gamepath.js')
-rw-r--r--src/modules/gamepath.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js
index 93290ec..af98f79 100644
--- a/src/modules/gamepath.js
+++ b/src/modules/gamepath.js
@@ -9,32 +9,38 @@ const settings = require("./settings");
let gamepath = {};
-// Returns true/false depending on if the gamepath currently exists/is
+// returns true/false depending on if the gamepath currently exists/is
// mounted, used to avoid issues...
gamepath.exists = () => {
return fs.existsSync(settings.gamepath);
}
-// Requests to set the game path
+// requests to set the game path
//
-// If running with CLI it takes in the --setpath argument otherwise it
+// if running with CLI it takes in the --setpath argument otherwise it
// open the systems file browser for the user to select a path.
-gamepath.set = async (win, forcedialog) => {
+gamepath.set = async (win, force_dialog) => {
+ // actually sets and saves the gamepath in the settings
function set_gamepath(folder) {
+ // set settings
settings.gamepath = folder;
settings.zip = path.join(settings.gamepath + "/northstar.zip");
- settings.save();
+
+ settings.save(); // save settings
+
+ // tell the renderer the path has changed
win.webContents.send("newpath", settings.gamepath);
ipcMain.emit("newpath", null, settings.gamepath);
-
- modpath = path.join(settings.gamepath, "R2Northstar/mods");
}
if (! win) { // CLI
+ // sets the path to the --setpath argument's value
set_gamepath(cli.param("setpath"));
} else { // GUI
- if (! forcedialog) {
- function set_gamepath(folder, forcedialog) {
+ // unless specified, we will first try to automatically find the
+ // gamepath, and then later fallback to the GUI/manual selection
+ if (! force_dialog) {
+ function set_gamepath(folder, force_dialog) {
settings.gamepath = folder;
settings.zip = path.join(settings.gamepath + "/northstar.zip");
settings.save();
@@ -51,12 +57,13 @@ gamepath.set = async (win, forcedialog) => {
win.alert(lang("general.missingpath"));
}
- // Fallback to manual selection
+ // fallback to GUI/manual selection
dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
if (res.canceled) {
ipcMain.emit("newpath", null, false);
return;
}
+
if (! fs.existsSync(path.join(res.filePaths[0], "Titanfall2.exe"))) {
ipcMain.emit("wrong-path");
return;
@@ -70,7 +77,9 @@ gamepath.set = async (win, forcedialog) => {
}
}
-// periodically check for the gamepath still existing
+// periodically check for the gamepath still existing, in case the
+// folder is on a disk that gets unmounted, or anything similar, we dont
+// want to assume the gamepath is available forever and ever.
setInterval(() => {
if (gamepath.exists()) {
ipcMain.emit("gui-getmods");