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); } }
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; }
return notifyStatus(DownloadStatus.SKIPPED); val decodedFileName = URLHelper.decodeSpaces(downloadableFile.getFileName());