Read VLC path with correct bitness for current java

This commit is contained in:
Jindra Petřík
2022-12-05 20:30:26 +01:00
parent 3003cc3f24
commit e4f5ca4537
2 changed files with 21 additions and 9 deletions

View File

@@ -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;

View File

@@ -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);
}