aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGitExample <git@example.com>2022-02-03 01:09:37 +0100
committerGitExample <git@example.com>2022-02-03 01:09:37 +0100
commitd3228ae7fad117a8313731107f572ba4879569b6 (patch)
treece67a33514eccb055580f15d3b7162c5261efed3 /src
parent396c1f3c9499a2bb50b2b5f3760cc58acfe9b87f (diff)
downloadViper-d3228ae7fad117a8313731107f572ba4879569b6.tar.gz
Viper-d3228ae7fad117a8313731107f572ba4879569b6.zip
ability to download from browser
This should work for all mods, assuming that all mods come packages the same, aka, in a Zip, with mods/<mod> in it. Which from what I know they do.
Diffstat (limited to 'src')
-rw-r--r--src/app/browser.js4
-rw-r--r--src/app/main.js5
-rw-r--r--src/index.js1
-rw-r--r--src/utils.js55
4 files changed, 63 insertions, 2 deletions
diff --git a/src/app/browser.js b/src/app/browser.js
index eb18fe5..73eb6f7 100644
--- a/src/app/browser.js
+++ b/src/app/browser.js
@@ -25,6 +25,7 @@ var Browser = {
title: pkg.name,
image: pkg.icon,
author: pkg.owner,
+ download: pkg.download_url,
description: pkg.description
})
}
@@ -62,8 +63,7 @@ function BrowserEl(properties) {
<div class="text">
<div class="title">${properties.title}</div>
<div class="description">${properties.description} - ${lang("gui.browser.madeby")} ${properties.author}</div>
- <button>Install</button>
- <button>Info</button>
+ <button onclick="installFromURL('${properties.download}')">Install</button>
</div>
</div>
`
diff --git a/src/app/main.js b/src/app/main.js
index 5f0cc9a..b61b20a 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -153,6 +153,11 @@ function installmod() {
ipcRenderer.send("installmod")
}
+// Tells the main process to install a mod from a URL
+function installFromURL(url) {
+ ipcRenderer.send("installfromurl", url)
+}
+
// Frontend part of settings a new game path
ipcRenderer.on("newpath", (event, newpath) => {
settings.gamepath = newpath;
diff --git a/src/index.js b/src/index.js
index 3f50840..4849b72 100644
--- a/src/index.js
+++ b/src/index.js
@@ -47,6 +47,7 @@ function start() {
ipcMain.on("winAlert", (event, ...args) => {win.webContents.send("alert", ...args)});
ipcMain.on("ns-update-event", (event) => win.webContents.send("ns-update-event", event));
ipcMain.on("guigetmods", (event, ...args) => {win.webContents.send("mods", utils.mods.list())});
+ ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)})
win.webContents.on("dom-ready", () => {
win.webContents.send("mods", utils.mods.list());
diff --git a/src/utils.js b/src/utils.js
index 50ffed0..d1cc345 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -440,6 +440,7 @@ const mods = {
if (fs.statSync(mod).isDirectory()) {
winLog(lang("gui.mods.installing"))
+ files = fs.readdirSync(mod);
if (fs.existsSync(path.join(mod, "mod.json")) &&
fs.statSync(path.join(mod, "mod.json")).isFile()) {
@@ -458,6 +459,7 @@ const mods = {
if (fs.existsSync(path.join(mod, files[i], "mod.json")) &&
fs.statSync(path.join(mod, files[i], "mod.json")).isFile()) {
+ console.log(mods.install(path.join(mod, files[i])))
if (mods.install(path.join(mod, files[i]))) {return true};
}
}
@@ -479,6 +481,20 @@ const mods = {
try {
fs.createReadStream(mod).pipe(unzip.Extract({path: cache}))
.on("finish", () => {
+ if (fs.existsSync(path.join(cache, "manifest.json"))) {
+ files = fs.readdirSync(path.join(cache, "mods"));
+
+ for (let i = 0; i < files.length; i++) {
+ let mod = path.join(cache, "mods", files[i]);
+ if (fs.statSync(mod).isDirectory()) {
+ setTimeout(() => {
+ if (mods.install(mod)) {return true};
+ }, 1000)
+ }
+ }
+ return notamod();
+ }
+
if (mods.install(cache)) {
installed();
} else {return notamod()}
@@ -486,6 +502,45 @@ const mods = {
}catch(err) {return notamod()}
}
},
+
+ // Installs mods from URL's
+ //
+ // This'll simply download the file that the URL points to and then
+ // install it with mods.install()
+ installFromURL: (url) => {
+ https.get(url, (res) => {
+ let tmp = path.join(app.getPath("cache"), "vipertmp");
+ let modlocation = path.join(tmp, "/mod.zip");
+
+ if (fs.existsSync(tmp)) {
+ if (! fs.statSync(tmp).isDirectory()) {
+ fs.rmSync(tmp)
+ }
+ } else {
+ fs.mkdirSync(tmp)
+ if (fs.existsSync(modlocation)) {
+ fs.rmSync(modlocation)
+ }
+ }
+
+ let stream = fs.createWriteStream(modlocation);
+ res.pipe(stream);
+
+ // let received = 0;
+ // // Progress messages, we should probably switch this to
+ // // percentage instead of how much is downloaded.
+ // res.on("data", (chunk) => {
+ // received += chunk.length;
+ // ipcMain.emit("ns-update-event", lang("gui.update.downloading") + " " + (received / 1024 / 1024).toFixed(1) + "mb");
+ // })
+
+ stream.on("finish", () => {
+ stream.close();
+ mods.install(modlocation)
+ })
+ })
+ },
+
// Removes mods
//
// Takes in the names of the mod then removes it, no confirmation,