From 6c3ade3e7558cd2f2b4dc7f9fd85a322e18842dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sat, 18 Jan 2014 11:28:11 +0000 Subject: PluginUpdater: try to download file once more if there is some error git-svn-id: http://svn.miranda-ng.org/main/trunk@7712 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/Common.h | 2 ++ plugins/PluginUpdater/src/Utils.cpp | 59 ++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 27 deletions(-) (limited to 'plugins') diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h index 4b3a8c570e..fe55e8fafd 100644 --- a/plugins/PluginUpdater/src/Common.h +++ b/plugins/PluginUpdater/src/Common.h @@ -110,6 +110,8 @@ struct PlugOptions #define DEFAULT_UPDATE_URL_TRUNK "http://miranda-ng.org/distr/x%platform%" #define DEFAULT_UPDATE_URL_TRUNK_SYMBOLS "http://miranda-ng.now.im/pdb_x%platform%/" +#define MAX_RETRIES 2 + #define IDINFO 3 #define IDDOWNLOAD 4 #define IDDOWNLOADALL 5 diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index d7171e4f71..1d5824666c 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -290,45 +290,50 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal, int CRCsum, HANDLE &nlc) nlhr.headers[3].szValue = "no-cache"; bool ret = false; - NETLIBHTTPREQUEST *pReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser,(LPARAM)&nlhr); - if (pReply) { - nlc = pReply->nlc; - if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) { - HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile != INVALID_HANDLE_VALUE) { - // write the downloaded file firectly - WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL); - CloseHandle(hFile); - if (CRCsum) { - InitCrcTable(); - int crc = Get_CRC((unsigned char*)pReply->pData, (long)dwBytes); - if (crc == CRCsum) - ret = true; - } else - ret = true; - } - else { - // try to write it via PU stub - TCHAR tszTempFile[MAX_PATH]; - mir_sntprintf(tszTempFile, SIZEOF(tszTempFile), _T("%s\\pulocal.tmp"), tszTempPath); - hFile = CreateFile(tszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + for (int i = 0; !ret && i < MAX_RETRIES; i++) { + NETLIBHTTPREQUEST *pReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&nlhr); + if (pReply) { + nlc = pReply->nlc; + if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) { + HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { + // write the downloaded file directly WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL); CloseHandle(hFile); - SafeMoveFile(tszTempFile, tszLocal); if (CRCsum) { InitCrcTable(); int crc = Get_CRC((unsigned char*)pReply->pData, (long)dwBytes); if (crc == CRCsum) ret = true; - } else + } + else ret = true; } + else { + // try to write it via PU stub + TCHAR tszTempFile[MAX_PATH]; + mir_sntprintf(tszTempFile, SIZEOF(tszTempFile), _T("%s\\pulocal.tmp"), tszTempPath); + hFile = CreateFile(tszTempFile, GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile != INVALID_HANDLE_VALUE) { + WriteFile(hFile, pReply->pData, (DWORD)pReply->dataLength, &dwBytes, NULL); + CloseHandle(hFile); + SafeMoveFile(tszTempFile, tszLocal); + if (CRCsum) { + InitCrcTable(); + int crc = Get_CRC((unsigned char*)pReply->pData, (long)dwBytes); + if (crc == CRCsum) + ret = true; + } + else + ret = true; + } + } } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pReply); + } + else { + nlc = NULL; } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pReply); - } else { - nlc = NULL; } mir_free(szUrl); -- cgit v1.2.3