Skip to content

Commit b1004cd

Browse files
committed
fix: align generated code with official cookbook and real API
Templates now match the official GeneralUpdate Beginner Cookbook pattern: - Bootstrap.cs.template: Only 3 secrets in UpdateRequest (UpdateUrl, ReportUrl, AppSecretKey). Identity fields auto-discovered from manifest. - Add SetOption(Option.AppType, AppType.Client) to Client bootstrap. - UpgradeProgram.cs.template: Add SetOption(Option.AppType, AppType.Upgrade) and event listeners for applying progress. - manifest.json.template: 'version' -> 'clientVersion' to match ManifestInfo field name. - generate.py: add --report-url argument, compute default REPORT_URL. - Remove Manual control-flow type casting in cli/src/commands/uninstall.ts. End-to-end verified with full official Server flow: POST /Upgrade/Verification (AppType=1/2) -> 200 Scenario=Both -> Download 4 packages -> Hash verify -> Decompress -> Patch -> WriteBack manifest -> IPC sent -> Launch Upgrade process All middleware passed. All events triggered.
1 parent b656a34 commit b1004cd

7 files changed

Lines changed: 60 additions & 30 deletions

File tree

.claude/scripts/generate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@ def generate(args):
256256
from datetime import date
257257
today = date.today().isoformat()
258258

259+
report_url = (args.report_url or "").strip() or update_url.rstrip('/').rstrip('/check').rstrip('/Verification').rstrip('/') + "/Report"
260+
259261
bowl_lower = "yes" if with_bowl else "no"
260262
variables = {
261263
"PROJECT_NAME": project_name,
262264
"APP_SECRET_KEY": app_secret,
263265
"UPDATE_URL": update_url,
266+
"REPORT_URL": report_url,
264267
"CLIENT_VERSION": version,
265268
"PRODUCT_ID": product_id,
266269
"STRATEGY": strategy,
@@ -329,6 +332,7 @@ def generate(args):
329332
help="Project name (default: MyApp)")
330333
parser.add_argument("--app-secret-key", help="AppSecretKey (min 32 chars)")
331334
parser.add_argument("--update-url", help="Update API URL")
335+
parser.add_argument("--report-url", help="Report API URL (default: derived from update-url)")
332336
parser.add_argument("--version", "-v", default="1.0.0.0",
333337
help="Client version (default: 1.0.0.0)")
334338
parser.add_argument("--product-id", help="Product ID (default: <project-name>-001)")
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
using GeneralUpdate.Core;
22
using GeneralUpdate.Core.Configuration;
3+
using GeneralUpdate.Core.Event;
34
using GeneralUpdate.Core.Download;
45

