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;
}
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();
}
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);
}
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;
}
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;
}
Aggregations