diff options
author | 0neGal <mail@0negal.com> | 2022-01-08 01:49:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-08 01:49:05 +0100 |
commit | 1702ef7c8db22a69320b04cc17af04113896cf7e (patch) | |
tree | d3773acfc9b5cbb8861a278cddd366ad95804e45 /src/utils.js | |
parent | a898d6866a912abceb78832bc1b3fe2ff56d1335 (diff) | |
parent | 31bd305d88409e70d3fabc41026fef572099163e (diff) | |
download | Viper-1702ef7c8db22a69320b04cc17af04113896cf7e.tar.gz Viper-1702ef7c8db22a69320b04cc17af04113896cf7e.zip |
Merge branch 'main' into mod-support
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/utils.js b/src/utils.js index fc62f01..9243546 100644 --- a/src/utils.js +++ b/src/utils.js @@ -8,9 +8,9 @@ const events = new Emitter(); const cli = require("./cli"); const lang = require("./lang"); +const requests = require("./requests"); const unzip = require("unzipper"); -const request = require("request"); const exec = require("child_process").spawn; const { https } = require("follow-redirects"); @@ -43,6 +43,11 @@ function setpath(win) { ipcMain.emit("newpath", null, false); return; } + if (! fs.existsSync(path.join(res.filePaths[0], "Titanfall2.exe"))) { + ipcMain.emit("wrongpath"); + return; + } + settings.gamepath = res.filePaths[0]; settings.zip = path.join(settings.gamepath + "/northstar.zip"); saveSettings(); @@ -51,7 +56,7 @@ function setpath(win) { }).catch(err => {console.error(err)}) } - fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify(settings)); + saveSettings(); cli.exit(); } @@ -70,7 +75,7 @@ function getNSVersion() { } } -function update() { +async function update() { for (let i = 0; i < settings.excludes.length; i++) { let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]); if (fs.existsSync(exclude)) { @@ -82,52 +87,47 @@ function update() { console.log(lang("cli.update.checking")); var version = getNSVersion(); - 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"]; + const latestAvailableVersion = await requests.getLatestNsVersion(); - if (version === tag) { - ipcMain.emit("ns-updated"); - console.log(lang("cli.update.uptodate"), version); + if (version === latestAvailableVersion) { + ipcMain.emit("ns-updated"); + console.log(lang("cli.update.uptodate"), version); - winLog(lang("gui.update.uptodate")); - return; - } else { - if (version != "unknown") { - console.log(lang("cli.update.current"), version); - }; console.log(lang("cli.update.downloading") + ":", tag); + winLog(lang("gui.update.uptodate")); + return; + } else { + if (version != "unknown") { + console.log(lang("cli.update.current"), version); + }; console.log(lang("cli.update.downloading") + ":", latestAvailableVersion); - winLog(lang("gui.update.downloading")); - } + winLog(lang("gui.update.downloading")); + } - https.get(body.assets[0].browser_download_url, (res) => { - let stream = fs.createWriteStream(settings.zip); - res.pipe(stream); - - let received = 0; - res.on("data", (chunk) => { - received += chunk.length; - winLog(lang("gui.update.downloading") + " " + (received / 1024 / 1024).toFixed(1) + "mb"); - }) - - stream.on("finish", () => { - stream.close(); - winLog(lang("gui.update.extracting")); - console.log(lang("cli.update.downloaddone")); - fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) - .on("finish", () => { - fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), tag); - ipcMain.emit("getversion"); + https.get(requests.getLatestNsVersionLink(), (res) => { + let stream = fs.createWriteStream(settings.zip); + res.pipe(stream); - for (let i = 0; i < settings.excludes.length; i++) { - let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]); - if (fs.existsSync(exclude + ".excluded")) { - fs.renameSync(exclude + ".excluded", exclude) - } + let received = 0; + res.on("data", (chunk) => { + received += chunk.length; + winLog(lang("gui.update.downloading") + " " + (received / 1024 / 1024).toFixed(1) + "mb"); + }) + + stream.on("finish", () => { + stream.close(); + winLog(lang("gui.update.extracting")); + console.log(lang("cli.update.downloaddone")); + fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath})) + .on("finish", () => { + fs.writeFileSync(path.join(settings.gamepath, "ns_version.txt"), latestAvailableVersion); + ipcMain.emit("getversion"); + + for (let i = 0; i < settings.excludes.length; i++) { + let exclude = path.join(settings.gamepath + "/" + settings.excludes[i]); + if (fs.existsSync(exclude + ".excluded")) { + fs.renameSync(exclude + ".excluded", exclude) } + } ipcMain.emit("guigetmods"); ipcMain.emit("ns-updated"); @@ -135,7 +135,7 @@ function update() { console.log(lang("cli.update.finished")); cli.exit(); }); - }) + }); }) }) } |