public void update() { JSONObject appJson; try { appJson = URLHelper.getJsonFromUrl(reference.getUpdateAppUrl()); } catch (IOException | ParseException e) { log.error("Failed to get latest download link, Nincraft server down?", e); return; } val downloadUrl = (String) appJson.get("url"); val appName = URLHelper .decodeSpaces(downloadUrl.substring(downloadUrl.lastIndexOf('/') + 1, downloadUrl.length())); val updatedApp = FileSystemHelper.getDownloadedFile(appName, "."); if (updatedApp.exists()) { log.info("No new updates found"); return; } else { log.info("Update found, downloading {}", appName); } try { FileUtils.copyURLToFile(new URL(downloadUrl), updatedApp); log.info("Downloaded {}", appName); } catch (IOException e) { log.error("Failed to download update", e); } }
private void addBatch(final Manifest manifestFile, final List<Mod> modList) { CurseFile curseFile; String projectIdPattern = "(\\d)+"; String projectNamePattern = "(((?:[a-z][a-z]+))(-)?)+"; for (String projectUrl : manifestFile.getBatchAddCurse()) { String projectId = URLHelper.parseCurseUrl(projectIdPattern, projectUrl); String projectName = URLHelper.parseCurseUrl(projectNamePattern, projectUrl); if (projectId != null && projectName != null) { curseFile = new CurseFile(projectId, projectName); curseFile.init(); log.debug("Adding {} from batch add", curseFile.getName()); modList.add(curseFile); manifestFile.getCurseFiles().add(curseFile); } else { log.warn("Unable to add {} from batch add", projectUrl); } } }
public CurseFile getCurseForgeDownloadLocation(final CurseFile curseFile) throws IOException { val url = curseFile.getCurseForgeDownloadUrl(); val projectName = curseFile.getName(); String encodedDownloadLocation = URLHelper.encodeSpaces(projectName); if (!encodedDownloadLocation.contains(reference.getJarFileExt()) || !encodedDownloadLocation.contains(reference.getZipFileExt())) { val newUrl = url + reference.getCookieTest1(); HttpURLConnection conn = (HttpURLConnection) new URL(newUrl).openConnection(); conn.setInstanceFollowRedirects(false); conn.connect(); String actualURL = conn.getURL().toString(); int retryCount = 0; while (conn.getResponseCode() != 200 || !actualURL.contains(reference.getJarFileExt()) || !actualURL.contains(reference.getZipFileExt())) { val headerLocation = conn.getHeaderField("Location"); if (headerLocation != null) { actualURL = headerLocation; } else { actualURL = conn.getURL().toString(); } if (retryCount > reference.getRetryCounter()) { break; } conn = (HttpURLConnection) new URL(newUrl).openConnection(); retryCount++; } encodedDownloadLocation = getEncodedDownloadLocation(projectName, actualURL, actualURL.lastIndexOf(reference.getUrlDelimiter()) + 1); curseFile.setDownloadUrl(actualURL.replace("http:", "https:")); } curseFile.setFileName(URLHelper.decodeSpaces(encodedDownloadLocation)); return curseFile; }
private JSONObject getCurseProjectJson(final CurseFile curseFile) throws ParseException, IOException { log.trace("Getting CurseForge Widget JSON..."); val projectId = curseFile.getProjectID(); val projectName = curseFile.getProjectName(); val modOrModPack = curseFile.getCurseforgeWidgetJson(); String urlStr = String.format(reference.getCurseforgeWidgetJsonUrl(), modOrModPack, projectName); log.debug(urlStr); try { return URLHelper.getJsonFromUrl(urlStr); } catch (final FileNotFoundException e) { urlStr = String.format(reference.getCurseforgeWidgetJsonUrl(), modOrModPack, projectId + "-" + projectName); log.debug(urlStr, e); return URLHelper.getJsonFromUrl(urlStr); } }
return notifyStatus(DownloadStatus.SKIPPED); val decodedFileName = URLHelper.decodeSpaces(downloadableFile.getFileName());
public List<ModLoader> updateForge(String minecraftVersion, List<ModLoader> modLoaders) { if (!arguments.isUpdateForge()) { log.trace("Updating Forge disabled"); return modLoaders; } for (ModLoader modLoader : modLoaders) { JSONObject fileListJson; if (modLoader.getRelease() == null) { log.warn("No Forge release type set for update, defaulting to recommended"); modLoader.setRelease("recommended"); } try { fileListJson = (JSONObject) (URLHelper.getJsonFromUrl(reference.getForgeUpdateUrl())).get("promos"); String updatedForgeVersion = (String) fileListJson.get(minecraftVersion + "-" + modLoader.getRelease()); String manifestForgeVersion = modLoader.getId().substring(modLoader.getId().indexOf('-') + 1); if (VersionHelper.compareVersions(manifestForgeVersion, updatedForgeVersion) < 0) { log.debug("Newer version of Forge found, updating to {}", updatedForgeVersion); modLoader.setId("forge-" + updatedForgeVersion); } } catch (IOException | ParseException e) { log.error("Failed to update Forge", e); } } return modLoaders; }