Cleanup old version service for maintenance.

This commit is contained in:
Burak Kaan Köse
2026-04-05 15:19:14 +02:00
parent ac78cf2b78
commit 32d677025d
5 changed files with 94 additions and 7 deletions
+4
View File
@@ -302,6 +302,7 @@ public partial class App : WinoApplication,
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IMailDialogService, DialogService>();
services.AddSingleton<IAiActionOptionsService, AiActionOptionsService>();
services.AddSingleton<ReleaseLocalAccountDataCleanupService>();
services.AddTransient<IProviderService, ProviderService>();
services.AddSingleton<IAuthenticatorConfig, MailAuthenticatorConfiguration>();
services.AddSingleton<IAccountCalendarStateService, AccountCalendarStateService>();
@@ -385,6 +386,9 @@ public partial class App : WinoApplication,
// Always register notification callbacks.
TryRegisterAppNotifications();
await Services.GetRequiredService<ReleaseLocalAccountDataCleanupService>()
.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.
@@ -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<ReleaseLocalAccountDataCleanupService>();
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<string>
{
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);
}
}
}
@@ -3,9 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Wino.Mail.WinUI.Controls">
<Style
BasedOn="{StaticResource DefaultCommandBarStyle}"
TargetType="controls:OperationCommandBar">
<Style BasedOn="{StaticResource DefaultCommandBarStyle}" TargetType="controls:OperationCommandBar">
<Setter Property="DefaultLabelPosition" Value="Right" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="IsDynamicOverflowEnabled" Value="True" />
@@ -12,7 +12,6 @@
<StackPanel
Padding="36,28,36,36"
HorizontalAlignment="Stretch"
Spacing="24">
<!-- Page Header -->
+1 -3
View File
@@ -92,9 +92,7 @@
Grid.Column="1"
VerticalAlignment="Center"
Spacing="8">
<TextBlock
Text="{x:Bind Title, Mode=OneTime}"
TextWrapping="WrapWholeWords" />
<TextBlock Text="{x:Bind Title, Mode=OneTime}" TextWrapping="WrapWholeWords" />
<TextBlock
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Text="{x:Bind Description, Mode=OneTime}"