public boolean handleErrors() throws PluginException {
   if (externalDownloadStop()) {
     return false;
   }
   if (getFileSize() > 0 && totalLinkBytesLoaded != getFileSize()) {
     if (totalLinkBytesLoaded > getFileSize()) {
       /*
        * workaround for old bug deep in this downloadsystem. more data got loaded (maybe just counting bug) than filesize. but in
        * most cases the file is okay! WONTFIX because new downloadsystem is on its way
        */
       logger.severe("Filesize: " + getFileSize() + " Loaded: " + totalLinkBytesLoaded);
       if (caughtPluginException == null) {
         downloadable.setLinkStatus(LinkStatus.FINISHED);
       }
       return true;
     }
     logger.severe("Filesize: " + getFileSize() + " Loaded: " + totalLinkBytesLoaded);
     logger.severe("DOWNLOAD INCOMPLETE DUE TO FILESIZECHECK");
     if (caughtPluginException != null) {
       throw caughtPluginException;
     }
     throw new PluginException(
         LinkStatus.ERROR_DOWNLOAD_INCOMPLETE, _JDT.T.download_error_message_incomplete());
   }
   if (caughtPluginException == null) {
     downloadable.setLinkStatus(LinkStatus.FINISHED);
     downloadable.setVerifiedFileSize(outputCompleteFile.length());
     return true;
   } else {
     throw caughtPluginException;
   }
 }
 private void finalizeDownload(final File outputPartFile, final File outputCompleteFile)
     throws Exception {
   if (downloadable.rename(outputPartFile, outputCompleteFile)) {
     try {
         /* set current timestamp as lastModified timestamp */
       outputCompleteFile.setLastModified(System.currentTimeMillis());
     } catch (final Throwable ignore) {
       LogSource.exception(logger, ignore);
     }
   } else {
     throw new PluginException(
         LinkStatus.ERROR_DOWNLOAD_FAILED,
         _JDT.T.system_download_errors_couldnotrename(),
         LinkStatus.VALUE_LOCAL_IO_ERROR);
   }
 }
public enum VariousCrawledLinkFlags implements MatchesInterface<CrawledLink> {
  DOWNLOAD_LIST_DUPE(_JDT.T.DOWNLOAD_LIST_DUPE()) {
    public boolean matches(CrawledLink link) {
      return link != null && DownloadController.getInstance().hasDownloadLinkByID(link.getLinkID());
    }
  };

  private final String translation;

  private VariousCrawledLinkFlags(String translation) {
    this.translation = translation;
  }

