From a4978e160eff00ab387d8217ac53d66ca2794ee3 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 23:48:07 +0100 Subject: [refactor] northstar version is stored in gamepath --- src/utils.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/utils.js') diff --git a/src/utils.js b/src/utils.js index 66c8644..dde5515 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,7 +17,6 @@ process.chdir(app.getPath("appData")); var settings = { gamepath: "", zip: "/northstar.zip", - northstar_version: "unknown", excludes: [ "ns_startup_args.txt", "ns_startup_args_dedi.txt" @@ -49,13 +48,21 @@ function setpath(win) { } function saveSettings() { - fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings})); + fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings)); } function getInstalledVersion() { - return JSON.parse( - fs.readFileSync(app.getPath("appData") + "/viper.json", "utf8") - )['northstarVersion']; + const versionFilePath = path.join(settings.gamepath, 'ns_version.txt'); + + if (fs.existsSync(versionFilePath)) { + return fs.readFileSync(versionFilePath, "utf8"); + } else { + fs.writeFileSync(versionFilePath, 'unknown'); + return 'unknown'; + } +} +function updateInstalledVersion(newTag) { + fs.writeFileSync(path.join(settings.gamepath, 'ns_version.txt'), newTag); } function update() { @@ -93,8 +100,9 @@ function update() { fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) .on("finish", () => { console.log("Installation/Update finished!"); - settings.northstar_version = tag; - saveSettings(); + + updateInstalledVersion(tag); + events.emit("updated"); for (let i = 0; i < settings.excludes.length; i++) { -- cgit v1.2.3