Skip to content

Commit 45ef638

Browse files
author
Aytackydln
committed
refactor ObjectSettings<T>.SettingsSavePath method
1 parent e38feb9 commit 45ef638

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

Project-Aurora/Project-Aurora/Profiles/Application.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class Application : ObjectSettings<ApplicationSettings>, ILightEvent, INo
4848
#endregion
4949

5050
#region Internal Properties
51+
protected override string SettingsSavePath => Path.Combine(GetProfileFolderPath(), "settings.json");
5152
protected ImageSource? icon;
5253
public virtual ImageSource Icon => icon ??= new BitmapImage(new Uri(GetBaseUri(), @"/AuroraRgb;component/" + Config.IconURI));
5354

@@ -72,7 +73,6 @@ private static Uri GetBaseUri()
7273
protected Application(LightEventConfig config)
7374
{
7475
Config = config;
75-
SettingsSavePath = Path.Combine(GetProfileFolderPath(), "settings.json");
7676
config.Application = this;
7777
config.Event.ResetGameState(config.GameStateType);
7878
Profiles = new ObservableCollection<ApplicationProfile>();
@@ -678,7 +678,10 @@ protected override async Task LoadSettings(Type settingsType)
678678
{
679679
await base.LoadSettings(settingsType);
680680

681-
Settings.PropertyChanged += OnSettingsPropertyChanged;
681+
if (Settings != null)
682+
{
683+
Settings.PropertyChanged += OnSettingsPropertyChanged;
684+
}
682685
}
683686

684687
private async void OnSettingsPropertyChanged(object? sender, PropertyChangedEventArgs e)

Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
namespace AuroraRgb.Settings;
77

8-
public class ObjectSettings<T>
8+
public abstract class ObjectSettings<T>
99
{
10-
protected string? SettingsSavePath { get; set; }
11-
public T? Settings { get; protected set; }
10+
protected abstract string SettingsSavePath { get; }
11+
public T? Settings { get; private set; }
1212

1313
public async Task SaveSettings()
1414
{
@@ -17,11 +17,6 @@ public async Task SaveSettings()
1717

1818
protected async Task SaveSettings(Type settingsType)
1919
{
20-
if (SettingsSavePath == null)
21-
{
22-
return;
23-
}
24-
2520
if (Settings == null) {
2621
Settings = (T)Activator.CreateInstance(settingsType);
2722
SettingsCreateHook();
@@ -58,12 +53,6 @@ protected async Task LoadSettings()
5853

5954
protected virtual async Task LoadSettings(Type settingsType)
6055
{
61-
if (SettingsSavePath == null)
62-
{
63-
Global.logger.Warning("Type {Type} does not have a setting save path!", GetType());
64-
return;
65-
}
66-
6756
if (File.Exists(SettingsSavePath))
6857
{
6958
try

Project-Aurora/Project-Aurora/Settings/PluginManager.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ public class PluginManager : ObjectSettings<PluginManagerSettings>, IPluginHost
9494
public const string PluginDirectory = "Plugins";
9595

9696
public Dictionary<string, IPlugin> Plugins { get; set; } = new();
97-
98-
public PluginManager()
99-
{
100-
SettingsSavePath = Path.Combine(Global.AppDataDirectory, "PluginSettings.json");
101-
}
102-
97+
protected override string SettingsSavePath => Path.Combine(Global.AppDataDirectory, "PluginSettings.json");
10398
public bool Initialized { get; protected set; }
10499

105100
public async Task<bool> Initialize(CancellationToken cancellationToken)

0 commit comments

Comments
 (0)