-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLauncher.java
112 lines (88 loc) · 4.21 KB
/
Launcher.java
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package fr.nemixcraft.launcher;
import java.io.File;
import java.io.IOException;
import fr.litarvan.openauth.AuthPoints;
import fr.litarvan.openauth.AuthenticationException;
import fr.litarvan.openauth.Authenticator;
import fr.litarvan.openauth.microsoft.MicrosoftAuthResult;
import fr.litarvan.openauth.microsoft.MicrosoftAuthenticationException;
import fr.litarvan.openauth.microsoft.MicrosoftAuthenticator;
import fr.litarvan.openauth.model.AuthAgent;
import fr.litarvan.openauth.model.response.AuthResponse;
import fr.theshark34.openlauncherlib.launcher.AuthInfos;
import fr.theshark34.openlauncherlib.launcher.GameFolder;
import fr.theshark34.openlauncherlib.launcher.GameInfos;
import fr.theshark34.openlauncherlib.launcher.GameLauncher;
import fr.theshark34.openlauncherlib.launcher.GameTweak;
import fr.theshark34.openlauncherlib.launcher.GameType;
import fr.theshark34.openlauncherlib.launcher.GameVersion;
import fr.theshark34.openlauncherlib.util.ErrorUtil;
import fr.theshark34.supdate.BarAPI;
import fr.theshark34.supdate.SUpdate;
import fr.theshark34.supdate.application.integrated.FileDeleter;
import fr.theshark34.swinger.Swinger;
public class Launcher {
public static final GameVersion SC_VERSION = new GameVersion("1.7.10", GameType.V1_7_10);
public static final GameInfos SC_INFOS = new GameInfos("Nemixcraft", SC_VERSION, true, new GameTweak[] {GameTweak.FORGE});
public static final File SC_DIR = SC_INFOS.getGameDir();
public static final File SC_CRASH_DIR = new File(SC_DIR, "CRASH");
private static AuthInfos authInfos;
private static Thread updateThread;
private static ErrorUtil errorUtil = new ErrorUtil(SC_CRASH_DIR);
public static void authJava(String username, String password) throws AuthenticationException {
Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
AuthResponse responce = authenticator.authenticate(AuthAgent.MINECRAFT, username, password, "");
authInfos = new AuthInfos(responce.getSelectedProfile().getName(), responce.getAccessToken(), responce.getSelectedProfile().getId());
}
public static void authMicrosoft(String email, String password) throws MicrosoftAuthenticationException {
MicrosoftAuthenticator authenticator = new MicrosoftAuthenticator();
MicrosoftAuthResult result = authenticator.loginWithCredentials(email, password);
authInfos = new AuthInfos(result.getProfile().getName(), result.getAccessToken(), result.getProfile().getId());
}
public static void update() throws Exception {
SUpdate su = new SUpdate("https://nemixcraft.com/minecraft/launcher/", SC_DIR);
su.getServerRequester().setRewriteEnabled(true);
su.addApplication(new FileDeleter());
updateThread= new Thread() {
private int val;
private int max;
@Override
public void run() {
while (!this.isInterrupted()) {
if(BarAPI.getNumberOfFileToDownload() == 0) {
LauncherFrame.getInstance().getLauncherPanel().setInfoText("Verification des fichiers");
continue;
}
val = (int) (BarAPI.getNumberOfTotalDownloadedBytes() / 1000);
max = (int) (BarAPI.getNumberOfTotalBytesToDownload() / 1000);
LauncherFrame.getInstance().getLauncherPanel().progressBar().setMaximum(max);
LauncherFrame.getInstance().getLauncherPanel().progressBar().setValue(val);
LauncherFrame.getInstance().getLauncherPanel().setInfoText("Téléchargement " + BarAPI.getNumberOfDownloadedFiles() + "/" + BarAPI.getNumberOfFileToDownload() + " " + Swinger.percentage(val, max) + "%");
}
}
};
updateThread.start();
su.start();
updateThread.interrupt();
}
public static void launch() throws IOException{
GameLauncher gameLauncher = new GameLauncher(SC_INFOS, GameFolder.BASIC, authInfos);
Process p = gameLauncher.launch();
try {
Thread.sleep(5000);
}catch (InterruptedException e) {
}
LauncherFrame.getInstance().setVisible(false);
try {
p.waitFor();
}catch (InterruptedException e) {
}
System.exit(0);
}
public static void interruptTread() {
updateThread.interrupt();
}
public static ErrorUtil getErrorUtil() {
return errorUtil;
}
}