summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-03-17 12:40:04 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-03-17 12:40:04 +0300
commit60a3976ffcba18b69e1da3a22e474e15b672aab2 (patch)
treedd0cfdcd7d93ea66564f639d8026301c2d2d39f7 /protocols/Telegram/src
parenteb6981dc2146cc8718eb913605fac6b9c3746642 (diff)
for #3392 - binary files receiving for Telegram
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/avatars.cpp25
-rw-r--r--protocols/Telegram/src/proto.cpp8
-rw-r--r--protocols/Telegram/src/proto.h12
-rw-r--r--protocols/Telegram/src/utils.cpp24
4 files changed, 44 insertions, 25 deletions
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp
index d3d8cf2d1d..b845d536de 100644
--- a/protocols/Telegram/src/avatars.cpp
+++ b/protocols/Telegram/src/avatars.cpp
@@ -87,21 +87,34 @@ void CTelegramProto::ProcessFile(TD::updateFile *pObj)
for (auto &it : m_arFiles) {
if (it->m_uniqueId == pFile->remote_->unique_id_.c_str()) {
+ CMStringW wszFullName = it->m_destPath + L"\\" + it->m_fileName;
+
if (it->m_type == it->AVATAR) {
if (it->m_destPath.Right(5).MakeLower() == L".webp") {
if (auto *pImage = FreeImage_LoadU(FIF_WEBP, wszExistingFile)) {
- it->m_destPath.Truncate(it->m_destPath.GetLength() - 5);
- it->m_destPath += L".png";
- FreeImage_SaveU(FIF_PNG, pImage, it->m_destPath);
+ wszFullName.Truncate(wszFullName.GetLength() - 5);
+ wszFullName += L".png";
+ FreeImage_SaveU(FIF_PNG, pImage, wszFullName);
FreeImage_Unload(pImage);
}
}
- else MoveFileW(wszExistingFile, it->m_destPath);
+ else MoveFileW(wszExistingFile, wszFullName);
- SMADD_CONT cont = {1, m_szModuleName, it->m_destPath};
+ SMADD_CONT cont = { 1, m_szModuleName, wszFullName };
CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, LPARAM(&cont));
+ m_arFiles.removeItem(&it);
+ }
+ else { // FILE
+ it->pfts.currentFileProgress = pFile->local_->downloaded_size_;
+ ProtoBroadcastAck(it->pfts.hContact, ACKTYPE_FILE, ACKRESULT_DATA, it, (LPARAM)&it->pfts);
+
+ if (pFile->local_->is_downloading_completed_) {
+ MoveFileW(wszExistingFile, wszFullName);
+ ProtoBroadcastAck(it->pfts.hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, it);
+
+ m_arFiles.removeItem(&it);
+ }
}
- m_arFiles.removeItem(&it);
return;
}
}
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index 039bc6bcb9..d7cac65780 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -283,13 +283,17 @@ HANDLE CTelegramProto::FileAllow(MCONTACT, HANDLE hTransfer, const wchar_t *pwsz
if (ft == nullptr)
return nullptr;
+ ft->m_destPath = pwszSavePath;
+ ft->pfts.szCurrentFile.w = ft->m_fileName.GetBuffer();
+ ft->pfts.szWorkingDir.w = ft->m_destPath.GetBuffer();
+ SendQuery(new TD::downloadFile(ft->m_fileId, 5, 0, 0, false));
return ft;
}
-int CTelegramProto::FileCancel(MCONTACT hContact, HANDLE hTransfer)
+int CTelegramProto::FileCancel(MCONTACT, HANDLE hTransfer)
{
auto *ft = (TG_FILE_REQUEST *)hTransfer;
-
+ delete ft;
return 1;
}
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index fd08f08de2..657dce496a 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -59,19 +59,21 @@ struct TG_REQUEST_FULL : public TG_REQUEST_BASE
/////////////////////////////////////////////////////////////////////////////////////////
-struct TG_FILE_REQUEST
+struct TG_FILE_REQUEST : public MZeroedObject
{
enum Type { AVATAR = 1, FILE = 2 };
- TG_FILE_REQUEST(Type _1, const char *_2, const wchar_t *_3) :
+ TG_FILE_REQUEST(Type _1, TD::int53 _2, const char *_3) :
m_type(_1),
- m_uniqueId(_2),
- m_destPath(_3)
+ m_fileId(_2),
+ m_uniqueId(_3)
{}
Type m_type;
+ TD::int53 m_fileId;
CMStringA m_uniqueId;
- CMStringW m_destPath;
+ CMStringW m_destPath, m_fileName;
+ PROTOFILETRANSFERSTATUS pfts;
};
struct TG_USER
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp
index 1c8e31d0f3..a9213d55ac 100644
--- a/protocols/Telegram/src/utils.cpp
+++ b/protocols/Telegram/src/utils.cpp
@@ -230,13 +230,12 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, TD::MessageContent *pBo
break;
}
- auto *pFileId = pFile->remote_->unique_id_.c_str();
-
- CMStringW wszDest(GetProtoFolder() + L"\\tmpfiles");
- CreateDirectoryW(wszDest, 0);
- wszDest.AppendFormat(L"\\%s", Utf2T(pDoc->document_->file_name_.c_str()).get());
-
- auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::FILE, pFileId, wszDest);
+ auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::FILE, pFile->id_, pFile->remote_->unique_id_.c_str());
+ pRequest->m_fileName = Utf2T(pDoc->document_->file_name_.c_str());
+ pRequest->m_destPath = GetProtoFolder() + L"\\tmpfiles";
+ pRequest->pfts.flags = PFTS_UNICODE;
+ pRequest->pfts.hContact = pUser->hContact;
+ pRequest->pfts.currentFileSize = pFile->size_;
m_arFiles.insert(pRequest);
auto *pszFileName = pDoc->document_->file_name_.c_str();
@@ -269,11 +268,12 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, TD::MessageContent *pBo
default:pwszFileExt = "jpeg"; break;
}
- CMStringW wszDest(GetAvatarPath() + L"\\Stickers");
- CreateDirectoryW(wszDest, 0);
- wszDest.AppendFormat(L"\\STK{%S}.%S", pFileId, pwszFileExt);
-
- m_arFiles.insert(new TG_FILE_REQUEST(TG_FILE_REQUEST::AVATAR, pFileId, wszDest));
+ auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::AVATAR, pFile->id_, pFileId);
+ pRequest->m_destPath = GetAvatarPath() + L"\\Stickers";
+ CreateDirectoryW(pRequest->m_destPath, 0);
+
+ pRequest->m_fileName.Format(L"STK{%S}.%S", pFileId, pwszFileExt);
+ m_arFiles.insert(pRequest);
SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
return CMStringA(FORMAT, "STK{%s}", pFileId);