From babacb68dd00753ddc6d94b8a7709337890ce5b3 Mon Sep 17 00:00:00 2001 From: fyr77 Date: Sun, 2 May 2021 16:16:03 +0200 Subject: [PATCH] add workaround for registry read error --- EnvyUpdate/Debug.cs | 1 + EnvyUpdate/Util.cs | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/EnvyUpdate/Debug.cs b/EnvyUpdate/Debug.cs index 3b4d7f0..ff64185 100644 --- a/EnvyUpdate/Debug.cs +++ b/EnvyUpdate/Debug.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; namespace EnvyUpdate diff --git a/EnvyUpdate/Util.cs b/EnvyUpdate/Util.cs index 56f9158..ecfa422 100644 --- a/EnvyUpdate/Util.cs +++ b/EnvyUpdate/Util.cs @@ -387,10 +387,27 @@ namespace EnvyUpdate RegistryKey nvlddmkm = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\services\nvlddmkm", true); return nvlddmkm.GetValueNames().Contains("DCHUVen"); } - catch (NullReferenceException) + catch (Exception ex) { - // Assume no DCH driver is installed if key is not found. - return false; + if (ex.InnerException is NullReferenceException) + { + // Assume no DCH driver is installed if key is not found. + return false; + } + else if (ex.InnerException is System.Security.SecurityException) + { + //Registry reading error. Check for existance of file nvsvs.dll instead. + if (System.IO.File.Exists(Path.Combine(Environment.SystemDirectory, "nvsvs.dll"))) + return true; + else + return false; + } + else + { + MessageBox.Show("An error has occured. Please report this on GitHub.\nError:" + ex.Message); + Environment.Exit(20); + return false; + } } } public static int GetDTCID()