Updater: Add total progressbar

This commit is contained in:
spycrab 2018-11-15 09:01:29 +01:00
parent 4271a0ab97
commit 3cfa255c5a
3 changed files with 66 additions and 25 deletions

View File

@ -485,7 +485,7 @@ Manifest::Hash ComputeHash(const std::string& contents)
bool ProgressCallback(double total, double now, double, double) bool ProgressCallback(double total, double now, double, double)
{ {
UI::SetProgress(static_cast<int>(now), static_cast<int>(total)); UI::SetCurrentProgress(static_cast<int>(now), static_cast<int>(total));
return true; return true;
} }
@ -494,14 +494,18 @@ bool DownloadContent(const std::vector<TodoList::DownloadOp>& to_download,
{ {
Common::HttpRequest req(std::chrono::seconds(30), ProgressCallback); Common::HttpRequest req(std::chrono::seconds(30), ProgressCallback);
UI::SetTotalMarquee(false);
for (size_t i = 0; i < to_download.size(); i++) for (size_t i = 0; i < to_download.size(); i++)
{ {
UI::SetTotalProgress(static_cast<int>(i + 1), static_cast<int>(to_download.size()));
auto& download = to_download[i]; auto& download = to_download[i];
std::string hash_filename = HexEncode(download.hash.data(), download.hash.size()); std::string hash_filename = HexEncode(download.hash.data(), download.hash.size());
UI::SetDescription("Downloading " + download.filename + "... (File " + std::to_string(i + 1) + UI::SetDescription("Downloading " + download.filename + "... (File " + std::to_string(i + 1) +
" of " + std::to_string(to_download.size()) + ")"); " of " + std::to_string(to_download.size()) + ")");
UI::SetMarquee(false); UI::SetCurrentMarquee(false);
// Add slashes where needed. // Add slashes where needed.
std::string content_store_path = hash_filename; std::string content_store_path = hash_filename;
@ -515,7 +519,7 @@ bool DownloadContent(const std::vector<TodoList::DownloadOp>& to_download,
if (!resp) if (!resp)
return false; return false;
UI::SetMarquee(true); UI::SetCurrentMarquee(true);
UI::SetDescription("Verifying " + download.filename + "..."); UI::SetDescription("Verifying " + download.filename + "...");
std::string contents(reinterpret_cast<char*>(resp->data()), resp->size()); std::string contents(reinterpret_cast<char*>(resp->data()), resp->size());
@ -776,9 +780,12 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
CleanUpTempDir(temp_dir, todo); CleanUpTempDir(temp_dir, todo);
UI::ResetProgress(); UI::ResetCurrentProgress();
UI::SetMarquee(false); UI::ResetTotalProgress();
UI::SetProgress(100, 100); UI::SetCurrentMarquee(false);
UI::SetTotalMarquee(false);
UI::SetCurrentProgress(0, 1);
UI::SetTotalProgress(1, 1);
UI::SetDescription("Done!"); UI::SetDescription("Done!");
// Let the user process that we are done. // Let the user process that we are done.

View File

@ -16,7 +16,8 @@ namespace
{ {
HWND window_handle = nullptr; HWND window_handle = nullptr;
HWND label_handle = nullptr; HWND label_handle = nullptr;
HWND progressbar_handle = nullptr; HWND total_progressbar_handle = nullptr;
HWND current_progressbar_handle = nullptr;
ITaskbarList3* taskbar_list = nullptr; ITaskbarList3* taskbar_list = nullptr;
Common::Flag running; Common::Flag running;
@ -64,10 +65,16 @@ bool Init()
SendMessage(label_handle, WM_SETFONT, SendMessage(label_handle, WM_SETFONT,
reinterpret_cast<WPARAM>(CreateFontIndirect(&metrics.lfMessageFont)), 0); reinterpret_cast<WPARAM>(CreateFontIndirect(&metrics.lfMessageFont)), 0);
progressbar_handle = CreateWindow(PROGRESS_CLASS, NULL, PROGRESSBAR_FLAGS, 5, 25, 470, 25, total_progressbar_handle = CreateWindow(PROGRESS_CLASS, NULL, PROGRESSBAR_FLAGS, 5, 25, 470, 25,
window_handle, nullptr, nullptr, 0); 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 false;
return true; return true;
@ -77,20 +84,42 @@ void Destroy()
{ {
DestroyWindow(window_handle); DestroyWindow(window_handle);
DestroyWindow(label_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)); SetWindowLong(total_progressbar_handle, GWL_STYLE,
SendMessage(progressbar_handle, PBM_SETMARQUEE, marquee, 0); PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0));
SendMessage(total_progressbar_handle, PBM_SETMARQUEE, marquee, 0);
taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL); taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL);
} }
void ResetProgress() void ResetTotalProgress()
{ {
SendMessage(progressbar_handle, PBM_SETPOS, 0, 0); SendMessage(total_progressbar_handle, PBM_SETPOS, 0, 0);
SetMarquee(true); 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) void Error(const std::string& text)
@ -104,11 +133,10 @@ void Error(const std::string& text)
taskbar_list->SetProgressState(window_handle, TBPF_ERROR); 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(current_progressbar_handle, PBM_SETRANGE32, 0, total);
SendMessage(progressbar_handle, PBM_SETPOS, current, 0); SendMessage(current_progressbar_handle, PBM_SETPOS, current, 0);
taskbar_list->SetProgressValue(window_handle, current, total);
} }
void SetDescription(const std::string& text) void SetDescription(const std::string& text)
@ -127,7 +155,8 @@ void MessageLoop()
MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR); MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR);
} }
SetMarquee(true); SetTotalMarquee(true);
SetCurrentMarquee(true);
while (!request_stop.IsSet()) while (!request_stop.IsSet())
{ {

View File

@ -13,7 +13,12 @@ void Error(const std::string& text);
void Stop(); void Stop();
void SetDescription(const std::string& text); void SetDescription(const std::string& text);
void SetMarquee(bool marquee);
void ResetProgress(); void SetTotalMarquee(bool marquee);
void SetProgress(int current, int total); void ResetTotalProgress();
void SetTotalProgress(int current, int total);
void SetCurrentMarquee(bool marquee);
void ResetCurrentProgress();
void SetCurrentProgress(int current, int total);
} // namespace UI } // namespace UI