예제 #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();
   }
 }
예제 #2
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);
   }
 }
예제 #3
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);
 }
예제 #4
0
  public void run() {
    Logger.logInfo("[i18n] Checking for updates ...");
    File dir = new File(root);
    File tmp = new File(dir, "locale");

    if (!dir.exists() || !tmp.exists()) {
      dir.mkdirs();
      tmp.mkdirs();
    }
    cleanUpFiles();
    try {
      URLConnection connection =
          new URL(DownloadUtils.getStaticCreeperhostLink("locales")).openConnection();
      Scanner scanner = new Scanner(connection.getInputStream());
      remoteVer = scanner.nextInt();
      Logger.logInfo("[i18n] remoteVer = " + remoteVer);
      scanner.close();
    } catch (MalformedURLException e1) {
      Logger.logError(e1.getMessage(), e1);
    } catch (IOException e1) {
      Logger.logInfo("[i18n] Could not retrieve version info, skipping update.", e1);
      return;
    }
    if (local.exists()) {
      try {
        int localVer;
        Scanner scanner = new Scanner(local);
        localVer = scanner.nextInt();
        Logger.logInfo("[i18n] localVer = " + localVer);
        scanner.close();
        if (localVer < remoteVer) {
          updateFiles();
        } else {
          Logger.logInfo("[i18n] Files are up to date");
        }
      } catch (FileNotFoundException e1) {
        Logger.logInfo("[i18n] Could not read version file", e1);
      }
    } else {
      updateFiles();
    }
    I18N.addFiles();
  }
예제 #5
0
 @Override
 public void run() {
   try { // TODO ASAP THREAD THIS!!!
     Benchmark.start("MapLoader");
     Logger.logInfo("loading map information...");
     Document doc =
         AppUtils.downloadXML(new URL(DownloadUtils.getStaticCreeperhostLink(Locations.MAPXML)));
     if (doc == null) {
       Logger.logError("Error: Could not load map data!");
     }
     NodeList maps = doc.getElementsByTagName("map");
     for (int i = 0; i < maps.getLength(); i++) {
       Node map = maps.item(i);
       NamedNodeMap mapAttr = map.getAttributes();
       Map.addMap(
           new Map(
               mapAttr.getNamedItem("name").getTextContent(),
               mapAttr.getNamedItem("author").getTextContent(),
               mapAttr.getNamedItem("version").getTextContent(),
               mapAttr.getNamedItem("url").getTextContent(),
               mapAttr.getNamedItem("logo").getTextContent(),
               mapAttr.getNamedItem("image").getTextContent(),
               mapAttr.getNamedItem("compatible").getTextContent(),
               mapAttr.getNamedItem("mcversion").getTextContent(),
               mapAttr.getNamedItem("mapname").getTextContent(),
               mapAttr.getNamedItem("description") == null
                   ? null
                   : mapAttr.getNamedItem("description").getTextContent().replace("\\n", "\n"),
               i));
     }
   } catch (Exception e) {
     Logger.logError("Error while updating map info", e);
   } finally {
     MapUtils.loaded = true;
     Benchmark.logBenchAs("MapLoader", "MapLoader run ");
     LaunchFrame.checkDoneLoading();
   }
 }
예제 #6
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;
    }
