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

Commit

Permalink
Fixed #3
Browse files Browse the repository at this point in the history
  • Loading branch information
skyecodes committed Apr 5, 2018
1 parent c9bfcda commit 66126e5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
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.github.franckyi</groupId>
<artifactId>cmpdl</artifactId>
<version>2.0.0-b3</version>
<version>2.0.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/franckyi/cmpdl/CMPDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class CMPDL extends Application {

private static final String NAME = "Curse Modpack Downloader";
private static final String VERSION = "2.0.0-b3";
private static final String VERSION = "2.0.0";
private static final String AUTHOR = "Franckyi (original version by Vazkii)";

public static String title() {
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/github/franckyi/cmpdl/task/CustomTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

abstract class CustomTask<V> extends Task<V> {
Expand Down Expand Up @@ -37,18 +39,28 @@ InterfaceController getController() {
return CMPDL.controller;
}

String crawl(String url) throws IOException, IllegalArgumentException {
String crawl(String url) throws IOException, URISyntaxException {
URL url0 = new URL(crawl0(url));
return new URI(url0.getProtocol(), url0.getHost(), url0.getFile(), null).toASCIIString();
}

String crawlAddHost(String url) throws IOException, URISyntaxException {
URL url0 = new URL(crawlAddHost0(url));
return new URI(url0.getProtocol(), url0.getHost(), url0.getFile(), null).toASCIIString();
}

private String crawl0(String url) throws IOException, IllegalArgumentException, URISyntaxException {
String location = getLocation(url);
return location != null ? crawl(location) : url;
return location != null ? crawl0(location) : url;
}

String crawlAddHost(String url) throws IOException, IllegalArgumentException {
private String crawlAddHost0(String url) throws IOException, IllegalArgumentException, URISyntaxException {
URL url0 = new URL(url);
String location = getLocation(url);
return location != null ? location.contains("://") ? crawlAddHost(location) : crawl(url0.getProtocol() + "://" + url0.getHost() + location) : url;
return location != null ? location.contains("://") ? crawlAddHost0(location) : crawl0(url0.getProtocol() + "://" + url0.getHost() + location) : url;
}

private String getLocation(String url) throws IOException {
private String getLocation(String url) throws IOException, URISyntaxException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setInstanceFollowRedirects(false);
if (connection.getResponseCode() < 200 || connection.getResponseCode() >= 400)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.FileReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;

public class DownloadModsTask extends CustomTask<Void> {

Expand Down Expand Up @@ -65,8 +66,8 @@ protected Void call0() throws Exception {
updateProgress(0, 1);
String url0 = crawl(crawlAddHost("http://minecraft.curseforge.com/projects/" + fileJson.projectID) + "/files/" + fileJson.fileID + "/download");
if (DownloadModsTask.this.isCancelled()) return null;
URL url = new URL(url0);
String fileName = new File(url.getFile()).getName().replaceAll("%20", " ");
URL url = new URL(url0.replaceAll("%25", "%"));
String fileName = new File(URLDecoder.decode(url.getFile(), "UTF-8")).getName();
log("> Downloading " + fileName);
Platform.runLater(() -> getController().setSecondaryProgress(this, fileName));
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ protected Optional<String> call0() throws Exception {
protocol = url.getProtocol();
host = url.getHost();
folder = url.getFile();
isCurse = host.equals("mods.curse.com");
isCurse = host.equals("www.curseforge.com");
protocolValid = Arrays.asList("http", "https").contains(protocol);
hostValid = Arrays.asList("mods.curse.com", "minecraft.curseforge.com", "www.feed-the-beast.com").contains(host);
folderValid = isCurse ? folder.startsWith("/modpacks/minecraft/") && folder.split("/").length == 4 : folder.startsWith("/projects/") && folder.split("/").length == 3;
hostValid = Arrays.asList("www.curseforge.com", "minecraft.curseforge.com", "www.feed-the-beast.com").contains(host);
folderValid = isCurse ? folder.startsWith("/minecraft/modpacks/") && folder.split("/").length == 4 : folder.startsWith("/projects/") && folder.split("/").length == 3;
if (!protocolValid || !hostValid || !folderValid) {
log("The URL is incorrect !" + (!protocolValid ? "\n- Protocol invalid" : "") + (!hostValid ? "\n- Host invalid" : "") + (!folderValid ? "\n- Folder invalid" : ""));
return Optional.empty();
}
if (fileID.isEmpty()) {
fileID = "latest";
}
if (host.equals("www.feed-the-beast.com") && fileID.equals("latest")) {
log("You must specify a file ID other than\n'latest' for host www.feed-the-beast.com.");
if ((host.equals("www.feed-the-beast.com") || host.equals("www.curseforge.com")) && fileID.equals("latest")) {
log("You must specify a file ID other than\n'latest' for host www.feed-the-beast.com or www.curseforge.com.");
return Optional.empty();
}
try {
return Optional.of(crawl(isCurse ? modpackURL + "/" + (fileID.equals("latest") ? "download" : fileID) : modpackURL + "/files/" + fileID + (fileID.equals("latest") ? "" : "/download")));
return Optional.of(crawl(isCurse ? modpackURL + "/download/" + fileID + "/file" : modpackURL + "/files/" + fileID + (fileID.equals("latest") ? "" : "/download")));
} catch (IOException e) {
log("The file doesn't exist or website is unreachable !");
return Optional.empty();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/interface.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Font size="24.0"/>
</font>
</Button>
<Label layoutX="11.0" layoutY="81.0" text="Modpack URL (Curse, Curseforge or FTB) :"/>
<Label layoutX="11.0" layoutY="81.0" text="Modpack URL (Curseforge or FTB) :"/>
<Label layoutX="386.0" layoutY="81.0" text="File ID :"/>
<Separator layoutX="50.0" layoutY="250.0" prefWidth="500.0"/>
<TextArea fx:id="logTextArea" editable="false" layoutX="25.0" layoutY="296.0" prefHeight="200.0"
Expand Down

0 comments on commit 66126e5

Please sign in to comment.