@Override public void refreshList(String[] sss) throws Exception { String content = NetUtils.doGet("http://optifine.net/downloads"); if (versions != null) return; versionMap = new HashMap<>(); versions = new ArrayList<>(); content = content.replace(" ", " ").replace(">", ">").replace("<", "<"); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(new StringBufferInputStream(content)); Element r = doc.getDocumentElement(); NodeList tables = r.getElementsByTagName("table"); for (int i = 0; i < tables.getLength(); i++) { Element e = (Element) tables.item(i); if ("downloadTable".equals(e.getAttribute("class"))) { NodeList tr = e.getElementsByTagName("tr"); for (int k = 0; k < tr.getLength(); k++) { NodeList downloadLine = ((Element) tr.item(k)).getElementsByTagName("td"); OptiFineVersion v = new OptiFineVersion(); for (int j = 0; j < downloadLine.getLength(); j++) { Element td = (Element) downloadLine.item(j); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineMirror")) v.mirror = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDownload")) v.dl = ((Element) td.getElementsByTagName("a").item(0)).getAttribute("href"); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineDate")) v.date = td.getTextContent(); if (StrUtils.startsWith(td.getAttribute("class"), "downloadLineFile")) v.ver = td.getTextContent(); } if (StrUtils.isBlank(v.mcver)) { Pattern p = Pattern.compile("OptiFine (.*?) "); Matcher m = p.matcher(v.ver); while (m.find()) v.mcver = StrUtils.formatVersion(m.group(1)); } InstallerVersion iv = new InstallerVersion(v.ver, StrUtils.formatVersion(v.mcver)); iv.installer = iv.universal = v.mirror; root.add(v); versions.add(iv); List<InstallerVersion> ivl = ArrayUtils.tryGetMapWithList(versionMap, StrUtils.formatVersion(v.mcver)); ivl.add(iv); } } } } catch (ParserConfigurationException | SAXException | IOException | DOMException ex) { throw new RuntimeException(ex); } Collections.sort(versions, InstallerVersionComparator.INSTANCE); }
@Override public void executeTask() throws Exception { HMCLog.log("Extracting install profiles..."); ZipFile zipFile = new ZipFile(forgeInstaller); ZipEntry entry = zipFile.getEntry("install_profile.json"); String content = NetUtils.getStreamContent(zipFile.getInputStream(entry)); InstallProfile profile = C.gsonPrettyPrinting.fromJson(content, InstallProfile.class); File from = new File(gameDir, "versions" + File.separator + profile.install.minecraft); if (!from.exists()) if (MessageBox.Show(C.i18n("install.no_version_if_intall")) == MessageBox.YES_OPTION) { if (!mp.version().install(profile.install.minecraft, null)) throw new IllegalStateException(C.i18n("install.no_version")); } else throw new IllegalStateException(C.i18n("install.no_version")); File to = new File(gameDir, "versions" + File.separator + profile.install.target); to.mkdirs(); HMCLog.log( "Copying jar..." + profile.install.minecraft + ".jar to " + profile.install.target + ".jar"); FileUtils.copyFile( new File(from, profile.install.minecraft + ".jar"), new File(to, profile.install.target + ".jar")); HMCLog.log("Creating new version profile..." + profile.install.target + ".json"); /* * for (MinecraftLibrary library : profile.versionInfo.libraries) * if (library.name.startsWith("net.minecraftforge:forge:")) * library.url = installerVersion.universal; */ FileUtils.write( new File(to, profile.install.target + ".json"), C.gsonPrettyPrinting.toJson(profile.versionInfo)); HMCLog.log("Extracting universal forge pack..." + profile.install.filePath); entry = zipFile.getEntry(profile.install.filePath); InputStream is = zipFile.getInputStream(entry); MinecraftLibrary forge = new MinecraftLibrary(profile.install.path); forge.init(); File file = new File(gameDir, "libraries/" + forge.formatted); file.getParentFile().mkdirs(); try (FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos)) { int c; while ((c = is.read()) != -1) bos.write((byte) c); } }
@Override public void refreshList(String[] needed) throws Exception { String s = NetUtils.get(C.URL_LITELOADER_LIST); if (root != null) return; root = C.gson.fromJson(s, LiteLoaderVersionsRoot.class); versionMap = new HashMap<>(); versions = new ArrayList<>(); for (Map.Entry<String, LiteLoaderMCVersions> arr : root.versions.entrySet()) { ArrayList<InstallerVersion> al = new ArrayList<>(); LiteLoaderMCVersions mcv = arr.getValue(); for (Map.Entry<String, LiteLoaderVersion> entry : mcv.artefacts.get("com.mumfrey:liteloader").entrySet()) { if ("latest".equals(entry.getKey())) continue; LiteLoaderVersion v = entry.getValue(); LiteLoaderInstallerVersion iv = new LiteLoaderInstallerVersion(v.version, StrUtils.formatVersion(arr.getKey())); iv.universal = "http://dl.liteloader.com/versions/com/mumfrey/liteloader/" + arr.getKey() + "/" + v.file; iv.tweakClass = v.tweakClass; iv.libraries = Arrays.copyOf(v.libraries, v.libraries.length); iv.installer = "http://dl.liteloader.com/redist/" + iv.mcVersion + "/liteloader-installer-" + iv.selfVersion.replace("_", "-") + ".jar"; al.add(iv); versions.add(iv); } Collections.sort(al, new InstallerVersionNewerComparator()); versionMap.put(StrUtils.formatVersion(arr.getKey()), al); } Collections.sort(versions, InstallerVersionComparator.INSTANCE); }
@Override public boolean executeTask() { if (mv == null || assetsDownloadURLs == null) { setFailReason(new RuntimeException(C.i18n("assets.not_refreshed"))); return false; } progress = 0; max = assetsDownloadURLs.size(); al = new ArrayList<>(); int hasDownloaded = 0; for (int i = 0; i < max; i++) { String mark = assetsDownloadURLs.get(i); String url = u + mark; File location = assetsLocalNames.get(i); if (!location.getParentFile().exists()) location.getParentFile().mkdirs(); if (location.isDirectory()) continue; boolean need = true; try { if (location.exists()) { FileInputStream fis = new FileInputStream(location); String sha = DigestUtils.sha1Hex(NetUtils.getBytesFromStream(fis)); IOUtils.closeQuietly(fis); if (contents.get(i).eTag.equals(sha)) { hasDownloaded++; HMCLog.log( "File " + assetsLocalNames.get(i) + " has downloaded successfully, skipped downloading."); if (ppl != null) ppl.setProgress(this, hasDownloaded, max); continue; } } } catch (IOException e) { HMCLog.warn("Failed to get hash: " + location, e); need = !location.exists(); } if (need) al.add(new FileDownloadTask(url, location).setTag(mark)); } return true; }