diff options
author | 0neGal <mail@0negal.com> | 2022-01-03 01:20:50 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-01-03 01:20:50 +0100 |
commit | 42e6f3b358bf4d569a0849f3d5c99bb58bf432ba (patch) | |
tree | f4495accf8e57b904dd8e4c0afca3da409f22be9 /src | |
parent | c356beee2be1840aa257cb335272026d846f02d1 (diff) | |
download | Viper-42e6f3b358bf4d569a0849f3d5c99bb58bf432ba.tar.gz Viper-42e6f3b358bf4d569a0849f3d5c99bb58bf432ba.zip |
installing mods from folders got a lil easier
If a mod decided to put their actual mod files inside a folder inside a
folder it'll search sub folders to try and find them and usually it's
able to install it.
Meaning, if instead of the mod being structured as such:
mod/
mod.json
other files ...
It is structured as such:
folder/
mod/
mod.json
other files ...
This will be very useful for zip files... As some people tend to archive
a folder and not make an archive with the files in it. Leading to the
above structure...
Diffstat (limited to 'src')
-rw-r--r-- | src/app/main.js | 2 | ||||
-rw-r--r-- | src/index.js | 1 | ||||
-rw-r--r-- | src/utils.js | 24 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/app/main.js b/src/app/main.js index 897c82c..8db6561 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -104,9 +104,9 @@ ipcRenderer.on("newpath", (event, newpath) => { }) ipcRenderer.on("log", (event, msg) => {log(msg)}) +ipcRenderer.on("alert", (event, msg) => {alert(msg)}) ipcRenderer.on("mods", (event, mods) => { - console.log("refreshed mods") modcount.innerHTML = `${lang("gui.mods.count")} ${mods.all.length}`; modsdiv.innerHTML = ""; diff --git a/src/index.js b/src/index.js index 7ef9321..45400a5 100644 --- a/src/index.js +++ b/src/index.js @@ -42,6 +42,7 @@ function start() { ipcMain.on("ns-updated", () => {win.webContents.send("ns-updated")}) ipcMain.on("ns-updating", () => {win.webContents.send("ns-updating")}) ipcMain.on("winLog", (event, ...args) => {win.webContents.send("log", ...args)}) + ipcMain.on("winAlert", (event, ...args) => {win.webContents.send("alert", ...args)}) ipcMain.on("guigetmods", (event, ...args) => {win.webContents.send("mods", utils.mods.list())}) win.webContents.once("dom-ready", () => { diff --git a/src/utils.js b/src/utils.js index ef8b586..a34f91f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -166,6 +166,10 @@ function winLog(msg) { ipcMain.emit("winLog", msg, msg); } +function winAlert(msg) { + ipcMain.emit("winAlert", msg, msg); +} + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); const mods = { list: () => { @@ -220,7 +224,9 @@ const mods = { }, install: (mod) => { if (fs.statSync(mod).isDirectory()) { - if (fs.statSync(path.join(mod, "mod.json"))) { + if (fs.existsSync(path.join(mod, "mod.json")) && + fs.statSync(path.join(mod, "mod.json")).isFile()) { + copy.sync(mod, path.join(modpath, mod.replace(/^.*(\\|\/|\:)/, "")), { mode: true, cover: true, @@ -228,11 +234,23 @@ const mods = { }); cli.exit(); ipcMain.emit("guigetmods"); - return + return true; } else { + files = fs.readdirSync(mod); + + for (let i = 0; i < files.length; i++) { + if (fs.statSync(path.join(mod, files[i])).isDirectory()) { + if (fs.existsSync(path.join(mod, files[i], "mod.json")) && + fs.statSync(path.join(mod, files[i], "mod.json")).isFile()) { + + if (mods.install(path.join(mod, files[i]))) {return}; + } + } + } + winAlert(lang("cli.mods.notamod")) console.log("error: " + lang("cli.mods.notamod")) cli.exit(1); - return; + return false; } } |