summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/PluginUpdater/src')
-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);