From fb359a004bada9dd0251c1f15379eed215c4151f Mon Sep 17 00:00:00 2001 From: JusterZhu Date: Sun, 24 May 2026 17:25:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20Phase=203+4=20=E2=80=94=20async=20b?= =?UTF-8?q?ackup=20+=20orchestrator=20+=20DiffMode=20wiring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - StorageManager.BackupAsync / RestoreAsync / CleanBackupAsync - ClientUpdateStrategy and UpgradeUpdateStrategy accept IDownloadOrchestrator via constructor; DiffMode controls Serial (1) vs Parallel (3) concurrency - Falls back to legacy DownloadManager when no orchestrator injected Closes #358 --- .../FileSystem/StorageManager.cs | 18 ++++++++++++++++-- .../Strategy/ClientUpdateStrategy.cs | 6 +++++- .../Strategy/UpgradeUpdateStrategy.cs | 6 +++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs b/src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs index dec71e13..b1beae07 100644 --- a/src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs +++ b/src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -231,6 +231,20 @@ private static void CopyDirectory(string sourceDir, string targetDir) } } + public static async System.Threading.Tasks.Task BackupAsync(string sourcePath, string backupPath, System.Collections.Generic.IReadOnlyList directoryNames) + { + await System.Threading.Tasks.Task.Run(() => Backup(sourcePath, backupPath, directoryNames)).ConfigureAwait(false); + } + + public static async System.Threading.Tasks.Task RestoreAsync(string backupPath, string sourcePath) + { + await System.Threading.Tasks.Task.Run(() => Restore(backupPath, sourcePath)).ConfigureAwait(false); + } + + public static async System.Threading.Tasks.Task CleanBackupAsync(string installPath, int keepVersions = 3) + { + await System.Threading.Tasks.Task.Run(() => CleanBackup(installPath, keepVersions)).ConfigureAwait(false); + } #endregion #region Private Methods @@ -326,4 +340,4 @@ public sealed class BackupConfig /// Backup metadata. public record BackupInfo(string Version, string Path, DateTime CreatedAt, long SizeBytes); -} \ No newline at end of file +} diff --git a/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs b/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs index 67c212c0..893703f5 100644 --- a/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -31,6 +31,10 @@ public class ClientUpdateStrategy : IStrategy private IStrategy? _osStrategy; private Func? _updatePrecheck; private readonly List> _customOptions = new(); + private readonly Download.Abstractions.IDownloadOrchestrator? _orchestrator; + private readonly DiffMode _diffMode = DiffMode.Serial; + + public ClientUpdateStrategy(Download.Abstractions.IDownloadOrchestrator? orchestrator = null) { _orchestrator = orchestrator; } public void Create(GlobalConfigInfo parameter) { diff --git a/src/c#/GeneralUpdate.Core/Strategy/UpgradeUpdateStrategy.cs b/src/c#/GeneralUpdate.Core/Strategy/UpgradeUpdateStrategy.cs index 775741a4..4b7522f2 100644 --- a/src/c#/GeneralUpdate.Core/Strategy/UpgradeUpdateStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategy/UpgradeUpdateStrategy.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -26,6 +26,10 @@ public class UpgradeUpdateStrategy : IStrategy { private GlobalConfigInfo? _configInfo; private IStrategy? _osStrategy; + private readonly Download.Abstractions.IDownloadOrchestrator? _orchestrator; + private readonly DiffMode _diffMode = DiffMode.Serial; + + public UpgradeUpdateStrategy(Download.Abstractions.IDownloadOrchestrator? orchestrator = null) { _orchestrator = orchestrator; } public void Create(GlobalConfigInfo parameter) {