mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Add GetDwordValue method to WindowsRegistryAdvanced
This commit introduces the GetDwordValue method in the WindowsRegistryAdvanced class, allowing the retrieval of DWORD values from the Windows Registry. The implementation uses int.TryParse for efficient parsing and handles default values gracefully.
This commit is contained in:
@@ -15,7 +15,9 @@ namespace mRemoteNG.Tools.WindowsRegistry
|
||||
string[] GetSubKeyNames(RegistryHive hive, string path);
|
||||
string GetPropertyValue(WindowsRegistryKey key);
|
||||
string GetPropertyValue(RegistryHive hive, string path, string name);
|
||||
|
||||
bool GetBoolValue(RegistryHive hive, string path, string propertyName, bool defaultValue = false);
|
||||
int GetDwordValue(RegistryHive hive, string path, string propertyName, int defaultValue = 0);
|
||||
|
||||
WindowsRegistryKey GetWindowsRegistryKey(RegistryHive hive, string path, string name);
|
||||
WindowsRegistryKey GetWindowsRegistryKey(WindowsRegistryKey key);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Versioning;
|
||||
using static mRemoteNG.Config.Settings.Registry.RegistryController;
|
||||
|
||||
namespace mRemoteNG.Tools.WindowsRegistry
|
||||
{
|
||||
@@ -17,6 +16,9 @@ namespace mRemoteNG.Tools.WindowsRegistry
|
||||
string GetPropertyValue(WindowsRegistryKey key);
|
||||
string GetPropertyValue(RegistryHive hive, string path, string name);
|
||||
|
||||
bool GetBoolValue(RegistryHive hive, string path, string propertyName, bool defaultValue = false);
|
||||
int GetDwordValue(RegistryHive hive, string path, string propertyName, int defaultValue = 0);
|
||||
|
||||
WindowsRegistryKey GetWindowsRegistryKey(RegistryHive hive, string path, string name);
|
||||
WindowsRegistryKey GetWindowsRegistryKey(WindowsRegistryKey key);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Versioning;
|
||||
using static mRemoteNG.Config.Settings.Registry.RegistryController;
|
||||
|
||||
namespace mRemoteNG.Tools.WindowsRegistry
|
||||
{
|
||||
@@ -17,6 +16,9 @@ namespace mRemoteNG.Tools.WindowsRegistry
|
||||
string GetPropertyValue(WindowsRegistryKey key);
|
||||
string GetPropertyValue(RegistryHive hive, string path, string name);
|
||||
|
||||
bool GetBoolValue(RegistryHive hive, string path, string propertyName, bool defaultValue = false);
|
||||
int GetDwordValue(RegistryHive hive, string path, string propertyName, int defaultValue = 0);
|
||||
|
||||
WindowsRegistryKey GetWindowsRegistryKey(RegistryHive hive, string path, string name);
|
||||
WindowsRegistryKey GetWindowsRegistryKey(WindowsRegistryKey key);
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@ namespace mRemoteNG.Tools.WindowsRegistry
|
||||
{
|
||||
#region registry reader
|
||||
string[] GetSubKeyNames(RegistryHive hive, string path);
|
||||
|
||||
string GetPropertyValue(WindowsRegistryKey key);
|
||||
string GetPropertyValue(RegistryHive hive, string path, string name);
|
||||
|
||||
bool GetBoolValue(RegistryHive hive, string path, string propertyName, bool defaultValue = false);
|
||||
int GetDwordValue(RegistryHive hive, string path, string propertyName, int defaultValue = 0);
|
||||
|
||||
WindowsRegistryKey GetWindowsRegistryKey(RegistryHive hive, string path, string name);
|
||||
WindowsRegistryKey GetWindowsRegistryKey(WindowsRegistryKey key);
|
||||
|
||||
@@ -100,6 +100,26 @@ namespace mRemoteNG.Tools.WindowsRegistry
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// Retrieves a DWORD value from the Windows Registry, with an optional default value.
|
||||
/// </summary>
|
||||
/// <param name="hive">The Registry hive to access.</param>
|
||||
/// <param name="path">The Registry path containing the key.</param>
|
||||
/// <param name="propertyName">The name of the Registry property.</param>
|
||||
/// <param name="defaultValue">The default value to return if the property is not found or cannot be parsed.</param>
|
||||
/// <returns>The DWORD value from the Registry, or the specified default value.</returns>
|
||||
public int GetDwordValue(RegistryHive hive, string path, string propertyName, int defaultValue = 0)
|
||||
{
|
||||
var value = GetPropertyValue(hive, path, propertyName);
|
||||
|
||||
if (int.TryParse(value, out int intValue))
|
||||
{
|
||||
return intValue;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a WindowsRegistryKey object for a specific registry hive, path, and value name.
|
||||
/// </summary>
|
||||
|
||||
@@ -113,6 +113,13 @@ namespace mRemoteNGTests.Tools.Registry
|
||||
Assert.That(key.IsKeyPresent, Is.EqualTo(false));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetDwordValue_returnIntegerValue()
|
||||
{
|
||||
int value = GetDwordValue(_TestHive, _TestRootKey, "TestInteger");
|
||||
Assert.That(value, Is.EqualTo(4711));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetString()
|
||||
|
||||
Reference in New Issue
Block a user