aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-01-12 19:13:38 +0100
committer0neGal <mail@0negal.com>2023-01-12 19:13:38 +0100
commita67040498d238c3d7b1b947f7be02034f3b71d52 (patch)
treeefcc16b14240fc56748bf558549c192c1594df1a /src/utils.js
parentf81558d552e5e3f98438a3fe94290a96041a443a (diff)
downloadViper-a67040498d238c3d7b1b947f7be02034f3b71d52.tar.gz
Viper-a67040498d238c3d7b1b947f7be02034f3b71d52.zip
modularize settings Object
The reasoning behind this is obvious, I overall would like to make utils.js far smaller, and if not get entirely rid of it.
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js76
1 files changed, 4 insertions, 72 deletions
diff --git a/src/utils.js b/src/utils.js
index 647e089..e3e47e5 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -8,6 +8,7 @@ const events = new Emitter();
const cli = require("./cli");
const lang = require("./lang");
+const settings = require("./modules/settings");
const requests = require("./modules/requests");
const findgame = require("./modules/findgame");
@@ -16,30 +17,6 @@ const repair = require("jsonrepair");
const exec = require("child_process").exec;
const { https } = require("follow-redirects");
-process.chdir(app.getPath("appData"));
-
-var invalidsettings = false;
-
-// Base settings
-var settings = {
- gamepath: "",
- lang: "en-US",
- nsupdate: true,
- autolang: true,
- forcedlang: "en",
- autoupdate: true,
- originkill: false,
- nsargs: "-multiple",
- zip: "/northstar.zip",
-
- // These files won't be overwritten when installing/updating
- // Northstar, useful for config files
- excludes: [
- "ns_startup_args.txt",
- "ns_startup_args_dedi.txt"
- ]
-}
-
// Logs into the dev tools of the renderer
function winLog(msg) {
ipcMain.emit("win-log", msg, msg);
@@ -50,29 +27,6 @@ function winAlert(msg) {
ipcMain.emit("win-alert", msg, msg);
}
-// Creates the settings file with the base settings if it doesn't exist.
-if (fs.existsSync("viper.json")) {
- let conf = fs.readFileSync("viper.json", "utf8");
- let json = "{}";
-
- // Validates viper.json
- try {
- json = JSON.parse(conf);
- }catch (e) {
- invalidsettings = true;
- }
-
- settings = {...settings, ...json};
- settings.zip = path.join(settings.gamepath + "/northstar.zip");
-
- let args = path.join(settings.gamepath, "ns_startup_args.txt");
- if (fs.existsSync(args)) {
- settings.nsargs = fs.readFileSync(args, "utf8");
- }
-} else {
- console.log(lang("general.missingpath"));
-}
-
// A simple function that checks if the game is running, which we use to
// not update Northstar when it is running.
async function isGameRunning() {
@@ -194,7 +148,7 @@ async function setpath(win, forcedialog) {
function setGamepath(folder) {
settings.gamepath = folder;
settings.zip = path.join(settings.gamepath + "/northstar.zip");
- saveSettings();
+ settings.save();
win.webContents.send("newpath", settings.gamepath);
ipcMain.emit("newpath", null, settings.gamepath);
@@ -208,7 +162,7 @@ async function setpath(win, forcedialog) {
function setGamepath(folder, forcedialog) {
settings.gamepath = folder;
settings.zip = path.join(settings.gamepath + "/northstar.zip");
- saveSettings();
+ settings.save();
win.webContents.send("newpath", settings.gamepath);
ipcMain.emit("newpath", null, settings.gamepath);
}
@@ -241,24 +195,6 @@ async function setpath(win, forcedialog) {
}
}
-// As to not have to do the same one liner a million times, this
-// function exists, as the name suggests, it simply writes the current
-// settings to the disk.
-//
-// You can also pass a settings object to the function and it'll try and
-// merge it together with the already existing settings
-function saveSettings(obj = {}) {
- if (invalidsettings) {return false}
-
- settings = {...settings, ...obj};
-
- if (fs.existsSync(settings.gamepath)) {
- fs.writeFileSync(path.join(settings.gamepath, "ns_startup_args.txt"), settings.nsargs);
- }
-
- fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings, ...obj}));
-}
-
// Returns the current Northstar version
// If not installed it'll return "unknown"
function getNSVersion() {
@@ -1052,16 +988,12 @@ module.exports = {
isGameRunning,
isOriginRunning,
-
- settings,
- saveSettings,
-
setpath,
gamepathExists,
lang,
setlang: (lang) => {
settings.lang = lang;
- saveSettings();
+ settings.save();
},
}