Advertisement
Guest User

Lancher.java

a guest
Feb 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. package fr.xolium.urafightlauncher;
  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 UF_VERSION = new GameVersion("1.7.10", GameType.V1_7_10);
  26. public static final GameInfos UF_INFOS = new GameInfos(".urafigth", UF_VERSION, true, new GameTweak[] {GameTweak.FORGE});
  27. public static final File UF_DIR = UF_INFOS.getGameDir();
  28. private static AuthInfos authInfos;
  29. private static Thread updateThread;
  30.  
  31. public static void auth(String username, String password)throws AuthenticationException{
  32. Authenticator authentificator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
  33. AuthResponse response = authentificator.authenticate(AuthAgent.MINECRAFT, username, password, "");
  34. authInfos = new AuthInfos(response.getSelectedProfile().getName(), response.getAccessToken(), response.getSelectedProfile().getId());
  35. }
  36. public static void update() throws Exception{
  37. SUpdate su = new SUpdate("https://urafight.000webhostapp.com/", UF_DIR);
  38.  
  39. //https://urafight.000webhostapp.com/
  40. su.addApplication(new FileDeleter());
  41.  
  42. updateThread = new Thread() {
  43. private int val;
  44. private int max;
  45.  
  46. @Override
  47. public void run() {
  48. while(!this.isInterrupted()) {
  49. if(BarAPI.getNumberOfFileToDownload() == 0) {
  50. LauncherFrame.getLauncherPanel().setInfoText("Verification des fichiers");
  51. continue;
  52. }
  53.  
  54. val = (int) (BarAPI.getNumberOfTotalDownloadedBytes() / 1000);
  55. max = (int) (BarAPI.getNumberOfTotalBytesToDownload() / 1000);
  56.  
  57. LauncherFrame.getLauncherPanel().getProgressBar().setMaximum(max);
  58. LauncherFrame.getLauncherPanel().getProgressBar().setValue(val);
  59.  
  60. LauncherFrame.getLauncherPanel().setInfoText("Telechargement des fichiers" + BarAPI.getNumberOfDownloadedFiles() + "/" + BarAPI.getNumberOfFileToDownload() + " " + Swinger.percentage(val, max) + "%");
  61. }
  62. }
  63. };
  64. updateThread.start();
  65.  
  66. su.start();
  67. updateThread.interrupt();
  68.  
  69. }
  70.  
  71. public static void launch() throws IOException{
  72. GameLauncher gamelauncher = new GameLauncher(UF_INFOS, GameFolder.BASIC, authInfos);
  73. Process p = gamelauncher.launch();
  74. try {
  75. Thread.sleep(5000L);
  76. }catch(InterruptedException e) {
  77. }
  78. LauncherFrame.getInstance().setVisible(false);
  79. try {
  80. p.waitFor();
  81. }catch(InterruptedException e) {
  82. }
  83. System.exit(0);
  84. }
  85.  
  86. public static void InterruptThread() {
  87. updateThread.interrupt();
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement