diff --git a/.classpath b/.classpath
index cec9ef29..6eb7c10f 100644
--- a/.classpath
+++ b/.classpath
@@ -28,7 +28,7 @@
-
+
diff --git a/source/net/filebot/MetaAttributeView.java b/source/net/filebot/MetaAttributeView.java
index ba2f0511..b947417f 100644
--- a/source/net/filebot/MetaAttributeView.java
+++ b/source/net/filebot/MetaAttributeView.java
@@ -10,8 +10,6 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.UserDefinedFileAttributeView;
-import java.text.Normalizer;
-import java.text.Normalizer.Form;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -19,7 +17,7 @@ import java.util.Set;
import com.sun.jna.Platform;
-import net.filebot.mac.xattr.XAttrUtil;
+import net.filebot.mac.MacXattrView;
public class MetaAttributeView extends AbstractMap {
@@ -165,30 +163,4 @@ public class MetaAttributeView extends AbstractMap {
}
}
- private static class MacXattrView {
-
- private final String path;
-
- public MacXattrView(Path path) {
- // MacOS filesystem may require NFD unicode decomposition
- this.path = Normalizer.normalize(path.toFile().getAbsolutePath(), Form.NFD);
- }
-
- public List list() {
- return XAttrUtil.listXAttr(path);
- }
-
- public String read(String key) {
- return XAttrUtil.getXAttr(path, key);
- }
-
- public void write(String key, String value) {
- XAttrUtil.setXAttr(path, key, value);
- }
-
- public void delete(String key) {
- XAttrUtil.removeXAttr(path, key);
- }
- }
-
}
diff --git a/source/net/filebot/mac/MacXattrView.java b/source/net/filebot/mac/MacXattrView.java
new file mode 100644
index 00000000..8e82e8e4
--- /dev/null
+++ b/source/net/filebot/mac/MacXattrView.java
@@ -0,0 +1,35 @@
+package net.filebot.mac;
+
+import java.nio.file.Path;
+import java.text.Normalizer;
+import java.text.Normalizer.Form;
+import java.util.List;
+
+import static com.sun.jna.platform.mac.XAttrUtil.*;
+
+public class MacXattrView {
+
+ private final String path;
+
+ public MacXattrView(Path path) {
+ // MacOS filesystem may require NFD unicode decomposition
+ this.path = Normalizer.normalize(path.toFile().getAbsolutePath(), Form.NFD);
+ }
+
+ public List list() {
+ return listXAttr(path);
+ }
+
+ public String read(String key) {
+ return getXAttr(path, key);
+ }
+
+ public void write(String key, String value) {
+ setXAttr(path, key, value);
+ }
+
+ public void delete(String key) {
+ removeXAttr(path, key);
+ }
+
+}
diff --git a/source/net/filebot/mac/xattr/XAttr.java b/source/net/filebot/mac/xattr/XAttr.java
deleted file mode 100644
index a685a37e..00000000
--- a/source/net/filebot/mac/xattr/XAttr.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (c) 2014 Reinhard Pointner, All Rights Reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package net.filebot.mac.xattr;
-
-import com.sun.jna.Library;
-import com.sun.jna.Native;
-import com.sun.jna.Pointer;
-
-/**
- * JNA wrapper for
- *
- */
-interface XAttr extends Library {
-
- // load from current image
- XAttr INSTANCE = (XAttr) Native.loadLibrary(null, XAttr.class);
-
- // see /usr/include/sys/xattr.h
- int XATTR_NOFOLLOW = 0x0001;
- int XATTR_CREATE = 0x0002;
- int XATTR_REPLACE = 0x0004;
- int XATTR_NOSECURITY = 0x0008;
- int XATTR_NODEFAULT = 0x0010;
- int XATTR_SHOWCOMPRESSION = 0x0020;
- int XATTR_MAXNAMELEN = 127;
- String XATTR_FINDERINFO_NAME = "com.apple.FinderInfo";
- String XATTR_RESOURCEFORK_NAME = "com.apple.ResourceFork";
-
- // see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/getxattr.2.html
- long getxattr(String path, String name, Pointer value, long size, int position, int options);
-
- // see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/setxattr.2.html
- int setxattr(String path, String name, Pointer value, long size, int position, int options);
-
- // see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/removexattr.2.html
- int removexattr(String path, String name, int options);
-
- // see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/listxattr.2.html
- long listxattr(String path, Pointer namebuff, long size, int options);
-
-}
diff --git a/source/net/filebot/mac/xattr/XAttrUtil.java b/source/net/filebot/mac/xattr/XAttrUtil.java
deleted file mode 100644
index 58378930..00000000
--- a/source/net/filebot/mac/xattr/XAttrUtil.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Copyright (c) 2014 Reinhard Pointner, All Rights Reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package net.filebot.mac.xattr;
-
-import static java.nio.charset.StandardCharsets.*;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.sun.jna.Memory;
-
-public class XAttrUtil {
-
- public static List listXAttr(String path) {
- // get required buffer size
- long bufferLength = XAttr.INSTANCE.listxattr(path, null, 0, 0);
-
- if (bufferLength < 0)
- return null;
-
- if (bufferLength == 0)
- return new ArrayList();
-
- Memory valueBuffer = new Memory(bufferLength);
- long valueLength = XAttr.INSTANCE.listxattr(path, valueBuffer, bufferLength, 0);
-
- if (valueLength < 0)
- return null;
-
- return decodeStringSequence(valueBuffer.getByteBuffer(0, valueLength));
- }
-
- public static String getXAttr(String path, String name) {
- // get required buffer size
- long bufferLength = XAttr.INSTANCE.getxattr(path, name, null, 0, 0, 0);
-
- if (bufferLength < 0)
- return null;
-
- Memory valueBuffer = new Memory(bufferLength);
- long valueLength = XAttr.INSTANCE.getxattr(path, name, valueBuffer, bufferLength, 0, 0);
-
- if (valueLength < 0)
- return null;
-
- return decodeString(valueBuffer.getByteBuffer(0, valueLength - 1));
- }
-
- public static int setXAttr(String path, String name, String value) {
- Memory valueBuffer = encodeString(value);
- return XAttr.INSTANCE.setxattr(path, name, valueBuffer, valueBuffer.size(), 0, 0);
- }
-
- public static int removeXAttr(String path, String name) {
- return XAttr.INSTANCE.removexattr(path, name, 0);
- }
-
- protected static Memory encodeString(String s) {
- // create NULL-terminated UTF-8 String
- byte[] bb = s.getBytes(UTF_8);
- Memory valueBuffer = new Memory(bb.length + 1);
- valueBuffer.write(0, bb, 0, bb.length);
- valueBuffer.setByte(valueBuffer.size() - 1, (byte) 0);
- return valueBuffer;
- }
-
- protected static String decodeString(ByteBuffer bb) {
- return UTF_8.decode(bb).toString();
- }
-
- protected static List decodeStringSequence(ByteBuffer bb) {
- List names = new ArrayList();
-
- bb.mark(); // first key starts from here
- while (bb.hasRemaining()) {
- if (bb.get() == 0) {
- ByteBuffer nameBuffer = (ByteBuffer) bb.duplicate().limit(bb.position() - 1).reset();
- if (nameBuffer.hasRemaining()) {
- names.add(decodeString(nameBuffer));
- }
- bb.mark(); // next key starts from here
- }
- }
-
- return names;
- }
-
-}
diff --git a/source/net/filebot/win/Shell32.java b/source/net/filebot/win/Shell32.java
deleted file mode 100644
index c9809aad..00000000
--- a/source/net/filebot/win/Shell32.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package net.filebot.win;
-
-import com.sun.jna.Native;
-import com.sun.jna.NativeLong;
-import com.sun.jna.WString;
-import com.sun.jna.ptr.PointerByReference;
-import com.sun.jna.win32.StdCallLibrary;
-import com.sun.jna.win32.W32APIOptions;
-
-interface Shell32 extends StdCallLibrary {
-
- Shell32 INSTANCE = (Shell32) Native.loadLibrary("shell32", Shell32.class, W32APIOptions.DEFAULT_OPTIONS);
-
- NativeLong SetCurrentProcessExplicitAppUserModelID(WString appID);
-
- NativeLong GetCurrentProcessExplicitAppUserModelID(PointerByReference appID);
-}
diff --git a/source/net/filebot/win/WinAppUtilities.java b/source/net/filebot/win/WinAppUtilities.java
index fca6b157..529caad5 100644
--- a/source/net/filebot/win/WinAppUtilities.java
+++ b/source/net/filebot/win/WinAppUtilities.java
@@ -4,8 +4,9 @@ import static net.filebot.Logging.*;
import java.util.logging.Level;
-import com.sun.jna.Pointer;
import com.sun.jna.WString;
+import com.sun.jna.platform.win32.Shell32;
+import com.sun.jna.platform.win32.WinError;
import com.sun.jna.ptr.PointerByReference;
public class WinAppUtilities {
@@ -20,10 +21,9 @@ public class WinAppUtilities {
public static String getAppUserModelID() {
try {
- PointerByReference r = new PointerByReference();
- if (Shell32.INSTANCE.GetCurrentProcessExplicitAppUserModelID(r).longValue() != 0) {
- Pointer p = r.getPointer();
- return p.getWideString(0); // LEAK NATIVE MEMORY
+ PointerByReference ppszAppID = new PointerByReference();
+ if (Shell32.INSTANCE.GetCurrentProcessExplicitAppUserModelID(ppszAppID) == WinError.S_OK) {
+ return ppszAppID.getValue().getWideString(0);
}
} catch (Throwable t) {
debug.log(Level.WARNING, t.getMessage(), t);