Пример #1
0
 public static Download downloadFile(
     String url, String output, String cacheName, String md5, DownloadListener listener)
     throws IOException {
   int tries = Settings.getLoginTries();
   File outputFile = null;
   Download download = null;
   while (tries > 0) {
     System.out.println("Starting download of " + url + ", with " + tries + " tries remaining");
     tries--;
     download = new Download(url, output);
     download.setListener(listener);
     download.run();
     if (!download.isSuccess()) {
       if (download.getOutFile() != null) {
         download.getOutFile().delete();
       }
       System.err.println("Download of " + url + " Failed!");
       if (listener != null)
         listener.stateChanged("Download Failed, retries remaining: " + tries, 0F);
     } else {
       if (md5 != null) {
         String resultMD5 = MD5Utils.getMD5(download.getOutFile());
         System.out.println("Expected MD5: " + md5 + " Calculated MD5: " + resultMD5);
         if (resultMD5.equals(md5)) {
           outputFile = download.getOutFile();
           break;
         }
       } else {
         outputFile = download.getOutFile();
         break;
       }
     }
   }
   if (outputFile == null) {
     throw new IOException("Failed to download " + url);
   }
   if (cacheName != null) {
     Utils.copy(outputFile, new File(Launcher.getGameUpdater().getBinCacheDir(), cacheName));
   }
   return download;
 }
Пример #2
0
 public void stateChanged(String message, float progress) {
   if (listener != null) listener.stateChanged(message, progress);
 }