From 8ac28f25e42458eba92def08f6dcd4e19ec3a5c3 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 27 Nov 2017 17:16:13 +0100 Subject: [PATCH] Refactor NativeRenameAction --- source/net/filebot/NativeRenameAction.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/net/filebot/NativeRenameAction.java b/source/net/filebot/NativeRenameAction.java index 4c44d0f9..a53490f4 100644 --- a/source/net/filebot/NativeRenameAction.java +++ b/source/net/filebot/NativeRenameAction.java @@ -42,7 +42,8 @@ public enum NativeRenameAction implements RenameAction { 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; + + op.wFunc = SHFileOperationFunction(action); op.fFlags = Shell32.FOF_MULTIDESTFILES | Shell32.FOF_NOCOPYSECURITYATTRIBS | Shell32.FOF_NOCONFIRMATION | Shell32.FOF_NOCONFIRMMKDIR; op.pFrom = op.encodePaths(src); @@ -55,6 +56,17 @@ public enum NativeRenameAction implements RenameAction { } } + private static int SHFileOperationFunction(NativeRenameAction action) { + switch (action) { + case MOVE: + return ShellAPI.FO_MOVE; + case COPY: + return ShellAPI.FO_COPY; + default: + throw new UnsupportedOperationException("SHFileOperation not supported: " + action); + } + } + private static String[] getPathArray(List files) { return files.stream().map(File::getAbsolutePath).toArray(String[]::new); }