之前客户端在 Check() 里按版本号自行判重:latest_version == current_version 就 直接返回不更新,导致服务端重传的同号包永远下不来。 - Util: 新增 UrlEncodeQuery(查询参数百分号编码) - Auth::CheckUpdate(version, manifestHash):带上本地清单指纹请求 - Update: UpdateInfo 增加 manifestHash;本地 update_state.json 记录指纹; 版本号相同但服务端指纹变化时照常更新;新包落地后立即记住新指纹 已用 mingw-w64 g++ 14 / C++17 编译通过(Util/Auth/Update 三个 TU), Windows 侧仍需 native\build.bat 出包。
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
namespace pddai {
|
|
|
|
// 版本检测与自动更新:走验证平台的 /check-update,下载完整包后替换自身并重启
|
|
struct UpdateInfo {
|
|
bool available = false;
|
|
bool forced = false;
|
|
std::string currentVersion;
|
|
std::string latestVersion;
|
|
std::string notes;
|
|
std::string downloadUrl;
|
|
std::string fileHash;
|
|
std::string manifestHash; // 服务端版本清单指纹,用于识别同版本号换文件
|
|
std::string entryFile;
|
|
long long fileSize = 0;
|
|
std::string error;
|
|
};
|
|
|
|
class Update {
|
|
public:
|
|
// 当前 exe 的文件版本,格式化为 a.b.c
|
|
static std::string CurrentVersion();
|
|
|
|
// 查询服务端最新版本;网络错误或服务端异常时 available=false 并填 error
|
|
static UpdateInfo Check();
|
|
|
|
// 下载 → 校验 SHA256 → 解压(zip 包)→ 替换 exe → 启动新进程并退出。
|
|
// progress 回调传入 0~100 的进度,可能在工作线程中被调用。
|
|
static bool Apply(const UpdateInfo& info, const std::function<void(int)>& progress,
|
|
std::string& error);
|
|
};
|
|
|
|
}
|