Search in sources :

Example 6 with SaveLocationChange

use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.

the class DownloadManagerMoveHandler method recalculatePath.

public static SaveLocationChange recalculatePath(DownloadManager dm) {
    Download download = PluginCoreUtils.wrap(dm);
    SaveLocationChange result = null;
    if (canGoToCompleteDir(dm)) {
        result = CURRENT_HANDLER.onCompletion(download, true, false);
    }
    if (result == null) {
        result = CURRENT_HANDLER.onInitialization(download, true, false);
    }
    return result;
}
Also used : Download(com.biglybt.pif.download.Download) SaveLocationChange(com.biglybt.pif.download.savelocation.SaveLocationChange)

Example 7 with SaveLocationChange

use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.

the class DiskManagerImpl method moveDownloadFilesWhenEndedOrRemoved.

private boolean moveDownloadFilesWhenEndedOrRemoved(final boolean removing, final boolean torrent_file_exists, final OperationStatus op_status) {
    try {
        start_stop_mon.enter();
        // Just a friendly alias.
        final boolean ending = !removing;
        /**
         * It doesn't matter if we set alreadyMoved, but don't end up moving the files.
         * This is because we only get called once (when it matters), which is when the
         * download has finished. We only want this to apply when the download has finished,
         * not if the user restarts the (already completed) download.
         */
        if (ending) {
            if (this.alreadyMoved) {
                return false;
            }
            this.alreadyMoved = true;
        }
        SaveLocationChange move_details;
        if (removing) {
            move_details = DownloadManagerMoveHandler.onRemoval(this.download_manager);
        } else {
            DownloadManagerMoveHandler.onCompletion(this.download_manager, new DownloadManagerMoveHandler.MoveCallback() {

                @Override
                public void perform(SaveLocationChange move_details) {
                    moveFiles(move_details, true, op_status);
                }
            });
            move_details = null;
        }
        if (move_details != null) {
            moveFiles(move_details, true, op_status);
        }
        return true;
    } finally {
        start_stop_mon.exit();
        if (!removing) {
            try {
                saveResumeData(false);
            } catch (Throwable e) {
                setFailed("Resume data save fails: " + Debug.getNestedExceptionMessage(e));
            }
        }
    }
}
Also used : DownloadManagerMoveHandler(com.biglybt.core.download.impl.DownloadManagerMoveHandler) SaveLocationChange(com.biglybt.pif.download.savelocation.SaveLocationChange)

Example 8 with SaveLocationChange

use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.

the class DiskManagerImpl method startSupport.

void startSupport() {
    // if the data file is already in the completed files dir, we want to use it
    boolean files_exist = false;
    if (download_manager.isPersistent()) {
        /**
         * Try one of these candidate directories, see if the data already exists there.
         */
        File[] move_to_dirs = DownloadManagerMoveHandler.getRelatedDirs(download_manager);
        for (int i = 0; i < move_to_dirs.length; i++) {
            String move_to_dir = move_to_dirs[i].getAbsolutePath();
            if (filesExist(move_to_dir)) {
                alreadyMoved = files_exist = true;
                download_manager.setTorrentSaveDir(move_to_dir);
                break;
            }
        }
    }
    reader.start();
    checker.start();
    writer.start();
    // save path calculations.
    if (!alreadyMoved && !download_manager.isDataAlreadyAllocated()) {
        // Check the files don't already exist in their current location.
        if (!files_exist) {
            files_exist = this.filesExist();
        }
        if (!files_exist) {
            SaveLocationChange transfer = DownloadManagerMoveHandler.onInitialisation(download_manager);
            if (transfer != null) {
                if (transfer.download_location != null || transfer.download_name != null) {
                    File dl_location = transfer.download_location;
                    if (dl_location == null) {
                        dl_location = download_manager.getAbsoluteSaveLocation().getParentFile();
                    }
                    if (transfer.download_name == null) {
                        download_manager.setTorrentSaveDir(dl_location.getAbsolutePath());
                    } else {
                        download_manager.setTorrentSaveDir(dl_location.getAbsolutePath(), transfer.download_name);
                    }
                }
                if (transfer.torrent_location != null || transfer.torrent_name != null) {
                    try {
                        download_manager.setTorrentFile(transfer.torrent_location, transfer.torrent_name);
                    } catch (DownloadManagerException e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }
    }
    // allocate / check every file
    int[] alloc_result = allocateFiles();
    int newFiles = alloc_result[0];
    int notNeededFiles = alloc_result[1];
    if (getState() == FAULTY) {
        return;
    }
    if (getState() == FAULTY) {
        return;
    }
    setState(DiskManager.CHECKING);
    resume_handler.start();
    if (checking_enabled) {
        if (newFiles == 0) {
            resume_handler.checkAllPieces(false);
            if (getRemainingExcludingDND() == 0) {
                checkFreePieceList(true);
            }
        } else if (newFiles + notNeededFiles != files.length) {
            // if not a fresh torrent, check pieces ignoring fast resume data
            resume_handler.checkAllPieces(true);
        }
    }
    if (getState() == FAULTY) {
        return;
    }
    // in all the above cases we want to continue to here if we have been "stopped" as
    // other components require that we end up either FAULTY or READY
    // 3.Change State
    // flag for an update of the 'downloaded' values for skipped files
    skipped_file_set_changed = true;
    setState(READY);
}
Also used : DownloadManagerException(com.biglybt.core.download.DownloadManagerException) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) CacheFile(com.biglybt.core.diskmanager.cache.CacheFile) File(java.io.File) SaveLocationChange(com.biglybt.pif.download.savelocation.SaveLocationChange)

Aggregations

SaveLocationChange (com.biglybt.pif.download.savelocation.SaveLocationChange)8 File (java.io.File)3 CoreOperation (com.biglybt.core.CoreOperation)1 CoreOperationTask (com.biglybt.core.CoreOperationTask)1 DiskManager (com.biglybt.core.disk.DiskManager)1 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)1 DownloadManagerException (com.biglybt.core.download.DownloadManagerException)1 DownloadManagerMoveHandler (com.biglybt.core.download.impl.DownloadManagerMoveHandler)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 Download (com.biglybt.pif.download.Download)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1