Advertisement
DarkWitch_

Untitled

Mar 4th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1. package fr.mine4craft.bootstrap;
  2.  
  3. import java.awt.Color;
  4. import java.io.File;
  5. import java.io.IOException;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. import fr.theshark34.openlauncherlib.bootstrap.Bootstrap;
  10. import fr.theshark34.openlauncherlib.bootstrap.LauncherClasspath;
  11. import fr.theshark34.openlauncherlib.bootstrap.LauncherInfos;
  12. import fr.theshark34.openlauncherlib.util.ErrorUtil;
  13. import fr.theshark34.openlauncherlib.util.GameDir;
  14. import fr.theshark34.openlauncherlib.util.SplashScreen;
  15. import fr.theshark34.supdate.BarAPI;
  16. import fr.theshark34.supdate.SUpdate;
  17. import fr.theshark34.supdate.application.integrated.FileDeleter;
  18. import fr.theshark34.swinger.Swinger;
  19. import fr.theshark34.swinger.textured.STexturedProgressBar;
  20.  
  21. @SuppressWarnings("serial")
  22. public class MyBootstrap extends JFrame{
  23.  
  24.     private static SplashScreen splash;
  25.     private static Thread barThread;
  26.     private static JLabel infoText = new JLabel("", 0);
  27.  
  28.     private static STexturedProgressBar bar ;
  29.     private static final LauncherInfos M4C_B_INFOS = new LauncherInfos("mine4craft", "fr.mine4craft.launcher.LauncherFrame");
  30.     private static File M4C_B_DIR = GameDir.createGameDir("Mine4Craft");
  31.     private static final LauncherClasspath M4C_B_CP = new LauncherClasspath(new File(M4C_B_DIR, "launcher.jar"), new File(M4C_B_DIR, "launcher_lib/"));
  32.     private static ErrorUtil errorUtil = new ErrorUtil(new File(M4C_B_DIR, "crashes"));
  33.    
  34.  
  35.     public static void main(String[] args) {
  36.         Swinger.setResourcePath("/fr/mine4craft/bootstrap/ressources/");
  37.         displaySplash();
  38.        
  39.         try {
  40.         doUpdate();
  41.         }
  42.         catch (Exception e){
  43.             errorUtil.catchError(e, "impossible de mettre a jour le launcher...");
  44.             barThread.interrupt();
  45.         }
  46.         try{
  47.         launchLauncher();
  48.         }
  49.         catch (IOException e){
  50.             errorUtil.catchError(e, "impossible de lancer le launcher...");
  51.  
  52.         }
  53.     }
  54.    
  55.    
  56.    
  57.     public static void displaySplash() {
  58.         splash = new SplashScreen("Mine4Craft", Swinger.getResource("backgroundbootstrap.png"));
  59.         splash.setLayout(null);
  60.         infoText.setBounds(300, 470, 300, 20);
  61.         infoText.setFont(infoText.getFont().deriveFont(20.0F));
  62.         infoText.setForeground(Color.WHITE);
  63.         splash.add(infoText);
  64.         bar = new STexturedProgressBar(Swinger.getResource("barre_vide.png"), Swinger.getResource("barre_pleine.png"));
  65.         bar.setBounds(0, 490, 900, 10);
  66.         splash.add(bar);
  67.         splash.setIconImage(Swinger.getResource("favicon.png"));
  68.        
  69.         splash.setVisible(true);
  70.        
  71.        
  72.     }
  73.    
  74.     public static void doUpdate() throws Exception{
  75.         SUpdate su = new SUpdate("http://mine4craft.fr/bootstrapdata/", M4C_B_DIR);
  76.          su.getServerRequester().setRewriteEnabled(true);
  77.          su.addApplication(new FileDeleter());
  78.        
  79.          
  80.         barThread = new Thread () {
  81.             @Override
  82.             public void run(){
  83.                 while(!this.isInterrupted()){
  84.                     infoText.setText("Verification du launcher");
  85.                     bar.setValue((int)(BarAPI.getNumberOfTotalDownloadedBytes()/ 1000));
  86.                     bar.setMaximum((int) (BarAPI.getNumberOfTotalBytesToDownload()/ 100));
  87.                    
  88.                 }
  89.             }
  90.         };
  91.         barThread.start();
  92.         su.start();
  93.         barThread.interrupt();
  94.        
  95.     }
  96.    
  97.     private static void launchLauncher() throws IOException{
  98.         Bootstrap bootstrap = new Bootstrap(M4C_B_CP, M4C_B_INFOS);
  99.         Process p = bootstrap.launch();
  100.         infoText.setText("Lancement du launcher");
  101.         splash.setVisible(false);
  102.         try {
  103.         p.waitFor();
  104.         }
  105.         catch (InterruptedException e){
  106.             System.exit(0);
  107.            
  108.         }
  109.     }
  110.    
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement