101 lines
2.6 KiB
C++
101 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <windows.h>
|
|
|
|
#include <string>
|
|
|
|
#include "Api.h"
|
|
#include "Worker.h"
|
|
|
|
namespace Gdiplus {
|
|
class Graphics;
|
|
}
|
|
|
|
namespace updater {
|
|
|
|
// 工作线程 -> UI 线程的状态投递结构,由窗口负责释放
|
|
struct UiState {
|
|
int percent = 0;
|
|
std::wstring status;
|
|
bool finished = false;
|
|
bool success = false;
|
|
bool hasInfo = false; // true 时 info 有效,界面据此刷新更新日志
|
|
UpdateInfo info;
|
|
};
|
|
|
|
class UpdateWindow {
|
|
public:
|
|
UpdateWindow();
|
|
~UpdateWindow();
|
|
|
|
UpdateWindow(const UpdateWindow&) = delete;
|
|
UpdateWindow& operator=(const UpdateWindow&) = delete;
|
|
|
|
bool Create(HINSTANCE instance, const UpdateOptions& options);
|
|
int MessageLoop();
|
|
|
|
private:
|
|
// 完整包模式下先让用户选安装目录,之后再切到更新进度
|
|
enum class Phase { PickDir, Updating };
|
|
|
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
LRESULT HandleMessage(UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
void OnPaint();
|
|
void Render();
|
|
void DrawBackground(Gdiplus::Graphics& graphics);
|
|
void DrawPickPanel(Gdiplus::Graphics& graphics);
|
|
void DrawProgressPanel(Gdiplus::Graphics& graphics);
|
|
void DrawChangelog(Gdiplus::Graphics& graphics);
|
|
void DrawCloseButton(Gdiplus::Graphics& graphics);
|
|
void OnState(const UiState& state);
|
|
void ApplyInfo(const UpdateInfo& info);
|
|
void ScrollChangelog(int delta);
|
|
void RequestClose();
|
|
void Invalidate();
|
|
|
|
// 目录选择阶段
|
|
bool BrowseFolder();
|
|
void StartUpdate();
|
|
void StartWorker(const UpdateOptions& options);
|
|
|
|
bool HitCloseButton(int x, int y) const;
|
|
bool HitBrowseButton(int x, int y) const;
|
|
bool HitInstallButton(int x, int y) const;
|
|
bool HitCancelButton(int x, int y) const;
|
|
bool HitAnyButton(int x, int y) const;
|
|
void UpdateHover(int x, int y);
|
|
|
|
HWND hwnd_ = nullptr;
|
|
HINSTANCE instance_ = nullptr;
|
|
Worker worker_;
|
|
|
|
Phase phase_ = Phase::Updating;
|
|
UpdateOptions options_;
|
|
std::wstring installDir_;
|
|
bool started_ = false;
|
|
|
|
int percent_ = 0;
|
|
std::wstring status_;
|
|
bool finished_ = false;
|
|
bool success_ = false;
|
|
bool closing_ = false;
|
|
|
|
UpdateInfo info_;
|
|
std::wstring changelogText_;
|
|
int changelogScroll_ = 0;
|
|
int changelogContentH_ = 0;
|
|
|
|
int closeState_ = 0; // 0 普通 1 悬停 2 按下
|
|
int browseState_ = 0;
|
|
int installState_ = 0;
|
|
int cancelState_ = 0;
|
|
int pressed_ = 0; // 0 无 1 关闭 2 浏览 3 安装 4 取消
|
|
bool tracking_ = false;
|
|
|
|
struct RenderContext;
|
|
RenderContext* render_ = nullptr;
|
|
};
|
|
|
|
}
|