Exemplo n.º 1
0
 public void downloadUrl(String filename, String urlString)
     throws MalformedURLException, IOException, NoSuchAlgorithmException {
   BufferedInputStream in = null;
   FileOutputStream fout = null;
   try {
     in = new BufferedInputStream(new URL(urlString).openStream());
     fout = new FileOutputStream(filename);
     byte data[] = new byte[1024];
     int count, amount = 0, steps = 0;
     URL url_ =
         new URL(
             DownloadUtils.getCreeperhostLink(
                 Map.getMap(LaunchFrame.getSelectedMapIndex()).getUrl()));
     int mapSize = url_.openConnection().getContentLength();
     progressBar.setMaximum(10000);
     while ((count = in.read(data, 0, 1024)) != -1) {
       fout.write(data, 0, count);
       downloadedPerc += (count * 1.0 / mapSize) * 100;
       amount += count;
       steps++;
       if (steps > 100) {
         steps = 0;
         progressBar.setValue((int) downloadedPerc * 100);
         label.setText((amount / 1024) + "Kb / " + (mapSize / 1024) + "Kb");
       }
     }
   } finally {
     in.close();
     fout.flush();
     fout.close();
   }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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);
   }
 }
Exemplo n.º 4
0
    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;
    }