From 6963eb41eb70867bc273491301376c6ee89e7186 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 20 Jul 2012 03:38:47 +0000 Subject: [PATCH] * added -DuseNativeShell to jnlp * don't create auto-create folders when not necessary * manually set java/jna.library.path to make sure it's in the install folder --- installer/msi/filebot.launcher.l4j.ini | 4 ++++ installer/msi/filebot.platform.launcher.l4j.ini | 4 ++++ installer/webstart/filebot.jnlp | 4 +++- .../net/sourceforge/filebot/NativeRenameAction.java | 11 ++++++++--- source/net/sourceforge/filebot/Settings.java | 6 ++---- .../sourceforge/filebot/StandardRenameAction.java | 8 ++++---- .../sourceforge/filebot/ui/rename/RenameAction.java | 8 +++++--- source/net/sourceforge/tuned/FileUtilities.java | 12 +++++++----- 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/installer/msi/filebot.launcher.l4j.ini b/installer/msi/filebot.launcher.l4j.ini index c7a44b4c..4f7b2524 100644 --- a/installer/msi/filebot.launcher.l4j.ini +++ b/installer/msi/filebot.launcher.l4j.ini @@ -18,3 +18,7 @@ # http connection timeouts -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 + +# look for native libs here +-Djna.library.path="%EXEDIR%" +-Djava.library.path="%EXEDIR%" diff --git a/installer/msi/filebot.platform.launcher.l4j.ini b/installer/msi/filebot.platform.launcher.l4j.ini index 640d87a7..308c5ecf 100644 --- a/installer/msi/filebot.platform.launcher.l4j.ini +++ b/installer/msi/filebot.platform.launcher.l4j.ini @@ -24,6 +24,10 @@ -Dsun.net.client.defaultConnectTimeout=5000 -Dsun.net.client.defaultReadTimeout=25000 +# look for native libs here +-Djna.library.path="%EXEDIR%" +-Djava.library.path="%EXEDIR%" + # force english locale -Dfile.encoding=UTF-8 -Duser.country=US diff --git a/installer/webstart/filebot.jnlp b/installer/webstart/filebot.jnlp index 37231ebd..cb28ba8d 100644 --- a/installer/webstart/filebot.jnlp +++ b/installer/webstart/filebot.jnlp @@ -24,9 +24,11 @@ - + + + diff --git a/source/net/sourceforge/filebot/NativeRenameAction.java b/source/net/sourceforge/filebot/NativeRenameAction.java index 6742ee5d..9fa06b98 100644 --- a/source/net/sourceforge/filebot/NativeRenameAction.java +++ b/source/net/sourceforge/filebot/NativeRenameAction.java @@ -26,7 +26,7 @@ public enum NativeRenameAction implements RenameAction { @Override public File rename(File src, File dst) throws IOException { - dst = resolveDestination(src, dst).getCanonicalFile(); + dst = resolveDestination(src, dst, false).getCanonicalFile(); rename(singletonMap(src, dst)); return dst; } @@ -40,13 +40,18 @@ public enum NativeRenameAction implements RenameAction { int i = 0; for (Entry it : map.entrySet()) { src[i] = it.getKey().getCanonicalPath(); - dst[i] = resolveDestination(it.getKey(), it.getValue()).getCanonicalPath(); + dst[i] = resolveDestination(it.getKey(), it.getValue(), false).getCanonicalPath(); i++; } + callNative_Shell32(this, src, dst); + } + + + private static void callNative_Shell32(NativeRenameAction action, String[] src, String[] dst) { // configure parameter structure SHFILEOPSTRUCT op = new SHFILEOPSTRUCT(); - op.wFunc = (this == MOVE) ? ShellAPI.FO_MOVE : ShellAPI.FO_COPY; + op.wFunc = (action == MOVE) ? ShellAPI.FO_MOVE : ShellAPI.FO_COPY; op.fFlags = Shell32.FOF_MULTIDESTFILES | Shell32.FOF_NOCONFIRMMKDIR; op.pFrom = new WString(op.encodePaths(src)); diff --git a/source/net/sourceforge/filebot/Settings.java b/source/net/sourceforge/filebot/Settings.java index 37f7698e..a101ab1c 100644 --- a/source/net/sourceforge/filebot/Settings.java +++ b/source/net/sourceforge/filebot/Settings.java @@ -50,8 +50,7 @@ public final class Settings { public static boolean useNativeShell() { - //TODO disable by default for final release - return System.getProperty("useNativeShell") == null ? true : Boolean.parseBoolean(System.getProperty("useNativeShell")); + return Boolean.parseBoolean(System.getProperty("useNativeShell")); } @@ -91,7 +90,7 @@ public final class Settings { applicationFolder = new File(System.getProperty("user.dir")); } - // create folder if necessary + // create folder if necessary if (!applicationFolder.exists()) { applicationFolder.mkdirs(); } @@ -104,7 +103,6 @@ public final class Settings { return new Settings(Preferences.userNodeForPackage(type)); } - private final Preferences prefs; diff --git a/source/net/sourceforge/filebot/StandardRenameAction.java b/source/net/sourceforge/filebot/StandardRenameAction.java index 8127f5bb..3b2524e2 100644 --- a/source/net/sourceforge/filebot/StandardRenameAction.java +++ b/source/net/sourceforge/filebot/StandardRenameAction.java @@ -30,7 +30,7 @@ public enum StandardRenameAction implements RenameAction { @Override public File rename(File from, File to) throws Exception { - File destionation = FileUtilities.resolveDestination(from, to); + File destionation = FileUtilities.resolveDestination(from, to, true); // move file and the create a symlink to the new location via NIO.2 try { @@ -48,7 +48,7 @@ public enum StandardRenameAction implements RenameAction { @Override public File rename(File from, File to) throws Exception { - File destionation = FileUtilities.resolveDestination(from, to); + File destionation = FileUtilities.resolveDestination(from, to, true); // create symlink via NIO.2 try { @@ -65,7 +65,7 @@ public enum StandardRenameAction implements RenameAction { @Override public File rename(File from, File to) throws Exception { - File destionation = FileUtilities.resolveDestination(from, to); + File destionation = FileUtilities.resolveDestination(from, to, true); // create hardlink via NIO.2 try { @@ -82,7 +82,7 @@ public enum StandardRenameAction implements RenameAction { @Override public File rename(File from, File to) throws IOException { - return FileUtilities.resolveDestination(from, to); + return FileUtilities.resolveDestination(from, to, false); } }; diff --git a/source/net/sourceforge/filebot/ui/rename/RenameAction.java b/source/net/sourceforge/filebot/ui/rename/RenameAction.java index d9cea02e..eda34f81 100644 --- a/source/net/sourceforge/filebot/ui/rename/RenameAction.java +++ b/source/net/sourceforge/filebot/ui/rename/RenameAction.java @@ -47,6 +47,7 @@ class RenameAction extends AbstractAction { public static final String RENAME_ACTION = "RENAME_ACTION"; + private final RenameModel model; @@ -63,6 +64,7 @@ class RenameAction extends AbstractAction { } + @Override public void actionPerformed(ActionEvent evt) { if (model.getRenameMap().isEmpty()) { return; @@ -102,7 +104,7 @@ class RenameAction extends AbstractAction { dialog.setVisible(true); } } - } catch (Exception e) { + } catch (Throwable e) { // could not rename one of the files, revert all changes UILogger.log(Level.WARNING, e.getMessage(), e); } @@ -253,7 +255,7 @@ class RenameAction extends AbstractAction { // rename file, throw exception on failure action.rename(mapping.getKey(), mapping.getValue()); - // remember successfully renamed matches for history entry and possible revert + // remember successfully renamed matches for history entry and possible revert renameLog.put(mapping.getKey(), mapping.getValue()); } } finally { @@ -323,7 +325,7 @@ class RenameAction extends AbstractAction { super.cancel(false); throw e; } finally { - // check status of renamed files + // check status of renamed files for (Entry it : renameMap.entrySet()) { if (it.getValue().exists()) { renameLog.put(it.getKey(), it.getValue()); diff --git a/source/net/sourceforge/tuned/FileUtilities.java b/source/net/sourceforge/tuned/FileUtilities.java index dffebb4f..fbbf9792 100644 --- a/source/net/sourceforge/tuned/FileUtilities.java +++ b/source/net/sourceforge/tuned/FileUtilities.java @@ -44,7 +44,7 @@ public final class FileUtilities { public static File moveRename(File source, File destination) throws IOException { // resolve destination - destination = resolveDestination(source, destination); + destination = resolveDestination(source, destination, true); if (source.isDirectory()) { // move folder @@ -64,7 +64,7 @@ public final class FileUtilities { public static File copyAs(File source, File destination) throws IOException { // resolve destination - destination = resolveDestination(source, destination); + destination = resolveDestination(source, destination, true); if (source.isDirectory()) { // copy folder @@ -82,7 +82,7 @@ public final class FileUtilities { } - public static File resolveDestination(File source, File destination) throws IOException { + public static File resolveDestination(File source, File destination, boolean mkdirs) throws IOException { // resolve destination if (!destination.isAbsolute()) { // same folder, different name @@ -93,7 +93,7 @@ public final class FileUtilities { File destinationFolder = destination.getParentFile(); // create parent folder if necessary - if (!destinationFolder.isDirectory() && !destinationFolder.mkdirs()) { + if (mkdirs && !destinationFolder.isDirectory() && !destinationFolder.mkdirs()) { throw new IOException("Failed to create folder: " + destinationFolder); } @@ -502,7 +502,7 @@ public final class FileUtilities { tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); tr.setOutputProperty(OutputKeys.INDENT, "yes"); - //create string from dom + // create string from dom StringWriter buffer = new StringWriter(); tr.transform(new DOMSource(dom), new StreamResult(buffer)); return buffer.toString(); @@ -532,6 +532,7 @@ public final class FileUtilities { } }; + public static final FileFilter FILES = new FileFilter() { @Override @@ -540,6 +541,7 @@ public final class FileUtilities { } }; + public static final FileFilter TEMPORARY = new FileFilter() { private final String tmpdir = System.getProperty("java.io.tmpdir");