]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Fix installer breaking profiles
authorIrtimaled <irtimaled@gmail.com>
Sun, 1 Sep 2019 07:18:29 +0000 (00:18 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 18 Nov 2019 17:21:09 +0000 (09:21 -0800)
src/main/java/com/irtimaled/bbor/install/Installer.java

index d0f6a210b3e431821ed8f821d3e9e87fe7b5acf5..327a81334781dd612a05bcf766d682e2367ffdf6 100644 (file)
@@ -30,24 +30,24 @@ public class Installer {
 
             try {
                 File profilesJson = new File(minecraftFolder, "launcher_profiles.json");
-                if (profilesJson.exists()) { // TODO: use gson instead
+                if (profilesJson.exists()) {
                     String identifier = "\"bbor-" + mcVersion + "\"";
                     String contents = new String(Files.readAllBytes(profilesJson.toPath()));
                     if (contents.contains(identifier)) {
-                        contents = contents.replaceAll(",\n *" + identifier + ": \\{[^}]*},", ",");
-                        contents = contents.replaceAll(",?\n *" + identifier + ": \\{[^}]*},?", "");
+                        contents = contents.replaceAll(",\n?\\s*" + identifier + "\\s*:\\s*\\{[^}]*},", ",");
+                        contents = contents.replaceAll(",?\n?\\s*" + identifier + "\\s*:\\s*\\{[^}]*},?", "");
                     }
 
                     String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
 
-                    contents = contents.replaceAll("(\n\\s*\"profiles\"\\s*:\\s*\\{)", "$1\n" +
+                    contents = contents.replaceAll("([}],\n?\\s*\"profiles\"\\s*:\\s*[{]\n?)", "$1" +
                             "    " + identifier + ": {\n" +
                             "      \"name\": \"Bounding Box Outline Reloaded\",\n" +
                             "      \"type\": \"custom\",\n" +
                             "      \"created\": \"" + date + "T00:00:00.000Z\",\n" +
                             "      \"lastUsed\": \"2100-01-01T00:00:00.000Z\",\n" +
                             "      \"lastVersionId\": \"BBOR-" + version + "\"\n" +
-                            "    },");
+                            "    },\n");
 
                     Files.write(profilesJson.toPath(), contents.getBytes());
                 }