public Object getElementAt(int index) { return files.elementAt(index); } });
@Override protected PathFieldContent computeInitialPath(FileSet files) { AbstractFile file = files.elementAt(0); return selectDestinationFilename(file, file.getName(), 0); } }
public boolean match(FileSet files) { int nbFiles = files.size(); for(int i=0; i<nbFiles; i++) if(!match(files.elementAt(i))) return false; return true; }
public boolean reject(FileSet files) { int nbFiles = files.size(); for(int i=0; i<nbFiles; i++) if(!reject(files.elementAt(i))) return false; return true; } }
public boolean accept(FileSet files) { int nbFiles = files.size(); for(int i=0; i<nbFiles; i++) if(!accept(files.elementAt(i))) return false; return true; }
/** * Returns a de-facto standard filename for the specified checksum algorithm, e.g. <code>MD5SUMS</code> for * <code>md5</code>. * * @param algorithm a checksum algorithm * @return a standard filename for the specified checksum algorithm */ private String getChecksumFilename(String algorithm) { // Adler32 -> ADLER32SUMS // CRC32 -> <filename>.sfv (needs special treatment) // MD2 -> MD2SUMS // MD4 -> MD4SUMS // MD5 -> MD5SUMS // SHA -> SHA1SUMS (needs special treatment) // SHA-256 -> SHA256SUMS // SHA-384 -> SHA384SUMS // SHA-512 -> SHA512SUMS algorithm = algorithm.toUpperCase(); if(algorithm.equals("SHA")) return "SHA1SUMS"; if(algorithm.equals("CRC32")) return (files.size()==1?files.elementAt(0):files.getBaseFolder()).getName()+".sfv"; return algorithm.replace("-", "")+"SUMS"; }
public void filter(FileSet files) { for(int i=0; i<files.size();) { if(reject(files.elementAt(i))) files.removeElementAt(i); else i++; } }
/** * Updates the number of selected files and their total size. */ private void updateInfoLabel() { int nbFiles = fileCheckboxes.length; int nbSelected = 0; int bytesTotal = 0; long fileSize; for(int i=0; i<nbFiles; i++) { if(fileCheckboxes[i].isSelected()) { fileSize = flattenedFiles.elementAt(i).getSize(); if(fileSize>0) bytesTotal += fileSize; nbSelected++; } } String text = Translator.get("nb_files", ""+nbSelected) +(nbSelected==0?"":" ("+ SizeFormat.format(bytesTotal, SizeFormat.DIGITS_MEDIUM| SizeFormat.UNIT_LONG| SizeFormat.ROUND_TO_KB)+")"); infoLabel.setText(text); infoLabel.repaint(100); }
/** * Returns a FileSet of *files* (as opposed to folders) that have been found either in the given * FileSet or in one of the subfolders. * * @param originalFiles files as selected by the user which may contain folders */ private FileSet getFlattenedFiles(FileSet originalFiles) throws IOException { int nbFiles = originalFiles.size(); FileSet flattenedFiles = new FileSet(originalFiles.getBaseFolder()); for(int i=0; i<nbFiles; i++) recurseOnFolder(originalFiles.elementAt(i), flattenedFiles); return flattenedFiles; }
for(int i=0; i<nbFiles; i++) if(fileCheckboxes[i].isSelected()) filesToSend.add(flattenedFiles.elementAt(i));
@Override protected PathFieldContent computeInitialPath(FileSet files) { AbstractFile file = files.elementAt(0); // AbstractFile activeFolder = mainFrame.getActiveTable().getCurrentFolder(); AbstractFile unactiveFolder = mainFrame.getInactivePanel().getCurrentFolder(); // Fill text field with current folder's absolute path and file name return new PathFieldContent(unactiveFolder.getAbsolutePath(true)+file.getName()); }
this.formats = Archiver.getFormats(nbFiles>1 || (nbFiles>0 && files.elementAt(0).isDirectory())); int nbFormats = formats.length;
AbstractFile file = files.elementAt(0); AbstractFile destFile;
@Override protected PathFieldContent computeInitialPath(FileSet files) { String initialPath = mainFrame.getInactivePanel().getCurrentFolder().getAbsolutePath(true); AbstractFile file; String fileName; // Computes the archive's default name: // - if it only contains one file, uses that file's name. // - if it contains more than one file, uses the FileSet's parent folder's name. if(files.size() == 1) { file = files.elementAt(0); fileName = file.isDirectory() && !DesktopManager.isApplication(file) ?file.getName() :file.getNameWithoutExtension(); } else { file = files.getBaseFolder(); fileName = file.isRoot()?"":DesktopManager.isApplication(file)?file.getNameWithoutExtension():file.getName(); } return new PathFieldContent(initialPath + fileName + "." + Archiver.getFormatExtension(lastFormat), initialPath.length(), initialPath.length() + fileName.length()); }
@Override protected void jobCompleted() { super.jobCompleted(); // If the destination files are located inside an archive, optimize the archive file AbstractArchiveFile archiveFile = baseDestFolder.getParentArchive(); if(archiveFile!=null && archiveFile.isArchive() && archiveFile.isWritable()) optimizeArchive((AbstractRWArchiveFile)archiveFile); // If this job corresponds to a 'local copy' of a single file and in the same directory, // select the copied file in the active table after this job has finished (and hasn't been cancelled) if(files.size()==1 && newName!=null && baseDestFolder.equalsCanonical(files.elementAt(0).getParent())) { // Resolve new file instance now that it exists: some remote files do not immediately update file attributes // after creation, we need to get an instance that reflects the newly created file attributes selectFileWhenFinished(FileFactory.getFile(baseDestFolder.getAbsolutePath(true)+newName)); } }
/** * Creates a new FileJob without starting it, and with no associated ProgressDialog. * * @param mainFrame mainFrame this job has been triggered by * @param files files which are going to be processed */ public FileJob(MainFrame mainFrame, FileSet files) { this.mainFrame = mainFrame; this.files = files; this.nbFiles = files.size(); this.baseSourceFolder = files.getBaseFolder(); // Create CachedFile instances around the source files in order to cache the return value of frequently accessed // methods. This eliminates some I/O, at the (small) cost of a bit more CPU and memory. Recursion is enabled // so that children and parents of the files are also cached. // Note: When cached methods are called, they no longer reflect changes in the underlying files. In particular, // changes of size or date could potentially not be reflected when files are being processed but this should // not really present a risk. AbstractFile tempFile; for(int i=0; i<nbFiles; i++) { tempFile = files.elementAt(i); files.setElementAt((tempFile instanceof CachedFile)?tempFile:new CachedFile(tempFile, true), i); } if (this.baseSourceFolder!=null) this.baseSourceFolder = (getBaseSourceFolder() instanceof CachedFile)?getBaseSourceFolder():new CachedFile(getBaseSourceFolder(), true); this.jobProgress = new JobProgress(this); }
List<ArchiveEntry> selectedEntries = new Vector<ArchiveEntry>(); for(int i=0; i<nbFiles; i++) { selectedEntries.add((ArchiveEntry)files.elementAt(i).getAncestor(AbstractArchiveEntryFile.class).getUnderlyingFileObject());
AbstractFile currentFile = files.elementAt(currentFileIndex);
@Override protected void jobCompleted() { super.jobCompleted(); // If the source files are located inside an archive, optimize the archive file AbstractArchiveFile sourceArchiveFile = getBaseSourceFolder()==null?null:getBaseSourceFolder().getParentArchive(); if(sourceArchiveFile!=null && sourceArchiveFile.isArchive() && sourceArchiveFile.isWritable()) optimizeArchive((AbstractRWArchiveFile)sourceArchiveFile); // If the destination files are located inside an archive, optimize the archive file, only if the destination // archive is different from the source one AbstractArchiveFile destArchiveFile = baseDestFolder.getParentArchive(); if(destArchiveFile!=null && destArchiveFile.isArchive() && destArchiveFile.isWritable() && !(sourceArchiveFile!=null && destArchiveFile.equalsCanonical(sourceArchiveFile))) optimizeArchive((AbstractRWArchiveFile)destArchiveFile); // If this job corresponds to a file renaming in the same directory, select the renamed file // in the active table after this job has finished (and hasn't been cancelled) if(files.size()==1 && newName!=null && baseDestFolder.equalsCanonical(files.elementAt(0).getParent())) { // Resolve new file instance now that it exists: some remote files do not immediately update file attributes // after creation, we need to get an instance that reflects the newly created file attributes selectFileWhenFinished(FileFactory.getFile(baseDestFolder.getAbsolutePath(true)+newName)); } }