/**
  * launch the game with the mods in the classpath
  *
  * @param workingDir - install path
  * @param username - the MC username
  * @param password - the MC password
  */
 public void launchMinecraft(String workingDir, String username, String password) {
   try {
     Process minecraftProcess =
         MinecraftLauncher.launchMinecraft(
             workingDir, username, password, FORGENAME, Settings.getSettings().getRamMax());
     StreamLogger.start(minecraftProcess.getInputStream(), new LogEntry().level(LogLevel.UNKNOWN));
     TrackerUtils.sendPageView(
         ModPack.getSelectedPack().getName() + " Launched", ModPack.getSelectedPack().getName());
     try {
       Thread.sleep(1500);
     } catch (InterruptedException e) {
     }
     try {
       minecraftProcess.exitValue();
     } catch (IllegalThreadStateException e) {
       this.setVisible(false);
       ProcessMonitor.create(
           minecraftProcess,
           new Runnable() {
             @Override
             public void run() {
               if (!Settings.getSettings().getKeepLauncherOpen()) {
                 System.exit(0);
               } else {
                 LaunchFrame launchFrame = LaunchFrame.this;
                 launchFrame.setVisible(true);
                 launchFrame.enableObjects();
                 try {
                   Settings.getSettings()
                       .load(new FileInputStream(Settings.getSettings().getConfigFile()));
                   tabbedPane.remove(1);
                   optionsPane = new OptionsPane(Settings.getSettings());
                   tabbedPane.add(optionsPane, 1);
                   tabbedPane.setIconAt(
                       1, new ImageIcon(this.getClass().getResource("/image/tabs/options.png")));
                 } catch (Exception e1) {
                   Logger.logError("Failed to reload settings after launcher closed", e1);
                 }
               }
             }
           });
     }
   } catch (Exception e) {
   }
 }
    protected boolean downloadModPack(String modPackName, String dir) {
      boolean debugVerbose = Settings.getSettings().getDebugLauncher();
      String debugTag = "debug: downloadModPack: ";

      Logger.logInfo("Downloading Mod Pack");
      TrackerUtils.sendPageView(
          "net/ftb/tools/ModManager.java",
          "Downloaded: " + modPackName + " v." + curVersion.replace('_', '.'));
      String dynamicLoc = OSUtils.getDynamicStorageLocation();
      String installPath = Settings.getSettings().getInstallPath();
      ModPack pack = ModPack.getSelectedPack();
      String baseLink =
          (pack.isPrivatePack()
              ? "privatepacks/" + dir + "/" + curVersion + "/"
              : "modpacks/" + dir + "/" + curVersion + "/");
      File baseDynamic = new File(dynamicLoc, "ModPacks" + sep + dir + sep);
      if (debugVerbose) {
        Logger.logInfo(debugTag + "pack dir: " + dir);
        Logger.logInfo(debugTag + "dynamicLoc: " + dynamicLoc);
        Logger.logInfo(debugTag + "installPath: " + installPath);
        Logger.logInfo(debugTag + "baseLink: " + baseLink);
      }
      baseDynamic.mkdirs();
      String md5 = "";
      try {
        new File(baseDynamic, modPackName).createNewFile();
        md5 =
            downloadUrl(
                baseDynamic.getPath() + sep + modPackName,
                DownloadUtils.getCreeperhostLink(baseLink + modPackName));
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
      String animation = pack.getAnimation();
      if (!animation.equalsIgnoreCase("empty")) {
        try {
          downloadUrl(
              baseDynamic.getPath() + sep + animation,
              DownloadUtils.getCreeperhostLink(baseLink + animation));
        } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
        }
      }
      try {
        if ((md5 == null || md5.isEmpty())
            ? DownloadUtils.backupIsValid(
                new File(baseDynamic, modPackName), baseLink + modPackName)
            : DownloadUtils.isValid(new File(baseDynamic, modPackName), md5)) {
          if (debugVerbose) {
            Logger.logInfo(debugTag + "Extracting pack.");
          }
          FileUtils.extractZipTo(baseDynamic.getPath() + sep + modPackName, baseDynamic.getPath());
          if (debugVerbose) {
            Logger.logInfo(debugTag + "Purging mods, coremods, instMods");
          }
          clearModsFolder(pack);
          FileUtils.delete(new File(installPath, dir + "/minecraft/coremods"));
          FileUtils.delete(new File(installPath, dir + "/instMods/"));
          File version = new File(installPath, dir + sep + "version");
          BufferedWriter out = new BufferedWriter(new FileWriter(version));
          out.write(curVersion.replace("_", "."));
          out.flush();
          out.close();
          if (debugVerbose) {
            Logger.logInfo(debugTag + "Pack extracted, version tagged.");
          }
          return true;
        } else {
          ErrorUtils.tossError("Error downloading modpack!!!");
          return false;
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      return false;
    }
  /**
   * Launch the application.
   *
   * @param args - CLI arguments
   */
  public static void main(String[] args) {
    tracker.setEnabled(true);
    TrackerUtils.sendPageView("net/ftb/gui/LaunchFrame.java", "Launcher Start v" + version);

    if (new File(Settings.getSettings().getInstallPath(), "FTBLauncherLog.txt").exists()) {
      new File(Settings.getSettings().getInstallPath(), "FTBLauncherLog.txt").delete();
    }

    if (new File(Settings.getSettings().getInstallPath(), "MinecraftLog.txt").exists()) {
      new File(Settings.getSettings().getInstallPath(), "MinecraftLog.txt").delete();
    }

    DownloadUtils thread = new DownloadUtils();
    thread.start();

    Logger.logInfo("FTBLaunch starting up (version " + version + ")");
    Logger.logInfo("Java version: " + System.getProperty("java.version"));
    Logger.logInfo("Java vendor: " + System.getProperty("java.vendor"));
    Logger.logInfo("Java home: " + System.getProperty("java.home"));
    Logger.logInfo(
        "Java specification: "
            + System.getProperty("java.vm.specification.name")
            + " version: "
            + System.getProperty("java.vm.specification.version")
            + " by "
            + System.getProperty("java.vm.specification.vendor"));
    Logger.logInfo(
        "Java vm: "
            + System.getProperty("java.vm.name")
            + " version: "
            + System.getProperty("java.vm.version")
            + " by "
            + System.getProperty("java.vm.vendor"));
    Logger.logInfo(
        "OS: "
            + System.getProperty("os.arch")
            + " "
            + System.getProperty("os.name")
            + " "
            + System.getProperty("os.version"));

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            StyleUtil.loadUiStyles();
            Logger.logInfo(UIManager.getInstalledLookAndFeels().toString());
            try {
              for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                  UIManager.setLookAndFeel(info.getClassName());
                  break;
                }
              }
            } catch (Exception e) {
              try {
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              } catch (Exception e1) {
              }
            }
            I18N.setupLocale();
            I18N.setLocale(Settings.getSettings().getLocale());

            if (noConfig) {
              InstallDirectoryDialog installDialog = new InstallDirectoryDialog();
              installDialog.setVisible(true);
            }

            File installDir = new File(Settings.getSettings().getInstallPath());
            if (!installDir.exists()) {
              installDir.mkdirs();
            }
            File dynamicDir = new File(OSUtils.getDynamicStorageLocation());
            if (!dynamicDir.exists()) {
              dynamicDir.mkdirs();
            }

            userManager =
                new UserManager(new File(OSUtils.getDynamicStorageLocation(), "logindata"));
            con = new LauncherConsole();
            if (Settings.getSettings().getConsoleActive()) {
              con.setVisible(true);
            }

            File credits = new File(OSUtils.getDynamicStorageLocation(), "credits.txt");

            try {
              if (!credits.exists()) {
                FileOutputStream fos = new FileOutputStream(credits);
                OutputStreamWriter osw = new OutputStreamWriter(fos);

                osw.write(
                    "FTB Launcher and Modpack Credits " + System.getProperty("line.separator"));
                osw.write("-------------------------------" + System.getProperty("line.separator"));
                osw.write("Launcher Developers:" + System.getProperty("line.separator"));
                osw.write("jjw123" + System.getProperty("line.separator"));
                osw.write("unv_annihilator" + System.getProperty("line.separator"));
                osw.write(
                    "Vbitz"
                        + System.getProperty("line.separator")
                        + System.getProperty("line.separator"));
                osw.write("Web Developers:" + System.getProperty("line.separator"));
                osw.write("captainnana" + System.getProperty("line.separator"));
                osw.write(
                    "Rob"
                        + System.getProperty("line.separator")
                        + System.getProperty("line.separator"));
                osw.write("Modpack Team:" + System.getProperty("line.separator"));
                osw.write("CWW256" + System.getProperty("line.separator"));
                osw.write("Lathanael" + System.getProperty("line.separator"));
                osw.write("Watchful11" + System.getProperty("line.separator"));

                osw.flush();

                TrackerUtils.sendPageView("net/ftb/gui/LaunchFrame.java", "Unique User (Credits)");
              }

              if (!Settings.getSettings().getLoaded() && !Settings.getSettings().getSnooper()) {
                TrackerUtils.sendPageView("net/ftb/gui/LaunchFrame.java", "Unique User (Settings)");
                Settings.getSettings().setLoaded(true);
              }

            } catch (FileNotFoundException e1) {
              Logger.logError(e1.getMessage());
            } catch (IOException e1) {
              Logger.logError(e1.getMessage());
            }

            LaunchFrame frame = new LaunchFrame(2);
            instance = frame;
            frame.setVisible(true);

            Thread.setDefaultUncaughtExceptionHandler(
                new Thread.UncaughtExceptionHandler() {
                  @Override
                  public void uncaughtException(Thread t, Throwable e) {
                    Logger.logError("Unhandled exception in " + t.toString(), e);
                  }
                });

            ModPack.addListener(frame.modPacksPane);
            ModPack.loadXml(getXmls());

            Map.addListener(frame.mapsPane);
            //				Map.loadAll();

            TexturePack.addListener(frame.tpPane);
            //				TexturePack.loadAll();

            UpdateChecker updateChecker = new UpdateChecker(buildNumber);
            if (updateChecker.shouldUpdate()) {
              LauncherUpdateDialog p = new LauncherUpdateDialog(updateChecker);
              p.setVisible(true);
            }
          }
        });
  }