From dfed4cb19de76c999e016f0278f7e9c5da8ea042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Sat, 10 Nov 2018 19:32:27 +0100 Subject: [PATCH] Removed redundant helper method --- DerpingDrivers/Util/OSVersionInfo.cs | 66 +++------------------------- 1 file changed, 7 insertions(+), 59 deletions(-) diff --git a/DerpingDrivers/Util/OSVersionInfo.cs b/DerpingDrivers/Util/OSVersionInfo.cs index 52a488c..fc94951 100644 --- a/DerpingDrivers/Util/OSVersionInfo.cs +++ b/DerpingDrivers/Util/OSVersionInfo.cs @@ -68,58 +68,6 @@ namespace DerpingDrivers.Util #endregion - #region Registry Methods - - private static string RegistryRead(string registryPath, string field, string defaultValue) - { - var rtn = string.Empty; - var backSlash = string.Empty; - var newRegistryPath = string.Empty; - - try - { - RegistryKey ourKey = null; - var splitResult = registryPath.Split('\\'); - - if (splitResult.Length > 0) - { - splitResult[0] = splitResult[0].ToUpper(); // Make the first entry uppercase... - - if (splitResult[0] == "HKEY_CLASSES_ROOT") ourKey = Registry.ClassesRoot; - else if (splitResult[0] == "HKEY_CURRENT_USER") ourKey = Registry.CurrentUser; - else if (splitResult[0] == "HKEY_LOCAL_MACHINE") ourKey = Registry.LocalMachine; - else if (splitResult[0] == "HKEY_USERS") ourKey = Registry.Users; - else if (splitResult[0] == "HKEY_CURRENT_CONFIG") ourKey = Registry.CurrentConfig; - - if (ourKey != null) - { - for (var i = 1; i < splitResult.Length; i++) - { - newRegistryPath += backSlash + splitResult[i]; - backSlash = "\\"; - } - - if (newRegistryPath != "") - { - //rtn = (string)Registry.GetValue(RegistryPath, "CurrentVersion", DefaultValue); - - ourKey = ourKey.OpenSubKey(newRegistryPath); - rtn = (string) ourKey.GetValue(field, defaultValue); - ourKey.Close(); - } - } - } - } - catch - { - // TODO: argh! - } - - return rtn; - } - - #endregion Registry Methods - #region DELEGATE DECLARATION private delegate bool IsWow64ProcessDelegate([In] IntPtr handle, [Out] out bool isWow64Process); @@ -606,8 +554,8 @@ namespace DerpingDrivers.Util // For applications that have been manifested for Windows 8.1 & Windows 10. Applications not manifested for 8.1 or 10 will return the Windows 8 OS version value (6.2). // By reading the registry, we'll get the exact version - meaning we can even compare against Win 8 and Win 8.1. var exactVersion = - RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", - "CurrentVersion", ""); + Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", + "CurrentVersion", null) as string; if (!string.IsNullOrEmpty(exactVersion)) { var splitResult = exactVersion.Split('.'); @@ -1004,7 +952,7 @@ namespace DerpingDrivers.Util /// Gets the build version number of the operating system running on this computer. /// public static int BuildVersion => - int.Parse(RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", + int.Parse((string) Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber", "0")); #endregion BUILD @@ -1041,8 +989,8 @@ namespace DerpingDrivers.Util get { if (IsWindows10) return 10; - var exactVersion = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", - "CurrentVersion", ""); + var exactVersion = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", + "CurrentVersion", null) as string; if (string.IsNullOrEmpty(exactVersion)) return Environment.OSVersion.Version.Major; @@ -1063,8 +1011,8 @@ namespace DerpingDrivers.Util get { if (IsWindows10) return 0; - var exactVersion = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", - "CurrentVersion", ""); + var exactVersion = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", + "CurrentVersion", null) as string; if (string.IsNullOrEmpty(exactVersion)) return Environment.OSVersion.Version.Minor;