From ff656b58f2a1d0814daf8c9529a82da906e16fb8 Mon Sep 17 00:00:00 2001 From: Franckyi Date: Sun, 30 Jul 2017 14:38:20 +0200 Subject: [PATCH] 2.0.0-b3 - Dependency changes, memory leak fix --- pom.xml | 8 ++-- .../java/com/github/franckyi/cmpdl/CMPDL.java | 6 +-- .../franckyi/cmpdl/InterfaceController.java | 16 ++++---- .../github/franckyi/cmpdl/ManifestJson.java | 41 +++++++++++++++++-- .../github/franckyi/cmpdl/task/CleanTask.java | 8 ++-- .../cmpdl/task/CopyOverridesTask.java | 6 +-- .../cmpdl/task/DownloadModpackTask.java | 4 +- .../franckyi/cmpdl/task/DownloadModsTask.java | 13 +++--- .../franckyi/cmpdl/task/UnzipModpackTask.java | 4 +- 9 files changed, 69 insertions(+), 37 deletions(-) diff --git a/pom.xml b/pom.xml index 6a552d0..277ef93 100644 --- a/pom.xml +++ b/pom.xml @@ -6,16 +6,16 @@ com.github.franckyi cmpdl - 2.0.0-b2 + 2.0.0-b3 1.8 1.8 - com.google.code.gson - gson - 2.8.1 + com.eclipsesource.minimal-json + minimal-json + 0.9.4 diff --git a/src/main/java/com/github/franckyi/cmpdl/CMPDL.java b/src/main/java/com/github/franckyi/cmpdl/CMPDL.java index 48944fd..bd5d3ad 100644 --- a/src/main/java/com/github/franckyi/cmpdl/CMPDL.java +++ b/src/main/java/com/github/franckyi/cmpdl/CMPDL.java @@ -1,7 +1,5 @@ package com.github.franckyi.cmpdl; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -16,7 +14,7 @@ public class CMPDL extends Application { private static final String NAME = "Curse Modpack Downloader"; - private static final String VERSION = "2.0.0-b2"; + private static final String VERSION = "2.0.0-b3"; private static final String AUTHOR = "Franckyi (original version by Vazkii)"; public static String title() { @@ -26,7 +24,6 @@ public static String title() { public static InterfaceController controller; public static Parent parent; public static Stage stage; - public static Gson gson; public static String path; public static String zipFileName; @@ -35,7 +32,6 @@ public static String title() { public void start(Stage primaryStage) throws Exception { stage = primaryStage; - gson = new GsonBuilder().create(); URL interface0 = getClass().getClassLoader().getResource("interface.fxml"); if (interface0 != null) { FXMLLoader loader = new FXMLLoader(interface0); diff --git a/src/main/java/com/github/franckyi/cmpdl/InterfaceController.java b/src/main/java/com/github/franckyi/cmpdl/InterfaceController.java index 3075dae..aa3293b 100644 --- a/src/main/java/com/github/franckyi/cmpdl/InterfaceController.java +++ b/src/main/java/com/github/franckyi/cmpdl/InterfaceController.java @@ -38,12 +38,14 @@ public void initialize(URL location, ResourceBundle resources) { log(CMPDL.title()); log("Java version " + System.getProperty("java.version")); destinationPath.setText(System.getProperty("user.home") + File.separator + "modpack"); - TranslateTransition transition = new TranslateTransition(Duration.seconds(1), title); - transition.setFromY(-10); - transition.setToY(10); - transition.setCycleCount(Animation.INDEFINITE); - transition.setAutoReverse(true); - transition.play(); + if (System.getProperty("os.name").toLowerCase().contains("win")) { + TranslateTransition transition = new TranslateTransition(Duration.seconds(1), title); + transition.setFromY(-10); + transition.setToY(10); + transition.setCycleCount(Animation.INDEFINITE); + transition.setAutoReverse(true); + transition.play(); + } } @FXML @@ -56,7 +58,7 @@ public void initialize(URL location, ResourceBundle resources) { private TextField fileID; @FXML - public TextField destinationPath; + private TextField destinationPath; @FXML private TextArea logTextArea; diff --git a/src/main/java/com/github/franckyi/cmpdl/ManifestJson.java b/src/main/java/com/github/franckyi/cmpdl/ManifestJson.java index d1db733..c795f89 100644 --- a/src/main/java/com/github/franckyi/cmpdl/ManifestJson.java +++ b/src/main/java/com/github/franckyi/cmpdl/ManifestJson.java @@ -1,8 +1,11 @@ package com.github.franckyi.cmpdl; +import com.eclipsesource.json.JsonArray; +import com.eclipsesource.json.JsonObject; + +import java.util.ArrayList; import java.util.List; -@SuppressWarnings("unused") public class ManifestJson { public MinecraftJson minecraft; @@ -15,13 +18,44 @@ public String getForgeVersion() { return "N/A"; } - @SuppressWarnings("unused") + public static ManifestJson from(JsonObject root) { + ManifestJson manifestJson = new ManifestJson(); + MinecraftJson minecraftJson = manifestJson.new MinecraftJson(); + JsonObject minecraft = root.get("minecraft").asObject(); + minecraftJson.version = minecraft.getString("version", "N/A"); + minecraftJson.modLoaders = new ArrayList<>(); + JsonArray modLoaders = minecraft.get("modLoaders").asArray(); + modLoaders.iterator().forEachRemaining(jsonValue -> { + JsonObject modloader = jsonValue.asObject(); + MinecraftJson.ModloaderJson modloaderJson = minecraftJson.new ModloaderJson(); + modloaderJson.id = modloader.getString("id", "N/A"); + modloaderJson.primary = modloader.getBoolean("primary", false); + minecraftJson.modLoaders.add(modloaderJson); + }); + manifestJson.minecraft = minecraftJson; + manifestJson.manifestType = root.getString("manifestType", "N/A"); + manifestJson.manifestVersion = root.getInt("manifestVersion", 0); + manifestJson.name = root.getString("name", "N/A"); + manifestJson.version = root.getString("version", "N/A"); + manifestJson.author = root.getString("author", "N/A"); + manifestJson.files = new ArrayList<>(); + JsonArray files = root.get("files").asArray(); + files.iterator().forEachRemaining(jsonValue -> { + JsonObject file = jsonValue.asObject(); + FileJson fileJson = manifestJson.new FileJson(); + fileJson.projectID = file.getInt("projectID", 0); + fileJson.fileID = file.getInt("fileID", 0); + fileJson.required = file.getBoolean("required", false); + manifestJson.files.add(fileJson); + }); + return manifestJson; + } + public class MinecraftJson { public String version; public List modLoaders; - @SuppressWarnings("unused") public class ModloaderJson { public String id; @@ -37,7 +71,6 @@ public class ModloaderJson { public String author; public List files; - @SuppressWarnings("unused") public class FileJson { public int projectID; diff --git a/src/main/java/com/github/franckyi/cmpdl/task/CleanTask.java b/src/main/java/com/github/franckyi/cmpdl/task/CleanTask.java index 80e6571..e99ea16 100644 --- a/src/main/java/com/github/franckyi/cmpdl/task/CleanTask.java +++ b/src/main/java/com/github/franckyi/cmpdl/task/CleanTask.java @@ -19,7 +19,7 @@ public CleanTask() { @Override protected Void call0() throws Exception { - log("> Cleaning up..."); + log("Cleaning up..."); del(new File(CMPDL.getTempDirectory())); return null; } @@ -27,9 +27,9 @@ protected Void call0() throws Exception { @Override protected void succeeded() { if (manifest != null) { - log("### RECOMMENDED FORGE VERSION : " + manifest.getForgeVersion() + ". ###"); - log("### A newer version should also work."); - log("### You must install it manually if you're using MultiMC ! ###"); + log("!#! RECOMMENDED FORGE VERSION : " + manifest.getForgeVersion()); + log("!#! A newer version should also work."); + log("!#! You must install it manually if you're using MultiMC !"); } getController().reset(); log(CMPDL.exceptions.isEmpty() ? "Done !" : "Done with " + CMPDL.exceptions.size() + " error(s). See log for more info."); diff --git a/src/main/java/com/github/franckyi/cmpdl/task/CopyOverridesTask.java b/src/main/java/com/github/franckyi/cmpdl/task/CopyOverridesTask.java index 8f5cee8..02e52b5 100644 --- a/src/main/java/com/github/franckyi/cmpdl/task/CopyOverridesTask.java +++ b/src/main/java/com/github/franckyi/cmpdl/task/CopyOverridesTask.java @@ -22,7 +22,7 @@ public CopyOverridesTask(ManifestJson manifest, File folder) { @Override protected Void call0() throws Exception { - log("> Copying overrides"); + log("Copying overrides"); if (dir.isDirectory()) { for (File file : dir.listFiles()) { if (!processFile(file)) return null; @@ -75,7 +75,7 @@ private boolean processFile(File file) { @Override protected void succeeded() { - log("> Done copying overrides"); + log("Done copying overrides"); new Thread(new CleanTask(manifest)).start(); } @@ -104,7 +104,7 @@ protected Void call0() throws Exception { } out.close(); } - log("> > Copied " + dest.getName()); + log("> Copied " + dest.getName()); return null; } } diff --git a/src/main/java/com/github/franckyi/cmpdl/task/DownloadModpackTask.java b/src/main/java/com/github/franckyi/cmpdl/task/DownloadModpackTask.java index 0244533..8356ce4 100644 --- a/src/main/java/com/github/franckyi/cmpdl/task/DownloadModpackTask.java +++ b/src/main/java/com/github/franckyi/cmpdl/task/DownloadModpackTask.java @@ -23,7 +23,7 @@ public DownloadModpackTask(String url) throws IOException { @Override protected Void call0() throws Exception { - log("> Downloading modpack at " + url); + log("Downloading modpack at " + url); this.updateProgress(0, 1); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); long completeFileSize = httpConnection.getContentLength(); @@ -47,7 +47,7 @@ protected void succeeded() { UnzipModpackTask task = new UnzipModpackTask(tmp); getController().setSecondaryProgress(task, "Unzipping modpack"); new Thread(task).start(); - log("> Download succeeded !"); + log("Download succeeded !"); } } diff --git a/src/main/java/com/github/franckyi/cmpdl/task/DownloadModsTask.java b/src/main/java/com/github/franckyi/cmpdl/task/DownloadModsTask.java index d3687ce..3dbdb7f 100644 --- a/src/main/java/com/github/franckyi/cmpdl/task/DownloadModsTask.java +++ b/src/main/java/com/github/franckyi/cmpdl/task/DownloadModsTask.java @@ -1,5 +1,6 @@ package com.github.franckyi.cmpdl.task; +import com.eclipsesource.json.Json; import com.github.franckyi.cmpdl.CMPDL; import com.github.franckyi.cmpdl.ManifestJson; import javafx.application.Platform; @@ -24,14 +25,14 @@ public class DownloadModsTask extends CustomTask { @Override protected Void call0() throws Exception { updateProgress(0, 1); - manifest = CMPDL.gson.fromJson(new FileReader(CMPDL.getManifestFile()), ManifestJson.class); + manifest = ManifestJson.from(Json.parse(new FileReader(CMPDL.getManifestFile())).asObject()); int length = manifest.files.size(); - log("### " + manifest.name + " v" + manifest.version + " by " + manifest.author + " ###"); - log("> Mods download started : " + length + " files found"); + log("# " + manifest.name + " v" + manifest.version + " by " + manifest.author); + log("Mods download started : " + length + " files found"); final int[] i = {0}; for (ManifestJson.FileJson fileJson : manifest.files) { if (!isCancelled()) { - log("> > Resolving " + fileJson.projectID + ":" + fileJson.fileID + " (" + (i[0]++) + "/" + length + ")"); + log("# Resolving " + fileJson.projectID + ":" + fileJson.fileID + " (" + (i[0]++ + 1) + "/" + length + ")"); DownloadModTask task = new DownloadModTask(fileJson); task.setOnSucceeded(event -> updateProgress(i[0] - 1, length)); new Thread(task).start(); @@ -66,7 +67,7 @@ protected Void call0() throws Exception { if (DownloadModsTask.this.isCancelled()) return null; URL url = new URL(url0); String fileName = new File(url.getFile()).getName().replaceAll("%20", " "); - log("> > > Downloading " + fileName); + log("> Downloading " + fileName); Platform.runLater(() -> getController().setSecondaryProgress(this, fileName)); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); long completeFileSize = httpConnection.getContentLength(); @@ -84,7 +85,7 @@ protected Void call0() throws Exception { } fos.close(); bis.close(); - log("> > > Download succeeded !"); + log("> Download succeeded !"); return null; } diff --git a/src/main/java/com/github/franckyi/cmpdl/task/UnzipModpackTask.java b/src/main/java/com/github/franckyi/cmpdl/task/UnzipModpackTask.java index 68edfcb..12a6969 100644 --- a/src/main/java/com/github/franckyi/cmpdl/task/UnzipModpackTask.java +++ b/src/main/java/com/github/franckyi/cmpdl/task/UnzipModpackTask.java @@ -17,7 +17,7 @@ public class UnzipModpackTask extends CustomTask { @Override protected Void call0() throws Exception { - log("> Unzipping file at " + folder.getAbsolutePath()); + log("Unzipping file at " + folder.getAbsolutePath()); FileInputStream is = new FileInputStream(zipfile.getCanonicalFile()); FileChannel channel = is.getChannel(); ZipEntry ze; @@ -56,6 +56,6 @@ protected void succeeded() { DownloadModsTask task = new DownloadModsTask(folder); getController().setPrimaryProgress(task, "Step 2/3 : Downloading dependencies"); new Thread(task).start(); - log("> Unzipping succeeded !"); + log("Unzipping succeeded !"); } }