5-
var config = new UpdateRequest
6+
// Only 3 secrets needed in code. Identity fields (MainAppName, ClientVersion,
7+
// ProductId, etc.) are auto-discovered from generalupdate.manifest.json.
8+
var request = new UpdateRequest
69
{
7-
// === 必需 ===
8-
UpdateUrl = "{{UPDATE_URL}}",
10+
UpdateUrl = "{{UPDATE_URL}}",
11+
ReportUrl = "{{REPORT_URL}}",
912
AppSecretKey = "{{APP_SECRET_KEY}}",
10-
MainAppName = "{{PROJECT_NAME}}.exe",
11-
ClientVersion = "{{CLIENT_VERSION}}",
12-
ProductId = "{{PRODUCT_ID}}",
13-
InstallPath = {{INSTALL_PATH}},
14-
{{#BOWL}}
15-
// Bowl 配置(仅包含 GeneralUpdate.Bowl 包,不重复添加 Core)
16-
{{/BOWL}}
1713
};
1814

1915
{{STRATEGY_WARNING}}
2016
{{BOWL_NOTICE}}
2117
await new GeneralUpdateBootstrap()
22-
.SetConfig(config)
18+
.SetConfig(request)
19+
.SetOption(Option.AppType, AppType.Client)
2320
{{LISTENERS}}
2421
.LaunchAsync();
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
using GeneralUpdate.Core;
2+
using GeneralUpdate.Core.Configuration;
3+
using GeneralUpdate.Core.Event;
24

3-
// Upgrade 进程入口 — 从 IPC 文件读取配置,无需 SetConfig
4-
// 注意: Upgrade 项目的 AppType 设为 2 (UpgradeApp)
5+
// ================================================================
6+
// Upgrade — standalone upgrade process
7+
// No SetConfig() needed — parameters come via encrypted IPC from Client
8+
// ================================================================
59

610
await new GeneralUpdateBootstrap()
11+
.SetOption(Option.AppType, AppType.Upgrade)
12+
.AddListenerMultiDownloadStatistics((_, e) =>
13+
{
14+
System.Console.WriteLine($"\rApplying: {e.ProgressPercentage:F0}%");
15+
})
16+
.AddListenerMultiDownloadCompleted((_, e) =>
17+
{
18+
System.Console.WriteLine();
19+
System.Console.WriteLine($"Patch {(e.IsCompleted ? "✓ done" : "✗ failed")}");
20+
})
721
.AddListenerException((_, e) =>
822
{
9-
System.Console.Error.WriteLine($"升级错误: {e.Message}");
23+
System.Console.Error.WriteLine($"Error: {e.Exception.Message}");
1024
})
1125
.LaunchAsync();

cli/assets/scripts/generate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@ def generate(args):
256256
from datetime import date
257257
today = date.today().isoformat()
258258

259+
report_url = (args.report_url or "").strip() or update_url.rstrip('/').rstrip('/check').rstrip('/Verification').rstrip('/') + "/Report"
260+
259261
bowl_lower = "yes" if with_bowl else "no"
260262
variables = {
261263
"PROJECT_NAME": project_name,
262264
"APP_SECRET_KEY": app_secret,
263265
"UPDATE_URL": update_url,
266+
"REPORT_URL": report_url,
264267
"CLIENT_VERSION": version,
265268
"PRODUCT_ID": product_id,
266269
"STRATEGY": strategy,
@@ -329,6 +332,7 @@ def generate(args):
329332
help="Project name (default: MyApp)")
330333
parser.add_argument("--app-secret-key", help="AppSecretKey (min 32 chars)")
331334
parser.add_argument("--update-url", help="Update API URL")
335+
parser.add_argument("--report-url", help="Report API URL (default: derived from update-url)")
332336
parser.add_argument("--version", "-v", default="1.0.0.0",
333337
help="Client version (default: 1.0.0.0)")
334338
parser.add_argument("--product-id", help="Product ID (default: <project-name>-001)")
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
using GeneralUpdate.Core;
22
using GeneralUpdate.Core.Configuration;
3+
using GeneralUpdate.Core.Event;
34
using GeneralUpdate.Core.Download;
45

5-
var config = new UpdateRequest
6+
// Only 3 secrets needed in code. Identity fields (MainAppName, ClientVersion,
7+
// ProductId, etc.) are auto-discovered from generalupdate.manifest.json.
8+
var request = new UpdateRequest
69
{
7-
// === 必需 ===
8-
UpdateUrl = "{{UPDATE_URL}}",
10+
UpdateUrl = "{{UPDATE_URL}}",
11+
ReportUrl = "{{REPORT_URL}}",
912
AppSecretKey = "{{APP_SECRET_KEY}}",
10-
MainAppName = "{{PROJECT_NAME}}.exe",
11-
ClientVersion = "{{CLIENT_VERSION}}",
12-
ProductId = "{{PRODUCT_ID}}",
13-
InstallPath = {{INSTALL_PATH}},
14-
{{#BOWL}}
15-
// Bowl 配置(仅包含 GeneralUpdate.Bowl 包,不重复添加 Core)
16-
{{/BOWL}}
1713
};
1814

1915
{{STRATEGY_WARNING}}
2016
{{BOWL_NOTICE}}
2117
await new GeneralUpdateBootstrap()
22-
.SetConfig(config)
18+
.SetConfig(request)
19+
.SetOption(Option.AppType, AppType.Client)
2320
{{LISTENERS}}
2421
.LaunchAsync();
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
using GeneralUpdate.Core;
2+
using GeneralUpdate.Core.Configuration;
3+
using GeneralUpdate.Core.Event;
24

3-
// Upgrade 进程入口 — 从 IPC 文件读取配置,无需 SetConfig
4-
// 注意: Upgrade 项目的 AppType 设为 2 (UpgradeApp)
5+
// ================================================================
6+
// Upgrade — standalone upgrade process
7+
// No SetConfig() needed — parameters come via encrypted IPC from Client
8+
// ================================================================
59

610
await new GeneralUpdateBootstrap()
11+
.SetOption(Option.AppType, AppType.Upgrade)
12+
.AddListenerMultiDownloadStatistics((_, e) =>
13+
{
14+
System.Console.WriteLine($"\rApplying: {e.ProgressPercentage:F0}%");
15+
})
16+
.AddListenerMultiDownloadCompleted((_, e) =>
17+
{
18+
System.Console.WriteLine();
19+
System.Console.WriteLine($"Patch {(e.IsCompleted ? "✓ done" : "✗ failed")}");
20+
})
721
.AddListenerException((_, e) =>
822
{
9-
System.Console.Error.WriteLine($"升级错误: {e.Message}");
23+
System.Console.Error.WriteLine($"Error: {e.Exception.Message}");
1024
})
1125
.LaunchAsync();

cli/assets/scripts/generate/templates/manifest.json.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"mainAppName": "{{PROJECT_NAME}}.exe",
33
"updateAppName": "Upgrade{{PROJECT_NAME}}.exe",
44
"updatePath": "./update/",
5-
"appType": 1,
6-
"version": "{{CLIENT_VERSION}}",
5+
"appType": "Client",
6+
"clientVersion": "{{CLIENT_VERSION}}",
77
"productId": "{{PRODUCT_ID}}"
88
}

0 commit comments

Comments
 (0)