From e4f5ca45375fd4f0a6a932fe4b4d836bf8020717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 5 Dec 2022 20:30:26 +0100 Subject: [PATCH] Read VLC path with correct bitness for current java --- .../com/jpexs/video/SimpleMediaPlayer.java | 8 ++++--- .../sun/jna/platform/win32/Advapi32Util.java | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java b/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java index 7248ed6f3..61cafd150 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java @@ -1,6 +1,7 @@ package com.jpexs.video; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.helpers.Helper; import java.awt.image.BufferedImage; import java.lang.annotation.Native; import java.nio.ByteBuffer; @@ -70,10 +71,11 @@ public class SimpleMediaPlayer { static { if (Platform.isWindows()) { + boolean needs64bit = Helper.is64BitJre(); final String VLC_REGISTRY_KEY = "SOFTWARE\\VideoLAN\\VLC"; - if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY)) { - if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, "InstallDir")) { - String vlcInstallDir = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, "InstallDir"); + if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, needs64bit)) { + if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, "InstallDir", needs64bit)) { + String vlcInstallDir = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, "InstallDir", needs64bit); NativeLibrary.addSearchPath("libvlc", vlcInstallDir); } else { available = false; diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java b/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java index 7a469e10c..21eb4030e 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java +++ b/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java @@ -75,6 +75,10 @@ public abstract class Advapi32Util { public String fqn; } + + public static boolean registryKeyExists(HKEY root, String key) { + return registryKeyExists(root, key, false); + } /** * Checks whether a registry key exists. * @@ -82,9 +86,9 @@ public abstract class Advapi32Util { * @param key Path to the registry key. * @return True if the key exists. */ - public static boolean registryKeyExists(HKEY root, String key) { + public static boolean registryKeyExists(HKEY root, String key, boolean use64BitKey) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | (use64BitKey ? 0 : WinNT.KEY_WOW64_32KEY), phkKey); switch (rc) { case W32Errors.ERROR_SUCCESS: Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); @@ -96,6 +100,9 @@ public abstract class Advapi32Util { } } + public static boolean registryValueExists(HKEY root, String key, String value) { + return registryValueExists(root, key, value, false); + } /** * Checks whether a registry value exists. * @@ -104,9 +111,9 @@ public abstract class Advapi32Util { * @param value Value name. * @return True if the value exists. */ - public static boolean registryValueExists(HKEY root, String key, String value) { + public static boolean registryValueExists(HKEY root, String key, String value, boolean use64bitKey) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | (use64bitKey ? 0 : WinNT.KEY_WOW64_32KEY), phkKey); try { switch (rc) { case W32Errors.ERROR_SUCCESS: @@ -139,6 +146,9 @@ public abstract class Advapi32Util { } } + public static String registryGetStringValue(HKEY root, String key, String value) { + return registryGetStringValue(root, key, value, false); + } /** * Get a registry REG_SZ value. * @@ -147,9 +157,9 @@ public abstract class Advapi32Util { * @param value Name of the value to retrieve. * @return String value. */ - public static String registryGetStringValue(HKEY root, String key, String value) { + public static String registryGetStringValue(HKEY root, String key, String value, boolean use64bitKey) { HKEYByReference phkKey = new HKEYByReference(); - int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | (use64bitKey ? 0 : WinNT.KEY_WOW64_32KEY), phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); }