  public String getTranslation() {
    return translation;
  }
}
 public String getNewPackageName(String nameFactory, String oldPackageName, String host) {
   if (StringUtils.isEmpty(nameFactory)) {
     if (!StringUtils.isEmpty(oldPackageName)) {
       return oldPackageName;
     }
     return host;
   }
   if (!StringUtils.isEmpty(oldPackageName)) {
     nameFactory = nameFactory.replaceAll("\\{PACKAGENAME\\}", oldPackageName);
   } else {
     nameFactory =
         nameFactory.replaceAll(
             "\\{PACKAGENAME\\}", _JDT.T.LinkCollector_addCrawledLink_variouspackage());
   }
   nameFactory = nameFactory.replaceAll("\\{HOSTNAME\\}", host);
   return nameFactory;
 }
  public LinkgrabberFilterRule duplicate() {
    LinkgrabberFilterRule ret = new LinkgrabberFilterRule();
    ret.accept = accept;
    ret.setEnabled(isEnabled());
    ret.setIconKey(getIconKey());
    ret.setFilenameFilter(getFilenameFilter());
    ret.setPackagenameFilter(getPackagenameFilter());
    ret.setFilesizeFilter(getFilesizeFilter());
    ret.setMatchAlwaysFilter(getMatchAlwaysFilter());
    ret.setFiletypeFilter(getFiletypeFilter());
    ret.setOnlineStatusFilter(getOnlineStatusFilter());
    ret.setOriginFilter(getOriginFilter());
    ret.setConditionFilter(getConditionFilter());
    ret.setPluginStatusFilter(getPluginStatusFilter());
    ret.setHosterURLFilter(getHosterURLFilter());
    ret.setName(_JDT.T.LinkgrabberFilterRule_duplicate(getName()));
    ret.setSourceURLFilter(getSourceURLFilter());

    return ret;
  }
  @Override
  protected void setStringValue(final String value, final AbstractNode object) {
    if (StringUtils.isEmpty(value) || object == null) {
      return;
    }
    File oldPath = LinkTreeUtils.getDownloadDirectory(object);
    File newPath = LinkTreeUtils.getDownloadDirectory(value, null, object);
    if (oldPath.equals(newPath)) {
      /* both paths are same, so nothing to do */
      return;
    }
    if (object instanceof CrawledPackage) {
      LinkCollector.getInstance()
          .getQueue()
          .add(
              new QueueAction<Object, RuntimeException>(
                  org.appwork.utils.event.queue.Queue.QueuePriority.HIGH) {
                @Override
                protected Object run() {
                  ((CrawledPackage) object).setDownloadFolder(value);
                  return null;
                }
              });
      return;
    } else if (object instanceof CrawledLink) {
      final CrawledPackage p = ((CrawledLink) object).getParentNode();
      try {
        Dialog.getInstance()
            .showConfirmDialog(
                Dialog.LOGIC_DONOTSHOW_BASED_ON_TITLE_ONLY | Dialog.STYLE_SHOW_DO_NOT_DISPLAY_AGAIN,
                _JDT.T.SetDownloadFolderAction_actionPerformed_(p.getName()),
                _JDT.T.SetDownloadFolderAction_msg(p.getName(), 1),
                null,
                _JDT.T.SetDownloadFolderAction_yes(),
                _JDT.T.SetDownloadFolderAction_no());
        LinkCollector.getInstance()
            .getQueue()
            .add(
                new QueueAction<Object, RuntimeException>(
                    org.appwork.utils.event.queue.Queue.QueuePriority.HIGH) {
                  @Override
                  protected Object run() {
                    p.setDownloadFolder(value);
                    return null;
                  }
                });
        return;
      } catch (DialogClosedException e) {
        return;
      } catch (DialogCanceledException e) {
        /* user clicked no */
      }

      final CrawledPackage pkg = new CrawledPackage();
      pkg.setExpanded(CFG_LINKCOLLECTOR.CFG.isPackageAutoExpanded());
      if (TYPE.NORMAL != p.getType()) {
        final String pkgName;
        if (object instanceof AbstractPackageNode) {
          pkgName =
              LinknameCleaner.cleanFileName(
                  object.getName(),
                  false,
                  true,
                  LinknameCleaner.EXTENSION_SETTINGS.REMOVE_KNOWN,
                  true);
        } else {
          pkgName =
              LinknameCleaner.cleanFileName(
                  object.getName(),
                  false,
                  true,
                  LinknameCleaner.EXTENSION_SETTINGS.REMOVE_ALL,
                  true);
        }
        pkg.setName(pkgName);
      } else {
        pkg.setName(p.getName());
      }
      pkg.setComment(p.getComment());
      pkg.setDownloadFolder(value);

      final java.util.List<CrawledLink> links = new ArrayList<CrawledLink>();
      links.add((CrawledLink) object);
      LinkCollector.getInstance()
          .getQueue()
          .add(
              new QueueAction<Object, RuntimeException>(
                  org.appwork.utils.event.queue.Queue.QueuePriority.HIGH) {

                @Override
                protected Object run() {
                  LinkCollector.getInstance().moveOrAddAt(pkg, links, -1);
                  return null;
                }
              });
    }
  }
 @Override
 public String toString() {
   return _JDT.T.ConnectExceptionInPluginBan(
       getProtocol() + "://" + getHost().concat(":").concat(Integer.toString(getPort())));
 }
