From 864601c41faeec6dea78baf6c14f15c3ba164486 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 20 Apr 2023 11:42:18 +0300 Subject: Telegram: fix for Unicode file names --- include/m_protosvc.h | 1 + protocols/JabberG/src/jabber_iq_handlers.cpp | 1 + protocols/JabberG/src/jabber_thread.cpp | 1 + protocols/Telegram/src/utils.cpp | 1 + src/core/stdfile/src/file.cpp | 9 +++++++-- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/m_protosvc.h b/include/m_protosvc.h index e98a13c489..d61165f403 100644 --- a/include/m_protosvc.h +++ b/include/m_protosvc.h @@ -769,6 +769,7 @@ EXTERN_C MIR_APP_DLL(MEVENT) Proto_AuthRecv(const char *szProtoName, PROTORECVEV // lParam = (LPARAM)(PROTORECVFILE*)&prf #define PRFF_UNICODE 1 +#define PRFF_UTF 2 struct PROTORECVFILE { diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 2c3b25b90c..2b21589caa 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -321,6 +321,7 @@ bool CJabberProto::OnIqRequestOOB(const TiXmlElement*, CJabberIqInfo *pInfo) str2 = ft->httpPath; PROTORECVFILE pre = {}; + pre.dwFlags = PRFF_UTF; pre.timestamp = time(0); pre.descr.a = desc; pre.files.a = &str2; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 5e4fae32b9..5ee69b908e 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1342,6 +1342,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) ft->std.szCurrentFile.w = mir_utf8decodeW(szName); PROTORECVFILE pre = {}; + pre.dwFlags = PRFF_UTF; pre.fileCount = 1; pre.timestamp = time(0); pre.files.a = &pszName; diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 0884188c16..ef2636563f 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -248,6 +248,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, TD::MessageContent *pBo auto *pszFileName = pDoc->document_->file_name_.c_str(); PROTORECVFILE pre = {}; + pre.dwFlags = PRFF_UTF; pre.fileCount = 1; pre.timestamp = time(0); pre.files.a = &pszFileName; diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp index 4d007ec3ed..e8573eca6b 100644 --- a/src/core/stdfile/src/file.cpp +++ b/src/core/stdfile/src/file.cpp @@ -339,15 +339,20 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam) blob.write(dbei); } else { + bool bUtf = (pre->dwFlags & PRFF_UTF) != 0; CMStringW wszFiles; for (int i = 0; i < pre->fileCount; i++) { if (i != 0) wszFiles.AppendChar(','); - wszFiles.Append(_A2T(pre->files.a[i])); + + if (bUtf) + wszFiles.Append(Utf2T(pre->files.a[i])); + else + wszFiles.Append(_A2T(pre->files.a[i])); } - DB::FILE_BLOB blob(wszFiles, _A2T(pre->descr.a)); + DB::FILE_BLOB blob(wszFiles, bUtf ? Utf2T(pre->descr.a).get() : _A2T(pre->descr.a)); blob.write(dbei); } -- cgit v1.2.3