Advertisement
Guest User

launcher

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