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

Commit 3fc4f11

Browse files
committed
Hotfix while CurseMeta API is broken
1 parent 9ceaa20 commit 3fc4f11

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-7
lines changed

src/main/java/com/github/franckyi/cmpdl/CMPDL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
public class CMPDL extends Application {
2121

2222
public static final String NAME = "CMPDL";
23-
public static final String VERSION = "2.1.1";
23+
public static final String VERSION = "2.1.1-hotfix";
2424
public static final String AUTHOR = "Franckyi";
2525
public static final String TITLE = String.format("%s v%s by %s", NAME, VERSION, AUTHOR);
2626

27-
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);
27+
public static final String USER_AGENT = String.format("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 %s/%s (%s)", NAME, VERSION, AUTHOR);
2828

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

src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
public class CurseMetaAPI {
1919

2020
private static final OkHttpClient CLIENT = new OkHttpClient();
21-
private static final String URL = "http://cursemeta.dries007.net/api/v2/direct";
21+
//private static final String URL = "http://cursemeta.dries007.net/api/v2/direct";
22+
private static final String URL = "http://cursemeta.dries007.net";
2223

2324
public static Project getProject(int projectId) {
2425
try {
@@ -40,6 +41,7 @@ public static ProjectFilesList getProjectFiles(int projectId) {
4041
}
4142
}
4243

44+
/*
4345
public static ProjectFile getProjectFile(int projectId, int fileId) {
4446
try {
4547
return new ProjectFile(new JSONObject(get("/GetAddOnFile", projectId, fileId)));
@@ -49,6 +51,17 @@ public static ProjectFile getProjectFile(int projectId, int fileId) {
4951
return null;
5052
}
5153
}
54+
*/
55+
56+
public static ProjectFile getProjectFile(int projectId, int fileId) {
57+
try {
58+
return new ProjectFile(new JSONObject(get(String.format("/%d/%d.json", projectId, fileId))));
59+
} catch (JSONException e) {
60+
e.printStackTrace();
61+
Platform.runLater(() -> new Alert(Alert.AlertType.ERROR, String.format("Unknown project file (%d:%d)", projectId, fileId), ButtonType.OK).show());
62+
return null;
63+
}
64+
}
5265

5366
private static String get(String path, Object... args) {
5467
StringBuilder sb = new StringBuilder(URL + path);

src/main/java/com/github/franckyi/cmpdl/model/Project.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class Project {
2121
private final List<ProjectFileMinimal> files;
2222

2323
public Project(JSONObject json) {
24+
if (json.has("error") && json.getBoolean("error"))
25+
throw new IllegalArgumentException("Error " + json.getInt("status"));
2426
projectId = json.getInt("Id");
2527
name = json.getString("Name");
2628
author = json.getString("PrimaryAuthorName");

src/main/java/com/github/franckyi/cmpdl/model/ProjectFile.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ public class ProjectFile implements IProjectFile {
77
private final String fileName;
88
private final String fileNameOnDisk;
99
private final String gameVersion;
10-
private final String fileType;
10+
//private final String fileType;
1111
private final int fileId;
1212
private final String downloadUrl;
1313

1414
public ProjectFile(JSONObject json) {
15+
if (json.has("error") && json.getBoolean("error"))
16+
throw new IllegalArgumentException("Error " + json.getInt("status"));
1517
fileName = json.getString("FileName");
1618
fileNameOnDisk = json.getString("FileNameOnDisk");
17-
gameVersion = json.getJSONArray("GameVersion").getString(0);
18-
fileType = json.getString("ReleaseType");
19+
//gameVersion = json.getJSONArray("GameVersion").getString(0);
20+
gameVersion = json.getJSONArray("gameVersion").getString(0);
21+
//fileType = json.getString("ReleaseType");
1922
fileId = json.getInt("Id");
2023
downloadUrl = json.getString("DownloadURL");
2124
}
@@ -41,7 +44,8 @@ public String getGameVersion() {
4144

4245
@Override
4346
public String getFileType() {
44-
return fileType;
47+
//return fileType;
48+
return "";
4549
}
4650

4751
public String getDownloadUrl() {

src/main/java/com/github/franckyi/cmpdl/model/ProjectFileMinimal.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class ProjectFileMinimal implements IProjectFile {
1010
private final int fileId;
1111

1212
public ProjectFileMinimal(JSONObject json) {
13+
if (json.has("error") && json.getBoolean("error"))
14+
throw new IllegalArgumentException("Error " + json.getInt("status"));
1315
fileName = json.getString("ProjectFileName");
1416
gameVersion = json.getString("GameVesion");
1517
fileType = json.getString("FileType");

src/main/main.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
7+
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
</component>
12+
</module>

0 commit comments

Comments
 (0)