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

Commit

Permalink
Hotfix while CurseMeta API is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
skyecodes committed Jun 20, 2018
1 parent 9ceaa20 commit 3fc4f11
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/franckyi/cmpdl/CMPDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
public class CMPDL extends Application {

public static final String NAME = "CMPDL";
public static final String VERSION = "2.1.1";
public static final String VERSION = "2.1.1-hotfix";
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);
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);

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

Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
public class CurseMetaAPI {

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

public static Project getProject(int projectId) {
try {
Expand All @@ -40,6 +41,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)));
Expand All @@ -49,6 +51,17 @@ public static ProjectFile getProjectFile(int projectId, int fileId) {
return null;
}
}
*/

public static ProjectFile getProjectFile(int projectId, int fileId) {
try {
return new ProjectFile(new JSONObject(get(String.format("/%d/%d.json", 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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/franckyi/cmpdl/model/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class Project {
private final List<ProjectFileMinimal> files;

public Project(JSONObject json) {
if (json.has("error") && json.getBoolean("error"))
throw new IllegalArgumentException("Error " + json.getInt("status"));
projectId = json.getInt("Id");
name = json.getString("Name");
author = json.getString("PrimaryAuthorName");
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/github/franckyi/cmpdl/model/ProjectFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ public class ProjectFile implements IProjectFile {
private final String fileName;
private final String fileNameOnDisk;
private final String gameVersion;
private final String fileType;
//private final String fileType;
private final int fileId;
private final String downloadUrl;

public ProjectFile(JSONObject json) {
if (json.has("error") && json.getBoolean("error"))
throw new IllegalArgumentException("Error " + json.getInt("status"));
fileName = json.getString("FileName");
fileNameOnDisk = json.getString("FileNameOnDisk");
gameVersion = json.getJSONArray("GameVersion").getString(0);
fileType = json.getString("ReleaseType");
//gameVersion = json.getJSONArray("GameVersion").getString(0);
gameVersion = json.getJSONArray("gameVersion").getString(0);
//fileType = json.getString("ReleaseType");
fileId = json.getInt("Id");
downloadUrl = json.getString("DownloadURL");
}
Expand All @@ -41,7 +44,8 @@ public String getGameVersion() {

@Override
public String getFileType() {
return fileType;
//return fileType;
return "";
}

public String getDownloadUrl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ProjectFileMinimal implements IProjectFile {
private final int fileId;

public ProjectFileMinimal(JSONObject json) {
if (json.has("error") && json.getBoolean("error"))
throw new IllegalArgumentException("Error " + json.getInt("status"));
fileName = json.getString("ProjectFileName");
gameVersion = json.getString("GameVesion");
fileType = json.getString("FileType");
Expand Down
12 changes: 12 additions & 0 deletions src/main/main.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

0 comments on commit 3fc4f11

Please sign in to comment.