From f851e3cd24227b524c145eb287392471edb20c08 Mon Sep 17 00:00:00 2001 From: Inestic <50652175+Inestic@users.noreply.github.com> Date: Wed, 18 May 2022 14:45:30 +0300 Subject: [PATCH] Fixed the order of ids :id: --- SophiApp/SophiApp/Helpers/RegHelper.cs | 2 +- .../SophiApp/Helpers/VisualRedistrLibsHelper.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/SophiApp/SophiApp/Helpers/RegHelper.cs b/SophiApp/SophiApp/Helpers/RegHelper.cs index 9092483f..46399bec 100644 --- a/SophiApp/SophiApp/Helpers/RegHelper.cs +++ b/SophiApp/SophiApp/Helpers/RegHelper.cs @@ -6,7 +6,7 @@ namespace SophiApp.Helpers { internal class RegHelper { - private static RegistryKey GetKey(RegistryHive hive, string keyPath) => RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenSubKey(keyPath); + private static RegistryKey GetKey(RegistryHive hive, string keyPath) => RegistryKey.OpenBaseKey(hive, RegistryView.Registry64)?.OpenSubKey(keyPath); private static RegistryKey SetKey(RegistryHive hive, string keyPath) => RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenSubKey(keyPath, true) ?? RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).CreateSubKey(keyPath, true); diff --git a/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs b/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs index 1abc8200..d791f108 100644 --- a/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs +++ b/SophiApp/SophiApp/Helpers/VisualRedistrLibsHelper.cs @@ -33,11 +33,18 @@ internal static Version GetInstalledVersion() internal static bool IsInstalled() { - var vcRegistryPath = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, REDISTRX64_REGISTRY_PATH) + try + { + var vcRegistryPath = RegHelper.GetSubKeyNames(RegistryHive.ClassesRoot, REDISTRX64_REGISTRY_PATH) .FirstOrDefault(key => key.Contains(REDISTRX64_REGISTRY_NAME_PATTERN)); - return vcRegistryPath != null && RegHelper.GetStringValue(RegistryHive.ClassesRoot, vcRegistryPath, DISPLAY_NAME) - .Contains(MSREDISTR_LIB_VS_2022_NAME); + return vcRegistryPath != null && RegHelper.GetStringValue(RegistryHive.ClassesRoot, vcRegistryPath, DISPLAY_NAME) + .Contains(MSREDISTR_LIB_VS_2022_NAME); + } + catch (Exception) + { + return false; + } } } } \ No newline at end of file