From 32d677025db2fb35e56d9913afc4746c789e9039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sun, 5 Apr 2026 15:19:14 +0200 Subject: [PATCH] Cleanup old version service for maintenance. --- Wino.Mail.WinUI/App.xaml.cs | 4 + .../ReleaseLocalAccountDataCleanupService.cs | 88 +++++++++++++++++++ .../Styles/OperationCommandBar.xaml | 4 +- .../Views/Account/ImapCalDavSettingsPage.xaml | 1 - Wino.Mail.WinUI/Views/WelcomePageV2.xaml | 4 +- 5 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 Wino.Mail.WinUI/Services/ReleaseLocalAccountDataCleanupService.cs diff --git a/Wino.Mail.WinUI/App.xaml.cs b/Wino.Mail.WinUI/App.xaml.cs index 17003f24..06289cb2 100644 --- a/Wino.Mail.WinUI/App.xaml.cs +++ b/Wino.Mail.WinUI/App.xaml.cs @@ -302,6 +302,7 @@ public partial class App : WinoApplication, services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); @@ -385,6 +386,9 @@ public partial class App : WinoApplication, // Always register notification callbacks. TryRegisterAppNotifications(); + await Services.GetRequiredService() + .RunIfNeededAsync(); + // Initialize required services regardless of launch activation type. // All activation scenarios require these services to be ready. // Note: Theme service is initialized separately after window creation. diff --git a/Wino.Mail.WinUI/Services/ReleaseLocalAccountDataCleanupService.cs b/Wino.Mail.WinUI/Services/ReleaseLocalAccountDataCleanupService.cs new file mode 100644 index 00000000..44edc737 --- /dev/null +++ b/Wino.Mail.WinUI/Services/ReleaseLocalAccountDataCleanupService.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Serilog; +using Wino.Core.Domain.Interfaces; + +namespace Wino.Mail.WinUI.Services; + +public sealed class ReleaseLocalAccountDataCleanupService +{ + private const string CleanupCompletedSettingKey = "ReleaseLocalAccountDataCleanup_v1_Completed"; + private const string LegacyDatabaseFileName = "Wino180.db"; + + private readonly IConfigurationService _configurationService; + private readonly IApplicationConfiguration _applicationConfiguration; + private readonly ILogger _logger = Log.ForContext(); + + public ReleaseLocalAccountDataCleanupService(IConfigurationService configurationService, + IApplicationConfiguration applicationConfiguration) + { + _configurationService = configurationService; + _applicationConfiguration = applicationConfiguration; + } + + public async Task RunIfNeededAsync() + { + if (_configurationService.Get(CleanupCompletedSettingKey, false)) + return; + + var localFolderPath = _applicationConfiguration.ApplicationDataFolderPath; + var publisherPath = _applicationConfiguration.PublisherSharedFolderPath; + + if (string.IsNullOrWhiteSpace(localFolderPath) || !Directory.Exists(localFolderPath)) + { + _configurationService.Set(CleanupCompletedSettingKey, true); + return; + } + + var cleanupTargets = new List + { + Path.Combine(localFolderPath, "Mime"), + Path.Combine(localFolderPath, "contacts"), + Path.Combine(localFolderPath, "CalendarAttachments"), + Path.Combine(publisherPath, LegacyDatabaseFileName) + }; + + foreach (var targetPath in cleanupTargets) + { + await DeletePathIfExistsAsync(localFolderPath, targetPath).ConfigureAwait(false); + } + + _configurationService.Set(CleanupCompletedSettingKey, true); + _logger.Information("Completed one-time local account data cleanup for release migration."); + } + + private async Task DeletePathIfExistsAsync(string localFolderPath, string targetPath) + { + try + { + var fullTargetPath = Path.GetFullPath(targetPath); + var fullLocalFolderPath = Path.GetFullPath(localFolderPath); + + if (!fullTargetPath.StartsWith(fullLocalFolderPath, StringComparison.OrdinalIgnoreCase)) + { + _logger.Warning("Skipped startup cleanup for path outside local folder: {TargetPath}", fullTargetPath); + return; + } + + if (Directory.Exists(fullTargetPath)) + { + await Task.Run(() => Directory.Delete(fullTargetPath, recursive: true)).ConfigureAwait(false); + _logger.Information("Deleted legacy startup cleanup directory {TargetPath}", fullTargetPath); + return; + } + + if (File.Exists(fullTargetPath)) + { + File.Delete(fullTargetPath); + _logger.Information("Deleted legacy startup cleanup file {TargetPath}", fullTargetPath); + } + } + catch (Exception ex) + { + _logger.Warning(ex, "Failed to delete legacy startup cleanup path {TargetPath}", targetPath); + } + } +} diff --git a/Wino.Mail.WinUI/Styles/OperationCommandBar.xaml b/Wino.Mail.WinUI/Styles/OperationCommandBar.xaml index 63a5b4be..77fd8d25 100644 --- a/Wino.Mail.WinUI/Styles/OperationCommandBar.xaml +++ b/Wino.Mail.WinUI/Styles/OperationCommandBar.xaml @@ -3,9 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Wino.Mail.WinUI.Controls"> -