From 962265ffbe3aa0a9c2084d370c914c0265ee6bd9 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 17 Jan 2022 00:16:15 +0100 Subject: initial commit for implementing enabledmods.json All the basic stuff is here, I just need to actually hook it up into the old utils calls/I need to change them to the new ones. The latter will likely be the one I'm doing. --- src/utils.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/utils.js b/src/utils.js index e6fa5b0..bdfa7f3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -337,6 +337,51 @@ const mods = { return false; }, + modfile: () => { + let file = path.join(modpath, "..", "enabledmods.json"); + + if (! fs.existsSync(modpath)) { + fs.mkdirSync(path.join(modpath), {recursive: true}) + } + + if (! fs.existsSync(file)) { + fs.writeFileSync(file, "{}") + } + + return { + gen: () => { + let names = {}; + let list = mods.list().all; + for (let i = 0; i < list.length; i++) { + names[list[i].Name] = true + } + + fs.writeFileSync(file, JSON.stringify(names)) + }, + toggle: (mod) => { + let data = require(file); + data[mod] = !data[mod]; + console.log(data) + }, + get: () => { + let enabled = []; + let disabled = []; + let data = require(file); + + for (let i in data) { + if (data[i]) { + enabled.push(data[i]) + } else {disabled.push(data[i])} + } + + return { + enabled: enabled, + disabled: disabled, + all: [...enabled, ...disabled] + } + } + }; + }, install: (mod) => { if (getNSVersion() == "unknown") { winLog(lang("general.notinstalled")) @@ -502,6 +547,8 @@ const mods = { } }; +console.log(mods.modfile().get()) + module.exports = { mods, lang, -- cgit v1.2.3 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 From 32b033d6dac63cb6cf783394d20459dd44b9459a Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 3 May 2022 00:03:05 +0200 Subject: modfile. enable(), disable() and toggle() now work --- src/utils.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index d1b1ebb..971ecd9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -539,10 +539,20 @@ const mods = { fs.writeFileSync(file, JSON.stringify(names)) }, + disable: (mod) => { + let data = require(file); + data[mod] = false; + fs.writeFileSync(file, JSON.stringify(data)); + }, + enable: (mod) => { + let data = require(file); + data[mod] = true; + fs.writeFileSync(file, JSON.stringify(data)); + }, toggle: (mod) => { let data = require(file); - data[mod] = !data[mod]; - console.log(data) + data[mod] = ! data[mod]; + fs.writeFileSync(file, JSON.stringify(data)); }, get: () => { let enabled = []; @@ -901,8 +911,7 @@ const mods = { } }; -mods.modfile().gen(); -console.log(mods.modfile().toggle("EladNLG.HUDRevamp")) +console.log(mods.list()) setInterval(() => { if (gamepathExists()) { ipcMain.emit("guigetmods"); -- cgit v1.2.3 From e5fa26a944f8a4d025ce9fcc2aa1ec8fbf26874b Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 3 May 2022 00:20:05 +0200 Subject: simplified get() and made list() used get() Instead of repeating code and everything, get() now only returns a boolean, based on the arg inputted into get(mod), it returns true if the mod is enabled and false if disabled. If the mod isn't found inside the enabledmods.json it is assumed that it's enabled, as Northstar doesn't update this unless you actually disable the mod first, and the mod won't be found in there. Then I used get() to simplify list() a whole lot, and adding that functionality of using the manifest for a version number if one couldn't be found in the mod.json. --- src/utils.js | 132 +++++++++++++++-------------------------------------------- 1 file changed, 33 insertions(+), 99 deletions(-) diff --git a/src/utils.js b/src/utils.js index 971ecd9..eb833d3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -424,7 +424,7 @@ const mods = { return false; } - let mods = []; + let enabled = []; let disabled = []; if (! fs.existsSync(modpath)) { @@ -439,50 +439,41 @@ const mods = { files = fs.readdirSync(modpath) files.forEach((file) => { if (fs.statSync(path.join(modpath, file)).isDirectory()) { - if (fs.existsSync(path.join(modpath, file, "mod.json"))) { - try { - mods.push({...require(path.join(modpath, file, "mod.json")), FolderName: file, Disabled: false}) - }catch(err) { - if (cli.hasArgs()) {console.log("error: " + lang("cli.mods.improperjson"), file)} - mods.push({Name: file, FolderName: file, Version: "unknown", Disabled: false}) - } + let modjson = path.join(modpath, file, "mod.json"); + if (fs.existsSync(modjson)) { + let mod = JSON.parse(repair(fs.readFileSync(modjson, "utf8"))); - let manifest = path.join(modpath, file, "manifest.json"); - if (fs.existsSync(manifest)) { - try {mods[mods.length - 1].ManifestName = require(manifest).name}catch(err){} - } - } - } - }) + let obj = { + Version: "unknown", + Name: "unknown", + FolderName: file, + ...mod} - let disabledPath = path.join(modpath, "disabled") - if (! fs.existsSync(disabledPath)) { - fs.mkdirSync(disabledPath) - } + obj.Disabled = ! mods.modfile().get(obj.Name); - files = fs.readdirSync(disabledPath) - files.forEach((file) => { - if (fs.statSync(path.join(disabledPath, file)).isDirectory()) { - if (fs.existsSync(path.join(disabledPath, file, "mod.json"))) { - try { - disabled.push({...require(path.join(disabledPath, file, "mod.json")), FolderName: file, Disabled: true}) - }catch(err) { - if (cli.hasArgs()) {console.log("error: " + lang("cli.mods.improperjson"), file)} - disabled.push({Name: file, FolderName: file, Version: "unknown", Disabled: true}) + let manifestfile = path.join(modpath, file, "manifest.json"); + if (fs.existsSync(manifestfile)) { + let manifest = JSON.parse(repair(fs.readFileSync(manifestfile, "utf8"))); + + obj.ManifestName = manifest.name; + if (obj.Version == "unknown") { + obj.Version = manifest.version_number; + } } - } - let manifest = path.join(modpath, file, "manifest.json"); - if (fs.existsSync(manifest)) { - try {mods[mods.length - 1].ManifestName = require(manifest).name}catch(err){} + if (obj.Disabled) { + disabled.push(obj); + } else { + enabled.push(obj); + } } } }) return { - enabled: mods, + enabled: enabled, disabled: disabled, - all: [...mods, ...disabled] + all: [...enabled, ...disabled] }; }, @@ -512,7 +503,7 @@ const mods = { return false; }, - + // Manages the enabledmods.json file // // It can both return info about the file, but also toggle mods in @@ -554,73 +545,16 @@ const mods = { data[mod] = ! data[mod]; fs.writeFileSync(file, JSON.stringify(data)); }, - get: () => { - let enabled = []; - let disabled = []; + get: (mod) => { 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} - } - - if (data[name]) { - enabled.push(obj); - } else {disabled.push(obj)} - } - - return { - enabled: enabled, - disabled: disabled, - all: [...enabled, ...disabled] + if (data[mod]) { + return true; + } else if (data[mod] === false) { + return false; + } else { + return true; } } }; -- cgit v1.2.3 From 0290e8e2f9e2e04c1958f61fbded32a21cd98043 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 3 May 2022 00:28:51 +0200 Subject: hopefully fully implement everything?? i think? Everything seems to be working just fine, and I can't find any problems, so I'll likely merge this soon. --- src/utils.js | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/utils.js b/src/utils.js index eb833d3..4afbb2b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -542,7 +542,12 @@ const mods = { }, toggle: (mod) => { let data = require(file); - data[mod] = ! data[mod]; + if (data[mod] != undefined) { + data[mod] = ! data[mod]; + } else { + data[mod] = false; + } + fs.writeFileSync(file, JSON.stringify(data)); }, get: (mod) => { @@ -796,8 +801,6 @@ 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")) @@ -816,27 +819,7 @@ const mods = { return } - let disabled = path.join(modpath, "disabled"); - if (! fs.existsSync(disabled)) { - fs.mkdirSync(disabled) - } - - let modName = mods.get(mod).FolderName; - if (! modName) { - console.log("error: " + lang("cli.mods.cantfind")) - cli.exit(1); - return; - } - - let modPath = path.join(modpath, modName); - let dest = path.join(disabled, modName); - - if (mods.get(mod).Disabled) { - modPath = path.join(disabled, modName); - dest = path.join(modpath, modName); - } - - fs.moveSync(modPath, dest) + mods.modfile().toggle(mod); if (! fork) { console.log(lang("cli.mods.toggled")); cli.exit(); @@ -845,7 +828,6 @@ const mods = { } }; -console.log(mods.list()) setInterval(() => { if (gamepathExists()) { ipcMain.emit("guigetmods"); -- cgit v1.2.3 From ec85ca36735cbebe81e0f9e2bbd4006572e25d46 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Tue, 3 May 2022 02:25:51 +0200 Subject: changed "Overview" link to "FAQ" link The GitHub projects page is never updated, and it never will be, so I've removed it's link and replaced it with something useful. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b049f29..254f483 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@



- Overview | + FAQ | Releases

-- cgit v1.2.3