@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;
   }
 }
Example #3
0
 protected void installMap(String mapName, String dir) throws IOException {
   Logger.logInfo("Installing");
   String installPath = Settings.getSettings().getInstallPath();
   String tempPath = OSUtils.getDynamicStorageLocation();
   Map map = Map.getMap(LaunchFrame.getSelectedMapIndex());
   new File(installPath, map.getSelectedCompatible() + "/minecraft/saves/" + dir).mkdirs();
   FileUtils.copyFolder(
       new File(tempPath, "Maps/" + dir + "/" + dir),
       new File(installPath, map.getSelectedCompatible() + "/minecraft/saves/" + dir));
   FileUtils.copyFile(
       new File(tempPath, "Maps/" + dir + "/" + "version"),
       new File(
           installPath, map.getSelectedCompatible() + "/minecraft/saves/" + dir + "/version"));
 }
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 void update() {
    String path = null;
    try {
      path =
          new File(LaunchFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath())
              .getCanonicalPath();
    } catch (IOException e) {
      Logger.logError("Couldn't get path to current launcher jar/exe", e);
    }
    String temporaryUpdatePath =
        Settings.getSettings().getInstallPath()
            + File.separator
            + "updatetemp"
            + File.separator
            + path.substring(path.lastIndexOf(File.separator) + 1);
    String extension = path.substring(path.lastIndexOf('.') + 1);
    extension = "exe".equalsIgnoreCase(extension) ? extension : "jar";

    try {
      URL updateURL = new URL(downloadUrl.toString() + "." + extension);
      File temporaryUpdate = new File(temporaryUpdatePath);
      temporaryUpdate.getParentFile().mkdir();
      FileUtils.downloadToFile(updateURL, temporaryUpdate);
      SelfUpdate.runUpdate(path, temporaryUpdatePath);
    } catch (MalformedURLException e) {
      Logger.logError("Malformed download URL for launcher update", e);
    } catch (IOException e) {
      Logger.logError("Failed to download launcher update", e);
    }
  }
Example #6
0
 public UpdateChecker(int version) {
   this.version = version;
   loadInfo();
   try {
     FileUtils.delete(
         new File(Settings.getSettings().getInstallPath() + File.separator + "updatetemp"));
   } catch (Exception ignored) {
   }
 }
Example #7
0
 private void updateFiles() {
   Logger.logInfo("[i18n] Downloading locale files ...");
   try {
     DownloadUtils.downloadToFile(
         new URL(DownloadUtils.getCreeperhostLink("locales.zip")), archive);
     Logger.logInfo("[i18n] Moving files into place ...");
     if (local.getParentFile().exists()) {
       FileUtils.delete(local.getParentFile());
     }
     FileUtils.extractZipTo(archive.getAbsolutePath(), local.getParentFile().getPath());
     if (!local.exists()) {
       local.createNewFile();
     }
     Writer wr = new FileWriter(local);
     wr.write(String.valueOf(remoteVer));
     wr.close();
     cleanUpFiles();
   } catch (Exception e) {
     Logger.logWarn("[i18n] Update IOException", e);
   }
 }
Example #8
0
 protected void downloadMap(String mapName, String dir)
     throws IOException, NoSuchAlgorithmException {
   Logger.logInfo("Downloading");
   String installPath = OSUtils.getDynamicStorageLocation();
   new File(installPath + "/Maps/" + dir + "/").mkdirs();
   new File(installPath + "/Maps/" + dir + "/" + mapName).createNewFile();
   downloadUrl(
       installPath + "/Maps/" + dir + "/" + mapName, DownloadUtils.getCreeperhostLink(mapName));
   FileUtils.extractZipTo(
       installPath + "/Maps/" + dir + "/" + mapName, installPath + "/Maps/" + dir);
   installMap(mapName, dir);
 }
Example #9
0
 public static void cleanUp() {
   Map map = Map.getMap(LaunchFrame.getSelectedMapIndex());
   File tempFolder =
       new File(OSUtils.getDynamicStorageLocation(), "Maps" + sep + map.getMapName() + sep);
   for (String file : tempFolder.list()) {
     if (!file.equals(map.getLogoName())
         && !file.equals(map.getImageName())
         && !file.equalsIgnoreCase("version")) {
       try {
         FileUtils.delete(new File(tempFolder, file));
       } catch (IOException e) {
       }
     }
   }
 }
 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 #12
0
 public static void clearFolder(File folder) {
   if (folder.exists()) {
     for (String file : folder.list()) {
       if (new File(folder, file).isDirectory()) {
         // Logger.logInfo(new File(folder, file).toString());
         clearFolder(new File(folder, file));
       }
       if (file.toLowerCase().endsWith(".zip")
           || file.toLowerCase().endsWith(".jar")
           || file.toLowerCase().endsWith(".disabled")
           || file.toLowerCase().endsWith(".litemod")) {
         try {
           boolean b = FileUtils.delete(new File(folder, file));
           if (!b) Logger.logInfo("Error deleting " + file);
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
     }
   }
 }
Example #13
0
 @Override
 protected Boolean doInBackground() throws Exception {
   String installPath = Settings.getSettings().getInstallPath();
   Map map = Map.getMap(LaunchFrame.getSelectedMapIndex());
   if (new File(
           installPath, map.getSelectedCompatible() + "/minecraft/saves/" + map.getMapName())
       .exists()) {
     MapOverwriteDialog dialog = new MapOverwriteDialog(LaunchFrame.getInstance(), true);
     dialog.setVisible(true);
     if (overwrite) {
       FileUtils.delete(
           new File(
               installPath,
               map.getSelectedCompatible() + "/minecraft/saves/" + map.getMapName()));
     } else {
       Logger.logInfo("Canceled map installation.");
       return false;
     }
   }
   downloadMap(map.getUrl(), map.getMapName());
   return false;
 }
    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;
    }