diff options
author | 0neGal <mail@0negal.com> | 2022-05-02 23:47:47 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-05-02 23:47:47 +0200 |
commit | 547cd10bb77be6aee0eb781fd9de44c934772909 (patch) | |
tree | 56eb101fecc55f4cde477abf27ff007d8ec6a6cb /src/utils.js | |
parent | c40e331bdc4b2375d3802a515c9b7a032118dea7 (diff) | |
download | Viper-547cd10bb77be6aee0eb781fd9de44c934772909.tar.gz Viper-547cd10bb77be6aee0eb781fd9de44c934772909.zip |
mods.modfile().get() is identical to mods.list()
Albeit mods.list() doesn't actually search the manifest file for a
version number, and I'll implement that later.
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/src/utils.js b/src/utils.js index ee101de..d1b1ebb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -12,6 +12,7 @@ const requests = require("./extras/requests"); const findgame = require("./extras/findgame"); const unzip = require("unzipper"); +const repair = require("jsonrepair"); const run = require("child_process").spawn; const exec = require("child_process").exec; const { https } = require("follow-redirects"); @@ -512,11 +513,12 @@ const mods = { return false; }, - // Manages the enabledmods.json file - // + // Manages the enabledmods.json file + // // It can both return info about the file, but also toggle mods in // it, generate the file itself, and so on. modfile: () => { + let modpath = path.join(settings.gamepath, "R2Northstar/mods"); let file = path.join(modpath, "..", "enabledmods.json"); if (! fs.existsSync(modpath)) { @@ -546,11 +548,63 @@ const mods = { let enabled = []; let disabled = []; let data = require(file); + let names = Object.keys(data); + + for (let i = 0; i < names.length; i++) { + let manifest; + let name = names[i]; + let folder = "unknown"; + let version = "unknown"; + + if (fs.existsSync(path.join(modpath, name))) { + folder = name; + } else { + let files = fs.readdirSync(modpath); + for (let ii = 0; ii < files.length; ii++) { + let mod = path.join(modpath, files[ii], "mod.json"); + if (fs.existsSync(mod)) { + mod = JSON.parse(repair(fs.readFileSync(mod, "utf8"))); + + version = mod.Version; + if (mod.Name == name) { + folder = files[ii]; + break + } + } + + } + } + + let manifestfile = path.join(modpath, folder, "manifest.json"); + if (fs.existsSync(manifestfile)) { + manifest = JSON.parse(repair(fs.readFileSync(manifestfile, "utf8"))); + + if (version == "unknown" || version == "") { + if (manifest != false) { + console.log(name) + version = manifest.version_number; + console.log(version + name) + } + } + } + + if (folder == "unknown") {continue} + console.log(manifest) + + let obj = { + Name: name, + Version: version, + FolderName: folder, + Disabled: data[name] + } + + if (manifest) { + obj = {...obj, ManifestName: manifest.name} + } - for (let i in data) { - if (data[i]) { - enabled.push(data[i]) - } else {disabled.push(data[i])} + if (data[name]) { + enabled.push(obj); + } else {disabled.push(obj)} } return { @@ -847,7 +901,8 @@ const mods = { } }; -console.log(mods.modfile().get()) +mods.modfile().gen(); +console.log(mods.modfile().toggle("EladNLG.HUDRevamp")) setInterval(() => { if (gamepathExists()) { ipcMain.emit("guigetmods"); |