Refactor NativeRenameAction

This commit is contained in:
Reinhard Pointner 2017-11-27 17:16:13 +01:00
parent 0fd06eff35
commit 8ac28f25e4
1 changed files with 13 additions and 1 deletions

View File

@ -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<File> files) {
return files.stream().map(File::getAbsolutePath).toArray(String[]::new);
}