From 404542d9730b05dc54b83483f960d1c3170841e9 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Mon, 20 Feb 2023 02:56:39 +0200 Subject: [PATCH] Replace Tyrrrz.Settings with Cogwheel --- .../DiscordChatExporter.Gui.csproj | 2 +- .../Services/SettingsService.cs | 18 ++++++++++++------ .../Components/DashboardViewModel.cs | 4 +--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj index 9fa9269..a0c9dd0 100644 --- a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj +++ b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj @@ -13,6 +13,7 @@ + @@ -21,7 +22,6 @@ - diff --git a/DiscordChatExporter.Gui/Services/SettingsService.cs b/DiscordChatExporter.Gui/Services/SettingsService.cs index 9e8d3de..07d718f 100644 --- a/DiscordChatExporter.Gui/Services/SettingsService.cs +++ b/DiscordChatExporter.Gui/Services/SettingsService.cs @@ -1,11 +1,12 @@ using System; +using System.IO; +using Cogwheel; using DiscordChatExporter.Core.Exporting; using Microsoft.Win32; -using Tyrrrz.Settings; namespace DiscordChatExporter.Gui.Services; -public partial class SettingsService : SettingsManager +public partial class SettingsService : SettingsBase { public bool IsUkraineSupportMessageEnabled { get; set; } = true; @@ -38,13 +39,18 @@ public partial class SettingsService : SettingsManager public string? LastAssetsDirPath { get; set; } public SettingsService() + : base(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat")) { - Configuration.StorageSpace = StorageSpace.Instance; - Configuration.SubDirectoryPath = ""; - Configuration.FileName = "Settings.dat"; } - public bool ShouldSerializeLastToken() => IsTokenPersisted; + public override void Save() + { + // Clear token if it's not supposed to be persisted + if (!IsTokenPersisted) + LastToken = null; + + base.Save(); + } } public partial class SettingsService diff --git a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs index ffc5b02..4044d5c 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs @@ -71,10 +71,8 @@ public class DashboardViewModel : PropertyChangedBase public void OnViewLoaded() { - if (_settingsService.LastToken is not null) - { + if (!string.IsNullOrWhiteSpace(_settingsService.LastToken)) Token = _settingsService.LastToken; - } } public async void ShowSettings()