From 91a6f7161865b4b405e7c5517113d8e519c15aaf Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 24 May 2022 15:21:32 +0200 Subject: deprecate ns_version.txt --- src/utils.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils.js b/src/utils.js index e63297e..c4318d0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -220,15 +220,19 @@ function saveSettings(obj = {}) { // Returns the current Northstar version // If not installed it'll return "unknown" function getNSVersion() { - var versionFilePath = path.join(settings.gamepath, "ns_version.txt"); + var versionFile = path.join(settings.gamepath, "R2Northstar/mods/Northstar.Client/mod.json"); - if (fs.existsSync(versionFilePath)) { - return fs.readFileSync(versionFilePath, "utf8"); - } else { - if (gamepathExists()) { - fs.writeFileSync(versionFilePath, "unknown"); + if (fs.existsSync(versionFile)) { + if (! fs.statSync(versionFile).isFile()) { + return "unknown" } + try { + return "v" + JSON.parse(fs.readFileSync(versionFile, "utf8")).Version; + }catch(err) { + return "unknown"; + } + } else { return "unknown"; } } @@ -278,6 +282,7 @@ async function update() { var version = getNSVersion(); const latestAvailableVersion = await requests.getLatestNsVersion(); + console.log(latestAvailableVersion) // Makes sure it is not already the latest version if (version === latestAvailableVersion) { @@ -325,7 +330,6 @@ async function update() { // installing Northstar. fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) .on("finish", () => { - fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), latestAvailableVersion); ipcMain.emit("getversion"); restoreExcludedFiles(); -- cgit v1.2.3 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(-) 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 From d21931a94c20bd37278986185433df60c495250a Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 29 Jun 2022 18:02:39 +0200 Subject: require NorthstarLauncher.exe to be found Now, even if the core mods are installed it'll still make sure the NorthstarLauncher.exe exists, so if Northstar has only been half installed it'll be detected. --- src/utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils.js b/src/utils.js index 7139706..a47bff1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -220,6 +220,12 @@ function saveSettings(obj = {}) { // Returns the current Northstar version // If not installed it'll return "unknown" function getNSVersion() { + // if NorthstarLauncher.exe doesn't exist, always return "unknown" + if (! fs.existsSync(path.join(settings.gamepath, "NorthstarLauncher.exe"))) { + return "unknown"; + } + + // mods to check version of var versionFiles = [ "Northstar.Client", "Northstar.Custom", @@ -233,6 +239,7 @@ function getNSVersion() { versions.push(version) } + // checks version of mods for (let i = 0; i < versionFiles.length; i++) { var versionFile = path.join(settings.gamepath, "R2Northstar/mods/", versionFiles[i],"/mod.json"); if (fs.existsSync(versionFile)) { @@ -252,6 +259,7 @@ function getNSVersion() { if (versions.includes("unknown")) {return "unknown"} + // verifies all mods have the same version number let mismatch = false; let baseVersion = versions[0]; for (let i = 0; i < versions.length; i++) { -- cgit v1.2.3