use of com.biglybt.core.CoreOperation 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.core.CoreOperation in project BiglyBT by BiglySoftware.
the class NameItem method inplaceValueSet.
@Override
public boolean inplaceValueSet(TableCell cell, String value, boolean finalEdit) {
if (value.equalsIgnoreCase(cell.getText()) || "".equals(value) || "".equals(cell.getText()))
return true;
final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
final File target;
try {
target = new File(fileInfo.getFile(true).getParentFile(), value).getCanonicalFile();
} catch (IOException e) {
return false;
}
if (!finalEdit)
return !target.exists();
if (target.exists())
return false;
// code stolen from FilesView
final boolean[] result = { false };
boolean paused = fileInfo.getDownloadManager().pause();
FileUtil.runAsTask(new CoreOperationTask() {
@Override
public void run(CoreOperation operation) {
result[0] = fileInfo.setLink(target);
}
@Override
public ProgressCallback getProgressCallback() {
return null;
}
});
if (paused)
fileInfo.getDownloadManager().resume();
if (!result[0]) {
new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("FilesView.rename.failed.title"), MessageText.getString("FilesView.rename.failed.text")).open(null);
}
return true;
}
Aggregations