From 12cca9b07a9cf1a6759e991e46da632c9dee6379 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Thu, 10 Oct 2024 16:55:42 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Misc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Microsoft.Win32/Registry2.cs | 49 ++++++++++++++++--- src/Sdk/Links/Random2.props | 8 +++ 2 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/Sdk/Links/Random2.props diff --git a/src/BD.Common8.Bcl/Microsoft.Win32/Registry2.cs b/src/BD.Common8.Bcl/Microsoft.Win32/Registry2.cs index d66c8d026..af63001c5 100644 --- a/src/BD.Common8.Bcl/Microsoft.Win32/Registry2.cs +++ b/src/BD.Common8.Bcl/Microsoft.Win32/Registry2.cs @@ -13,15 +13,48 @@ public static partial class Registry2 /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RegistryHive? GetRegistryHive(string hKey) => hKey.ToUpperInvariant() switch + public static RegistryHive? GetRegistryHive(string hKey) { - "HKCR" => RegistryHive.ClassesRoot, - "HKCU" => RegistryHive.CurrentUser, - "HKLM" => RegistryHive.LocalMachine, - "HKCC" => RegistryHive.CurrentConfig, - "HKPD" => RegistryHive.PerformanceData, - _ => default, - }; + if (hKey != null && hKey.Length >= 4) + { + if ((hKey[0] == 'h' || hKey[0] == 'H') && (hKey[1] == 'k' || hKey[1] == 'K')) + { + switch (hKey[2]) + { + case 'c': + case 'C': + if (hKey[3] == 'r' || hKey[3] == 'R') + { + return RegistryHive.ClassesRoot; + } + else if (hKey[3] == 'u' || hKey[3] == 'U') + { + return RegistryHive.CurrentUser; + } + else if (hKey[3] == 'c' || hKey[3] == 'C') + { + return RegistryHive.CurrentConfig; + } + break; + case 'l': + case 'L': + if (hKey[3] == 'm' || hKey[3] == 'M') + { + return RegistryHive.LocalMachine; + } + break; + case 'p': + case 'P': + if (hKey[3] == 'd' || hKey[3] == 'D') + { + return RegistryHive.PerformanceData; + } + break; + } + } + } + return default; + } #pragma warning restore CA1416 // 验证平台兼容性 #if WINDOWS diff --git a/src/Sdk/Links/Random2.props b/src/Sdk/Links/Random2.props new file mode 100644 index 000000000..5aa1a419f --- /dev/null +++ b/src/Sdk/Links/Random2.props @@ -0,0 +1,8 @@ + + + + + _SourceReference\BD.Common8.Bcl + + + \ No newline at end of file