summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/PackUpdater/Src/Utils.cpp14
-rw-r--r--plugins/SmileyAdd/src/download.cpp31
2 files changed, 13 insertions, 32 deletions
diff --git a/plugins/PackUpdater/Src/Utils.cpp b/plugins/PackUpdater/Src/Utils.cpp
index 7c3212388e..17b9f100f1 100644
--- a/plugins/PackUpdater/Src/Utils.cpp
+++ b/plugins/PackUpdater/Src/Utils.cpp
@@ -116,17 +116,9 @@ BOOL DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
nlhr.AddHeader("Pragma", "no-cache");
bool ret = false;
- NLHR_PTR pReply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
- if (pReply) {
- if (200 == pReply->resultCode && !pReply->body.IsEmpty()) {
- HANDLE hFile = CreateFile(tszLocal, GENERIC_READ | GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- DWORD dwBytes;
- WriteFile(hFile, pReply->body, pReply->body.GetLength(), &dwBytes, nullptr);
- ret = true;
- if (hFile)
- CloseHandle(hFile);
- }
- }
+ NLHR_PTR pReply(Netlib_DownloadFile(hNetlibUser, &nlhr, tszLocal));
+ if (pReply && pReply->resultCode == 200)
+ ret = true;
DlgDld = ret;
return ret;
diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp
index 0695876acc..978e00c72f 100644
--- a/plugins/SmileyAdd/src/download.cpp
+++ b/plugins/SmileyAdd/src/download.cpp
@@ -39,7 +39,7 @@ static LIST<QueueElem> dlQueue(10);
static wchar_t g_wszCachePath[MAX_PATH];
static bool threadRunning;
-bool InternetDownloadFile(const char *szUrl, char *szDest, HNETLIBCONN &hHttpDwnl)
+static bool InternetDownloadFile(const char *szUrl, const wchar_t *szDest, HNETLIBCONN &hHttpDwnl)
{
int result = 0xBADBAD;
@@ -53,33 +53,22 @@ bool InternetDownloadFile(const char *szUrl, char *szDest, HNETLIBCONN &hHttpDwn
nlhr.AddHeader("User-Agent", NETLIB_USER_AGENT);
nlhr.AddHeader("Connection", "close");
+ CreatePathToFileW(szDest);
+
while (result == 0xBADBAD) {
// download the page
- NLHR_PTR nlhrReply(Netlib_HttpTransaction(hNetlibUser, &nlhr));
+ NLHR_PTR nlhrReply(Netlib_DownloadFile(hNetlibUser, &nlhr, szDest));
if (nlhrReply) {
hHttpDwnl = nlhrReply->nlc;
// if the recieved code is 200 OK
- if (nlhrReply->resultCode == 200) {
- char *delim = strrchr(szDest, '\\');
- if (delim) *delim = '\0';
- CreateDirectoryTree(szDest);
- if (delim) *delim = '\\';
- int res = -1;
- int fh = _open(szDest, _O_BINARY | _O_WRONLY | _O_CREAT, _S_IREAD | _S_IWRITE);
- if (fh != -1) {
- res = _write(fh, nlhrReply->body, nlhrReply->body.GetLength());
- _close(fh);
- }
- if (res < 0)
- remove(szDest);
- else
- result = 0;
- }
- else result = 1;
+ if (nlhrReply->resultCode == 200)
+ result = 0;
+ else
+ result = 1;
}
else {
+ // retry
hHttpDwnl = nullptr;
- result = 1;
}
}
@@ -109,7 +98,7 @@ void __cdecl SmileyDownloadThread(void*)
}
if (_waccess(pItem->fname.c_str(), 0) != 0) {
- InternetDownloadFile(_T2A(pItem->url.c_str()), _T2A(pItem->fname.c_str()), hHttpDwnl);
+ InternetDownloadFile(_T2A(pItem->url.c_str()), pItem->fname, hHttpDwnl);
CMStringW fname(pItem->fname);
if (pItem->needext) {