Ejemplo n.º 1
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"));
 }
Ejemplo n.º 2
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) {
       }
     }
   }
 }
Ejemplo n.º 3
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();
   }
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 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();
   }
 }
Ejemplo n.º 6
0
  public MapFilterDialog(MapUtils instance) {
    super(LaunchFrame.getInstance(), true);
    this.pane = instance;

    setupGui();

    getRootPane().setDefaultButton(apply);

    this.pane = instance;

    type.setSelectedItem(pane.type);
    origin.setSelectedItem(pane.origin);
    compatiblePack.setSelectedItem(pane.compatible);

    ArrayList<String> packs = new ArrayList<String>();
    compatiblePack.addItem(I18N.getLocaleString("MAIN_ALL"));
    packs.add(I18N.getLocaleString("MAIN_ALL"));
    for (int i = 0; i < Map.getMapArray().size(); i++) {
      String[] compat = Map.getMap(i).getCompatible();
      for (String compatable : compat) {
        if (!compatable.isEmpty()
            && !packs.contains(ModPack.getPack(compatable.trim()).getName())) {
          packs.add(ModPack.getPack(compatable.trim()).getName());
          compatiblePack.addItem(ModPack.getPack(compatable.trim()).getName());
        }
      }
    }

    type.setModel(new DefaultComboBoxModel(new String[] {"Client", "Server"}));
    origin.setModel(
        new DefaultComboBoxModel(
            new String[] {
              I18N.getLocaleString("MAIN_ALL"), "FTB", I18N.getLocaleString("FILTER_3THPARTY")
            }));
    compatiblePack.setModel(new DefaultComboBoxModel(packs.toArray()));

    apply.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            pane.compatible = (String) compatiblePack.getSelectedItem();
            pane.type = (String) type.getSelectedItem();
            pane.origin = (String) origin.getSelectedItem();
            pane.updateFilter();
            setVisible(false);
          }
        });

    cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            setVisible(false);
          }
        });

    search.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            SearchDialog sd = new SearchDialog(pane);
            sd.setVisible(true);
            setVisible(false);
          }
        });
  }