aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2021-12-26 19:28:45 +0100
committer0neGal <mail@0negal.com>2021-12-26 19:28:45 +0100
commitdf7b714d27e5d23a6ac3e381e6684856bc818d1c (patch)
treed4afdcb0005ae1a4879c8594769df7a7524ef4b6 /src/utils.js
parente6a3c962330289e02276b0fafe4629598933e54e (diff)
downloadViper-df7b714d27e5d23a6ac3e381e6684856bc818d1c.tar.gz
Viper-df7b714d27e5d23a6ac3e381e6684856bc818d1c.zip
the renderer is no longer required for updating
Everything is now in utils.js and simply gets called through IPC calls which make it quite simple to add CLI arguments...
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js
new file mode 100644
index 0000000..c38cbcc
--- /dev/null
+++ b/src/utils.js
@@ -0,0 +1,59 @@
+const fs = require("fs");
+const path = require("path");
+const { app, dialog, ipcMain } = require("electron");
+
+const unzip = require("unzipper");
+const request = require("request");
+const { https } = require("follow-redirects");
+
+process.chdir(app.getPath("appData"));
+
+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");
+console.log(settings)
+} else {
+ console.log("Game path is not set! Please select the path!");
+}
+
+
+function setpath(win) {
+ dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({path: res.filePaths[0]}))
+
+ win.webContents.send("newpath", res.filePaths[0]);
+ settings.gamepath = res.filePaths[0];
+ }).catch(err => {console.error(err)})
+}
+
+function update() {
+ request({
+ json: true,
+ headers: {"User-Agent": "Viper"},
+ 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", () => {
+ console.log("Installation finished!")
+ });
+ })
+ })
+ })
+}
+
+module.exports = {
+ update,
+ setpath,
+}