[Tuto] Créé son Launcher en java ( win / mac / linux ...)!

Utile ?

  • Oui , super !!

    Votes: 57 91.9%
  • Non , arrête tout de suite ....

    Votes: 0 0.0%
  • Pas pour moi , mais merci !

    Votes: 5 8.1%

  • Total voters
    62

Theknarfal

Architecte en herbe
15 Septembre 2011
172
32
135
26
In a Minecraft World
Salut !

Je suis ici pour vous faire un petit tuto' , qui , j'espère aidera quelque personne .
Je voulais faire un tuto' video , mais ce fus un échec total a cause de mon jeune age et de mon inexpérimentation en vidéo . Bref , voici ce petit tuto .
/!\ Tuto pas bien rédiger et avec des bugs ! /!\ Voici le même tuto bien présenter et aucun bugs http://ironcraft.fr/forum/viewtopic.php?f=43&t=1373 Le tuto est encore la , sous les Spoilers !
Il vous suffis de télécharger :
- Le Launcher + pack de jar --> http://www.mediafire.com/?1qo20r3fxoe8iyk
- Jd-gui ---> http://java.decompiler.free.fr/?q=jdgui
- Eclipse --> http://www.eclipse.org/downloads/

Ce qui peut être utile :
Paint.net ou gimp ou photoshop ou tout autre logiciel d'image .
C'est tout !

1 ] Faites clique droit sur le Launcher -> Extraire vers Launcher Perso

2 ] Suprimer les fichiers SAUF "net"

3] Ouvrir JD-Gui et y clisser déposer un des fichiers class qui se trouve dans "net"

4] File -> Save all source

5] Extraire le fichier zip ou rar

6] Ouvrez eclipse -> File -> New > Java Project -> Decocher la case "Use default Location" -> Browse ->Allez cherche le fichier "parent" de "net" Puis cliquez sur finish .

9] Dans "Package explorer" votre projet devrais apparaitre , cliquez dessus puis sur net.minecraft et ouvrez "GameUpdate.java" et collez y ceci :

