@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;
 }
 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;
   }
 }
  // 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));
      }
    }
  }
Example #4
0
 /**
  * @param modPackName - The pack to install (should already be downloaded)
  * @throws IOException
  */
 protected void installMods(String modPackName) throws IOException {
   String installpath = Settings.getSettings().getInstallPath();
   String temppath = OSUtils.getDynamicStorageLocation();
   ModPack pack = ModPack.getPack(modPacksPane.getSelectedModIndex());
   Logger.logInfo("dirs mk'd");
   File source = new File(temppath, "ModPacks/" + pack.getDir() + "/.minecraft");
   if (!source.exists()) {
     source = new File(temppath, "ModPacks/" + pack.getDir() + "/minecraft");
   }
   FileUtils.copyFolder(source, new File(installpath, pack.getDir() + "/minecraft/"));
   FileUtils.copyFolder(
       new File(temppath, "ModPacks/" + pack.getDir() + "/instMods/"),
       new File(installpath, pack.getDir() + "/instMods/"));
 }
Example #5
0
 public static void clearModsFolder(ModPack pack) {
   File modsFolder =
       new File(
           Settings.getSettings().getInstallPath(),
           pack.getDir() + File.separator + "minecraft" + File.separator + "mods");
   clearFolder(modsFolder);
   Logger.logInfo("Mods Folder: " + modsFolder.toString());
   File dyn = new File(baseDynamic.getPath(), "minecraft" + File.separator + "mods");
   Logger.logInfo("Dynamic Folder: " + dyn);
   clearFolder(dyn);
 }
 public static void clearModsFolder(ModPack pack) {
   File modsFolder =
       new File(Settings.getSettings().getInstallPath(), pack.getDir() + "/minecraft/mods");
   if (modsFolder.exists()) {
     for (String file : modsFolder.list()) {
       if (file.toLowerCase().endsWith(".zip")
           || file.toLowerCase().endsWith(".jar")
           || file.toLowerCase().endsWith(".disabled")
           || file.toLowerCase().endsWith(".litemod")) {
         try {
           FileUtils.delete(new File(modsFolder, file));
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
     }
   }
 }
 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);
       }
     }
   }
 }
Example #8
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());
    }
  }
  /*
   * GUI Code to add a modpack to the selection
   */
  public void addPack(final ModPack pack) {
    if (!modPacksAdded) {
      modPacksAdded = true;
      packs.removeAll();
      packs.repaint();
    }
    final int packIndex = packPanels.size();
    final JPanel p = new JPanel();
    p.setBounds(0, (packIndex * 55), 420, 55);
    p.setLayout(null);
    JLabel logo = new JLabel(new ImageIcon(pack.getLogo()));
    logo.setBounds(6, 6, 42, 42);
    logo.setVisible(true);

    JTextArea filler =
        new JTextArea(
            pack.getName()
                + " (v"
                + pack.getVersion()
                + ") Minecraft Version "
                + pack.getMcVersion()
                + "\n"
                + "By "
                + pack.getAuthor());
    filler.setBorder(null);
    filler.setEditable(false);
    filler.setForeground(LauncherStyle.getCurrentStyle().tabPaneForeground);
    filler.setBounds(58, 6, 362, 42);
    filler.setBackground(LauncherStyle.getCurrentStyle().tabPaneBackground);

    MouseAdapter lin =
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              LaunchFrame.getInstance().doLaunch();
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            selectedPack = packIndex;
            updatePacks();
          }
        };
    p.addMouseListener(lin);
    filler.addMouseListener(lin);
    logo.addMouseListener(lin);
    p.add(filler);
    p.add(logo);
    packPanels.add(p);
    packs.add(p);

    packs.setMinimumSize(new Dimension(420, (packPanels.size() * 55)));
    packs.setPreferredSize(new Dimension(420, (packPanels.size() * 55)));

    //
    // packsScroll.revalidate();
    if (pack.getDir().equalsIgnoreCase(getLastPack())) {
      selectedPack = packIndex;
    }
  }
  /*
   * GUI Code to add a modpack to the selection
   */
  public static void addPack(ModPack pack) {
    if (!modPacksAdded) {
      modPacksAdded = true;
      packs.removeAll();
    }

    final int packIndex = packPanels.size();
    Logger.logInfo("Adding pack " + getModNum());
    final JPanel p = new JPanel();
    p.setBounds(0, (packIndex * 55), 420, 55);
    p.setLayout(null);
    JLabel logo = new JLabel(new ImageIcon(pack.getLogo()));
    logo.setBounds(6, 6, 42, 42);
    logo.setVisible(true);

    JTextArea filler =
        new JTextArea(
            pack.getName()
                + " (v"
                + pack.getVersion()
                + ") Minecraft Version "
                + pack.getMcVersion()
                + "\n"
                + "By "
                + pack.getAuthor());
    filler.setBorder(null);
    filler.setEditable(false);
    filler.setForeground(Color.white);
    filler.setBounds(58, 6, 378, 42);
    filler.setBackground(new Color(255, 255, 255, 0));
    MouseListener lin =
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            selectedPack = packIndex;
            updatePacks();
          }

          @Override
          public void mouseReleased(MouseEvent e) {}

          @Override
          public void mousePressed(MouseEvent e) {
            selectedPack = packIndex;
            updatePacks();
          }

          @Override
          public void mouseExited(MouseEvent e) {}

          @Override
          public void mouseEntered(MouseEvent e) {}
        };
    p.addMouseListener(lin);
    filler.addMouseListener(lin);
    logo.addMouseListener(lin);
    p.add(filler);
    p.add(logo);
    packPanels.add(p);
    packs.add(p);
    if (origin.equals("All")) {
      packs.setMinimumSize(new Dimension(420, (ModPack.getPackArray().size() * 55)));
      packs.setPreferredSize(new Dimension(420, (ModPack.getPackArray().size() * 55)));
    } else {
      packs.setMinimumSize(new Dimension(420, (currentPacks.size() * 55)));
      packs.setPreferredSize(new Dimension(420, (currentPacks.size() * 55)));
    }
    packsScroll.revalidate();
    if (pack.getDir().equalsIgnoreCase(Settings.getSettings().getLastPack())) {
      selectedPack = packIndex;
    }
  }