Skip to content

Commit 750fe15

Browse files
JusterZhuclaude
andcommitted
feat: add installPath to SetSource(), simplify OSS test code to use SetSource()
- SetSource() now accepts optional installPath parameter for scenarios where the current process runs from a subdirectory (e.g. OSS upgrade) and generalupdate.manifest.json lives in the parent directory. - Update SetSource() XML doc to mention OssStrategy and all AppType modes. - Update class-level example to show both standard and OSS usage patterns. - Simplify ClientTest and UpgradeTest OSS paths to use SetSource() instead of SetConfig(new UpdateRequest{...}) — matching the standard flow pattern where only secrets are passed in code and identity fields are read from generalupdate.manifest.json. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4b50eb5 commit 750fe15

3 files changed

Lines changed: 52 additions & 24 deletions

File tree

src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,33 @@ namespace GeneralUpdate.Core;
5353
/// components, network policies, and OS strategy.</para>
5454
/// </remarks>
5555
/// <example>
56+
/// <para><b>Standard flow (Client):</b></para>
5657
/// <code>
5758
/// var result = await new GeneralUpdateBootstrap()
58-
/// .SetConfig(new UpdateRequest {
59-
/// UpdateUrl = "https://api.example.com",
60-
/// ClientVersion = "1.0.0",
61-
/// InstallPath = @"C:\MyApp",
62-
/// AppSecretKey = "my-key"
63-
/// })
59+
/// .SetSource("https://api.example.com", "my-key")
6460
/// .SetOption(Option.AppType, AppType.Client)
6561
/// .Hooks&lt;MyCustomHooks&gt;()
6662
/// .LaunchAsync();
6763
/// </code>
64+
/// <para><b>OSS flow (Object Storage Service):</b></para>
65+
/// <code>
66+
/// // OssClient — only secrets in code; identity from generalupdate.manifest.json
67+
/// var result = await new GeneralUpdateBootstrap()
68+
/// .SetSource("https://oss.example.com/versions.json", "my-key")
69+
/// .SetOption(Option.AppType, AppType.OssClient)
70+
/// .Hooks&lt;MyCustomHooks&gt;()
71+
/// .LaunchAsync();
72+
///
73+
/// // OssUpgrade — running from a subdirectory; pass installPath to locate
74+
/// // generalupdate.manifest.json in the parent directory
75+
/// var installPath = Path.GetFullPath(Path.Combine(baseDir, ".."));
76+
/// var result = await new GeneralUpdateBootstrap()
77+
/// .SetSource("https://oss.example.com/versions.json", "my-key",
78+
/// installPath: installPath)
79+
/// .SetOption(Option.AppType, AppType.OssUpgrade)
80+
/// .Hooks&lt;MyCustomHooks&gt;()
81+
/// .LaunchAsync();
82+
/// </code>
6883
/// </example>
6984
public class GeneralUpdateBootstrap : AbstractBootstrap<GeneralUpdateBootstrap, IStrategy>
7085
{
@@ -232,15 +247,29 @@ public GeneralUpdateBootstrap SetConfig(string filePath)
232247
/// <summary>
233248
/// Zero-config entry-point: supply only secrets. Provides sensible identity defaults
234249
/// that pass <see cref="UpdateRequest.Validate"/>; the real identity metadata is
235-
/// discovered later by <see cref="ClientStrategy"/> from <c>generalupdate.manifest.json</c>.
250+
/// discovered later by <see cref="ClientStrategy"/> or <see cref="OssStrategy"/>
251+
/// from <c>generalupdate.manifest.json</c>. Works with all <see cref="AppType"/>
252+
/// modes (<c>Client</c>, <c>Upgrade</c>, <c>OssClient</c>, <c>OssUpgrade</c>).
236253
/// </summary>
254+
/// <param name="updateUrl">The remote endpoint for update validation or version config retrieval.</param>
255+
/// <param name="appSecretKey">The application secret key used for authentication.</param>
256+
/// <param name="reportUrl">Optional URL for reporting update status back to the server.</param>
257+
/// <param name="scheme">Optional URL scheme override (e.g. <c>"https"</c>).</param>
258+
/// <param name="token">Optional authentication token for API requests.</param>
259+
/// <param name="installPath">
260+
/// Optional override for the installation root directory. When <c>null</c>,
261+
/// defaults to <see cref="AppDomain.CurrentDomain.BaseDirectory"/>. Set this when
262+
/// the current process runs from a subdirectory (e.g. the OSS upgrade process in
263+
/// <c>update/</c>) and <c>generalupdate.manifest.json</c> lives in the parent.
264+
/// </param>
237265
/// <returns>This bootstrap instance for chaining.</returns>
238266
public GeneralUpdateBootstrap SetSource(
239267
string updateUrl,
240268
string appSecretKey,
241269
string? reportUrl = null,
242270
string? scheme = null,
243-
string? token = null)
271+
string? token = null,
272+
string? installPath = null)
244273
{
245274
var config = new UpdateRequest
246275
{
@@ -250,6 +279,8 @@ public GeneralUpdateBootstrap SetSource(
250279
Scheme = scheme,
251280
ReportUrl = reportUrl
252281
};
282+
if (installPath != null)
283+
config.InstallPath = installPath;
253284
return SetConfig(config);
254285
}
255286

tests/ClientTest/Program.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,18 @@ static async Task RunOssClientAsync()
3939
Console.WriteLine($"Started at {DateTime.Now}");
4040
Console.WriteLine($"Running from: {AppDomain.CurrentDomain.BaseDirectory}");
4141

42-
// Secrets come from code. Identity fields (MainAppName, ClientVersion,
43-
// UpdateAppName, UpdatePath) are read from generalupdate.manifest.json
44-
// by OssStrategy via AppMetadataDiscoverer.Discover() — same as standard flow.
42+
// Only secrets are supplied in code. Identity fields (MainAppName,
43+
// ClientVersion, UpdateAppName, UpdatePath) are read from
44+
// generalupdate.manifest.json by OssStrategy via
45+
// AppMetadataDiscoverer.Discover() — same as the standard flow.
4546
var updateUrl = "http://localhost:5000/packages/versions.json";
4647
var appSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6";
4748

4849
Console.WriteLine($"UpdateUrl: {updateUrl}");
4950
Console.WriteLine();
5051

5152
await new GeneralUpdateBootstrap()
52-
.SetConfig(new UpdateRequest
53-
{
54-
UpdateUrl = updateUrl,
55-
InstallPath = AppDomain.CurrentDomain.BaseDirectory,
56-
AppSecretKey = appSecretKey
57-
})
53+
.SetSource(updateUrl, appSecretKey)
5854
.SetOption(Option.AppType, AppType.OssClient)
5955
.Hooks<ClientTestHooks>()
6056
.AddListenerMultiDownloadStatistics(OnDownloadStatistics)

tests/UpgradeTest/Program.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ static async Task RunOssUpgradeAsync()
4444
Console.WriteLine($"InstallPath={installPath} (parent, where manifest + versions.json live)");
4545
Console.WriteLine();
4646

47+
// Only secrets and InstallPath are supplied in code. Identity fields
48+
// (MainAppName, ClientVersion, UpdateAppName) are read from
49+
// generalupdate.manifest.json by OssStrategy via
50+
// AppMetadataDiscoverer.Discover() — same as the standard OSS client flow.
4751
await new GeneralUpdateBootstrap()
48-
.SetConfig(new UpdateRequest
49-
{
50-
UpdateUrl = "http://localhost:5000/packages/versions.json",
51-
InstallPath = installPath,
52-
AppSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6"
53-
// Identity fields from generalupdate.manifest.json via Discover().
54-
})
52+
.SetSource(
53+
"http://localhost:5000/packages/versions.json",
54+
"dfeb5833-975e-4afb-88f1-6278ee9aeff6",
55+
installPath: installPath)
5556
.SetOption(Option.AppType, AppType.OssUpgrade)
5657
.Hooks<UpgradeTestHooks>()
5758
.AddListenerMultiDownloadStatistics(OnDownloadStatistics)

0 commit comments

Comments
 (0)