diff options
author | 0neGal <mail@0negal.com> | 2022-04-28 00:23:34 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-04-28 00:23:34 +0200 |
commit | 5302d33b7433c68947083ef57b6bb784bd02124f (patch) | |
tree | 55ed179f5976c659c3e3109a044fbfb5782c74c4 /src/utils.js | |
parent | 4f543a32e2fe5aa9d6a136e853dff8ab2cff4faf (diff) | |
download | Viper-5302d33b7433c68947083ef57b6bb784bd02124f.tar.gz Viper-5302d33b7433c68947083ef57b6bb784bd02124f.zip |
added: error if config file isn't valid
Essentially just validates the config file and then prompts you about
it, it allows you to reset it directly or just to exit and let yourself
fix it. And because the error message appears directly in the renderer
we have access to navigator.language, and can therefore still localize
the string. However! We can't actually care if the user has disabled
auto detection of their language, since... y'know, the config file where
that's stored isn't able to be read properly.
And so I added an argument to lang(), which allows you to force it to
use a specific language if that language is available, if not it
defaults back to English.
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/utils.js b/src/utils.js index 89bcf92..77e8fc7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -18,6 +18,8 @@ const { https } = require("follow-redirects"); process.chdir(app.getPath("appData")); +var invalidsettings = false; + // Base settings var settings = { gamepath: "", @@ -37,9 +39,29 @@ var settings = { ] } +// Logs into the dev tools of the renderer +function winLog(msg) { + ipcMain.emit("winLog", msg, msg); +} + +// Sends an alert to the renderer +function winAlert(msg) { + ipcMain.emit("winAlert", msg, msg); +} + // Creates the settings file with the base settings if it doesn't exist. if (fs.existsSync("viper.json")) { - settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))}; + 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"); @@ -183,6 +205,8 @@ async function setpath(win, forcedialog) { // 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)) { @@ -372,16 +396,6 @@ function launch(version) { } } -// Logs into the dev tools of the renderer -function winLog(msg) { - ipcMain.emit("winLog", msg, msg); -} - -// Sends an alert to the renderer -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() { |