// refactored the download logic into a separate method
  public void handleMagnetRequest(String arg) {
    LOG.trace("enter handleMagnetRequest");

    ActivityCallback callback = restoreApplication();
    MagnetOptions options[] = MagnetOptions.parseMagnet(arg);

    if (options.length == 0) {
      if (LOG.isWarnEnabled()) LOG.warn("Invalid magnet, ignoring: " + arg);
      return;
    }

    callback.handleMagnets(options);
  }
  private void handleCoreDownloader() {
    File possibleTorrentFile = null;

    possibleTorrentFile = downloader.getSaveFile();
    String fileExtension = FileUtils.getFileExtension(possibleTorrentFile);
    if ("torrent".equalsIgnoreCase(fileExtension)) {
      try {
        shareTorrentFile(possibleTorrentFile);
        downloadManager.downloadTorrent(possibleTorrentFile, null, false);
        downloadItems.remove(getDownloadItem(downloader));
      } catch (DownloadException e) {
        final File torrentFile = possibleTorrentFile;
        activityCallback.handleDownloadException(
            new DownloadAction() {
              @Override
              public void download(File saveDirectory, boolean overwrite) throws DownloadException {
                downloadManager.downloadTorrent(torrentFile, saveDirectory, overwrite);
                downloadItems.remove(getDownloadItem(downloader));
              }

              @Override
              public void downloadCanceled(DownloadException ignored) {
                // nothing to do
              }
            },
            e,
            false);
      }
    }
  }
  private void handleBTTorrentFileDownloader() {
    File torrentFile = null;
    final BTTorrentFileDownloader btTorrentFileDownloader = (BTTorrentFileDownloader) downloader;
    try {
      torrentFile = btTorrentFileDownloader.getTorrentFile();
      shareTorrentFile(torrentFile);
      downloadManager.downloadTorrent(torrentFile, null, false);
      downloadItems.remove(getDownloadItem(downloader));
    } catch (DownloadException e) {
      final File torrentFileFinal = torrentFile;
      activityCallback.handleDownloadException(
          new DownloadAction() {
            @Override
            public void download(File saveDirectory, boolean overwrite) throws DownloadException {
              downloadManager.downloadTorrent(torrentFileFinal, saveDirectory, overwrite);
              downloadItems.remove(getDownloadItem(downloader));
            }

            @Override
            public void downloadCanceled(DownloadException ex) {
              if (!torrentManager.isDownloadingTorrent(torrentFileFinal)) {
                // need to delete to clean up the torrent file in the
                // incomplete directory
                FileUtils.forceDelete(torrentFileFinal);
              }
            }
          },
          e,
          false);
    }
  }
Exemple #4
0
 @Override
 public void stop() {
   // TODO refactor to prompt from the gui
   if (activityCallback.promptTorrentUploadCancel(torrent)) {
     new ManagedThread(
             new Runnable() {
               @Override
               public void run() {
                 torrent.stop();
               }
             },
             "BTUploader Stop Torrent")
         .start();
     cancel();
   }
 }
Exemple #5
0
 private void remove() {
   torrent.removeListener(this);
   torrentUploadManager.removeMemento(torrent);
   activityCallback.removeUpload(this);
 };
Exemple #6
0
 private void torrentStopped() {
   activityCallback.removeUpload(this);
   stopTime = System.currentTimeMillis();
 }
Exemple #7
0
 private void torrentStarted() {
   startTime = System.currentTimeMillis();
   stopTime = 0;
   activityCallback.addUpload(this);
 }
 private void handleTorrentRequest(String arg) {
   LOG.trace("enter handleTorrentRequest");
   ActivityCallback callback = restoreApplication();
   File torrentFile = new File(arg.trim());
   callback.handleTorrent(torrentFile);
 }