Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update Registry Code #192

Merged
merged 12 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SauceControl.InheritDoc" Version="2.0.1" PrivateAssets="all" />
<PackageReference Include="SauceControl.InheritDoc" Version="2.0.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
<PrivateAssets>all</PrivateAssets>
<Version>3.6.143</Version>
<Version>3.6.146</Version>
</PackageReference>
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 AnakinSklavenwalker
Copyright (c) 2024 AnakinSklavenwalker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Testably.Abstractions" Version="3.2.3" />
Expand Down
2 changes: 1 addition & 1 deletion src/CommonUtilities.FileSystem/src/ThrowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;

namespace AnakinRaW.CommonUtilities.FileSystem.Windows;
namespace AnakinRaW.CommonUtilities.FileSystem;

internal static class ThrowHelper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/CommonUtilities.Registry/src/IRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/// </summary>
public interface IRegistry
{
/// <summary>
/// Gets a value indicating whether sub key paths and key value names are case-sensitive.
/// </summary>
public bool IsCaseSensitive { get; }

/// <summary>
/// Opens a new <see cref="IRegistryKey"/> that represents the requested key on the local machine
/// with the specified view.
Expand Down
241 changes: 134 additions & 107 deletions src/CommonUtilities.Registry/src/IRegistryKey.cs

Large diffs are not rendered by default.

47 changes: 35 additions & 12 deletions src/CommonUtilities.Registry/src/InMemoryRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,46 @@ public sealed class InMemoryRegistry : IRegistry
{
private readonly Dictionary<(RegistryView, RegistryHive), InMemoryRegistryKey> _rootKeys = new();

private static readonly ICollection<RegistryView> RegistryViews =
Enum.GetValues(typeof(RegistryView)).OfType<RegistryView>().ToList();

private static readonly (RegistryHive, string)[] HivesAndNames =
[
(RegistryHive.CurrentUser, "HKEY_CURRENT_USER"),
(RegistryHive.LocalMachine, "HKEY_LOCAL_MACHINE"),
(RegistryHive.ClassesRoot, "HKEY_CLASSES_ROOT")
];

/// <summary>
/// Gets a value indicating whether sub key paths and key value names are case-sensitive.
/// </summary>
public bool IsCaseSensitive { get; }

/// <summary>
/// Gets the option flags this <see cref="InMemoryRegistry"/> was created with.
/// </summary>
public InMemoryRegistryCreationFlags Flags { get; }

/// <summary>
/// Creates a new registry instance.
/// Creates a new instance of the <see cref="InMemoryRegistry"/> class.
/// </summary>
public InMemoryRegistry()
public InMemoryRegistry() : this(InMemoryRegistryCreationFlags.Default)
{
var hivesAndNames = new[]
{
(RegistryHive.None, string.Empty),
(RegistryHive.CurrentUser, "HKEY_CURRENT_USER"),
(RegistryHive.LocalMachine, "HKEY_LOCAL_MACHINE"),
(RegistryHive.ClassesRoot, "HKEY_CLASSES_ROOT"),
};
foreach (var (hive, name) in hivesAndNames)
}

/// <summary>
/// Creates a new instance of the <see cref="InMemoryRegistry"/> class.
/// </summary>
public InMemoryRegistry(InMemoryRegistryCreationFlags creationFlags)
{
IsCaseSensitive = creationFlags.HasFlag(InMemoryRegistryCreationFlags.CaseSensitive);
Flags = creationFlags;
foreach (var (hive, name) in HivesAndNames)
{
foreach (var view in Enum.GetValues(typeof(RegistryView)).OfType<RegistryView>())
foreach (var view in RegistryViews)
{
_rootKeys.Add((view, hive), new InMemoryRegistryKey(view, name));
var keyData = new InMemoryRegistryKeyData(view, name, null, creationFlags, true);
_rootKeys.Add((view, hive), new InMemoryRegistryKey(keyData.Name, keyData, true));
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/CommonUtilities.Registry/src/InMemoryRegistryCreationFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace AnakinRaW.CommonUtilities.Registry;

/// <summary>
/// Specifies the behavior of the <see cref="InMemoryRegistry"/>.
/// </summary>
[Flags]
public enum InMemoryRegistryCreationFlags
{
/// <summary>
/// By default, the <see cref="InMemoryRegistry"/> is case-insensitive and does not mimic any Windows Registry specialities
/// such as key and value name length or forbidden data types.
/// </summary>
Default = 0,
/// <summary>
/// The <see cref="InMemoryRegistry"/> shall treat key and value names in a case-sensitive manner.
/// </summary>
CaseSensitive = 1,
/// <summary>
/// The <see cref="InMemoryRegistry"/> uses the same key and value name length limitations as the Windows Registry.
/// For keys the max. name length is 255 .For values the max. name length is 16,383.
/// </summary>
UseWindowsLengthLimits = 2,
/// <summary>
/// The <see cref="InMemoryRegistry"/> only supports <see cref="string"/> and <see cref="byte"/> as array types.
/// String arrays must not contain <see langword="null"/> references.
/// </summary>
OnlyUseWindowsDataTypes = 4,
/// <summary>
/// The <see cref="InMemoryRegistry"/> behaves like the Windows Registry does.
/// </summary>
WindowsLike = UseWindowsLengthLimits | OnlyUseWindowsDataTypes
}
Loading
Loading