use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method moveTorrentFile.
@Override
public void moveTorrentFile(File new_parent_dir, String new_name) throws DownloadManagerException {
SaveLocationChange slc = new SaveLocationChange();
slc.torrent_location = new_parent_dir;
slc.torrent_name = new_name;
File torrent_file_now = new File(getTorrentFileName());
if (!slc.isDifferentTorrentLocation(torrent_file_now)) {
return;
}
boolean is_paused = this.pause();
try {
moveTorrentFile0(new_parent_dir, new_name);
} finally {
if (is_paused) {
this.resume();
}
}
}
use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.
the class DiskManagerImpl method moveDataFiles.
@Override
public void moveDataFiles(File new_parent_dir, String new_name, OperationStatus op_status) {
SaveLocationChange loc_change = new SaveLocationChange();
loc_change.download_location = new_parent_dir;
loc_change.download_name = new_name;
moveFiles(loc_change, false, op_status);
}
use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method moveDataFiles.
public void moveDataFiles(final File destination, final String new_name, final boolean live) throws DownloadManagerException {
if (destination == null && new_name == null) {
throw new NullPointerException("destination and new name are both null");
}
if (!canMoveDataFiles()) {
throw new DownloadManagerException("canMoveDataFiles is false!");
}
/**
* Test to see if the download is to be moved somewhere where it already
* exists. Perhaps you might think it is slightly unnecessary to check this,
* but I would prefer this test left in - we want to prevent pausing
* unnecessarily pausing a running torrent (it fires off listeners, which
* might try to move the download).
*
* This helps us avoid a situation with AzCatDest...
*/
SaveLocationChange slc = new SaveLocationChange();
slc.download_location = destination;
slc.download_name = new_name;
File current_location = getSaveLocation();
if (slc.normaliseDownloadLocation(current_location).equals(current_location)) {
return;
}
try {
FileUtil.runAsTask(new CoreOperationTask() {
private ProgressCallback callback = new ProgressCallback() {
@Override
public int getProgress() {
return (getMoveProgress());
}
};
@Override
public void run(CoreOperation operation) {
try {
if (live) {
moveDataFilesSupport0(destination, new_name);
} else {
moveDataFilesSupport(destination, new_name);
}
} catch (DownloadManagerException e) {
throw (new RuntimeException(e));
}
}
@Override
public ProgressCallback getProgressCallback() {
return (callback);
}
});
} catch (RuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof DownloadManagerException) {
throw ((DownloadManagerException) cause);
}
throw (e);
}
}
use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.
the class DownloadManagerImpl method destroy.
@Override
public void destroy(boolean is_duplicate) {
destroyed = true;
if (is_duplicate) {
// minimal tear-down
controller.destroy();
} else {
try {
// Data files don't exist, so we just don't do anything.
if (!getSaveLocation().exists()) {
return;
}
DiskManager dm = this.getDiskManager();
if (dm != null) {
dm.downloadRemoved();
return;
}
SaveLocationChange move_details;
move_details = DownloadManagerMoveHandler.onRemoval(this);
if (move_details == null) {
return;
}
boolean can_move_torrent = move_details.hasTorrentChange();
try {
if (move_details.hasDownloadChange()) {
this.moveDataFiles(move_details.download_location, move_details.download_name);
}
} catch (Exception e) {
can_move_torrent = false;
Logger.log(new LogAlert(this, true, "Problem moving files to removed download directory", e));
}
// This code will silently fail if the torrent file doesn't exist.
if (can_move_torrent) {
try {
this.moveTorrentFile(move_details.torrent_location, move_details.torrent_name);
} catch (Exception e) {
Logger.log(new LogAlert(this, true, "Problem moving torrent to removed download directory", e));
}
}
} finally {
clearFileLinks();
controller.destroy();
}
}
}
use of com.biglybt.pif.download.savelocation.SaveLocationChange in project BiglyBT by BiglySoftware.
the class DownloadManagerMoveHandler method onCompletion.
public static SaveLocationChange onCompletion(DownloadManager dm, MoveCallback callback) {
if (!isApplicableDownload(dm)) {
return null;
}
if (dm.getDownloadState().getFlag(DownloadManagerState.FLAG_MOVE_ON_COMPLETION_DONE)) {
logInfo("Completion flag already set on " + describe(dm) + ", skip move-on-completion behaviour.", dm);
return null;
}
SaveLocationChange sc;
try {
sc = CURRENT_HANDLER.onCompletion(PluginCoreUtils.wrap(dm), true, true);
} catch (Exception e) {
logError("Error trying to determine on-completion location.", dm, e);
return null;
}
if (callback != null && sc != null) {
callback.perform(sc);
}
logInfo("Setting completion flag on " + describe(dm) + ", may have been set before.", dm);
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_MOVE_ON_COMPLETION_DONE, true);
return sc;
}
Aggregations