aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js
index 1448007..a0c88ef 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -453,6 +453,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
//
@@ -735,6 +785,7 @@ const mods = {
}
};
+console.log(mods.modfile().get())
setInterval(() => {
ipcMain.emit("guigetmods");
}, 1500)