Exemple #1
0
 public void setPackVer(String string) {
   setProperty(ModPack.getSelectedPack().getDir(), string);
   if (ModPack.getSelectedPack().getDir().equals("mojang_vanilla")) {
     ModPack.setVanillaPackMCVersion(
         string.equalsIgnoreCase("Recommended Version")
             ? ModPack.getSelectedPack().getVersion()
             : string);
   }
 }
 public void doLaunch() {
   if (users.getSelectedIndex() > 1 && ModPack.getSelectedPack() != null) {
     Settings.getSettings().setLastPack(ModPack.getSelectedPack().getDir());
     saveSettings();
     doLogin(
         UserManager.getUsername(users.getSelectedItem().toString()),
         UserManager.getPassword(users.getSelectedItem().toString()));
   } else if (users.getSelectedIndex() <= 1) {
     ErrorUtils.tossError("Please select a profile!");
   }
 }
  // WTF: this does not update packs!!
  // only updating info for selected pack. pulldown menus and info area!
  void updatePacks() {
    for (int i = 0; i < packPanels.size(); i++) {
      if (selectedPack == i && getIndex() >= 0) {
        ModPack pack = ModPack.getPackArray().get(getIndex());
        if (pack != null) {
          String mods = "";
          if (pack.getMods() != null) {
            mods += "<p>This pack contains the following mods by default:</p><ul>";
            for (String name : pack.getMods()) {
              mods += "<li>" + name + "</li>";
            }
            mods += "</ul>";
          }
          packPanels.get(i).setBackground(UIManager.getColor("control").darker().darker());
          packPanels.get(i).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
          File tempDir =
              new File(
                  OSUtils.getCacheStorageLocation(), "ModPacks" + File.separator + pack.getDir());
          packInfo.setText(
              "<html><img src='file:///"
                  + tempDir.getPath()
                  + File.separator
                  + pack.getImageName()
                  + "' width=400 height=200></img> <br>"
                  + pack.getInfo()
                  + mods);
          packInfo.setCaretPosition(0);

          if (ModPack.getSelectedPack(isFTB()).getServerUrl().equals("")
              || ModPack.getSelectedPack(isFTB()).getServerUrl() == null) {
            server.setEnabled(false);
          } else {
            server.setEnabled(true);
          }
          String tempVer = Settings.getSettings().getPackVer(pack.getDir());
          version.removeActionListener(al);
          version.removeAllItems();
          version.addItem("Recommended");
          if (pack.getOldVersions() != null) {
            for (String s : pack.getOldVersions()) {
              version.addItem(s);
            }
            version.setSelectedItem(tempVer);
          }
          version.addActionListener(al);
        }
      } else {
        packPanels.get(i).setBackground(UIManager.getColor("control"));
        packPanels.get(i).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      }
    }
  }
 /**
  * Download and install mods
  *
  * @return boolean - represents whether it was successful in initializing mods
  */
 private boolean initializeMods() {
   Logger.logInfo(ModPack.getSelectedPack().getDir());
   ModManager man = new ModManager(new JFrame(), true);
   man.setVisible(true);
   if (man.erroneous) {
     return false;
   }
   try {
     installMods(ModPack.getSelectedPack().getDir());
     man.cleanUp();
   } catch (IOException e) {
   }
   return true;
 }
 @Override
 protected Boolean doInBackground() {
   try {
     if (!upToDate()) {
       String installPath = OSUtils.getDynamicStorageLocation();
       ModPack pack = ModPack.getSelectedPack();
       pack.setUpdated(true);
       File modPackZip =
           new File(installPath, "ModPacks" + sep + pack.getDir() + sep + pack.getUrl());
       if (modPackZip.exists()) {
         FileUtils.delete(modPackZip);
       }
       File animationGif =
           new File(
               OSUtils.getDynamicStorageLocation(),
               "ModPacks" + sep + pack.getDir() + sep + pack.getAnimation());
       if (animationGif.exists()) {
         FileUtils.delete(animationGif);
       }
       erroneous = !downloadModPack(pack.getUrl(), pack.getDir());
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return true;
 }
  /** deletes the META-INF */
  public static void killMetaInf() {
    File inputFile =
        new File(
            Settings.getSettings().getInstallPath()
                + "/"
                + ModPack.getSelectedPack().getDir()
                + "/minecraft/bin",
            "minecraft.jar");
    File outputTmpFile =
        new File(
            Settings.getSettings().getInstallPath()
                + "/"
                + ModPack.getSelectedPack().getDir()
                + "/minecraft/bin",
            "minecraft.jar.tmp");
    try {
      JarInputStream input = new JarInputStream(new FileInputStream(inputFile));
      JarOutputStream output = new JarOutputStream(new FileOutputStream(outputTmpFile));
      JarEntry entry;

      while ((entry = input.getNextJarEntry()) != null) {
        if (entry.getName().contains("META-INF")) {
          continue;
        }
        output.putNextEntry(entry);
        byte buffer[] = new byte[1024];
        int amo;
        while ((amo = input.read(buffer, 0, 1024)) != -1) {
          output.write(buffer, 0, amo);
        }
        output.closeEntry();
      }

      input.close();
      output.close();

      if (!inputFile.delete()) {
        Logger.logError("Failed to delete Minecraft.jar.");
        return;
      }
      outputTmpFile.renameTo(inputFile);
    } catch (FileNotFoundException e) {
      Logger.logError(e.getMessage(), e);
    } catch (IOException e) {
      Logger.logError(e.getMessage(), e);
    }
  }
 private boolean upToDate() throws IOException {
   ModPack pack = ModPack.getSelectedPack();
   File version =
       new File(Settings.getSettings().getInstallPath(), pack.getDir() + sep + "version");
   if (!version.exists()) {
     version.getParentFile().mkdirs();
     version.createNewFile();
     curVersion =
         (Settings.getSettings().getPackVer().equalsIgnoreCase("recommended version")
                 ? pack.getVersion()
                 : Settings.getSettings().getPackVer())
             .replace(".", "_");
     return false;
   }
   BufferedReader in = new BufferedReader(new FileReader(version));
   String line = in.readLine();
   in.close();
   int currentVersion, requestedVersion;
   currentVersion = (line != null) ? Integer.parseInt(line.replace(".", "")) : 0;
   if (!Settings.getSettings().getPackVer().equalsIgnoreCase("recommended version")
       && !Settings.getSettings().getPackVer().equalsIgnoreCase("newest version")) {
     requestedVersion =
         Integer.parseInt(Settings.getSettings().getPackVer().trim().replace(".", ""));
     if (requestedVersion != currentVersion) {
       Logger.logInfo("Modpack is out of date.");
       curVersion = Settings.getSettings().getPackVer().replace(".", "_");
       return false;
     } else {
       Logger.logInfo("Modpack is up to date.");
       return true;
     }
   } else if (Integer.parseInt(pack.getVersion().replace(".", "")) > currentVersion) {
     Logger.logInfo("Modpack is out of date.");
     ModpackUpdateDialog p = new ModpackUpdateDialog(LaunchFrame.getInstance(), true);
     p.setVisible(true);
     if (!update) {
       return true;
     }
     if (backup) {
       File destination =
           new File(
               OSUtils.getDynamicStorageLocation(),
               "backups" + sep + pack.getDir() + sep + "config_backup");
       if (destination.exists()) {
         FileUtils.delete(destination);
       }
       FileUtils.copyFolder(
           new File(
               Settings.getSettings().getInstallPath(),
               pack.getDir() + sep + "minecraft" + sep + "config"),
           destination);
     }
     curVersion = pack.getVersion().replace(".", "_");
     return false;
   } else {
     Logger.logInfo("Modpack is up to date.");
     return true;
   }
 }
 /**
  * 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) {
   }
 }
 /**
  * updates the tpInstall to the available ones
  *
  * @param locations - the available locations to install the tp to
  */
 public static void updateTpInstallLocs(String[] locations) {
   tpInstallLocation.removeAllItems();
   for (String location : locations) {
     if (!location.isEmpty()) {
       tpInstallLocation.addItem(ModPack.getPack(location.trim()).getName());
     }
   }
   tpInstallLocation.setSelectedItem(ModPack.getSelectedPack().getName());
 }
 public static void cleanUp() {
   ModPack pack = ModPack.getSelectedPack();
   File tempFolder =
       new File(OSUtils.getDynamicStorageLocation(), "ModPacks" + sep + pack.getDir() + sep);
   for (String file : tempFolder.list()) {
     if (!file.equals(pack.getLogoName())
         && !file.equals(pack.getImageName())
         && !file.equals("version")
         && !file.equals(pack.getAnimation())) {
       try {
         if (Settings.getSettings().getDebugLauncher() && file.endsWith(".zip")) {
           Logger.logInfo("debug: retaining modpack file: " + tempFolder + File.separator + file);
         } else {
           FileUtils.delete(new File(tempFolder, file));
         }
       } catch (IOException e) {
         Logger.logError(e.getMessage(), 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;
    }
Exemple #12
0
  /**
   * checks whether an update is needed, and then starts the update process off
   *
   * @param response - the response from the minecraft servers
   */
  private void runGameUpdater(final LoginResponse response) {
    final String installPath = Settings.getSettings().getInstallPath();
    final ModPack pack = ModPack.getSelectedPack();
    if (Settings.getSettings().getForceUpdate()
        && new File(installPath, pack.getDir() + File.separator + "version").exists()) {
      new File(installPath, pack.getDir() + File.separator + "version").delete();
    }
    if (!initializeMods()) {
      enableObjects();
      return;
    }
    try {
      TextureManager.updateTextures();
    } catch (Exception e1) {
    }
    MinecraftVersionDetector mvd = new MinecraftVersionDetector();
    if (!new File(installPath, pack.getDir() + "/minecraft/bin/minecraft.jar").exists()
        || mvd.shouldUpdate(installPath + "/" + pack.getDir() + "/minecraft")) {
      final ProgressMonitor progMonitor =
          new ProgressMonitor(this, "Downloading minecraft...", "", 0, 100);
      final GameUpdateWorker updater =
          new GameUpdateWorker(
              pack.getMcVersion(),
              new File(installPath, pack.getDir() + "/minecraft/bin").getPath()) {
            @Override
            public void done() {
              progMonitor.close();
              try {
                if (get()) {
                  Logger.logInfo("Game update complete");
                  FileUtils.killMetaInf();
                  launchMinecraft(
                      installPath + "/" + pack.getDir() + "/minecraft",
                      RESPONSE.getUsername(),
                      RESPONSE.getSessionID());
                } else {
                  ErrorUtils.tossError("Error occurred during downloading the game");
                }
              } catch (CancellationException e) {
                ErrorUtils.tossError("Game update canceled.");
              } catch (InterruptedException e) {
                ErrorUtils.tossError("Game update interrupted.");
              } catch (ExecutionException e) {
                ErrorUtils.tossError("Failed to download game.");
              } finally {
                enableObjects();
              }
            }
          };

      updater.addPropertyChangeListener(
          new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
              if (progMonitor.isCanceled()) {
                updater.cancel(false);
              }
              if (!updater.isDone()) {
                int prog = updater.getProgress();
                if (prog < 0) {
                  prog = 0;
                } else if (prog > 100) {
                  prog = 100;
                }
                progMonitor.setProgress(prog);
                progMonitor.setNote(updater.getStatus());
              }
            }
          });
      updater.execute();
    } else {
      launchMinecraft(
          installPath + "/" + pack.getDir() + "/minecraft",
          RESPONSE.getUsername(),
          RESPONSE.getSessionID());
    }
  }
Exemple #13
0
 public String getPackVer() {
   return getProperty(ModPack.getSelectedPack().getDir(), "Recommended Version");
 }