mirror of
https://github.com/rmcrackan/Libation.git
synced 2025-12-24 06:28:02 -05:00
All processables are now created with an instance of Configuration, and they use that instance's settings. Added Configuration.CreateEphemeralCopy() to clone Configuration without persistence.
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Dinah.Core;
|
|
using FileManager;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
#nullable enable
|
|
namespace LibationFileManager
|
|
{
|
|
public partial class Configuration : PropertyChangeFilter
|
|
{
|
|
|
|
#region singleton stuff
|
|
|
|
public static Configuration CreateMockInstance()
|
|
{
|
|
#if !DEBUG
|
|
if (!new StackTrace().GetFrames().Select(f => f.GetMethod()?.DeclaringType?.Assembly.GetName().Name).Any(f => f?.EndsWith(".Tests") ?? false))
|
|
throw new InvalidOperationException($"Can only mock {nameof(Configuration)} in Debug mode or in test assemblies.");
|
|
#endif
|
|
|
|
var mockInstance = new Configuration() { JsonBackedDictionary = new EphemeralDictionary() };
|
|
mockInstance.SetString("Light", "ThemeVariant");
|
|
Instance = mockInstance;
|
|
return mockInstance;
|
|
}
|
|
public static void RestoreSingletonInstance()
|
|
{
|
|
Instance = s_SingletonInstance;
|
|
}
|
|
private static readonly Configuration s_SingletonInstance = new();
|
|
public static Configuration Instance { get; private set; } = s_SingletonInstance;
|
|
public bool IsEphemeralInstance => JsonBackedDictionary is EphemeralDictionary;
|
|
|
|
public Configuration CreateEphemeralCopy()
|
|
{
|
|
var copy = new Configuration();
|
|
copy.LoadEphemeralSettings(Settings.GetJObject());
|
|
return copy;
|
|
}
|
|
|
|
private Configuration() { }
|
|
#endregion
|
|
}
|
|
}
|