Files
Libation/Source/LibationFileManager/Configuration.cs
MBucari 4c5fdf05f5 Add "Download split by chapters" context menu item (#1436)
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.
2025-12-01 23:23:47 -07:00

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
}
}