From 3cfa255c5a98ba4db8e1bf5eb223909f6753c976 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 15 Nov 2018 09:01:29 +0100 Subject: [PATCH] Updater: Add total progressbar --- Source/Core/Updater/Main.cpp | 19 +++++++---- Source/Core/Updater/UI.cpp | 61 ++++++++++++++++++++++++++---------- Source/Core/Updater/UI.h | 11 +++++-- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/Source/Core/Updater/Main.cpp b/Source/Core/Updater/Main.cpp index 10ae9aadd4..9acd3ece5c 100644 --- a/Source/Core/Updater/Main.cpp +++ b/Source/Core/Updater/Main.cpp @@ -485,7 +485,7 @@ Manifest::Hash ComputeHash(const std::string& contents) bool ProgressCallback(double total, double now, double, double) { - UI::SetProgress(static_cast(now), static_cast(total)); + UI::SetCurrentProgress(static_cast(now), static_cast(total)); return true; } @@ -494,14 +494,18 @@ bool DownloadContent(const std::vector& to_download, { Common::HttpRequest req(std::chrono::seconds(30), ProgressCallback); + UI::SetTotalMarquee(false); + for (size_t i = 0; i < to_download.size(); i++) { + UI::SetTotalProgress(static_cast(i + 1), static_cast(to_download.size())); + auto& download = to_download[i]; std::string hash_filename = HexEncode(download.hash.data(), download.hash.size()); UI::SetDescription("Downloading " + download.filename + "... (File " + std::to_string(i + 1) + " of " + std::to_string(to_download.size()) + ")"); - UI::SetMarquee(false); + UI::SetCurrentMarquee(false); // Add slashes where needed. std::string content_store_path = hash_filename; @@ -515,7 +519,7 @@ bool DownloadContent(const std::vector& to_download, if (!resp) return false; - UI::SetMarquee(true); + UI::SetCurrentMarquee(true); UI::SetDescription("Verifying " + download.filename + "..."); std::string contents(reinterpret_cast(resp->data()), resp->size()); @@ -776,9 +780,12 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine CleanUpTempDir(temp_dir, todo); - UI::ResetProgress(); - UI::SetMarquee(false); - UI::SetProgress(100, 100); + UI::ResetCurrentProgress(); + UI::ResetTotalProgress(); + UI::SetCurrentMarquee(false); + UI::SetTotalMarquee(false); + UI::SetCurrentProgress(0, 1); + UI::SetTotalProgress(1, 1); UI::SetDescription("Done!"); // Let the user process that we are done. diff --git a/Source/Core/Updater/UI.cpp b/Source/Core/Updater/UI.cpp index 43abd0362a..ed4aab9196 100644 --- a/Source/Core/Updater/UI.cpp +++ b/Source/Core/Updater/UI.cpp @@ -16,7 +16,8 @@ namespace { HWND window_handle = nullptr; HWND label_handle = nullptr; -HWND progressbar_handle = nullptr; +HWND total_progressbar_handle = nullptr; +HWND current_progressbar_handle = nullptr; ITaskbarList3* taskbar_list = nullptr; Common::Flag running; @@ -64,10 +65,16 @@ bool Init() SendMessage(label_handle, WM_SETFONT, reinterpret_cast(CreateFontIndirect(&metrics.lfMessageFont)), 0); - progressbar_handle = CreateWindow(PROGRESS_CLASS, NULL, PROGRESSBAR_FLAGS, 5, 25, 470, 25, - window_handle, nullptr, nullptr, 0); + total_progressbar_handle = CreateWindow(PROGRESS_CLASS, NULL, PROGRESSBAR_FLAGS, 5, 25, 470, 25, + window_handle, nullptr, nullptr, 0); - if (!progressbar_handle) + if (!total_progressbar_handle) + return false; + + current_progressbar_handle = CreateWindow(PROGRESS_CLASS, NULL, PROGRESSBAR_FLAGS, 5, 30, 470, 25, + window_handle, nullptr, nullptr, 0); + + if (!current_progressbar_handle) return false; return true; @@ -77,20 +84,42 @@ void Destroy() { DestroyWindow(window_handle); DestroyWindow(label_handle); - DestroyWindow(progressbar_handle); + DestroyWindow(total_progressbar_handle); + DestroyWindow(current_progressbar_handle); } -void SetMarquee(bool marquee) +void SetTotalMarquee(bool marquee) { - SetWindowLong(progressbar_handle, GWL_STYLE, PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0)); - SendMessage(progressbar_handle, PBM_SETMARQUEE, marquee, 0); + SetWindowLong(total_progressbar_handle, GWL_STYLE, + PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0)); + SendMessage(total_progressbar_handle, PBM_SETMARQUEE, marquee, 0); taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL); } -void ResetProgress() +void ResetTotalProgress() { - SendMessage(progressbar_handle, PBM_SETPOS, 0, 0); - SetMarquee(true); + SendMessage(total_progressbar_handle, PBM_SETPOS, 0, 0); + SetCurrentMarquee(true); +} + +void SetTotalProgress(int current, int total) +{ + SendMessage(total_progressbar_handle, PBM_SETRANGE32, 0, total); + SendMessage(total_progressbar_handle, PBM_SETPOS, current, 0); + taskbar_list->SetProgressValue(window_handle, current, total); +} + +void SetCurrentMarquee(bool marquee) +{ + SetWindowLong(current_progressbar_handle, GWL_STYLE, + PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0)); + SendMessage(current_progressbar_handle, PBM_SETMARQUEE, marquee, 0); +} + +void ResetCurrentProgress() +{ + SendMessage(current_progressbar_handle, PBM_SETPOS, 0, 0); + SetCurrentMarquee(true); } void Error(const std::string& text) @@ -104,11 +133,10 @@ void Error(const std::string& text) taskbar_list->SetProgressState(window_handle, TBPF_ERROR); } -void SetProgress(int current, int total) +void SetCurrentProgress(int current, int total) { - SendMessage(progressbar_handle, PBM_SETRANGE32, 0, total); - SendMessage(progressbar_handle, PBM_SETPOS, current, 0); - taskbar_list->SetProgressValue(window_handle, current, total); + SendMessage(current_progressbar_handle, PBM_SETRANGE32, 0, total); + SendMessage(current_progressbar_handle, PBM_SETPOS, current, 0); } void SetDescription(const std::string& text) @@ -127,7 +155,8 @@ void MessageLoop() MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR); } - SetMarquee(true); + SetTotalMarquee(true); + SetCurrentMarquee(true); while (!request_stop.IsSet()) { diff --git a/Source/Core/Updater/UI.h b/Source/Core/Updater/UI.h index 6b892f5b27..f0c1a6401a 100644 --- a/Source/Core/Updater/UI.h +++ b/Source/Core/Updater/UI.h @@ -13,7 +13,12 @@ void Error(const std::string& text); void Stop(); void SetDescription(const std::string& text); -void SetMarquee(bool marquee); -void ResetProgress(); -void SetProgress(int current, int total); + +void SetTotalMarquee(bool marquee); +void ResetTotalProgress(); +void SetTotalProgress(int current, int total); + +void SetCurrentMarquee(bool marquee); +void ResetCurrentProgress(); +void SetCurrentProgress(int current, int total); } // namespace UI