From 547cd10bb77be6aee0eb781fd9de44c934772909 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 2 May 2022 23:47:47 +0200 Subject: 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. --- package-lock.json | 14 +++++++++++ package.json | 1 + src/utils.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index b84a0cd..22788c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "follow-redirects": "^1.14.8", "fs-extra": "^10.0.0", "fuse.js": "^6.5.3", + "jsonrepair": "^2.2.1", "marked": "^4.0.10", "marked-man": "^0.7.0", "recursive-copy": "^2.0.13", @@ -1834,6 +1835,14 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsonrepair": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-2.2.1.tgz", + "integrity": "sha512-o9Je8TceILo872uQC9fIBJm957j1Io7z8Ca1iWIqY6S5S65HGE9XN7XEEw7+tUviB9Vq4sygV89MVTxl+rhZyg==", + "bin": { + "jsonrepair": "bin/cli.js" + } + }, "node_modules/junk": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/junk/-/junk-1.0.3.tgz", @@ -4521,6 +4530,11 @@ "universalify": "^2.0.0" } }, + "jsonrepair": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-2.2.1.tgz", + "integrity": "sha512-o9Je8TceILo872uQC9fIBJm957j1Io7z8Ca1iWIqY6S5S65HGE9XN7XEEw7+tUviB9Vq4sygV89MVTxl+rhZyg==" + }, "junk": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/junk/-/junk-1.0.3.tgz", diff --git a/package.json b/package.json index 3c3999a..6ebf10c 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "follow-redirects": "^1.14.8", "fs-extra": "^10.0.0", "fuse.js": "^6.5.3", + "jsonrepair": "^2.2.1", "marked": "^4.0.10", "marked-man": "^0.7.0", "recursive-copy": "^2.0.13", 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"); -- cgit v1.2.3