diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..9eab85a
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,8 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
diff --git a/.gitignore b/.gitignore
index efb6bcc..6fe218b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,4 +24,5 @@
hs_err_pid*
.idea/
-
+target/*
+*.iml
diff --git a/pom.xml b/pom.xml
index dd5abac..0d9c76d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,4 +28,4 @@
1.11.2
-
\ No newline at end of file
+
diff --git a/src/main/java/com/github/franckyi/cmpdl/CMPDL.java b/src/main/java/com/github/franckyi/cmpdl/CMPDL.java
index b294e8e..ea4a9cb 100644
--- a/src/main/java/com/github/franckyi/cmpdl/CMPDL.java
+++ b/src/main/java/com/github/franckyi/cmpdl/CMPDL.java
@@ -24,7 +24,8 @@ public class CMPDL extends Application {
public static final String AUTHOR = "Franckyi";
public static final String TITLE = 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);
+ // As per the "Required reading" section on https://staging_cursemeta.dries007.net/docs
+ public static final String USER_AGENT = String.format("%s/%s (%s)", NAME, AUTHOR, VERSION);
public static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool();
diff --git a/src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java b/src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java
index 8b8c326..dc5413c 100644
--- a/src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java
+++ b/src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java
@@ -18,11 +18,12 @@
public class CurseMetaAPI {
private static final OkHttpClient CLIENT = new OkHttpClient();
- private static final String URL = "http://cursemeta.dries007.net/api/v2/direct";
+ // Docs: https://staging_cursemeta.dries007.net/docs
+ private static final String URL = "https://staging_cursemeta.dries007.net/api/v3/direct";
public static Project getProject(int projectId) {
try {
- return new Project(new JSONObject(get("/GetAddOn", projectId)));
+ return new Project(new JSONObject(get("/addon", projectId)));
} catch (JSONException e) {
e.printStackTrace();
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, String.format("Unknown project (%d)", projectId), ButtonType.OK).show());
@@ -32,7 +33,7 @@ public static Project getProject(int projectId) {
public static ProjectFilesList getProjectFiles(int projectId) {
try {
- return new ProjectFilesList(new JSONArray(get("/GetAllFilesForAddOn", projectId)));
+ return new ProjectFilesList(new JSONArray(get("/addon", projectId, "/files")));
} catch (JSONException e) {
e.printStackTrace();
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, String.format("Unknown project (%d)", projectId), ButtonType.OK).show());
@@ -42,7 +43,7 @@ public static ProjectFilesList getProjectFiles(int projectId) {
public static ProjectFile getProjectFile(int projectId, int fileId) {
try {
- return new ProjectFile(new JSONObject(get("/GetAddOnFile", projectId, fileId)));
+ return new ProjectFile(new JSONObject(get("/addon", projectId, "/file", 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());
diff --git a/src/main/java/com/github/franckyi/cmpdl/controller/DestinationPaneController.java b/src/main/java/com/github/franckyi/cmpdl/controller/DestinationPaneController.java
index e537522..91c290f 100644
--- a/src/main/java/com/github/franckyi/cmpdl/controller/DestinationPaneController.java
+++ b/src/main/java/com/github/franckyi/cmpdl/controller/DestinationPaneController.java
@@ -59,6 +59,10 @@ public class DestinationPaneController implements Initializable, IContentControl
void actionChooseDestination(ActionEvent event) {
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle("Choose the destination folder :");
+ String currentChosenDirectory = destinationField.getText();
+ if (currentChosenDirectory != null && ! "".equals(currentChosenDirectory)) {
+ dc.setInitialDirectory(new File(currentChosenDirectory));
+ }
File dst = dc.showDialog(CMPDL.stage);
if (dst != null) {
destinationField.setText(dst.getAbsolutePath());
@@ -120,7 +124,7 @@ public void setProjectAndFile(Project project, ProjectFile file) {
categoryLabel.setText(project.getCategoryName());
fileNameLabel.setText(file.getFileName());
mcVersionLabel.setText(file.getGameVersion());
- releaseTypeLabel.setText(file.getFileType());
+ releaseTypeLabel.setText(file.getFileType().toString());
releaseTypeLabel.setTextFill(file.getColor());
}
}
diff --git a/src/main/java/com/github/franckyi/cmpdl/model/FileReleaseType.java b/src/main/java/com/github/franckyi/cmpdl/model/FileReleaseType.java
new file mode 100644
index 0000000..358980a
--- /dev/null
+++ b/src/main/java/com/github/franckyi/cmpdl/model/FileReleaseType.java
@@ -0,0 +1,7 @@
+package com.github.franckyi.cmpdl.model;
+
+public enum FileReleaseType {
+ ALPHA,
+ BETA,
+ RELEASE,
+}
diff --git a/src/main/java/com/github/franckyi/cmpdl/model/IProjectFile.java b/src/main/java/com/github/franckyi/cmpdl/model/IProjectFile.java
index ff66596..6380c6c 100644
--- a/src/main/java/com/github/franckyi/cmpdl/model/IProjectFile.java
+++ b/src/main/java/com/github/franckyi/cmpdl/model/IProjectFile.java
@@ -9,11 +9,31 @@ public interface IProjectFile extends Comparable {
int getFileId();
+ /**
+ * Parses the integer type provided by api to FileReleaseType
+ *
+ * @param releaseType the integer received from API
+ * @return FileReleaseType
+ * @throws Exception Thrown when the release type could not be determined
+ */
+ default FileReleaseType parseFileType(int releaseType) throws Exception {
+ switch (releaseType) {
+ case 1:
+ return FileReleaseType.RELEASE;
+ case 2:
+ return FileReleaseType.BETA;
+ case 3:
+ return FileReleaseType.ALPHA;
+ default:
+ throw new Exception("Failed to find release type for id " + releaseType);
+ }
+ }
+
String getFileName();
String getGameVersion();
- String getFileType();
+ FileReleaseType getFileType();
@Override
default int compareTo(IProjectFile o) {
@@ -22,11 +42,11 @@ default int compareTo(IProjectFile o) {
default Paint getColor() {
switch (getFileType()) {
- case "Alpha":
+ case ALPHA:
return Color.web("#E49788");
- case "Beta":
+ case BETA:
return Color.web("#7FA5C4");
- case "Release":
+ case RELEASE:
return Color.web("#8CAF62");
default:
return Color.BLACK;
diff --git a/src/main/java/com/github/franckyi/cmpdl/model/Project.java b/src/main/java/com/github/franckyi/cmpdl/model/Project.java
index a6b255f..c6f998b 100644
--- a/src/main/java/com/github/franckyi/cmpdl/model/Project.java
+++ b/src/main/java/com/github/franckyi/cmpdl/model/Project.java
@@ -9,6 +9,8 @@
public class Project {
+ private static final int PACKAGE_TYPE_MODPACK = 5;
+
private final int projectId;
private final String name;
private final String author;
@@ -21,16 +23,16 @@ public class Project {
private final List files;
public Project(JSONObject json) {
- projectId = json.getInt("Id");
- name = json.getString("Name");
- author = json.getString("PrimaryAuthorName");
- summary = json.getString("Summary");
- logoUrl = json.getJSONArray("Attachments").getJSONObject(0).getString("Url");
- url = json.getString("WebSiteURL");
- categoryName = json.getString("PrimaryCategoryName");
- categoryLogoUrl = json.getString("PrimaryCategoryAvatarUrl");
- modpack = "ModPack".equals(json.getString("PackageType"));
- JSONArray array = json.getJSONArray("GameVersionLatestFiles");
+ projectId = json.getInt("id");
+ name = json.getString("name");
+ author = json.getString("primaryAuthorName");
+ summary = json.getString("summary");
+ logoUrl = json.getJSONArray("attachments").getJSONObject(0).getString("url");
+ url = json.getString("websiteUrl");
+ categoryName = json.getString("primaryCategoryName");
+ categoryLogoUrl = json.getString("primaryCategoryAvatarUrl");
+ modpack = json.getInt("packageType") == PACKAGE_TYPE_MODPACK;
+ JSONArray array = json.getJSONArray("gameVersionLatestFiles");
files = new ArrayList<>(array.length());
for (int i = 0; i < array.length(); i++) {
files.add(new ProjectFileMinimal(array.getJSONObject(i)));
diff --git a/src/main/java/com/github/franckyi/cmpdl/model/ProjectFile.java b/src/main/java/com/github/franckyi/cmpdl/model/ProjectFile.java
index fb27706..4d33676 100644
--- a/src/main/java/com/github/franckyi/cmpdl/model/ProjectFile.java
+++ b/src/main/java/com/github/franckyi/cmpdl/model/ProjectFile.java
@@ -7,17 +7,22 @@ public class ProjectFile implements IProjectFile {
private final String fileName;
private final String fileNameOnDisk;
private final String gameVersion;
- private final String fileType;
+ private FileReleaseType fileType;
private final int fileId;
private final String downloadUrl;
public ProjectFile(JSONObject json) {
- fileName = json.getString("FileName");
- fileNameOnDisk = json.getString("FileNameOnDisk");
- gameVersion = json.getJSONArray("GameVersion").getString(0);
- fileType = json.getString("ReleaseType");
- fileId = json.getInt("Id");
- downloadUrl = json.getString("DownloadURL");
+ fileName = json.getString("fileName");
+ fileNameOnDisk = json.getString("fileNameOnDisk");
+ gameVersion = json.getJSONArray("gameVersion").getString(0);
+ try {
+ fileType = parseFileType(json.getInt("releaseType"));
+ } catch (Exception e) {
+ fileType = FileReleaseType.ALPHA;
+ e.printStackTrace();
+ }
+ fileId = json.getInt("id");
+ downloadUrl = json.getString("downloadUrl");
}
@Override
@@ -40,7 +45,7 @@ public String getGameVersion() {
}
@Override
- public String getFileType() {
+ public FileReleaseType getFileType() {
return fileType;
}
diff --git a/src/main/java/com/github/franckyi/cmpdl/model/ProjectFileMinimal.java b/src/main/java/com/github/franckyi/cmpdl/model/ProjectFileMinimal.java
index 20a418a..b13f769 100644
--- a/src/main/java/com/github/franckyi/cmpdl/model/ProjectFileMinimal.java
+++ b/src/main/java/com/github/franckyi/cmpdl/model/ProjectFileMinimal.java
@@ -6,14 +6,19 @@ public class ProjectFileMinimal implements IProjectFile {
private final String fileName;
private final String gameVersion;
- private final String fileType;
+ private FileReleaseType fileType;
private final int fileId;
- public ProjectFileMinimal(JSONObject json) {
- fileName = json.getString("ProjectFileName");
- gameVersion = json.getString("GameVesion");
- fileType = json.getString("FileType");
- fileId = json.getInt("ProjectFileID");
+ ProjectFileMinimal(JSONObject json) {
+ fileName = json.getString("projectFileName");
+ gameVersion = json.getString("gameVersion");
+ try {
+ fileType = parseFileType(json.getInt("fileType"));
+ } catch (Exception e) {
+ fileType = FileReleaseType.ALPHA;
+ e.printStackTrace();
+ }
+ fileId = json.getInt("projectFileId");
}
public String getFileName() {
@@ -24,7 +29,8 @@ public String getGameVersion() {
return gameVersion;
}
- public String getFileType() {
+ @Override
+ public FileReleaseType getFileType() {
return fileType;
}
diff --git a/src/main/java/com/github/franckyi/cmpdl/view/ProjectFileMinimalView.java b/src/main/java/com/github/franckyi/cmpdl/view/ProjectFileMinimalView.java
index a5f9c05..d164aa8 100644
--- a/src/main/java/com/github/franckyi/cmpdl/view/ProjectFileMinimalView.java
+++ b/src/main/java/com/github/franckyi/cmpdl/view/ProjectFileMinimalView.java
@@ -28,7 +28,7 @@ protected void updateItem(IProjectFile item, boolean empty) {
} else {
fileName.setText(item.getFileName());
gameVersion.setText("for MC " + item.getGameVersion());
- fileType.setText(item.getFileType());
+ fileType.setText(item.getFileType().toString());
fileType.setTextFill(item.getColor());
setGraphic(root);
}