aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2021-12-29 00:40:07 +0100
committer0neGal <mail@0negal.com>2021-12-29 00:40:07 +0100
commit4add9f34f5d9cded91db553aa7a72c6898f7d98b (patch)
tree5b0eeb6c16d8d419e9dc680136918938cee3aff6
parentaefef2040280ae9e4292c39df65f2b378128aa07 (diff)
parent3d5ccdad4b95e4453ac1857324b2a89497870f09 (diff)
downloadViper-4add9f34f5d9cded91db553aa7a72c6898f7d98b.tar.gz
Viper-4add9f34f5d9cded91db553aa7a72c6898f7d98b.zip
Merge branch 'main' of 0neGal/viper into localization
-rw-r--r--src/utils.js37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/utils.js b/src/utils.js
index ec15554..ce927b8 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -38,15 +38,30 @@ 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)})
}
- fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({...settings}));
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings));
cli.exit();
}
+function saveSettings() {
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings));
+}
+
+function getInstalledVersion() {
+ 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 update() {
for (let i = 0; i < settings.excludes.length; i++) {
let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]);
@@ -55,12 +70,25 @@ function update() {
}
}
- console.log("Downloading...");
+ console.log("Checking for updates...");
+ const version = getInstalledVersion();
+
request({
json: true,
headers: {"User-Agent": "Viper"},
url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest",
}, (error, response, body) => {
+ var tag = body["tag_name"];
+
+ if (version === tag) {
+ 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) => {
let stream = fs.createWriteStream(settings.zip);
res.pipe(stream);
@@ -70,6 +98,9 @@ function update() {
fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath}))
.on("finish", () => {
console.log("Installation/Update finished!");
+
+ fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), tag);
+
events.emit("updated");
for (let i = 0; i < settings.excludes.length; i++) {