Files

100 lines
2.6 KiB
Markdown
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.
# Velopack 迁移总结
## 目标
将自动更新从 AutoUpdater.NET 迁移到 Velopack,解决 .NET 8 ZipExtractor 依赖问题。
## 根本原因
AutoUpdater.NET 1.9.0 内部嵌入了 ZipExtractor.exe(.NET 8 WinForms 程序),用户机器只有 .NET 10 时无法运行。
## 修改文件
### 1. `henlo_migration_wpf10.csproj`
- 移除: `Autoupdater.NET.Official` 1.9.0
- 添加: `Velopack` 0.0.1298
### 2. `App.xaml.cs`
- 移除所有 AutoUpdater 相关代码
- 添加 Velopack 初始化: `VelopackApp.Build().Run()`
- 添加 `UpdateManager` 用于检查/下载/应用更新
- 后台静默检查更新
- 手动检查更新支持弹窗确认
### 3. `Views/HomeWindow.xaml.cs`
- `CheckUpdate_Click` 改为 async void,调用 `CheckUpdateManualAsync`
### 4. `pack.bat` (新增)
Velopack 打包脚本,用法:
```batch
pack.bat 1.0.002
```
## Velopack 工作流程
```
开发机:
dotnet publish → vpk pack → releases/
├── setup.exe (安装程序)
├── update.nupkg (更新包)
└── RELEASES (更新索引)
服务器:
上传 releases/ 到 http://zjhenlo.henlo.net:8878/henlo_migration/auto_update/
客户端:
启动 → VelopackApp.Build().Run()
→ UpdateManager.CheckForUpdatesAsync()
→ 有新版本 → DownloadUpdatesAsync()
→ 提示用户重启 → ApplyUpdatesAndRestart()
```
## 关键 API
```csharp
// 初始化(必须在启动时调用)
VelopackApp.Build().Run();
// 检查更新
var mgr = new UpdateManager("https://.../updates");
var newVersion = await mgr.CheckForUpdatesAsync();
// 下载更新
await mgr.DownloadUpdatesAsync(newVersion);
// 应用并重启
mgr.ApplyUpdatesAndRestart(newVersion);
```
## 打包命令
```bash
# 1. 发布应用
dotnet publish -c Release -o ./publish --self-contained false -r win-x64
# 2. Velopack 打包
vpk pack -u "henlo_migration" -v "1.0.002" -p "./publish" -e "恒诺迁移工具.exe" -o "./releases"
```
## 服务器部署
将 `releases/` 目录下的文件上传到:
```
http://zjhenlo.henlo.net:8878/henlo_migration/auto_update/
```
Velopack 会自动读取该目录下的 `RELEASES` 文件检查更新。
## 优势
1. **Rust 核心** → Updater 完全不需要 .NET Runtime
2. **Delta 更新** → 只下载变更文件
3. **自动回滚** → 更新失败自动恢复旧版本
4. **后台静默更新** → 下次启动时自动应用
5. **经过大规模验证** → osu!、STranslate 等大牌在用
## 待办
- [ ] 测试打包流程
- [ ] 配置服务器更新目录
- [ ] 测试完整更新流程
- [ ] 更新 CI/CD 脚本(如有)