Skip to content

Commit

Permalink
rename DefaultKey to RootRegistryKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
clown committed Jul 26, 2022
1 parent d7c8843 commit 3c37719
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
21 changes: 11 additions & 10 deletions Libraries/Core/Sources/DataContract/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Cube.DataContract;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading;
using System.Xml;
using Cube.FileSystem;
using Microsoft.Win32;
Expand All @@ -41,10 +42,10 @@ public static class Proxy

/* --------------------------------------------------------------------- */
///
/// DefaultKey
/// RootRegistryKey
///
/// <summary>
/// Gets or sets the default registry subkey when serializing or
/// Gets or sets the root registry subkey when serializing or
/// deserializing the registry.
/// </summary>
///
Expand All @@ -54,10 +55,10 @@ public static class Proxy
/// </remarks>
///
/* --------------------------------------------------------------------- */
public static RegistryKey DefaultKey
public static RegistryKey RootRegistryKey
{
get => _defaultKey ??= Registry.CurrentUser.OpenSubKey("Software", true);
set => _defaultKey = value;
get => _root ??= Registry.CurrentUser.OpenSubKey("Software", true);
set => Interlocked.Exchange(ref _root, value)?.Dispose();
}

#endregion
Expand Down Expand Up @@ -88,7 +89,7 @@ public static void Serialize<T>(this Format format, string dest, T src)
IoEx.Save(dest, e => SerializeJson(e, src));
break;
case Format.Registry:
using (var e = DefaultKey.CreateSubKey(dest)) Serialize(e, src);
using (var e = RootRegistryKey.CreateSubKey(dest)) Serialize(e, src);
break;
}
}
Expand Down Expand Up @@ -166,7 +167,7 @@ public static T Deserialize<T>(this Format format, string src)
case Format.Json:
return IoEx.Load(src, e => (T)new DataContractJsonSerializer(typeof(T)).ReadObject(e));
case Format.Registry:
using (var e = DefaultKey.OpenSubKey(src, false)) return Deserialize<T>(e);
using (var e = RootRegistryKey.OpenSubKey(src, false)) return Deserialize<T>(e);
}
return default;
}
Expand Down Expand Up @@ -210,7 +211,7 @@ public static bool Exists(this Format format, string src)
switch (format)
{
case Format.Registry:
using (var e = DefaultKey.OpenSubKey(src, false)) return e is not null;
using (var e = RootRegistryKey.OpenSubKey(src, false)) return e is not null;
default:
return Io.Exists(src);
}
Expand All @@ -233,7 +234,7 @@ public static void Delete(this Format format, string src)
switch (format)
{
case Format.Registry:
DefaultKey.DeleteSubKeyTree(src, false);
RootRegistryKey.DeleteSubKeyTree(src, false);
break;
default:
if (Io.Exists(src)) Io.Delete(src);
Expand All @@ -244,6 +245,6 @@ public static void Delete(this Format format, string src)
#endregion

#region Fields
private static RegistryKey _defaultKey;
private static RegistryKey _root;
#endregion
}
6 changes: 3 additions & 3 deletions Tests/FileSystem/Sources/Internal/RegistryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RegistryFixture : FileFixture
///
/* --------------------------------------------------------------------- */
protected RegistryKey CreateSubKey(string subkey) =>
Proxy.DefaultKey.CreateSubKey(GetKeyName(subkey));
Proxy.RootRegistryKey.CreateSubKey(GetKeyName(subkey));

/* --------------------------------------------------------------------- */
///
Expand All @@ -107,7 +107,7 @@ protected RegistryKey CreateSubKey(string subkey) =>
///
/* --------------------------------------------------------------------- */
protected RegistryKey OpenSubKey(string subkey) =>
Proxy.DefaultKey.OpenSubKey(GetKeyName(subkey), false);
Proxy.RootRegistryKey.OpenSubKey(GetKeyName(subkey), false);

/* --------------------------------------------------------------------- */
///
Expand Down Expand Up @@ -161,7 +161,7 @@ protected virtual void Setup()
///
/* --------------------------------------------------------------------- */
[TearDown]
protected override void Teardown() => Proxy.DefaultKey.DeleteSubKeyTree(Shared, false);
protected override void Teardown() => Proxy.RootRegistryKey.DeleteSubKeyTree(Shared, false);

#endregion
}

0 comments on commit 3c37719

Please sign in to comment.