summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-07-13 21:01:07 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-07-13 21:01:07 +0300
commitc1e60721e900cb28c4e39d106e65549d3579ccfc (patch)
treee0fe839e90ee8ef245d2b302ad410d5c380e7957
parentfa9cafb23a93496a4e67db2832f231b2f0f585b0 (diff)
standard offline file download finalization
-rw-r--r--include/m_protosvc.h13
-rw-r--r--libs/win32/mir_app.libbin262018 -> 262924 bytes
-rw-r--r--libs/win64/mir_app.libbin261020 -> 261946 bytes
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp1
-rw-r--r--protocols/JabberG/src/jabber_file.cpp3
-rw-r--r--protocols/Telegram/src/avatars.cpp53
-rw-r--r--protocols/Telegram/src/proto.h3
-rw-r--r--src/mir_app/src/mir_app.def3
-rw-r--r--src/mir_app/src/mir_app64.def3
-rw-r--r--src/mir_app/src/srmm_util.cpp13
10 files changed, 53 insertions, 39 deletions
diff --git a/include/m_protosvc.h b/include/m_protosvc.h
index 979d4568e9..c4a62e7327 100644
--- a/include/m_protosvc.h
+++ b/include/m_protosvc.h
@@ -444,8 +444,7 @@ struct CUSTOMSEARCHRESULTS
struct PROTOFILERESUME
{
- ~PROTOFILERESUME()
- {
+ ~PROTOFILERESUME() {
mir_free(szFilename);
}
@@ -811,13 +810,11 @@ __forceinline INT_PTR ProtoChainRecvFile(MCONTACT hContact, PROTORECVFILE *pre)
#define PS_OFFLINEFILE "/OfflineFile"
-struct OFDTHREAD
+struct MIR_APP_EXPORT OFDTHREAD : public MNonCopyable
{
- __forceinline OFDTHREAD(MEVENT _1, const CMStringW &_2, bool _3) :
- hDbEvent(_1),
- wszPath(_2),
- bOpen(_3)
- {}
+ OFDTHREAD(MEVENT, const CMStringW &, bool);
+
+ void Finish();
MEVENT hDbEvent;
CMStringW wszPath;
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index 5f7636deae..280e32a771 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index 6803677406..dddba5a8a5 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp
index f6a605d51e..a4b3207367 100644
--- a/protocols/ICQ-WIM/src/proto.cpp
+++ b/protocols/ICQ-WIM/src/proto.cpp
@@ -204,6 +204,7 @@ void CIcqProto::OnFileRecv(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
return;
}
+ ofd->Finish();
delete ofd;
}
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index 897f2c6c6f..aea0b617b1 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -100,8 +100,7 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *param)
db_event_setJson(param->hDbEvent, "fs", &dbv);
NotifyEventHooks(g_hevEventEdited, 0, param->hDbEvent);
- if (param->bOpen)
- ShellExecuteW(nullptr, L"open", param->wszPath, nullptr, nullptr, SW_SHOWDEFAULT);
+ param->Finish();
}
}
}
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
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 4b6efbca4e..6ec1f8b3ff 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -876,3 +876,6 @@ Clist_RemoveEvent @989
?Chat_EmptyHistory@@YGXPAUSESSION_INFO@@@Z @992 NONAME
?Utils_Unzip@@YG?AVMBinBuffer@@PBXI@Z @993 NONAME
?OnNickListTimer@CSrmmBaseDialog@@AAEXPAVCTimer@@@Z @994 NONAME
+??0OFDTHREAD@@QAE@IABV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@_N@Z @995 NONAME
+??1OFDTHREAD@@QAE@XZ @996 NONAME
+?Finish@OFDTHREAD@@QAEXXZ @997 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 4d1b14a509..a43ed51ffc 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -876,3 +876,6 @@ Clist_RemoveEvent @989
?Chat_EmptyHistory@@YAXPEAUSESSION_INFO@@@Z @992 NONAME
?Utils_Unzip@@YA?AVMBinBuffer@@PEBX_K@Z @993 NONAME
?OnNickListTimer@CSrmmBaseDialog@@AEAAXPEAVCTimer@@@Z @994 NONAME
+??0OFDTHREAD@@QEAA@IAEBV?$CMStringT@_WV?$ChTraitsCRT@_W@@@@_N@Z @995 NONAME
+??1OFDTHREAD@@QEAA@XZ @996 NONAME
+?Finish@OFDTHREAD@@QEAAXXZ @997 NONAME
diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp
index 32e247aa68..460c5be50d 100644
--- a/src/mir_app/src/srmm_util.cpp
+++ b/src/mir_app/src/srmm_util.cpp
@@ -106,6 +106,19 @@ MIR_APP_DLL(void) Srmm_AddEvent(MCONTACT hContact, MEVENT hDbEvent)
/////////////////////////////////////////////////////////////////////////////////////////
// downloads or launches offline file
+OFDTHREAD::OFDTHREAD(MEVENT _1, const CMStringW &_2, bool _3) :
+ hDbEvent(_1),
+ wszPath(_2),
+ bOpen(_3)
+{
+}
+
+void OFDTHREAD::Finish()
+{
+ if (bOpen)
+ ShellExecuteW(nullptr, L"open", wszPath, nullptr, nullptr, SW_SHOWDEFAULT);
+}
+
MIR_APP_DLL(void) Srmm_DownloadOfflineFile(MEVENT hDbEvent, bool bOpen)
{
DB::EventInfo dbei(hDbEvent);