Cleanup old version service for maintenance.
This commit is contained in:
@@ -302,6 +302,7 @@ public partial class App : WinoApplication,
|
|||||||
services.AddSingleton<INavigationService, NavigationService>();
|
services.AddSingleton<INavigationService, NavigationService>();
|
||||||
services.AddSingleton<IMailDialogService, DialogService>();
|
services.AddSingleton<IMailDialogService, DialogService>();
|
||||||
services.AddSingleton<IAiActionOptionsService, AiActionOptionsService>();
|
services.AddSingleton<IAiActionOptionsService, AiActionOptionsService>();
|
||||||
|
services.AddSingleton<ReleaseLocalAccountDataCleanupService>();
|
||||||
services.AddTransient<IProviderService, ProviderService>();
|
services.AddTransient<IProviderService, ProviderService>();
|
||||||
services.AddSingleton<IAuthenticatorConfig, MailAuthenticatorConfiguration>();
|
services.AddSingleton<IAuthenticatorConfig, MailAuthenticatorConfiguration>();
|
||||||
services.AddSingleton<IAccountCalendarStateService, AccountCalendarStateService>();
|
services.AddSingleton<IAccountCalendarStateService, AccountCalendarStateService>();
|
||||||
@@ -385,6 +386,9 @@ public partial class App : WinoApplication,
|
|||||||
// Always register notification callbacks.
|
// Always register notification callbacks.
|
||||||
TryRegisterAppNotifications();
|
TryRegisterAppNotifications();
|
||||||
|
|
||||||
|
await Services.GetRequiredService<ReleaseLocalAccountDataCleanupService>()
|
||||||
|
.RunIfNeededAsync();
|
||||||
|
|
||||||
// Initialize required services regardless of launch activation type.
|
// Initialize required services regardless of launch activation type.
|
||||||
// All activation scenarios require these services to be ready.
|
// All activation scenarios require these services to be ready.
|
||||||
// Note: Theme service is initialized separately after window creation.
|
// 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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:controls="using:Wino.Mail.WinUI.Controls">
|
xmlns:controls="using:Wino.Mail.WinUI.Controls">
|
||||||
|
|
||||||
<Style
|
<Style BasedOn="{StaticResource DefaultCommandBarStyle}" TargetType="controls:OperationCommandBar">
|
||||||
BasedOn="{StaticResource DefaultCommandBarStyle}"
|
|
||||||
TargetType="controls:OperationCommandBar">
|
|
||||||
<Setter Property="DefaultLabelPosition" Value="Right" />
|
<Setter Property="DefaultLabelPosition" Value="Right" />
|
||||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||||
<Setter Property="IsDynamicOverflowEnabled" Value="True" />
|
<Setter Property="IsDynamicOverflowEnabled" Value="True" />
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
<StackPanel
|
<StackPanel
|
||||||
Padding="36,28,36,36"
|
Padding="36,28,36,36"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
|
|
||||||
Spacing="24">
|
Spacing="24">
|
||||||
|
|
||||||
<!-- Page Header -->
|
<!-- Page Header -->
|
||||||
|
|||||||
@@ -92,9 +92,7 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Spacing="8">
|
Spacing="8">
|
||||||
<TextBlock
|
<TextBlock Text="{x:Bind Title, Mode=OneTime}" TextWrapping="WrapWholeWords" />
|
||||||
Text="{x:Bind Title, Mode=OneTime}"
|
|
||||||
TextWrapping="WrapWholeWords" />
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||||
Text="{x:Bind Description, Mode=OneTime}"
|
Text="{x:Bind Description, Mode=OneTime}"
|
||||||
|
|||||||
Reference in New Issue
Block a user