예제 #7
0
  /**
   * Launch the application.
   *
   * @param args - CLI arguments
   */
  public static void main(String[] args) {
    tracker.setEnabled(true);
    TrackerUtils.sendPageView("net/ftb/gui/LaunchFrame.java", "Launcher Start v" + version);

    if (new File(Settings.getSettings().getInstallPath(), "FTBLauncherLog.txt").exists()) {
      new File(Settings.getSettings().getInstallPath(), "FTBLauncherLog.txt").delete();
    }

    if (new File(Settings.getSettings().getInstallPath(), "MinecraftLog.txt").exists()) {
      new File(Settings.getSettings().getInstallPath(), "MinecraftLog.txt").delete();
    }

    DownloadUtils thread = new DownloadUtils();
    thread.start();

    Logger.logInfo("FTBLaunch starting up (version " + version + ")");
    Logger.logInfo("Java version: " + System.getProperty("java.version"));
    Logger.logInfo("Java vendor: " + System.getProperty("java.vendor"));
    Logger.logInfo("Java home: " + System.getProperty("java.home"));
    Logger.logInfo(
        "Java specification: "
            + System.getProperty("java.vm.specification.name")
            + " version: "
            + System.getProperty("java.vm.specification.version")
            + " by "
            + System.getProperty("java.vm.specification.vendor"));
    Logger.logInfo(
        "Java vm: "
            + System.getProperty("java.vm.name")
            + " version: "
            + System.getProperty("java.vm.version")
            + " by "
            + System.getProperty("java.vm.vendor"));
    Logger.logInfo(
        "OS: "
            + System.getProperty("os.arch")
            + " "
            + System.getProperty("os.name")
            + " "
            + System.getProperty("os.version"));

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            StyleUtil.loadUiStyles();
            Logger.logInfo(UIManager.getInstalledLookAndFeels().toString());
            try {
              for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                  UIManager.setLookAndFeel(info.getClassName());
                  break;
                }
              }
            } catch (Exception e) {
              try {
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              } catch (Exception e1) {
              }
            }
            I18N.setupLocale();
            I18N.setLocale(Settings.getSettings().getLocale());

            if (noConfig) {
              InstallDirectoryDialog installDialog = new InstallDirectoryDialog();
              installDialog.setVisible(true);
            }

            File installDir = new File(Settings.getSettings().getInstallPath());
            if (!installDir.exists()) {
              installDir.mkdirs();
            }
            File dynamicDir = new File(OSUtils.getDynamicStorageLocation());
            if (!dynamicDir.exists()) {
              dynamicDir.mkdirs();
            }

            userManager =
                new UserManager(new File(OSUtils.getDynamicStorageLocation(), "logindata"));
            con = new LauncherConsole();
            if (Settings.getSettings().getConsoleActive()) {
              con.setVisible(true);
            }

            File credits = new File(OSUtils.getDynamicStorageLocation(), "credits.txt");

            try {
              if (!credits.exists()) {
                FileOutputStream fos = new FileOutputStream(credits);
                OutputStreamWriter osw = new OutputStreamWriter(fos);

                osw.write(
                    "FTB Launcher and Modpack Credits " + System.getProperty("line.separator"));
                osw.write("-------------------------------" + System.getProperty("line.separator"));
                osw.write("Launcher Developers:" + System.getProperty("line.separator"));
                osw.write("jjw123" + System.getProperty("line.separator"));
                osw.write("unv_annihilator" + System.getProperty("line.separator"));
                osw.write(
                    "Vbitz"
                        + System.getProperty("line.separator")
                        + System.getProperty("line.separator"));
                osw.write("Web Developers:" + System.getProperty("line.separator"));
                osw.write("captainnana" + System.getProperty("line.separator"));
                osw.write(
                    "Rob"
                        + System.getProperty("line.separator")
                        + System.getProperty("line.separator"));
                osw.write("Modpack Team:" + System.getProperty("line.separator"));
                osw.write("CWW256" + System.getProperty("line.separator"));
                osw.write("Lathanael" + System.getProperty("line.separator"));
                osw.write("Watchful11" + System.getProperty("line.separator"));

                osw.flush();

                TrackerUtils.sendPageView("net/ftb/gui/LaunchFrame.java", "Unique User (Credits)");
              }

              if (!Settings.getSettings().getLoaded() && !Settings.getSettings().getSnooper()) {
                TrackerUtils.sendPageView("net/ftb/gui/LaunchFrame.java", "Unique User (Settings)");
                Settings.getSettings().setLoaded(true);
              }

            } catch (FileNotFoundException e1) {
              Logger.logError(e1.getMessage());
            } catch (IOException e1) {
              Logger.logError(e1.getMessage());
            }

            LaunchFrame frame = new LaunchFrame(2);
            instance = frame;
            frame.setVisible(true);

            Thread.setDefaultUncaughtExceptionHandler(
                new Thread.UncaughtExceptionHandler() {
                  @Override
                  public void uncaughtException(Thread t, Throwable e) {
                    Logger.logError("Unhandled exception in " + t.toString(), e);
                  }
                });

            ModPack.addListener(frame.modPacksPane);
            ModPack.loadXml(getXmls());

            Map.addListener(frame.mapsPane);
            //				Map.loadAll();

            TexturePack.addListener(frame.tpPane);
            //				TexturePack.loadAll();

            UpdateChecker updateChecker = new UpdateChecker(buildNumber);
            if (updateChecker.shouldUpdate()) {
              LauncherUpdateDialog p = new LauncherUpdateDialog(updateChecker);
              p.setVisible(true);
            }
          }
        });
  }
