From 367d1d249ed627ab541f138fca9334737b2807f9 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 9 Aug 2024 19:21:31 +0200 Subject: [PATCH 1/2] SettingsManager - Add default property and made class non-static --- PCK-Studio/Internal/App/ApplicationScope.cs | 1 - PCK-Studio/Internal/App/SettingsManager.cs | 28 +++++++++++-------- .../Internal/Misc/RichPresenceClient.cs | 2 +- PCK-Studio/MainForm.cs | 4 +-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/PCK-Studio/Internal/App/ApplicationScope.cs b/PCK-Studio/Internal/App/ApplicationScope.cs index df66124b..19f7109e 100644 --- a/PCK-Studio/Internal/App/ApplicationScope.cs +++ b/PCK-Studio/Internal/App/ApplicationScope.cs @@ -45,7 +45,6 @@ namespace PckStudio.Internal.App _ = Tiles.ExperienceOrbImageList; _ = Tiles.MoonPhaseImageList; _ = Tiles.PaintingImageList; - SettingsManager.Initialize(); CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; Task.Run(GetContributors); } diff --git a/PCK-Studio/Internal/App/SettingsManager.cs b/PCK-Studio/Internal/App/SettingsManager.cs index 3636c51d..9cc7e1b2 100644 --- a/PCK-Studio/Internal/App/SettingsManager.cs +++ b/PCK-Studio/Internal/App/SettingsManager.cs @@ -23,21 +23,25 @@ using PckStudio.Properties; namespace PckStudio.Internal.App { - internal static class SettingsManager + internal sealed class SettingsManager { - private static Dictionary> _registery = new Dictionary>(); + public static SettingsManager Default { get; } = new SettingsManager(Settings.Default); - private static object _newValue = null; + private Dictionary> _registery = new Dictionary>(); - internal static void Initialize() + private object _newValue = null; + private SettingsBase _settings = null; + + internal SettingsManager(ApplicationSettingsBase settings) { - Settings.Default.PropertyChanged += PropertyChangedHandler; - Settings.Default.SettingChanging += SettingChangingHandler; + _settings = settings; + settings.PropertyChanged += PropertyChangedHandler; + settings.SettingChanging += SettingChangingHandler; } - internal static bool RegisterPropertyChangedCallback(string propertyName, Action callback) + internal bool RegisterPropertyChangedCallback(string propertyName, Action callback) { - Type propertyType = Settings.Default[propertyName].GetType(); + Type propertyType = _settings[propertyName].GetType(); if (!propertyType.Equals(typeof(TSettingsType))) { return false; @@ -45,12 +49,12 @@ namespace PckStudio.Internal.App return RegisterPropertyChangedCallback(propertyName, delegate (object obj) { callback((TSettingsType)obj); }); } - internal static bool RegisterPropertyChangedCallback(string propertyName, Action callback) + internal bool RegisterPropertyChangedCallback(string propertyName, Action callback) { return RegisterPropertyChangedCallback(propertyName, delegate (object _) { callback(); }); } - private static bool RegisterPropertyChangedCallback(string propertyName, Action callback) + private bool RegisterPropertyChangedCallback(string propertyName, Action callback) { if (_registery.ContainsKey(propertyName)) return false; @@ -58,7 +62,7 @@ namespace PckStudio.Internal.App return true; } - private static void PropertyChangedHandler(object sender, PropertyChangedEventArgs e) + private void PropertyChangedHandler(object sender, PropertyChangedEventArgs e) { if (_registery.ContainsKey(e.PropertyName)) { @@ -67,7 +71,7 @@ namespace PckStudio.Internal.App } } - private static void SettingChangingHandler(object sender, SettingChangingEventArgs e) + private void SettingChangingHandler(object sender, SettingChangingEventArgs e) { if (_registery.ContainsKey(e.SettingName)) { diff --git a/PCK-Studio/Internal/Misc/RichPresenceClient.cs b/PCK-Studio/Internal/Misc/RichPresenceClient.cs index 94a482e1..a9590095 100644 --- a/PCK-Studio/Internal/Misc/RichPresenceClient.cs +++ b/PCK-Studio/Internal/Misc/RichPresenceClient.cs @@ -43,7 +43,7 @@ namespace PckStudio.Internal.Misc { Client.Initialize(); } - SettingsManager.RegisterPropertyChangedCallback(nameof(Settings.Default.ShowRichPresence), state => + SettingsManager.Default.RegisterPropertyChangedCallback(nameof(Settings.Default.ShowRichPresence), state => { if (state) { diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 48397756..888355e3 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -162,11 +162,11 @@ namespace PckStudio private void MainForm_Load(object sender, EventArgs e) { - SettingsManager.RegisterPropertyChangedCallback(nameof(Settings.Default.UseLittleEndianAsDefault), state => + SettingsManager.Default.RegisterPropertyChangedCallback(nameof(Settings.Default.UseLittleEndianAsDefault), state => { LittleEndianCheckBox.Checked = state; }); - SettingsManager.RegisterPropertyChangedCallback(nameof(Settings.Default.LoadSubPcks), () => + SettingsManager.Default.RegisterPropertyChangedCallback(nameof(Settings.Default.LoadSubPcks), () => { if (currentPCK is not null) { From 9af1db72d4dd2174a1c9dfcf365ab73a21db375c Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 9 Aug 2024 19:22:56 +0200 Subject: [PATCH 2/2] Update OMI submodule ref --- Vendor/OMI-Lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vendor/OMI-Lib b/Vendor/OMI-Lib index 55b084f4..02d37596 160000 --- a/Vendor/OMI-Lib +++ b/Vendor/OMI-Lib @@ -1 +1 @@ -Subproject commit 55b084f40e32e1427c12146fa35fa0525273a696 +Subproject commit 02d37596d071f8fa7b0fb98f6d7c989c7a98e774