diff --git a/source/net/filebot/NativeRenameAction.java b/source/net/filebot/NativeRenameAction.java index 89d6a315..665c5cc6 100644 --- a/source/net/filebot/NativeRenameAction.java +++ b/source/net/filebot/NativeRenameAction.java @@ -4,8 +4,9 @@ import static java.util.Collections.*; import static net.filebot.util.FileUtilities.*; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.concurrent.CancellationException; import com.sun.jna.Platform; @@ -26,21 +27,20 @@ public enum NativeRenameAction implements RenameAction { } public void rename(Map map) { - String[] src = new String[map.size()]; - String[] dst = new String[map.size()]; + List src = new ArrayList(map.size()); + List dst = new ArrayList(map.size()); - // resolve paths - int i = 0; - for (Entry it : map.entrySet()) { - src[i] = it.getKey().getAbsolutePath(); - dst[i] = resolve(it.getKey(), it.getValue()).getAbsolutePath(); - i++; - } + map.forEach((from, to) -> { + // resolve relative paths + src.add(from); + dst.add(resolve(from, to)); + }); - callNative_Shell32(this, src, dst); + // call Windows MOVE / COPY dialog + SHFileOperation(this, getPathArray(src), getPathArray(dst)); } - private static void callNative_Shell32(NativeRenameAction action, String[] src, String[] dst) { + private static void SHFileOperation(NativeRenameAction action, String[] src, String[] dst) { // configure parameter structure SHFILEOPSTRUCT op = new SHFILEOPSTRUCT(); op.wFunc = (action == MOVE) ? ShellAPI.FO_MOVE : ShellAPI.FO_COPY; @@ -56,9 +56,13 @@ public enum NativeRenameAction implements RenameAction { } } - public static boolean isSupported() { + private static String[] getPathArray(List files) { + return files.stream().map(File::getAbsolutePath).toArray(String[]::new); + } + + public static boolean isSupported(StandardRenameAction action) { try { - return Platform.isWindows(); + return Platform.isWindows() && (action == StandardRenameAction.MOVE || action == StandardRenameAction.COPY); } catch (Throwable e) { return false; } diff --git a/source/net/filebot/ui/rename/RenameAction.java b/source/net/filebot/ui/rename/RenameAction.java index 48a107af..e69d7996 100644 --- a/source/net/filebot/ui/rename/RenameAction.java +++ b/source/net/filebot/ui/rename/RenameAction.java @@ -88,7 +88,7 @@ class RenameAction extends AbstractAction { Map renameLog = new LinkedHashMap(); try { - if (useNativeShell() && isNativeActionSupported(action)) { + if (useNativeShell() && NativeRenameAction.isSupported(action)) { // call on EDT RenameWorker worker = new NativeRenameWorker(renameMap, renameLog, NativeRenameAction.valueOf(action.name())); worker.call(null, null, null); @@ -191,14 +191,6 @@ class RenameAction extends AbstractAction { } } - public boolean isNativeActionSupported(StandardRenameAction action) { - try { - return NativeRenameAction.isSupported() && NativeRenameAction.valueOf(action.name()) != null; - } catch (IllegalArgumentException e) { - return false; - } - } - private Map checkRenamePlan(List> renamePlan, Window parent) throws IOException { // ask for user permissions to output paths if (isMacSandbox()) { @@ -348,13 +340,15 @@ class RenameAction extends AbstractAction { // prepare delta, ignore files already named as desired Map renamePlan = new LinkedHashMap(); - for (Entry mapping : renameMap.entrySet()) { - File source = mapping.getKey(); - File destination = resolve(mapping.getKey(), mapping.getValue()); - if (!source.equals(destination)) { + + renameMap.forEach((source, destination) -> { + // resolve relative paths + destination = resolve(source, destination); + + if (!equalsCaseSensitive(source, destination)) { renamePlan.put(source, destination); } - } + }); // call native shell move/copy try {