Code:
/*    */ package net.minecraft;
/*    */
/*    */ import java.applet.Applet;
/*    */ import java.io.DataInputStream;
/*    */ import java.io.DataOutputStream;
/*    */ import java.io.File;
/*    */ import java.io.FileInputStream;
/*    */ import java.io.FileOutputStream;
/*    */ import java.io.FilePermission;
/*    */ import java.io.IOException;
/*    */ import java.io.InputStream;
/*    */ import java.io.OutputStream;
/*    */ import java.io.PrintStream;
/*    */ import java.io.PrintWriter;
/*    */ import java.io.StringWriter;
/*    */ import java.io.Writer;
/*    */ import java.lang.reflect.Constructor;
/*    */ import java.lang.reflect.Field;
/*    */ import java.lang.reflect.Method;
/*    */ import java.net.HttpURLConnection;
/*    */ import java.net.JarURLConnection;
/*    */ import java.net.SocketPermission;
/*    */ import java.net.URI;
/*    */ import java.net.URL;
/*    */ import java.net.URLClassLoader;
/*    */ import java.net.URLConnection;
/*    */ import java.security.AccessControlException;
/*    */ import java.security.AccessController;
/*    */ import java.security.CodeSource;
/*    */ import java.security.PermissionCollection;
/*    */ import java.security.PrivilegedExceptionAction;
/*    */ import java.security.ProtectionDomain;
/*    */ import java.security.SecureClassLoader;
/*    */ import java.security.cert.Certificate;
/*    */ import java.util.Enumeration;
/*    */ import java.util.StringTokenizer;
/*    */ import java.util.Vector;
/*    */ import java.util.jar.JarEntry;
/*    */ import java.util.jar.JarFile;
/*    */ import java.util.jar.JarOutputStream;
/*    */ import java.util.jar.Pack200;
/*    */ import java.util.jar.Pack200.Unpacker;
/*    */
/*    */ public class GameUpdater
/*    */  implements Runnable
/*    */ {
/*    */  public static final int STATE_INIT = 1;
/*    */  public static final int STATE_DETERMINING_PACKAGES = 2;
/*    */  public static final int STATE_CHECKING_CACHE = 3;
/*    */  public static final int STATE_DOWNLOADING = 4;
/*    */  public static final int STATE_EXTRACTING_PACKAGES = 5;
/*    */  public static final int STATE_UPDATING_CLASSPATH = 6;
/*    */  public static final int STATE_SWITCHING_APPLET = 7;
/*    */  public static final int STATE_INITIALIZE_REAL_APPLET = 8;
/*    */  public static final int STATE_START_REAL_APPLET = 9;
/*    */  public static final int STATE_DONE = 10;
/*    */  public int percentage;
/*    */  public int currentSizeDownload;
/*    */  public int totalSizeDownload;
/*    */  public int currentSizeExtract;
/*    */  public int totalSizeExtract;
/*    */  protected URL[] urlList;
/*    */  private static ClassLoader classLoader;
/*    */  protected Thread loaderThread;
/*    */  protected Thread animationThread;
/*    */  public boolean fatalError;
/*    */  public String fatalErrorDescription;
/*  80 */  protected String subtaskMessage = "";
/*  81 */  protected int state = 1;
/*    */
/*  83 */  protected boolean lzmaSupported = false;
/*  84 */  protected boolean pack200Supported = false;
/*    */
/*  86 */  protected String[] genericErrorMessage = { "An error occured while loading the applet.", "Please contact support to resolve this issue.", "<placeholder for error message>" };
/*    */  protected boolean certificateRefused;
/*  90 */  protected String[] certificateRefusedMessage = { "Permissions for Applet Refused.", "Please accept the permissions dialog to allow", "the applet to continue the loading process." };
/*    */
/*  92 */  protected static boolean natives_loaded = false;
/*    */  private String latestVersion;
/*    */  private String mainGameUrl;
/*    */
/*    */  public GameUpdater(String latestVersion, String mainGameUrl)
/*    */  {
/*  97 */    this.latestVersion = latestVersion;
/*  98 */    this.mainGameUrl = mainGameUrl;
/*    */  }
/*    */
/*    */  public void init() {
/* 102 */    this.state = 1;
/*    */    try
/*    */    {
/* 105 */      Class.forName("LZMA.LzmaInputStream");
/* 106 */      this.lzmaSupported = true;
/*    */    }
/*    */    catch (Throwable localThrowable) {
/*    */    }
/*    */    try {
/* 111 */      Pack200.class.getSimpleName();
/* 112 */      this.pack200Supported = true;
/*    */    } catch (Throwable localThrowable1) {
/*    */    }
/*    */  }
/*    */
/*    */  private String generateStacktrace(Exception exception) {
/* 118 */    Writer result = new StringWriter();
/* 119 */    PrintWriter printWriter = new PrintWriter(result);
/* 120 */    exception.printStackTrace(printWriter);
/* 121 */    return result.toString();
/*    */  }
/*    */
/*    */  protected String getDescriptionForState()
/*    */  {
/* 129 */    switch (this.state) {
/*    */    case 1:
/* 131 */      return "Initializing loader";
/*    */    case 2:
/* 133 */      return "Determining packages to load";
/*    */    case 3:
/* 135 */      return "Checking cache for existing files";
/*    */    case 4:
/* 137 */      return "Downloading packages";
/*    */    case 5:
/* 139 */      return "Extracting downloaded packages";
/*    */    case 6:
/* 141 */      return "Updating classpath";
/*    */    case 7:
/* 143 */      return "Switching applet";
/*    */    case 8:
/* 145 */      return "Initializing real applet";
/*    */    case 9:
/* 147 */      return "Starting real applet";
/*    */    case 10:
/* 149 */      return "Done loading";
/*    */    }
/* 151 */    return "unknown state";
/*    */  }
/*    */
/*    */  protected String trimExtensionByCapabilities(String file)
/*    */  {
/* 156 */    if (!this.pack200Supported) {
/* 157 */      file = file.replaceAll(".pack", "");
/*    */    }
/*    */
/* 160 */    if (!this.lzmaSupported) {
/* 161 */      file = file.replaceAll(".lzma", "");
/*    */    }
/* 163 */    return file;
/*    */  }
/*    */
/*    */  protected void loadJarURLs() throws Exception {
/* 167 */    this.state = 2;
/* 168 */    String jarList = "lwjgl.jar, jinput.jar, lwjgl_util.jar, " + this.mainGameUrl;
/* 169 */    jarList = trimExtensionByCapabilities(jarList);
/*    */
/* 171 */    StringTokenizer jar = new StringTokenizer(jarList, ", ");
/* 172 */    int jarCount = jar.countTokens() + 1;
/*    */
/* 174 */    this.urlList = new URL[jarCount];
/*    */
/* 176 */    URL path = new URL("http://s3.amazonaws.com/MinecraftDownload/");
/*    */
/* 178 */    for (int i = 0; i < jarCount - 1; i++) {
/* 179 */      this.urlList[i] = new URL(path, jar.nextToken());
/*    */    }
/*    */
/* 182 */    String osName = System.getProperty("os.name");
/* 183 */    String nativeJar = null;
/*    */
/* 185 */    if (osName.startsWith("Win"))
/* 186 */      nativeJar = "windows_natives.jar.lzma";
/* 187 */    else if (osName.startsWith("Linux"))
/* 188 */      nativeJar = "linux_natives.jar.lzma";
/* 189 */    else if (osName.startsWith("Mac"))
/* 190 */      nativeJar = "macosx_natives.jar.lzma";
/* 191 */    else if ((osName.startsWith("Solaris")) || (osName.startsWith("SunOS")))
/* 192 */      nativeJar = "solaris_natives.jar.lzma";
/*    */    else {
/* 194 */      fatalErrorOccured("OS (" + osName + ") not supported", null);
/*    */    }
/*    */
/* 197 */    if (nativeJar == null) {
/* 198 */      fatalErrorOccured("no lwjgl natives files found", null);
/*    */    } else {
/* 200 */      nativeJar = trimExtensionByCapabilities(nativeJar);
/* 201 */      this.urlList[(jarCount - 1)] = new URL(path, nativeJar);
/*    */    }
/*    */  }
/*    */
/*    */  public void run()
/*    */  {
/* 207 */    init();
/* 208 */    this.state = 3;
/*    */
/* 210 */    this.percentage = 5;
/*    */    try
/*    */    {
/* 213 */      loadJarURLs();
/*    */
/* 215 */      String path = (String)AccessController.doPrivileged(new PrivilegedExceptionAction() {
/*    */        public Object run() throws Exception {
/* 217 */          return Util.getWorkingDirectory() + File.separator + "bin" + File.separator;
/*    */        }
/*    */      });
/* 221 */      File dir = new File(path);
/*    */
/* 223 */      if (!dir.exists()) {
/* 224 */        dir.mkdirs();
/*    */      }
/*    */
/* 227 */      if (this.latestVersion != null) {
/* 228 */        File versionFile = new File(dir, "version");
/*    */
/* 230 */        boolean cacheAvailable = false;
/* 231 */        if ((versionFile.exists()) && (
/* 232 */          (this.latestVersion.equals("-1")) || (this.latestVersion.equals(readVersionFile(versionFile))))) {
/* 233 */          cacheAvailable = true;
/* 234 */          this.percentage = 90;
/*    */        }
/*    */
/* 238 */        if (!cacheAvailable) {
/* 239 */          downloadJars(path);
/* 240 */          extractJars(path);
/* 241 */          extractNatives(path);
/*    */
/* 243 */          if (this.latestVersion != null) {
/* 244 */            this.percentage = 90;
/* 245 */            writeVersionFile(versionFile, this.latestVersion);
/*    */          }
/*    */        }
/*    */      }
/*    */
/* 250 */      updateClassPath(dir);
/* 251 */      this.state = 10;
/*    */    } catch (AccessControlException ace) {
/* 253 */      fatalErrorOccured(ace.getMessage(), ace);
/* 254 */      this.certificateRefused = true;
/*    */    } catch (Exception e) {
/* 256 */      fatalErrorOccured(e.getMessage(), e);
/*    */    } finally {
/* 258 */      this.loaderThread = null;
/*    */    }
/*    */  }
/*    */
/*    */  protected String readVersionFile(File file) throws Exception {
/* 263 */    DataInputStream dis = new DataInputStream(new FileInputStream(file));
/* 264 */    String version = dis.readUTF();
/* 265 */    dis.close();
/* 266 */    return version;
/*    */  }
/*    */
/*    */  protected void writeVersionFile(File file, String version) throws Exception {
/* 270 */    DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
/* 271 */    dos.writeUTF(version);
/* 272 */    dos.close();
/*    */  }
/*    */
/*    */  protected void updateClassPath(File dir)
/*    */    throws Exception
/*    */  {
/* 278 */    this.state = 6;
/*    */
/* 280 */    this.percentage = 95;
/*    */
/* 282 */    URL[] urls = new URL[this.urlList.length];
/* 283 */    for (int i = 0; i < this.urlList.length; i++) {
/* 284 */      urls[i] = new File(dir, getJarName(this.urlList[i])).toURI().toURL();
/*    */    }
/*    */
/* 287 */    if (classLoader == null) {
/* 288 */      classLoader = new URLClassLoader(urls) {
/*    */        protected PermissionCollection getPermissions(CodeSource codesource) {
/* 290 */          PermissionCollection perms = null;
/*    */          try
/*    */          {
/* 294 */            Method method = SecureClassLoader.class.getDeclaredMethod("getPermissions", new Class[] { CodeSource.class });
/* 295 */            method.setAccessible(true);
/* 296 */            perms = (PermissionCollection)method.invoke(getClass().getClassLoader(), new Object[] { codesource });
/*    */
/* 298 */            String host = "www.minecraft.net";
/*    */
/* 300 */            if ((host != null) && (host.length() > 0))
/*    */            {
/* 302 */              perms.add(new SocketPermission(host, "connect,accept"));
/*    */            } else codesource.getLocation().getProtocol().equals("file");
/*    */
/* 306 */            perms.add(new FilePermission("<<ALL FILES>>", "read"));
/*    */          }
/*    */          catch (Exception e) {
/* 309 */            e.printStackTrace();
/*    */          }
/*    */
/* 312 */          return perms;
/*    */        }
/*    */      };
/*    */    }
/* 317 */    String path = dir.getAbsolutePath();
/* 318 */    if (!path.endsWith(File.separator)) path = path + File.separator;
/* 319 */    unloadNatives(path);
/*    */
/* 321 */    System.setProperty("org.lwjgl.librarypath", path + "natives");
/* 322 */    System.setProperty("net.java.games.input.librarypath", path + "natives");
/*    */
/* 324 */    natives_loaded = true;
/*    */  }
/*    */
/*    */  private void unloadNatives(String nativePath)
/*    */  {
/* 329 */    if (!natives_loaded) {
/* 330 */      return;
/*    */    }
/*    */    try
/*    */    {
/* 334 */      Field field = ClassLoader.class.getDeclaredField("loadedLibraryNames");
/* 335 */      field.setAccessible(true);
/* 336 */      Vector libs = (Vector)field.get(getClass().getClassLoader());
/*    */
/* 338 */      String path = new File(nativePath).getCanonicalPath();
/*    */
/* 340 */      for (int i = 0; i < libs.size(); i++) {
/* 341 */        String s = (String)libs.get(i);
/*    */
/* 343 */        if (s.startsWith(path)) {
/* 344 */          libs.remove(i);
/* 345 */          i--;
/*    */        }
/*    */      }
/*    */    } catch (Exception e) {
/* 349 */      e.printStackTrace();
/*    */    }
/*    */  }
/*    */
/*    */  public Applet createApplet() throws ClassNotFoundException, InstantiationException, IllegalAccessException
/*    */  {
/* 355 */    Class appletClass = classLoader.loadClass("net.minecraft.client.MinecraftApplet");
/* 356 */    return (Applet)appletClass.newInstance();
/*    */  }
/*    */
/*    */  protected void downloadJars(String path)
/*    */    throws Exception
/*    */  {
/* 384 */    this.state = 4;
/*    */
/* 389 */    int[] fileSizes = new int[this.urlList.length];
/*    */
/* 392 */    for (int i = 0; i < this.urlList.length; i++) {
/* 393 */      System.out.println(this.urlList[i]);
/* 394 */      URLConnection urlconnection = this.urlList[i].openConnection();
/* 395 */      urlconnection.setDefaultUseCaches(false);
/* 396 */      if ((urlconnection instanceof HttpURLConnection)) {
/* 397 */        ((HttpURLConnection)urlconnection).setRequestMethod("HEAD");
/*    */      }
/* 399 */      fileSizes[i] = urlconnection.getContentLength();
/* 400 */      this.totalSizeDownload += fileSizes[i];
/*    */    }
/*    */
/* 403 */    int initialPercentage = this.percentage = 10;
/*    */
/* 406 */    byte[] buffer = new byte[65536];
/* 407 */    for (int i = 0; i < this.urlList.length; i++)
/*    */    {
/* 409 */      int unsuccessfulAttempts = 0;
/* 410 */      int maxUnsuccessfulAttempts = 3;
/* 411 */      boolean downloadFile = true;
/*    */
/* 414 */      while (downloadFile) {
/* 415 */        downloadFile = false;
/*    */
/* 417 */        URLConnection urlconnection = this.urlList[i].openConnection();
/*    */
/* 419 */        if ((urlconnection instanceof HttpURLConnection)) {
/* 420 */          urlconnection.setRequestProperty("Cache-Control", "no-cache");
/* 421 */          urlconnection.connect();
/*    */        }
/*    */
/* 424 */        String currentFile = getFileName(this.urlList[i]);
/* 425 */        InputStream inputstream = getJarInputStream(currentFile, urlconnection);
/* 426 */        FileOutputStream fos = new FileOutputStream(path + currentFile);
/*    */
/* 430 */        long downloadStartTime = System.currentTimeMillis();
/* 431 */        int downloadedAmount = 0;
/* 432 */        int fileSize = 0;
/* 433 */        String downloadSpeedMessage = "";
/*    */        int bufferSize;
/* 435 */        while ((bufferSize = inputstream.read(buffer, 0, buffer.length)) != -1)
/*    */        {
/* 436 */          fos.write(buffer, 0, bufferSize);
/* 437 */          this.currentSizeDownload += bufferSize;
/* 438 */          fileSize += bufferSize;
/* 439 */          this.percentage = (initialPercentage + this.currentSizeDownload * 45 / this.totalSizeDownload);
/* 440 */          this.subtaskMessage = ("Retrieving: " + currentFile + " " + this.currentSizeDownload * 100 / this.totalSizeDownload + "%");
/*    */
/* 442 */          downloadedAmount += bufferSize;
/* 443 */          long timeLapse = System.currentTimeMillis() - downloadStartTime;
/*    */
/* 445 */          if (timeLapse >= 1000L)
/*    */          {
/* 447 */            float downloadSpeed = downloadedAmount / (float)timeLapse;
/*    */
/* 449 */            downloadSpeed = (int)(downloadSpeed * 100.0F) / 100.0F;
/*    */
/* 451 */            downloadSpeedMessage = " @ " + downloadSpeed + " KB/sec";
/*    */
/* 453 */            downloadedAmount = 0;
/*    */
/* 455 */            downloadStartTime += 1000L;
/*    */          }
/*    */
/* 458 */          this.subtaskMessage += downloadSpeedMessage;
/*    */        }
/*    */
/* 461 */        inputstream.close();
/* 462 */        fos.close();
/*    */
/* 465 */        if ((!(urlconnection instanceof HttpURLConnection)) ||
/* 466 */          (fileSize == fileSizes[i]))
/*    */          continue;
/* 468 */        if (fileSizes[i] <= 0)
/*    */        {
/*    */          continue;
/*    */        }
/* 472 */        unsuccessfulAttempts++;
/*    */
/* 474 */        if (unsuccessfulAttempts < maxUnsuccessfulAttempts) {
/* 475 */          downloadFile = true;
/* 476 */          this.currentSizeDownload -= fileSize;
/*    */        }
/*    */        else {
/* 479 */          throw new Exception("failed to download " + currentFile);
/*    */        }
/*    */      }
/*    */
/*    */    }
/*    */
/* 485 */    this.subtaskMessage = "";
/*    */  }
/*    */
/*    */  protected InputStream getJarInputStream(String currentFile, final URLConnection urlconnection)
/*    */    throws Exception
/*    */  {
/* 496 */    final InputStream[] is = new InputStream[1];
/*    */
/* 500 */    for (int j = 0; (j < 3) && (is[0] == null); j++) {
/* 501 */      Thread t = new Thread() {
/*    */        public void run() {
/*    */          try {
/* 504 */            is[0] = urlconnection.getInputStream();
/*    */          }
/*    */          catch (IOException localIOException)
/*    */          {
/*    */          }
/*    */        }
/*    */      };
/* 510 */      t.setName("JarInputStreamThread");
/* 511 */      t.start();
/*    */
/* 513 */      int iterationCount = 0;
/* 514 */      while ((is[0] == null) && (iterationCount++ < 5)) {
/*    */        try {
/* 516 */          t.join(1000L);
/*    */        }
/*    */        catch (InterruptedException localInterruptedException)
/*    */        {
/*    */        }
/*    */      }
/* 522 */      if (is[0] != null) continue;
/*    */      try {
/* 524 */        t.interrupt();
/* 525 */        t.join();
/*    */      }
/*    */      catch (InterruptedException localInterruptedException1)
/*    */      {
/*    */      }
/*    */    }
/*    */
/* 532 */    if (is[0] == null) {
/* 533 */      if (currentFile.equals("minecraft.jar")) {
/* 534 */        throw new Exception("Unable to download " + currentFile);
/*    */      }
/* 536 */      throw new Exception("Unable to download " + currentFile);
/*    */    }
/*    */
/* 541 */    return is[0];
/*    */  }
/*    */
/*    */  protected void extractLZMA(String in, String out)
/*    */    throws Exception
/*    */  {
/* 553 */    File f = new File(in);
/* 554 */    FileInputStream fileInputHandle = new FileInputStream(f);
/*    */
/* 557 */    Class clazz = Class.forName("LZMA.LzmaInputStream");
/* 558 */    Constructor constructor = clazz.getDeclaredConstructor(new Class[] { InputStream.class });
/* 559 */    InputStream inputHandle = (InputStream)constructor.newInstance(new Object[] { fileInputHandle });
/*    */
/* 562 */    OutputStream outputHandle = new FileOutputStream(out);
/*    */
/* 564 */    byte[] buffer = new byte[16384];
/*    */
/* 566 */    int ret = inputHandle.read(buffer);
/* 567 */    while (ret >= 1) {
/* 568 */      outputHandle.write(buffer, 0, ret);
/* 569 */      ret = inputHandle.read(buffer);
/*    */    }
/*    */
/* 572 */    inputHandle.close();
/* 573 */    outputHandle.close();
/*    */
/* 575 */    outputHandle = null;
/* 576 */    inputHandle = null;
/*    */
/* 579 */    f.delete();
/*    */  }
/*    */
/*    */  protected void extractPack(String in, String out)
/*    */    throws Exception
/*    */  {
/* 590 */    File f = new File(in);
/* 591 */    FileOutputStream fostream = new FileOutputStream(out);
/* 592 */    JarOutputStream jostream = new JarOutputStream(fostream);
/*    */
/* 594 */    Pack200.Unpacker unpacker = Pack200.newUnpacker();
/* 595 */    unpacker.unpack(f, jostream);
/* 596 */    jostream.close();
/*    */
/* 599 */    f.delete();
/*    */  }
/*    */
/*    */  protected void extractJars(String path)
/*    */    throws Exception
/*    */  {
/* 609 */    this.state = 5;
/*    */
/* 611 */    float increment = 10.0F / this.urlList.length;
/*    */
/* 613 */    for (int i = 0; i < this.urlList.length; i++) {
/* 614 */      this.percentage = (55 + (int)(increment * (i + 1)));
/* 615 */      String filename = getFileName(this.urlList[i]);
/*    */
/* 617 */      if (filename.endsWith(".pack.lzma")) {
/* 618 */        this.subtaskMessage = ("Extracting: " + filename + " to " + filename.replaceAll(".lzma", ""));
/* 619 */        extractLZMA(path + filename, path + filename.replaceAll(".lzma", ""));
/*    */
/* 621 */        this.subtaskMessage = ("Extracting: " + filename.replaceAll(".lzma", "") + " to " + filename.replaceAll(".pack.lzma", ""));
/* 622 */        extractPack(path + filename.replaceAll(".lzma", ""), path + filename.replaceAll(".pack.lzma", ""));
/* 623 */      } else if (filename.endsWith(".pack")) {
/* 624 */        this.subtaskMessage = ("Extracting: " + filename + " to " + filename.replace(".pack", ""));
/* 625 */        extractPack(path + filename, path + filename.replace(".pack", ""));
/* 626 */      } else if (filename.endsWith(".lzma")) {
/* 627 */        this.subtaskMessage = ("Extracting: " + filename + " to " + filename.replace(".lzma", ""));
/* 628 */        extractLZMA(path + filename, path + filename.replace(".lzma", ""));
/*    */      }
/*    */    }
/*    */  }
/*    */
/*    */  protected void extractNatives(String path) throws Exception
/*    */  {
/* 635 */    this.state = 5;
/*    */
/* 637 */    int initialPercentage = this.percentage;
/*    */
/* 639 */    String nativeJar = getJarName(this.urlList[(this.urlList.length - 1)]);
/*    */
/* 641 */    Certificate[] certificate = Launcher.class.getProtectionDomain().getCodeSource().getCertificates();
/*    */
/* 643 */    if (certificate == null) {
/* 644 */      URL location = Launcher.class.getProtectionDomain().getCodeSource().getLocation();
/*    */
/* 646 */      JarURLConnection jurl = (JarURLConnection)new URL("jar:" + location.toString() + "!/net/minecraft/Launcher.class").openConnection();
/* 647 */      jurl.setDefaultUseCaches(true);
/*    */      try {
/* 649 */        certificate = jurl.getCertificates();
/*    */      }
/*    */      catch (Exception localException)
/*    */      {
/*    */      }
/*    */    }
/* 655 */    File nativeFolder = new File(path + "natives");
/* 656 */    if (!nativeFolder.exists()) {
/* 657 */      nativeFolder.mkdir();
/*    */    }
/*    */
/* 660 */    JarFile jarFile = new JarFile(path + nativeJar, true);
/* 661 */    Enumeration entities = jarFile.entries();
/*    */
/* 663 */    this.totalSizeExtract = 0;
/*    */
/* 666 */    while (entities.hasMoreElements()) {
/* 667 */      JarEntry entry = (JarEntry)entities.nextElement();
/*    */
/* 671 */      if ((entry.isDirectory()) || (entry.getName().indexOf('/') != -1)) {
/*    */        continue;
/*    */      }
/* 674 */      this.totalSizeExtract = (int)(this.totalSizeExtract + entry.getSize());
/*    */    }
/*    */
/* 677 */    this.currentSizeExtract = 0;
/*    */
/* 679 */    entities = jarFile.entries();
/*    */
/* 681 */    while (entities.hasMoreElements()) {
/* 682 */      JarEntry entry = (JarEntry)entities.nextElement();
/*    */
/* 684 */      if ((entry.isDirectory()) || (entry.getName().indexOf('/') != -1))
/*    */      {
/*    */        continue;
/*    */      }
/* 688 */      File f = new File(path + "natives" + File.separator + entry.getName());
/* 689 */      if ((f.exists()) &&
/* 690 */        (!f.delete()))
/*    */      {
/*    */        continue;
/*    */      }
/*    */
/* 695 */      InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName()));
/* 696 */      OutputStream out = new FileOutputStream(path + "natives" + File.separator + entry.getName());
/*    */
/* 699 */      byte[] buffer = new byte[65536];
/*    */      int bufferSize;
/* 701 */      while ((bufferSize = in.read(buffer, 0, buffer.length)) != -1)
/*    */      {
/* 702 */        out.write(buffer, 0, bufferSize);
/* 703 */        this.currentSizeExtract += bufferSize;
/*    */
/* 705 */        this.percentage = (initialPercentage + this.currentSizeExtract * 20 / this.totalSizeExtract);
/* 706 */        this.subtaskMessage = ("Extracting: " + entry.getName() + " " + this.currentSizeExtract * 100 / this.totalSizeExtract + "%");
/*    */      }
/*    */
/* 709 */      validateCertificateChain(certificate, entry.getCertificates());
/*    */
/* 711 */      in.close();
/* 712 */      out.close();
/*    */    }
/* 714 */    this.subtaskMessage = "";
/*    */
/* 716 */    jarFile.close();
/*    */
/* 718 */    File f = new File(path + nativeJar);
/* 719 */    f.delete();
/*    */  }
/*    */
/*    */  protected static void validateCertificateChain(Certificate[] ownCerts, Certificate[] native_certs)
/*    */    throws Exception
/*    */  {
/* 729 */    if (ownCerts == null) return;
/* 730 */    if (native_certs == null) throw new Exception("Unable to validate certificate chain. Native entry did not have a certificate chain at all");
/*    */
/* 732 */    if (ownCerts.length != native_certs.length) throw new Exception("Unable to validate certificate chain. Chain differs in length [" + ownCerts.length + " vs " + native_certs.length + "]");
/*    */
/* 734 */    for (int i = 0; i < ownCerts.length; i++)
/* 735 */      if (!ownCerts[i].equals(native_certs[i]))
/* 736 */        throw new Exception("Certificate mismatch: " + ownCerts[i] + " != " + native_certs[i]);
/*    */  }
/*    */
/*    */  protected String getJarName(URL url)
/*    */  {
/* 742 */    String fileName = url.getFile();
/*    */
/* 744 */    if (fileName.contains("?")) {
/* 745 */      fileName = fileName.substring(0, fileName.indexOf("?"));
/*    */    }
/* 747 */    if (fileName.endsWith(".pack.lzma"))
/* 748 */      fileName = fileName.replaceAll(".pack.lzma", "");
/* 749 */    else if (fileName.endsWith(".pack"))
/* 750 */      fileName = fileName.replaceAll(".pack", "");
/* 751 */    else if (fileName.endsWith(".lzma")) {
/* 752 */      fileName = fileName.replaceAll(".lzma", "");
/*    */    }
/*    */
/* 755 */    return fileName.substring(fileName.lastIndexOf('/') + 1);
/*    */  }
/*    */
/*    */  protected String getFileName(URL url) {
/* 759 */    String fileName = url.getFile();
/* 760 */    if (fileName.contains("?")) {
/* 761 */      fileName = fileName.substring(0, fileName.indexOf("?"));
/*    */    }
/* 763 */    return fileName.substring(fileName.lastIndexOf('/') + 1);
/*    */  }
/*    */
/*    */  protected void fatalErrorOccured(String error, Exception e) {
/* 767 */    e.printStackTrace();
/* 768 */    this.fatalError = true;
/* 769 */    this.fatalErrorDescription = ("Fatal error occured (" + this.state + "): " + error);
/* 770 */    System.out.println(this.fatalErrorDescription);
/* 771 */    if (e != null)
/* 772 */      System.out.println(generateStacktrace(e));
/*    */  }
/*    */
/*    */  public boolean canPlayOffline()
/*    */  {
/*    */    try
/*    */    {
/* 779 */      String path = (String)AccessController.doPrivileged(new PrivilegedExceptionAction() {
/*    */        public Object run() throws Exception {
/* 781 */          return Util.getWorkingDirectory() + File.separator + "bin" + File.separator;
/*    */        }
/*    */      });
/* 785 */      File dir = new File(path);
/* 786 */      if (!dir.exists()) return false;
/*    */
/* 788 */      dir = new File(dir, "version");
/* 789 */      if (!dir.exists()) return false;
/*    */
/* 791 */      if (dir.exists()) {
/* 792 */        String version = readVersionFile(dir);
/* 793 */        if ((version != null) && (version.length() > 0))
/* 794 */          return true;
/*    */      }
/*    */    }
/*    */    catch (Exception e) {
/* 798 */      e.printStackTrace();
/* 799 */      return false;
/*    */    }
/* 801 */    return false;
/*    */  }
/*    */ }
 
