Skip to content

Commit 6fc2ba6

Browse files
authored
fix: update sample server to use PackageType (v10.5.0-beta.6 compat) (#131)
* fix: update server-side DTO and scripts to use PackageType instead of IsCrossVersion/FromVersion - Replace VerificationResultDTO.IsCrossVersion/FromVersion with PackageType - Replace Server internal VersionEntry record fields with PackageType - Update all 4 PowerShell scripts (generate, finalize, create_versions, gen_packages) - Update versions.json sample data - Update Program.cs verification/download logic - Keep PatchGenerator backward-compat parsing for old fields * feat: add StandardUpdateSample as the minimal production-grade bootstrap example - New StandardUpdateSample (Index=1): clean, minimal GeneralUpdateBootstrap config with all essential listeners, no mock files - Shift all existing sample indices by +1 to accommodate - StandardUpdateSample is the go-to reference for first-time integrators
1 parent b1811ec commit 6fc2ba6

17 files changed

Lines changed: 166 additions & 71 deletions

src/Hub/Samples/BowlSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Hub.Samples;
77

88
public class BowlSample : ISample
99
{
10-
public int Index => 6;
10+
public int Index => 7;
1111
public string Name => "进程守护 — 崩溃监控·Dump导出";
1212
public bool RequiresServer => false;
1313
public string[] CleanPaths => Array.Empty<string>();

src/Hub/Samples/CompleteUpdateSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Hub.Samples;
77

88
public class CompleteUpdateSample : ISample
99
{
10-
public int Index => 1;
10+
public int Index => 2;
1111
public string Name => "完整更新 — 版本发现→下载→应用";
1212
public bool RequiresServer => true;
1313
public string[] CleanPaths => new[] {

src/Hub/Samples/CompressSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Hub.Samples;
66

77
public class CompressSample : ISample
88
{
9-
public int Index => 9;
9+
public int Index => 10;
1010
public string Name => "压缩工具 — 压缩·解压·校验";
1111
public bool RequiresServer => false;
1212
public string[] CleanPaths => new[] { Path.Combine(Path.GetTempPath(), "compress_demo") };

src/Hub/Samples/DifferentialSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Hub.Samples;
77

88
public class DifferentialSample : ISample
99
{
10-
public int Index => 4;
10+
public int Index => 5;
1111
public string Name => "二进制差分 — 生成·应用·校验";
1212
public bool RequiresServer => false;
1313
public string[] CleanPaths => new[] {

src/Hub/Samples/ExtensionSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Hub.Samples;
99

1010
public class ExtensionSample : ISample
1111
{
12-
public int Index => 7;
12+
public int Index => 8;
1313
public string Name => "插件系统 — 安装·管理·兼容性";
1414
public bool RequiresServer => false;
1515
public string[] CleanPaths => new[] { "{BaseDir}/extensions" };

src/Hub/Samples/ImDiskQuickInstallSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Hub.Samples;
1414
/// </summary>
1515
public class ImDiskQuickInstallSample : ISample
1616
{
17-
public int Index => 8;
17+
public int Index => 9;
1818
public string Name => "Driver Update";
1919
public bool RequiresServer => false;
2020
public string[] CleanPaths => Array.Empty<string>();

src/Hub/Samples/OssSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Hub.Samples;
77

88
public class OssSample : ISample
99
{
10-
public int Index => 3;
10+
public int Index => 4;
1111
public string Name => "OSS 模式 — 对象存储更新";
1212
public bool RequiresServer => true;
1313
public string[] CleanPaths => new[] {

src/Hub/Samples/PushSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Hub.Samples;
88

99
public class PushSample : ISample
1010
{
11-
public int Index => 5;
11+
public int Index => 6;
1212
public string Name => "SignalR 推送 — 实时消息接收";
1313
public bool RequiresServer => false;
1414
public string[] CleanPaths => Array.Empty<string>();

src/Hub/Samples/SilentUpdateSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Hub.Samples;
77

88
public class SilentUpdateSample : ISample
99
{
10-
public int Index => 2;
10+
public int Index => 3;
1111
public string Name => "静默更新 — 后台轮询·退出前准备";
1212
public bool RequiresServer => true;
1313
public string[] CleanPaths => new[] {
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using GeneralUpdate.Core;
2+
using GeneralUpdate.Core.Configuration;
3+
using GeneralUpdate.Core.Download;
4+
using GeneralUpdate.Core.Event;
5+
6+
namespace Hub.Samples;
7+
8+
/// <summary>
9+
/// 标准更新流程 — 最简化的生产级集成方式。
10+
/// 展示从配置到执行的完整链路,不包含模拟数据或文件操作。
11+
/// </summary>
12+
/// <remarks>
13+
/// 相比 <see cref="CompleteUpdateSample"/>,本示例省略了模拟应用的创建和
14+
/// 更新后的文件遍历比对,聚焦于 GeneralUpdateBootstrap 的核心配置模式。
15+
/// </remarks>
16+
public class StandardUpdateSample : ISample
17+
{
18+
public int Index => 1;
19+
public string Name => "标准更新流程 — Bootstrap·配置·执行";
20+
public bool RequiresServer => true;
21+
public string[] CleanPaths => Array.Empty<string>();
22+
23+
public async Task RunAsync(AppConfig config, CancellationToken ct)
24+
{
25+
Console.WriteLine();
26+
Console.WriteLine("══ 标准更新流程 (v10.5.0-beta.6) ══");
27+
28+
// ════════════════════════════════════════════════════════════════
29+
// 1. 组装请求参数
30+
// ════════════════════════════════════════════════════════════════
31+
var request = new UpdateRequest
32+
{
33+
UpdateUrl = $"{config.ServerUrl}/Upgrade/Verification",
34+
ReportUrl = $"{config.ServerUrl}/Upgrade/Report",
35+
AppSecretKey = config.AppSecretKey,
36+
InstallPath = AppDomain.CurrentDomain.BaseDirectory,
37+
UpdatePath = AppDomain.CurrentDomain.BaseDirectory,
38+
ClientVersion = config.ClientVersion,
39+
MainAppName = config.MainAppName,
40+
UpdateAppName = config.UpgradeAppName,
41+
ProductId = config.ProductId
42+
};
43+
44+
Console.WriteLine();
45+
Console.WriteLine("══ 配置 ══");
46+
Console.WriteLine($" Server: {request.UpdateUrl}");
47+
Console.WriteLine($" Version: {request.ClientVersion}");
48+
Console.WriteLine($" AppKey: {request.AppSecretKey?[..Math.Min(8, request.AppSecretKey?.Length ?? 0)]}...");
49+
50+
// ════════════════════════════════════════════════════════════════
51+
// 2. 构建 Bootstrap
52+
// ════════════════════════════════════════════════════════════════
53+
Console.WriteLine();
54+
Console.WriteLine("══ 初始化 GeneralUpdateBootstrap ══");
55+
56+
var bootstrap = new GeneralUpdateBootstrap()
57+
58+
// — 必要:请求配置 —
59+
.SetConfig(request)
60+
61+
// — 必要:指定应用类型(Client=主应用, Upgrade=升级器) —
62+
.SetOption(Option.AppType, AppType.Client)
63+
64+
// — 必要:版本发现事件 —
65+
.AddListenerUpdateInfo((_, e) =>
66+
{
67+
var count = e.Info?.Body?.Count ?? 0;
68+
// 服务端可能在多个版本中返回 full + chain 包供客户端选择
69+
// 客户端会按 PackageType 自动排序:full 优先
70+
Console.WriteLine($" [版本发现] 找到 {count} 个可用更新");
71+
})
72+
73+
// — 可选:下载统计(多文件并行) —
74+
.AddListenerMultiDownloadStatistics((_, e) =>
75+
{
76+
Console.Write($"\r [下载] {e.BytesReceived}/{e.TotalBytesToReceive} bytes ({e.ProgressPercentage:F0}%) {e.Speed}");
77+
})
78+
79+
// — 可选:下载完成 —
80+
.AddListenerMultiDownloadCompleted((_, e) =>
81+
{
82+
Console.WriteLine();
83+
Console.WriteLine($" [下载完成] {(e.IsCompleted ? "✓" : "✗ 存在失败")}");
84+
})
85+
86+
// — 可选:单文件进度 —
87+
.AddListenerProgress((_, e) =>
88+
{
89+
if (e.Progress is { } p)
90+
Console.WriteLine($" {p.AssetName}: {p.Percentage:F0}% ({p.Status})");
91+
})
92+
93+
// — 可选:异常通知 —
94+
.AddListenerException((_, e) =>
95+
{
96+
Console.WriteLine($" [异常] {e.Message}");
97+
});
98+
99+
// ════════════════════════════════════════════════════════════════
100+
// 3. 执行更新
101+
// ════════════════════════════════════════════════════════════════
102+
Console.WriteLine();
103+
Console.WriteLine("══ 启动更新 (LaunchAsync) ══");
104+
Console.WriteLine(" 流程: 版本发现 → 下载 → 解压 → 备份旧版本 → 应用新版本");
105+
106+
try
107+
{
108+
await bootstrap.LaunchAsync();
109+
Console.WriteLine();
110+
Console.WriteLine("══ 更新完成 ✓ ══");
111+
}
112+
catch (Exception ex)
113+
{
114+
Console.WriteLine();
115+
Console.WriteLine($"══ 更新失败: {ex.Message} ══");
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)