From 197d0e0b6b22eee85a897877578de42dfc3cd6b4 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 13 Aug 2018 18:57:35 +0700 Subject: [PATCH] Try to fix 32-bit MWS support --- .../filebot/platform/windows/Kernel32.java | 5 +++- .../platform/windows/WinAppUtilities.java | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/platform/windows/Kernel32.java b/source/net/filebot/platform/windows/Kernel32.java index be6f491f..3df748f6 100644 --- a/source/net/filebot/platform/windows/Kernel32.java +++ b/source/net/filebot/platform/windows/Kernel32.java @@ -10,8 +10,11 @@ public interface Kernel32 extends StdCallLibrary { Kernel32 INSTANCE = Native.loadLibrary("kernel32", Kernel32.class, W32APIOptions.DEFAULT_OPTIONS); + long APPMODEL_ERROR_NO_PACKAGE = 15700; + long ERROR_INSUFFICIENT_BUFFER = 122; + long GetCurrentPackageFullName(UINTByReference packageFullNameLength, LPWSTR packageFullName); - long APPMODEL_ERROR_NO_PACKAGE = 15700; + long GetCurrentApplicationUserModelId(UINTByReference applicationUserModelIdLength, LPWSTR applicationUserModelId); } diff --git a/source/net/filebot/platform/windows/WinAppUtilities.java b/source/net/filebot/platform/windows/WinAppUtilities.java index cb4619a2..e9daa783 100644 --- a/source/net/filebot/platform/windows/WinAppUtilities.java +++ b/source/net/filebot/platform/windows/WinAppUtilities.java @@ -13,10 +13,10 @@ import com.sun.jna.Native; import com.sun.jna.WString; import com.sun.jna.platform.win32.Shell32; import com.sun.jna.platform.win32.W32Errors; +import com.sun.jna.platform.win32.WTypes.LPWSTR; import com.sun.jna.platform.win32.WinDef.UINT; import com.sun.jna.platform.win32.WinDef.UINTByReference; import com.sun.jna.platform.win32.WinError; -import com.sun.jna.platform.win32.WTypes.LPWSTR; import com.sun.jna.ptr.PointerByReference; public class WinAppUtilities { @@ -42,17 +42,29 @@ public class WinAppUtilities { } public static String getPackageName() { - UINTByReference length = new UINTByReference(new UINT(0)); - if (Kernel32.INSTANCE.GetCurrentPackageFullName(length, null) != W32Errors.ERROR_SUCCESS) { - throw new IllegalStateException("Kernel32.GetCurrentPackageFullName"); + UINTByReference packageFullNameLength = new UINTByReference(new UINT(64)); + LPWSTR packageFullName = new LPWSTR(new Memory(packageFullNameLength.getValue().intValue() * Native.WCHAR_SIZE)); + + long r = Kernel32.INSTANCE.GetCurrentPackageFullName(packageFullNameLength, packageFullName); + + if (r != W32Errors.ERROR_SUCCESS) { + throw new IllegalStateException(String.format("Kernel32.GetCurrentPackageFullName (%d)", r)); } - LPWSTR lpwstr = new LPWSTR(new Memory(length.getValue().intValue() * Native.WCHAR_SIZE)); - if (Kernel32.INSTANCE.GetCurrentPackageFullName(length, null) != W32Errors.ERROR_SUCCESS) { - throw new IllegalStateException("Kernel32.GetCurrentPackageFullName"); + return packageFullName.getValue(); + } + + public static String getPackageAppUserModelID() { + UINTByReference applicationUserModelIdLength = new UINTByReference(new UINT(64)); + LPWSTR applicationUserModelId = new LPWSTR(new Memory(applicationUserModelIdLength.getValue().intValue() * Native.WCHAR_SIZE)); + + long r = Kernel32.INSTANCE.GetCurrentPackageFullName(applicationUserModelIdLength, applicationUserModelId); + + if (r != W32Errors.ERROR_SUCCESS) { + throw new IllegalStateException(String.format("Kernel32.GetCurrentApplicationUserModelId (%d)", r)); } - return lpwstr.toString(); + return applicationUserModelId.getValue(); } public static void initializeApplication(String aumid) {