From bb9dce4b057d4533f2f8a0c8f5f899790685deff Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 9 Jan 2024 16:25:31 +0300 Subject: Jabber: offline file reading switched to Netlib_DownloadFile --- protocols/JabberG/src/jabber_file.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp index 616a629c59..7b0211e70e 100644 --- a/protocols/JabberG/src/jabber_file.cpp +++ b/protocols/JabberG/src/jabber_file.cpp @@ -54,12 +54,13 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *ofd) nlhr.m_szUrl = url; // download the page - NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr)); + NLHR_PTR nlhrReply(encrypted + ? Netlib_HttpTransaction(m_hNetlibUser, &nlhr) + : Netlib_DownloadFile(m_hNetlibUser, &nlhr, ofd->wszPath)); if (nlhrReply && nlhrReply->resultCode == 200) { - FILE *f = _wfopen(ofd->wszPath, L"wb"); size_t written = 0; - if (f) { - if (encrypted) { + if (encrypted) { + if (FILE *f = _wfopen(ofd->wszPath, L"wb")) { int payload_len = nlhrReply->body.GetLength() - 16; if (payload_len > 0) { uint8_t ivkey[44]; @@ -80,10 +81,13 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *ofd) written = payload_len; mir_free(out); } + fclose(f); } - else if (fwrite(nlhrReply->body, 1, nlhrReply->body.GetLength(), f) == size_t(nlhrReply->body.GetLength())) - written = nlhrReply->body.GetLength(); - fclose(f); + } + else { + struct _stat st; + _wstat(ofd->wszPath, &st); + written = st.st_size; } if (written) { -- cgit v1.2.3