diff options
author | George Hazan <ghazan@miranda.im> | 2021-04-14 13:29:17 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-04-14 13:29:17 +0300 |
commit | cbad4c760c68777c81015fa913479e70c36c9ca3 (patch) | |
tree | c3e322e5a96e404ed8c0ae8bc7a9a828e701d245 /plugins/PluginUpdater/src/Utils.cpp | |
parent | 3ba27f55a06359924d116eecbb0b233a291a0c9f (diff) |
fixes #2846 (Plugin Updater: more informative error messages, if updates are postponed)
Diffstat (limited to 'plugins/PluginUpdater/src/Utils.cpp')
-rw-r--r-- | plugins/PluginUpdater/src/Utils.cpp | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index f76e47237e..9d05d695b1 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -49,12 +49,15 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) pFileUrl.CRCsum = 0;
HNETLIBCONN nlc = nullptr;
- bool ret = DownloadFile(&pFileUrl, nlc);
+ int ret = DownloadFile(&pFileUrl, nlc);
Netlib_CloseHandle(nlc);
- if (!ret) {
- Netlib_LogfW(g_hNetlibUser, L"Downloading list of available updates from %s failed", baseUrl.get());
- ShowPopup(TranslateT("Plugin Updater"), TranslateT("An error occurred while checking for new updates."), POPUP_TYPE_ERROR);
+ if (ret != ERROR_SUCCESS) {
+ Netlib_LogfW(g_hNetlibUser, L"Downloading list of available updates from %s failed with error %d", baseUrl.get(), ret);
+ if (ret == 404)
+ ShowPopup(TranslateT("Plugin Updater"), TranslateT("Updates are temporarily disabled, try again later."), POPUP_TYPE_INFO);
+ else
+ ShowPopup(TranslateT("Plugin Updater"), TranslateT("An error occurred while checking for new updates."), POPUP_TYPE_ERROR);
Skin_PlaySound("updatefailed");
return false;
}
@@ -122,7 +125,7 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) /////////////////////////////////////////////////////////////////////////////////////////
// Single file HTTP transaction
-bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
+int DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc)
{
char szMirVer[100];
Miranda_GetVersionText(szMirVer, _countof(szMirVer));
@@ -162,49 +165,53 @@ bool DownloadFile(FILEURL *pFileURL, HNETLIBCONN &nlc) for (int i = 0; i < MAX_RETRIES; i++) {
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s to %s (attempt %d)", pFileURL->wszDownloadURL, pFileURL->wszDiskPath, i + 1);
NLHR_PTR pReply(Netlib_HttpTransaction(g_hNetlibUser, &nlhr));
- if (pReply) {
- nlc = pReply->nlc;
- if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) {
- // Check CRC sum
- if (pFileURL->CRCsum) {
- int crc = crc32(0, (unsigned char *)pReply->pData, pReply->dataLength);
- if (crc != pFileURL->CRCsum) {
- // crc check failed, try again
- Netlib_LogfW(g_hNetlibUser, L"crc check failed for file %s", pFileURL->wszDiskPath);
- continue;
- }
- }
+ if (pReply == nullptr) {
+ Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed, host is propably temporary down.", pFileURL->wszDownloadURL);
+ nlc = nullptr;
+ continue;
+ }
- DWORD dwBytes;
- HANDLE hFile = CreateFile(pFileURL->wszDiskPath, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (hFile != INVALID_HANDLE_VALUE) {
- // write the downloaded file directly
- WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
- CloseHandle(hFile);
- }
- else {
- // try to write it via PU stub
- TFileName wszTempFile;
- mir_snwprintf(wszTempFile, L"%s\\pulocal.tmp", g_wszTempPath);
- hFile = CreateFile(wszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (hFile != INVALID_HANDLE_VALUE) {
- WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
- CloseHandle(hFile);
- PU::SafeMoveFile(wszTempFile, pFileURL->wszDiskPath);
- }
- }
- return true;
- }
+ nlc = pReply->nlc;
+ if (pReply->resultCode != 200 || pReply->dataLength <= 0) {
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed with error %d", pFileURL->wszDownloadURL, pReply->resultCode);
+ return pReply->resultCode;
+ }
+
+ // Check CRC sum
+ if (pFileURL->CRCsum) {
+ int crc = crc32(0, (unsigned char *)pReply->pData, pReply->dataLength);
+ if (crc != pFileURL->CRCsum) {
+ // crc check failed, try again
+ Netlib_LogfW(g_hNetlibUser, L"crc check failed for file %s", pFileURL->wszDiskPath);
+ continue;
+ }
+ }
+
+ // everything is ok, write file down
+ DWORD dwBytes;
+ HANDLE hFile = CreateFile(pFileURL->wszDiskPath, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ // write the downloaded file directly
+ WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
+ CloseHandle(hFile);
}
else {
- Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed, host is propably temporary down.", pFileURL->wszDownloadURL);
- nlc = nullptr;
+ // try to write it via PU stub
+ TFileName wszTempFile;
+ mir_snwprintf(wszTempFile, L"%s\\pulocal.tmp", g_wszTempPath);
+ hFile = CreateFile(wszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, nullptr);
+ CloseHandle(hFile);
+ PU::SafeMoveFile(wszTempFile, pFileURL->wszDiskPath);
+ }
}
+ return ERROR_SUCCESS;
}
+ // no more retries, return previous error code
Netlib_LogfW(g_hNetlibUser, L"Downloading file %s failed, giving up", pFileURL->wszDownloadURL);
- return false;
+ return 500;
}
/////////////////////////////////////////////////////////////////////////////////////////
|