This repository has been 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.
- Loading branch information
Showing
26 changed files
with
358 additions
and
984 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
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,46 @@ | ||
package com.github.franckyi.cmpdl; | ||
|
||
import com.github.franckyi.cmpdl.controller.*; | ||
import com.mashape.unirest.http.Unirest; | ||
import javafx.application.Application; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Parent; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class CMPDL extends Application { | ||
|
||
private static final String NAME = "Curse Modpack Downloader"; | ||
private static final String VERSION = "2.1.0-b1"; | ||
private static final String AUTHOR = "Franckyi"; | ||
|
||
public static String title() { | ||
return String.format("%s v%s by %s", NAME, VERSION, AUTHOR); | ||
} | ||
public static final String NAME = "CMPDL"; | ||
public static final String VERSION = "2.1.0-b1"; | ||
public static final String AUTHOR = "Franckyi"; | ||
public static final String TITLE = String.format("%s v%s by %s", NAME, VERSION, AUTHOR); | ||
|
||
public static InterfaceController controller; | ||
public static Parent parent; | ||
public static Stage stage; | ||
|
||
public static String path; | ||
public static String zipFileName; | ||
|
||
public static final Set<Exception> exceptions = new HashSet<>(); | ||
public static ControllerView<MainWindowController> mainWindow; | ||
public static ControllerView<ModpackPaneController> modpackPane; | ||
public static ControllerView<FilePaneController> filePane; | ||
public static ControllerView<DestinationPaneController> destinationPane; | ||
public static ControllerView<ProgressPaneController> progressPane; | ||
|
||
@Override | ||
public void start(Stage primaryStage) throws Exception { | ||
modpackPane = new ControllerView<>("ModpackPane.fxml", EnumContent.MODPACK); | ||
filePane = new ControllerView<>("FilePane.fxml", EnumContent.FILE); | ||
destinationPane = new ControllerView<>("DestinationPane.fxml", EnumContent.DESTINATION); | ||
progressPane = new ControllerView<>("ProgressPane.fxml", EnumContent.PROGRESS); | ||
mainWindow = new ControllerView<>("MainWindow.fxml"); | ||
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); | ||
stage.setScene(new Scene(mainWindow.getView())); | ||
stage.setTitle(TITLE); | ||
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"; | ||
} | ||
|
||
public static String toOverridePath(File file, String override) { | ||
return file.getPath().replace(".cmpdl_temp" + File.separator + override, "minecraft"); | ||
Unirest.clearDefaultHeaders(); | ||
Unirest.setDefaultHeader("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)); | ||
if (args.length == 0) { | ||
launch(args); | ||
} else { | ||
// DO SOMETHING | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/franckyi/cmpdl/ControllerView.java
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,36 @@ | ||
package com.github.franckyi.cmpdl; | ||
|
||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Parent; | ||
|
||
import java.io.IOException; | ||
|
||
public class ControllerView<T> { | ||
|
||
private final Parent view; | ||
private final T controller; | ||
private EnumContent enumContent; | ||
|
||
public ControllerView(String res) throws IOException { | ||
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(res)); | ||
view = loader.load(); | ||
controller = loader.getController(); | ||
} | ||
|
||
public ControllerView(String res, EnumContent enumContent) throws IOException { | ||
this(res); | ||
this.enumContent = enumContent; | ||
} | ||
|
||
public Parent getView() { | ||
return view; | ||
} | ||
|
||
public T getController() { | ||
return controller; | ||
} | ||
|
||
public EnumContent getEnumContent() { | ||
return enumContent; | ||
} | ||
} |
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,33 @@ | ||
package com.github.franckyi.cmpdl; | ||
|
||
import com.mashape.unirest.http.JsonNode; | ||
import com.mashape.unirest.http.Unirest; | ||
import com.mashape.unirest.http.exceptions.UnirestException; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
public class CurseMetaAPI { | ||
|
||
private static final String URL = "http://cursemeta.dries007.net/api/v2/direct"; | ||
|
||
public static JSONObject getProject(int projectId) throws UnirestException { | ||
return get("/GetAddOn", projectId).getObject(); | ||
} | ||
|
||
public static JSONArray getProjectFiles(int projectId) throws UnirestException { | ||
return get("/GetAllFilesForAddOn", projectId).getArray(); | ||
} | ||
|
||
public static JSONObject getProjectFile(int projectId, int fileId) throws UnirestException { | ||
return get("/GetAddOnFile", projectId, fileId).getObject(); | ||
} | ||
|
||
private static JsonNode get(String path, Object... args) throws UnirestException { | ||
StringBuilder sb = new StringBuilder(URL + path); | ||
for (Object o : args) { | ||
sb.append("/").append(o); | ||
} | ||
return Unirest.get(sb.toString()).asJson().getBody(); | ||
} | ||
|
||
} |
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,5 @@ | ||
package com.github.franckyi.cmpdl; | ||
|
||
public enum EnumContent { | ||
MODPACK, FILE, DESTINATION, PROGRESS | ||
} |
Oops, something went wrong.