From 78a83334f42294fdc0e36c2c44e1fbff7369fd7c Mon Sep 17 00:00:00 2001 From: 0neGal Date: Fri, 18 Feb 2022 22:13:08 +0100 Subject: basic drag and drop support Since apparently dragleave and dragenter don't quite work as intended we have to resort to this obscure method which should work just fine on the user's end. --- src/lang/en.json | 1 + 1 file changed, 1 insertion(+) (limited to 'src/lang/en.json') diff --git a/src/lang/en.json b/src/lang/en.json index 27630ec..45bf7c0 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -62,6 +62,7 @@ "gui.mods.extracting": "Extracting mod...", "gui.mods.installing": "Installing mod...", "gui.mods.installedmod": "Installed mod!", + "gui.mods.dragdrop": "Drag and drop a mod to install", "gui.browser.info": "Info", "gui.browser.madeby": "by", -- cgit v1.2.3 From 68579acd60b284eeeb619595abb44a04e93887e0 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Thu, 24 Feb 2022 00:40:55 +0100 Subject: localized all strings I localized all strings for English, then went ahead and made array options have a wider input and more word spacing, since they're all space separated. --- src/app/index.html | 22 +++++++++++----------- src/app/main.css | 5 +++++ src/lang/en.json | 13 +++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) (limited to 'src/lang/en.json') diff --git a/src/app/index.html b/src/app/index.html index f605136..ac1e276 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -28,20 +28,20 @@

Northstar

- Launch options + %%gui.settings.nsargs.title%%
- Here you can add launch options for Northstar/Titanfall. + %%gui.settings.nsargs.desc%%
@@ -51,9 +51,9 @@

Updates

