packServer/desktop/UpdateWindow.xaml
liufumingren 21e8c6a5ec 更新改为软件内下载(进度条)+ 下载完成自动安装;修复 version.json 与包版本不一致导致的无限提示
一、需求:更新不要跳浏览器
- 新增 UpdateWindow(弹窗):显示新版本 / 当前版本 / 包大小 / 更新说明;
- 点「立即更新」→ 软件内流式下载(ProgressBar + 百分比 + 已下载/总大小)→ MD5 校验
  → 启动安装(等 3 秒让本进程退出,再 msiexec /passive)→ 装完自动重新打开;
- 下载目录 %TEMP%\YuncangTraceUpdate\,文件名取 downloadUrl 里的真实文件名
  (原来用 version.json 的 version 命名,配错时会误导)。

二、修复「更新不了一直提示 1.0.2」
- 原因:测试数据里 version.json 写 1.0.3,但 downloadUrl 指向 1.0.2 的包;
  装完仍是 1.0.2 → 下次启动又提示,永远循环。
- 修复(防御):解析 downloadUrl 里的包版本(YuncangTraceSetup-x.y.z.msi),
  若包版本 <= 当前版本则直接忽略更新 —— 以后 version.json 配错/漏传包也不会无限弹窗。
- 同时把环境打成一致:真实打包 1.0.3(version.json 与包都是 1.0.3)并安装。

三、build.ps1
- 自动设置 DOTNET_ROOT(wix 是 dotnet 全局工具,apphost 不认 PATH,只认 DOTNET_ROOT):
  之前在无该环境变量的终端里打包会报「You must install .NET to run this application」。

四、验证
- 安装 1.0.3 + version.json 1.0.3 → 启动无更新窗口、日志无「发现新版本」✅
- 伪造 version.json=1.0.4 但包仍是 1.0.3 → 启动**不弹窗**(防御生效)✅
- 恢复 version.json 为 1.0.3。
- 更新窗口 UI 已通过截图确认(新版本/当前版本/包大小/说明/稍后/立即更新)。
- 新增 YUNCANG_AUTO_UPDATE=1 测试开关:弹窗后自动开始下载,便于无 UI 自动化环境回归。

五、README
- 「自动更新怎么工作」改为软件内下载+自动安装,补充下载位置、安装时机、版本一致性防护与测试开关。
2026-10-17 12:27:05 +08:00

56 lines
2.9 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<Window x:Class="YuncangTrace.LocalService.UpdateWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="软件更新"
Height="340" Width="470"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="{StaticResource BgBrush}"
FontFamily="Microsoft YaHei UI, Segoe UI"
FontSize="13">
<!--
更新窗口:软件内下载(进度条)+ 校验 + 自动安装,不跳浏览器。
样式沿用 App.xaml 里的资源(BgBrush / LineBrush / MutedBrush / BrandBrush)。
-->
<Border Background="White" BorderBrush="{StaticResource LineBrush}" BorderThickness="1"
CornerRadius="10" Margin="22" Padding="20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock x:Name="TitleText" FontSize="17" FontWeight="SemiBold" />
<TextBlock x:Name="SubText" Grid.Row="1" Margin="0,6,0,12"
FontSize="12" Foreground="{StaticResource MutedBrush}" />
<Border Grid.Row="2" Background="#F9FAFB" BorderBrush="{StaticResource LineBrush}"
BorderThickness="1" CornerRadius="6" Padding="10" MaxHeight="96">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="NotesText" TextWrapping="Wrap" FontSize="12"
Foreground="{StaticResource MutedBrush}" />
</ScrollViewer>
</Border>
<StackPanel Grid.Row="3" VerticalAlignment="Bottom" Margin="0,14,0,0">
<ProgressBar x:Name="Progress" Height="8" Visibility="Collapsed"
Minimum="0" Maximum="100" />
<TextBlock x:Name="StatusText" Margin="0,8,0,0" FontSize="12"
Foreground="{StaticResource MutedBrush}" TextWrapping="Wrap" />
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,14,0,0">
<Button x:Name="LaterButton" Content="稍后提醒" Padding="14,7" Margin="0,0,8,0"
Background="Transparent" BorderBrush="{StaticResource LineBrush}" BorderThickness="1"
Cursor="Hand" Click="Later_Click" />
<Button x:Name="UpdateButton" Content="立即更新" Padding="16,7"
Background="{StaticResource BrandBrush}" Foreground="White" BorderThickness="0"
Cursor="Hand" Click="Update_Click" />
</StackPanel>
</Grid>
</Border>
</Window>