Advertisement
ClearRelic24

Untitled

Jun 11th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. package me.clearrelic24.crservlauncher;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  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.launcher.AuthInfos;
  12. import fr.theshark34.openlauncherlib.launcher.GameFolder;
  13. import fr.theshark34.openlauncherlib.launcher.GameInfos;
  14. import fr.theshark34.openlauncherlib.launcher.GameLauncher;
  15. import fr.theshark34.openlauncherlib.launcher.GameTweak;
  16. import fr.theshark34.openlauncherlib.launcher.GameType;
  17. import fr.theshark34.openlauncherlib.launcher.GameVersion;
  18. import fr.theshark34.supdate.BarAPI;
  19. import fr.theshark34.supdate.SUpdate;
  20. import fr.theshark34.supdate.application.integrated.FileDeleter;
  21. import fr.theshark34.swinger.Swinger;
  22.  
  23. public class Launcher {
  24.  
  25. public static final GameVersion CRSERV_VERSION = new GameVersion("1.7.10", GameType.V1_7_10);
  26. public static final GameInfos CRSERV_INFOS = new GameInfos("CRSERV", CRSERV_VERSION, true, new GameTweak[] {GameTweak.FORGE});
  27. public static final File CRSERV_DIR = CRSERV_INFOS.getGameDir();
  28.  
  29. private static AuthInfos authInfos;
  30. private static Thread updateThread;
  31.  
  32. public static void auth(String username, String password) throws AuthenticationException{
  33.  
  34. Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
  35. AuthResponse response = authenticator.authenticate(AuthAgent.MINECRAFT, username, password, "");
  36. authInfos = new AuthInfos(response.getSelectedProfile().getName(), response.getAccessToken(), response.getSelectedProfile().getId());
  37.  
  38. }
  39.  
  40.  
  41. public static void update() throws Exception{
  42. SUpdate su = new SUpdate("http://clearrelic24.esy.es/OLD_FILE/Launcher/", CRSERV_DIR);
  43. su.addApplication(new FileDeleter());
  44. updateThread = new Thread() {
  45. private int val;
  46. private int max;
  47. @Override
  48. public void run() {
  49.  
  50. while(!this.isInterrupted()) {
  51. if(BarAPI.getNumberOfFileToDownload() == 0) {
  52. LauncherFrame.getInstance().getLauncherPanel().setInfoText("Verification des fichiers");
  53. continue;
  54. }
  55.  
  56. val = (int) (BarAPI.getNumberOfTotalDownloadedBytes()/ 1000);
  57. max = (int) (BarAPI.getNumberOfTotalBytesToDownload()/ 1000);
  58.  
  59.  
  60. LauncherFrame.getInstance().getLauncherPanel().getProgressBar().setMaximum(max);
  61. LauncherFrame.getInstance().getLauncherPanel().getProgressBar().setValue(val);
  62. LauncherFrame.getInstance().getLauncherPanel().setInfoText(BarAPI.getNumberOfDownloadedFiles()+"/"+ BarAPI.getNumberOfFileToDownload()+" " +Swinger.percentage(val, max)+ " %");
  63. }
  64. }
  65. };
  66. updateThread.start();
  67.  
  68. su.start();
  69. updateThread.interrupt();
  70.  
  71. }
  72.  
  73. public static void launch() throws IOException{
  74. GameLauncher gameLauncher = new GameLauncher(CRSERV_INFOS, GameFolder.BASIC, authInfos);
  75. Process p = gameLauncher.launch();
  76. try {
  77. Thread.sleep(5000L);
  78. } catch(InterruptedException e) {
  79.  
  80. }
  81. LauncherFrame.getInstance().setVisible(false);
  82. try {
  83. p.waitFor();
  84.  
  85. }catch(InterruptedException e) {
  86.  
  87. }
  88. System.exit(0);
  89. }
  90.  
  91. public static void interruptThread() {
  92.  
  93. updateThread.interrupt();
  94.  
  95.  
  96. }
  97.  
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement