From 18d1166b6b8beef422590607cd02d613dd02d2d0 Mon Sep 17 00:00:00 2001 From: 3top1a <57371001+3top1a@users.noreply.github.com> Date: Mon, 24 Jan 2022 14:27:29 +0100 Subject: Edge case in vdf reading (#56) * Edge case * Alert user only when automatic detection failed * extra info on not found message * support for [Free/Open]BSD Co-authored-by: 0neGal --- src/app/main.js | 1 - 1 file changed, 1 deletion(-) (limited to 'src/app/main.js') diff --git a/src/app/main.js b/src/app/main.js index 5f0cc9a..dab584e 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -32,7 +32,6 @@ if (fs.existsSync("viper.json")) { setpath(true); } } else { - alert(lang("general.missingpath")); setpath(); } -- cgit v1.2.3 From 9c6ac295189acab7303952725755dfac87e18470 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 24 Jan 2022 18:21:13 +0100 Subject: no alert when manually changing the game path When changing the game path by clicking the button you shouldn't be told it can't find the game and you've to select one manually, as you know that already. More importantly, if it could be found automatically it'll just not do anything. With this change I also changed the "gui.setpath" string to be more logical, and to make it clear what it does. --- src/app/main.js | 1 - src/index.js | 10 +++++++--- src/lang/en.json | 2 +- src/utils.js | 30 ++++++++++++++++-------------- 4 files changed, 24 insertions(+), 19 deletions(-) (limited to 'src/app/main.js') diff --git a/src/app/main.js b/src/app/main.js index dab584e..a3a1d04 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -26,7 +26,6 @@ if (fs.existsSync("viper.json")) { settings.zip = path.join(settings.gamepath + "/northstar.zip"); if (settings.gamepath.length === 0) { - alert(lang("general.missingpath")); setpath(false); } else { setpath(true); diff --git a/src/index.js b/src/index.js index f4207e7..c8bfc53 100644 --- a/src/index.js +++ b/src/index.js @@ -87,9 +87,13 @@ ipcMain.on("launchVanilla", (event) => {utils.launch("vanilla")}) ipcMain.on("update", (event) => {utils.update()}) ipcMain.on("setpathcli", (event) => {utils.setpath()}); ipcMain.on("setpath", (event, value) => { - if (!value) { - utils.setpath(win); - } else if (!win.isVisible()) { + if (! value) { + if (! win.isVisible()) { + utils.setpath(win); + } else { + utils.setpath(win, true); + } + } else if (! win.isVisible()) { win.show(); } }); diff --git a/src/lang/en.json b/src/lang/en.json index 8d4daeb..fe9b0b0 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -42,7 +42,7 @@ "gui.versions.northstar": "Northstar version", "gui.exit": "Exit", "gui.update": "Update", - "gui.setpath": "Game Path", + "gui.setpath": "Change Game Path", "gui.update.check": "Check for updates", "gui.mods": "Mods", diff --git a/src/utils.js b/src/utils.js index ef647fe..fb94b92 100644 --- a/src/utils.js +++ b/src/utils.js @@ -116,7 +116,7 @@ northstar_auto_updates: { // // If running with CLI it takes in the --setpath argument otherwise it // open the systems file browser for the user to select a path. -async function setpath(win) { +async function setpath(win, forcedialog) { function setGamepath(folder) { settings.gamepath = folder; settings.zip = path.join(settings.gamepath + "/northstar.zip"); @@ -128,21 +128,23 @@ async function setpath(win) { if (! win) { // CLI setGamepath(cli.param("setpath")); } else { // GUI - function setGamepath(folder) { - settings.gamepath = folder; - settings.zip = path.join(settings.gamepath + "/northstar.zip"); - saveSettings(); - win.webContents.send("newpath", settings.gamepath); - ipcMain.emit("newpath", null, settings.gamepath); - } + if (! forcedialog) { + function setGamepath(folder, forcedialog) { + settings.gamepath = folder; + settings.zip = path.join(settings.gamepath + "/northstar.zip"); + saveSettings(); + win.webContents.send("newpath", settings.gamepath); + ipcMain.emit("newpath", null, settings.gamepath); + } - let gamepath = await findgame(); - if (gamepath) { - setGamepath(gamepath); - return; - } + let gamepath = await findgame(); + if (gamepath) { + setGamepath(gamepath); + return; + } - alert(lang("general.missingpath")); + winAlert(lang("general.missingpath")); + } // Fallback to manual selection dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => { -- cgit v1.2.3 From 6a08872d134f3afa3f81b92fabe51bdbd91f375d Mon Sep 17 00:00:00 2001 From: 0neGal Date: Wed, 26 Jan 2022 00:20:25 +0100 Subject: fixed mods not updating after changing path This also fixes mods not showing up after first install of NS --- src/app/main.js | 3 +++ src/utils.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/app/main.js') diff --git a/src/app/main.js b/src/app/main.js index a3a1d04..19f6c9e 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -154,6 +154,7 @@ function installmod() { // Frontend part of settings a new game path ipcRenderer.on("newpath", (event, newpath) => { settings.gamepath = newpath; + ipcRenderer.send("guigetmods"); }) // Continuation of log() @@ -162,6 +163,8 @@ ipcRenderer.on("alert", (event, msg) => {alert(msg)}) // Updates the installed mods ipcRenderer.on("mods", (event, mods) => { + if (! mods) {return} + modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`; modsdiv.innerHTML = ""; diff --git a/src/utils.js b/src/utils.js index fb94b92..0507921 100644 --- a/src/utils.js +++ b/src/utils.js @@ -339,7 +339,6 @@ function winAlert(msg) { // // We can both get list of disabled mods, remove/install/toggle mods and // other things akin to that, all kinds of mod related stuff -let modpath = path.join(settings.gamepath, "R2Northstar/mods"); const mods = { // Returns a list of mods // @@ -347,6 +346,8 @@ const mods = { // combination of the other two, enabled being enabled mods, and you // guessed it, disabled being disabled mods. list: () => { + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) console.log("error: " + lang("general.notinstalled")) @@ -413,6 +414,8 @@ const mods = { // the absolute basics will be provided and we can't know the // version or similar. get: (mod) => { + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) console.log("error: " + lang("general.notinstalled")) @@ -437,6 +440,8 @@ const mods = { // inside the zip or folder to see if buried in another folder or // not, as sometimes that's the case. install: (mod) => { + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) console.log("error: " + lang("general.notinstalled")) @@ -515,6 +520,8 @@ const mods = { // Takes in the names of the mod then removes it, no confirmation, // that'd be up to the GUI. remove: (mod) => { + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) console.log("error: " + lang("general.notinstalled")) @@ -565,6 +572,8 @@ const mods = { // you checked for if a mod is already disable and if not run the // function. However we currently have no need for that. toggle: (mod, fork) => { + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); + if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) console.log("error: " + lang("general.notinstalled")) -- cgit v1.2.3 From d3228ae7fad117a8313731107f572ba4879569b6 Mon Sep 17 00:00:00 2001 From: GitExample Date: Thu, 3 Feb 2022 01:09:37 +0100 Subject: 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/ in it. Which from what I know they do. --- src/app/browser.js | 4 ++-- src/app/main.js | 5 +++++ src/index.js | 1 + src/utils.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) (limited to 'src/app/main.js') 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) {
${properties.title}
${properties.description} - ${lang("gui.browser.madeby")} ${properties.author}
- - +
` 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, -- cgit v1.2.3 From a4b11903979fdb4c8b0f6dda8f7343e14c1ebe17 Mon Sep 17 00:00:00 2001 From: GitExample Date: Thu, 3 Feb 2022 01:36:11 +0100 Subject: detection of installed mods, disabling buttons When a new mod has been installed through the browser UI it's button is changed from "Install" to "Re-Install" instantly. We also now disable modding related buttons when updating NS, or when installing mods. This should prevent issues. --- src/app/browser.js | 34 ++++++++++++++++++++++++++++++++-- src/app/main.js | 11 +++++++++++ src/index.js | 3 ++- src/utils.js | 5 ++++- 4 files changed, 49 insertions(+), 4 deletions(-) (limited to 'src/app/main.js') diff --git a/src/app/browser.js b/src/app/browser.js index 73eb6f7..f152a6a 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -55,16 +55,46 @@ function BrowserEl(properties) { browserEntries.innerHTML = ""; } + let installstring = "Install"; + if (normalize(modsdiv.innerText.split("\n")).includes(normalize(properties.title))) { + installstring = "Re-Install"; + } + browserEntries.innerHTML += ` -
+
${properties.title}
${properties.description} - ${lang("gui.browser.madeby")} ${properties.author}
- +
` } + +ipcRenderer.on("installedmod", (event, modname) => { + setButtons(true); + modname = normalize(modname); + + if (document.getElementById(modname)) { + document.getElementById(modname).querySelector(".text button").innerHTML = "Re-Install"; + } +}) + +function normalize(items) { + let main = (string) => { + return string.replaceAll(" ", "").replaceAll(".", "").toLowerCase() + } + if (typeof items == "string") { + return main(items) + } else { + let newArray = []; + for (let i = 0; i < items.length; i++) { + newArray.push(main(items[i])); + } + + return newArray; + } +} diff --git a/src/app/main.js b/src/app/main.js index b61b20a..fa7cea8 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -68,6 +68,15 @@ function log(msg) { // updating/installing Northstar. function setButtons(state) { playNsBtn.disabled = !state; + + let disablearray = (array) => { + for (let i = 0; i < array.length; i++) { + array[i].disabled = !state; + } + } + + disablearray(document.querySelectorAll("#nsMods .buttons.modbtns button")) + disablearray(document.querySelectorAll("#browser #browserEntries .text button")) } // Frontend part of updating Northstar @@ -150,11 +159,13 @@ function selected(all) { // Tells the main process to install a mod function installmod() { + setButtons(false); ipcRenderer.send("installmod") } // Tells the main process to install a mod from a URL function installFromURL(url) { + setButtons(false); ipcRenderer.send("installfromurl", url) } diff --git a/src/index.js b/src/index.js index 4849b72..a847020 100644 --- a/src/index.js +++ b/src/index.js @@ -43,11 +43,12 @@ function start() { ipcMain.on("exit", () => {process.exit(0)}) ipcMain.on("minimize", () => {win.minimize()}) + ipcMain.on("installfromurl", (event, url) => {utils.mods.installFromURL(url)}) ipcMain.on("winLog", (event, ...args) => {win.webContents.send("log", ...args)}); 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)}) + ipcMain.on("installedmod", (event, modname) => {console.log(modname);win.webContents.send("installedmod", modname)}) win.webContents.on("dom-ready", () => { win.webContents.send("mods", utils.mods.list()); diff --git a/src/utils.js b/src/utils.js index d1cc345..b54808d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -444,12 +444,15 @@ const mods = { if (fs.existsSync(path.join(mod, "mod.json")) && fs.statSync(path.join(mod, "mod.json")).isFile()) { - copy.sync(mod, path.join(modpath, mod.replace(/^.*(\\|\/|\:)/, "")), { + let modname = mod.replace(/^.*(\\|\/|\:)/, ""); + copy.sync(mod, path.join(modpath, modname), { mode: true, cover: true, utimes: true, }); + ipcMain.emit("installedmod", "", modname); + return installed(); } else { files = fs.readdirSync(mod); -- cgit v1.2.3 From 5884b9a8e91ed8b2c5cfea90afa2709697b05afb Mon Sep 17 00:00:00 2001 From: GitExample Date: Thu, 3 Feb 2022 23:03:33 +0100 Subject: detection for new updates of mods --- src/app/browser.js | 9 +++++++++ src/app/main.js | 2 ++ src/lang/en.json | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/app/main.js') diff --git a/src/app/browser.js b/src/app/browser.js index b387a6a..dda0441 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -95,8 +95,17 @@ function BrowserEl(properties) { } let installstr = lang("gui.browser.install"); + if (normalize(modsdiv.innerText.split("\n")).includes(normalize(properties.title))) { installstr = lang("gui.browser.reinstall"); + + for (let i = 0; i < modsobj.all.length; i++) { + if (normalize(modsobj.all[i].Name) == normalize(properties.title) + && "v" + modsobj.all[i].Version != properties.version) { + + installstr = lang("gui.browser.update"); + } + } } browserEntries.innerHTML += ` diff --git a/src/app/main.js b/src/app/main.js index fa7cea8..08c70c1 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -3,6 +3,7 @@ const path = require("path"); const { ipcRenderer, shell } = require("electron"); const lang = require("../lang"); +var modsobj = {}; let shouldInstallNorthstar = false; // Base settings @@ -180,6 +181,7 @@ ipcRenderer.on("alert", (event, msg) => {alert(msg)}) // Updates the installed mods ipcRenderer.on("mods", (event, mods) => { + modsobj = mods; modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`; modsdiv.innerHTML = ""; diff --git a/src/lang/en.json b/src/lang/en.json index 47bfacb..59af04b 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -63,10 +63,11 @@ "gui.mods.installing": "Installing mod...", "gui.mods.installedmod": "Installed mod!", - "gui.browser.loading": "Loading mods...", "gui.browser.madeby": "by", + "gui.browser.update": "Update", "gui.browser.install": "Install", "gui.browser.reinstall": "Re-Install", + "gui.browser.loading": "Loading mods...", "gui.update.downloading": "Downloading...", "gui.update.extracting": "Extracting update...", -- cgit v1.2.3