Update: drop Qt dependency, rewrite as pure Win32 using v142 toolset. Replace Update.ui/qrc and miniz-based Zip with Api/Crypto/Http/Json/Unzip/UpdateWindow modules. CrownClient/CrownServer: update Verify and main sources, retarget x64 configs to v142 (VS2019) with SDK 10.0.19041.0, fix VMProtect SDK paths.
49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
namespace updater {
|
|
|
|
struct UpdateOptions {
|
|
std::wstring appKey;
|
|
std::wstring clientVersion; // 为空表示全量安装模式
|
|
std::wstring targetDir; // 为空时用 UPDATER_TARGET_DIR / 程序所在目录
|
|
bool fullMode = false; // true = 下载完整包;false = 按版本下载补丁包
|
|
std::wstring launchExe; // 更新完成后拉起的程序,留空用 UPDATER_LAUNCH_EXE
|
|
};
|
|
|
|
class Worker {
|
|
public:
|
|
using StateCallback = std::function<void(int percent, const std::wstring& text)>;
|
|
using FinishCallback = std::function<void(bool success, const std::wstring& text)>;
|
|
|
|
Worker();
|
|
~Worker();
|
|
|
|
Worker(const Worker&) = delete;
|
|
Worker& operator=(const Worker&) = delete;
|
|
|
|
void Start(const UpdateOptions& options, StateCallback onState, FinishCallback onFinish);
|
|
void Cancel();
|
|
bool running() const { return running_; }
|
|
|
|
private:
|
|
static unsigned __stdcall ThreadEntry(void* param);
|
|
void Run();
|
|
void Emit(int percent, const std::wstring& text);
|
|
void Finish(bool success, const std::wstring& text);
|
|
bool CopyToTarget(const std::wstring& staging, const std::wstring& targetDir,
|
|
std::wstring& err);
|
|
|
|
UpdateOptions options_;
|
|
StateCallback onState_;
|
|
FinishCallback onFinish_;
|
|
std::atomic<bool> cancel_;
|
|
std::atomic<bool> running_;
|
|
void* thread_ = nullptr;
|
|
};
|
|
|
|
}
|