*/
10] Ouvez "LoginForm.java" et y copier / remplacer ceci :

Code:
 /*    */ package net.minecraft;
 
/*    */
 
/*    */ import java.awt.BorderLayout;
 
/*    */ import java.awt.Button;
 
/*    */ import java.awt.Checkbox;
 
/*    */ import java.awt.Color;
 
/*    */ import java.awt.Cursor;
 
/*    */ import java.awt.Desktop;
 
/*    */ import java.awt.Font;
 
/*    */ import java.awt.FontMetrics;
 
/*    */ import java.awt.Graphics;
 
/*    */ import java.awt.GridBagLayout;
 
/*    */ import java.awt.GridLayout;
 
/*    */ import java.awt.HeadlessException;
 
/*    */ import java.awt.Image;
 
/*    */ import java.awt.Insets;
 
/*    */ import java.awt.Label;
 
/*    */ import java.awt.Panel;
 
/*    */ import java.awt.Rectangle;
 
/*    */ import java.awt.TextField;
 
/*    */ import java.awt.event.ActionEvent;
 
/*    */ import java.awt.event.ActionListener;
 
/*    */ import java.awt.event.MouseAdapter;
 
/*    */ import java.awt.event.MouseEvent;
 
/*    */ import java.awt.image.BufferedImage;
 
