summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-01-18 11:28:11 +0000
committerRobert Pösel <robyer@seznam.cz>2014-01-18 11:28:11 +0000
commit6c3ade3e7558cd2f2b4dc7f9fd85a322e18842dc (patch)
tree8b9e486d0d8c3a0dd504158fa8a2930b4dbeed50 /plugins/PluginUpdater
parente4c3968458eeb254d5877f10b3ea81743e06bd98 (diff)
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
Diffstat (limited to 'plugins/PluginUpdater')
-rw-r--r--plugins/PluginUpdater/src/Common.h2
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp59
2 files changed, 34 insertions, 27 deletions
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);