Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
2.0.0-b3 - Dependency changes, memory leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
skyecodes committed Jul 30, 2017
1 parent 9287c0f commit ff656b5
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 37 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

<groupId>com.github.franckyi</groupId>
<artifactId>cmpdl</artifactId>
<version>2.0.0-b2</version>
<version>2.0.0-b3</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
<groupId>com.eclipsesource.minimal-json</groupId>
<artifactId>minimal-json</artifactId>
<version>0.9.4</version>
</dependency>
</dependencies>
<build>
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/github/franckyi/cmpdl/CMPDL.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/github/franckyi/cmpdl/InterfaceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
41 changes: 37 additions & 4 deletions src/main/java/com/github/franckyi/cmpdl/ManifestJson.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ModloaderJson> modLoaders;

@SuppressWarnings("unused")
public class ModloaderJson {

public String id;
Expand All @@ -37,7 +71,6 @@ public class ModloaderJson {
public String author;
public List<FileJson> files;

@SuppressWarnings("unused")
public class FileJson {

public int projectID;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/franckyi/cmpdl/task/CleanTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public CleanTask() {

@Override
protected Void call0() throws Exception {
log("> Cleaning up...");
log("Cleaning up...");
del(new File(CMPDL.getTempDirectory()));
return null;
}

@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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -104,7 +104,7 @@ protected Void call0() throws Exception {
}
out.close();
}
log("> > Copied " + dest.getName());
log("> Copied " + dest.getName());
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 !");
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,14 +25,14 @@ public class DownloadModsTask extends CustomTask<Void> {
@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();
Expand Down Expand Up @@ -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();
Expand All @@ -84,7 +85,7 @@ protected Void call0() throws Exception {
}
fos.close();
bis.close();
log("> > > Download succeeded !");
log("> Download succeeded !");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UnzipModpackTask extends CustomTask<Void> {

@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;
Expand Down Expand Up @@ -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 !");
}
}

0 comments on commit ff656b5

Please sign in to comment.