/*    */ import java.awt.image.VolatileImage;
 
/*    */ import java.io.DataInputStream;
 
/*    */ import java.io.DataOutputStream;
 
/*    */ import java.io.File;
 
/*    */ import java.io.FileInputStream;
 
/*    */ import java.io.FileOutputStream;
 
/*    */ import java.io.IOException;
 
/*    */ import java.net.URL;
 
/*    */ import java.util.Random;
 
/*    */ import javax.crypto.Cipher;
 
/*    */ import javax.crypto.CipherInputStream;
 
/*    */ import javax.crypto.CipherOutputStream;
 
/*    */ import javax.crypto.SecretKey;
 
/*    */ import javax.crypto.SecretKeyFactory;
 
/*    */ import javax.crypto.spec.PBEKeySpec;
 
/*    */ import javax.crypto.spec.PBEParameterSpec;
 
/*    */ import javax.imageio.ImageIO;
 
/*    */
 
/*    */ public class LoginForm extends Panel
 
/*    */ {
 
/*    */  private static final long serialVersionUID = 1L;
 
/*    */  private Image bgImage;
 
/*  18 */  private TextField userName = new TextField(20);
 
/*  19 */  private TextField password = new TextField(20);
 
/*  20 */  private Checkbox rememberBox = new Checkbox("Remember password");
 
/*  21 */  private Button launchButton = new Button("Login");
 
/*  22 */  private Button retryButton = new Button("Try again");
 
/*  23 */  private Button offlineButton = new Button("Play offline");
 
/*  24 */  private Label errorLabel = new Label("", 1);
 
/*    */  private LauncherFrame launcherFrame;
 
/*  26 */  private boolean outdated = false;
 
/*    */  private VolatileImage img;
 
/*    */
 
/*    */  public LoginForm(final LauncherFrame launcherFrame)
 
/*    */  {
 
/*  29 */    this.launcherFrame = launcherFrame;
 
/*    */
 
/*  31 */    GridBagLayout gbl = new GridBagLayout();
 
/*  32 */    setLayout(gbl);
 
/*    */
 
/*  34 */    add(buildLoginPanel());
 
/*    */    try
 
/*    */    {
 
/*  37 */      this.bgImage = ImageIO.read(LoginForm.class.getResource("dirt.png")).getScaledInstance(32, 32, 16);
 
/*    */    } catch (IOException e) {
 
/*  39 */      e.printStackTrace();
 
/*    */    }
 
/*    */
 
/*  42 */    readUsername();
 
/*    */
 
/*  44 */    this.retryButton.addActionListener(new ActionListener() {
 
/*    */      public void actionPerformed(ActionEvent ae) {
 
/*  46 */        LoginForm.this.errorLabel.setText("");
 
/*  47 */        LoginForm.this.removeAll();
 
/*  48 */        LoginForm.this.add(LoginForm.this.buildLoginPanel());
 
/*  49 */        LoginForm.this.validate();
 
/*    */      }
 
/*    */    });
 
/*  53 */    this.offlineButton.addActionListener(new ActionListener() {
 
/*    */      public void actionPerformed(ActionEvent ae) {
 
/*  55 */        launcherFrame.playCached(LoginForm.this.userName.getText());
 
/*    */      }
 
/*    */    });
 
/*  59 */    this.launchButton.addActionListener(new ActionListener() {
 
/*    */      public void actionPerformed(ActionEvent ae) {
 
/*  61 */        launcherFrame.login(LoginForm.this.userName.getText(), LoginForm.this.password.getText());
 
/*    */      } } );
 
/*    */  }
 
/*    */
 
/*    */  private void readUsername() {
 
/*    */    try {
 
/*  68 */      File lastLogin = new File(Util.getWorkingDirectory(), "lastlogin");
 
/*    */
 
/*  70 */      Cipher cipher = getCipher(2, "passwordfile");
 
/*    */      DataInputStream dis;
 
/*  71 */      if (cipher != null)
 
/*  72 */        dis = new DataInputStream(new CipherInputStream(new FileInputStream(lastLogin), cipher));
 
/*    */      else {
 
/*  74 */        dis = new DataInputStream(new FileInputStream(lastLogin));
 
/*    */      }
 
/*  76 */      this.userName.setText(dis.readUTF());
 
/*  77 */      this.password.setText(dis.readUTF());
 
/*  78 */      this.rememberBox.setState(this.password.getText().length() > 0);
 
/*  79 */      dis.close();
 
/*    */    } catch (Exception e) {
 
/*  81 */      e.printStackTrace();
 
/*    */    }
 
/*    */  }
 
/*    */
 
/*    */  private void writeUsername() {
 
/*    */    try {
 
/*  87 */      File lastLogin = new File(Util.getWorkingDirectory(), "lastlogin");
 
/*    */
 
/*  89 */      Cipher cipher = getCipher(1, "passwordfile");
 
/*    */      DataOutputStream dos;
 
/*  90 */      if (cipher != null)
 
/*  91 */        dos = new DataOutputStream(new CipherOutputStream(new FileOutputStream(lastLogin), cipher));
 
/*    */      else {
 
/*  93 */        dos = new DataOutputStream(new FileOutputStream(lastLogin));
 
/*    */      }
 
/*  95 */      dos.writeUTF(this.userName.getText());
 
/*  96 */      dos.writeUTF(this.rememberBox.getState() ? this.password.getText() : "");
 
/*  97 */      dos.close();
 
/*    */    } catch (Exception e) {
 
/*  99 */      e.printStackTrace();
 
/*    */    }
 
/*    */  }
 
/*    */
 
/*    */  private Cipher getCipher(int mode, String password) throws Exception {
 
/* 104 */    Random random = new Random(43287234L);
 
/* 105 */    byte[] salt = new byte[8];
 
/* 106 */    random.nextBytes(salt);
 
/* 107 */    PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
 
/*    */
 
/* 109 */    SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(password.toCharArray()));
 
/* 110 */    Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
 
/* 111 */    cipher.init(mode, pbeKey, pbeParamSpec);
 
/* 112 */    return cipher;
 
/*    */  }
 
