* experimental support for windows shell operations

This commit is contained in:
Reinhard Pointner 2012-07-16 19:11:07 +00:00
parent d9df1f21af
commit 27e8ec1806
3 changed files with 68 additions and 1 deletions

View File

@ -115,11 +115,15 @@
<include name="org/apache/commons/io/**" /> <include name="org/apache/commons/io/**" />
</zipfileset> </zipfileset>
<zipfileset src="${dir.lib}/jna.jar">
<!-- include classes and native libraries --> <!-- include classes and native libraries -->
<zipfileset src="${dir.lib}/jna.jar">
<include name="com/sun/jna/**" /> <include name="com/sun/jna/**" />
</zipfileset> </zipfileset>
<zipfileset src="${dir.lib}/platform.jar">
<include name="com/sun/jna/platform/win32/**" />
</zipfileset>
<zipfileset src="${dir.lib}/groovy.jar"> <zipfileset src="${dir.lib}/groovy.jar">
<include name="groovy*/**" /> <include name="groovy*/**" />
<include name="org/codehaus/groovy/**" /> <include name="org/codehaus/groovy/**" />

BIN
lib/platform.jar Normal file

Binary file not shown.

View File

@ -0,0 +1,63 @@
package net.sourceforge.filebot;
import static net.sourceforge.tuned.FileUtilities.*;
import java.io.File;
import java.io.IOException;
import com.sun.jna.Platform;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Shell32;
import com.sun.jna.platform.win32.ShellAPI;
import com.sun.jna.platform.win32.ShellAPI.SHFILEOPSTRUCT;
public enum NativeRenameAction implements RenameAction {
MOVE,
COPY;
@Override
public File rename(File src, File dst) throws Exception {
return rename(new File[] { src }, new File[] { dst })[0];
}
public File[] rename(File[] src, File[] dst) throws Exception {
String[] pFrom = new String[src.length];
String[] pTo = new String[dst.length];
File[] result = new File[dst.length];
// resolve paths
for (int i = 0; i < pFrom.length; i++) {
result[i] = resolveDestination(src[i], dst[i]).getCanonicalFile(); // resolve dst
pTo[i] = result[i].getPath();
pFrom[i] = src[i].getCanonicalPath(); // resolve src
}
// configure parameter structure
SHFILEOPSTRUCT op = new SHFILEOPSTRUCT();
op.wFunc = ShellAPI.class.getField("FO_" + name()).getInt(null); // ShellAPI.FO_MOVE | ShellAPI.FO_COPY
op.fFlags = Shell32.FOF_MULTIDESTFILES | Shell32.FOF_NOCONFIRMMKDIR;
op.pFrom = new WString(op.encodePaths(pFrom));
op.pTo = new WString(op.encodePaths(pTo));
Shell32.INSTANCE.SHFileOperation(op);
if (op.fAnyOperationsAborted) {
throw new IOException("Operation Aborted");
}
return result;
}
public static boolean isSupported(NativeRenameAction action) {
return Platform.isWindows();
}
}