| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="WindowsRegistryNavigator.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | using System.Linq; |
| | | 9 | | using System.Runtime.Versioning; |
| | | 10 | | using Microsoft.Win32; |
| | | 11 | | using MyNet.IO.Registry; |
| | | 12 | | |
| | | 13 | | namespace MyNet.Platform.Windows.Registry; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Provides a registry navigator implementation for Windows using Microsoft.Win32.Registry. |
| | | 17 | | /// </summary> |
| | | 18 | | [SupportedOSPlatform("windows")] |
| | | 19 | | public sealed class WindowsRegistryNavigator : IRegistryNavigator |
| | | 20 | | { |
| | 24 | 21 | | private readonly RegistryKey _root = Microsoft.Win32.Registry.CurrentUser; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets the child registry paths of the specified parent registry path. This method opens the registry key correspo |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="parent">The parent registry path.</param> |
| | | 27 | | /// <returns>An enumerable collection of child registry paths.</returns> |
| | | 28 | | public IEnumerable<RegistryPath> GetChildren(RegistryPath parent) |
| | | 29 | | { |
| | 6 | 30 | | using var key = _root.OpenSubKey(parent.ToString()); |
| | | 31 | | |
| | 6 | 32 | | return key is null |
| | 6 | 33 | | ? [] |
| | 6 | 34 | | : key.GetSubKeyNames() |
| | 6 | 35 | | .Select(name => RegistryPath.Combine(parent.ToString(), name)); |
| | 6 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Counts the number of child registry keys under the specified parent registry path. This method opens the registr |
| | | 40 | | /// </summary> |
| | | 41 | | /// <param name="parent">The parent registry path.</param> |
| | | 42 | | /// <returns>The number of child registry keys.</returns> |
| | 3 | 43 | | public int Count(RegistryPath parent) => _root.OpenSubKey(parent.ToString())?.SubKeyCount ?? 0; |
| | | 44 | | } |
| | | 45 | | |