summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-02-19 15:08:17 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-02-19 15:08:17 +0300
commit00cff5cf367a3dd8f2ff5c88d59430787f6df884 (patch)
tree6626dd969fe353107e9552cf66120a7bad114676
parent5940cb3dc7bc68e7a6483a820eaf7dc105b7cef7 (diff)
fixes #4193 (Если второй раз кликнуть на уже загружаемый, но еще не загруженный, оффлайн-файл, то полоску загрузки начинает глючить.)
-rw-r--r--include/m_protosvc.h2
-rw-r--r--src/mir_app/src/srmm_util.cpp23
-rw-r--r--src/mir_app/src/stdafx.h1
3 files changed, 22 insertions, 4 deletions
diff --git a/include/m_protosvc.h b/include/m_protosvc.h
index 64d31b6aa8..7f33cf5e2b 100644
--- a/include/m_protosvc.h
+++ b/include/m_protosvc.h
@@ -725,7 +725,7 @@ struct MIR_APP_EXPORT OFDTHREAD : public MNonCopyable
MEVENT hDbEvent;
MFilePath wszPath;
struct OFD_Callback *pCallback = nullptr;
- bool bOpen = false, bCopy = false;
+ bool bOpen = false, bCopy = false, bLocked = false;
};
struct OFD_Callback
diff --git a/src/mir_app/src/srmm_util.cpp b/src/mir_app/src/srmm_util.cpp
index f78513cd70..b9e4d4c4ff 100644
--- a/src/mir_app/src/srmm_util.cpp
+++ b/src/mir_app/src/srmm_util.cpp
@@ -117,6 +117,9 @@ MIR_APP_DLL(int) Srmm_GetWindowData(MCONTACT hContact, MessageWindowData &mwd)
/////////////////////////////////////////////////////////////////////////////////////////
// downloads or launches cloud file
+static mir_cs csLocked;
+static std::map<MEVENT, bool> arLocked;
+
OFDTHREAD::OFDTHREAD(MEVENT _1, const CMStringW &_2, int iCommand) :
hDbEvent(_1),
wszPath(_2)
@@ -127,6 +130,11 @@ OFDTHREAD::OFDTHREAD(MEVENT _1, const CMStringW &_2, int iCommand) :
OFDTHREAD::~OFDTHREAD()
{
+ if (bLocked) {
+ mir_cslock lck(csLocked);
+ arLocked.erase(hDbEvent);
+ }
+
delete pCallback;
}
@@ -161,7 +169,6 @@ void GetContactSentFilesDir(MCONTACT hContact, wchar_t *szDir, int cchDir)
mir_snwprintf(szDir, cchDir, L"%s\\dlFiles\\%d\\", VARSW(L"%miranda_userdata%").get(), hContact);
}
-
static void GenerateLocalName(const DB::EventInfo &dbei, DB::FILE_BLOB &blob, MCONTACT hContact)
{
wchar_t wszReceiveFolder[MAX_PATH];
@@ -178,6 +185,8 @@ static void GenerateLocalName(const DB::EventInfo &dbei, DB::FILE_BLOB &blob, MC
void DownloadOfflineFile(MCONTACT hContact, MEVENT hDbEvent, DB::EventInfo &dbei, int iCommand, OFD_Callback *pCallback)
{
+ std::unique_ptr<OFD_Callback> callback(pCallback);
+
DB::FILE_BLOB blob(dbei);
if (!blob.isOffline())
return;
@@ -199,11 +208,19 @@ void DownloadOfflineFile(MCONTACT hContact, MEVENT hDbEvent, DB::EventInfo &dbei
if (bDownloaded) {
OFDTHREAD ofd(hDbEvent, blob.getLocalName(), iCommand);
pCallback->Invoke(ofd);
- delete pCallback;
}
else {
+ {
+ mir_cslock lck(csLocked);
+ if (arLocked.find(hDbEvent) != arLocked.end())
+ return;
+
+ arLocked[hDbEvent] = true;
+ }
+
OFDTHREAD *ofd = new OFDTHREAD(hDbEvent, blob.getLocalName(), iCommand);
- ofd->pCallback = pCallback;
+ ofd->bLocked = true;
+ ofd->pCallback = callback.release();
CallProtoService(dbei.szModule, PS_OFFLINEFILE, (WPARAM)ofd);
}
}
diff --git a/src/mir_app/src/stdafx.h b/src/mir_app/src/stdafx.h
index 9c91bb225b..3962c77b01 100644
--- a/src/mir_app/src/stdafx.h
+++ b/src/mir_app/src/stdafx.h
@@ -56,6 +56,7 @@ typedef struct SslHandle *HSSL;
#include <string.h>
#include <locale.h>
+#include <map>
#include <memory>
#define __NO_CMPLUGIN_NEEDED