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 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); } }
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"); } }