/*    */
 
/*    */  public void update(Graphics g) {
 
/* 116 */    paint(g);
 
/*    */  }
 
/*    */
 
/*    */  public void paint(Graphics g2)
 
/*    */  {
 
/* 122 */    int w = getWidth() / 2;
 
/* 123 */    int h = getHeight() / 2;
 
/* 124 */    if ((this.img == null) || (this.img.getWidth() != w) || (this.img.getHeight() != h)) {
 
/* 125 */      this.img = createVolatileImage(w, h);
 
/*    */    }
 
/*    */
 
/* 128 */    Graphics g = this.img.getGraphics();
 
/* 129 */    for (int x = 0; x <= w / 32; x++) {
 
/* 130 */      for (int y = 0; y <= h / 32; y++)
 
/* 131 */        g.drawImage(this.bgImage, x * 32, y * 32, null);
 
/*    */    }
 
/* 133 */    g.setColor(Color.LIGHT_GRAY);
 
/*    */
 
/* 137 */    String msg = "Minecraft Launcher";
 
/* 138 */    g.setFont(new Font(null, 1, 20));
 
/* 139 */    FontMetrics fm = g.getFontMetrics();
 
/* 140 */    g.drawString(msg, w / 2 - fm.stringWidth(msg) / 2, h / 2 - fm.getHeight() * 2);
 
/*    */
 
/* 142 */    g.dispose();
 
/* 143 */    g2.drawImage(this.img, 0, 0, w * 2, h * 2, null);
 
/*    */  }
 
