This repository was archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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
Showing
45 changed files
with
1,980 additions
and
951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.