Ejemplo n.º 1
0
 /**
  * Used to grab the currently selected ModPack based off the selected index from ModPacksPane
  *
  * @return ModPack - the currently selected ModPack
  */
 public static ModPack getSelectedPack() {
   return getPack(ModpacksPane.getIndex());
 }
Ejemplo n.º 2
0
  public static Process launchMinecraft(
      String workingDir,
      String username,
      String password,
      String forgename,
      String rmax,
      String addOpt)
      throws IOException {
    String[] jarFiles = new String[] {"minecraft.jar", "lwjgl.jar", "lwjgl_util.jar", "jinput.jar"};
    StringBuilder cpb = new StringBuilder("");
    File tempDir = new File(new File(workingDir).getParentFile(), "/instMods/");
    if (tempDir.isDirectory()) {
      for (String name : tempDir.list()) {
        if (name.toLowerCase().contains("forge") && name.toLowerCase().endsWith(".zip")) {
          if (!name.toLowerCase().equalsIgnoreCase(forgename)) {
            if (new File(tempDir, forgename).exists()) {
              new File(tempDir, name).delete();
            } else {
              new File(tempDir, name).renameTo(new File(tempDir, forgename));
            }
          }
        }
        if (!name.equalsIgnoreCase(forgename)) {
          if (name.toLowerCase().endsWith(".zip") || name.toLowerCase().endsWith(".jar")) {
            cpb.append(OSUtils.getJavaDelimiter());
            cpb.append(new File(tempDir, name).getAbsolutePath());
          }
        }
      }
    } else {
      Logger.logInfo("Not a directory.");
    }

    cpb.append(OSUtils.getJavaDelimiter());
    cpb.append(new File(tempDir, forgename).getAbsolutePath());

    for (String jarFile : jarFiles) {
      cpb.append(OSUtils.getJavaDelimiter());
      cpb.append(new File(new File(workingDir, "bin"), jarFile).getAbsolutePath());
    }

    List<String> arguments = new ArrayList<String>();

    String separator = System.getProperty("file.separator");
    String path = System.getProperty("java.home") + separator + "bin" + separator + "java";
    arguments.add(path);

    setMemory(arguments, rmax);

    // If given, add additional command line options (e.g. -Djava.net.preferIPv4Stack=true)
    arguments.add(addOpt);

    arguments.add("-cp");
    arguments.add(System.getProperty("java.class.path") + cpb.toString());

    arguments.add(MinecraftLauncher.class.getCanonicalName());
    arguments.add(workingDir);
    arguments.add(forgename);
    arguments.add(username);
    arguments.add(password);
    arguments.add(ModPack.getPack(ModpacksPane.getIndex()).getName());
    arguments.add(
        OSUtils.getDynamicStorageLocation()
            + "ModPacks"
            + separator
            + ModPack.getPack(ModpacksPane.getIndex()).getDir()
            + separator
            + ModPack.getPack(ModpacksPane.getIndex()).getLogoName());
    arguments.add(Settings.getSettings().getMinecraftX());
    arguments.add(Settings.getSettings().getMinecraftY());
    arguments.add(Settings.getSettings().getMinecraftXPos());
    arguments.add(Settings.getSettings().getMinecraftYPos());
    arguments.add(Settings.getSettings().getAutoMaximize());
    arguments.add(Settings.getSettings().getCenterWindow());

    ProcessBuilder processBuilder = new ProcessBuilder(arguments);
    processBuilder.redirectErrorStream(true);
    return processBuilder.start();
  }