Search in sources :

Example 1 with CoreOperationTask

use of com.biglybt.core.CoreOperationTask 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);
    }
}
Also used : CoreOperation(com.biglybt.core.CoreOperation) CoreOperationTask(com.biglybt.core.CoreOperationTask) File(java.io.File) SaveLocationChange(com.biglybt.pif.download.savelocation.SaveLocationChange)

Example 2 with CoreOperationTask

use of com.biglybt.core.CoreOperationTask 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;
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) CoreOperation(com.biglybt.core.CoreOperation) CoreOperationTask(com.biglybt.core.CoreOperationTask) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) IOException(java.io.IOException) File(java.io.File)

Aggregations

CoreOperation (com.biglybt.core.CoreOperation)2 CoreOperationTask (com.biglybt.core.CoreOperationTask)2 File (java.io.File)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 SaveLocationChange (com.biglybt.pif.download.savelocation.SaveLocationChange)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 IOException (java.io.IOException)1