diff --git a/source/net/filebot/ui/rename/HistoryDialog.java b/source/net/filebot/ui/rename/HistoryDialog.java index 5f06af8e..51316670 100644 --- a/source/net/filebot/ui/rename/HistoryDialog.java +++ b/source/net/filebot/ui/rename/HistoryDialog.java @@ -4,6 +4,7 @@ import static java.awt.Font.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.regex.Pattern.*; +import static java.util.stream.Collectors.*; import static javax.swing.JOptionPane.*; import static net.filebot.Logging.*; import static net.filebot.Settings.*; @@ -37,7 +38,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.AbstractAction; @@ -446,15 +446,18 @@ class HistoryDialog extends JDialog { } private enum Option { + Revert, ChangeDirectory, Cancel; @Override public String toString() { switch (this) { + case Revert: + return "Revert"; case ChangeDirectory: return "Change Directory"; default: - return name(); + return "Cancel"; } } } @@ -529,7 +532,7 @@ class HistoryDialog extends JDialog { private void revert(File directory, List elements) { Map renamePlan = getRenameMap(directory); if (isMacSandbox()) { - if (!MacAppUtilities.askUnlockFolders(parent(), Stream.of(renamePlan.keySet(), renamePlan.values()).flatMap(c -> c.stream()).collect(Collectors.toList()))) { + if (!MacAppUtilities.askUnlockFolders(parent(), Stream.of(renamePlan.keySet(), renamePlan.values()).flatMap(c -> c.stream()).collect(toList()))) { return; } } diff --git a/source/net/filebot/ui/rename/RenameAction.java b/source/net/filebot/ui/rename/RenameAction.java index bf71ec64..133089de 100644 --- a/source/net/filebot/ui/rename/RenameAction.java +++ b/source/net/filebot/ui/rename/RenameAction.java @@ -2,6 +2,7 @@ package net.filebot.ui.rename; import static java.util.Arrays.*; import static java.util.Collections.*; +import static java.util.stream.Collectors.*; import static javax.swing.JOptionPane.*; import static net.filebot.Logging.*; import static net.filebot.Settings.*; @@ -32,7 +33,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.logging.Level; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.swing.AbstractAction; @@ -202,14 +202,14 @@ class RenameAction extends AbstractAction { private Map checkRenamePlan(List> renamePlan, Window parent) throws IOException { // ask for user permissions to output paths if (isMacSandbox()) { - if (!MacAppUtilities.askUnlockFolders(parent, renamePlan.stream().flatMap(e -> Stream.of(e.getKey(), resolve(e.getKey(), e.getValue()))).map(f -> new File(f.getAbsolutePath())).collect(Collectors.toList()))) { + if (!MacAppUtilities.askUnlockFolders(parent, renamePlan.stream().flatMap(e -> Stream.of(e.getKey(), resolve(e.getKey(), e.getValue()))).map(f -> new File(f.getAbsolutePath())).collect(toList()))) { return emptyMap(); } } // build rename map and perform some sanity checks Map renameMap = new HashMap(); - Set destinationSet = new HashSet(); + Set destinationFiles = new HashSet(); List issues = new ArrayList(); for (Entry mapping : renamePlan) { @@ -220,7 +220,7 @@ class RenameAction extends AbstractAction { if (renameMap.containsKey(source)) throw new IllegalArgumentException("Duplicate source file: " + source.getPath()); - if (destinationSet.contains(destination)) + if (destinationFiles.contains(destination)) throw new IllegalArgumentException("Conflict detected: " + mapping.getValue().getPath()); if (destination.exists() && !resolve(mapping.getKey(), mapping.getValue()).equals(mapping.getKey())) @@ -231,7 +231,7 @@ class RenameAction extends AbstractAction { // use original mapping values renameMap.put(mapping.getKey(), mapping.getValue()); - destinationSet.add(destination); + destinationFiles.add(destination); } catch (Exception e) { issues.add(e.getMessage()); } diff --git a/source/net/filebot/ui/rename/RenameListCellRenderer.java b/source/net/filebot/ui/rename/RenameListCellRenderer.java index d0068f25..292f5864 100644 --- a/source/net/filebot/ui/rename/RenameListCellRenderer.java +++ b/source/net/filebot/ui/rename/RenameListCellRenderer.java @@ -160,7 +160,7 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer { if (pathFuture.isDone() && !pathFuture.isCancelled()) { File from = renameModel.getMatch(index).getCandidate(); File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null); - if (from.getAbsolutePath().equals(to.getAbsolutePath())) { + if (equalsCaseSensitive(from, to)) { setIcon(ResourceManager.getIcon("dialog.continue")); } else if (to.exists() && !to.equals(from)) { setIcon(ResourceManager.getIcon("dialog.cancel")); // take into account that on Windows equals/exists is case-insensitive which we have to work around diff --git a/source/net/filebot/util/FileUtilities.java b/source/net/filebot/util/FileUtilities.java index 57b2c000..c45c9020 100644 --- a/source/net/filebot/util/FileUtilities.java +++ b/source/net/filebot/util/FileUtilities.java @@ -59,6 +59,11 @@ public final class FileUtilities { // resolve destination destination = resolveDestination(source, destination); + // do nothing if source and destination path is the same + if (equalsCaseSensitive(source, destination)) { + return destination; + } + if (source.isDirectory()) { // move folder FileUtils.moveDirectory(source, destination); @@ -67,11 +72,11 @@ public final class FileUtilities { // on Windows, use ATOMIC_MOVE which allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored) // but ATOMIC_MOVE can only work for files on the same drive, if that is not the case there is no point trying move with ATOMIC_MOVE - if (isWindows() && source.equals(destination) && !equalsCaseSensitive(source, destination)) { + if (isWindows() && source.equals(destination)) { try { return Files.move(source.toPath(), destination.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile(); } catch (AtomicMoveNotSupportedException e) { - debug.warning(e.getMessage()); + debug.warning(e::toString); } }