Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. package com.drastiam.launcher;
  2.  
  3. import java.io.File;
  4. import java.util.Arrays;
  5.  
  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.AuthInfos;
  15. import fr.theshark34.openlauncherlib.minecraft.GameFolder;
  16. import fr.theshark34.openlauncherlib.minecraft.GameInfos;
  17. import fr.theshark34.openlauncherlib.minecraft.GameTweak;
  18. import fr.theshark34.openlauncherlib.minecraft.GameType;
  19. import fr.theshark34.openlauncherlib.minecraft.GameVersion;
  20. import fr.theshark34.openlauncherlib.minecraft.MinecraftLauncher;
  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 D_VERSION = new GameVersion("1.12.2", GameType.V1_8_HIGHER);
  29. public static final GameInfos D_INFOS = new GameInfos("EasyMC.V.1", D_VERSION, new GameTweak[] {GameTweak.FORGE});
  30. public static final File D_DIR = D_INFOS.getGameDir();
  31. public static final File D_CRASHES = new File(D_DIR, "crashes");
  32.  
  33.  
  34. private static AuthInfos authInfos;
  35. private static Thread updateThread;
  36.  
  37. public static void auth(String username, String password) throws AuthenticationException
  38. {
  39. Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
  40. AuthResponse response = authenticator.authenticate(AuthAgent.MINECRAFT, username, password, "");
  41.  
  42. authInfos = new AuthInfos(response.getSelectedProfile().getName(), response.getAccessToken(), response.getSelectedProfile().getId());
  43. }
  44.  
  45. public static void update() throws Exception
  46. {
  47. SUpdate su = new SUpdate("http://easymc.livehost.fr/", D_DIR);
  48.  
  49. su.addApplication(new FileDeleter());
  50.  
  51. updateThread = new Thread()
  52. {
  53. private int val;
  54. private int max;
  55. @Override
  56. public void run()
  57. {
  58. while(!this.isInterrupted())
  59. {
  60. if(BarAPI.getNumberOfFileToDownload() == 0)
  61. {
  62. LauncherFrame.getInstance().getLauncherPanel().setInfoText("Vérification des fichiers...");
  63. continue;
  64. }
  65. val = (int)(BarAPI.getNumberOfTotalDownloadedBytes() / 1000);
  66. max = (int)(BarAPI.getNumberOfTotalBytesToDownload() / 1000);
  67.  
  68. LauncherFrame.getInstance().getLauncherPanel().getProgressBar().setMaximum(max);
  69. LauncherFrame.getInstance().getLauncherPanel().getProgressBar().setValue(val);
  70.  
  71. LauncherFrame.getInstance().getLauncherPanel().setInfoText("Téléchargement des fichiers : " +
  72. BarAPI.getNumberOfDownloadedFiles() + "/" + BarAPI.getNumberOfFileToDownload() + " "+
  73. Swinger.percentage(val, max) + "%");
  74.  
  75. }
  76. }
  77. };
  78.  
  79. updateThread.start();
  80.  
  81. su.start();
  82. updateThread.interrupt();
  83. }
  84.  
  85.  
  86. public static void launch() throws LaunchException
  87. {
  88. ExternalLaunchProfile profile = MinecraftLauncher.createExternalProfile(D_INFOS, GameFolder.BASIC, authInfos);
  89. profile.getVmArgs().addAll(Arrays.asList(LauncherFrame.getInstance().getLauncherPanel().getRamSelector().getRamArguments()));
  90. ExternalLauncher launcher = new ExternalLauncher(profile);
  91.  
  92. LauncherFrame.getInstance().setVisible(false);
  93.  
  94. launcher.launch();
  95. System.exit(0);
  96. }
  97.  
  98. public static void interruptThread()
  99. {
  100. updateThread.interrupt();
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement