// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using Microsoft.Win32;
namespace Deltares.Dam.Data.Registry;
public abstract class RegistryReader
{
///
/// Reads a string value from the Windows registry for the local machine.
///
/// The path to the key
/// The name of the key
/// The value or empty string if key is not found
public static string GetRegistryValueFromLocalMachine(string registryPath, string valueName)
{
using RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath);
return GetRegistryValue(key, valueName);
}
///
/// Reads a string value from the Windows registry for the current user.
///
/// The path to the key
/// The name of the key
/// The value or empty string if key is not found
public static string GetRegistryValueFromCurrentUser(string registryPath, string valueName)
{
using RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(registryPath);
return GetRegistryValue(key, valueName);
}
private static string GetRegistryValue(RegistryKey key, string valueName)
{
var stringValue = "";
if (key != null)
{
object value = key.GetValue(valueName);
if (value != null)
{
stringValue = value.ToString();
}
}
return stringValue;
}
}