From b967b24e550e2e3576ddbe20de315eec3e7209cf Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 22:21:42 +0100 Subject: [feat] extracting latest northstar release version tag --- src/utils.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 85ce5ce..376c03c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -61,6 +61,9 @@ function update() { headers: {"User-Agent": "Viper"}, url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest", }, (error, response, body) => { + const tag = body['tag_name']; + console.log(tag); + https.get(body.assets[0].browser_download_url, (res) => { let stream = fs.createWriteStream(settings.zip); res.pipe(stream); -- cgit v1.2.3 From e9bd16e8cee14b983bad23cbae088794bb80349d Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 22:37:18 +0100 Subject: [feat] storing local northstar version in viper.json --- src/utils.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 376c03c..e7e118d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,6 +17,7 @@ process.chdir(app.getPath("appData")); var settings = { gamepath: "", zip: "/northstar.zip", + northstarVersion: "unknown", excludes: [ "ns_startup_args.txt", "ns_startup_args_dedi.txt" @@ -47,6 +48,11 @@ function setpath(win) { cli.exit(); } +function getNorthstarInstalledVersion() { + const configFilePath = app.getPath("appData") + "/viper.json"; + return JSON.parse(fs.readFileSync(configFilePath, "utf8"))['northstarVersion']; +} + function update() { for (let i = 0; i < settings.excludes.length; i++) { let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]); @@ -56,6 +62,9 @@ function update() { } console.log("Downloading..."); + const version = getNorthstarInstalledVersion(); + console.log(version); + request({ json: true, headers: {"User-Agent": "Viper"}, -- cgit v1.2.3 From 810176c592c5cc071dd8ca14ed9519b38e1c96d9 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 22:41:19 +0100 Subject: [feat] saving newly installed version tag --- src/utils.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index e7e118d..a6be21d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -48,6 +48,10 @@ function setpath(win) { cli.exit(); } +function saveSettings() { + fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings})); +} + function getNorthstarInstalledVersion() { const configFilePath = app.getPath("appData") + "/viper.json"; return JSON.parse(fs.readFileSync(configFilePath, "utf8"))['northstarVersion']; @@ -64,7 +68,7 @@ function update() { console.log("Downloading..."); const version = getNorthstarInstalledVersion(); console.log(version); - + request({ json: true, headers: {"User-Agent": "Viper"}, @@ -82,6 +86,8 @@ function update() { fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) .on("finish", () => { console.log("Installation/Update finished!"); + settings.northstarVersion = tag; + saveSettings(); events.emit("updated"); for (let i = 0; i < settings.excludes.length; i++) { -- cgit v1.2.3 From 30fc024406227c89dc3c6d5a067f21a991d1e20c Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 22:49:11 +0100 Subject: [feat] latest update is not downloaded if it's already installed --- src/utils.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index a6be21d..c5bf05e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -65,9 +65,8 @@ function update() { } } - console.log("Downloading..."); + console.log("Checking for updates..."); const version = getNorthstarInstalledVersion(); - console.log(version); request({ json: true, @@ -75,7 +74,14 @@ function update() { url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest", }, (error, response, body) => { const tag = body['tag_name']; - console.log(tag); + + console.log('current version:', version); + console.log('remote version:', tag); + + if (version === tag) { + console.log('Latest version is already installed, skipping update.'); + return; + } https.get(body.assets[0].browser_download_url, (res) => { let stream = fs.createWriteStream(settings.zip); -- cgit v1.2.3 From 68e268303778e7b6d01ff37c4996b3b1c2ea7ead Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 23:15:07 +0100 Subject: [refactor] using snake_case for settings.northstar_version property --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index c5bf05e..13894a8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -17,7 +17,7 @@ process.chdir(app.getPath("appData")); var settings = { gamepath: "", zip: "/northstar.zip", - northstarVersion: "unknown", + northstar_version: "unknown", excludes: [ "ns_startup_args.txt", "ns_startup_args_dedi.txt" @@ -92,7 +92,7 @@ function update() { fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) .on("finish", () => { console.log("Installation/Update finished!"); - settings.northstarVersion = tag; + settings.northstar_version = tag; saveSettings(); events.emit("updated"); -- cgit v1.2.3 From 78888b8465f833a8dd8ba00d3c34b21ba8dd6cb4 Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 23:24:32 +0100 Subject: [refactor] renaming getInstalledVersion method --- src/utils.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 13894a8..66c8644 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,9 +52,10 @@ function saveSettings() { fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings})); } -function getNorthstarInstalledVersion() { - const configFilePath = app.getPath("appData") + "/viper.json"; - return JSON.parse(fs.readFileSync(configFilePath, "utf8"))['northstarVersion']; +function getInstalledVersion() { + return JSON.parse( + fs.readFileSync(app.getPath("appData") + "/viper.json", "utf8") + )['northstarVersion']; } function update() { @@ -66,7 +67,7 @@ function update() { } console.log("Checking for updates..."); - const version = getNorthstarInstalledVersion(); + const version = getInstalledVersion(); request({ json: true, -- cgit v1.2.3 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') 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 From a23f5200a0330b24a1f77a63755367148cd0763f Mon Sep 17 00:00:00 2001 From: Alystrasz Date: Tue, 28 Dec 2021 23:50:39 +0100 Subject: [fix] settings are saved after setpath call on Windows After game path was set on Windows in first launch, the settings object would not be written to viper.json file, meaning that on next start, settings.gamepath variable would be loaded with a "" value, leading to errors. --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index dde5515..270b57a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,7 +38,7 @@ function setpath(win) { dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => { settings.gamepath = res.filePaths[0]; settings.zip = path.join(settings.gamepath + "/northstar.zip"); - + saveSettings(); win.webContents.send("newpath", settings.gamepath); }).catch(err => {console.error(err)}) } -- cgit v1.2.3 From 5ff7e1a8123e18951aff4643993a5b6296c409af Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 28 Dec 2021 23:58:07 +0100 Subject: switched single quotes to double --- src/utils.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 270b57a..3bad620 100644 --- a/src/utils.js +++ b/src/utils.js @@ -52,17 +52,17 @@ function saveSettings() { } function getInstalledVersion() { - const versionFilePath = path.join(settings.gamepath, 'ns_version.txt'); + 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'; + fs.writeFileSync(versionFilePath, "unknown"); + return "unknown"; } } function updateInstalledVersion(newTag) { - fs.writeFileSync(path.join(settings.gamepath, 'ns_version.txt'), newTag); + fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), newTag); } function update() { @@ -81,13 +81,13 @@ function update() { headers: {"User-Agent": "Viper"}, url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest", }, (error, response, body) => { - const tag = body['tag_name']; + const tag = body["tag_name"]; - console.log('current version:', version); - console.log('remote version:', tag); + console.log("current version:", version); + console.log("remote version:", tag); if (version === tag) { - console.log('Latest version is already installed, skipping update.'); + console.log("Latest version is already installed, skipping update."); return; } -- cgit v1.2.3 From 9d5498708b1b7db82fae53b4c858de7e43f21c95 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 29 Dec 2021 00:00:27 +0100 Subject: removed updateInstalledVersion() I'm not quite sure what the purpose of this function is considering we only use it once, and there's not much reason to export it or anything. --- src/utils.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 3bad620..5ae535f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -61,9 +61,6 @@ function getInstalledVersion() { return "unknown"; } } -function updateInstalledVersion(newTag) { - fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), newTag); -} function update() { for (let i = 0; i < settings.excludes.length; i++) { @@ -81,7 +78,7 @@ function update() { headers: {"User-Agent": "Viper"}, url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest", }, (error, response, body) => { - const tag = body["tag_name"]; + var tag = body["tag_name"]; console.log("current version:", version); console.log("remote version:", tag); @@ -101,7 +98,7 @@ function update() { .on("finish", () => { console.log("Installation/Update finished!"); - updateInstalledVersion(tag); + fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), tag); events.emit("updated"); -- cgit v1.2.3 From 79672ab18d84bd7599205ebf0c39779a5f2b2888 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 29 Dec 2021 00:18:34 +0100 Subject: lil touch up on the log messages --- src/utils.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/utils.js b/src/utils.js index 5ae535f..f310ef8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -80,12 +80,13 @@ function update() { }, (error, response, body) => { var tag = body["tag_name"]; - console.log("current version:", version); - console.log("remote version:", tag); - if (version === tag) { - console.log("Latest version is already installed, skipping update."); + console.log(`Latest version (${version}) is already installed, skipping update.`); return; + } else { + if (version != "unknown") { + console.log("Current version:", version); + }; console.log("Downloading:", tag); } https.get(body.assets[0].browser_download_url, (res) => { -- cgit v1.2.3