diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app/index.html | 2 | ||||
-rw-r--r-- | src/app/main.js | 38 | ||||
-rw-r--r-- | src/index.js | 1 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/app/index.html b/src/app/index.html index c2bb777..97a14ab 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -8,7 +8,7 @@ <div class="line"> <div class="text">Welcome to Viper!</div> <div class="buttons"> - <button id="update">Update</button> + <button id="update" onclick="update()">Update</button> <button id="setpath">Game Path</button> </div> </div> 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!") + }); + }) + }) + }) +} diff --git a/src/index.js b/src/index.js index 50f2b6e..ebea48f 100644 --- a/src/index.js +++ b/src/index.js @@ -19,6 +19,7 @@ function start() { } app.on("ready", () => { + process.chdir(app.getPath("appData")); app.setPath("userData", path.join(app.getPath("cache"), app.name)); start(); }) |