diff --git a/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java index 099dbc23..2d9d2512 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppAvCheck.java @@ -28,8 +28,7 @@ public class AppAvCheck { @Override public boolean isActive() { - var bitdefender = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Bitdefender", "InstallDir"); - return bitdefender.isPresent(); + return WindowsRegistry.exists(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Bitdefender", "InstallDir"); } }, MALWAREBYTES("Malwarebytes") { @@ -40,8 +39,7 @@ public class AppAvCheck { @Override public boolean isActive() { - var reg = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Malwarebytes", "id"); - return reg.isPresent(); + return WindowsRegistry.exists(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Malwarebytes", "id"); } }, MCAFEE("McAfee") { @@ -52,8 +50,7 @@ public class AppAvCheck { @Override public boolean isActive() { - var mcafee = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\McAfee", "mi"); - return mcafee.isPresent(); + return WindowsRegistry.exists(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\McAfee", "mi"); } }; diff --git a/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java b/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java index 98221d33..1354c754 100644 --- a/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java +++ b/app/src/main/java/io/xpipe/app/util/WindowsRegistry.java @@ -13,6 +13,17 @@ public class WindowsRegistry { public static final int HKEY_CURRENT_USER = 0x80000001; public static final int HKEY_LOCAL_MACHINE = 0x80000002; + public static boolean exists(int hkey, String key, String valueName) { + // This can fail even with errors in case the jna native library extraction fails + try { + return Advapi32Util.registryValueExists( + hkey == HKEY_LOCAL_MACHINE ? WinReg.HKEY_LOCAL_MACHINE : WinReg.HKEY_CURRENT_USER, key, valueName); + } catch (Throwable t) { + ErrorEvent.fromThrowable(t).handle(); + return false; + } + } + public static Optional readString(int hkey, String key) { return readString(hkey, key, null); }