Skip to content

Commit

Permalink
🚧 Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Oct 10, 2024
1 parent e3c7b06 commit 12cca9b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/BD.Common8.Bcl/Microsoft.Win32/Registry2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,48 @@ public static partial class Registry2
/// <param name="hKey"></param>
/// <returns></returns>
[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
Expand Down
8 changes: 8 additions & 0 deletions src/Sdk/Links/Random2.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<!-- 📄 源码引用 -->
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)..\..\BD.Common8.Bcl\Random2.cs">
<LinkBase>_SourceReference\BD.Common8.Bcl</LinkBase>
</Compile>
</ItemGroup>
</Project>

0 comments on commit 12cca9b

Please sign in to comment.