Refactor using c# 12 features

This commit is contained in:
Tyrrrz
2023-12-10 22:32:45 +02:00
parent 174b92cbb0
commit 619fe9ccf7
30 changed files with 155 additions and 290 deletions

View File

@@ -8,7 +8,8 @@ using Microsoft.Win32;
namespace DiscordChatExporter.Gui.Services;
public partial class SettingsService : SettingsBase
public partial class SettingsService()
: SettingsBase(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat"))
{
public bool IsUkraineSupportMessageEnabled { get; set; } = true;
@@ -44,9 +45,6 @@ public partial class SettingsService : SettingsBase
public string? LastAssetsDirPath { get; set; }
public SettingsService()
: base(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat")) { }
public override void Save()
{
// Clear the token if it's not supposed to be persisted

View File

@@ -6,27 +6,20 @@ using Onova.Services;
namespace DiscordChatExporter.Gui.Services;
public class UpdateService : IDisposable
public class UpdateService(SettingsService settingsService) : IDisposable
{
private readonly IUpdateManager _updateManager = new UpdateManager(
new GithubPackageResolver("Tyrrrz", "DiscordChatExporter", "DiscordChatExporter.zip"),
new ZipPackageExtractor()
);
private readonly SettingsService _settingsService;
private Version? _updateVersion;
private bool _updatePrepared;
private bool _updaterLaunched;
public UpdateService(SettingsService settingsService)
{
_settingsService = settingsService;
}
public async ValueTask<Version?> CheckForUpdatesAsync()
{
if (!_settingsService.IsAutoUpdateEnabled)
if (!settingsService.IsAutoUpdateEnabled)
return null;
var check = await _updateManager.CheckForUpdatesAsync();
@@ -35,7 +28,7 @@ public class UpdateService : IDisposable
public async ValueTask PrepareUpdateAsync(Version version)
{
if (!_settingsService.IsAutoUpdateEnabled)
if (!settingsService.IsAutoUpdateEnabled)
return;
try
@@ -55,7 +48,7 @@ public class UpdateService : IDisposable
public void FinalizeUpdate(bool needRestart)
{
if (!_settingsService.IsAutoUpdateEnabled)
if (!settingsService.IsAutoUpdateEnabled)
return;
if (_updateVersion is null || !_updatePrepared || _updaterLaunched)