use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class OvirtDataCenter method ls.
@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
String dcName = fileURL.getFilename();
log.debug("listing Data Center {}", dcName);
try (OvirtConnHandler connHandler = getConnHandler()) {
DataCenter dc = Utils.getDataCenter(connHandler, dcName);
return Utils.getStorageDomains(connHandler, dc.id()).stream().filter(sd -> sd.type() == StorageDomainType.DATA).map(this::toFile).filter(Objects::nonNull).toArray(AbstractFile[]::new);
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class CommandManager method loadAssociations.
/**
* Loads the custom associations XML File.
* <p>
* The command files will be loaded as a <i>backed-up file</i> (see {@link BackupInputStream}).
* Its format is described {@link AssociationsXmlConstants here}.
* </p>
* @throws IOException if an IO error occurs.
* @see #writeAssociations()
* @see #getAssociationFile()
* @see #setAssociationFile(String)
*/
public static void loadAssociations() throws IOException, CommandException {
AbstractFile file = getAssociationFile();
LOGGER.debug("Loading associations from file: " + file.getAbsolutePath());
// Tries to load the associations file.
// Associations are not considered to be modified by this.
InputStream in = null;
try {
AssociationReader.read(in = new BackupInputStream(file), new AssociationFactory());
} finally {
wereAssociationsModified = false;
// Makes sure the input stream is closed.
if (in != null) {
try {
in.close();
} catch (Exception e) {
// Ignores this.
}
}
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class GnomeTrash method moveToTrash.
/**
* Implementation of {@link com.mucommander.desktop.QueuedTrash} moveToTrash method.
* <p>
* Try to copy a collection of files to the GNOME's Trash.
* </p>
* @param queuedFiles Collection of files to the trash
* @return <code>true</code> if movement has been successful or <code>false</code> otherwise
*/
@Override
protected boolean moveToTrash(List<AbstractFile> queuedFiles) {
int nbFiles = queuedFiles.size();
String fileInfoContent;
String trashFileName;
// overall return value (if everything went OK or at least one file wasn't moved properly
boolean retVal = true;
for (int i = 0; i < nbFiles; i++) {
AbstractFile fileToDelete = queuedFiles.get(i);
// generate content of info file and new filename
try {
fileInfoContent = getFileInfoContent(fileToDelete);
trashFileName = getUniqueFilename(fileToDelete);
} catch (IOException ex) {
LOGGER.debug("Failed to create filename for new trash item: " + fileToDelete.getName(), ex);
// continue with other file (do not move file, because info file cannot be properly created
continue;
}
AbstractFile infoFile = null;
OutputStreamWriter infoWriter = null;
try {
// create info file
infoFile = TRASH_INFO_SUBFOLDER.getChild(trashFileName + ".trashinfo");
infoWriter = new OutputStreamWriter(infoFile.getOutputStream());
infoWriter.write(fileInfoContent);
} catch (IOException ex) {
retVal = false;
LOGGER.debug("Failed to create trash info file: " + trashFileName, ex);
// continue with other file (do not move file, because info file wasn't properly created)
continue;
} finally {
if (infoWriter != null) {
try {
infoWriter.close();
} catch (IOException e) {
// Not much else to do
}
}
}
try {
// rename original file
fileToDelete.renameTo(TRASH_FILES_SUBFOLDER.getChild(trashFileName));
} catch (IOException ex) {
try {
// remove info file
infoFile.delete();
} catch (IOException ex1) {
// simply ignore
}
retVal = false;
LOGGER.debug("Failed to move file to trash: " + trashFileName, ex);
}
}
return retVal;
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class RenameAction method performAction.
@Override
public void performAction() {
FileTable activeTable = mainFrame.getActiveTable();
AbstractFile selectedFile = activeTable.getSelectedFile(false);
// Trigger in-table editing only if a file other than parent folder '..' is selected
if (selectedFile != null) {
// Trigger in-table renaming
activeTable.editCurrentFilename();
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class RevealInDesktopAction method toggleEnabledState.
@Override
protected void toggleEnabledState() {
AbstractFile currentFolder = mainFrame.getActivePanel().getCurrentFolder();
switch(currentFolder.getURL().getScheme()) {
case LocalFile.SCHEMA:
setEnabled(!currentFolder.isArchive() && !currentFolder.hasAncestor(AbstractArchiveEntryFile.class));
break;
case SearchFile.SCHEMA:
AbstractFile selectedFile = mainFrame.getActiveTable().getSelectedFile();
setEnabled(selectedFile != null && selectedFile.getURL().getScheme().equals(LocalFile.SCHEMA));
break;
}
}
Aggregations