use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class SelfUpdateJob method loadClassRecurse.
/**
* Loads all the class files contained in the given JAR file recursively.
*
* @param file the JAR file from which to load the classes
* @throws Exception if an error occurred while loading the classes
*/
private void loadClassRecurse(AbstractFile file) throws Exception {
if (file.isBrowsable()) {
AbstractFile[] children = file.ls(directoryOrClassFileFilter);
for (AbstractFile child : children) loadClassRecurse(child);
} else {
// .class file
String classname = file.getAbsolutePath(false);
// Strip off the JAR file's path and ".class" extension
classname = classname.substring(destJar.getAbsolutePath(true).length(), classname.length() - 6);
// Replace separator characters by '.'
classname = classname.replace(destJar.getSeparator(), ".");
try {
classLoader.loadClass(classname);
LOGGER.trace("Loaded class " + classname);
} catch (java.lang.NoClassDefFoundError e) {
LOGGER.debug("Caught an error while loading class " + classname, e);
}
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class SelfUpdateJob method jobCompleted.
@Override
protected void jobCompleted() {
try {
AbstractFile parent;
// Mac OS X
if (OsFamily.MAC_OS.isCurrent()) {
parent = destJar.getParent();
// Look for an .app container that encloses the JAR file
if (parent.getName().equals("Java") && (parent = parent.getParent()) != null && parent.getName().equals("Resources") && (parent = parent.getParent()) != null && parent.getName().equals("Contents") && (parent = parent.getParent()) != null && "app".equals(parent.getExtension())) {
String appPath = parent.getAbsolutePath();
LOGGER.debug("Opening " + appPath);
// Open -W wait for the current muCommander .app to terminate, before re-opening it
ProcessRunner.execute(new String[] { "/bin/sh", "-c", "open -W " + appPath + " && open " + appPath });
return;
}
} else {
parent = destJar.getParent();
EqualsFilenameFilter launcherFilter;
// Windows
if (OsFamily.WINDOWS.isCurrent()) {
// Look for a muCommander.exe launcher located in the same folder as the JAR file
launcherFilter = new EqualsFilenameFilter("muCommander.exe", false);
} else // Other platforms, possibly Unix/Linux
{
// Look for a mucommander.sh located in the same folder as the JAR file
launcherFilter = new EqualsFilenameFilter("mucommander.sh", false);
}
AbstractFile[] launcherFile = parent.ls(launcherFilter);
// If a launcher file was found, execute it
if (launcherFile != null && launcherFile.length == 1) {
DesktopManager.open(launcherFile[0]);
return;
}
}
// No platform-specific launcher found, launch the Jar directly
ProcessRunner.execute(new String[] { "java", "-jar", destJar.getAbsolutePath() });
} catch (IOException e) {
LOGGER.debug("Caught exception", e);
// Todo: we might want to do something about this
} finally {
Application.initiateShutdown();
}
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class SplitFileJob method jobCompleted.
@Override
protected void jobCompleted() {
// create checksum file
if (isIntegrityCheckEnabled()) {
if (origFileStream != null && (origFileStream instanceof ChecksumInputStream)) {
String crcFileName = sourceFile.getName() + ".sfv";
try {
String sourceChecksum;
if (recalculateCRC) {
origFileStream = sourceFile.getInputStream();
sourceChecksum = AbstractFile.calculateChecksum(origFileStream, MessageDigest.getInstance("CRC32"));
origFileStream.close();
} else {
sourceChecksum = ((ChecksumInputStream) origFileStream).getChecksumString();
}
AbstractFile crcFile = baseDestFolder.getDirectChild(crcFileName);
OutputStream crcStream = crcFile.getOutputStream();
String line = sourceFile.getName() + " " + sourceChecksum;
crcStream.write(line.getBytes("utf-8"));
crcStream.close();
} catch (Exception e) {
LOGGER.debug("Caught exception", e);
showErrorDialog(errorDialogTitle, Translator.get("error_while_transferring", crcFileName), Arrays.asList(FileJobAction.CANCEL));
}
}
}
super.jobCompleted();
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class SplitFileJob method processFile.
@Override
protected boolean processFile(AbstractFile file, Object recurseParams) {
if (getState() == FileJobState.INTERRUPTED)
return false;
// Create destination AbstractFile instance
AbstractFile destFile = createDestinationFile(file, baseDestFolder, file.getName());
if (destFile == null)
return false;
destFile = checkForCollision(sourceFile, baseDestFolder, destFile, false);
if (destFile == null)
return false;
OutputStream out = null;
try {
out = destFile.getOutputStream();
try {
long written = StreamUtils.copyStream(origFileStream, out, BufferPool.getDefaultBufferSize(), partSize);
sizeLeft -= written;
} catch (FileTransferException e) {
if (e.getReason() == FileTransferError.WRITING_DESTINATION) {
// out of disk space - ask a user for a new disk
// recalculate CRC (DigestInputStream doesn't support mark() and reset())
recalculateCRC = true;
out.close();
out = null;
sizeLeft -= e.getBytesWritten();
showErrorDialog(ActionProperties.getActionLabel(SplitFileAction.Descriptor.ACTION_ID), Translator.get("split_file_dialog.insert_new_media"), Arrays.asList(FileJobAction.OK, FileJobAction.CANCEL));
if (getState() == FileJobState.INTERRUPTED) {
return false;
}
// create new output file if necessary
if (sizeLeft > 0 && getCurrentFileIndex() == getNbFiles() - 1) {
setNbFiles(getNbFiles() + 1);
addDummyFile(getNbFiles(), sizeLeft);
}
} else {
throw e;
}
}
// Preserve source file's date
if (destFile.isFileOperationSupported(FileOperation.CHANGE_DATE)) {
try {
destFile.changeDate(sourceFile.getDate());
} catch (IOException e) {
LOGGER.debug("failed to change date of " + destFile, e);
// Fail silently
}
}
// file and use default permissions for the rest of them.
if (destFile.isFileOperationSupported(FileOperation.CHANGE_PERMISSION)) {
try {
// use #importPermissions(AbstractFile, int) to avoid isDirectory test
destFile.importPermissions(sourceFile, FilePermissions.DEFAULT_FILE_PERMISSIONS);
} catch (IOException e) {
LOGGER.debug("failed to import " + sourceFile + " permissions into " + destFile, e);
// Fail silently
}
}
} catch (IOException e) {
LOGGER.debug("Caught exception", e);
showErrorDialog(errorDialogTitle, Translator.get("error_while_transferring", destFile.getName()), Arrays.asList(FileJobAction.CANCEL));
return false;
} finally {
try {
if (out != null)
out.close();
} catch (IOException e2) {
}
}
return true;
}
use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.
the class SearchBuilder method createFilenamePredicate.
private Predicate<AbstractFile> createFilenamePredicate() {
if (!matchRegex) {
String regex = SearchUtils.wildcardToRegex(searchStr);
if (!searchStr.equals(regex)) {
searchStr = regex;
matchRegex = true;
}
}
if (matchRegex) {
int flags = matchCaseSensitive ? 0 : Pattern.CASE_INSENSITIVE;
Pattern pattern = Pattern.compile(searchStr, flags);
return file -> pattern.matcher(file.getName()).matches();
}
return matchCaseSensitive ? file -> file.getName().equals(searchStr) : file -> file.getName().equalsIgnoreCase(searchStr);
}
Aggregations