/*    */
 
/*    */  private Panel buildLoginPanel() {
 
/* 147 */    Panel panel = new Panel()
 
/*    */    {
 
/*    */      private static final long serialVersionUID = 1L;
 
/* 150 */      private Insets insets = new Insets(12, 24, 16, 32);
 
/*    */
 
/*    */      public Insets getInsets() {
 
/* 153 */        return this.insets;
 
/*    */      }
 
/*    */
 
/*    */      public void update(Graphics g) {
 
/* 157 */        paint(g);
 
/*    */      }
 
/*    */
 
/*    */      public void paint(Graphics g) {
 
/* 161 */        super.paint(g);
 
/* 162 */        int hOffs = 0;
 
/*    */
 
/* 164 */        g.setColor(Color.BLACK);
 
/* 165 */        g.drawRect(0, 0 + hOffs, getWidth() - 1, getHeight() - 1 - hOffs);
 
/* 166 */        g.drawRect(1, 1 + hOffs, getWidth() - 3, getHeight() - 3 - hOffs);
 
/* 167 */        g.setColor(Color.WHITE);
 
/*    */
 
/* 169 */        g.drawRect(2, 2 + hOffs, getWidth() - 5, getHeight() - 5 - hOffs);
 
/*    */      }
 
/*    */    };
 
/* 173 */    panel.setBackground(Color.GRAY);
 
/* 174 */    BorderLayout layout = new BorderLayout();
 
/* 175 */    layout.setHgap(0);
 
/* 176 */    layout.setVgap(8);
 
/* 177 */    panel.setLayout(layout);
 
/*    */
 
/* 180 */    GridLayout gl1 = new GridLayout(0, 1);
 
/* 181 */    GridLayout gl2 = new GridLayout(0, 1);
 
/* 182 */    gl1.setVgap(2);
 
/* 183 */    gl2.setVgap(2);
 
/* 184 */    Panel titles = new Panel(gl1);
 
/* 185 */    Panel values = new Panel(gl2);
 
/*    */
 
/* 187 */    titles.add(new Label("Username:", 2));
 
/* 188 */    titles.add(new Label("Password:", 2));
 
/* 189 */    titles.add(new Label("", 2));
 
/*    */
 
/* 191 */    this.password.setEchoChar('*');
 
/* 192 */    values.add(this.userName);
 
/* 193 */    values.add(this.password);
 
/* 194 */    values.add(this.rememberBox);
 
/*    */
 
/* 196 */    panel.add(titles, "West");
 
/* 197 */    panel.add(values, "Center");
 
/*    */
 
/* 199 */    Panel loginPanel = new Panel(new BorderLayout());
 
/*    */
 
/* 201 */    Panel registerPanel = new Panel(new BorderLayout());
 
/*    */    try {
 
/* 203 */      if (this.outdated) {
 
/* 204 */        Label accountLink = new Label("You need to update the launcher!") {
 
/*    */          private static final long serialVersionUID = 0L;
 
/*    */
 
/* 208 */          public void paint(Graphics g) { super.paint(g);
 
/*    */
 
/* 210 */            int x = 0;
 
/* 211 */            int y = 0;
 
/*    */
 
/* 215 */            FontMetrics fm = g.getFontMetrics();
 
/* 216 */            int width = fm.stringWidth(getText());
 
/* 217 */            int height = fm.getHeight();
 
/*    */
 
/* 219 */            if (getAlignment() == 0) x = 0;
 
/* 220 */            else if (getAlignment() == 1) x = getBounds().width / 2 - width / 2;
 
/* 221 */            else if (getAlignment() == 2) x = getBounds().width - width;
 
/* 222 */            y = getBounds().height / 2 + height / 2 - 1;
 
/*    */
 
/* 224 */            g.drawLine(x + 2, y, x + width - 2, y); }
 
/*    */
 
/*    */          public void update(Graphics g)
 
/*    */          {
 
/* 228 */            paint(g);
 
/*    */          }
 
/*    */        };
 
/* 232 */        accountLink.setCursor(Cursor.getPredefinedCursor(12));
 
/* 233 */        accountLink.addMouseListener(new MouseAdapter() {
 
/*    */          public void mousePressed(MouseEvent arg0) {
 
/*    */            try {
 
/* 236 */              Desktop.getDesktop().browse(new URL("http://www.minecraft.net/download.jsp").toURI());
 
/*    */            } catch (Exception e) {
 
/* 238 */              e.printStackTrace();
 
/*    */            }
 
/*    */          }
 
/*    */        });
 
/* 242 */        accountLink.setForeground(Color.BLUE);
 
/* 243 */        registerPanel.add(accountLink, "West");
 
/* 244 */        registerPanel.add(new Panel(), "Center");
 
/*    */      } else {
 
/* 246 */        Label accountLink = new Label("Need account?") {
 
/*    */          private static final long serialVersionUID = 0L;
 
/*    */
 
/* 250 */          public void paint(Graphics g) { super.paint(g);
 
/*    */
 
/* 252 */            int x = 0;
 
/* 253 */            int y = 0;
 
/*    */
 
/* 257 */            FontMetrics fm = g.getFontMetrics();
 
/* 258 */            int width = fm.stringWidth(getText());
 
/* 259 */            int height = fm.getHeight();
 
/*    */
 
/* 261 */            if (getAlignment() == 0) x = 0;
 
/* 262 */            else if (getAlignment() == 1) x = getBounds().width / 2 - width / 2;
 
/* 263 */            else if (getAlignment() == 2) x = getBounds().width - width;
 
/* 264 */            y = getBounds().height / 2 + height / 2 - 1;
 
/*    */
 
/* 266 */            g.drawLine(x + 2, y, x + width - 2, y); }
 
/*    */
 
/*    */          public void update(Graphics g)
 
/*    */          {
 
/* 270 */            paint(g);
 
/*    */          }
 
/*    */        };
 
/* 274 */        accountLink.setCursor(Cursor.getPredefinedCursor(12));
 
/* 275 */        accountLink.addMouseListener(new MouseAdapter() {
 
/*    */          public void mousePressed(MouseEvent arg0) {
 
/*    */            try {
 
/* 278 */              Desktop.getDesktop().browse(new URL("http://www.minecraft.net/register.jsp").toURI());
 
/*    */            } catch (Exception e) {
 
/* 280 */              e.printStackTrace();
 
/*    */            }
 
/*    */          }
 
/*    */        });
 
/* 284 */        accountLink.setForeground(Color.BLUE);
 
/* 285 */        registerPanel.add(accountLink, "West");
 
/* 286 */        registerPanel.add(new Panel(), "Center");
 
/*    */      }
 
/*    */    }
 
/*    */    catch (Error localError) {
 
/*    */    }
 
/* 291 */    loginPanel.add(registerPanel, "Center");
 
/* 292 */    loginPanel.add(this.launchButton, "East");
 
/* 293 */    panel.add(loginPanel, "South");
 
/*    */
 
/* 295 */    this.errorLabel.setFont(new Font(null, 2, 16));
 
/* 296 */    this.errorLabel.setForeground(new Color(8388608));
 
/* 297 */    panel.add(this.errorLabel, "North");
 
/*    */
 
/* 300 */    return panel;
 
/*    */  }
 
/*    */
 
