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 @@ -189,7 +189,10 @@ private async Task<GeneralUpdateBootstrap> LaunchOssAsync()
return this;
}

var upgradeAppName = "GeneralUpdate.Upgrade.exe";
// Use user-configured AppName, fall back to default updater name
var upgradeAppName = !string.IsNullOrWhiteSpace(_configInfo.AppName) && _configInfo.AppName != "Update.exe"
? _configInfo.AppName
: "GeneralUpdate.Upgrade.exe";
var appPath = Path.Combine(basePath, upgradeAppName);
if (!File.Exists(appPath))
throw new Exception($"Upgrade application not found: {upgradeAppName}");
Expand Down
34 changes: 34 additions & 0 deletions src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ private async Task ExecuteStandardWorkflowAsync()
}

await SafeReportDownloadCompletedAsync(hooksCtx).ConfigureAwait(false);
await SafeOnDownloadCompletedAsync(hooksCtx).ConfigureAwait(false);

// Apply updates and start app
await _osStrategy.ExecuteAsync();
await SafeOnAfterUpdateAsync(hooksCtx).ConfigureAwait(false);
await SafeReportUpdateAppliedAsync(hooksCtx).ConfigureAwait(false);
await SafeOnBeforeStartAppAsync(hooksCtx).ConfigureAwait(false);
_osStrategy.StartApp();
}
Expand Down Expand Up @@ -318,6 +321,25 @@ private async Task SafeOnUpdateErrorAsync(Hooks.UpdateContext ctx, Exception err
catch (Exception ex) { GeneralTracer.Warn($"OnUpdateErrorAsync hook failed: {ex.Message}"); }
}

private async Task SafeOnAfterUpdateAsync(Hooks.UpdateContext ctx)
{
try { await Hooks.OnAfterUpdateAsync(ctx).ConfigureAwait(false); }
catch (Exception ex) { GeneralTracer.Warn($"OnAfterUpdateAsync hook failed: {ex.Message}"); }
}

private async Task SafeOnDownloadCompletedAsync(Hooks.UpdateContext ctx)
{
try
{
var downloadCtx = new Hooks.DownloadContext(
_configInfo?.MainAppName ?? _configInfo?.AppName ?? "unknown",
_configInfo?.LastVersion ?? "",
0, TimeSpan.Zero, _configInfo?.TempPath, true);
await Hooks.OnDownloadCompletedAsync(downloadCtx).ConfigureAwait(false);
}
catch (Exception ex) { GeneralTracer.Warn($"OnDownloadCompletedAsync hook failed: {ex.Message}"); }
}

private async Task SafeReportUpdateStartedAsync(Hooks.UpdateContext ctx)
{
try
Expand Down Expand Up @@ -355,5 +377,17 @@ await Reporter.ReportAsync(new Download.Reporting.UpdateReport(
catch (Exception ex) { GeneralTracer.Warn($"Report UpdateFailed failed: {ex.Message}"); }
}

private async Task SafeReportUpdateAppliedAsync(Hooks.UpdateContext ctx)
{
try
{
await Reporter.ReportAsync(new Download.Reporting.UpdateReport(
ctx.AppName, ctx.CurrentVersion, ctx.TargetVersion,
Download.Reporting.UpdateEvent.UpdateApplied, ctx.AppType, DateTimeOffset.UtcNow
)).ConfigureAwait(false);
}
catch (Exception ex) { GeneralTracer.Warn($"Report UpdateApplied failed: {ex.Message}"); }
}

#endregion
}
23 changes: 23 additions & 0 deletions src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public async Task ExecuteAsync()
GeneralTracer.Debug("OSSUpdateStrategy: 4. Decompressing packages.");
DecompressAssets(assets);

// Hooks: download + decompress completed
await SafeOnDownloadCompletedAsync(ctx).ConfigureAwait(false);
await SafeOnAfterUpdateAsync(ctx).ConfigureAwait(false);

// Report: update applied
await SafeReportUpdateAppliedAsync(ctx).ConfigureAwait(false);

Expand Down Expand Up @@ -210,6 +214,25 @@ private async Task SafeOnUpdateErrorAsync(Hooks.UpdateContext ctx, Exception err
catch (Exception ex) { GeneralTracer.Warn($"OnUpdateErrorAsync hook failed: {ex.Message}"); }
}

private async Task SafeOnAfterUpdateAsync(Hooks.UpdateContext ctx)
{
try { await Hooks.OnAfterUpdateAsync(ctx).ConfigureAwait(false); }
catch (Exception ex) { GeneralTracer.Warn($"OnAfterUpdateAsync hook failed: {ex.Message}"); }
}

private async Task SafeOnDownloadCompletedAsync(Hooks.UpdateContext ctx)
{
try
{
var downloadCtx = new Hooks.DownloadContext(
_configInfo?.MainAppName ?? _configInfo?.AppName ?? "unknown",
_configInfo?.LastVersion ?? "",
0, TimeSpan.Zero, _appPath, true);
await Hooks.OnDownloadCompletedAsync(downloadCtx).ConfigureAwait(false);
}
catch (Exception ex) { GeneralTracer.Warn($"OnDownloadCompletedAsync hook failed: {ex.Message}"); }
}

private async Task SafeReportUpdateStartedAsync(Hooks.UpdateContext ctx)
{
try
Expand Down
Loading