Updater: Add total progressbar
This commit is contained in:
parent
4271a0ab97
commit
3cfa255c5a
|
@ -485,7 +485,7 @@ Manifest::Hash ComputeHash(const std::string& contents)
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -494,14 +494,18 @@ bool DownloadContent(const std::vector<TodoList::DownloadOp>& 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<int>(i + 1), static_cast<int>(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<TodoList::DownloadOp>& to_download,
|
|||
if (!resp)
|
||||
return false;
|
||||
|
||||
UI::SetMarquee(true);
|
||||
UI::SetCurrentMarquee(true);
|
||||
UI::SetDescription("Verifying " + download.filename + "...");
|
||||
|
||||
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);
|
||||
|
||||
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.
|
||||
|
|
|
@ -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<WPARAM>(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())
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue