summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZekerZhayard <trees1000@qq.com>2021-12-22 22:28:35 +0800
committerZekerZhayard <trees1000@qq.com>2021-12-22 22:28:35 +0800
commit71ac68371b30097b887bb3635ea27c4dc91bca8b (patch)
tree64d02ad2d5f02073f4f56dd7686028b52508aba6
parentf0a1b27529e3512cc0a4aaf01f0fb94c5ff2fcbc (diff)
downloadProject-Tick-71ac68371b30097b887bb3635ea27c4dc91bca8b.tar.gz
Project-Tick-71ac68371b30097b887bb3635ea27c4dc91bca8b.zip
Use a better way to determine the installer version.
-rw-r--r--gradle.properties2
-rw-r--r--gradle/wrapper/gradle-wrapper.properties2
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java32
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java2
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java13
5 files changed, 20 insertions, 31 deletions
diff --git a/gradle.properties b/gradle.properties
index 29b7ba0097..85a1608512 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
org.gradle.daemon = false
-fw_version = 1.5.4
+fw_version = 1.5.5
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 3cd8500c13..669386b870 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java
index 72181dde2c..278688e773 100644
--- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java
@@ -1,18 +1,18 @@
package io.github.zekerzhayard.forgewrapper.installer;
import java.io.File;
-import java.lang.reflect.Method;
import io.github.zekerzhayard.forgewrapper.installer.util.AbstractInstaller;
import io.github.zekerzhayard.forgewrapper.installer.util.InstallerV0;
import io.github.zekerzhayard.forgewrapper.installer.util.InstallerV1;
import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.json.Install;
+import net.minecraftforge.installer.json.InstallV1;
import net.minecraftforge.installer.json.Util;
public class Installer {
- public static boolean install(File libraryDir, File minecraftJar, File installerJar, int installerSpec) {
- AbstractInstaller installer = getInstaller(installerSpec);
+ public static boolean install(File libraryDir, File minecraftJar, File installerJar) {
+ AbstractInstaller installer = createInstaller();
ProgressCallback monitor = ProgressCallback.withOutputs(System.out);
Install profile = installer.loadInstallProfile();
if (System.getProperty("java.net.preferIPv4Stack") == null) {
@@ -26,22 +26,18 @@ public class Installer {
return installer.runClientInstall(profile, monitor, libraryDir, minecraftJar, installerJar);
}
- private static AbstractInstaller getInstaller(int installerSpec) {
- switch (installerSpec) {
- case 0: {
- Boolean isV1 = false;
- Method[] methods = Util.class.getDeclaredMethods();
- for (Method method: methods) {
- String methodName = method.toString();
- if (methodName.contains("InstallV1") && methodName.contains("loadInstallProfile")) {
- isV1 = true;
- break;
- }
- }
- return isV1 ? new InstallerV1() : new InstallerV0();
+ private static AbstractInstaller createInstaller() {
+ try {
+ Class<?> installerClass = Util.class.getMethod("loadInstallProfile").getReturnType();
+ if (installerClass.equals(Install.class)) {
+ return new InstallerV0();
+ } else if (installerClass.equals(InstallV1.class)) {
+ return new InstallerV1();
+ } else {
+ throw new IllegalArgumentException("Unable to determine the installer version. (" + installerClass + ")");
}
- case 1: return new InstallerV1();
- default: throw new IllegalArgumentException("Invalid installer profile spec: " + installerSpec);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
}
}
}
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java
index 1df9aaacc7..7134ba5fff 100644
--- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java
@@ -47,7 +47,7 @@ public class Main {
installerJar.toUri().toURL()
}, ModuleUtil.getPlatformClassLoader())) {
Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");
- if (!(boolean) installer.getMethod("install", File.class, File.class, File.class, int.class).invoke(null, detector.getLibraryDir().toFile(), minecraftJar.toFile(), installerJar.toFile(), detector.getInstallProfileSpec(forgeFullVersion))) {
+ if (!(boolean) installer.getMethod("install", File.class, File.class, File.class).invoke(null, detector.getLibraryDir().toFile(), minecraftJar.toFile(), installerJar.toFile())) {
return;
}
}
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java
index 1bb024a80a..76df474631 100644
--- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/detector/IFileDetector.java
@@ -109,20 +109,13 @@ public interface IFileDetector {
/**
* @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
- * @return The installer specification version.
- */
- default int getInstallProfileSpec(String forgeFullVersion) {
- return this.getDataFromInstaller(forgeFullVersion, "install_profile.json", e -> e.getAsJsonObject().getAsJsonPrimitive("spec").getAsInt());
- }
-
- /**
- * @param forgeFullVersion Forge full version (e.g. 1.14.4-28.2.0).
* @return The json object in the-installer-jar-->install_profile.json-->data-->xxx-->client.
*/
default JsonObject getInstallProfileExtraData(String forgeFullVersion) {
return this.getDataFromInstaller(forgeFullVersion, "install_profile.json", e -> e.getAsJsonObject().getAsJsonObject("data"));
}
+ @SuppressWarnings("deprecation")
default <R> R getDataFromInstaller(String forgeFullVersion, String entry, Function<JsonElement, R> function) {
Path installer = this.getInstallerJar(forgeFullVersion);
if (isFile(installer)) {
@@ -186,7 +179,7 @@ public interface IFileDetector {
// Check all cached libraries.
boolean checked = true;
for (Map.Entry<String, Path> entry : libsMap.entrySet()) {
- checked = this.checkExtraFile(entry.getValue(), hashMap.get(entry.getKey() + "_SHA"));
+ checked = checkExtraFile(entry.getValue(), hashMap.get(entry.getKey() + "_SHA"));
if (!checked) {
System.out.println("Missing: " + entry.getValue());
break;
@@ -204,7 +197,7 @@ public interface IFileDetector {
* @param sha1 The sha1 defined in installer.
* @return True represents the file is ready.
*/
- default boolean checkExtraFile(Path path, String sha1) {
+ static boolean checkExtraFile(Path path, String sha1) {
return sha1 == null || sha1.equals("") || (isFile(path) && sha1.toLowerCase(Locale.ENGLISH).equals(getFileSHA1(path)));
}