diff --git a/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs b/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs index 5ba001f95..bd11d31c7 100755 --- a/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs +++ b/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs @@ -190,8 +190,7 @@ private static IEnumerable EnumerateUserApps() return Array.Empty(); } - var additionals = new List(Directory.EnumerateDirectories(additionalProfilesPath)); - var userApps = from dir in additionals + var userApps = from dir in Directory.EnumerateDirectories(additionalProfilesPath) where File.Exists(Path.Combine(dir, "settings.json")) select Path.GetFileName(dir); diff --git a/Project-Aurora/Project-Aurora/Settings/ApplicationSettings.cs b/Project-Aurora/Project-Aurora/Settings/ApplicationSettings.cs index 29f8638ad..566cdef1e 100644 --- a/Project-Aurora/Project-Aurora/Settings/ApplicationSettings.cs +++ b/Project-Aurora/Project-Aurora/Settings/ApplicationSettings.cs @@ -1,8 +1,16 @@ using System.ComponentModel; using System.Text.Json.Serialization; +using AuroraRgb.Profiles.Generic_Application; namespace AuroraRgb.Settings; +[JsonSerializable(typeof(ApplicationSettings))] +[JsonSerializable(typeof(FirstTimeApplicationSettings))] +[JsonSerializable(typeof(NewJsonApplicationSettings))] +[JsonSerializable(typeof(GenericApplicationSettings))] +[JsonSourceGenerationOptions(WriteIndented = true)] +public partial class SettingsJsonContext : JsonSerializerContext; + public class ApplicationSettings : INotifyPropertyChanged { public bool IsEnabled { get; set; } = true; @@ -41,7 +49,6 @@ public override void CompleteInstallation() } } - public class NewJsonApplicationSettings : ApplicationSettings { public bool IsNewJsonInstalled { get; private set; } @@ -53,9 +60,9 @@ public NewJsonApplicationSettings() } [method: JsonConstructor] - public NewJsonApplicationSettings(bool isFirstTimeInstalled) + public NewJsonApplicationSettings(bool isNewJsonInstalled) { - IsNewJsonInstalled = isFirstTimeInstalled; + IsNewJsonInstalled = isNewJsonInstalled; } public override void CompleteInstallation() diff --git a/Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs b/Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs index dd6c912a2..70cab2555 100644 --- a/Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs +++ b/Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs @@ -1,11 +1,10 @@ using System; using System.IO; using System.Threading.Tasks; -using Newtonsoft.Json; +using JsonSerializer = System.Text.Json.JsonSerializer; namespace AuroraRgb.Settings; -[JsonObject(ItemTypeNameHandling = TypeNameHandling.None)] public class ObjectSettings { protected string? SettingsSavePath { get; set; } @@ -37,10 +36,8 @@ protected async Task SaveSettings(Type settingsType) { try { - await File.WriteAllTextAsync(SettingsSavePath, JsonConvert.SerializeObject(Settings, new JsonSerializerSettings - { - TypeNameHandling = TypeNameHandling.Auto, Formatting = Formatting.Indented - })); + var json = JsonSerializer.Serialize(Settings, Settings.GetType(), SettingsJsonContext.Default); + await File.WriteAllTextAsync(SettingsSavePath, json); return; } catch (IOException ioException) @@ -71,9 +68,12 @@ protected virtual async Task LoadSettings(Type settingsType) { try { - var json = await File.ReadAllTextAsync(SettingsSavePath); - var jsonSerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None }; - Settings = (T)JsonConvert.DeserializeObject(json, settingsType, jsonSerializerSettings); + string json; + using (var streamReader = new StreamReader(SettingsSavePath)) + { + json = await streamReader.ReadToEndAsync(); + } + Settings = (T)JsonSerializer.Deserialize(json, settingsType, SettingsJsonContext.Default); } catch (Exception exc) {