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

Commit

Permalink
Merge branch '2.1.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
#	src/main/java/com/github/franckyi/cmpdl/CMPDL.java
#	src/main/java/com/github/franckyi/cmpdl/task/CustomTask.java
#	src/main/java/com/github/franckyi/cmpdl/task/DownloadModsTask.java
#	src/main/java/com/github/franckyi/cmpdl/task/VerifyProjectTask.java
#	src/main/resources/interface.fxml
  • Loading branch information
skyecodes committed Apr 12, 2018
2 parents 66126e5 + 305f05c commit fb5d713
Show file tree
Hide file tree
Showing 45 changed files with 1,980 additions and 951 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea/

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Franckyi
Copyright (c) 2018 Franckyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
44 changes: 14 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,26 @@

<groupId>com.github.franckyi</groupId>
<artifactId>cmpdl</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.eclipsesource.minimal-json</groupId>
<artifactId>minimal-json</artifactId>
<version>0.9.4</version>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.franckyi.cmpdl.CMPDL</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
109 changes: 51 additions & 58 deletions src/main/java/com/github/franckyi/cmpdl/CMPDL.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,78 @@
package com.github.franckyi.cmpdl;

import com.github.franckyi.cmpdl.controller.*;
import com.github.franckyi.cmpdl.core.ContentControllerView;
import com.github.franckyi.cmpdl.core.ControllerView;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;

import java.io.File;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CMPDL extends Application {

private static final String NAME = "Curse Modpack Downloader";
private static final String VERSION = "2.0.0";
private static final String AUTHOR = "Franckyi (original version by Vazkii)";
public static final String NAME = "CMPDL";
public static final String VERSION = "2.1.0";
public static final String AUTHOR = "Franckyi";
public static final String TITLE = String.format("%s v%s by %s", NAME, VERSION, AUTHOR);

public static String title() {
return String.format("%s v%s by %s", NAME, VERSION, AUTHOR);
}
public static final String USER_AGENT = String.format("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0 %s/%s (%s)", NAME, VERSION, AUTHOR);

public static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool();

public static InterfaceController controller;
public static Parent parent;
public static Stage stage;

public static String path;
public static String zipFileName;
public static ControllerView<MainWindowController> mainWindow;
public static ContentControllerView<ModpackPaneController> modpackPane;
public static ContentControllerView<FilePaneController> filePane;
public static ContentControllerView<DestinationPaneController> destinationPane;
public static ContentControllerView<ProgressPaneController> progressPane;

public static final Set<Exception> exceptions = new HashSet<>();
public static ContentControllerView<?> currentContent;

@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
URL interface0 = getClass().getClassLoader().getResource("interface.fxml");
if (interface0 != null) {
FXMLLoader loader = new FXMLLoader(interface0);
parent = loader.load();
controller = loader.getController();
stage.setScene(new Scene(parent));
stage.setResizable(false);
stage.setTitle(title());
stage.show();
} else {
throw new RuntimeException("Impossible to load interface.fxml file : the application can't start");
}
}

@Override
public void stop() throws Exception {
controller.stop(null);
modpackPane = new ContentControllerView<>("ModpackPane.fxml");
filePane = new ContentControllerView<>("FilePane.fxml");
destinationPane = new ContentControllerView<>("DestinationPane.fxml");
progressPane = new ContentControllerView<>("ProgressPane.fxml");
mainWindow = new ControllerView<>("MainWindow.fxml");
stage.setScene(new Scene(mainWindow.getView()));
stage.setTitle(TITLE);
stage.setOnCloseRequest(e -> currentContent.getController().handleClose());
stage.show();
}

public static void main(String[] args) {
launch(args);
}

public static String getTempDirectory() {
return path + File.separator + ".cmpdl_temp";
}

public static String getZipFile() {
return getTempDirectory() + File.separator + zipFileName;
}

private static String getMinecraftDirectory() {
return path + File.separator + "minecraft";
}

public static String getModsDirectory() {
return getMinecraftDirectory() + File.separator + "mods";
}

public static String getInstanceFile() {
return path + File.separator + "instance.cfg";
}

public static String getManifestFile() {
return getTempDirectory() + File.separator + "manifest.json";
@Override
public void stop() {
EXECUTOR_SERVICE.shutdown();
}

public static String toOverridePath(File file, String override) {
return file.getPath().replace(".cmpdl_temp" + File.separator + override, "minecraft");
public static void openBrowser(String url) {
if (Desktop.isDesktopSupported()) {
EXECUTOR_SERVICE.execute(() -> {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException | URISyntaxException e) {
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, "Can't open URL", ButtonType.OK).show());
e.printStackTrace();
}
});
} else {
new Alert(Alert.AlertType.ERROR, "Desktop not supported", ButtonType.OK).show();
}
}
}
71 changes: 71 additions & 0 deletions src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.github.franckyi.cmpdl;

import com.github.franckyi.cmpdl.model.Project;
import com.github.franckyi.cmpdl.model.ProjectFile;
import com.github.franckyi.cmpdl.model.ProjectFilesList;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

public class CurseMetaAPI {

private static final OkHttpClient CLIENT = new OkHttpClient();
private static final String URL = "http://cursemeta.dries007.net/api/v2/direct";

public static Project getProject(int projectId) {
try {
return new Project(new JSONObject(get("/GetAddOn", projectId)));
} catch (JSONException e) {
e.printStackTrace();
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, String.format("Unknown project (%d)", projectId), ButtonType.OK).show());
return null;
}
}

public static ProjectFilesList getProjectFiles(int projectId) {
try {
return new ProjectFilesList(new JSONArray(get("/GetAllFilesForAddOn", projectId)));
} catch (JSONException e) {
e.printStackTrace();
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, String.format("Unknown project (%d)", projectId), ButtonType.OK).show());
return null;
}
}

public static ProjectFile getProjectFile(int projectId, int fileId) {
try {
return new ProjectFile(new JSONObject(get("/GetAddOnFile", projectId, fileId)));
} catch (JSONException e) {
e.printStackTrace();
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, String.format("Unknown project file (%d:%d)", projectId, fileId), ButtonType.OK).show());
return null;
}
}

private static String get(String path, Object... args) {
StringBuilder sb = new StringBuilder(URL + path);
for (Object o : args) {
sb.append("/").append(o);
}
Request request = new Request.Builder().header("User-Agent", CMPDL.USER_AGENT).url(sb.toString()).get().build();
try (Response response = CLIENT.newCall(request).execute()) {
if (response.body() != null) {
return response.body().string();
} else {
return "";
}
} catch (IOException e) {
e.printStackTrace();
return "";
}
}

}
Loading

0 comments on commit fb5d713

Please sign in to comment.