예제 #8
0
  /**
   * Launch the application.
   *
   * @param args - CLI arguments
   */
  public static void main(String[] args) {
    // AnalyticsConfigData config = new AnalyticsConfigData("UA-37330489-2");
    // tracker = new JGoogleAnalyticsTracker(config, GoogleAnalyticsVersion.V_4_7_2,
    // DispatchMode.MULTI_THREAD);
    // tracker.setEnabled(true);

    if (!Settings.getSettings().getSnooper()) {
      //	tracker.trackPageViewFromReferrer("net/ftb/gui/LaunchFrame.java", "Launcher Start", "Feed
      // The Beast", "http://www.feed-the-beast.com", "/");
    }

    if (new File(Settings.getSettings().getInstallPath(), "AZLauncherLog.txt").exists()) {
      new File(Settings.getSettings().getInstallPath(), "AZLauncherLog.txt").delete();
    }
    if (new File(Settings.getSettings().getInstallPath(), "MinecraftLog.txt").exists()) {
      new File(Settings.getSettings().getInstallPath(), "MinecraftLog.txt").delete();
    }

    DownloadUtils thread = new DownloadUtils();
    thread.start();

    Logger.logInfo("FTBLaunch starting up (version " + version + ")");
    Logger.logInfo("Java version: " + System.getProperty("java.version"));
    Logger.logInfo("Java vendor: " + System.getProperty("java.vendor"));
    Logger.logInfo("Java home: " + System.getProperty("java.home"));
    Logger.logInfo(
        "Java specification: "
            + System.getProperty("java.vm.specification.name")
            + " version: "
            + System.getProperty("java.vm.specification.version")
            + " by "
            + System.getProperty("java.vm.specification.vendor"));
    Logger.logInfo(
        "Java vm: "
            + System.getProperty("java.vm.name")
            + " version: "
            + System.getProperty("java.vm.version")
            + " by "
            + System.getProperty("java.vm.vendor"));
    Logger.logInfo(
        "OS: "
            + System.getProperty("os.arch")
            + " "
            + System.getProperty("os.name")
            + " "
            + System.getProperty("os.version"));

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            StyleUtil.loadUiStyles();
            try {
              for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                  UIManager.setLookAndFeel(info.getClassName());
                  break;
                }
              }
            } catch (Exception e) {
              try {
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              } catch (Exception e1) {
              }
            }
            I18N.setupLocale();
            I18N.setLocale(Settings.getSettings().getLocale());

            if (noConfig) {
              InstallDirectoryDialog installDialog = new InstallDirectoryDialog();
              installDialog.setVisible(true);
            }

            File installDir = new File(Settings.getSettings().getInstallPath());
            if (!installDir.exists()) {
              installDir.mkdirs();
            }
            File dynamicDir = new File(OSUtils.getDynamicStorageLocation());
            if (!dynamicDir.exists()) {
              dynamicDir.mkdirs();
            }

            userManager =
                new UserManager(new File(OSUtils.getDynamicStorageLocation(), "logindata"));
            con = new LauncherConsole();
            if (Settings.getSettings().getConsoleActive()) {
              con.setVisible(true);
            }

            LaunchFrame frame = new LaunchFrame(2);
            instance = frame;
            frame.setVisible(true);

            Thread.setDefaultUncaughtExceptionHandler(
                new Thread.UncaughtExceptionHandler() {
                  @Override
                  public void uncaughtException(Thread t, Throwable e) {
                    Logger.logError("Unhandled exception in " + t.toString(), e);
                  }
                });

            ModPack.addListener(frame.modPacksPane);
            ModPack.loadXml(getXmls());

            Map.addListener(frame.mapsPane);
            Map.loadAll();

            //				TexturePack.addListener(frame.tpPane);
            //				TexturePack.loadAll();

            UpdateChecker updateChecker = new UpdateChecker(buildNumber);
            if (updateChecker.shouldUpdate()) {
              LauncherUpdateDialog p = new LauncherUpdateDialog(updateChecker);
              p.setVisible(true);
            }
          }
        });
  }
