Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/0.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nincodedo committed Nov 21, 2017
2 parents 92ac52d + 5036012 commit d20fdde
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modpackdownloader-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>modpackdownloader</artifactId>
<groupId>com.nincraft</groupId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion modpackdownloader-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.nincraft</groupId>
<artifactId>modpackdownloader</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>
<artifactId>modpackdownloader-core</artifactId>
<name>Modpack Downloader Core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
import lombok.val;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -99,15 +104,16 @@ public void updateCurseFile(final CurseFile curseFile) {
log.debug("Skipped updating {}", curseFile.getName());
return;
}
JSONObject fileListJson;
disableCertValidation();
JSONObject fileListJson = new JSONObject();
try {
val conn = (HttpURLConnection) new URL(curseFile.getProjectUrl()).openConnection();
conn.setInstanceFollowRedirects(false);
conn.connect();

fileListJson = (JSONObject) getCurseProjectJson(curseFile).get("files");
fileListJson.put("curse", getCurseProjectJson(curseFile).get("files"));

if (fileListJson == null) {
if (fileListJson.get("curse") == null) {
log.error("No file list found for {}, and will be skipped.", curseFile.getName());
return;
}
Expand All @@ -124,6 +130,31 @@ public void updateCurseFile(final CurseFile curseFile) {
}
}

private void disableCertValidation() {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}

public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}

public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
};

try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
}

private void updateCurseFile(CurseFile curseFile, CurseFile newMod) {
curseFile.setFileID(newMod.getFileID());
curseFile.setVersion(newMod.getVersion());
Expand All @@ -144,12 +175,12 @@ private CurseFile getLatestVersion(String releaseType,
CurseFile newMod = new CurseFile(curseFile);
curseFile = checkFileId(curseFile);

List<JSONObject> fileList = new ArrayList<>(fileListJson.values());
JSONArray fileList = (JSONArray) fileListJson.get("curse");
List<Long> fileIds = new ArrayList<>();
checkFileIds(releaseType, mcVersion, fileList, fileIds);
Collections.sort(fileIds);
Collections.reverse(fileIds);
setUpdatedFileId(curseFile, fileListJson, newMod, fileIds);
setUpdatedFileId(curseFile, fileList, newMod, fileIds);

if (!"alpha".equals(releaseType) && fileIds.isEmpty()) {
if (CollectionUtils.isEmpty(arguments.getBackupVersions())) {
Expand All @@ -171,11 +202,20 @@ private CurseFile getLatestVersion(String releaseType,
return newMod;
}

private void setUpdatedFileId(CurseFile curseFile, JSONObject fileListJson, CurseFile newMod, List<Long> fileIds) {
private void setUpdatedFileId(CurseFile curseFile, JSONArray fileListJson, CurseFile newMod, List<Long> fileIds) {
if (!fileIds.isEmpty() && fileIds.get(0).intValue() != curseFile.getFileID()) {
newMod.setFileID(fileIds.get(0).intValue());
newMod.setVersion((String) ((JSONObject) fileListJson.get(newMod.getFileID().toString())).get("name"));
newMod.setVersion(getJSONFileNode(fileListJson, newMod.getFileID()).get("version").toString());
}
}

private JSONObject getJSONFileNode(JSONArray fileListJson, Integer fileID) {
for (val jsonNode : fileListJson) {
if (fileID.equals(((Long) ((JSONObject) jsonNode).get("id")).intValue())) {
return (JSONObject) jsonNode;
}
}
return new JSONObject();
}

private void checkFileIds(String releaseType, String mcVersion, List<JSONObject> fileList, List<Long> fileIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Reference {
private String ftbBaseUrl = "https://www.feed-the-beast.com/projects/";
private String curseforgeWidgetJsonMod = "mc-mods";
private String curseforgeWidgetJsonModpack = "modpacks";
private String curseforgeWidgetJsonUrl = "http://widget.mcf.li/%s/minecraft/%s.json";
private String curseforgeWidgetJsonUrl = "https://api.cfwidget.com/%s/minecraft/%s.json";
private String cookieTest1 = "?cookieTest=1";
private String downloadingModXOfY = "Downloading {}. Mod {} of {}.";
private String updatingModXOfY = "Updating {}. Mod {} of {}.";
Expand Down
2 changes: 1 addition & 1 deletion modpackdownloader-gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>modpackdownloader</artifactId>
<groupId>com.nincraft</groupId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion modpackdownloader-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.nincraft</groupId>
<artifactId>modpackdownloader</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>
<artifactId>modpackdownloader-maven-plugin</artifactId>
<name>Modpack Downloader Maven Plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.nincraft</groupId>
<artifactId>modpackdownloader</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
<packaging>pom</packaging>
<name>Modpack Downloader</name>
<properties>
Expand Down

0 comments on commit d20fdde

Please sign in to comment.