Markdown页面测试
# GZUpdate.Client.Win `GZUpdate.Client.Win` 是 `GZUpdate.Client` 的 WinForms 开箱即用集成包。业务项目只需要设置一次升级参数,再调用检查升级方法即可。 ## 安装 ```xml ``` ## 启动时自动检查并升级 ```csharp using GZUpdate.Client; using GZUpdate.Client.Win; [STAThread] static void Main() { // .NET Framework 项目可替换为 Application.EnableVisualStyles() // 和 Application.SetCompatibleTextRenderingDefault(false)。 ApplicationConfiguration.Initialize(); WinUpdateClient.Configure( server: "https://update.infnitee.com/", productId: "YourProductId", versionType: EnumVersionType.release, upgradeExecutorDllPath: "__upgrade_executor_dll"); var result = WinUpdateClient.CheckAndUpdate(); if (result.ShouldExitApplication) return; Application.Run(new MainForm()); } ``` 启动模式下,如果发现新版本,包会显示默认升级进度弹窗;升级成功后会自动启动新实例,调用方根据 `ShouldExitApplication` 停止继续打开主窗体。 ## 手动检查更新 主窗体中可以这样绑定“检查更新”按钮: ```csharp void BtnCheckUpdate_Click(object sender, EventArgs e) { WinUpdateClient.CheckAndUpdate(this, WinUpdateMode.Manual); } ``` 手动模式下,发现新版本会先询问用户是否升级;升级完成后默认保留弹窗上的“重启”按钮,由用户手动重启。 ## 可选配置 如果需要更多控制,可以使用 `WinUpdateOptions`: ```csharp WinUpdateClient.Configure(new WinUpdateOptions { Server = "https://update.infnitee.com/", ProductId = "YourProductId", VersionType = EnumVersionType.release, UpgradeExecutorDllPath = "__upgrade_executor_dll", RestartAfterStartupUpdate = true, RestartAfterManualUpdate = false, PromptBeforeManualUpdate = true, ShowNoUpdateMessage = true }); ``` ## 自定义升级弹窗 实现 `IWinUpdateProgressDialogFactory` 和 `IWinUpdateProgressDialog`,再通过 `Configure` 注入: ```csharp WinUpdateClient.Configure( server: "https://update.infnitee.com/", productId: "YourProductId", versionType: EnumVersionType.release, upgradeExecutorDllPath: "__upgrade_executor_dll", progressDialogFactory: new YourUpdateDialogFactory()); ``` 自定义弹窗需要处理这些方法: - `SetMessage`:显示当前升级消息。 - `SetDownloadProgress`:显示下载进度。 - `SetPackageProgress`:显示升级包数量进度。 - `SetComplete`:显示升级完成状态。 - `SetFailure`:显示升级失败状态。 - `EnableClose` / `RequestClose`:控制弹窗关闭。 ## 返回结果 `CheckAndUpdate` 返回 `WinUpdateResult`: - `Status`:本次检查/升级状态。 - `IsUpdated`:是否已完成升级。 - `ShouldExitApplication`:是否应停止当前启动流程。 - `LatestVersion`:检测到的最新版本。 - `CurrentVersion`:升级后写入的当前版本。 - `Error`:失败异常。
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post 张国生


