Search in sources :

Example 1 with Download

use of net.technicpack.launchercore.mirror.download.Download in project LauncherV3 by TechnicPack.

the class Utils method downloadFile.

public static Download downloadFile(String url, String name, String output, File cache, IFileVerifier verifier, DownloadListener listener) throws IOException, InterruptedException {
    int tries = DOWNLOAD_RETRIES;
    File outputFile = null;
    Download download = null;
    while (tries > 0) {
        getLogger().info("Starting download of " + url + ", with " + tries + " tries remaining");
        tries--;
        download = new Download(getFullUrl(url), name, output);
        download.setListener(listener);
        download.run();
        if (download.getResult() != Download.Result.SUCCESS) {
            if (download.getOutFile() != null) {
                download.getOutFile().delete();
            }
            if (Thread.interrupted())
                throw new InterruptedException();
            System.err.println("Download of " + url + " Failed!");
            if (listener != null) {
                listener.stateChanged("Download failed, retries remaining: " + tries, 0F);
            }
        } else {
            if (download.getOutFile().exists() && (verifier == null || verifier.isFileValid(download.getOutFile()))) {
                outputFile = download.getOutFile();
                break;
            }
        }
    }
    if (outputFile == null) {
        throw new DownloadException("Failed to download " + url, download != null ? download.getException() : null);
    }
    if (cache != null) {
        FileUtils.copyFile(outputFile, cache);
    }
    return download;
}
Also used : DownloadException(net.technicpack.launchercore.exception.DownloadException) Download(net.technicpack.launchercore.mirror.download.Download)

Aggregations

DownloadException (net.technicpack.launchercore.exception.DownloadException)1 Download (net.technicpack.launchercore.mirror.download.Download)1