/*    */  private Panel buildOfflinePanel() {
 
/* 304 */    Panel panel = new Panel()
 
/*    */    {
 
/*    */      private static final long serialVersionUID = 1L;
 
/* 307 */      private Insets insets = new Insets(12, 24, 16, 32);
 
/*    */
 
/*    */      public Insets getInsets() {
 
/* 310 */        return this.insets;
 
/*    */      }
 
/*    */
 
/*    */      public void update(Graphics g) {
 
/* 314 */        paint(g);
 
/*    */      }
 
/*    */
 
/*    */      public void paint(Graphics g) {
 
/* 318 */        super.paint(g);
 
/* 319 */        int hOffs = 0;
 
/* 320 */        g.setColor(Color.BLACK);
 
/* 321 */        g.drawRect(0, 0 + hOffs, getWidth() - 1, getHeight() - 1 - hOffs);
 
/* 322 */        g.drawRect(1, 1 + hOffs, getWidth() - 3, getHeight() - 3 - hOffs);
 
/* 323 */        g.setColor(Color.WHITE);
 
/*    */
 
/* 325 */        g.drawRect(2, 2 + hOffs, getWidth() - 5, getHeight() - 5 - hOffs);
 
/*    */      }
 
/*    */    };
 
/* 329 */    panel.setBackground(Color.GRAY);
 
/* 330 */    BorderLayout layout = new BorderLayout();
 
/* 331 */    panel.setLayout(layout);
 
/*    */
 
/* 333 */    Panel loginPanel = new Panel(new BorderLayout());
 
/* 334 */    loginPanel.add(new Panel(), "Center");
 
/* 335 */    panel.add(new Panel(), "Center");
 
/* 336 */    loginPanel.add(this.retryButton, "East");
 
/* 337 */    loginPanel.add(this.offlineButton, "West");
 
/*    */
 
/* 339 */    boolean canPlayOffline = this.launcherFrame.canPlayOffline(this.userName.getText());
 
/* 340 */    this.offlineButton.setEnabled(canPlayOffline);
 
/* 341 */    if (!canPlayOffline) {
 
/* 342 */      panel.add(new Label("Play online once to enable offline"), "Center");
 
/*    */    }
 
/* 344 */    panel.add(loginPanel, "South");
 
/*    */
 
/* 346 */    this.errorLabel.setFont(new Font(null, 2, 16));
 
/* 347 */    this.errorLabel.setForeground(new Color(8388608));
 
/* 348 */    panel.add(this.errorLabel, "North");
 
/*    */
 
/* 351 */    return panel;
 
/*    */  }
 
/*    */
 
/*    */  public void setError(String errorMessage) {
 
/* 355 */    removeAll();
 
/* 356 */    add(buildLoginPanel());
 
/* 357 */    this.errorLabel.setText(errorMessage);
 
/* 358 */    validate();
 
/*    */  }
 
/*    */
 
/*    */  public void loginOk() {
 
/* 362 */    writeUsername();
 
/*    */  }
 
/*    */
 
/*    */  public void setNoNetwork() {
 
/* 366 */    removeAll();
 
/* 367 */    add(buildOfflinePanel());
 
/* 368 */    validate();
 
/*    */  }
 
/*    */
 
/*    */  public void checkAutologin() {
 
/* 372 */    if (this.password.getText().length() > 0)
 
/* 373 */      this.launcherFrame.login(this.userName.getText(), this.password.getText());
 
/*    */  }
 
/*    */
 
/*    */  public void setOutdated()
 
/*    */  {
 
/* 378 */    this.outdated = true;
 
/*    */  }
 
/*    */ }
 
*/
11] Et pour finir de coriger les erreurs , ouvez util.java et replacer tout par ceci :

Code:
/*    */ package net.minecraft;
 
/*    */
 
/*    */ import java.io.BufferedReader;
 
/*    */ import java.io.DataOutputStream;
 
/*    */ import java.io.File;
 
/*    */ import java.io.InputStream;
 
/*    */ import java.io.InputStreamReader;
 
/*    */ import java.net.HttpURLConnection;
 
/*    */ import java.net.URL;
 
/*    */
 
/*    */ public class Util
 
/*    */ {
 
/* 11 */  private static File workDir = null;
 
/*    */
 
/*    */  public static File getWorkingDirectory() {
 
/* 14 */    if (workDir == null) workDir = getWorkingDirectory("minecraft");
 
/* 15 */    return workDir;
 
/*    */  }
 
/*    */
 
/*    */  public static File getWorkingDirectory(String applicationName) {
 
/* 19 */    String userHome = System.getProperty("user.home", ".");
 
/*    */    File workingDirectory;
 
/* 21 */    switch (getPlatform().ordinal()) {
 
/*    */    case 1:
 
/*    */    case 2:
 
/* 24 */      workingDirectory = new File(userHome, '.' + applicationName + '/');
 
/* 25 */      break;
 
/*    */    case 3:
 
/* 27 */      String applicationData = System.getenv("APPDATA");
 
/* 28 */      if (applicationData != null) workingDirectory = new File(applicationData, "." + applicationName + '/'); else
 
/* 29 */        workingDirectory = new File(userHome, '.' + applicationName + '/');
 
/* 30 */      break;
 
/*    */    case 4:
 
/* 32 */      workingDirectory = new File(userHome, "Library/Application Support/" + applicationName);
 
/* 33 */      break;
 
/*    */    default:
 
/* 35 */      workingDirectory = new File(userHome, applicationName + '/');
 
/*    */    }
 
/* 37 */    if ((!workingDirectory.exists()) && (!workingDirectory.mkdirs())) throw new RuntimeException("The working directory could not be created: " + workingDirectory);
 
/* 38 */    return workingDirectory;
 
/*    */  }
 
/*    */
 
/*    */  private static OS getPlatform() {
 
/* 42 */    String osName = System.getProperty("os.name").toLowerCase();
 
/* 43 */    if (osName.contains("win")) return OS.windows;
 
/* 44 */    if (osName.contains("mac")) return OS.macos;
 
/* 45 */    if (osName.contains("solaris")) return OS.solaris;
 
/* 46 */    if (osName.contains("sunos")) return OS.solaris;
 
/* 47 */    if (osName.contains("linux")) return OS.linux;
 
/* 48 */    if (osName.contains("unix")) return OS.linux;
 
/* 49 */    return OS.unknown;
 
/*    */  }
 
/*    */
 
/*    */  public static String excutePost(String targetURL, String urlParameters)
 
/*    */  {
 
/* 54 */    HttpURLConnection connection = null;
 
/*    */    try
 
/*    */    {
 
/* 57 */      URL url = new URL(targetURL);
 
/* 58 */      connection = (HttpURLConnection)url.openConnection();
 
/* 59 */      connection.setRequestMethod("POST");
 
/* 60 */      connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
 
/*    */
 
/* 62 */      connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
 
/* 63 */      connection.setRequestProperty("Content-Language", "en-US");
 
/*    */
 
/* 65 */      connection.setUseCaches(false);
 
/* 66 */      connection.setDoInput(true);
 
/* 67 */      connection.setDoOutput(true);
 
/*    */
 
/* 70 */      DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
 
/* 71 */      wr.writeBytes(urlParameters);
 
/* 72 */      wr.flush();
 
/* 73 */      wr.close();
 
/*    */
 
/* 76 */      InputStream is = connection.getInputStream();
 
/* 77 */      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
 
/*    */
 
/* 79 */      StringBuffer response = new StringBuffer();
 
/*    */      String line;
 
/* 80 */      while ((line = rd.readLine()) != null)
 
/*    */      {
 
/* 81 */        response.append(line);
 
/* 82 */        response.append('\r');
 
/*    */      }
 
/* 84 */      rd.close();
 
/* 85 */      String str1 = response.toString();
 
/*    */      return str1;
 
/*    */    }
 
/*    */    catch (Exception e)
 
/*    */    {
 
/* 89 */      e.printStackTrace();
 
/*    */      return null;
 
/*    */    }
 
/*    */    finally
 
/*    */    {
 
/* 94 */      if (connection != null)
 
/* 95 */        connection.disconnect();
 
/*    */    }
 
/*    */  }
 
/*    */
 
/*    */  private static enum OS
 
/*    */  {
 
/*  8 */    linux, solaris, windows, macos, unknown;
 
/*    */  }
 
/*    */ }
 
*/
 

Theknarfal

