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(); }
@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(); } }
/** * 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(); } } }