aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/main.js29
-rw-r--r--src/index.js11
-rw-r--r--src/utils.js59
3 files changed, 65 insertions, 34 deletions
diff --git a/src/app/main.js b/src/app/main.js
index 352e654..8d174c1 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -1,9 +1,6 @@
const fs = require("fs");
const path = require("path");
-const unzip = require("unzipper");
-const request = require("request");
const { ipcRenderer } = require("electron");
-const { https } = require("follow-redirects");
var settings = {
gamepath: "",
@@ -19,30 +16,8 @@ if (fs.existsSync(settings.file)) {
setpath();
}
-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!")
- });
- })
- })
- })
-}
-
-function setpath() {
- ipcRenderer.send("setpath");
-}
+function update() {ipcRenderer.send("update")}
+function setpath() {ipcRenderer.send("setpath")}
ipcRenderer.on("newpath", (event, newpath) => {
settings.gamepath = newpath;
diff --git a/src/index.js b/src/index.js
index 0babcea..5586633 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,6 +2,8 @@ const fs = require("fs");
const path = require("path");
const { app, dialog, ipcMain, BrowserWindow } = require("electron");
+const utils = require("./utils")
+
function start() {
win = new BrowserWindow({
width: 500,
@@ -18,13 +20,8 @@ function start() {
win.loadFile(__dirname + "/app/index.html");
win.webContents.once("dom-ready", () => {win.show()});
- ipcMain.on("setpath", (event) => {
- 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]);
- }).catch(err => {console.error(err)})
- })
+ ipcMain.on("update", (event) => {utils.update(win)})
+ ipcMain.on("setpath", (event) => {utils.setpath(win)})
}
app.on("ready", () => {
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,
+}