diff --git a/Crown.sln b/Crown.sln index 2857e86..6b5ce94 100644 --- a/Crown.sln +++ b/Crown.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.6.33829.357 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.37530.7 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CrownServer", "CrownServer\Crown.vcxproj", "{67E7A149-F86D-481B-AF61-E98BA438B8C4}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CrownClient", "CrownClient\CrownClient.vcxproj", "{C339197A-FFBA-4AE7-81FA-325702162EC1}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Update", "Update\Update.vcxproj", "{9CBBB245-EA92-4F87-A00E-70C3D10F86E8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +33,14 @@ Global {C339197A-FFBA-4AE7-81FA-325702162EC1}.Release|x64.Build.0 = Release|x64 {C339197A-FFBA-4AE7-81FA-325702162EC1}.Release|x86.ActiveCfg = Release|Win32 {C339197A-FFBA-4AE7-81FA-325702162EC1}.Release|x86.Build.0 = Release|Win32 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Debug|x64.ActiveCfg = Debug|x64 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Debug|x64.Build.0 = Debug|x64 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Debug|x86.ActiveCfg = Debug|Win32 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Debug|x86.Build.0 = Debug|Win32 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Release|x64.ActiveCfg = Release|x64 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Release|x64.Build.0 = Release|x64 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Release|x86.ActiveCfg = Release|Win32 + {9CBBB245-EA92-4F87-A00E-70C3D10F86E8}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Update/Config.h b/Update/Config.h index 0fc8ba9..76d3c3d 100644 --- a/Update/Config.h +++ b/Update/Config.h @@ -80,8 +80,8 @@ #define UPDATER_TIMEOUT_SEC 30 // 窗口尺寸 -#define UPDATER_WINDOW_WIDTH 860 -#define UPDATER_WINDOW_HEIGHT 480 +#define UPDATER_WINDOW_WIDTH 560 +#define UPDATER_WINDOW_HEIGHT 360 // 静默检查(--check-only)的退出码,主程序据此决定继续启动还是交给更新器 #define UPDATER_EXIT_NO_UPDATE 0 // 已是最新,主程序正常往下走 diff --git a/Update/Update.rc b/Update/Update.rc index 2a1a6d1..201aafd 100644 --- a/Update/Update.rc +++ b/Update/Update.rc @@ -88,16 +88,9 @@ END ///////////////////////////////////////////////////////////////////////////// // -// RCDATA (updater self-draw resources, loaded by GDI+) +// 更新器界面全部用 GDI+ 矢量绘制(VS 安装器风格),不再内嵌图片资源 // -IDR_BG RCDATA "res\\bg.gif" -IDR_CLOSE_NORMAL RCDATA "res\\close_0_28_28.png" -IDR_CLOSE_HOVER RCDATA "res\\close_1_28_28.png" -IDR_CLOSE_PRESS RCDATA "res\\close_2_28_28.png" - -///////////////////////////////////////////////////////////////////////////// - #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// diff --git a/Update/UpdateWindow.cpp b/Update/UpdateWindow.cpp index fb61eae..3ef2031 100644 --- a/Update/UpdateWindow.cpp +++ b/Update/UpdateWindow.cpp @@ -1,4 +1,4 @@ -#define NOMINMAX +#define NOMINMAX #include "UpdateWindow.h" @@ -37,127 +37,123 @@ const UINT kTimerClose = 1; const int kWidth = UPDATER_WINDOW_WIDTH; const int kHeight = UPDATER_WINDOW_HEIGHT; -const int kCloseSize = 28; -const int kCloseMarginX = 14; -const int kCloseMarginY = 12; +// VS 2019 是直角窗口,窗口和控件都不做圆角 +const int kTitleH = 32; // 标题栏高度 +const int kCloseSize = 32; // 关闭按钮是标题栏右侧的正方形 +const int kCloseMarginX = 0; +const int kCloseMarginY = 0; -// 更新进度面板 -const int kPanelX = 48; -const int kPanelY = 300; -const int kPanelW = kWidth - kPanelX * 2; -const int kPanelH = 132; +const int kMarginX = 24; -const int kTextX = 72; -const int kTitleY = 316; -const int kStatusY = 356; -const int kBarX = 72; -const int kBarY = 388; -const int kBarW = kWidth - kBarX * 2; -const int kBarH = 12; +// 标题区 +const int kHeadY = 46; +const int kHeadH = 26; +const int kSubY = 74; +const int kSubH = 20; + +// 更新日志卡片 +const int kLogX = kMarginX; +const int kLogY = 100; +const int kLogW = kWidth - kMarginX * 2; +const int kLogH = 180; +const int kLogPadX = 16; +const int kLogTitleY = kLogY + 12; +const int kLogTitleH = 22; +const int kLogTextY = kLogTitleY + kLogTitleH + 4; +const int kLogTextH = kLogY + kLogH - 12 - kLogTextY; +const int kLogTextW = kLogW - kLogPadX * 2; + +// 状态行与进度条 +const int kStatusY = kLogY + kLogH + 12; +const int kStatusH = 22; +const int kBarX = kMarginX; +const int kBarY = kStatusY + kStatusH + 10; +const int kBarW = kWidth - kMarginX * 2; +const int kBarH = 10; // 安装目录选择面板 -const int kPickPanelX = 48; -const int kPickPanelY = 176; -const int kPickPanelW = kWidth - kPickPanelX * 2; -const int kPickPanelH = 248; +const int kPickPanelX = kMarginX; +const int kPickPanelW = kWidth - kMarginX * 2; -const int kPickTextX = 72; -const int kPickTitleY = 196; -const int kPickHintY = 234; +const int kPickTextX = kPickPanelX; +const int kPickTitleY = 46; +const int kPickHintY = 78; -const int kPathX = 72; -const int kPathY = 268; -const int kPathW = 596; -const int kPathH = 38; +const int kPathX = kPickPanelX; +const int kPathY = 126; +const int kPathW = kPickPanelW - 12 - 104; +const int kPathH = 34; const int kBrowseX = kPathX + kPathW + 12; -const int kBrowseW = 116; +const int kBrowseW = 104; -const int kSpaceY = 318; +const int kSpaceY = 176; -const int kButtonY = 356; -const int kButtonH = 44; -const int kInstallW = 148; -const int kInstallX = kPickPanelX + kPickPanelW - kInstallW; -const int kCancelW = 108; +const int kButtonY = 298; +const int kButtonH = 38; +const int kInstallW = 140; +const int kInstallX = kWidth - kMarginX - kInstallW; +const int kCancelW = 104; const int kCancelX = kInstallX - 12 - kCancelW; -const wchar_t* const kFontName = L"Microsoft YaHei"; +// 更新日志一屏滚动的步长 +const int kScrollStep = 24; -void AddRoundRect(Gdiplus::GraphicsPath& path, int x, int y, int w, int h, int r) { - int d = r * 2; - path.AddArc(x, y, d, d, 180, 90); - path.AddArc(x + w - d, y, d, d, 270, 90); - path.AddArc(x + w - d, y + h - d, d, d, 0, 90); - path.AddArc(x, y + h - d, d, d, 90, 90); - path.CloseFigure(); +const wchar_t* const kFontName = L"Segoe UI"; + +// Visual Studio 2019 暗色主题取色 +const Gdiplus::ARGB kArgbWindow = 0xFF1E1E1E; // 窗口背景 +const Gdiplus::ARGB kArgbTitleBar = 0xFF2D2D30; // 标题栏 +const Gdiplus::ARGB kArgbSurface = 0xFF252526; // 卡片/面板 +const Gdiplus::ARGB kArgbControl = 0xFF333337; // 输入框/按钮/进度条轨道 +const Gdiplus::ARGB kArgbBorder = 0xFF3F3F46; // 分隔线/边框 +const Gdiplus::ARGB kArgbHover = 0xFF3E3E42; // 控件悬停 +const Gdiplus::ARGB kArgbAccent = 0xFF007ACC; // 强调蓝 +const Gdiplus::ARGB kArgbAccentHover = 0xFF1B8AD6; +const Gdiplus::ARGB kArgbAccentPress = 0xFF005C9E; +const Gdiplus::ARGB kArgbText = 0xFFFFFFFF; +const Gdiplus::ARGB kArgbTextDim = 0xFFCCCCCC; +const Gdiplus::ARGB kArgbTextWeak = 0xFF999999; +const Gdiplus::ARGB kArgbCloseHover = 0xFFE81123; // 关闭按钮悬停红 +const Gdiplus::ARGB kArgbClosePress = 0xFFB01018; +const Gdiplus::ARGB kArgbError = 0xFFE81123; + +// 1 像素描边:GDI+ 默认会把整数坐标的边框画成两像素灰边,内缩半像素才是清晰的一条线 +void DrawHairline(Gdiplus::Graphics& graphics, const Gdiplus::Rect& rect, Gdiplus::ARGB color) { + Gdiplus::Pen pen(color, 1.0f); + graphics.DrawRectangle(&pen, + Gdiplus::RectF(static_cast(rect.X) + 0.5f, + static_cast(rect.Y) + 0.5f, + static_cast(rect.Width) - 1.0f, + static_cast(rect.Height) - 1.0f)); } +// VS 2019 的按钮是直角矩形:主按钮强调蓝实底,次按钮深灰底 + 灰描边 void DrawButton(Gdiplus::Graphics& graphics, int x, int y, int w, int h, const wchar_t* text, bool primary, int state) { - Gdiplus::GraphicsPath path; - AddRoundRect(path, x, y, w, h, 8); - - Gdiplus::Color top; - Gdiplus::Color bottom; + Gdiplus::Rect rect(x, y, w, h); + Gdiplus::Color textColor; if (primary) { - if (state == 2) { - top = Gdiplus::Color(255, 30, 104, 182); - bottom = Gdiplus::Color(255, 22, 78, 142); - } else if (state == 1) { - top = Gdiplus::Color(255, 74, 182, 250); - bottom = Gdiplus::Color(255, 42, 136, 212); - } else { - top = Gdiplus::Color(255, 58, 160, 238); - bottom = Gdiplus::Color(255, 32, 114, 192); - } + Gdiplus::ARGB fill = state == 2 ? kArgbAccentPress : state == 1 ? kArgbAccentHover : kArgbAccent; + Gdiplus::SolidBrush brush(fill); + graphics.FillRectangle(&brush, rect); + textColor = Gdiplus::Color(kArgbText); } else { - if (state == 2) { - top = Gdiplus::Color(255, 54, 62, 78); - bottom = Gdiplus::Color(255, 40, 46, 60); - } else if (state == 1) { - top = Gdiplus::Color(255, 82, 92, 110); - bottom = Gdiplus::Color(255, 60, 68, 86); - } else { - top = Gdiplus::Color(255, 68, 76, 94); - bottom = Gdiplus::Color(255, 50, 56, 70); - } + Gdiplus::ARGB fill = state == 2 ? kArgbSurface : state == 1 ? kArgbHover : kArgbControl; + Gdiplus::SolidBrush brush(fill); + graphics.FillRectangle(&brush, rect); + DrawHairline(graphics, rect, kArgbBorder); + textColor = Gdiplus::Color(state == 0 ? kArgbTextDim : kArgbText); } - Gdiplus::LinearGradientBrush brush(Gdiplus::Point(x, y), Gdiplus::Point(x, y + h), top, - bottom); - graphics.FillPath(&brush, &path); - Gdiplus::StringFormat format; format.SetAlignment(Gdiplus::StringAlignmentCenter); format.SetLineAlignment(Gdiplus::StringAlignmentCenter); - Gdiplus::Font font(kFontName, primary ? 15.0f : 14.0f, Gdiplus::FontStyleBold, - Gdiplus::UnitPixel); - Gdiplus::SolidBrush textBrush(Gdiplus::Color(255, 245, 248, 252)); - Gdiplus::RectF rect(static_cast(x), static_cast(y), static_cast(w), - static_cast(h)); - graphics.DrawString(text, -1, &font, rect, &format, &textBrush); -} - -Gdiplus::Image* LoadImageFromResource(HINSTANCE instance, int resourceId) { - HRSRC found = FindResourceW(instance, MAKEINTRESOURCEW(resourceId), RT_RCDATA); - if (!found) return nullptr; - HGLOBAL loaded = LoadResource(instance, found); - if (!loaded) return nullptr; - void* data = LockResource(loaded); - DWORD size = SizeofResource(instance, found); - if (!data || size == 0) return nullptr; - - IStream* stream = SHCreateMemStream(static_cast(data), size); - if (!stream) return nullptr; - Gdiplus::Image* image = Gdiplus::Image::FromStream(stream, FALSE); - stream->Release(); - return image; -} - -Gdiplus::Image* LoadImageFromFile(const std::wstring& path) { - if (path.empty() || !Utils::FileExists(path)) return nullptr; - return Gdiplus::Image::FromFile(path.c_str(), FALSE); + Gdiplus::Font font(kFontName, 13.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::SolidBrush textBrush(textColor); + Gdiplus::RectF textRect(static_cast(x), static_cast(y), static_cast(w), + static_cast(h)); + graphics.DrawString(text, -1, &font, textRect, &format, &textBrush); } std::wstring PercentText(int percent) { @@ -191,8 +187,6 @@ bool QueryFreeSpace(const std::wstring& path, unsigned long long& freeBytes) { struct UpdateWindow::RenderContext { ULONG_PTR token = 0; - Gdiplus::Image* background = nullptr; - Gdiplus::Image* closeImages[3] = {nullptr, nullptr, nullptr}; }; UpdateWindow::UpdateWindow() : render_(new RenderContext()) { @@ -203,8 +197,6 @@ UpdateWindow::UpdateWindow() : render_(new RenderContext()) { UpdateWindow::~UpdateWindow() { if (render_) { - delete render_->background; - for (int i = 0; i < 3; ++i) delete render_->closeImages[i]; if (render_->token) Gdiplus::GdiplusShutdown(render_->token); delete render_; render_ = nullptr; @@ -216,17 +208,9 @@ bool UpdateWindow::Create(HINSTANCE instance, const UpdateOptions& options) { instance_ = instance; options_ = options; - render_->background = LoadImageFromResource(instance, 101); - if (!render_->background) { - render_->background = LoadImageFromFile(Utils::JoinPath(Utils::GetModuleDir(), L"res\\bg.gif")); - } - render_->closeImages[0] = LoadImageFromResource(instance, 102); - render_->closeImages[1] = LoadImageFromResource(instance, 103); - render_->closeImages[2] = LoadImageFromResource(instance, 104); - WNDCLASSW wc; ZeroMemory(&wc, sizeof(wc)); - wc.style = CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW; + wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = &UpdateWindow::WndProc; wc.hInstance = instance; wc.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -239,14 +223,12 @@ bool UpdateWindow::Create(HINSTANCE instance, const UpdateOptions& options) { int left = (screenX - kWidth) / 2; int top = (screenY - kHeight) / 2; - hwnd_ = CreateWindowExW(WS_EX_TOPMOST | WS_EX_TOOLWINDOW, wc.lpszClassName, UPDATER_TITLE, - WS_POPUP, left, top, kWidth, kHeight, nullptr, nullptr, instance, - this); + // 分层窗口:整体画在 32 位位图上再提交,圆角由 GDI+ 抗锯齿,不会有锯齿边 + hwnd_ = CreateWindowExW(WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, wc.lpszClassName, + UPDATER_TITLE, WS_POPUP, left, top, kWidth, kHeight, nullptr, nullptr, + instance, this); if (!hwnd_) return false; - HRGN region = CreateRoundRectRgn(0, 0, kWidth + 1, kHeight + 1, 12, 12); - SetWindowRgn(hwnd_, region, FALSE); - // 完整包安装且没有指定目录时,先让用户选安装目录 // 必须在首次显示之前定好阶段,否则首帧会画成更新进度面板 bool pickDir = options.fullMode && options.targetDir.empty(); @@ -259,8 +241,9 @@ bool UpdateWindow::Create(HINSTANCE instance, const UpdateOptions& options) { status_ = options.fullMode ? L"正在准备完整包更新..." : L"正在检查版本更新..."; } + Render(); ShowWindow(hwnd_, SW_SHOW); - ::UpdateWindow(hwnd_); + Render(); if (!pickDir) StartWorker(options); return true; @@ -282,6 +265,12 @@ void UpdateWindow::StartWorker(const UpdateOptions& options) { state->finished = true; state->success = ok; PostMessageW(hwnd, kWmState, 0, reinterpret_cast(state)); + }, + [this, hwnd](const UpdateInfo& info) { + UiState* state = new UiState(); + state->hasInfo = true; + state->info = info; + PostMessageW(hwnd, kWmState, 0, reinterpret_cast(state)); }); } @@ -404,8 +393,38 @@ void UpdateWindow::RequestClose() { DestroyWindow(hwnd_); } +void UpdateWindow::ApplyInfo(const UpdateInfo& info) { + info_ = info; + + // 后台可能只填了其中一个,两个都没有时给句占位说明 + std::wstring text = info.changelog; + if (text.empty()) text = info.updateNotes; + if (text.empty()) text = L"本次更新包含功能优化与稳定性改进。"; + changelogText_ = text; + + if (info.currentVersion.empty() && !options_.clientVersion.empty()) { + info_.currentVersion = options_.clientVersion; + } + changelogScroll_ = 0; + Invalidate(); +} + +void UpdateWindow::ScrollChangelog(int delta) { + int maxScroll = (std::max)(0, changelogContentH_ - kLogTextH); + int next = changelogScroll_ + delta; + next = (std::max)(0, (std::min)(maxScroll, next)); + if (next != changelogScroll_) { + changelogScroll_ = next; + Invalidate(); + } +} + void UpdateWindow::OnState(const UiState& state) { if (closing_) return; + if (state.hasInfo) { + ApplyInfo(state.info); + return; + } percent_ = std::max(0, std::min(100, state.percent)); status_ = state.status; if (state.finished) { @@ -417,22 +436,17 @@ void UpdateWindow::OnState(const UiState& state) { } void UpdateWindow::DrawPickPanel(Gdiplus::Graphics& graphics) { - Gdiplus::GraphicsPath panelPath; - AddRoundRect(panelPath, kPickPanelX, kPickPanelY, kPickPanelW, kPickPanelH, 12); - Gdiplus::SolidBrush panelBrush(Gdiplus::Color(165, 12, 16, 24)); - graphics.FillPath(&panelBrush, &panelPath); - Gdiplus::StringFormat nearFormat; nearFormat.SetAlignment(Gdiplus::StringAlignmentNear); nearFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter); nearFormat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord); - Gdiplus::SolidBrush textBrush(Gdiplus::Color(255, 240, 244, 250)); - Gdiplus::SolidBrush dimBrush(Gdiplus::Color(200, 176, 186, 202)); + Gdiplus::SolidBrush textBrush(kArgbText); + Gdiplus::SolidBrush dimBrush(kArgbTextDim); - Gdiplus::Font titleFont(kFontName, 18.0f, Gdiplus::FontStyleBold, Gdiplus::UnitPixel); + Gdiplus::Font titleFont(kFontName, 16.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); Gdiplus::RectF titleRect(static_cast(kPickTextX), static_cast(kPickTitleY), - static_cast(kPickPanelW - 48), 28.0f); + static_cast(kPickPanelW), 26.0f); std::wstring appName = UPDATER_APP_NAME; std::wstring titleText = appName.empty() ? L"选择安装目录" : (L"选择 " + appName + L" 的安装目录"); @@ -440,17 +454,15 @@ void UpdateWindow::DrawPickPanel(Gdiplus::Graphics& graphics) { Gdiplus::Font hintFont(kFontName, 13.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); Gdiplus::RectF hintRect(static_cast(kPickTextX), static_cast(kPickHintY), - static_cast(kPickPanelW - 48), 22.0f); + static_cast(kPickPanelW), 22.0f); graphics.DrawString(L"请选择程序的安装位置,目录下的同名文件会被覆盖", -1, &hintFont, hintRect, &nearFormat, &dimBrush); - // 路径显示框 - Gdiplus::GraphicsPath boxPath; - AddRoundRect(boxPath, kPathX, kPathY, kPathW, kPathH, 8); - Gdiplus::SolidBrush boxBrush(Gdiplus::Color(130, 8, 10, 16)); - graphics.FillPath(&boxBrush, &boxPath); - Gdiplus::Pen boxPen(Gdiplus::Color(190, 98, 110, 130), 1.0f); - graphics.DrawPath(&boxPen, &boxPath); + // 路径输入框:控件底色 + 灰描边,直角 + Gdiplus::Rect boxRect(kPathX, kPathY, kPathW, kPathH); + Gdiplus::SolidBrush boxBrush(kArgbControl); + graphics.FillRectangle(&boxBrush, boxRect); + DrawHairline(graphics, boxRect, kArgbBorder); Gdiplus::StringFormat pathFormat; pathFormat.SetAlignment(Gdiplus::StringAlignmentNear); @@ -475,7 +487,7 @@ void UpdateWindow::DrawPickPanel(Gdiplus::Graphics& graphics) { } if (!spaceText.empty()) { Gdiplus::RectF spaceRect(static_cast(kPickTextX), static_cast(kSpaceY), - static_cast(kPickPanelW - 48), 22.0f); + static_cast(kPickPanelW), 22.0f); graphics.DrawString(spaceText.c_str(), -1, &hintFont, spaceRect, &nearFormat, &dimBrush); } @@ -484,87 +496,194 @@ void UpdateWindow::DrawPickPanel(Gdiplus::Graphics& graphics) { installState_); } -void UpdateWindow::DrawProgressPanel(Gdiplus::Graphics& graphics) { - Gdiplus::GraphicsPath panelPath; - AddRoundRect(panelPath, kPanelX, kPanelY, kPanelW, kPanelH, 12); - Gdiplus::SolidBrush panelBrush(Gdiplus::Color(150, 12, 16, 24)); - graphics.FillPath(&panelBrush, &panelPath); +// VS 2019 暗色主题:纯色窗口背景 + 一条标题栏,不做渐变和装饰 +void UpdateWindow::DrawBackground(Gdiplus::Graphics& graphics) { + Gdiplus::SolidBrush windowBrush(kArgbWindow); + graphics.FillRectangle(&windowBrush, 0, 0, kWidth, kHeight); - Gdiplus::SolidBrush textBrush(Gdiplus::Color(255, 240, 244, 250)); - Gdiplus::SolidBrush dimBrush(Gdiplus::Color(200, 176, 186, 202)); + Gdiplus::SolidBrush titleBrush(kArgbTitleBar); + graphics.FillRectangle(&titleBrush, 0, 0, kWidth, kTitleH); + + // 标题栏与内容区之间的分隔线,取整像素位置避免被抗锯齿糊掉 + Gdiplus::Pen line(kArgbBorder, 1.0f); + graphics.DrawLine(&line, Gdiplus::PointF(0.0f, static_cast(kTitleH) - 0.5f), + Gdiplus::PointF(static_cast(kWidth), static_cast(kTitleH) - 0.5f)); + + Gdiplus::Font font(kFontName, 12.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::StringFormat format; + format.SetAlignment(Gdiplus::StringAlignmentNear); + format.SetLineAlignment(Gdiplus::StringAlignmentCenter); + format.SetTrimming(Gdiplus::StringTrimmingEllipsisWord); + Gdiplus::SolidBrush textBrush(kArgbTextDim); + Gdiplus::RectF rect(10.0f, 0.0f, static_cast(kWidth - kCloseSize - 16), + static_cast(kTitleH)); + graphics.DrawString(UPDATER_TITLE, -1, &font, rect, &format, &textBrush); +} + +// 更新日志:先量出文本总高度,再按滚动偏移裁剪绘制 +void UpdateWindow::DrawChangelog(Gdiplus::Graphics& graphics) { + Gdiplus::Rect card(kLogX, kLogY, kLogW, kLogH); + Gdiplus::SolidBrush cardBrush(kArgbSurface); + graphics.FillRectangle(&cardBrush, card); + DrawHairline(graphics, card, kArgbBorder); + + Gdiplus::SolidBrush titleBrush(kArgbText); + Gdiplus::Font titleFont(kFontName, 13.0f, Gdiplus::FontStyleBold, Gdiplus::UnitPixel); + Gdiplus::RectF titleRect(static_cast(kLogX + kLogPadX), static_cast(kLogTitleY), + static_cast(kLogTextW), static_cast(kLogTitleH)); + graphics.DrawString(L"更新内容", -1, &titleFont, titleRect, nullptr, &titleBrush); + + std::wstring text = changelogText_.empty() ? L"正在获取更新说明..." : changelogText_; + + Gdiplus::Font textFont(kFontName, 12.5f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::StringFormat format; + format.SetAlignment(Gdiplus::StringAlignmentNear); + format.SetLineAlignment(Gdiplus::StringAlignmentNear); + format.SetTrimming(Gdiplus::StringTrimmingNone); + + Gdiplus::RectF measureRect(0.0f, 0.0f, static_cast(kLogTextW), 10000.0f); + Gdiplus::RectF needed; + graphics.MeasureString(text.c_str(), -1, &textFont, measureRect, &format, &needed); + changelogContentH_ = static_cast(needed.Height + 0.999f); + + int maxScroll = (std::max)(0, changelogContentH_ - kLogTextH); + if (changelogScroll_ > maxScroll) changelogScroll_ = maxScroll; + if (changelogScroll_ < 0) changelogScroll_ = 0; + + graphics.SetClip(Gdiplus::Rect(kLogX + kLogPadX, kLogTextY, kLogTextW, kLogTextH)); + Gdiplus::SolidBrush textBrush(kArgbTextDim); + Gdiplus::RectF drawRect(static_cast(kLogX + kLogPadX), + static_cast(kLogTextY - changelogScroll_), + static_cast(kLogTextW), static_cast(needed.Height)); + graphics.DrawString(text.c_str(), -1, &textFont, drawRect, &format, &textBrush); + graphics.ResetClip(); + + // 内容超出时给个滚动提示 + if (maxScroll > 0) { + Gdiplus::SolidBrush hintBrush(kArgbTextWeak); + Gdiplus::Font hintFont(kFontName, 11.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::StringFormat farFormat; + farFormat.SetAlignment(Gdiplus::StringAlignmentFar); + farFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter); + Gdiplus::RectF hintRect(static_cast(kLogTextW - 150), + static_cast(kLogTitleY), 150.0f, + static_cast(kLogTitleH)); + graphics.DrawString(L"滚轮可滚动", -1, &hintFont, hintRect, &farFormat, &hintBrush); + } +} + +void UpdateWindow::DrawProgressPanel(Gdiplus::Graphics& graphics) { + Gdiplus::SolidBrush textBrush(kArgbText); + Gdiplus::SolidBrush dimBrush(kArgbTextDim); Gdiplus::StringFormat nearFormat; nearFormat.SetAlignment(Gdiplus::StringAlignmentNear); nearFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter); nearFormat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord); - Gdiplus::Font titleFont(kFontName, 18.0f, Gdiplus::FontStyleBold, Gdiplus::UnitPixel); - Gdiplus::RectF titleRect(static_cast(kTextX), static_cast(kTitleY), - static_cast(kPanelW - 48), 28.0f); - graphics.DrawString(UPDATER_TITLE, -1, &titleFont, titleRect, &nearFormat, &textBrush); + std::wstring headText = L"正在检查更新"; + std::wstring subText = UPDATER_APP_NAME; + if (info_.hasUpdate) { + if (!info_.latestVersion.empty()) headText = L"发现新版本 " + info_.latestVersion; + if (!info_.currentVersion.empty() && !info_.latestVersion.empty()) { + subText = L"当前 " + info_.currentVersion + L" → 最新 " + info_.latestVersion; + } + } - Gdiplus::Font statusFont(kFontName, 14.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); - Gdiplus::RectF statusRect(static_cast(kTextX), static_cast(kStatusY), - static_cast(kBarW - 90), 24.0f); + Gdiplus::Font headFont(kFontName, 17.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::RectF headRect(static_cast(kMarginX), static_cast(kHeadY), + static_cast(kWidth - kMarginX * 2 - kCloseSize), + static_cast(kHeadH)); + graphics.DrawString(headText.c_str(), -1, &headFont, headRect, &nearFormat, &textBrush); + + Gdiplus::Font subFont(kFontName, 12.5f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::RectF subRect(static_cast(kMarginX), static_cast(kSubY), + static_cast(kWidth - kMarginX * 2), static_cast(kSubH)); + graphics.DrawString(subText.c_str(), -1, &subFont, subRect, &nearFormat, &dimBrush); + + DrawChangelog(graphics); + + Gdiplus::Font statusFont(kFontName, 13.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); + Gdiplus::RectF statusRect(static_cast(kBarX), static_cast(kStatusY), + static_cast(kBarW - 90), static_cast(kStatusH)); graphics.DrawString(status_.c_str(), -1, &statusFont, statusRect, &nearFormat, &dimBrush); Gdiplus::StringFormat farFormat; farFormat.SetAlignment(Gdiplus::StringAlignmentFar); farFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter); - Gdiplus::Font percentFont(kFontName, 15.0f, Gdiplus::FontStyleBold, Gdiplus::UnitPixel); + Gdiplus::Font percentFont(kFontName, 13.0f, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel); Gdiplus::RectF percentRect(static_cast(kBarX + kBarW - 80), - static_cast(kStatusY), 80.0f, 24.0f); - graphics.DrawString(PercentText(percent_).c_str(), -1, &percentFont, percentRect, - &farFormat, &textBrush); + static_cast(kStatusY), 80.0f, static_cast(kStatusH)); + graphics.DrawString(PercentText(percent_).c_str(), -1, &percentFont, percentRect, &farFormat, + &textBrush); - Gdiplus::GraphicsPath trackPath; - AddRoundRect(trackPath, kBarX, kBarY, kBarW, kBarH, kBarH / 2); - Gdiplus::SolidBrush trackBrush(Gdiplus::Color(200, 48, 54, 68)); - graphics.FillPath(&trackBrush, &trackPath); + Gdiplus::SolidBrush trackBrush(kArgbControl); + graphics.FillRectangle(&trackBrush, kBarX, kBarY, kBarW, kBarH); int fillW = static_cast(static_cast(kBarW) * percent_ / 100.0); - if (fillW > kBarH) { - Gdiplus::GraphicsPath fillPath; - AddRoundRect(fillPath, kBarX, kBarY, fillW, kBarH, kBarH / 2); - + if (fillW > 0) { + // 失败时转 VS 的错误红,正常时是主题蓝 bool failed = finished_ && !success_; - Gdiplus::Color c1 = failed ? Gdiplus::Color(255, 226, 92, 92) - : Gdiplus::Color(255, 88, 196, 248); - Gdiplus::Color c2 = failed ? Gdiplus::Color(255, 198, 58, 72) - : Gdiplus::Color(255, 46, 140, 226); - Gdiplus::LinearGradientBrush fillBrush( - Gdiplus::Point(kBarX, kBarY), Gdiplus::Point(kBarX + fillW, kBarY + kBarH), c1, c2); - graphics.FillPath(&fillBrush, &fillPath); + Gdiplus::SolidBrush fillBrush(failed ? kArgbError : kArgbAccent); + graphics.FillRectangle(&fillBrush, kBarX, kBarY, fillW, kBarH); } } -void UpdateWindow::OnPaint() { - PAINTSTRUCT ps; - HDC hdc = BeginPaint(hwnd_, &ps); +// 标题栏右侧的关闭按钮:悬停/按下时整块变红,和 VS 2019 一致 +void UpdateWindow::DrawCloseButton(Gdiplus::Graphics& graphics) { + int left = kWidth - kCloseSize; - RECT rc; - GetClientRect(hwnd_, &rc); - int width = rc.right - rc.left; - int height = rc.bottom - rc.top; + if (closeState_ != 0) { + Gdiplus::SolidBrush bg(closeState_ == 2 ? kArgbClosePress : kArgbCloseHover); + graphics.FillRectangle(&bg, left, 0, kCloseSize, kTitleH); + } - HDC memDc = CreateCompatibleDC(hdc); - HBITMAP memBmp = CreateCompatibleBitmap(hdc, width, height); - HGDIOBJ old = SelectObject(memDc, memBmp); + float cx = static_cast(left + kCloseSize / 2); + float cy = static_cast(kTitleH / 2); + float a = 5.0f; + Gdiplus::Pen pen(kArgbText, 1.4f); + pen.SetStartCap(Gdiplus::LineCapRound); + pen.SetEndCap(Gdiplus::LineCapRound); + pen.SetLineJoin(Gdiplus::LineJoinRound); + graphics.DrawLine(&pen, cx - a, cy - a, cx + a, cy + a); + graphics.DrawLine(&pen, cx + a, cy - a, cx - a, cy + a); +} + +// 分层窗口:整窗画到 32 位 DIB 上再一次性提交。 +// 圆角、斜切色块、进度条全部走 GDI+ 抗锯齿,边缘不会出现锯齿 +void UpdateWindow::Render() { + if (!hwnd_) return; + + BITMAPINFO bi; + ZeroMemory(&bi, sizeof(bi)); + bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bi.bmiHeader.biWidth = kWidth; + bi.bmiHeader.biHeight = -kHeight; // 负值 = 自上而下,省一次翻转 + bi.bmiHeader.biPlanes = 1; + bi.bmiHeader.biBitCount = 32; + bi.bmiHeader.biCompression = BI_RGB; + + void* bits = nullptr; + HDC screenDc = GetDC(nullptr); + HBITMAP dib = CreateDIBSection(screenDc, &bi, DIB_RGB_COLORS, &bits, nullptr, 0); + ReleaseDC(nullptr, screenDc); + if (!dib || !bits) { + if (dib) DeleteObject(dib); + return; + } + + HDC memDc = CreateCompatibleDC(nullptr); + HGDIOBJ oldBmp = SelectObject(memDc, dib); { - Gdiplus::Graphics graphics(memDc); - graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); + Gdiplus::Bitmap bitmap(kWidth, kHeight, kWidth * 4, PixelFormat32bppARGB, + static_cast(bits)); + Gdiplus::Graphics graphics(&bitmap); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAliasGridFit); - graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic); + graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); + graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf); - if (render_->background && render_->background->GetLastStatus() == Gdiplus::Ok) { - graphics.DrawImage(render_->background, 0, 0, width, height); - } else { - Gdiplus::LinearGradientBrush bgBrush( - Gdiplus::Point(0, 0), Gdiplus::Point(0, height), - Gdiplus::Color(255, 32, 38, 52), Gdiplus::Color(255, 18, 22, 32)); - graphics.FillRectangle(&bgBrush, 0, 0, width, height); - } + DrawBackground(graphics); if (phase_ == Phase::PickDir) { DrawPickPanel(graphics); @@ -572,25 +691,33 @@ void UpdateWindow::OnPaint() { DrawProgressPanel(graphics); } - int closeLeft = kWidth - kCloseMarginX - kCloseSize; - Gdiplus::Image* closeImage = render_->closeImages[closeState_]; - if (closeImage && closeImage->GetLastStatus() == Gdiplus::Ok) { - graphics.DrawImage(closeImage, closeLeft, kCloseMarginY, kCloseSize, kCloseSize); - } else { - Gdiplus::Color penColor(220, 235, 240, 248); - Gdiplus::Pen pen(penColor, 2.0f); - graphics.DrawLine(&pen, closeLeft + 8, kCloseMarginY + 8, closeLeft + kCloseSize - 8, - kCloseMarginY + kCloseSize - 8); - graphics.DrawLine(&pen, closeLeft + kCloseSize - 8, kCloseMarginY + 8, closeLeft + 8, - kCloseMarginY + kCloseSize - 8); - } + DrawCloseButton(graphics); + + DrawHairline(graphics, Gdiplus::Rect(0, 0, kWidth, kHeight), kArgbBorder); } - BitBlt(hdc, 0, 0, width, height, memDc, 0, 0, SRCCOPY); - SelectObject(memDc, old); - DeleteObject(memBmp); + POINT ptSrc = {0, 0}; + RECT wr; + GetWindowRect(hwnd_, &wr); + POINT ptDst = {wr.left, wr.top}; + SIZE size = {kWidth, kHeight}; + BLENDFUNCTION blend; + blend.BlendOp = AC_SRC_OVER; + blend.BlendFlags = 0; + blend.SourceConstantAlpha = 255; + blend.AlphaFormat = AC_SRC_ALPHA; + UpdateLayeredWindow(hwnd_, nullptr, &ptDst, &size, memDc, &ptSrc, 0, &blend, ULW_ALPHA); + + SelectObject(memDc, oldBmp); DeleteDC(memDc); + DeleteObject(dib); +} + +void UpdateWindow::OnPaint() { + PAINTSTRUCT ps; + BeginPaint(hwnd_, &ps); EndPaint(hwnd_, &ps); + Render(); } LRESULT UpdateWindow::HandleMessage(UINT msg, WPARAM wParam, LPARAM lParam) { @@ -637,6 +764,14 @@ LRESULT UpdateWindow::HandleMessage(UINT msg, WPARAM wParam, LPARAM lParam) { return 0; } + case WM_MOUSEWHEEL: { + if (phase_ != Phase::PickDir) { + int delta = GET_WHEEL_DELTA_WPARAM(wParam); + ScrollChangelog(-delta / WHEEL_DELTA * kScrollStep); + } + return 0; + } + case WM_MOUSELEAVE: tracking_ = false; pressed_ = 0; diff --git a/Update/UpdateWindow.h b/Update/UpdateWindow.h index d6d8376..ed0d7b6 100644 --- a/Update/UpdateWindow.h +++ b/Update/UpdateWindow.h @@ -4,6 +4,7 @@ #include +#include "Api.h" #include "Worker.h" namespace Gdiplus { @@ -18,6 +19,8 @@ struct UiState { std::wstring status; bool finished = false; bool success = false; + bool hasInfo = false; // true 时 info 有效,界面据此刷新更新日志 + UpdateInfo info; }; class UpdateWindow { @@ -39,9 +42,15 @@ private: 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(); @@ -72,6 +81,11 @@ private: 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; diff --git a/Update/Utils.cpp b/Update/Utils.cpp index 60119ea..44adf82 100644 --- a/Update/Utils.cpp +++ b/Update/Utils.cpp @@ -3,6 +3,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -11,6 +15,8 @@ #pragma comment(lib, "bcrypt.lib") #pragma comment(lib, "shell32.lib") #pragma comment(lib, "kernel32.lib") +#pragma comment(lib, "ole32.lib") +#pragma comment(lib, "uuid.lib") namespace updater { @@ -407,6 +413,46 @@ bool Utils::CloseProcesses(const std::wstring& processName, int timeoutSec) { return false; } +std::wstring Utils::GetDesktopDir() { + PWSTR path = nullptr; + if (SHGetKnownFolderPath(FOLDERID_Desktop, 0, nullptr, &path) != S_OK) return std::wstring(); + std::wstring dir = path; + CoTaskMemFree(path); + return dir; +} + +bool Utils::CreateDesktopShortcut(const std::wstring& targetPath, const std::wstring& linkName) { + if (linkName.empty() || !FileExists(targetPath)) return false; + + std::wstring dir = GetDesktopDir(); + if (dir.empty()) return false; + + HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + bool needUninit = SUCCEEDED(hr); + // RPC_E_CHANGED_MODE 说明调用方已经初始化过 COM,用它的,不要在这里反初始化 + if (!needUninit && hr != RPC_E_CHANGED_MODE) return false; + + bool ok = false; + IShellLinkW* link = nullptr; + if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, + IID_IShellLinkW, reinterpret_cast(&link)))) { + link->SetPath(targetPath.c_str()); + link->SetWorkingDirectory(GetParentDir(targetPath).c_str()); + + IPersistFile* persist = nullptr; + if (SUCCEEDED(link->QueryInterface(IID_IPersistFile, + reinterpret_cast(&persist)))) { + std::wstring shortcut = JoinPath(dir, linkName + L".lnk"); + ok = SUCCEEDED(persist->Save(shortcut.c_str(), TRUE)); + persist->Release(); + } + link->Release(); + } + + if (needUninit) CoUninitialize(); + return ok; +} + bool Utils::ReplaceInUse(const std::wstring& srcTmp, const std::wstring& target) { if (MoveFileExW(srcTmp.c_str(), target.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) != FALSE) { diff --git a/Update/Utils.h b/Update/Utils.h index d54c9e2..65bbe47 100644 --- a/Update/Utils.h +++ b/Update/Utils.h @@ -44,6 +44,11 @@ public: const std::wstring& workDir); static bool WaitForProcessExit(const std::wstring& processName, int timeoutSec); + // 桌面快捷方式:后台给包里的文件勾选"创建快捷方式"时调用 + static std::wstring GetDesktopDir(); + static bool CreateDesktopShortcut(const std::wstring& targetPath, + const std::wstring& linkName); + // 关闭指定名称的进程:先投递 WM_CLOSE 请求其自行退出,超时后强制结束。 // 运行中的 EXE 无法被覆盖,更新前必须让它们先退出 static bool CloseProcesses(const std::wstring& processName, int timeoutSec); diff --git a/Update/Worker.cpp b/Update/Worker.cpp index 81d2496..0a3b3b8 100644 --- a/Update/Worker.cpp +++ b/Update/Worker.cpp @@ -42,6 +42,15 @@ void CollectFiles(const std::wstring& dir, const std::wstring& relBase, FindClose(handle); } +// 取文件名的主干(去掉目录和扩展名),用作快捷方式名字 +std::wstring StemOf(const std::wstring& path) { + size_t slash = path.find_last_of(L"\\/"); + std::wstring base = (slash == std::wstring::npos) ? path : path.substr(slash + 1); + size_t dot = base.rfind(L'.'); + if (dot == std::wstring::npos || dot == 0) return base; + return base.substr(0, dot); +} + std::vector SplitProcessNames(const std::wstring& text) { std::vector names; std::wstring current; @@ -99,10 +108,12 @@ void Worker::Finish(bool success, const std::wstring& text) { if (onFinish_) onFinish_(success, text); } -void Worker::Start(const UpdateOptions& options, StateCallback onState, FinishCallback onFinish) { +void Worker::Start(const UpdateOptions& options, StateCallback onState, FinishCallback onFinish, + InfoCallback onInfo) { options_ = options; onState_ = onState; onFinish_ = onFinish; + onInfo_ = onInfo; cancel_.store(false); running_.store(true); @@ -203,6 +214,9 @@ void Worker::Run() { return; } + // 先把版本信息交给界面,更新日志可以趁下载的时候显示 + if (onInfo_) onInfo_(info); + // 更新包同时包含多个 EXE,正在运行的无法被覆盖。 // 手动运行更新器时这些进程可能还在跑,必须先让它们退出 std::vector closeNames = SplitProcessNames(UPDATER_CLOSE_PROCESSES); @@ -368,12 +382,33 @@ void Worker::Run() { Emit(100, L"更新完成"); -#if defined(UPDATER_LAUNCH_EXE) - std::wstring launch = options_.launchExe.empty() ? UPDATER_LAUNCH_EXE : options_.launchExe; - if (!launch.empty()) { - Utils::LaunchProcess(Utils::JoinPath(targetDir, launch), L"", targetDir); + // 后台可以给包里的文件勾选"创建快捷方式",装完后按配置在桌面生成 + for (size_t i = 0; i < info.desktopShortcutFiles.size(); ++i) { + std::wstring target = Utils::JoinPath(targetDir, info.desktopShortcutFiles[i]); + if (!Utils::FileExists(target)) continue; + Emit(100, L"正在创建快捷方式 " + StemOf(info.desktopShortcutFiles[i]) + L"..."); + Utils::CreateDesktopShortcut(target, StemOf(info.desktopShortcutFiles[i])); } + + // 启动项:命令行 --launch 优先,其次用后台勾选了"启动"的文件,都没有才回退到编译期配置 + std::vector entries; + if (!options_.launchExe.empty()) { + entries.push_back(options_.launchExe); + } else { + entries = info.entryFiles; + if (entries.empty() && !info.entryFile.empty()) entries.push_back(info.entryFile); +#if defined(UPDATER_LAUNCH_EXE) + if (entries.empty()) { + std::wstring fallback = UPDATER_LAUNCH_EXE; + if (!fallback.empty()) entries.push_back(fallback); + } #endif + } + for (size_t i = 0; i < entries.size(); ++i) { + std::wstring exe = Utils::JoinPath(targetDir, entries[i]); + if (!Utils::FileExists(exe)) continue; + Utils::LaunchProcess(exe, L"", targetDir); + } Finish(true, L"更新完成" + versionText); } diff --git a/Update/Worker.h b/Update/Worker.h index ed6d5fb..b17820e 100644 --- a/Update/Worker.h +++ b/Update/Worker.h @@ -4,6 +4,8 @@ #include #include +#include "Api.h" + namespace updater { struct UpdateOptions { @@ -18,6 +20,8 @@ class Worker { public: using StateCallback = std::function; using FinishCallback = std::function; + // 拿到版本信息后立刻回调,界面用它显示更新日志 + using InfoCallback = std::function; Worker(); ~Worker(); @@ -25,7 +29,8 @@ public: Worker(const Worker&) = delete; Worker& operator=(const Worker&) = delete; - void Start(const UpdateOptions& options, StateCallback onState, FinishCallback onFinish); + void Start(const UpdateOptions& options, StateCallback onState, FinishCallback onFinish, + InfoCallback onInfo = nullptr); void Cancel(); bool running() const { return running_; } @@ -40,6 +45,7 @@ private: UpdateOptions options_; StateCallback onState_; FinishCallback onFinish_; + InfoCallback onInfo_; std::atomic cancel_; std::atomic running_; void* thread_ = nullptr;