aboutsummaryrefslogtreecommitdiff
path: root/src/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.js')
-rw-r--r--src/utils.js34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/utils.js b/src/utils.js
index c38cbcc..000c911 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -2,6 +2,11 @@ const fs = require("fs");
const path = require("path");
const { app, dialog, ipcMain } = require("electron");
+const Emitter = require("events");
+const events = new Emitter();
+
+const cli = require("./cli");
+
const unzip = require("unzipper");
const request = require("request");
const { https } = require("follow-redirects");
@@ -17,22 +22,28 @@ var settings = {
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!");
+ 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]}))
+ if (! win) {
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({path: cli.param("setpath")}));
+ settings.gamepath = cli.param("setpath");
+ cli.exit();
+ } else {
+ 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)})
+ win.webContents.send("newpath", res.filePaths[0]);
+ settings.gamepath = res.filePaths[0];
+ }).catch(err => {console.error(err)})
+ }
}
function update() {
+ console.log("Downloading...");
request({
json: true,
headers: {"User-Agent": "Viper"},
@@ -41,12 +52,14 @@ function update() {
https.get(body.assets[0].browser_download_url, (res) => {
let stream = fs.createWriteStream(settings.zip);
res.pipe(stream);
- stream.on("finish",() => {
+ stream.on("finish", () => {
stream.close();
- console.log("Download done!");
+ console.log("Download done! Extracting...");
fs.createReadStream(settings.zip).pipe(unzip.Extract({path: settings.gamepath}))
.on("finish", () => {
- console.log("Installation finished!")
+ console.log("Installation/Update finished!");
+ events.emit("updated");
+ cli.exit();
});
})
})
@@ -56,4 +69,5 @@ function update() {
module.exports = {
update,
setpath,
+ settings,
}