aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/index.js12
-rw-r--r--src/modules/gamepath.js33
-rw-r--r--src/modules/launch.js8
-rw-r--r--src/modules/mods.js2
-rw-r--r--src/modules/packages.js2
-rw-r--r--src/modules/settings.js28
-rw-r--r--src/modules/update.js30
-rw-r--r--src/modules/version.js6
8 files changed, 73 insertions, 48 deletions
diff --git a/src/index.js b/src/index.js
index 74fe669..82805d1 100644
--- a/src/index.js
+++ b/src/index.js
@@ -74,7 +74,7 @@ function start() {
}; send = win.send;
ipcMain.on("exit", () => {
- if (settings.originkill) {
+ if (settings().originkill) {
is_running.origin().then((running) => {
if (running) {
kill.origin().then(process.exit(0))
@@ -111,7 +111,7 @@ function start() {
ipcMain.on("delete-install-cache", () => {
let delete_dirs = [
path.join(app.getPath("cache"), "vipertmp"),
- path.join(settings.gamepath, "northstar.zip")
+ path.join(settings().gamepath, "northstar.zip")
]
for (let i = 0; i < delete_dirs.length; i++) {
@@ -197,7 +197,7 @@ function start() {
});
ipcMain.on("save-settings", (event, obj) => {
- settings.save(obj, false)
+ settings().save(obj, false);
});
ipcMain.on("saved-settings", (event, obj) => {
@@ -219,7 +219,7 @@ function start() {
})
// start auto-update process
- if (settings.autoupdate) {
+ if (settings().autoupdate) {
if (cli.hasParam("no-vp-updates")) {
update.northstar_autoupdate();
} else {
@@ -265,8 +265,8 @@ ipcMain.on("launch-ns", () => {launch()});
ipcMain.on("launch-vanilla", () => {launch("vanilla")});
ipcMain.on("setlang", (event, lang) => {
- settings.lang = lang;
- settings.save();
+ settings().set("lang", lang);
+ settings().save();
});
ipcMain.on("update-northstar", async (e, force_install) => {
diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js
index 0a9dcc6..8d28c29 100644
--- a/src/modules/gamepath.js
+++ b/src/modules/gamepath.js
@@ -16,7 +16,7 @@ let gamepath = {};
// returns true/false depending on if the gamepath currently exists/is
// mounted, used to avoid issues...
gamepath.exists = (folder) => {
- return fs.existsSync(folder || settings.gamepath);
+ return fs.existsSync(folder || settings().gamepath);
}
// returns false if the user doesn't have read/write permissions to the
@@ -29,7 +29,7 @@ gamepath.has_perms = (folder) => {
try {
fs.accessSync(
- folder || settings.gamepath,
+ folder || settings().gamepath,
fs.constants.R_OK | fs.constants.W_OK
)
@@ -51,14 +51,16 @@ 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().set("gamepath", folder);
+ settings().set("zip", path.join(
+ settings().gamepath + "/northstar.zip"
+ ))
- settings.save(); // save settings
+ settings().save(); // save settings
// tell the renderer the path has changed
- win.webContents.send("newpath", settings.gamepath);
- ipcMain.emit("newpath", null, settings.gamepath);
+ win.webContents.send("newpath", settings().gamepath);
+ ipcMain.emit("newpath", null, settings().gamepath);
}
if (! win) { // CLI
@@ -69,11 +71,14 @@ gamepath.set = async (win, force_dialog) => {
// 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();
- win.webContents.send("newpath", settings.gamepath);
- ipcMain.emit("newpath", null, settings.gamepath);
+ settings().set("gamepath", folder);
+ settings().set("zip", path.join(
+ settings().gamepath + "/northstar.zip")
+ )
+
+ settings().save();
+ win.webContents.send("newpath", settings().gamepath);
+ ipcMain.emit("newpath", null, settings().gamepath);
gamepath.setting = false;
}
@@ -127,13 +132,13 @@ gamepath.set = async (win, force_dialog) => {
setInterval(() => {
if (gamepath.exists()) {
if (! gamepath.has_perms()) {
- return ipcMain.emit("gamepath-lost-perms", null, settings.gamepath);
+ return ipcMain.emit("gamepath-lost-perms", null, settings().gamepath);
}
ipcMain.emit("gui-getmods");
} else {
if (fs.existsSync("viper.json")) {
- if (settings.gamepath != "") {
+ if (settings().gamepath != "") {
ipcMain.emit("gamepath-lost");
}
}
diff --git a/src/modules/launch.js b/src/modules/launch.js
index 9238336..bb094e9 100644
--- a/src/modules/launch.js
+++ b/src/modules/launch.js
@@ -22,23 +22,23 @@ function launch(game_version) {
}
// change current directory to gamepath
- process.chdir(settings.gamepath);
+ process.chdir(settings().gamepath);
- let launch_args = settings.nsargs || "";
+ let launch_args = settings().nsargs || "";
// launch the requested game version
switch(game_version) {
case "vanilla":
console.info(lang("general.launching"), "Vanilla...");
exec("Titanfall2.exe " + launch_args, {
- cwd: settings.gamepath
+ cwd: settings().gamepath
})
break;
default:
console.info(lang("general.launching"), "Northstar...");
exec("NorthstarLauncher.exe " + launch_args, {
- cwd: settings.gamepath
+ cwd: settings().gamepath
})
break;
diff --git a/src/modules/mods.js b/src/modules/mods.js
index 50db011..122ff7f 100644
--- a/src/modules/mods.js
+++ b/src/modules/mods.js
@@ -21,7 +21,7 @@ var mods = {
}
function update_path() {
- mods.path = path.join(settings.gamepath, "R2Northstar/mods");
+ mods.path = path.join(settings().gamepath, "R2Northstar/mods");
}; update_path();
// returns a list of mods
diff --git a/src/modules/packages.js b/src/modules/packages.js
index 38303e2..392c550 100644
--- a/src/modules/packages.js
+++ b/src/modules/packages.js
@@ -15,7 +15,7 @@ console = require("./console");
var packages = {};
function update_path() {
- packages.path = path.join(settings.gamepath, "R2Northstar/packages");
+ packages.path = path.join(settings().gamepath, "R2Northstar/packages");
// make sure the `packages` folder exists
if (fs.existsSync(packages.path)) {
diff --git a/src/modules/settings.js b/src/modules/settings.js
index 9d036cf..db6c68c 100644
--- a/src/modules/settings.js
+++ b/src/modules/settings.js
@@ -58,7 +58,7 @@ if (fs.existsSync("viper.json")) {
//
// you can also pass a settings object to the function and it'll try and
// merge it together with the already existing settings
-settings.save = (obj = {}, notify_renderer = true) => {
+let save = (obj = {}, notify_renderer = true) => {
// refuse to save if settings aren't valid
if (invalid_settings) {
settings = {};
@@ -68,8 +68,6 @@ settings.save = (obj = {}, notify_renderer = true) => {
...settings, ...obj
}
- delete settings_content.save;
-
let stringified_settings = JSON.stringify({
...settings, ...obj
})
@@ -87,4 +85,26 @@ settings.save = (obj = {}, notify_renderer = true) => {
}
}
-module.exports = settings;
+// sets `key` in `settings` to `value`
+let set = (key, value) => {
+ settings[key] = value;
+}
+
+// returns up-to-date `settings`, along with `set()` and `save()`
+let export_func = () => {
+ return {
+ ...settings,
+
+ set,
+ save
+ }
+}
+
+// add properties from `settings` to `export_func`, this is just for
+// backwards compatibility, and they really shouldn't be relied on,
+// this'll likely be removed at some point
+for (let i in settings) {
+ export_func[i] = settings[i];
+}
+
+module.exports = export_func;
diff --git a/src/modules/update.js b/src/modules/update.js
index 0876993..6b31da7 100644
--- a/src/modules/update.js
+++ b/src/modules/update.js
@@ -23,8 +23,8 @@ let update = {};
function restore_excluded_files() {
if (! gamepath.exists()) {return}
- for (let i = 0; i < settings.excludes.length; i++) {
- let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]);
+ for (let i = 0; i < settings().excludes.length; i++) {
+ let exclude = path.join(settings().gamepath + "/" + settings().excludes[i]);
if (fs.existsSync(exclude + ".excluded")) {
fs.renameSync(exclude + ".excluded", exclude);
}
@@ -32,10 +32,10 @@ function restore_excluded_files() {
}; restore_excluded_files();
// renames excluded files to <file>.excluded, the list of files to be
-// exluded is set in the settings (settings.excludes)
+// exluded is set in the settings (settings().excludes)
function exclude_files() {
- for (let i = 0; i < settings.excludes.length; i++) {
- let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]);
+ for (let i = 0; i < settings().excludes.length; i++) {
+ let exclude = path.join(settings().gamepath + "/" + settings().excludes[i]);
if (fs.existsSync(exclude)) {
fs.renameSync(exclude, exclude + ".excluded");
}
@@ -50,7 +50,7 @@ let is_auto_updating = false;
// it uses isGameRunning() to ensure it doesn't run while the game is
// running, as that may have all kinds of issues.
update.northstar_autoupdate = () => {
- if (! settings.nsupdate || ! fs.existsSync("viper.json") || settings.gamepath.length === 0) {
+ if (! settings().nsupdate || ! fs.existsSync("viper.json") || settings().gamepath.length === 0) {
return;
}
@@ -124,7 +124,7 @@ update.viper = (autoinstall) => {
if (! autoUpdater.isUpdaterActive()) {
update.viper.updating = false;
- if (settings.nsupdate) {
+ if (settings().nsupdate) {
update.northstar_autoupdate();
}
@@ -148,7 +148,7 @@ update.viper = (autoinstall) => {
// only check for NS updates if Viper itself has no updates and
// if NS auto updates is enabled.
- if (settings.nsupdate || cli.hasArgs()) {
+ if (settings().nsupdate || cli.hasArgs()) {
update.northstar_autoupdate();
}
@@ -166,7 +166,7 @@ function remove_core_mods() {
// make sure the "R2Northstar/mods" folder exists, on top of making
// sure that, it is in fact a folder
- let mod_dir = path.join(settings.gamepath, "R2Northstar/mods");
+ let mod_dir = path.join(settings().gamepath, "R2Northstar/mods");
if (! fs.existsSync(mod_dir) && ! fs.statSync(mod_dir).isFile()) {
return
}
@@ -285,7 +285,7 @@ update.northstar = async (force_install) => {
key: "cli.update.downloading",
});
- let tmp = path.dirname(settings.zip);
+ let tmp = path.dirname(settings().zip);
if (fs.existsSync(tmp)) {
if (! fs.statSync(tmp).isDirectory()) {
@@ -293,12 +293,12 @@ update.northstar = async (force_install) => {
}
} else {
fs.mkdirSync(tmp);
- if (fs.existsSync(settings.zip)) {
- fs.rmSync(settings.zip);
+ if (fs.existsSync(settings().zip)) {
+ fs.rmSync(settings().zip);
}
}
- let stream = fs.createWriteStream(settings.zip);
+ let stream = fs.createWriteStream(settings().zip);
res.pipe(stream);
let received = 0;
@@ -328,7 +328,7 @@ update.northstar = async (force_install) => {
remove_core_mods();
stream.close();
- let extract = fs.createReadStream(settings.zip);
+ let extract = fs.createReadStream(settings().zip);
win.log(lang("gui.update.extracting"));
ipcMain.emit("ns-update-event", {
@@ -341,7 +341,7 @@ update.northstar = async (force_install) => {
// extracts the zip, this is the part where we're actually
// installing Northstar.
- extract.pipe(unzip.Extract({path: settings.gamepath}))
+ extract.pipe(unzip.Extract({path: settings().gamepath}))
let extracted = 0;
let size = received;
diff --git a/src/modules/version.js b/src/modules/version.js
index 6195cad..da0a730 100644
--- a/src/modules/version.js
+++ b/src/modules/version.js
@@ -10,7 +10,7 @@ let version = {};
// if not installed it'll return "unknown"
version.northstar = () => {
// if NorthstarLauncher.exe doesn't exist, always return "unknown"
- if (! fs.existsSync(path.join(settings.gamepath, "NorthstarLauncher.exe"))) {
+ if (! fs.existsSync(path.join(settings().gamepath, "NorthstarLauncher.exe"))) {
return "unknown";
}
@@ -30,7 +30,7 @@ version.northstar = () => {
// checks version of mods
for (let i = 0; i < versionFiles.length; i++) {
- var versionFile = path.join(settings.gamepath, "R2Northstar/mods/", versionFiles[i],"/mod.json");
+ var versionFile = path.join(settings().gamepath, "R2Northstar/mods/", versionFiles[i],"/mod.json");
if (fs.existsSync(versionFile)) {
if (! fs.statSync(versionFile).isFile()) {
add("unknown");
@@ -68,7 +68,7 @@ version.northstar = () => {
// TODO: This file is present on Origin install, should check if it's
// present with Steam install as well.
version.titanfall = () => {
- var versionFilePath = path.join(settings.gamepath, "gameversion.txt");
+ var versionFilePath = path.join(settings().gamepath, "gameversion.txt");
if (fs.existsSync(versionFilePath)) {
return fs.readFileSync(versionFilePath, "utf8");
} else {