Architecte en herbe
15 Septembre 2011
172
32
135
26
In a Minecraft World
11] Et pour finir de coriger les erreurs , ouvez util.java et replacer tout par ceci :

Code:
 /*    */ package net.minecraft;
 
/*    */
 
/*    */ import java.io.BufferedReader;
 
/*    */ import java.io.DataOutputStream;
 
/*    */ import java.io.File;
 
/*    */ import java.io.InputStream;
 
/*    */ import java.io.InputStreamReader;
 
/*    */ import java.net.HttpURLConnection;
 
/*    */ import java.net.URL;
 
/*    */
 
/*    */ public class Util
 
/*    */ {
 
/* 11 */  private static File workDir = null;
 
/*    */
 
/*    */  public static File getWorkingDirectory() {
 
/* 14 */    if (workDir == null) workDir = getWorkingDirectory("minecraft");
 
/* 15 */    return workDir;
 
/*    */  }
 
/*    */
 
/*    */  public static File getWorkingDirectory(String applicationName) {
 
/* 19 */    String userHome = System.getProperty("user.home", ".");
 
/*    */    File workingDirectory;
 
/* 21 */    switch (getPlatform().ordinal()) {
 
/*    */    case 1:
 
/*    */    case 2:
 
/* 24 */      workingDirectory = new File(userHome, '.' + applicationName + '/');
 
/* 25 */      break;
 
/*    */    case 3:
 
/* 27 */      String applicationData = System.getenv("APPDATA");
 
/* 28 */      if (applicationData != null) workingDirectory = new File(applicationData, "." + applicationName + '/'); else
 
/* 29 */        workingDirectory = new File(userHome, '.' + applicationName + '/');
 
/* 30 */      break;
 
/*    */    case 4:
 
/* 32 */      workingDirectory = new File(userHome, "Library/Application Support/" + applicationName);
 
/* 33 */      break;
 
/*    */    default:
 
/* 35 */      workingDirectory = new File(userHome, applicationName + '/');
 
/*    */    }
 
/* 37 */    if ((!workingDirectory.exists()) && (!workingDirectory.mkdirs())) throw new RuntimeException("The working directory could not be created: " + workingDirectory);
 
/* 38 */    return workingDirectory;
 
/*    */  }
 
/*    */
 
/*    */  private static OS getPlatform() {
 
/* 42 */    String osName = System.getProperty("os.name").toLowerCase();
 
/* 43 */    if (osName.contains("win")) return OS.windows;
 
/* 44 */    if (osName.contains("mac")) return OS.macos;
 
/* 45 */    if (osName.contains("solaris")) return OS.solaris;
 
/* 46 */    if (osName.contains("sunos")) return OS.solaris;
 
/* 47 */    if (osName.contains("linux")) return OS.linux;
 
/* 48 */    if (osName.contains("unix")) return OS.linux;
 
/* 49 */    return OS.unknown;
 
/*    */  }
 
/*    */
 
/*    */  public static String excutePost(String targetURL, String urlParameters)
 
/*    */  {
 
/* 54 */    HttpURLConnection connection = null;
 
/*    */    try
 
/*    */    {
 
/* 57 */      URL url = new URL(targetURL);
 
/* 58 */      connection = (HttpURLConnection)url.openConnection();
 
/* 59 */      connection.setRequestMethod("POST");
 
/* 60 */      connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
 
/*    */
 
/* 62 */      connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
 
/* 63 */      connection.setRequestProperty("Content-Language", "en-US");
 
/*    */
 
/* 65 */      connection.setUseCaches(false);
 
/* 66 */      connection.setDoInput(true);
 
/* 67 */      connection.setDoOutput(true);
 
/*    */
 
/* 70 */      DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
 
/* 71 */      wr.writeBytes(urlParameters);
 
/* 72 */      wr.flush();
 
/* 73 */      wr.close();
 
/*    */
 
/* 76 */      InputStream is = connection.getInputStream();
 
/* 77 */      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
 
/*    */
 
/* 79 */      StringBuffer response = new StringBuffer();
 
/*    */      String line;
 
/* 80 */      while ((line = rd.readLine()) != null)
 
/*    */      {
 
/* 81 */        response.append(line);
 
/* 82 */        response.append('\r');
 
/*    */      }
 
/* 84 */      rd.close();
 
/* 85 */      String str1 = response.toString();
 
/*    */      return str1;
 
/*    */    }
 
/*    */    catch (Exception e)
 
/*    */    {
 
/* 89 */      e.printStackTrace();
 
/*    */      return null;
 
/*    */    }
 
/*    */    finally
 
/*    */    {
 
/* 94 */      if (connection != null)
 
/* 95 */        connection.disconnect();
 
/*    */    }
 
/*    */  }
 
/*    */
 
/*    */  private static enum OS
 
/*    */  {
 
/*  8 */    linux, solaris, windows, macos, unknown;
 
/*    */  }
 
/*    */ }
 
*/

12] Ouvrez ensuite LauncherFrame.java , ligne 80 et remplacer "http://www.minecraft.net/game/getversion.jsp" par "https://login.minecraft.net/"

Votre Launcher est terminer !!

Oui mais...a quoi sert ce qu j'ai fait la en faites ?

Rien de bien super cool qui tue les kevins mais bon ...apres je vais vous expliquer quoi modifier !

13] Le mêtre en Francais

13a) J'esère que vous êtes toujours dans LauncherFrame.java , car c'est ici que l'on doit aller . Juste en dessous de l'URL , vous pouvez voir des phrases en anglais entre guillemets , alors vous pouvez les mêtre en FR .

Code:
showError("Can't connect to minecraft.net");

Par :

Code:
showError("Connexion impossible avec Minecraft.net");

==============================================

Code:
if (result.trim().equals("Bad login")) {

Par :

Code:
if (result.trim().equals("Mauvais identifiants")) {

===================================================

Code:
showError("Login failed");

Par :

Code:
showError("Erreur de connexion");

Old version = Vielle version / Version dépassée

Outdated launcher = Launcher pas a jours / ou ce que vous voulez

Ligne 17 , si vous voulez modifier Minecraft Launcher , en haut a droite de la fenêtre ( pour windows )

Code:
super("Minecraft Launcher");

En :

Code:
super("Launcher TestCraft");

Maintenant passe au LoginForm.java

Code:
/*  20 */  private Checkbox rememberBox = new Checkbox("Remember password");
/*  21 */  private Button launchButton = new Button("Login");
/*  22 */  private Button retryButton = new Button("Try again");
/*  23 */  private Button offlineButton = new Button("Play offline");

Par /

Code:
/*  20 */  private Checkbox rememberBox = new Checkbox("Se souvenir de moi ?");
/*  21 */  private Button launchButton = new Button("Connexion");
/*  22 */  private Button retryButton = new Button("Réessayer");
/*  23 */  private Button offlineButton = new Button("Jouez Hors-ligne");

Ligne 187 :

Code:
/* 187 */    titles.add(new Label("Identifiant :", 2));
/* 188 */    titles.add(new Label("Mot de passe :", 2));
Dans GameUpdater :

Ligne 176 : pour telecharger le jar
Code:
/* 176 */    URL path = new URL("http://votreserveur.fr");
Mettez le pack de jar ( voir téléchargement ) sur votre ftp et voila !! ( changer le minecraft.jar si vous voulez le modifier , mettez le votre a la place . )
Voila pour le tuto' si vous voulez plus d'infos , mp moi ou dites le sur le topique . Merci d'avoir lue et a bientôt pour un prochain tuto'
 

akiranai

Architecte en herbe
21 Mai 2011
344
13
124
Merci pour ce fabuleux tutoriel, je le test de suite.
edit : je fais comment pour compiler en exe ou en .jar ? :noob java:
EDIT 2 : serait t'il possible que le launcher télécharge par exemple un pack de texture et le dossier mod? (fichier x téléchargé sera déstiné à pack de texture et y pour créer le dossier mod ou télécharger le dossier mod) et si je veux rajouter quelque chose en plus de tout sa (un fichier u)
EDIT 3 : je n'arrive pas à lancer le projet.
 

CraaaVI

CraaaIsGod
20 Septembre 2011
271
39
135
29
Met ton pack dans le jar.. ils pourront pas le changer mais il auront un pack