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

Commit

Permalink
Started rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
skyecodes committed Apr 5, 2018
1 parent 75dc0bd commit b82f3aa
Show file tree
Hide file tree
Showing 26 changed files with 358 additions and 984 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Franckyi
Copyright (c) 2018 Franckyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
31 changes: 5 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,10 @@
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.franckyi.cmpdl.CMPDL</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
93 changes: 27 additions & 66 deletions src/main/java/com/github/franckyi/cmpdl/CMPDL.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,46 @@
package com.github.franckyi.cmpdl;

import com.github.franckyi.cmpdl.controller.*;
import com.mashape.unirest.http.Unirest;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.File;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;

public class CMPDL extends Application {

private static final String NAME = "Curse Modpack Downloader";
private static final String VERSION = "2.1.0-b1";
private static final String AUTHOR = "Franckyi";

public static String title() {
return String.format("%s v%s by %s", NAME, VERSION, AUTHOR);
}
public static final String NAME = "CMPDL";
public static final String VERSION = "2.1.0-b1";
public static final String AUTHOR = "Franckyi";
public static final String TITLE = String.format("%s v%s by %s", NAME, VERSION, AUTHOR);

public static InterfaceController controller;
public static Parent parent;
public static Stage stage;

public static String path;
public static String zipFileName;

public static final Set<Exception> exceptions = new HashSet<>();
public static ControllerView<MainWindowController> mainWindow;
public static ControllerView<ModpackPaneController> modpackPane;
public static ControllerView<FilePaneController> filePane;
public static ControllerView<DestinationPaneController> destinationPane;
public static ControllerView<ProgressPaneController> progressPane;

@Override
public void start(Stage primaryStage) throws Exception {
modpackPane = new ControllerView<>("ModpackPane.fxml", EnumContent.MODPACK);
filePane = new ControllerView<>("FilePane.fxml", EnumContent.FILE);
destinationPane = new ControllerView<>("DestinationPane.fxml", EnumContent.DESTINATION);
progressPane = new ControllerView<>("ProgressPane.fxml", EnumContent.PROGRESS);
mainWindow = new ControllerView<>("MainWindow.fxml");
stage = primaryStage;
URL interface0 = getClass().getClassLoader().getResource("interface.fxml");
if (interface0 != null) {
FXMLLoader loader = new FXMLLoader(interface0);
parent = loader.load();
controller = loader.getController();
stage.setScene(new Scene(parent));
stage.setResizable(false);
stage.setTitle(title());
stage.show();
} else {
throw new RuntimeException("Impossible to load interface.fxml file : the application can't start");
}
}

@Override
public void stop() throws Exception {
controller.stop(null);
stage.setScene(new Scene(mainWindow.getView()));
stage.setTitle(TITLE);
stage.show();
}

public static void main(String[] args) {
launch(args);
}

public static String getTempDirectory() {
return path + File.separator + ".cmpdl_temp";
}

public static String getZipFile() {
return getTempDirectory() + File.separator + zipFileName;
}

private static String getMinecraftDirectory() {
return path + File.separator + "minecraft";
}

public static String getModsDirectory() {
return getMinecraftDirectory() + File.separator + "mods";
}

public static String getInstanceFile() {
return path + File.separator + "instance.cfg";
}

public static String getManifestFile() {
return getTempDirectory() + File.separator + "manifest.json";
}

public static String toOverridePath(File file, String override) {
return file.getPath().replace(".cmpdl_temp" + File.separator + override, "minecraft");
Unirest.clearDefaultHeaders();
Unirest.setDefaultHeader("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));
if (args.length == 0) {
launch(args);
} else {
// DO SOMETHING
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/github/franckyi/cmpdl/ControllerView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.franckyi.cmpdl;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

import java.io.IOException;

public class ControllerView<T> {

private final Parent view;
private final T controller;
private EnumContent enumContent;

public ControllerView(String res) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(res));
view = loader.load();
controller = loader.getController();
}

public ControllerView(String res, EnumContent enumContent) throws IOException {
this(res);
this.enumContent = enumContent;
}

public Parent getView() {
return view;
}

public T getController() {
return controller;
}

public EnumContent getEnumContent() {
return enumContent;
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/github/franckyi/cmpdl/CurseMetaAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.franckyi.cmpdl;

import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONArray;
import org.json.JSONObject;

public class CurseMetaAPI {

private static final String URL = "http://cursemeta.dries007.net/api/v2/direct";

public static JSONObject getProject(int projectId) throws UnirestException {
return get("/GetAddOn", projectId).getObject();
}

public static JSONArray getProjectFiles(int projectId) throws UnirestException {
return get("/GetAllFilesForAddOn", projectId).getArray();
}

public static JSONObject getProjectFile(int projectId, int fileId) throws UnirestException {
return get("/GetAddOnFile", projectId, fileId).getObject();
}

private static JsonNode get(String path, Object... args) throws UnirestException {
StringBuilder sb = new StringBuilder(URL + path);
for (Object o : args) {
sb.append("/").append(o);
}
return Unirest.get(sb.toString()).asJson().getBody();
}

}
5 changes: 5 additions & 0 deletions src/main/java/com/github/franckyi/cmpdl/EnumContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.franckyi.cmpdl;

public enum EnumContent {
MODPACK, FILE, DESTINATION, PROGRESS
}
Loading

0 comments on commit b82f3aa

Please sign in to comment.