Skip to content

Commit

Permalink
Also detect modpacks that don't have a mod-list.json
Browse files Browse the repository at this point in the history
Version to 0.1.2
  • Loading branch information
narrowtux committed Jul 4, 2015
1 parent 7a9935e commit 6e97078
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.narrowtux</groupId>
<artifactId>FactorioModManager</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>

<build>
<plugins>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/narrowtux/fmm/Datastore.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public void scanDirectory(Path path) throws IOException {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
System.out.println(getTabs() + "Enter directory " + dir);
if (Files.exists(Paths.get(dir.toString(), "mod-list.json"))) {
Path modList = dir.resolve("mod-list.json");
if (!Files.exists(modList) && dir.getParent().equals(getFMMDir())) {
Modpack.writeModList(modList);
}
if (Files.exists(modList)) {
currentModpack = new Modpack(dir.getFileName().toString(), dir);
System.out.println(getTabs() + "Enter modpack " + currentModpack.getName());
currentTabs++;
Expand Down Expand Up @@ -109,7 +113,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
.findAny()
.ifPresent(mod2 -> mod2.setEnabled(enabled));
}

currentModpack.writeModList();
Datastore.getInstance().getModpacks().add(currentModpack);
currentModpack = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/narrowtux/fmm/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Mod(String name, String version, Path path, Modpack modpack) {
setModpack(modpack);

enabledProperty().addListener((observableValue, ov, nv) -> {
getModpack().writeModList();
modpack.writeModList();
});
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/narrowtux/fmm/Modpack.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ public String toString() {
}

public void writeModList() {
writeModList(getPath().resolve("mod-list.json"), getMods().toArray(new Mod[0]));
}

public static void writeModList(Path file, Mod ... mods) {
JsonObject root = new JsonObject();
JsonArray modList = new JsonArray();
JsonObject baseMod = new JsonObject();
baseMod.addProperty("name", "base");
baseMod.addProperty("enabled", true);
modList.add(baseMod);
for (Mod mod : getMods()) {
for (Mod mod : mods) {
JsonObject modInfo = new JsonObject();
modInfo.addProperty("name", mod.getName());
modInfo.addProperty("enabled", mod.getEnabled());
Expand All @@ -82,7 +86,7 @@ public void writeModList() {
try {
Gson gson = new Gson();
String json = gson.toJson(root);
FileWriter writer = new FileWriter(new File(getPath().toString(), "mod-list.json"));
FileWriter writer = new FileWriter(file.toFile());
writer.write(json);
writer.close();
} catch (IOException e) {
Expand Down

0 comments on commit 6e97078

Please sign in to comment.