summaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost
diff options
context:
space:
mode:
authorEthanDevelops <git@ethanlibs.co>2022-05-26 18:43:27 -0400
committerEthanDevelops <git@ethanlibs.co>2022-05-26 18:43:27 -0400
commitde1325f1cdac0c10052f4b5a6b78331185b2ca4c (patch)
tree4f318e87877081cdba17d6ba341202d3086f25f9 /src/main/java/cc/polyfrost
parent4cc9804bc6095e7648b21803302443fb598eaf0a (diff)
downloadOneConfigLoader-de1325f1cdac0c10052f4b5a6b78331185b2ca4c.tar.gz
OneConfigLoader-de1325f1cdac0c10052f4b5a6b78331185b2ca4c.tar.bz2
OneConfigLoader-de1325f1cdac0c10052f4b5a6b78331185b2ca4c.zip
format
Diffstat (limited to 'src/main/java/cc/polyfrost')
-rw-r--r--src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java b/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java
index d8622e2..7806a67 100644
--- a/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java
+++ b/src/main/java/cc/polyfrost/oneconfigloader/OneConfigLoader.java
@@ -26,27 +26,35 @@ public class OneConfigLoader implements IFMLLoadingPlugin {
public OneConfigLoader() {
File oneConfigDir = new File(Launch.minecraftHome, "OneConfig");
+
if (!oneConfigDir.exists() && !oneConfigDir.mkdir())
throw new IllegalStateException("Could not create OneConfig dir!");
+
File oneConfigFile = new File(oneConfigDir, "OneConfig (1.8.9).jar");
+
if (!isInitialized(oneConfigFile)) {
JsonElement json = getRequest("https://polyfrost.cc/static/oneconfig-versions.json");
+
if (json != null && json.isJsonObject()) {
JsonObject jsonObject = json.getAsJsonObject();
+
if (jsonObject.has("oneconfig") && jsonObject.getAsJsonObject("oneconfig").has("url")
&& jsonObject.getAsJsonObject("oneconfig").has("checksum")) {
+
String checksum = jsonObject.getAsJsonObject("oneconfig").get("checksum").getAsString();
String downloadUrl = jsonObject.getAsJsonObject("oneconfig").get("url").getAsString();
+
if (!oneConfigFile.exists() || !checksum.equals(getChecksum(oneConfigFile))) {
System.out.println("Updating OneConfig...");
+
File newOneConfigFile = new File(oneConfigDir, "OneConfig-NEW (1.8.9).jar");
downloadFile(downloadUrl, newOneConfigFile);
+
if (newOneConfigFile.exists() && checksum.equals(getChecksum(newOneConfigFile))) {
try {
Files.move(newOneConfigFile.toPath(), oneConfigFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
System.out.println("Updated OneConfig");
- } catch (IOException ignored) {
- }
+ } catch (IOException ignored) {}
} else {
if (newOneConfigFile.exists()) newOneConfigFile.delete();
System.out.println("Failed to update OneConfig, trying to continue...");
@@ -54,6 +62,7 @@ public class OneConfigLoader implements IFMLLoadingPlugin {
}
}
}
+
if (!oneConfigFile.exists()) throw new IllegalStateException("OneConfig jar doesn't exist");
addToClasspath(oneConfigFile);
}
@@ -67,6 +76,7 @@ public class OneConfigLoader implements IFMLLoadingPlugin {
private boolean isInitialized(File file) {
try {
URL url = file.toURI().toURL();
+
return Arrays.asList(((URLClassLoader) Launch.classLoader.getClass().getClassLoader()).getURLs()).contains(url);
} catch (MalformedURLException e) {
e.printStackTrace();