Skip to content

Commit

Permalink
This should fix mods not being updated in the mods json
Browse files Browse the repository at this point in the history
  • Loading branch information
zpiddock committed Sep 3, 2020
1 parent e280015 commit 08ced67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ publishing {
artifact javadocJar
groupId 'uk.co.innoxium.candor'
artifactId 'candor-full'
version '0.1.5'
version '0.1.7'
}
}
}
Expand All @@ -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()
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/uk/co/innoxium/candor/mod/ModsHandler.java

This file was deleted.

32 changes: 32 additions & 0 deletions src/main/java/uk/co/innoxium/candor/mod/store/ModStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}
}

0 comments on commit 08ced67

Please sign in to comment.