Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. package fr.epicdream.launcher;
  2.  
  3. import fr.epicdream.launcher.ui.LauncherFrame;
  4. import fr.epicdream.settings.GlobalSettings;
  5. import fr.epicdream.settings.LocalSettings;
  6. import fr.theshark34.openauth.AuthPoints;
  7. import fr.theshark34.openauth.AuthenticationException;
  8. import fr.theshark34.openauth.Authenticator;
  9. import fr.theshark34.openauth.model.AuthAgent;
  10. import fr.theshark34.openauth.model.response.AuthResponse;
  11. import fr.theshark34.openlauncherlib.LaunchException;
  12. import fr.theshark34.openlauncherlib.external.ExternalLaunchProfile;
  13. import fr.theshark34.openlauncherlib.external.ExternalLauncher;
  14. import fr.theshark34.openlauncherlib.minecraft.*;
  15. import fr.theshark34.supdate.BarAPI;
  16. import fr.theshark34.supdate.SUpdate;
  17. import fr.theshark34.supdate.application.integrated.FileDeleter;
  18.  
  19. import javax.swing.*;
  20. import java.io.File;
  21. import java.util.Arrays;
  22.  
  23. //import net.lingala.zip4j.exception.ZipException;
  24. //import net.lingala.zip4j.core.ZipFile;
  25.  
  26. public final class Launcher
  27. {
  28.  
  29. public static final GameVersion VERSION = new GameVersion("1.10.2", GameType.V1_8_HIGHER);
  30. public static final GameInfos INFOS = new GameInfos("EpicDream", VERSION, new GameTweak[]{GameTweak.FORGE});
  31. public static final File DIRECTORY = INFOS.getGameDir();
  32. public static final File CRASHS_DIR = new File(DIRECTORY, "crashlogs");
  33. public static LauncherFrame mainFrame;
  34. private static AuthInfos authinfos;
  35.  
  36. public static void auth(String username, String password) throws AuthenticationException
  37. {
  38. if(LauncherFrame.passwordField.isVisible()) {
  39. Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
  40. AuthResponse response = authenticator.authenticate(AuthAgent.MINECRAFT, username, password, "");
  41. authinfos = new AuthInfos(response.getSelectedProfile().getName(), response.getAccessToken(), response.getSelectedProfile().getId());
  42. System.out.println("Auth");
  43. } else {
  44. authinfos = new AuthInfos(username, "sry", "nope");
  45. }
  46. }
  47. public static File getDir(String name)
  48. {
  49. String os = System.getProperty("os.name").toLowerCase();
  50.  
  51. if (os.contains("win"))
  52. {
  53. return new File(System.getProperty("user.home") + "\\AppData\\Roaming\\" + name);
  54. }
  55. else
  56. {
  57. return os.contains("mac") ? new File(System.getProperty("user.home") + "/Library/Application Support/" + name) : new File(System.getProperty("user.home") + "/" + name);
  58. }
  59. }
  60.  
  61. public static void update() throws Exception
  62. {
  63. mainFrame.getBar().setVisible(true);
  64. mainFrame.getPlay().setEnabled(false);
  65. mainFrame.getUsernameField().setEnabled(false);
  66. mainFrame.getPasswordField().setEnabled(false);
  67. mainFrame.getSettings().setEnabled(false);
  68. mainFrame.getBar().setValue(0);
  69.  
  70. if (!DIRECTORY.exists())
  71. {
  72. DIRECTORY.mkdirs();
  73. }
  74.  
  75. SUpdate su = new SUpdate(GlobalSettings.S_UPDATE_LINK.getValue(), DIRECTORY);
  76. su.getServerRequester().setRewriteEnabled(true);
  77. su.addApplication(new FileDeleter());
  78.  
  79. Thread t = new Thread(() -> {
  80. int val;
  81. int max;
  82.  
  83. while (true)
  84. {
  85. val = (int) (BarAPI.getNumberOfTotalDownloadedBytes() / 1000);
  86. max = (int) (BarAPI.getNumberOfTotalBytesToDownload() / 1000);
  87. Launcher.mainFrame.getBar().setMaximum(max);
  88. Launcher.mainFrame.getBar().setValue(val);
  89. }
  90. });
  91. t.start();
  92. su.start();
  93. t.interrupt();
  94. mainFrame.getBar().setVisible(false);
  95. }
  96.  
  97. public static void launch(String username, String password) throws LaunchException
  98. {
  99. System.out.println("Online");
  100. ExternalLaunchProfile profile = MinecraftLauncher.createExternalProfile(INFOS, GameFolder.BASIC, authinfos);
  101. profile.getVmArgs().addAll(Arrays.asList(LocalSettings.getRamArg() + "", LocalSettings.JVM_ARGS.getValue()));
  102. profile.getArgs().addAll(Arrays.asList(LocalSettings.MC_ARGS.getValue()));
  103. ExternalLauncher launcher = new ExternalLauncher(profile);
  104.  
  105. LocalSettings.USERNAME.setValue(LocalSettings.KEEP_USERNAME.getValue() ? username : "");
  106. LocalSettings.PASSWORD.setValue(LocalSettings.KEEP_USERNAME.getValue() ? password : "");
  107. LocalSettings.PROPERTIES.save();
  108.  
  109. Process p = launcher.launch();
  110.  
  111. if (!LocalSettings.KEEP_OPEN.getValue())
  112. {
  113. System.exit(0);
  114. }
  115.  
  116. try
  117. {
  118. Thread.sleep(5000L);
  119.  
  120. p.waitFor();
  121. }
  122. catch (InterruptedException e)
  123. {
  124. e.printStackTrace();
  125. }
  126.  
  127. if (!p.isAlive())
  128. {
  129. mainFrame.getPlay().setEnabled(true);
  130. mainFrame.getUsernameField().setEnabled(true);
  131. mainFrame.getSettings().setEnabled(true);
  132. mainFrame.getPasswordField().setEnabled(true);
  133. }
  134.  
  135.  
  136. }
  137.  
  138.  
  139. public static void play(String username, String password)
  140. {
  141. if (username.replaceAll(" ", "").length() == 0 | password.replaceAll(" ", "").length() == 0)
  142. {
  143. JOptionPane.showMessageDialog(mainFrame, "Erreur veuillez entrer un pseudo valide et/ou un mot de passe valide.", "Erreur", JOptionPane.ERROR_MESSAGE);
  144. return;
  145. }
  146.  
  147. new Thread(() -> {
  148. try
  149. {
  150. Launcher.update();
  151. }
  152. catch (Exception e)
  153. {
  154. try
  155. {
  156. Launcher.launch(username, password);
  157. }
  158. catch (LaunchException a)
  159. {
  160. JOptionPane.showMessageDialog(mainFrame, "Impossible d'effectuer la mise à jour, merci de nous joindre le code d'erreur suivant : Chocolat", "Erreur", JOptionPane.ERROR_MESSAGE);
  161. a.printStackTrace();
  162. }
  163. }
  164. try
  165. {
  166. Launcher.launch(username, password);
  167. }
  168. catch (LaunchException l)
  169. {
  170. JOptionPane.showMessageDialog(mainFrame, "Impossible de demarrer le jeu, merci de nous joindre le code d'erreur suivant : M&N's", "Erreur", JOptionPane.ERROR_MESSAGE);
  171. l.printStackTrace();
  172. }
  173.  
  174. }).start();
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement