diff --git a/source/net/filebot/ui/filter/AttributeTool.java b/source/net/filebot/ui/filter/AttributeTool.java index 9eed09c4..6ee865ec 100644 --- a/source/net/filebot/ui/filter/AttributeTool.java +++ b/source/net/filebot/ui/filter/AttributeTool.java @@ -56,6 +56,7 @@ class AttributeTool extends Tool { } List files = filter(listFiles(root), VIDEO_FILES, SUBTITLE_FILES); + files.sort(HUMAN_ORDER); for (File file : files) { Object metaObject = xattr.getMetaInfo(file); diff --git a/source/net/filebot/ui/filter/ExtractTool.java b/source/net/filebot/ui/filter/ExtractTool.java index 39d8932a..04041dbe 100644 --- a/source/net/filebot/ui/filter/ExtractTool.java +++ b/source/net/filebot/ui/filter/ExtractTool.java @@ -1,6 +1,5 @@ package net.filebot.ui.filter; -import static java.util.Collections.*; import static net.filebot.Logging.*; import static net.filebot.UserFiles.*; import static net.filebot.util.ExceptionUtilities.*; @@ -78,20 +77,21 @@ class ExtractTool extends Tool { @Override protected TableModel createModelInBackground(File root) throws InterruptedException { - List files = root != null ? listFiles(root) : emptyList(); + if (root == null) { + return new ArchiveEntryModel(); + } + + // ignore non-archives files and trailing multi-volume parts + List files = filter(listFiles(root), Archive.VOLUME_ONE_FILTER); + files.sort(HUMAN_ORDER); List entries = new ArrayList(); + try { for (File file : files) { - // ignore non-archives files and trailing multi-volume parts - if (Archive.VOLUME_ONE_FILTER.accept(file)) { - Archive archive = Archive.open(file); - try { - for (FileInfo it : archive.listFiles()) { - entries.add(new ArchiveEntry(file, it)); - } - } finally { - archive.close(); + try (Archive archive = Archive.open(file)) { + for (FileInfo it : archive.listFiles()) { + entries.add(new ArchiveEntry(file, it)); } } diff --git a/source/net/filebot/ui/filter/FileTreeTransferablePolicy.java b/source/net/filebot/ui/filter/FileTreeTransferablePolicy.java index aae92810..aa82f5f7 100644 --- a/source/net/filebot/ui/filter/FileTreeTransferablePolicy.java +++ b/source/net/filebot/ui/filter/FileTreeTransferablePolicy.java @@ -86,10 +86,8 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy children = new LinkedList(); - for (File f : getChildren(file)) { - if (f.isHidden()) - continue; + for (File f : getChildren(file, NOT_HIDDEN, HUMAN_ORDER)) { if (f.isDirectory()) { children.addFirst(getTreeNode(f)); } else { diff --git a/source/net/filebot/ui/filter/MediaInfoTool.java b/source/net/filebot/ui/filter/MediaInfoTool.java index f5d2c67a..9e8ae26f 100644 --- a/source/net/filebot/ui/filter/MediaInfoTool.java +++ b/source/net/filebot/ui/filter/MediaInfoTool.java @@ -59,6 +59,8 @@ class MediaInfoTool extends Tool { } List files = filter(listFiles(root), VIDEO_FILES, AUDIO_FILES); + files.sort(HUMAN_ORDER); + Map data = new TreeMap(); try (MediaInfo mi = new MediaInfo()) { diff --git a/source/net/filebot/ui/filter/SplitTool.java b/source/net/filebot/ui/filter/SplitTool.java index 9ce31c94..a10e2652 100644 --- a/source/net/filebot/ui/filter/SplitTool.java +++ b/source/net/filebot/ui/filter/SplitTool.java @@ -1,5 +1,6 @@ package net.filebot.ui.filter; +import static java.util.Collections.*; import static net.filebot.util.FileUtilities.*; import java.awt.Color; @@ -68,10 +69,15 @@ class SplitTool extends Tool { @Override protected TreeModel createModelInBackground(File root) throws InterruptedException { + if (root == null) { + return new DefaultTreeModel(new FolderNode("Volumes", emptyList())); + } + int nextPart = 1; long splitSize = getSplitSize(); - List files = (root != null) ? listFiles(root) : new ArrayList(); + List files = listFiles(root); + files.sort(HUMAN_ORDER); List rootGroup = new ArrayList(); List currentPart = new ArrayList(); diff --git a/source/net/filebot/ui/list/FileListTransferablePolicy.java b/source/net/filebot/ui/list/FileListTransferablePolicy.java index 1174789a..b241e1c1 100644 --- a/source/net/filebot/ui/list/FileListTransferablePolicy.java +++ b/source/net/filebot/ui/list/FileListTransferablePolicy.java @@ -82,9 +82,12 @@ class FileListTransferablePolicy extends FileTransferablePolicy { title.accept(getFolderName(files.get(0))); } + List list = listFiles(files); + list.sort(HUMAN_ORDER); + // load all files from the given folders recursively up do a depth of 32 format.accept(ListPanel.DEFAULT_FILE_FORMAT); - model.accept(listFiles(files)); + model.accept(list); } } diff --git a/source/net/filebot/ui/rename/Preset.java b/source/net/filebot/ui/rename/Preset.java index 9b67e062..fde9834f 100644 --- a/source/net/filebot/ui/rename/Preset.java +++ b/source/net/filebot/ui/rename/Preset.java @@ -1,6 +1,7 @@ package net.filebot.ui.rename; import static java.util.Collections.*; +import static net.filebot.util.FileUtilities.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.event.ActionEvent; @@ -15,7 +16,6 @@ import net.filebot.format.ExpressionFileFilter; import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFormat; import net.filebot.mac.MacAppUtilities; -import net.filebot.util.FileUtilities; import net.filebot.web.Datasource; import net.filebot.web.EpisodeListProvider; import net.filebot.web.MovieIdentificationService; @@ -84,10 +84,12 @@ public class Preset { } } - List files = FileUtilities.listFiles(getInputFolder()); + List files = listFiles(getInputFolder()); if (filter != null) { - files = FileUtilities.filter(files, filter); + files = filter(files, filter); } + files.sort(HUMAN_ORDER); + return files; } diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 476ac436..e45a89fe 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -677,19 +677,20 @@ public class RenamePanel extends JComponent { @Override public List getFiles(ActionEvent evt) { - List input = preset.selectInputFiles(evt); + List selection = preset.selectInputFiles(evt); - if (input != null) { + if (selection != null) { renameModel.clear(); - renameModel.files().addAll(input); + renameModel.files().addAll(selection); } else { - input = new ArrayList(super.getFiles(evt)); + selection = new ArrayList(super.getFiles(evt)); } - if (input.isEmpty()) { + if (selection.isEmpty()) { throw new IllegalStateException("No files selected."); } - return input; + + return selection; } @Override diff --git a/source/net/filebot/ui/sfv/ChecksumTableTransferablePolicy.java b/source/net/filebot/ui/sfv/ChecksumTableTransferablePolicy.java index 9a5dfb58..3cd90470 100644 --- a/source/net/filebot/ui/sfv/ChecksumTableTransferablePolicy.java +++ b/source/net/filebot/ui/sfv/ChecksumTableTransferablePolicy.java @@ -96,7 +96,7 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy input) { + protected DropAction getDropAction(List selection) { // accept video files and folders return filter(input, VIDEO_FILES, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel; } @Override - protected boolean handleDrop(List input) { + protected boolean handleDrop(List selection) { if (getQueryLanguage() == null) { log.info("Please select your preferred subtitle language."); return false; @@ -176,14 +177,11 @@ abstract class SubtitleDropTarget extends JButton { return false; } - // perform a drop action depending on the given files - final Collection videoFiles = new TreeSet(); + List files = filter(listFiles(selection), VIDEO_FILES); + files.sort(HUMAN_ORDER); - // video files only - videoFiles.addAll(filter(listFiles(input), VIDEO_FILES)); - - if (videoFiles.size() > 0) { - handleDownload(videoFiles); + if (files.size() > 0) { + handleDownload(files); return true; } @@ -234,13 +232,13 @@ abstract class SubtitleDropTarget extends JButton { public static abstract class Upload extends SubtitleDropTarget { @Override - protected DropAction getDropAction(List input) { + protected DropAction getDropAction(List selection) { // accept video files and folders - return filter(input, SUBTITLE_FILES).size() > 0 || filter(input, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel; + return filter(selection, SUBTITLE_FILES).size() > 0 || filter(selection, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel; } @Override - protected boolean handleDrop(List input) { + protected boolean handleDrop(List selection) { if (getSubtitleService().isAnonymous()) { log.info(String.format("%s: You must be logged in to upload subtitles.", getSubtitleService().getName())); return false; @@ -250,19 +248,20 @@ abstract class SubtitleDropTarget extends JButton { // make sure we have access to the parent folder structure, not just the dropped file if (isMacSandbox()) { - MacAppUtilities.askUnlockFolders(getWindow(this), input); + MacAppUtilities.askUnlockFolders(getWindow(this), selection); } // perform a drop action depending on the given files - final Collection files = new TreeSet(); + List files = listFiles(selection); - // video files only - files.addAll(listFiles(input)); + List videos = filter(files, VIDEO_FILES); + videos.sort(HUMAN_ORDER); - final List videos = filter(files, VIDEO_FILES); - final List subtitles = filter(files, SUBTITLE_FILES); + List subtitles = filter(files, SUBTITLE_FILES); + subtitles.sort(HUMAN_ORDER); + + Map uploadPlan = new LinkedHashMap(); - final Map uploadPlan = new LinkedHashMap(); for (File subtitle : subtitles) { File video = getVideoForSubtitle(subtitle, filter(videos, new ParentFilter(subtitle.getParentFile()))); uploadPlan.put(subtitle, video); @@ -274,6 +273,7 @@ abstract class SubtitleDropTarget extends JButton { handleUpload(uploadPlan); return true; } + return false; } diff --git a/source/net/filebot/util/FileUtilities.java b/source/net/filebot/util/FileUtilities.java index d124fffa..3ba8c424 100644 --- a/source/net/filebot/util/FileUtilities.java +++ b/source/net/filebot/util/FileUtilities.java @@ -443,8 +443,10 @@ public final class FileUtilities { // children array may be null if folder permissions do not allow listing of files if (files == null) { - files = new File[0]; - } else if (order != null) { + return emptyList(); + } + + if (order != null) { sort(files, order); }