diff options
author | George Hazan <george.hazan@gmail.com> | 2023-07-13 21:01:07 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-07-13 21:01:07 +0300 |
commit | c1e60721e900cb28c4e39d106e65549d3579ccfc (patch) | |
tree | e0fe839e90ee8ef245d2b302ad410d5c380e7957 /protocols/Telegram/src | |
parent | fa9cafb23a93496a4e67db2832f231b2f0f585b0 (diff) |
standard offline file download finalization
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r-- | protocols/Telegram/src/avatars.cpp | 53 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 3 |
2 files changed, 27 insertions, 29 deletions
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index bad675ad76..433bda9e9f 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -106,9 +106,7 @@ void __cdecl CTelegramProto::OfflineFileThread(void *pParam) JSONNode root = JSONNode::parse((const char *)dbei.pBlob);
if (root) {
auto *ft = new TG_FILE_REQUEST(TG_FILE_REQUEST::Type(root["t"].as_int()), 0, "");
- ft->m_fileName = ofd->wszPath;
- ft->m_bOpen = ofd->bOpen;
- ft->m_hEvent = ofd->hDbEvent;
+ ft->ofd = ofd;
m_arFiles.insert(ft);
SendQuery(new TD::getRemoteFile(root["u"].as_string(), 0), &CTelegramProto::OnGetFileInfo, ft);
@@ -184,32 +182,33 @@ void CTelegramProto::ProcessFile(TD::updateFile *pObj) }
else { // FILE, PICTURE, VIDEO, VOICE
if (pFile->local_->is_downloading_completed_) {
- DBVARIANT dbv = { DBVT_DWORD };
- dbv.dVal = pFile->local_->downloaded_size_;
- db_event_setJson(F->m_hEvent, "ft", &dbv);
- db_event_setJson(F->m_hEvent, "fs", &dbv);
-
- if (F->m_type != F->FILE) {
- auto *pSlash = strrchr(pFile->local_->path_.c_str(), '\\');
- if (!pSlash)
- pSlash = pFile->local_->path_.c_str();
- else
- pSlash++;
-
- dbv.type = DBVT_UTF8;
- dbv.pszVal = (char*)pSlash;
- db_event_setJson(F->m_hEvent, "f", &dbv);
-
- wszFullName.Truncate(wszFullName.ReverseFind('\\') + 1);
- wszFullName.Append(Utf2T(pSlash));
+ if (F->ofd) {
+ DBVARIANT dbv = { DBVT_DWORD };
+ dbv.dVal = pFile->local_->downloaded_size_;
+ db_event_setJson(F->ofd->hDbEvent, "ft", &dbv);
+ db_event_setJson(F->ofd->hDbEvent, "fs", &dbv);
+
+ if (F->m_type != F->FILE) {
+ auto *pSlash = strrchr(pFile->local_->path_.c_str(), '\\');
+ if (!pSlash)
+ pSlash = pFile->local_->path_.c_str();
+ else
+ pSlash++;
+
+ dbv.type = DBVT_UTF8;
+ dbv.pszVal = (char *)pSlash;
+ db_event_setJson(F->ofd->hDbEvent, "f", &dbv);
+
+ wszFullName.Truncate(wszFullName.ReverseFind('\\') + 1);
+ wszFullName.Append(Utf2T(pSlash));
+ }
+
+ MoveFileW(wszExistingFile, wszFullName);
+ NotifyEventHooks(g_plugin.m_hevEventEdited, 0, F->ofd->hDbEvent);
+
+ F->ofd->Finish();
}
- MoveFileW(wszExistingFile, wszFullName);
- NotifyEventHooks(g_plugin.m_hevEventEdited, 0, F->m_hEvent);
-
- if (F->m_bOpen)
- ShellExecuteW(nullptr, L"open", wszFullName, nullptr, nullptr, SW_SHOWDEFAULT);
-
mir_cslock lck(m_csFiles);
m_arFiles.remove(F);
}
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 331a7b9d82..e83ed8ae6d 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -74,12 +74,11 @@ struct TG_FILE_REQUEST : public MZeroedObject void AutoDetectType(); Type m_type; - bool m_bOpen = false; - MEVENT m_hEvent = 0; MCONTACT m_hContact = 0; TD::int53 m_fileId, m_fileSize = 0; CMStringA m_uniqueId; CMStringW m_destPath, m_fileName, m_wszDescr; + OFDTHREAD *ofd; }; struct TG_USER : public MZeroedObject |