From 730c132f369842cd219388905cf981c2e90f98b3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 10 Jan 2024 12:11:16 +0300 Subject: code cleaning --- protocols/Twitter/src/connection.cpp | 11 +++++++++-- protocols/Twitter/src/utility.cpp | 29 ----------------------------- protocols/Twitter/src/utility.h | 2 -- 3 files changed, 9 insertions(+), 33 deletions(-) (limited to 'protocols/Twitter') diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp index 3cf4673d27..438572eb7e 100644 --- a/protocols/Twitter/src/connection.cpp +++ b/protocols/Twitter/src/connection.cpp @@ -164,7 +164,9 @@ void CTwitterProto::UpdateAvatarWorker(void *p) return; CMStringA ext = data->url.Mid(data->url.ReverseFind('.')); // finds the filetype of the avatar - CMStringW filename(FORMAT, L"%s\\%S%S", GetAvatarFolder().c_str(), username.c_str(), ext.c_str()); // local filename and path + + MFilePath filename; // local filename and path + filename.Format(L"%s\\%S%S", GetAvatarFolder().c_str(), username.c_str(), ext.c_str()); PROTO_AVATAR_INFORMATION ai = { 0 }; ai.hContact = data->hContact; @@ -185,7 +187,12 @@ void CTwitterProto::UpdateAvatarWorker(void *p) return; } - if (save_url(hAvatarNetlib_, data->url, filename)) { + MHttpRequest req(REQUEST_GET); + req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT; + req.m_szUrl = data->url; + + NLHR_PTR resp(Netlib_DownloadFile(hAvatarNetlib_, &req, filename)); + if (resp && resp->resultCode == 200) { setString(data->hContact, TWITTER_KEY_AV_URL, data->url.c_str()); ProtoBroadcastAck(data->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai); } diff --git a/protocols/Twitter/src/utility.cpp b/protocols/Twitter/src/utility.cpp index c46c146390..09e764f5f6 100644 --- a/protocols/Twitter/src/utility.cpp +++ b/protocols/Twitter/src/utility.cpp @@ -66,32 +66,3 @@ void CTwitterProto::ShowPopup(const char *text, int Error) } PUAddPopupW(&popup); } - -///////////////////////////////////////////////////////////////////////////////////////// - -bool save_url(HNETLIBUSER hNetlib, const CMStringA &url, const CMStringW &filename) -{ - MHttpRequest req(REQUEST_GET); - req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT; - req.m_szUrl = const_cast(url.c_str()); - - NLHR_PTR resp(Netlib_HttpTransaction(hNetlib, &req)); - if (!resp) - return false; - - if (resp->resultCode != 200) - return false; - - // Create folder if necessary - if (CreatePathToFileW(filename) != ERROR_SUCCESS) - return false; - - // Write to file - if (FILE *f = _wfopen(filename, L"wb")) { - fwrite(resp->body, 1, resp->body.GetLength(), f); - fclose(f); - } - else return false; - - return true; -} diff --git a/protocols/Twitter/src/utility.h b/protocols/Twitter/src/utility.h index 3a7e32a0e1..aa53df8dc0 100644 --- a/protocols/Twitter/src/utility.h +++ b/protocols/Twitter/src/utility.h @@ -24,5 +24,3 @@ StringPairs ParseQueryString(const CMStringA &queryString); void Split(const CMStringA &str, OBJLIST &out, char sep, bool includeEmpty = false); void htmlEntitiesDecode(CMStringA &context); - -bool save_url(HNETLIBUSER hNetlib,const CMStringA &url,const CMStringW &filename); -- cgit v1.2.3