Beispiel #8
0
 public static boolean addAccount(final Account ac) throws DialogNoAnswerException {
   try {
     checkAccount(ac);
   } catch (DialogNoAnswerException e) {
     throw e;
   } catch (Throwable e) {
     Dialog.getInstance()
         .showExceptionDialog(
             _GUI.T.accountdialog_check_failed(), _GUI.T.accountdialog_check_failed_msg(), e);
   }
   AccountError error = ac.getError();
   String errorMessage = ac.getErrorString();
   if (StringUtils.isEmpty(errorMessage)) {
     AccountInfo ai = ac.getAccountInfo();
     if (ai != null) {
       errorMessage = ai.getStatus();
     }
   }
   if (error != null) {
     switch (error) {
       case PLUGIN_ERROR:
         if (StringUtils.isEmpty(errorMessage)) {
           errorMessage = _JDT.T.AccountController_updateAccountInfo_status_plugin_defect();
         }
         Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_invalid(errorMessage));
         return false;
       case EXPIRED:
         Dialog.getInstance()
             .showConfirmDialog(
                 0,
                 _GUI.T.accountdialog_check_expired_title(),
                 _GUI.T.accountdialog_check_expired(ac.getUser()),
                 null,
                 _GUI.T.accountdialog_check_expired_renew(),
                 null);
         AccountController.getInstance().addAccount(ac, false);
         return true;
       case TEMP_DISABLED:
         if (StringUtils.isEmpty(errorMessage)) {
           errorMessage = _GUI.T.accountdialog_check_failed();
         }
         Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_result(errorMessage));
         AccountController.getInstance().addAccount(ac, false);
         return true;
       default:
       case INVALID:
         if (StringUtils.isEmpty(errorMessage)) {
           errorMessage = _GUI.T.accountdialog_check_failed_msg();
         }
         Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_invalid(errorMessage));
         return false;
     }
   } else {
     String message = null;
     AccountInfo ai = ac.getAccountInfo();
     if (ai != null) {
       message = ai.getStatus();
     }
     if (StringUtils.isEmpty(message)) {
       message = _GUI.T.lit_yes();
     }
     Dialog.getInstance().showMessageDialog(_GUI.T.accountdialog_check_valid(message));
     AccountController.getInstance().addAccount(ac, false);
     return true;
   }
 }
 public static String getTranslationForLocation() {
   return _JDT.T.SplitPackagesByHost_getTranslationForLocation();
 }
 public static String getTranslationForAskForNewDownloadFolderAndPackageName() {
   return _JDT.T.SplitPackagesByHost_getTranslationForAskForNewDownloadFolderAndPackageName();
 }
  @Override
  public boolean startDownload() throws Exception {
    try {
      downloadable.setConnectionHandler(this.getManagedConnetionHandler());
      final DiskSpaceReservation reservation = downloadable.createDiskSpaceReservation();
      DownloadPluginProgress downloadPluginProgress = null;
      try {
        if (!downloadable.checkIfWeCanWrite(
            new ExceptionRunnable() {

              @Override
              public void run() throws Exception {
                downloadable.checkAndReserve(reservation);
                createOutputFiles();
                try {
                  downloadable.lockFiles(
                      outputCompleteFile, outputFinalCompleteFile, outputPartFile);
                } catch (FileIsLockedException e) {
                  downloadable.unlockFiles(
                      outputCompleteFile, outputFinalCompleteFile, outputPartFile);
                  throw new PluginException(LinkStatus.ERROR_ALREADYEXISTS);
                }
              }
            },
            null)) {
          throw new SkipReasonException(SkipReason.INVALID_DESTINATION);
        }
        startTimeStamp = System.currentTimeMillis();
        downloadPluginProgress =
            new DownloadPluginProgress(downloadable, this, Color.GREEN.darker());
        downloadable.addPluginProgress(downloadPluginProgress);
        downloadable.setAvailable(AvailableStatus.TRUE);
        download(filePath, downloadable.isResumable());
      } finally {
        try {
          downloadable.free(reservation);
        } catch (final Throwable e) {
          LogSource.exception(logger, e);
        }
        try {
          downloadable.addDownloadTime(System.currentTimeMillis() - getStartTimeStamp());
        } catch (final Throwable e) {
        }
        downloadable.removePluginProgress(downloadPluginProgress);
      }
      if (isDownloadComplete()) {
        logger.info("Download is complete");
        final HashResult hashResult = getHashResult(downloadable, outputPartFile);
        if (hashResult != null) {
          logger.info(hashResult.toString());
          downloadable.setHashResult(hashResult);
        }
        if (hashResult == null || hashResult.match()) {
          downloadable.setVerifiedFileSize(outputPartFile.length());
        } else {
          if (hashResult.getHashInfo().isTrustworthy()) {
            throw new PluginException(
                LinkStatus.ERROR_DOWNLOAD_FAILED,
                _JDT.T.system_download_doCRC2_failed(hashResult.getHashInfo().getType()));
          }
        }
        finalizeDownload(outputPartFile, outputCompleteFile);
        downloadable.setLinkStatus(LinkStatus.FINISHED);
        return true;
      }
      if (externalDownloadStop() == false) {
        throw new PluginException(
            LinkStatus.ERROR_DOWNLOAD_INCOMPLETE, _JDT.T.download_error_message_incomplete());
      }
      return false;
    } finally {
      downloadable.unlockFiles(outputCompleteFile, outputFinalCompleteFile, outputPartFile);
      cleanupDownladInterface();
    }
  }
 protected void download(String filename, boolean resume)
     throws IOException, PluginException, SkipReasonException {
   final File file = outputPartFile;
   if (!simpleFTP.isBinary()) {
     logger.info("Warning: Download in ASCII mode may fail!");
   }
   final InetSocketAddress pasv = simpleFTP.pasv();
   resumed = false;
   if (resume) {
     final long resumePosition = file.length();
     if (resumePosition > 0) {
       resumed = true;
       totalLinkBytesLoadedLive.set(resumePosition);
       simpleFTP.sendLine("REST " + resumePosition);
       try {
         simpleFTP.readLines(new int[] {350}, "Resume not supported");
         downloadable.setResumeable(true);
       } catch (final IOException e) {
         cleanupDownladInterface();
         if (e.getMessage().contains("Resume not")) {
           file.delete();
           downloadable.setResumeable(false);
           throw new PluginException(LinkStatus.ERROR_RETRY);
         }
         throw e;
       }
     }
   }
   final RandomAccessFile raf;
   try {
     raf = IO.open(file, "rw");
   } catch (final IOException e) {
     throw new SkipReasonException(SkipReason.INVALID_DESTINATION, e);
   }
   Socket dataSocket = null;
   MeteredThrottledInputStream input = null;
   try {
     dataSocket =
         simpleFTP.createSocket(new InetSocketAddress(pasv.getHostName(), pasv.getPort()));
     dataSocket.setSoTimeout(30 * 1000);
     simpleFTP.sendLine("RETR " + filename);
     simpleFTP.readLines(new int[] {150, 125}, null);
     input =
         new MeteredThrottledInputStream(dataSocket.getInputStream(), new AverageSpeedMeter(10));
     connectionHandler.addThrottledConnection(input);
     if (resumed) {
       /* in case we do resume, reposition the writepointer */
       totalLinkBytesLoaded = file.length();
       raf.seek(totalLinkBytesLoaded);
     } else {
       totalLinkBytesLoaded = 0;
     }
     final byte[] buffer = new byte[32767];
     int bytesRead = 0;
     while ((bytesRead = input.read(buffer)) != -1) {
       if (abort.get()) {
         break;
       }
       if (bytesRead > 0) {
         raf.write(buffer, 0, bytesRead);
         totalLinkBytesLoaded += bytesRead;
         totalLinkBytesLoadedLive.addAndGet(bytesRead);
       }
     }
     /* max 10 seks wait for buggy servers */
     simpleFTP.getSocket().setSoTimeout(20 * 1000);
     simpleFTP.shutDownSocket(dataSocket);
     input.close();
     try {
       simpleFTP.readLine();
     } catch (SocketTimeoutException e) {
       LogSource.exception(logger, e);
     }
   } catch (SocketTimeoutException e) {
     LogSource.exception(logger, e);
     error(
         new PluginException(
             LinkStatus.ERROR_DOWNLOAD_INCOMPLETE,
             _JDT.T.download_error_message_networkreset(),
             LinkStatus.VALUE_NETWORK_IO_ERROR));
   } catch (SocketException e) {
     LogSource.exception(logger, e);
     error(
         new PluginException(
             LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
             _JDT.T.download_error_message_networkreset(),
             1000l * 60 * 5));
   } catch (ConnectException e) {
     LogSource.exception(logger, e);
     error(
         new PluginException(
             LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE,
             _JDT.T.download_error_message_networkreset(),
             1000l * 60 * 5));
   } finally {
     close(raf);
     close(input);
     close(dataSocket);
     cleanupDownladInterface();
     if (totalLinkBytesLoaded >= 0) {
       downloadable.setDownloadBytesLoaded(totalLinkBytesLoaded);
     }
   }
 }