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/utils.js | |
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/utils.js')
-rw-r--r-- | src/utils.js | 24 |
1 files changed, 21 insertions, 3 deletions
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; } } |