Advertisement
Guest User

Launcherjava

a guest
Aug 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. package fr.Tristan29490.EdgeCraft.launcher;
  2.  
  3. import java.io.File;
  4.  
  5. import fr.theshark34.openauth.AuthPoints;
  6. import fr.theshark34.openauth.AuthenticationException;
  7. import fr.theshark34.openauth.Authenticator;
  8. import fr.theshark34.openauth.model.AuthAgent;
  9. import fr.theshark34.openauth.model.response.AuthResponse;
  10. import fr.theshark34.openlauncherlib.LaunchException;
  11. import fr.theshark34.openlauncherlib.internal.InternalLaunchProfile;
  12. import fr.theshark34.openlauncherlib.internal.InternalLauncher;
  13. import fr.theshark34.openlauncherlib.minecraft.AuthInfos;
  14. import fr.theshark34.openlauncherlib.minecraft.GameFolder;
  15. import fr.theshark34.openlauncherlib.minecraft.GameInfos;
  16. import fr.theshark34.openlauncherlib.minecraft.GameTweak;
  17. import fr.theshark34.openlauncherlib.minecraft.GameType;
  18. import fr.theshark34.openlauncherlib.minecraft.GameVersion;
  19. import fr.theshark34.openlauncherlib.minecraft.MinecraftLauncher;
  20. import fr.theshark34.openlauncherlib.util.CrashReporter;
  21. import fr.theshark34.supdate.BarAPI;
  22. import fr.theshark34.supdate.SUpdate;
  23. import fr.theshark34.supdate.application.integrated.FileDeleter;
  24. import fr.theshark34.swinger.Swinger;
  25.  
  26. public class Launcher {
  27.  
  28. public static final GameVersion EC_VERSION = new GameVersion("1.7.10", GameType.V1_7_10);
  29. public static final GameInfos EC_INFOS = new GameInfos("EdgeCraft", EC_VERSION, new GameTweak[] {GameTweak.FORGE});
  30. public static final File EC_DIR = EC_INFOS.getGameDir();
  31. public static final File EC_CRASHES_DIR = new File(EC_DIR, "crashes");
  32.  
  33. private static AuthInfos authInfos;
  34. private static Thread updateThread;
  35.  
  36. private static CrashReporter crashReporter = new CrashReporter(null, EC_CRASHES_DIR);
  37.  
  38.  
  39. public static void auth(String username, String password) throws AuthenticationException {
  40. Authenticator authenticator = new Authenticator (Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
  41. AuthResponse response = authenticator.authenticate(AuthAgent.MINECRAFT, username, password, "");
  42. authInfos = new AuthInfos(response.getSelectedProfile().getName(), response.getAccessToken(), response.getSelectedProfile().getId());
  43. }
  44.  
  45.  
  46. public static void update() throws Exception {
  47. SUpdate su = new SUpdate("http://edgecraftlaunch.livehost.fr/supdate-launcher/", EC_DIR);
  48. su.addApplication(new FileDeleter());
  49. updateThread = new Thread() {
  50.  
  51. private int val;
  52. private int max;
  53.  
  54. @Override
  55. public void run() {
  56. while(!this.isInterrupted()) {
  57. if(BarAPI.getNumberOfFileToDownload() == 0) {
  58. Launcherframe.getInstance().getLauncherPanel().setInfoText("Verification des fichiers...");
  59. continue;
  60.  
  61. }
  62.  
  63. val = (int) (BarAPI.getNumberOfTotalDownloadedBytes() / 1000);
  64. max = (int) (BarAPI.getNumberOfTotalBytesToDownload() / 1000);
  65.  
  66. Launcherframe.getInstance().getLauncherPanel().getProgressBar().setMaximum(max);
  67. Launcherframe.getInstance().getLauncherPanel().getProgressBar().setValue(val);
  68.  
  69. Launcherframe.getInstance().getLauncherPanel().setInfoText("Telechargement des fichiers " + BarAPI.getNumberOfDownloadedFiles() + "/" + BarAPI.getNumberOfFileToDownload() +
  70. " " + Swinger.percentage(val, max) + "%");
  71. }
  72. }
  73. };
  74. updateThread.start();
  75.  
  76. su.start();
  77. updateThread.interrupt();
  78.  
  79.  
  80. }
  81.  
  82. public static void launch() throws LaunchException {
  83.  
  84.  
  85. InternalLaunchProfile profile = MinecraftLauncher.createInternalProfile(EC_INFOS, GameFolder.BASIC, authInfos);
  86. InternalLauncher launcher = new InternalLauncher(profile);
  87.  
  88.  
  89. Launcherframe.getInstance().setVisible(false);
  90.  
  91.  
  92. launcher.launch();
  93. System.exit(0);
  94. }
  95.  
  96. public static void interruptThread() {
  97. updateThread.interrupt();
  98.  
  99.  
  100. }
  101.  
  102. public static CrashReporter getErrorUtil() {
  103. return crashReporter;
  104. }
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement