From 83361f13bbc656faca99ba21f6394d7072c2fa63 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sun, 29 May 2022 16:48:26 +0200 Subject: added checks to make sure the version is correct We now check all the Northstar mods and make sure they've the same version number, and if not it's counted as an unknown version, as we can't reliable guess which version is the correct one. If Northstar Auto-Updates is enabled it'll then re-install. --- src/utils.js | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index c4318d0..7139706 100644 --- a/src/utils.js +++ b/src/utils.js @@ -220,21 +220,49 @@ function saveSettings(obj = {}) { // Returns the current Northstar version // If not installed it'll return "unknown" function getNSVersion() { - var versionFile = path.join(settings.gamepath, "R2Northstar/mods/Northstar.Client/mod.json"); + var versionFiles = [ + "Northstar.Client", + "Northstar.Custom", + "Northstar.CustomServers" + ] + + var versions = []; + + + let add = (version) => { + versions.push(version) + } + + for (let i = 0; i < versionFiles.length; i++) { + var versionFile = path.join(settings.gamepath, "R2Northstar/mods/", versionFiles[i],"/mod.json"); + if (fs.existsSync(versionFile)) { + if (! fs.statSync(versionFile).isFile()) { + add("unknown"); + } - if (fs.existsSync(versionFile)) { - if (! fs.statSync(versionFile).isFile()) { - return "unknown" + try { + add("v" + JSON.parse(fs.readFileSync(versionFile, "utf8")).Version); + }catch(err) { + add("unknown"); + } + } else { + add("unknown"); } + } + + if (versions.includes("unknown")) {return "unknown"} - try { - return "v" + JSON.parse(fs.readFileSync(versionFile, "utf8")).Version; - }catch(err) { - return "unknown"; + let mismatch = false; + let baseVersion = versions[0]; + for (let i = 0; i < versions.length; i++) { + if (versions[i] != baseVersion) { + mismatch = true; + break } - } else { - return "unknown"; } + + if (mismatch) {return "unknown"} + return baseVersion; } -- cgit v1.2.3