Search in sources :

Example 46 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class LocationChanger method getWorkableFolder.

/**
 * Returns a 'workable' folder as a substitute for the given non-existing folder. This method will return the
 * first existing parent if there is one, to the first existing local volume otherwise. In the unlikely event
 * that no local volume exists, <code>null</code> will be returned.
 *
 * @param folder folder for which to find a workable folder
 * @return a 'workable' folder for the given non-existing folder, <code>null</code> if there is none.
 */
AbstractFile getWorkableFolder(AbstractFile folder) {
    // Look for an existing parent
    AbstractFile newFolder = folder;
    do {
        newFolder = newFolder.getParent();
        if (newFolder != null && newFolder.exists())
            return newFolder;
    } while (newFolder != null);
    // Fall back to the first existing volume
    AbstractFile[] localVolumes = LocalFile.getVolumes();
    for (AbstractFile volume : localVolumes) {
        if (volume.exists())
            return volume;
    }
    // No volume could be found, return null
    return null;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 47 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class LocationChanger method tryChangeCurrentFolderInternal.

/**
 * This method is triggered internally (i.e not by user request) to change the current
 * folder to the given folder
 *
 * @param folderURL the URL of the folder to switch to
 * @param runnable an Implementation of {@link Runnable} that would be executed after the location is changed
 */
public void tryChangeCurrentFolderInternal(FileTableTab tab, Runnable runnable) {
    mainFrame.setNoEventsMode(true);
    // Set cursor to hourglass/wait
    mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    Runnable locationSetter = () -> {
        AbstractFile folder = getWorkableLocation(tab.getLocation());
        AbstractFile selectedFile = tab.getSelectedFile();
        try {
            locationManager.setCurrentFolder(folder, selectedFile, true);
            tab.setSelectedFile(null);
        } finally {
            mainFrame.setNoEventsMode(false);
            // Restore default cursor
            mainFrame.setCursor(Cursor.getDefaultCursor());
            // Execute the given runnable
            runnable.run();
        }
    };
    if (EventQueue.isDispatchThread())
        new Thread(locationSetter).start();
    else
        locationSetter.run();
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) Cursor(java.awt.Cursor)

Example 48 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class DeleteJob method processFile.

// //////////////////////////
// FileJob implementation //
// //////////////////////////
/**
 * Deletes recursively the given file or folder.
 *
 * @param file the file or folder to delete
 * @param recurseParams not used
 *
 * @return <code>true</code> if the file has been completely deleted.
 */
@Override
protected boolean processFile(AbstractFile file, Object recurseParams) {
    if (getState() == FileJobState.INTERRUPTED)
        return false;
    // Delete files recursively, only if trash is not used.
    DialogAction ret;
    if (!moveToTrash && file.isDirectory()) {
        String filePath = file.getAbsolutePath();
        filePath = filePath.substring(getBaseSourceFolder().getAbsolutePath(false).length() + 1, filePath.length());
        // Important: symlinks must *not* be followed -- following symlinks could have disastrous effects.
        if (!file.isSymlink()) {
            do {
                // Delete each file in this folder
                try {
                    AbstractFile[] subFiles = file.ls();
                    for (int i = 0; i < subFiles.length && getState() != FileJobState.INTERRUPTED; i++) {
                        // Notify job that we're starting to process this file (needed for recursive calls to processFile)
                        nextFile(subFiles[i]);
                        processFile(subFiles[i], null);
                    }
                    break;
                } catch (IOException e) {
                    LOGGER.debug("IOException caught", e);
                    ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_read_file", filePath));
                    // Retry loops
                    if (ret == FileJobAction.RETRY)
                        continue;
                    // Cancel, skip or close dialog returns false
                    return false;
                }
            } while (true);
        }
    }
    // Return now if the job was interrupted, so that we do not attempt to delete this folder
    if (getState() == FileJobState.INTERRUPTED)
        return false;
    do {
        // Loop for retry
        try {
            deleteFile(file);
            return true;
        } catch (IOException e) {
            LOGGER.debug("IOException caught", e);
            ret = showErrorDialog(errorDialogTitle, Translator.get(file.isDirectory() ? "cannot_delete_folder" : "cannot_delete_file", file.getName()));
            // Retry loops
            if (ret == FileJobAction.RETRY)
                continue;
            // Cancel, skip or close dialog returns false
            return false;
        }
    } while (true);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) DialogAction(com.mucommander.ui.dialog.DialogAction) IOException(java.io.IOException)

Example 49 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class SelfUpdateJob method createTemporaryFolder.

private static AbstractFile createTemporaryFolder() {
    AbstractFile tempFolder;
    try {
        tempFolder = FileFactory.getTemporaryFile("mucomander-self-update", true);
        tempFolder.mkdir();
    } catch (IOException e) {
        tempFolder = FileFactory.getTemporaryFolder();
    }
    return tempFolder;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) IOException(java.io.IOException)

Example 50 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class TempCopyJob method getTemporaryFolder.

protected static AbstractFile getTemporaryFolder(FileSet files) {
    AbstractFile tempFolder;
    try {
        tempFolder = FileFactory.getTemporaryFile(files.getBaseFolder().getName(), true);
        tempFolder.mkdir();
    } catch (IOException e) {
        tempFolder = FileFactory.getTemporaryFolder();
    }
    return tempFolder;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) IOException(java.io.IOException)

Aggregations

AbstractFile (com.mucommander.commons.file.AbstractFile)150 IOException (java.io.IOException)49 FileURL (com.mucommander.commons.file.FileURL)19 FileSet (com.mucommander.commons.file.util.FileSet)11 FileTable (com.mucommander.ui.main.table.FileTable)11 DialogAction (com.mucommander.ui.dialog.DialogAction)10 File (java.io.File)9 List (java.util.List)8 MainFrame (com.mucommander.ui.main.MainFrame)6 InputStream (java.io.InputStream)6 Vector (java.util.Vector)6 AbstractArchiveEntryFile (com.mucommander.commons.file.archive.AbstractArchiveEntryFile)5 ProtocolFile (com.mucommander.commons.file.protocol.ProtocolFile)5 LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)5 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)5 FolderPanel (com.mucommander.ui.main.FolderPanel)5 FileTableModel (com.mucommander.ui.main.table.FileTableModel)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)4