- Viper Auto-Updates + %%gui.settings.autoupdate.title%%
- Viper will automatically keep itself up-to-date. + %%gui.settings.autoupdate.desc%%
@@ -62,9 +62,9 @@
- Northstar Auto-Updates + %%gui.settings.nsupdate.title%%
- Viper will automatically keep Northstar up-to-date, however it can still manually be updated through the Northstar page. + %%gui.settings.nsupdate.desc%%
@@ -73,13 +73,13 @@
- Retain files on update + %%gui.settings.excludes.title%%
- When Northstar is updated, files specified here will not be overwritten by files from the new Northstar update, unless you know what you're changing, you should probably not change anything here. + %%gui.settings.excludes.desc%%
- +
diff --git a/src/app/main.css b/src/app/main.css index 0d4b9ad..734f60b 100644 --- a/src/app/main.css +++ b/src/app/main.css @@ -251,6 +251,11 @@ button { --spacing: calc(var(--padding) / 3); } +.option[type=array] .actions input { + word-spacing: 15px; + margin-right: 15vw; +} + .option .actions button { background: var(--selbg); } diff --git a/src/lang/en.json b/src/lang/en.json index 45bf7c0..47e18c0 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -73,6 +73,19 @@ "gui.browser.loading": "Loading mods...", "gui.browser.endoflist": "Maximum packages has been loaded.
Use the search for finding other packages!", + "gui.settings.save": "Save", + "gui.settings.discard": "Discard", + "gui.settings.title.ns": "Northstar", + "gui.settings.title.updates": "Updates", + "gui.settings.nsargs.title": "Launch options", + "gui.settings.nsargs.desc": "Here you can add launch options for Northstar/Titanfall.", + "gui.settings.autoupdate.title": "Viper Auto-Updates", + "gui.settings.autoupdate.desc": "Viper will automatically keep itself up-to-date.", + "gui.settings.nsupdate.title": "Northstar Auto-Updates", + "gui.settings.nsupdate.desc": "Viper will automatically keep Northstar up-to-date, however it can still manually be updated through the Northstar page.", + "gui.settings.excludes.title": "Retain files on update", + "gui.settings.excludes.desc": "When Northstar is updated, files specified here will not be overwritten by files from the new Northstar update, unless you know what you're changing, you should probably not change anything here. Each file is separated with a space.", + "gui.update.downloading": "Downloading...", "gui.update.extracting": "Extracting update...", "gui.update.finished": "Done! Ready to play!", -- cgit v1.2.3 From 63fb961c1a3b5df509ee96711b6d489b40efb330 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Thu, 24 Mar 2022 17:15:44 +0100 Subject: added --no-vp-updates This overwrites viper.json and disables Viper updates, this is useful when repackaging Viper for other formats we don't already support. --- src/cli.js | 21 +++++++++++---------- src/index.js | 8 ++++++-- src/lang/en.json | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src/lang/en.json') diff --git a/src/cli.js b/src/cli.js index cef2295..dd043c5 100644 --- a/src/cli.js +++ b/src/cli.js @@ -43,18 +43,19 @@ async function init() { // --help menu/argument if (cli.hasSwitch("help")) { console.log(`options: - --help ${lang("cli.help.help")} - --debug ${lang("cli.help.debug")} - --version ${lang("cli.help.version")} + --help ${lang("cli.help.help")} + --debug ${lang("cli.help.debug")} + --version ${lang("cli.help.version")} - --cli ${lang("cli.help.cli")} - --update ${lang("cli.help.update")} - --updatevp ${lang("cli.help.updatevp")} - --setpath ${lang("cli.help.setpath")} + --cli ${lang("cli.help.cli")} + --update ${lang("cli.help.update")} + --updatevp ${lang("cli.help.updatevp")} + --setpath ${lang("cli.help.setpath")} + --no-vp-updates ${lang("cli.help.novpupdates")} - --installmod ${lang("cli.help.installmod")} - --removemod ${lang("cli.help.removemod")} - --togglemod ${lang("cli.help.togglemod")}`) + --installmod ${lang("cli.help.installmod")} + --removemod ${lang("cli.help.removemod")} + --togglemod ${lang("cli.help.togglemod")}`) // In the future --setpath should be able to understand // relative paths, instead of just absolute ones. exit(); diff --git a/src/index.js b/src/index.js index 265e13d..752410e 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,7 @@ function start() { ipcMain.on("savesettings", (event, obj) => {utils.saveSettings(obj)}) ipcMain.on("can-autoupdate", (event) => { - if (! require("electron-updater").autoUpdater.isUpdaterActive()) { + if (! require("electron-updater").autoUpdater.isUpdaterActive() || cli.hasParam("no-vp-updates")) { win.webContents.send("cant-autoupdate") } }) @@ -66,7 +66,11 @@ function start() { }); if (utils.settings.autoupdate) { - utils.updatevp(false) + if (cli.hasParam("no-vp-updates")) { + utils.handleNorthstarUpdating(); + } else { + utils.updatevp(false) + } } else { utils.handleNorthstarUpdating(); } diff --git a/src/lang/en.json b/src/lang/en.json index 47e18c0..04ecfdd 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -6,6 +6,7 @@ "cli.help.update": "updates Northstar from your set game path", "cli.help.setpath": "sets your game path", "cli.help.updatevp": "updates Viper itself, if supported.", + "cli.help.novpupdates": "overwrites viper.json and disables Viper updates", "cli.help.installmod": "installs a mod, folder or zip", "cli.help.removemod": "removes a mod", "cli.help.togglemod": "toggles a mod", -- cgit v1.2.3 From cd48513b061898601f2a52cf7d3f5f92ad9ce958 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 26 Mar 2022 01:52:19 +0100 Subject: fixed error and removed browser on startup For testing purposes I had the mod browser auto show on startup, that's removed now, I also when refactoring some code forgot to change the name of a function everywhere, leading to an error. --- src/app/browser.js | 9 +++------ src/app/index.html | 8 ++++---- src/lang/en.json | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/lang/en.json') diff --git a/src/app/browser.js b/src/app/browser.js index b9ab165..40670bc 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -68,7 +68,7 @@ var Browser = { return } else if (! state) { if (state != undefined) { - Browser.filters(false); + Browser.filters.toggle(false); overlay.classList.remove("shown") browser.classList.remove("shown") return @@ -96,7 +96,7 @@ var Browser = { }, loading: (string) => { if (Browser.filters.get().unfiltered.length == 0) { - string = "No mods found..."; + string = lang("gui.browser.noresults"); } if (string) { @@ -116,7 +116,7 @@ var Browser = { let res = fuse.search(string); if (res.length < 1) { - Browser.loading("No results...") + Browser.loading(lang("gui.browser.noresults")) return } @@ -326,9 +326,6 @@ browser.addEventListener("scroll", () => { Browser.filters.toggle(false); }) -Browser.toggle(true); -Browser.filters.toggle(); - let checks = document.querySelectorAll(".check"); for (let i = 0; i < checks.length; i++) { checks[i].setAttribute("onclick", "this.classList.toggle('checked');Browser.loadfront();search.value = ''") diff --git a/src/app/index.html b/src/app/index.html index eab84e3..8ad5ecf 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -88,10 +88,10 @@
-

