diff --git a/build.gradle b/build.gradle index 26deefc..3ec87a6 100644 --- a/build.gradle +++ b/build.gradle @@ -178,7 +178,7 @@ publishing { artifact javadocJar groupId 'uk.co.innoxium.candor' artifactId 'candor-full' - version '0.1.5' + version '0.1.7' } } } @@ -204,8 +204,8 @@ bintray { licenses = ['MIT'] version { - name = '0.1.5' - desc = ' Initial Test Release For Candor' + name = '0.1.7' + desc = 'This release has the new ModStore, which enables better handling of mods' released = new Date() } } diff --git a/src/main/java/uk/co/innoxium/candor/mod/ModsHandler.java b/src/main/java/uk/co/innoxium/candor/mod/ModsHandler.java deleted file mode 100644 index 1adb42a..0000000 --- a/src/main/java/uk/co/innoxium/candor/mod/ModsHandler.java +++ /dev/null @@ -1,6 +0,0 @@ -package uk.co.innoxium.candor.mod; - -public class ModsHandler { - -// public static final ModList MODS = new ModList(); -} diff --git a/src/main/java/uk/co/innoxium/candor/mod/store/ModStore.java b/src/main/java/uk/co/innoxium/candor/mod/store/ModStore.java index be245ae..8e4d290 100644 --- a/src/main/java/uk/co/innoxium/candor/mod/store/ModStore.java +++ b/src/main/java/uk/co/innoxium/candor/mod/store/ModStore.java @@ -130,6 +130,38 @@ public static boolean removeModFile(Mod mod) throws IOException { return false; } + public static void updateModState(Mod mod, Mod.State state) { + + try { + + JsonObject contents = JsonUtil.getObjectFromPath(modStoreFile.toPath()); + JsonArray array = contents.get("mods").getAsJsonArray(); + JsonArray newArray = array.deepCopy(); + + for (int i = 0; i < array.size(); i++) { + + JsonObject obj = array.get(i).getAsJsonObject(); + if(mod.getName().equals(obj.get("name").getAsString())) { + + newArray.get(i).getAsJsonObject().remove("state"); + newArray.get(i).getAsJsonObject().addProperty("state", state.name()); + } + } + + contents.remove("mods"); + contents.add("mods", newArray); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + FileWriter writer = new FileWriter(modStoreFile); + gson.toJson(contents, writer); + + writer.close(); + } catch (IOException e) { + + e.printStackTrace(); + } + } + public static File getModStoreFolder() { return modStoreFolder; diff --git a/src/main/java/uk/co/innoxium/candor/thread/ThreadModInstaller.java b/src/main/java/uk/co/innoxium/candor/thread/ThreadModInstaller.java index 45e2166..d7642f6 100644 --- a/src/main/java/uk/co/innoxium/candor/thread/ThreadModInstaller.java +++ b/src/main/java/uk/co/innoxium/candor/thread/ThreadModInstaller.java @@ -46,7 +46,7 @@ public void run() { if(installed) { mod.setState(Mod.State.ENABLED); - updateStateInModStore(mod, Mod.State.ENABLED); + ModStore.updateModState(mod, Mod.State.ENABLED); ModStore.MODS.fireChangeToListeners("install", mod, true); } } else { @@ -55,38 +55,4 @@ public void run() { ModStore.MODS.fireChangeToListeners("uninstall", mod, successful); } } - - private void updateStateInModStore(Mod mod, Mod.State state) { - - File installedModsConfig = new File("config/" + ModuleSelector.currentModule.getExeName() + "/mods.json"); - - try { - - JsonObject contents = JsonUtil.getObjectFromPath(installedModsConfig.toPath()); - JsonArray array = contents.get("mods").getAsJsonArray(); - JsonArray newArray = array.deepCopy(); - - for (int i = 0; i < array.size(); i++) { - - JsonObject obj = array.get(i).getAsJsonObject(); - if(mod.getName().equals(obj.get("name").getAsString())) { - - newArray.get(i).getAsJsonObject().remove("state"); - newArray.get(i).getAsJsonObject().addProperty("state", state.name()); - } - } - - contents.remove("mods"); - contents.add("mods", newArray); - - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - FileWriter writer = new FileWriter(installedModsConfig); - gson.toJson(contents, writer); - - writer.close(); - } catch (IOException e) { - - e.printStackTrace(); - } - } }