[RAPPS] reduce the chance assert failed

This commit is contained in:
赫杨 2020-08-16 03:38:28 +08:00 committed by Mark Jansen
parent 4c524ee3d5
commit c5e111427c
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B

View file

@ -149,6 +149,7 @@ public:
UINT uiPercentage = ((ULONGLONG) ulProgress * 100) / ulProgressMax; UINT uiPercentage = ((ULONGLONG) ulProgress * 100) / ulProgressMax;
/* send the current progress to the progress bar */ /* send the current progress to the progress bar */
if (!IsWindow()) return;
SendMessage(PBM_SETPOS, uiPercentage, 0); SendMessage(PBM_SETPOS, uiPercentage, 0);
/* format total download size */ /* format total download size */
@ -163,6 +164,7 @@ public:
else else
{ {
/* send the current progress to the progress bar */ /* send the current progress to the progress bar */
if (!IsWindow()) return;
SendMessage(PBM_SETPOS, 0, 0); SendMessage(PBM_SETPOS, 0, 0);
/* total size is not known, display only current size */ /* total size is not known, display only current size */
@ -170,6 +172,7 @@ public:
} }
/* and finally display it */ /* and finally display it */
if (!IsWindow()) return;
SendMessage(WM_SETTEXT, 0, (LPARAM) ProgressText.GetString()); SendMessage(WM_SETTEXT, 0, (LPARAM) ProgressText.GetString());
} }
@ -492,8 +495,10 @@ VOID CDownloadManager::UpdateProgress(
{ {
HWND Item; HWND Item;
if (!IsWindow(hDlg)) return;
ProgressBar.SetProgress(ulProgress, ulProgressMax); ProgressBar.SetProgress(ulProgress, ulProgressMax);
if (!IsWindow(hDlg)) return;
Item = GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS); Item = GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS);
if (Item && szStatusText && wcslen(szStatusText) > 0 && UrlHasBeenCopied == FALSE) if (Item && szStatusText && wcslen(szStatusText) > 0 && UrlHasBeenCopied == FALSE)
{ {
@ -580,6 +585,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
for (iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId) for (iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId)
{ {
// Reset progress bar // Reset progress bar
if (!IsWindow(hDlg)) break;
Item = GetDlgItem(hDlg, IDC_DOWNLOAD_PROGRESS); Item = GetDlgItem(hDlg, IDC_DOWNLOAD_PROGRESS);
if (Item) if (Item)
{ {
@ -616,7 +622,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
break; break;
} }
if (!IsWindow(hDlg)) goto end;
SetWindowTextW(hDlg, szNewCaption.GetString()); SetWindowTextW(hDlg, szNewCaption.GetString());
// build the path for the download // build the path for the download
@ -671,6 +677,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
} }
// Add the download URL // Add the download URL
if (!IsWindow(hDlg)) goto end;
SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, InfoArray[iAppId].szUrl.GetString()); SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, InfoArray[iAppId].szUrl.GetString());
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_DOWNLOADING); DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_DOWNLOADING);
@ -832,6 +839,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
} }
dwCurrentBytesRead += dwBytesRead; dwCurrentBytesRead += dwBytesRead;
if (!IsWindow(hDlg)) goto end;
UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString()); UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
} while (dwBytesRead && !bCancelled); } while (dwBytesRead && !bCancelled);
@ -850,6 +858,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
ProgressBar.SetMarquee(FALSE); ProgressBar.SetMarquee(FALSE);
dwContentLen = dwCurrentBytesRead; dwContentLen = dwCurrentBytesRead;
if (!IsWindow(hDlg)) goto end;
UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString()); UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
} }
@ -866,6 +875,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
goto end; goto end;
} }
if (!IsWindow(hDlg)) goto end;
SetWindowTextW(hDlg, szMsgText.GetString()); SetWindowTextW(hDlg, szMsgText.GetString());
SendMessageW(GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString()); SendMessageW(GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString());
@ -878,6 +888,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
goto end; goto end;
} }
if (!IsWindow(hDlg)) goto end;
MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR); MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
goto end; goto end;
} }
@ -902,6 +913,7 @@ run:
//reflect installation progress in the titlebar //reflect installation progress in the titlebar
//TODO: make a separate string with a placeholder to include app name? //TODO: make a separate string with a placeholder to include app name?
ATL::CStringW szMsgText = LoadStatusString(DLSTATUS_INSTALLING); ATL::CStringW szMsgText = LoadStatusString(DLSTATUS_INSTALLING);
if (!IsWindow(hDlg)) goto end;
SetWindowTextW(hDlg, szMsgText.GetString()); SetWindowTextW(hDlg, szMsgText.GetString());
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_INSTALLING); DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_INSTALLING);
@ -929,10 +941,12 @@ end:
DeleteFileW(Path.GetString()); DeleteFileW(Path.GetString());
} }
if (!IsWindow(hDlg)) return 0;
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_FINISHED); DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_FINISHED);
} }
delete static_cast<DownloadParam*>(param); delete static_cast<DownloadParam*>(param);
if (!IsWindow(hDlg)) return 0;
SendMessageW(hDlg, WM_CLOSE, 0, 0); SendMessageW(hDlg, WM_CLOSE, 0, 0);
return 0; return 0;
} }