private void removePreviousModVersion(String modName, String installedVersion) { try { // Mod has been previously installed uninstall previous version File previousModZip = new File(cacheDir, modName + "-" + installedVersion + ".zip"); ZipFile zf = new ZipFile(previousModZip); Enumeration<? extends ZipEntry> entries = zf.entries(); // Go through zipfile of previous version and delete all file from // Modpack that exist in the zip while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { continue; } File file = new File(GameUpdater.modpackDir, entry.getName()); Util.log("Deleting '%s'", entry.getName()); if (file.exists()) { // File from mod exists.. delete it file.delete(); } } InstalledModsYML.removeMod(modName); } catch (IOException e) { e.printStackTrace(); } }
public boolean downloadModPackage(String name, String filename, File downloadedFile) { try { // Install from cache if md5 matches otherwise download and insert // to cache File modCache = new File(cacheDir, filename); String md5Name = "mods\\" + name + "\\" + filename; if (modCache.exists() && MD5Utils.checksumCachePath(filename, md5Name)) { stateChanged("Copying " + filename + " from cache", 0); copy(modCache, downloadedFile); stateChanged("Copied " + filename + " from cache", 100); return true; } else { String mirrorURL = "mods/" + name + "/" + filename; String fallbackURL = fallbackModsURL + name + "/" + filename; String url = MirrorUtils.getMirrorUrl(mirrorURL, fallbackURL, this); String fileMD5 = MD5Utils.getMD5FromList(mirrorURL); Download download = DownloadUtils.downloadFile(url, downloadedFile.getPath(), filename, fileMD5, this); return download.isSuccess(); } } catch (MalformedURLException e) { Util.log( "Cannot download the mod '%s'. Does the exact filename exist on the mirror?", "mods/" + name + "/" + filename); } catch (IOException e) { e.printStackTrace(); } return false; }
public static boolean setModPack(String modPack, String modPackLabel, boolean ignoreCheck) { if (modPack.equalsIgnoreCase(currentModPack)) { return true; } if (!ignoreCheck) { Map<String, String> modPacks = getModPacks(); if (!modPacks.containsKey(modPack)) { // Mod Pack not in list Util.log("ModPack '%s' not in '%s' file.", modPackLabel, MODPACKS_YML); return false; } } SettingsUtil.setModPack(modPack); currentModPack = modPack; currentModPackLabel = modPackLabel; GameUpdater.setModpackDirectory(currentModPack); currentModPackDirectory = new File(GameUpdater.workDir, currentModPack); currentModPackDirectory.mkdirs(); ModPackYML.updateModPackYML(true); return true; }
public static void downloadModPackResources(String name, String label, File path) { Map<String, String> downloadFileList = getModPackResources(name, path); if (downloadFileList.size() > 0 && DownloadUtils.downloadFiles(downloadFileList, 30, TimeUnit.SECONDS) != downloadFileList.size()) { Util.log("Could not download all resources for modpack '%s'.", label); } }
@Override protected Object doInBackground() { URL url = null; try { url = new URL(this.url); if (MirrorUtils.isAddressReachable(url.toString())) { editorPane.setVisible(false); editorPane.setContentType("text/html"); // editorPane.setEditable(false); ToolTipManager.sharedInstance().registerComponent(editorPane); editorPane.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (HyperlinkEvent.EventType.ACTIVATED == e.getEventType()) { try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(e.getURL().toURI()); } } catch (IOException e1) { e1.printStackTrace(); } catch (URISyntaxException e1) { e1.printStackTrace(); } } } }); editorPane.addPropertyChangeListener(this); editorPane.setPage(url); } else { editorPane.setText("Oh Noes! Our Tumblr Feed is Down!"); } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { editorPane.setText("Oh Noes! Our Tumblr Server is Down!"); Util.log("Tumbler log @ '%' not avaliable.", url); } return null; }
public static void downloadAllFiles(Map<String, String> fileMap) { int size = fileMap.size(); if (size > 0 && DownloadUtils.downloadFiles(fileMap, 30, TimeUnit.SECONDS) != size) { Util.log("Could not download all files"); } }