mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
50 lines
2.5 KiB
C#
50 lines
2.5 KiB
C#
namespace ZuneDBApi.Abstractions
|
|
{
|
|
// TODO: back this with a real persistent store (e.g. a JSON/INI file under
|
|
// XDG_CONFIG_HOME) once non-Windows platform support is prioritized; for now
|
|
// values only live for the lifetime of the process, matching the previous
|
|
// no-op stub behavior except that values round-trip within a single run.
|
|
internal sealed class InMemoryRegistryProvider : IRegistryProvider
|
|
{
|
|
private readonly Dictionary<string, object> m_values = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
public bool GetBoolValue(string valueName, bool defaultValue) => Get(valueName, defaultValue);
|
|
public void SetBoolValue(string valueName, bool value) => Set(valueName, value);
|
|
|
|
public int GetIntValue(string valueName, int defaultValue) => Get(valueName, defaultValue);
|
|
public void SetIntValue(string valueName, int value) => Set(valueName, value);
|
|
|
|
public long GetInt64Value(string valueName, long defaultValue) => Get(valueName, defaultValue);
|
|
public void SetInt64Value(string valueName, long value) => Set(valueName, value);
|
|
|
|
public double GetDoubleValue(string valueName, double defaultValue) => Get(valueName, defaultValue);
|
|
public void SetDoubleValue(string valueName, double value) => Set(valueName, value);
|
|
|
|
public DateTime GetDateTimeValue(string valueName, DateTime defaultValue) => Get(valueName, defaultValue);
|
|
public void SetDateTimeValue(string valueName, DateTime value) => Set(valueName, value);
|
|
|
|
public string? GetStringValue(string valueName, string? defaultValue) => Get(valueName, defaultValue);
|
|
public void SetStringValue(string valueName, string value) => Set(valueName, value);
|
|
|
|
public IList<string>? GetStringListValue(string valueName) => Get<IList<string>?>(valueName, null);
|
|
public void SetStringListValue(string valueName, IList<string> value) => Set(valueName, value);
|
|
|
|
public byte[]? GetBinaryValue(string valueName) => Get<byte[]?>(valueName, null);
|
|
public void SetBinaryValue(string valueName, byte[] value) => Set(valueName, value);
|
|
|
|
private T Get<T>(string valueName, T defaultValue)
|
|
{
|
|
lock (m_values)
|
|
return m_values.TryGetValue(valueName, out object? stored) && stored is T typed ? typed : defaultValue;
|
|
}
|
|
|
|
private void Set(string valueName, object value)
|
|
{
|
|
lock (m_values)
|
|
m_values[valueName] = value;
|
|
}
|
|
|
|
public void Dispose() { }
|
|
}
|
|
}
|