diff options
-rw-r--r-- | src/utils.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js index 77e8fc7..ee101de 100644 --- a/src/utils.js +++ b/src/utils.js @@ -511,6 +511,56 @@ const mods = { return false; }, + + // 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 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] + } + } + }; + }, // Installs mods from a file path // @@ -797,6 +847,7 @@ const mods = { } }; +console.log(mods.modfile().get()) setInterval(() => { if (gamepathExists()) { ipcMain.emit("guigetmods"); |