Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public async Task<IReadOnlyList<DownloadAsset>> ListAsync(CancellationToken toke
var mainResp = await VersionService.Validate(
_updateUrl, _clientVersion, AppType.ClientApp,
_appSecretKey, _platform, _productId,
_scheme, _token);
_scheme, _token, token);

var upgradeResp = await VersionService.Validate(
_updateUrl, _upgradeClientVersion ?? _clientVersion, AppType.UpgradeApp,
_appSecretKey, _platform, _productId,
_scheme, _token);
_scheme, _token, token);

var assets = new List<DownloadAsset>();

Expand Down
59 changes: 59 additions & 0 deletions src/c#/GeneralUpdate.Core/FileSystem/IStorageManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace GeneralUpdate.Core.FileSystem;

/// <summary>
/// Storage management interface — backup, restore, and cleanup operations.
/// Instance-based for dependency injection with blacklist matcher support.
/// </summary>
public interface IStorageManager
{
/// <summary>Backup source directory to destination.</summary>
Task BackupAsync(string source, string dest, IReadOnlyList<string> skipDirectories, CancellationToken token = default);

/// <summary>Restore from backup to installation path.</summary>
Task RestoreAsync(string backupDir, string installPath, CancellationToken token = default);

/// <summary>Clean old backups, keeping only the N most recent versions.</summary>
Task CleanBackupAsync(string installPath, int keepVersions = 3, CancellationToken token = default);

/// <summary>List all backups with metadata.</summary>
IReadOnlyList<BackupInfo> ListBackups(string installPath);
}

/// <summary>
/// Default storage manager implementation wrapping the static StorageManager.
/// </summary>
public class DefaultStorageManager : IStorageManager
{
private readonly IBlackListMatcher? _matcher;

public DefaultStorageManager(IBlackListMatcher? matcher = null)
{
_matcher = matcher;
}

public Task BackupAsync(string source, string dest, IReadOnlyList<string> skipDirectories, CancellationToken token = default)
{
return StorageManager.BackupAsync(source, dest, skipDirectories);
}

public Task RestoreAsync(string backupDir, string installPath, CancellationToken token = default)
{
return StorageManager.RestoreAsync(backupDir, installPath);
}

public Task CleanBackupAsync(string installPath, int keepVersions = 3, CancellationToken token = default)
{
return StorageManager.CleanBackupAsync(installPath, keepVersions);
}

public IReadOnlyList<BackupInfo> ListBackups(string installPath)
{
return StorageManager.ListBackups(installPath);
}
}
10 changes: 5 additions & 5 deletions src/c#/GeneralUpdate.Core/Network/VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ public VersionService(IHttpAuthProvider? auth = null, TimeSpan? timeout = null,
}
private VersionService() { }

// Static API (backward-compatible)
// Static API (backward-compatible, CancellationToken optional)
public static Task Report(string url, int recordId, int status, int? type,
string scheme = null, string token = null)
string scheme = null, string token = null, CancellationToken ct = default)
{
var a = HttpAuthProviderFactory.Create(scheme, token, null);
return new VersionService(a).ReportAsync(url, recordId, status, type);
return new VersionService(a).ReportAsync(url, recordId, status, type, ct);
}

public static Task<VersionRespDTO> Validate(string url, string version,
int appType, string appKey, int platform, string productId,
string scheme = null, string token = null)
string scheme = null, string token = null, CancellationToken ct = default)
{
var a = HttpAuthProviderFactory.Create(scheme, token, appKey);
return new VersionService(a).ValidateAsync(url, version, appType, platform, productId);
return new VersionService(a).ValidateAsync(url, version, appType, platform, productId, ct);
}

private async Task ReportAsync(string url, int recordId, int status, int? type, CancellationToken t = default)
Expand Down
Loading