-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForgeInstallWrapper.java
More file actions
78 lines (67 loc) · 2.09 KB
/
ForgeInstallWrapper.java
File metadata and controls
78 lines (67 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.net.URL;
import java.io.File;
import java.net.URLClassLoader;
import java.lang.reflect.Method;
import java.io.PrintStream;
import com.google.common.base.Predicate;
public class ForgeInstallWrapper {
private static File installerJar;
private static URLClassLoader loader;
@SuppressWarnings("rawtypes")
private static Class installerClass;
private static Method runnerMethod;
public static void main(String[] args) {
if (args.length == 2)
{
ForgeInstall(new File(args[0]), new File(args[1]));
}
else
{
System.out.println("Incorrect parameters");
}
}
@SuppressWarnings("unchecked")
public static void ForgeInstall(File _installerJar, File minecraftDir) {
installerJar = _installerJar;
System.out.println("Installing Forge from JAR");
try {
URL[] jarPath = { installerJar.toURI().toURL() };
loader = new URLClassLoader(jarPath, ForgeInstallWrapper.class.getClassLoader());
installerClass = Class.forName("net.minecraftforge.installer.ClientInstall", true, loader);
} catch (Throwable e) {
e.printStackTrace();
System.exit(-1);
}
try {
runnerMethod = installerClass.getMethod("run", File.class);
try {
Object instance = installerClass.newInstance();
Object result = runnerMethod.invoke(instance, minecraftDir);
} catch (Throwable e) {
System.out.println("Unable to install Forge");
System.exit(-1);
}
} catch (Throwable e1) {
try {
runnerMethod = installerClass.getMethod("run", File.class, Predicate.class);
Predicate<String> optPred = new Predicate<String>() {
@Override
public boolean apply(String s) {
return false;
}
};
try {
Object instance = installerClass.newInstance();
Object result = runnerMethod.invoke(instance, minecraftDir, optPred);
} catch (Throwable e) {
System.out.println("Unable to install Forge");
System.exit(-1);
}
} catch (Throwable e2) {
e2.printStackTrace();
System.exit(-1);
}
}
System.out.println("Forge update complete");
}
}