Search in sources :

Example 91 with AbstractFile

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);
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 92 with AbstractFile

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();
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) IOException(java.io.IOException)

Example 93 with AbstractFile

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();
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) ChecksumInputStream(com.mucommander.commons.io.ChecksumInputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) FileTransferException(com.mucommander.commons.io.FileTransferException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 94 with AbstractFile

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;
}
Also used : FileTransferException(com.mucommander.commons.io.FileTransferException) AbstractFile(com.mucommander.commons.file.AbstractFile) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 95 with AbstractFile

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);
}
Also used : Logger(org.slf4j.Logger) GrepOptions(org.unix4j.unix.grep.GrepOptions) Predicate(java.util.function.Predicate) GrepOptionSet_Fcilnvx(org.unix4j.unix.grep.GrepOptionSet_Fcilnvx) SearchJob(com.mucommander.job.impl.SearchJob) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Pair(com.mucommander.commons.util.Pair) Grep(org.unix4j.unix.Grep) List(java.util.List) FileSet(com.mucommander.commons.file.util.FileSet) Unix4j(org.unix4j.Unix4j) SearchListener(com.mucommander.commons.file.protocol.search.SearchListener) Pattern(java.util.regex.Pattern) AbstractFile(com.mucommander.commons.file.AbstractFile) MainFrame(com.mucommander.ui.main.MainFrame) Pattern(java.util.regex.Pattern)

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