diff --git a/src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs index 140b4ec7..20d213e9 100644 --- a/src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/Bootstrap/GeneralUpdateBootstrap.cs @@ -189,7 +189,10 @@ private async Task 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}"); diff --git a/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs b/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs index 09f305c1..96a536ee 100644 --- a/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategy/ClientUpdateStrategy.cs @@ -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(); } @@ -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 @@ -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 } diff --git a/src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs b/src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs index c7d6528a..61739c04 100644 --- a/src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategy/OSSUpdateStrategy.cs @@ -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); @@ -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