예제 #9
0
 /**
  * Constructor for ModPack class
  *
  * @param name - the name of the ModPack
  * @param author - the author of the ModPack
  * @param version - the version of the ModPack
  * @param logo - the logo file name for the ModPack
  * @param url - the ModPack file name
  * @param image - the splash image file name for the ModPack
  * @param dir - the directory for the ModPack
  * @param mcVersion - the minecraft version required for the ModPack
  * @param serverUrl - the server file name of the ModPack
  * @param info - the description for the ModPack
  * @param mods - string containing a list of mods included in the ModPack by default
  * @param oldVersions - string containing all available old versions of the ModPack
  * @param animation - the animation to display before minecraft launches
  * @param idx - the actual position of the modpack in the index
  * @throws IOException
  * @throws NoSuchAlgorithmException
  */
 public ModPack(
     String name,
     String author,
     String version,
     String logo,
     String url,
     String image,
     String dir,
     String mcVersion,
     String serverUrl,
     String info,
     String mods,
     String oldVersions,
     String animation,
     int idx,
     boolean privatePack)
     throws IOException, NoSuchAlgorithmException {
   index = idx;
   this.name = name;
   this.author = author;
   this.version = version;
   this.dir = dir;
   this.mcVersion = mcVersion;
   this.url = url;
   this.serverUrl = serverUrl;
   this.privatePack = privatePack;
   if (!animation.equalsIgnoreCase("")) {
     this.animation = animation;
   } else {
     this.animation = "empty";
   }
   logoName = logo;
   imageName = image;
   this.info = info;
   if (mods.isEmpty()) {
     this.mods = null;
   } else {
     this.mods = mods.split("; ");
   }
   if (oldVersions.isEmpty()) {
     this.oldVersions = null;
   } else {
     this.oldVersions = oldVersions.split(";");
   }
   String installPath = OSUtils.getDynamicStorageLocation();
   File tempDir = new File(installPath, "ModPacks" + sep + dir);
   File verFile = new File(tempDir, "version");
   URL url_;
   if (!upToDate(verFile)) {
     url_ = new URL(DownloadUtils.getStaticCreeperhostLink(logo));
     this.logo = Toolkit.getDefaultToolkit().createImage(url_);
     BufferedImage tempImg = ImageIO.read(url_);
     ImageIO.write(tempImg, "png", new File(tempDir, logo));
     tempImg.flush();
     url_ = new URL(DownloadUtils.getStaticCreeperhostLink(image));
     this.image = Toolkit.getDefaultToolkit().createImage(url_);
     tempImg = ImageIO.read(url_);
     ImageIO.write(tempImg, "png", new File(tempDir, image));
     tempImg.flush();
   } else {
     if (new File(tempDir, logo).exists()) {
       this.logo = Toolkit.getDefaultToolkit().createImage(tempDir.getPath() + sep + logo);
     } else {
       url_ = new URL(DownloadUtils.getStaticCreeperhostLink(logo));
       this.logo = Toolkit.getDefaultToolkit().createImage(url_);
       BufferedImage tempImg = ImageIO.read(url_);
       ImageIO.write(tempImg, "png", new File(tempDir, logo));
       tempImg.flush();
     }
     if (new File(tempDir, image).exists()) {
       this.image = Toolkit.getDefaultToolkit().createImage(tempDir.getPath() + sep + image);
     } else {
       url_ = new URL(DownloadUtils.getStaticCreeperhostLink(image));
       this.image = Toolkit.getDefaultToolkit().createImage(url_);
       BufferedImage tempImg = ImageIO.read(url_);
       ImageIO.write(tempImg, "png", new File(tempDir, image));
       tempImg.flush();
     }
   }
 }