aboutsummaryrefslogtreecommitdiff
path: root/src/app/main.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2021-12-25 22:24:08 +0100
committer0neGal <mail@0negal.com>2021-12-25 22:24:08 +0100
commit37679dc22b90eaf2a0f7153d9133f8aedf66d35c (patch)
tree7be14b05fcda44e3e23e5b14b73856a3b6cbcd70 /src/app/main.js
parent59bd6890cc825592f6070b24681f8314624cc21f (diff)
downloadViper-37679dc22b90eaf2a0f7153d9133f8aedf66d35c.tar.gz
Viper-37679dc22b90eaf2a0f7153d9133f8aedf66d35c.zip
basic updater/installer is now working
Diffstat (limited to 'src/app/main.js')
-rw-r--r--src/app/main.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/app/main.js b/src/app/main.js
new file mode 100644
index 0000000..b7071ec
--- /dev/null
+++ b/src/app/main.js
@@ -0,0 +1,38 @@
+const fs = require("fs");
+const path = require("path");
+const unzip = require("unzipper");
+const request = require("request");
+const { dialog } = require("electron");
+const { https } = require("follow-redirects");
+
+var settings = {
+ gamepath: "",
+ file: "viper.json",
+ zip: "/northstar.zip",
+}
+
+if (fs.existsSync(settings.file)) {
+ settings.gamepath = JSON.parse(fs.readFileSync(settings.file, "utf8")).path;
+ settings.zip = path.join(settings.gamepath + "/northstar.zip");
+}
+
+function update() {
+ request({
+ json: true,
+ headers: {"User-Agent": navigator.userAgent},
+ url: "https://api.github.com/repos/R2Northstar/Northstar/releases/latest",
+ }, (error, response, body) => {
+ https.get(body.assets[0].browser_download_url, (res) => {
+ let stream = fs.createWriteStream(settings.zip);
+ res.pipe(stream);
+ stream.on("finish",() => {
+ stream.close();
+ console.log("download done");
+ fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath}))
+ .on("finish", () => {
+ alert("Installation finished!")
+ });
+ })
+ })
+ })
+}