Skip to content

Commit

Permalink
Further reverting autoformat
Browse files Browse the repository at this point in the history
  • Loading branch information
a17t authored and ahadas committed Sep 24, 2021
1 parent 26d6fe2 commit 43c44f8
Showing 1 changed file with 44 additions and 36 deletions.
Expand Up @@ -87,7 +87,7 @@ public UnpackJob(ProgressDialog progressDialog, MainFrame mainFrame, FileSet fil
* @param destFolder destination folder where the files will be copied
* @param newName the new filename in the destination folder, if <code>null</code> the original filename will be used
* @param fileExistsAction default action to be performed when a file already exists in the destination, see {@link com.mucommander.ui.dialog.file.FileCollisionDialog} for allowed values
* @param selectedEntries entries to be unpacked
* @param selectedEntries entries to be unpacked
* @param baseArchiveDepth depth of the folder in which the top entries are located. 0 is the highest depth (archive's root folder)
*/
public UnpackJob(ProgressDialog progressDialog, MainFrame mainFrame, AbstractArchiveFile archiveFile, int baseArchiveDepth, AbstractFile destFolder, String newName, int fileExistsAction, List<ArchiveEntry> selectedEntries) {
Expand All @@ -108,23 +108,24 @@ protected void jobStarted() {
super.jobStarted();

// Create the base destination folder if it doesn't exist yet
if (!baseDestFolder.exists()) {
if(!baseDestFolder.exists()) {
// Loop for retry
do {
try {
baseDestFolder.mkdir();
} catch (IOException e) {
}
catch(IOException e) {
// Unable to create folder
int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_create_folder", baseDestFolder.getName()));
// Retry loops
if (ret == FileJobAction.RETRY)
if(ret==FileJobAction.RETRY)
continue;
// Cancel or close dialog interrupts the job
interrupt();
// Skip continues
}
break;
} while (true);
} while(true);
}
}

Expand All @@ -146,35 +147,36 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
AbstractFile destFolder = baseDestFolder;

// If the file is a directory, process its children recursively
if (file.isDirectory()) {
if(file.isDirectory()) {
do { // Loop for retries
try {
// List files inside archive file (can throw an IOException)
AbstractFile[] archiveFiles = getCurrentFile().ls();

// Recurse on zip's contents
for (int j = 0; j < archiveFiles.length && getState() != FileJobState.INTERRUPTED; j++) {
for(int j=0; j<archiveFiles.length && getState() != FileJobState.INTERRUPTED; j++) {
// Notify job that we're starting to process this file (needed for recursive calls to processFile)
nextFile(archiveFiles[j]);
// Recurse
processFile(archiveFiles[j], destFolder);
}
// Return true when complete
return true;
} catch (IOException e) {
}
catch(IOException e) {
// File could not be uncompressed properly
int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_read_file", getCurrentFilename()));
// Retry loops
if (ret == FileJobAction.RETRY)
if(ret==FileJobAction.RETRY)
continue;
// cancel, skip or close dialog will simply return false
return false;
}
} while (true);
} while(true);
}

// Abort if the file is neither an archive file nor a directory
if (!file.isArchive())
if(!file.isArchive())
return false;

// 'Cast' the file as an archive file
Expand All @@ -189,22 +191,24 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
String entryPath = entry.getPath();

boolean processEntry = false;
if (selectedEntries == null) { // Entries are processed
if(selectedEntries ==null) { // Entries are processed
processEntry = true;
} else { // We need to determine if the entry should be processed or not
}
else { // We need to determine if the entry should be processed or not
// Process this entry if the selectedEntries set contains this entry, or a parent of this entry
int nbSelectedEntries = selectedEntries.size();
for (int i = 0; i < nbSelectedEntries; i++) {
for(int i=0; i<nbSelectedEntries; i++) {
ArchiveEntry selectedEntry = selectedEntries.get(i);
// Note: paths of directory entries must end with '/', so this compares whether
// selectedEntry is a parent of the current entry.
if (selectedEntry.isDirectory()) {
if (entryPath.startsWith(selectedEntry.getPath())) {
if(selectedEntry.isDirectory()) {
if(entryPath.startsWith(selectedEntry.getPath())) {
processEntry = true;
break;
// Note: we can't remove selectedEntryPath from the set, we still need it
}
} else if (entryPath.equals(selectedEntry.getPath())) {
}
else if(entryPath.equals(selectedEntry.getPath())) {
// If the (regular file) entry is in the set, remove it as we no longer need it (will speed up
// subsequent searches)
processEntry = true;
Expand All @@ -214,7 +218,7 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
}
}

if (!processEntry)
if(!processEntry)
continue;

DefaultMutableTreeNode entryNode = archiveFile.getArchiveEntryNode(entryPath);
Expand All @@ -238,11 +242,12 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
?entry.getPath()
:PathUtils.removeLeadingFragments(entry.getPath(), "/", baseArchiveDepth);

if (newName != null)
relDestPath = newName + (PathUtils.getDepth(relDestPath, "/") <= 1 ? "" : "/" + PathUtils.removeLeadingFragments(relDestPath, "/", 1));
if(newName!=null)
relDestPath = newName+(PathUtils.getDepth(relDestPath, "/")<=1?"":"/"+PathUtils.removeLeadingFragments(relDestPath, "/", 1));

if (!"/".equals(destSeparator))
if(!"/".equals(destSeparator))
relDestPath = relDestPath.replace("/", destSeparator);

// Create destination AbstractFile instance
AbstractFile destFile = destFolder.getChild(relDestPath);

Expand All @@ -261,48 +266,51 @@ protected boolean processFile(AbstractFile file, Object recurseParams) {
// It is noteworthy that the iterator returns entries in no particular order (consider it random).
// For that reason, we cannot assume that the parent directory of an entry will be processed
// before the entry itself.

// If the entry is a directory ...
if (entryFile.isDirectory()) {
if(entryFile.isDirectory()) {
// Create the directory in the destination, if it doesn't already exist
if (!(destFile.exists() && destFile.isDirectory())) {
if(!(destFile.exists() && destFile.isDirectory())) {
// Loop for retry
do {
try {
// Use mkdirs() instead of mkdir() to create any parent folder that doesn't exist yet
destFile.mkdirs();
} catch (IOException e) {
}
catch(IOException e) {
// Unable to create folder
int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_create_folder", entryFile.getName()));
// Retry loops
if (ret == FileJobAction.RETRY)
if(ret==FileJobAction.RETRY)
continue;
// Cancel or close dialog return false
return false;
// Skip continues
}
break;
} while (true);
} while(true);
}
}
// The entry is a regular file, copy it
else {
else {
// Create the file's parent directory(s) if it doesn't already exist
AbstractFile destParentFile = destFile.getParent();
if (!destParentFile.exists()) {
if(!destParentFile.exists()) {
// Use mkdirs() instead of mkdir() to create any parent folder that doesn't exist yet
destParentFile.mkdirs();
}

// The entry is wrapped in a ProxyFile to override #getInputStream() and delegate it to
// ArchiveFile#getEntryInputStream in order to take advantage of the ArchiveEntryIterator, which for
// some archive file implementations (such as TAR) can speed things by an order of magnitude.
if (!tryCopyFile(new ProxiedEntryFile(entryFile, entry, archiveFile, iterator), destFile, append, errorDialogTitle))
return false;
if(!tryCopyFile(new ProxiedEntryFile(entryFile, entry, archiveFile, iterator), destFile, append, errorDialogTitle))
return false;
}
}

return true;
} catch (IOException e) {
}
catch(IOException e) {
showErrorDialog(errorDialogTitle, Translator.get("cannot_read_file", archiveFile.getName()));
}

Expand Down Expand Up @@ -346,21 +354,21 @@ protected void 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(archiveFile!=null && archiveFile.isArchive() && archiveFile.isWritable())
optimizeArchive((AbstractRWArchiveFile)archiveFile);

// Unselect all files in the active table upon successful completion
if (selectedEntries != null) {
if(selectedEntries!=null) {
ActionManager.performAction(UnmarkAllAction.Descriptor.ACTION_ID, getMainFrame());
}
}

@Override
public String getStatusString() {
if (isCheckingIntegrity())
if(isCheckingIntegrity())
return super.getStatusString();

if (isOptimizingArchive)
if(isOptimizingArchive)
return Translator.get("optimizing_archive", archiveToOptimize.getName());

return Translator.get("unpack_dialog.unpacking_file", getCurrentFilename());
Expand Down

0 comments on commit 43c44f8

Please sign in to comment.