Merge pull request #7583 from delroth/updater-crash

Fix Updater crashes with new taskbar integration feature
This commit is contained in:
Pierre Bourdon 2018-11-22 02:59:53 +01:00 committed by GitHub
commit fe8854db43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 4 deletions

View File

@ -47,7 +47,16 @@ bool Init()
if (!window_handle) if (!window_handle)
return false; return false;
CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&taskbar_list)); if (FAILED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&taskbar_list))))
{
taskbar_list = nullptr;
}
if (taskbar_list && FAILED(taskbar_list->HrInit()))
{
taskbar_list->Release();
taskbar_list = nullptr;
}
label_handle = CreateWindow(L"STATIC", NULL, WS_VISIBLE | WS_CHILD, 5, 5, 500, 25, window_handle, label_handle = CreateWindow(L"STATIC", NULL, WS_VISIBLE | WS_CHILD, 5, 5, 500, 25, window_handle,
nullptr, nullptr, 0); nullptr, nullptr, 0);
@ -93,7 +102,10 @@ void SetTotalMarquee(bool marquee)
SetWindowLong(total_progressbar_handle, GWL_STYLE, SetWindowLong(total_progressbar_handle, GWL_STYLE,
PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0)); PROGRESSBAR_FLAGS | (marquee ? PBS_MARQUEE : 0));
SendMessage(total_progressbar_handle, PBM_SETMARQUEE, marquee, 0); SendMessage(total_progressbar_handle, PBM_SETMARQUEE, marquee, 0);
taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL); if (taskbar_list)
{
taskbar_list->SetProgressState(window_handle, marquee ? TBPF_INDETERMINATE : TBPF_NORMAL);
}
} }
void ResetTotalProgress() void ResetTotalProgress()
@ -106,7 +118,10 @@ void SetTotalProgress(int current, int total)
{ {
SendMessage(total_progressbar_handle, PBM_SETRANGE32, 0, total); SendMessage(total_progressbar_handle, PBM_SETRANGE32, 0, total);
SendMessage(total_progressbar_handle, PBM_SETPOS, current, 0); SendMessage(total_progressbar_handle, PBM_SETPOS, current, 0);
taskbar_list->SetProgressValue(window_handle, current, total); if (taskbar_list)
{
taskbar_list->SetProgressValue(window_handle, current, total);
}
} }
void SetCurrentMarquee(bool marquee) void SetCurrentMarquee(bool marquee)
@ -130,7 +145,10 @@ void Error(const std::string& text)
(L"A fatal error occured and the updater cannot continue:\n " + wide_text).c_str(), (L"A fatal error occured and the updater cannot continue:\n " + wide_text).c_str(),
L"Error", MB_ICONERROR); L"Error", MB_ICONERROR);
taskbar_list->SetProgressState(window_handle, TBPF_ERROR); if (taskbar_list)
{
taskbar_list->SetProgressState(window_handle, TBPF_ERROR);
}
} }
void SetCurrentProgress(int current, int total) void SetCurrentProgress(int current, int total)