Northstar

+

%%gui.settings.title.ns%%

%%gui.settings.nsargs.title%% @@ -48,7 +48,32 @@
-

Updates

+

%%gui.settings.title.language%%

+
+
+ %%gui.settings.autolang.title%% +
+ %%gui.settings.autolang.desc%% +
+
+
+ +
+
+
+
+ %%gui.settings.forcedlang.title%% +
+ %%gui.settings.forcedlang.desc%% +
+
+
+ +
+
+

%%gui.settings.title.updates%%

%%gui.settings.autoupdate.title%% diff --git a/src/app/main.css b/src/app/main.css index 3f542ec..87d89e0 100644 --- a/src/app/main.css +++ b/src/app/main.css @@ -129,7 +129,7 @@ button { transition: 0.15s ease-in-out; } -.popup .el, .popup #search, .option .actions input, .popup #close, .popup .misc button { +.popup .el, .popup #search, .option .actions select, .option .actions input, .popup #close, .popup .misc button { color: white; display: flex; align-items: center; @@ -149,7 +149,7 @@ button { display: flex; } -.popup #search, .option .actions input { +.popup #search, .option .actions input, .option .actions select { border: none; outline: none; transition: filter 0.15s ease-in-out; @@ -292,7 +292,7 @@ button { margin-top: calc(var(--padding) / 3); } -.option .actions input { +.option .actions input, .option .actions select { width: 100%; margin: 0px; --spacing: calc(var(--padding) / 3); diff --git a/src/app/main.js b/src/app/main.js index 1688ab2..9206ae6 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -11,6 +11,8 @@ var settings = { nsargs: "", gamepath: "", nsupdate: true, + autolang: true, + forcedlang: "en", autoupdate: true, zip: "/northstar.zip", lang: navigator.language, diff --git a/src/app/settings.js b/src/app/settings.js index 902e57b..853cd0b 100644 --- a/src/app/settings.js +++ b/src/app/settings.js @@ -58,6 +58,8 @@ var Settings = { } else { opts[optName] = input; } + } else if (options[i].querySelector(".actions select")) { + opts[optName] = options[i].querySelector(".actions select").value; } else if (options[i].querySelector(".actions .switch")) { if (options[i].querySelector(".actions .switch.on")) { opts[optName] = true; @@ -74,6 +76,23 @@ var Settings = { for (let i = 0; i < options.length; i++) { let optName = options[i].getAttribute("name"); + if (optName == "forcedlang") { + let div = options[i].querySelector("select"); + + div.innerHTML = ""; + let langs = fs.readdirSync(__dirname + "/../lang"); + for (let i in langs) { + title = JSON.parse(fs.readFileSync(__dirname + `/../lang/${langs[i]}`, "utf8"))["lang.title"]; + if (title) { + div.innerHTML += `` + } + + } + + div.value = settings.forcedlang; + continue; + } + if (settings[optName] != undefined) { switch(typeof settings[optName]) { case "string": diff --git a/src/lang.js b/src/lang.js index 8174174..041ef35 100644 --- a/src/lang.js +++ b/src/lang.js @@ -7,8 +7,16 @@ var langObj = {}; function _loadTranslation() { if (fs.existsSync("viper.json")) { - lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang; + opts = JSON.parse(fs.readFileSync("viper.json", "utf8")); + lang = opts.lang; + if (! lang) {lang = "en"} + + if (opts.autolang == false) { + lang = opts.forcedlang; + if (! lang) {lang = "en"} + } + if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) { if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) { lang = lang.replace(/-.*$/, ""); @@ -19,6 +27,7 @@ function _loadTranslation() { } else { lang = "en"; } + langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8")); } diff --git a/src/lang/en.json b/src/lang/en.json index 8defc7d..501eadd 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1,4 +1,6 @@ { + "lang.title": "English", + "cli.help.help": "shows this help message", "cli.help.debug": "opens the dev/debug tools", "cli.help.version": "outputs version info", @@ -82,9 +84,14 @@ "gui.settings.save": "Save", "gui.settings.discard": "Discard", "gui.settings.title.ns": "Northstar", + "gui.settings.title.language": "Language", "gui.settings.title.updates": "Updates", "gui.settings.nsargs.title": "Launch options", "gui.settings.nsargs.desc": "Here you can add launch options for Northstar/Titanfall.", + "gui.settings.autolang.title": "Auto-Detect Language", + "gui.settings.autolang.desc": "When enabled, Viper tries to automatically detect your system language, when disabled you can manually change the language below.", + "gui.settings.forcedlang.title": "Language", + "gui.settings.forcedlang.desc": "When \"Auto-Detect Language\" is disabled, this will decide the language. Requires a restart to take effect.", "gui.settings.autoupdate.title": "Viper Auto-Updates", "gui.settings.autoupdate.desc": "Viper will automatically keep itself up-to-date.", "gui.settings.nsupdate.title": "Northstar Auto-Updates", diff --git a/src/lang/es.json b/src/lang/es.json index a5b3685..18c00a5 100644 --- a/src/lang/es.json +++ b/src/lang/es.json @@ -1,4 +1,6 @@ { + "lang.title": "Spanish - Española", + "cli.help.help": "muestra este mensaje de ayuda", "cli.help.debug": "habre las herramientas de desarrollador/depuración ", "cli.help.version": "muestra la información de la versión", diff --git a/src/lang/fr.json b/src/lang/fr.json index c1797e4..018676c 100644 --- a/src/lang/fr.json +++ b/src/lang/fr.json @@ -1,4 +1,6 @@ { + "lang.title": "French - Français", + "cli.help.help": "affiche ce message d'aide", "cli.help.debug": "affiche les outils de développement", "cli.help.version": "retourne des informations sur la version du logiciel", diff --git a/src/utils.js b/src/utils.js index 7c1c22b..92197d1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -23,6 +23,8 @@ var settings = { gamepath: "", lang: "en-US", nsupdate: true, + autolang: true, + forcedlang: "en", autoupdate: true, nsargs: "-multiple", zip: "/northstar.zip", -- cgit v1.2.3 From cbcaafa35624c70e313c00232f78a366d05ef3a9 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 13 Apr 2022 23:22:42 +0200 Subject: 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. --- src/app/main.js | 6 ++++++ src/cli.js | 29 ++++++++++++++++++++++------- src/index.js | 8 ++++++++ src/lang/en.json | 3 +++ src/utils.js | 24 +++++++++++++++++++++--- 5 files changed, 60 insertions(+), 10 deletions(-) (limited to 'src/lang/en.json') 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(); // .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; -- cgit v1.2.3 From 5302d33b7433c68947083ef57b6bb784bd02124f Mon Sep 17 00:00:00 2001 From: 0neGal Date: Thu, 28 Apr 2022 00:23:34 +0200 Subject: 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. --- src/app/main.js | 19 ++++++++++++++++++- src/index.js | 2 ++ src/lang.js | 24 ++++++++++++++++++++---- src/lang/en.json | 4 +++- src/utils.js | 36 +++++++++++++++++++++++++----------- 5 files changed, 68 insertions(+), 17 deletions(-) (limited to 'src/lang/en.json') diff --git a/src/app/main.js b/src/app/main.js index 70d1b0c..95b6f4c 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -27,7 +27,24 @@ ipcRenderer.send("setlang", settings.lang); // Loads the settings 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) { + let reset = confirm(lang("general.invalidconfig", navigator.language) + e); + if (! reset) { + ipcRenderer.send("exit") + } else { + fs.writeFileSync("viper.json", "{}") + ipcRenderer.send("relaunch"); + } + + } + + settings = {...settings, ...json}; settings.zip = path.join(settings.gamepath + "/northstar.zip"); if (settings.gamepath.length === 0) { diff --git a/src/index.js b/src/index.js index b38b65d..6c3c79c 100644 --- a/src/index.js +++ b/src/index.js @@ -41,8 +41,10 @@ function start() { win.removeMenu(); win.loadFile(__dirname + "/app/index.html"); + ipcMain.on("exit", () => {process.exit(0)}) ipcMain.on("minimize", () => {win.minimize()}) + ipcMain.on("relaunch", () => {app.relaunch();app.exit()}) ipcMain.on("installfrompath", (event, path) => {utils.mods.install(path)}) ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)}) ipcMain.on("winLog", (event, ...args) => {win.webContents.send("log", ...args)}); diff --git a/src/lang.js b/src/lang.js index 041ef35..f2fab3a 100644 --- a/src/lang.js +++ b/src/lang.js @@ -5,13 +5,24 @@ let lang = ""; var langObj = {}; -function _loadTranslation() { +function _loadTranslation(forcedlang) { if (fs.existsSync("viper.json")) { - opts = JSON.parse(fs.readFileSync("viper.json", "utf8")); + // Validate viper.json + let opts = { + lang: "en", + autolang: true, + } + + try { + opts = JSON.parse(fs.readFileSync("viper.json", "utf8")); + }catch (e) {} + lang = opts.lang; if (! lang) {lang = "en"} + if (forcedlang) {lang = forcedlang} + if (opts.autolang == false) { lang = opts.forcedlang; if (! lang) {lang = "en"} @@ -32,9 +43,14 @@ function _loadTranslation() { } -module.exports = (string) => { - if (lang === "") +module.exports = (string, forcedlang) => { + if (lang === "") { _loadTranslation(); + } + + if (forcedlang) { + _loadTranslation(forcedlang); + } if (langObj[string]) { return langObj[string]; diff --git a/src/lang/en.json b/src/lang/en.json index af388d8..6849573 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -145,5 +145,7 @@ "general.mods.installed": "Installed mods:", "general.missingpath": "Game location could not be found automatically! Please select it manually!", "general.notinstalled": "Northstar is not installed!", - "general.launching": "Launching" + "general.launching": "Launching", + "general.reset": "Reset", + "general.invalidconfig": "Your config file is improperly formatted, if it's been manually edited, please validate that everything is typed correctly.\n\nIf you did not manually edit the config file, it is recommended to simply reset the config.\n\nTo reset your config file simply click \"Ok\" below.\n\nMore details:\n" } 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() { -- cgit v1.2.3 From 847a2178e7823749e3096daf24dfcd3df8b236cb Mon Sep 17 00:00:00 2001 From: 0neGal Date: Thu, 28 Apr 2022 00:29:07 +0200 Subject: removed: unused lang string This was meant to be used for the reset config prompt, but confirm() doesn't allow you to change the button messages, which I forgot when I was making this lang string, and subsequently lead to me forgetting I even made the string, accidentally pushing it... --- src/lang/en.json | 1 - 1 file changed, 1 deletion(-) (limited to 'src/lang/en.json') diff --git a/src/lang/en.json b/src/lang/en.json index 6849573..ee932a2 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -146,6 +146,5 @@ "general.missingpath": "Game location could not be found automatically! Please select it manually!", "general.notinstalled": "Northstar is not installed!", "general.launching": "Launching", - "general.reset": "Reset", "general.invalidconfig": "Your config file is improperly formatted, if it's been manually edited, please validate that everything is typed correctly.\n\nIf you did not manually edit the config file, it is recommended to simply reset the config.\n\nTo reset your config file simply click \"Ok\" below.\n\nMore details:\n" } -- cgit v1.2.3