summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java7
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java8
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java12
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/MainV2.java15
-rw-r--r--src/main/java/io/github/zekerzhayard/forgewrapper/installer/util/InstallerUtil.java52
-rw-r--r--src/main/resources/META-INF/services/java.util.function.Consumer1
6 files changed, 82 insertions, 13 deletions
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java
index ea7256416c..6daa1e5371 100644
--- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/ClientInstall4MultiMC.java
@@ -6,19 +6,20 @@ import java.util.function.Predicate;
import net.minecraftforge.installer.actions.ClientInstall;
import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.json.Install;
+import net.minecraftforge.installer.json.InstallV1;
public class ClientInstall4MultiMC extends ClientInstall {
protected File libraryDir;
protected File minecraftJar;
public ClientInstall4MultiMC(Install profile, ProgressCallback monitor, File libraryDir, File minecraftJar) {
- super(profile, monitor);
+ super(profile instanceof InstallV1 ? (InstallV1) profile : new InstallV1(profile), monitor);
this.libraryDir = libraryDir;
this.minecraftJar = minecraftJar;
}
@Override
- public boolean run(File target, Predicate<String> optionals) {
- return this.processors.process(this.libraryDir, this.minecraftJar);
+ public boolean run(File target, Predicate<String> optionals, File installer) {
+ return this.processors.process(this.libraryDir, this.minecraftJar, this.libraryDir.getParentFile(), installer);
}
}
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 1a822ce06e..6294c77940 100644
--- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Installer.java
@@ -2,14 +2,14 @@ package io.github.zekerzhayard.forgewrapper.installer;
import java.io.File;
+import io.github.zekerzhayard.forgewrapper.installer.util.InstallerUtil;
import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.json.Install;
-import net.minecraftforge.installer.json.Util;
public class Installer {
- public static boolean install(File libraryDir, File minecraftJar) {
+ public static boolean install(File libraryDir, File minecraftJar, File installerJar, String forgeVersion) {
ProgressCallback monitor = ProgressCallback.withOutputs(System.out);
- Install install = Util.loadInstallProfile();
+ Install install = InstallerUtil.loadInstallProfile(forgeVersion);
if (System.getProperty("java.net.preferIPv4Stack") == null) {
System.setProperty("java.net.preferIPv4Stack", "true");
}
@@ -18,6 +18,6 @@ public class Installer {
String jvmVersion = System.getProperty("java.vm.version", "missing jvm version");
monitor.message(String.format("JVM info: %s - %s - %s", vendor, javaVersion, jvmVersion));
monitor.message("java.net.preferIPv4Stack=" + System.getProperty("java.net.preferIPv4Stack"));
- return new ClientInstall4MultiMC(install, monitor, libraryDir, minecraftJar).run(null, input -> true);
+ return InstallerUtil.runClientInstall(forgeVersion, install, monitor, libraryDir, minecraftJar, installerJar);
}
}
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 c52c272493..78c2d5880c 100644
--- a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/Main.java
@@ -3,7 +3,6 @@ package io.github.zekerzhayard.forgewrapper.installer;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
@@ -17,7 +16,8 @@ public class Main {
public static void main(String[] args) throws Exception {
List<String> argsList = Stream.of(args).collect(Collectors.toList());
String mcVersion = argsList.get(argsList.indexOf("--fml.mcVersion") + 1);
- String forgeFullVersion = mcVersion + "-" + argsList.get(argsList.indexOf("--fml.forgeVersion") + 1);
+ String forgeVersion = argsList.get(argsList.indexOf("--fml.forgeVersion") + 1);
+ String forgeFullVersion = mcVersion + "-" + forgeVersion;
IFileDetector detector = DetectorLoader.loadDetector();
if (!detector.checkExtraFiles(forgeFullVersion)) {
@@ -26,13 +26,13 @@ public class Main {
// Check installer jar.
Path installerJar = detector.getInstallerJar(forgeFullVersion);
if (!IFileDetector.isFile(installerJar)) {
- throw new RuntimeException("Can't detect the forge installer!");
+ throw new RuntimeException("Unable to detect the forge installer!");
}
// Check vanilla Minecraft jar.
Path minecraftJar = detector.getMinecraftJar(mcVersion);
if (!IFileDetector.isFile(minecraftJar)) {
- throw new RuntimeException("Can't detect the Minecraft jar!");
+ throw new RuntimeException("Unable to detect the Minecraft jar!");
}
try (URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {
@@ -41,13 +41,13 @@ public class Main {
installerJar.toUri().toURL()
}, getParentClassLoader())) {
Class<?> installer = ucl.loadClass("io.github.zekerzhayard.forgewrapper.installer.Installer");
- if (!(boolean) installer.getMethod("install", File.class, File.class).invoke(null, detector.getLibraryDir().toFile(), minecraftJar.toFile())) {
+ if (!(boolean) installer.getMethod("install", File.class, File.class, File.class, String.class).invoke(null, detector.getLibraryDir().toFile(), minecraftJar.toFile(), installerJar.toFile(), forgeVersion)) {
return;
}
}
}
- Launcher.main(args);
+ Launcher.main(args); // TODO: this will be broken in forge 1.17
}
// https://github.com/MinecraftForge/Installer/blob/fe18a164b5ebb15b5f8f33f6a149cc224f446dc2/src/main/java/net/minecraftforge/installer/actions/PostProcessors.java#L287-L303
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/MainV2.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/MainV2.java
new file mode 100644
index 0000000000..230d9fbe28
--- /dev/null
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/MainV2.java
@@ -0,0 +1,15 @@
+package io.github.zekerzhayard.forgewrapper.installer;
+
+import java.util.function.Consumer;
+
+// to support forge 1.17 (bootstraplauncher)
+public class MainV2 implements Consumer<String[]> {
+ @Override
+ public void accept(String[] args) {
+ try {
+ Main.main(args);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+}
diff --git a/src/main/java/io/github/zekerzhayard/forgewrapper/installer/util/InstallerUtil.java b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/util/InstallerUtil.java
new file mode 100644
index 0000000000..26f11ce583
--- /dev/null
+++ b/src/main/java/io/github/zekerzhayard/forgewrapper/installer/util/InstallerUtil.java
@@ -0,0 +1,52 @@
+package io.github.zekerzhayard.forgewrapper.installer.util;
+
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import io.github.zekerzhayard.forgewrapper.installer.ClientInstall4MultiMC;
+import io.github.zekerzhayard.forgewrapper.installer.LegacyClientInstall4MultiMC;
+import net.minecraftforge.installer.actions.ProgressCallback;
+import net.minecraftforge.installer.json.Install;
+import net.minecraftforge.installer.json.Util;
+
+public class InstallerUtil {
+ public static Install loadInstallProfile(String forgeVersion) {
+ if (isLegacyForge(forgeVersion, "36.1.65")) {
+ return LegacyInstallerUtil.loadInstallProfile();
+ } else {
+ // to prevent ClassNotFoundException
+ return new Object() {
+ public Install get() {
+ return Util.loadInstallProfile();
+ }
+ }.get();
+ }
+ }
+
+ public static boolean runClientInstall(String forgeVersion, Install profile, ProgressCallback monitor, File libraryDir, File minecraftJar, File installerJar) {
+ if (isLegacyForge(forgeVersion, "36.1.65")) {
+ return new LegacyClientInstall4MultiMC(profile, monitor, libraryDir, minecraftJar).run(null, input -> true);
+ } else {
+ return new ClientInstall4MultiMC(profile, monitor, libraryDir, minecraftJar).run(null, input -> true, installerJar);
+ }
+ }
+
+ private final static Pattern FORGE_VERSION_PATTERN = Pattern.compile("(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<build>\\d+)");
+ private static boolean isLegacyForge(String forgeVersion, String legacyForgeVersion) {
+ Matcher m0 = FORGE_VERSION_PATTERN.matcher(forgeVersion);
+ Matcher m1 = FORGE_VERSION_PATTERN.matcher(legacyForgeVersion);
+ if (m0.find() && m1.find()) {
+ return compareVersion(m0, m1, 0, "major", "minor", "build");
+ }
+ throw new RuntimeException("Missing forge version!");
+ }
+
+ private static boolean compareVersion(Matcher m0, Matcher m1, int index, String... groups) {
+ if (index == groups.length) return true; // the same as the legacy version
+ int result = Integer.compare(Integer.parseInt(m0.group(groups[index])), Integer.parseInt(m1.group(groups[index])));
+ if (result < 0) return true; // less than the legacy version
+ if (result > 0) return false; // greater than the legacy version
+ return compareVersion(m0, m1, index + 1, groups);
+ }
+}
diff --git a/src/main/resources/META-INF/services/java.util.function.Consumer b/src/main/resources/META-INF/services/java.util.function.Consumer
new file mode 100644
index 0000000000..64cc969425
--- /dev/null
+++ b/src/main/resources/META-INF/services/java.util.function.Consumer
@@ -0,0 +1 @@
+io.github.zekerzhayard.forgewrapper.installer.MainV2 \ No newline at end of file