diff --git a/Glamourer/Config/IgnoredMods.cs b/Glamourer/Config/IgnoredMods.cs new file mode 100644 index 0000000..d123108 --- /dev/null +++ b/Glamourer/Config/IgnoredMods.cs @@ -0,0 +1,84 @@ +using Glamourer.Services; +using Luna; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Glamourer.Config; + +public sealed class IgnoredMods : ConfigurationFile, IReadOnlySet +{ + public override int CurrentVersion + => 1; + + private readonly HashSet _ignoredMods = []; + + public IgnoredMods(SaveService saveService, MessageService messageService) + : base(saveService, messageService) + { + Load(); + } + + protected override void AddData(JsonTextWriter j) + { + j.WritePropertyName("IgnoredMods"); + j.WriteStartArray(); + foreach (var mod in _ignoredMods) + j.WriteValue(mod); + j.WriteEndArray(); + } + + protected override void LoadData(JObject j) + { + _ignoredMods.Clear(); + if (j["IgnoredMods"] is not JArray arr) + return; + + foreach (var value in arr.Values().OfType()) + _ignoredMods.Add(value); + } + + public override string ToFilePath(FilenameService fileNames) + => fileNames.IgnoredModsFile; + + public IEnumerator GetEnumerator() + => _ignoredMods.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + => GetEnumerator(); + + public int Count + => _ignoredMods.Count; + + public void Add(string mod) + { + if (_ignoredMods.Add(mod)) + Save(); + } + + public void Remove(string mod) + { + if (_ignoredMods.Remove(mod)) + Save(); + } + + public bool Contains(string item) + => _ignoredMods.Contains(item); + + public bool IsProperSubsetOf(IEnumerable other) + => _ignoredMods.IsProperSubsetOf(other); + + public bool IsProperSupersetOf(IEnumerable other) + => _ignoredMods.IsProperSupersetOf(other); + + public bool IsSubsetOf(IEnumerable other) + => _ignoredMods.IsSubsetOf(other); + + public bool IsSupersetOf(IEnumerable other) + => _ignoredMods.IsSupersetOf(other); + + public bool Overlaps(IEnumerable other) + => _ignoredMods.Overlaps(other); + + public bool SetEquals(IEnumerable other) + => _ignoredMods.SetEquals(other); +}