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
2 changes: 1 addition & 1 deletion src/Hub/Samples/BowlSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Hub.Samples;

public class BowlSample : ISample
{
public int Index => 6;
public int Index => 7;
public string Name => "进程守护 — 崩溃监控·Dump导出";
public bool RequiresServer => false;
public string[] CleanPaths => Array.Empty<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/CompleteUpdateSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Hub.Samples;

public class CompleteUpdateSample : ISample
{
public int Index => 1;
public int Index => 2;
public string Name => "完整更新 — 版本发现→下载→应用";
public bool RequiresServer => true;
public string[] CleanPaths => new[] {
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/CompressSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Hub.Samples;

public class CompressSample : ISample
{
public int Index => 9;
public int Index => 10;
public string Name => "压缩工具 — 压缩·解压·校验";
public bool RequiresServer => false;
public string[] CleanPaths => new[] { Path.Combine(Path.GetTempPath(), "compress_demo") };
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/DifferentialSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Hub.Samples;

public class DifferentialSample : ISample
{
public int Index => 4;
public int Index => 5;
public string Name => "二进制差分 — 生成·应用·校验";
public bool RequiresServer => false;
public string[] CleanPaths => new[] {
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/ExtensionSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Hub.Samples;

public class ExtensionSample : ISample
{
public int Index => 7;
public int Index => 8;
public string Name => "插件系统 — 安装·管理·兼容性";
public bool RequiresServer => false;
public string[] CleanPaths => new[] { "{BaseDir}/extensions" };
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/ImDiskQuickInstallSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Hub.Samples;
/// </summary>
public class ImDiskQuickInstallSample : ISample
{
public int Index => 8;
public int Index => 9;
public string Name => "Driver Update";
public bool RequiresServer => false;
public string[] CleanPaths => Array.Empty<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/OssSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Hub.Samples;

public class OssSample : ISample
{
public int Index => 3;
public int Index => 4;
public string Name => "OSS 模式 — 对象存储更新";
public bool RequiresServer => true;
public string[] CleanPaths => new[] {
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/PushSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Hub.Samples;

public class PushSample : ISample
{
public int Index => 5;
public int Index => 6;
public string Name => "SignalR 推送 — 实时消息接收";
public bool RequiresServer => false;
public string[] CleanPaths => Array.Empty<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Samples/SilentUpdateSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Hub.Samples;

public class SilentUpdateSample : ISample
{
public int Index => 2;
public int Index => 3;
public string Name => "静默更新 — 后台轮询·退出前准备";
public bool RequiresServer => true;
public string[] CleanPaths => new[] {
Expand Down
118 changes: 118 additions & 0 deletions src/Hub/Samples/StandardUpdateSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using GeneralUpdate.Core;
using GeneralUpdate.Core.Configuration;
using GeneralUpdate.Core.Download;
using GeneralUpdate.Core.Event;

namespace Hub.Samples;

/// <summary>
/// 标准更新流程 — 最简化的生产级集成方式。
/// 展示从配置到执行的完整链路,不包含模拟数据或文件操作。
/// </summary>
/// <remarks>
/// 相比 <see cref="CompleteUpdateSample"/>,本示例省略了模拟应用的创建和
/// 更新后的文件遍历比对,聚焦于 GeneralUpdateBootstrap 的核心配置模式。
/// </remarks>
public class StandardUpdateSample : ISample
{
public int Index => 1;
public string Name => "标准更新流程 — Bootstrap·配置·执行";
public bool RequiresServer => true;
public string[] CleanPaths => Array.Empty<string>();

public async Task RunAsync(AppConfig config, CancellationToken ct)
{
Console.WriteLine();
Console.WriteLine("══ 标准更新流程 (v10.5.0-beta.6) ══");

// ════════════════════════════════════════════════════════════════
// 1. 组装请求参数
// ════════════════════════════════════════════════════════════════
var request = new UpdateRequest
{
UpdateUrl = $"{config.ServerUrl}/Upgrade/Verification",
ReportUrl = $"{config.ServerUrl}/Upgrade/Report",
AppSecretKey = config.AppSecretKey,
InstallPath = AppDomain.CurrentDomain.BaseDirectory,
UpdatePath = AppDomain.CurrentDomain.BaseDirectory,
ClientVersion = config.ClientVersion,
MainAppName = config.MainAppName,
UpdateAppName = config.UpgradeAppName,
ProductId = config.ProductId
};

Console.WriteLine();
Console.WriteLine("══ 配置 ══");
Console.WriteLine($" Server: {request.UpdateUrl}");
Console.WriteLine($" Version: {request.ClientVersion}");
Console.WriteLine($" AppKey: {request.AppSecretKey?[..Math.Min(8, request.AppSecretKey?.Length ?? 0)]}...");

// ════════════════════════════════════════════════════════════════
// 2. 构建 Bootstrap
// ════════════════════════════════════════════════════════════════
Console.WriteLine();
Console.WriteLine("══ 初始化 GeneralUpdateBootstrap ══");

var bootstrap = new GeneralUpdateBootstrap()

// — 必要:请求配置 —
.SetConfig(request)

// — 必要:指定应用类型(Client=主应用, Upgrade=升级器) —
.SetOption(Option.AppType, AppType.Client)

// — 必要:版本发现事件 —
.AddListenerUpdateInfo((_, e) =>
{
var count = e.Info?.Body?.Count ?? 0;
// 服务端可能在多个版本中返回 full + chain 包供客户端选择
// 客户端会按 PackageType 自动排序:full 优先
Console.WriteLine($" [版本发现] 找到 {count} 个可用更新");
})

// — 可选:下载统计(多文件并行) —
.AddListenerMultiDownloadStatistics((_, e) =>
{
Console.Write($"\r [下载] {e.BytesReceived}/{e.TotalBytesToReceive} bytes ({e.ProgressPercentage:F0}%) {e.Speed}");
})

// — 可选:下载完成 —
.AddListenerMultiDownloadCompleted((_, e) =>
{
Console.WriteLine();
Console.WriteLine($" [下载完成] {(e.IsCompleted ? "✓" : "✗ 存在失败")}");
})

// — 可选:单文件进度 —
.AddListenerProgress((_, e) =>
{
if (e.Progress is { } p)
Console.WriteLine($" {p.AssetName}: {p.Percentage:F0}% ({p.Status})");
})

// — 可选:异常通知 —
.AddListenerException((_, e) =>
{
Console.WriteLine($" [异常] {e.Message}");
});

// ════════════════════════════════════════════════════════════════
// 3. 执行更新
// ════════════════════════════════════════════════════════════════
Console.WriteLine();
Console.WriteLine("══ 启动更新 (LaunchAsync) ══");
Console.WriteLine(" 流程: 版本发现 → 下载 → 解压 → 备份旧版本 → 应用新版本");

try
{
await bootstrap.LaunchAsync();
Console.WriteLine();
Console.WriteLine("══ 更新完成 ✓ ══");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine($"══ 更新失败: {ex.Message} ══");
}
}
}
9 changes: 2 additions & 7 deletions src/Server/DTOs/VerificationResultDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ public record VerificationResultDTO
public bool? IsFreeze { get; set; }

/// <summary>
/// 是否为跨版本升级包
/// 包类型: 0=Unspecified, 1=Chain(差分), 2=Full(完整包), 3=Driver
/// </summary>
Comment on lines 75 to 77
public bool? IsCrossVersion { get; set; }

/// <summary>
/// 跨版本升级的源版本号
/// </summary>
public string? FromVersion { get; set; }
public int PackageType { get; set; }
}
15 changes: 8 additions & 7 deletions src/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
return true;
})
.OrderByDescending(v => new Version(v.Version!))
.ThenBy(v => v.IsCrossVersion == true ? 1 : 0)
.ThenBy(v => v.PackageType == 1 ? 1 : 0)
.ToList();

if (available.Count == 0)
Expand All @@ -80,14 +80,13 @@
Version = v.Version, AppType = v.AppType, Platform = v.Platform,
ProductId = v.ProductId, IsForcibly = v.IsForcibly,
Format = v.Format ?? ".zip", Size = v.Size, IsFreeze = v.IsFreeze,
IsCrossVersion = v.IsCrossVersion ?? false,
FromVersion = v.FromVersion
PackageType = v.PackageType,
});
}

Console.WriteLine($"[Verification] Returning {results.Count} packages");
foreach (var r in results)
Console.WriteLine($" {r.Version} — {r.Name} ({(r.IsCrossVersion == true ? $"Cross {r.FromVersion} → {r.Version}" : "Full")})");
Console.WriteLine($" {r.Version} — {r.Name} ({(r.PackageType == 1 ? "Chain" : "Full")})");
Comment on lines 88 to +89

return Results.Ok(HttpResponseDTO<IEnumerable<VerificationResultDTO>>.Success(results,
$"Found {results.Count} update(s)."));
Expand Down Expand Up @@ -162,7 +161,7 @@
if (versionStore.Count > 0)
{
foreach (var v in versionStore.OrderBy(v => new Version(v.Version!)))
Console.WriteLine($" {v.Version,-12} AppType={v.AppType} {(v.IsCrossVersion == true ? $"Cross {v.FromVersion} → {v.Version}" : "Full")} {v.PacketName}");
Console.WriteLine($" {v.Version,-12} AppType={v.AppType} {(v.PackageType == 1 ? "Chain" : "Full")} {v.PacketName}");
Comment on lines 163 to +164
}
else
{
Expand Down Expand Up @@ -232,6 +231,8 @@ record VersionEntry
public string? Format { get; set; }
public long? Size { get; set; }
public bool? IsFreeze { get; set; }
public bool? IsCrossVersion { get; set; }
public string? FromVersion { get; set; }
/// <summary>
/// 包类型: 0=Unspecified, 1=Chain(差分), 2=Full(完整包), 3=Driver
/// </summary>
Comment on lines +234 to +236
public int PackageType { get; set; }
}
6 changes: 2 additions & 4 deletions src/Server/create_versions_json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ foreach ($p in $packages) {
Format = ".zip"
Size = $size
IsFreeze = $false
IsCrossVersion = $p.IsCross
FromVersion = $fromVer
ToVersion = $toVer
PackageType = $(if ($p.IsCross) { 1 } else { 2 })
}
$entries += $entry
$crossLabel = if ($p.IsCross) { "Cross $fromVer -> $toVer" } else { "Full" }
$crossLabel = if ($p.IsCross) { "Chain" } else { "Full" }
Write-Host " AppType=$($p.AppType) v$($p.Ver) [$crossLabel] $($file.Name) ($size bytes)"
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Server/finalize_packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ foreach ($f in $zipFiles) {
Format = ".zip"
Size = $size
IsFreeze = $false
IsCrossVersion = $isCross
FromVersion = $fromVer
ToVersion = $toVer
PackageType = $(if ($isCross) { 1 } else { 2 })
}
$entries += $entry
$crossLabel = if ($isCross) { "Cross $fromVer -> $toVer" } else { "Full" }
$crossLabel = if ($isCross) { "Chain" } else { "Full" }
Write-Host " AppType=$appType v$version [$crossLabel] $($f.Name) ($size bytes)"
}

Expand Down
26 changes: 10 additions & 16 deletions src/Server/generate_packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ function New-VersionEntry {
[string]$PacketName, [string]$Version, [int]$AppType,
[int]$Platform = 1, [string]$ProductId,
[bool]$IsForcibly = $false, [string]$Format = ".zip",
[bool]$IsCrossVersion = $false,
[string]$FromVersion = $null, [string]$ToVersion = $null,
[int]$PackageType = 2, # 1=Chain(差分), 2=Full(完整包)
[bool]$IsFreeze = $false
)
$zipPath = Join-Path $packagesDir "$PacketName.zip"
Expand All @@ -70,18 +69,15 @@ function New-VersionEntry {
Format = $Format
Size = $size
IsFreeze = $IsFreeze
IsCrossVersion = $(if ($IsCrossVersion) { $true } else { $false })
FromVersion = $FromVersion
ToVersion = $ToVersion
PackageType = $PackageType
}
}

function Add-ZipPackage {
param(
[string]$SourceDir, [string]$PacketName,
[string]$Version, [int]$AppType,
[bool]$IsCrossVersion = $false,
[string]$FromVersion = $null, [string]$ToVersion = $null
[int]$PackageType = 2 # 1=Chain(差分), 2=Full(完整包)
)
$zipPath = Join-Path $packagesDir "$PacketName.zip"
Write-Host " Creating: $PacketName.zip" -ForegroundColor Yellow
Expand All @@ -101,7 +97,7 @@ function Add-ZipPackage {

$entry = New-VersionEntry -PacketName $PacketName -Version $Version `
-AppType $AppType -ProductId $productId `
-IsCrossVersion $IsCrossVersion -FromVersion $FromVersion -ToVersion $ToVersion
-PackageType $PackageType
$script:allVersions += $entry
}

Expand All @@ -119,7 +115,7 @@ if ((Test-Path $clientV2) -and (Test-Path $clientV1)) {
# Full (VersionChain) package
$pkgName = "packet_${timestamp}_full_client_2.0.0.0"
Add-ZipPackage -SourceDir $clientV2 -PacketName $pkgName `
-Version "2.0.0.0" -AppType 1 -IsCrossVersion $false
-Version "2.0.0.0" -AppType 1 -PackageType 2

if (-not $FullOnly) {
# Differential (CrossVersion) package via PatchGenerator
Expand Down Expand Up @@ -156,9 +152,7 @@ if ((Test-Path $clientV2) -and (Test-Path $clientV1)) {
Format = $pe.Format
Size = $pe.Size
IsFreeze = $pe.IsFreeze
IsCrossVersion = $(if ($pe.IsCrossVersion) { $true } else { $false })
FromVersion = $pe.FromVersion
ToVersion = $pe.ToVersion
PackageType = $(if ($pe.PackageType) { $pe.PackageType } elseif ($pe.IsCrossVersion) { 1 } else { 2 })
}
Comment on lines 153 to 156
}
}
Expand Down Expand Up @@ -186,7 +180,7 @@ if ((Test-Path $upgradeV2) -and (Test-Path $upgradeV1)) {
# Full (VersionChain) package
$pkgName = "packet_${timestamp}_full_upgrade_2.0.0.0"
Add-ZipPackage -SourceDir $upgradeV2 -PacketName $pkgName `
-Version "2.0.0.0" -AppType 2 -IsCrossVersion $false
-Version "2.0.0.0" -AppType 2 -PackageType 2
}
else {
Write-Host " [Skip] content_upgrade directories not found: $upgradeV1 or $upgradeV2" -ForegroundColor Yellow
Expand All @@ -207,12 +201,12 @@ foreach ($ver in @("1.0.0.1", "1.0.0.2")) {
# Client full package
$pkgName = "packet_${timestamp}_full_client_$ver"
Add-ZipPackage -SourceDir $srcPath -PacketName $pkgName `
-Version $ver -AppType 1 -IsCrossVersion $false
-Version $ver -AppType 1 -PackageType 2

# Upgrade full package
$pkgName = "packet_${timestamp}_full_upgrade_$ver"
Add-ZipPackage -SourceDir $srcPath -PacketName $pkgName `
-Version $ver -AppType 2 -IsCrossVersion $false
-Version $ver -AppType 2 -PackageType 2
}
}

Expand All @@ -233,6 +227,6 @@ Write-Host " Metadata: $versionsJsonPath" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan

foreach ($v in $uniqueVersions) {
$cross = if ($v.IsCrossVersion) { "Cross $($v.FromVersion) → $($v.ToVersion)" } else { "Full" }
$cross = if ($v.PackageType -eq 1) { "Chain" } else { "Full" }
Write-Host " AppType=$($v.AppType) v$($v.Version) [$cross] $($v.PacketName)" -ForegroundColor Gray
}
Loading
Loading