summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-01-03 19:15:44 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-01-03 19:15:44 +0300
commit09a49cfe0925494f7fd516657df7fe327c7370dd (patch)
tree44d9d0e278fe250282bbe73b082a8952bb4645c0
parent756cbebea5281171c32d62a599cedd9657db7999 (diff)
fixes #3946 (Прогресс скачивания крупных файлов)
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp9
-rw-r--r--plugins/NewStory/src/history_array.cpp5
-rw-r--r--plugins/NewStory/src/history_array.h5
-rw-r--r--plugins/NewStory/src/history_control.cpp18
-rw-r--r--protocols/Telegram/src/avatars.cpp176
-rw-r--r--protocols/Telegram/src/proto.h2
6 files changed, 128 insertions, 87 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index 3d26ec28c5..81fc24fa39 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -368,6 +368,15 @@ int CDbxSQLite::SetEventJson(MEVENT hDbEvent, const char *szSetting, DBVARIANT *
}
DBFlush();
+
+ if (m_safetyMode) {
+ MCONTACT hContact = GetEventContact(hDbEvent);
+ if (auto *cc = m_cache->GetCachedContact(hContact))
+ if (cc->IsSub())
+ hContact = cc->parentID;
+
+ NotifyEventHooks(g_hevEventEdited, hContact, hDbEvent);
+ }
return 0;
}
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 2d109c1540..4e5ac3a1a5 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -401,7 +401,10 @@ void ItemData::load(bool bLoadAlways)
DB::FILE_BLOB blob(dbe);
if (blob.isOffline()) {
m_bOfflineFile = true;
- m_bOfflineDownloaded = blob.isCompleted();
+ if (blob.isCompleted())
+ m_bOfflineDownloaded = 100;
+ else
+ m_bOfflineDownloaded = uint8_t(100.0 * blob.getTransferred() / blob.getSize());
CMStringW buf;
buf.Append(blob.getName() ? blob.getName() : TranslateT("Unnamed"));
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index 29331d0235..afeb93e54c 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -17,8 +17,8 @@ struct ItemData
bool m_bSelected, m_bHighlighted;
bool m_bLoaded, m_bIsResult;
- bool m_bOfflineFile, m_bOfflineDownloaded;
- uint8_t m_grouping;
+ bool m_bOfflineFile;
+ uint8_t m_grouping, m_bOfflineDownloaded;
int savedTop, savedHeight;
@@ -38,6 +38,7 @@ struct ItemData
void markRead();
void setText(HWND hwnd);
+ bool completed() const { return m_bOfflineDownloaded == 100; }
bool fetch(void);
void fill(int tmpl);
void load(bool bLoad = false);
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 32e01076c4..d0ffd77994 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -289,7 +289,7 @@ void NewstoryListData::Copy(bool bTextOnly)
void NewstoryListData::CopyUrl()
{
if (auto *pItem = GetItem(caret)) {
- if (pItem->m_bOfflineDownloaded) {
+ if (pItem->completed()) {
DB::EventInfo dbei(pItem->hEvent);
DB::FILE_BLOB blob(dbei);
Utils_ClipboardCopy(blob.getLocalName());
@@ -551,7 +551,7 @@ ItemData* NewstoryListData::LoadItem(int idx)
void NewstoryListData::OpenFolder()
{
if (auto *pItem = GetItem(caret)) {
- if (pItem->m_bOfflineDownloaded) {
+ if (pItem->completed()) {
DB::EventInfo dbei(pItem->hEvent);
DB::FILE_BLOB blob(dbei);
CMStringW wszFile(blob.getLocalName());
@@ -608,7 +608,7 @@ int NewstoryListData::PaintItem(HDC hdc, ItemData *pItem, int top, int width, bo
pos.x += 18;
sz.cx -= pos.x;
- if (pItem->m_bOfflineDownloaded) // Download completed icon
+ if (pItem->m_bOfflineDownloaded != 0) // Download completed icon
sz.cx -= 18;
HFONT hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
@@ -667,8 +667,16 @@ int NewstoryListData::PaintItem(HDC hdc, ItemData *pItem, int top, int width, bo
}
// Finished icon
- if (pItem->m_bOfflineDownloaded)
- DrawIconEx(hdc, width-20, pos.y, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL);
+ if (pItem->m_bOfflineDownloaded != 0) {
+ if (pItem->completed())
+ DrawIconEx(hdc, width - 20, pos.y, g_plugin.getIcon(IDI_OK), 16, 16, 0, 0, DI_NORMAL);
+ else {
+ HPEN hpn = (HPEN)SelectObject(hdc, CreatePen(PS_SOLID, 4, RGB(255, 0, 0)));
+ MoveToEx(hdc, rc.left, rc.bottom - 4, 0);
+ LineTo(hdc, rc.left + (rc.right - rc.left) * int(pItem->m_bOfflineDownloaded) / 100, rc.bottom - 4);
+ DeleteObject(SelectObject(hdc, hpn));
+ }
+ }
hfnt = (HFONT)SelectObject(hdc, g_fontTable[fontid].hfnt);
MTextDisplay(hdc, pos, sz, pItem->data);
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp
index 9da6068cce..932e63ca43 100644
--- a/protocols/Telegram/src/avatars.cpp
+++ b/protocols/Telegram/src/avatars.cpp
@@ -94,7 +94,7 @@ void CTelegramProto::OnGetFileInfo(td::ClientManager::Response &response, void *
ft->m_fileId = pFile->id_;
ft->m_uniqueId = pFile->remote_->unique_id_.c_str();
- SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
+ SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, false));
}
void CTelegramProto::OnGetFileLink(td::ClientManager::Response &response)
@@ -161,7 +161,7 @@ void CTelegramProto::OnSendOfflineFile(DB::EventInfo &dbei, DB::FILE_BLOB &blob,
/////////////////////////////////////////////////////////////////////////////////////////
-TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
+TG_FILE_REQUEST* CTelegramProto::FindFile(const char *pszUniqueId)
{
mir_cslock lck(m_csFiles);
@@ -177,99 +177,119 @@ TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
void CTelegramProto::ProcessFile(TD::updateFile *pObj)
{
- if (auto *pFile = pObj->file_.get()) {
- if (!pFile->local_->is_downloading_completed_)
- return;
-
- Utf2T wszExistingFile(pFile->local_->path_.c_str());
-
- if (auto *F = PopFile(pFile->remote_->unique_id_.c_str())) {
- if (F->m_type == F->AVATAR) {
- CMStringW wszFullName = F->m_destPath;
- if (!wszFullName.IsEmpty())
- wszFullName += L"\\";
- wszFullName += F->m_fileName;
-
- if (F->m_fileName.Right(5).MakeLower() == L".webp") {
- if (auto *pImage = FreeImage_LoadU(FIF_WEBP, wszExistingFile)) {
- wszFullName.Truncate(wszFullName.GetLength() - 5);
- wszFullName += L".png";
- FreeImage_SaveU(FIF_PNG, pImage, wszFullName);
- FreeImage_Unload(pImage);
- }
- }
- else MoveFileW(wszExistingFile, wszFullName);
-
- SmileyAdd_LoadContactSmileys(SMADD_FILE, m_szModuleName, wszFullName);
+ auto *pFile = pObj->file_.get();
+ if (pFile == nullptr)
+ return;
- mir_cslock lck(m_csFiles);
- m_arFiles.remove(F);
+ if (!pFile->local_->is_downloading_completed_) {
+ if (auto *F = FindFile(pFile->remote_->unique_id_.c_str())) {
+ if (F->m_type != F->AVATAR && F->ofd) {
+ DBVARIANT dbv = { DBVT_DWORD };
+ dbv.dVal = pFile->local_->downloaded_size_;
+ db_event_setJson(F->ofd->hDbEvent, "ft", &dbv);
}
- else { // FILE, PICTURE, VIDEO, VOICE
- if (pFile->local_->is_downloading_completed_) {
- 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);
-
- CMStringW wszFullName(F->ofd->wszPath);
-
- 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));
- F->ofd->ResetFileName(wszFullName); // resulting ofd->wszPath may differ from wszFullName
-
- MoveFileW(wszExistingFile, F->ofd->wszPath);
- F->ofd->Finish();
- }
+ }
+ return;
+ }
- mir_cslock lck(m_csFiles);
- m_arFiles.remove(F);
+ Utf2T wszExistingFile(pFile->local_->path_.c_str());
+
+ if (auto *F = FindFile(pFile->remote_->unique_id_.c_str())) {
+ if (F->m_type == F->AVATAR) {
+ CMStringW wszFullName = F->m_destPath;
+ if (!wszFullName.IsEmpty())
+ wszFullName += L"\\";
+ wszFullName += F->m_fileName;
+
+ if (F->m_fileName.Right(5).MakeLower() == L".webp") {
+ if (auto *pImage = FreeImage_LoadU(FIF_WEBP, wszExistingFile)) {
+ wszFullName.Truncate(wszFullName.GetLength() - 5);
+ wszFullName += L".png";
+ FreeImage_SaveU(FIF_PNG, pImage, wszFullName);
+ FreeImage_Unload(pImage);
}
}
+ else MoveFileW(wszExistingFile, wszFullName);
+
+ SmileyAdd_LoadContactSmileys(SMADD_FILE, m_szModuleName, wszFullName);
+ mir_cslock lck(m_csFiles);
+ m_arFiles.remove(F);
delete F;
- return;
}
+ else { // FILE, PICTURE, VIDEO, VOICE
+ if (F->ofd == nullptr)
+ return;
- for (auto &it : m_arOwnMsg) {
- if (it->tmpFileId == pFile->id_) {
- if (!pFile->remote_->id_.empty()) {
- if (auto hDbEvent = db_event_getById(m_szModuleName, it->szMsgId)) {
- DBVARIANT dbv = { DBVT_UTF8 };
- dbv.pszVal = (char *)pFile->remote_->id_.c_str();
- db_event_setJson(hDbEvent, "u", &dbv);
+ DBVARIANT dbv = { DBVT_DWORD };
+ dbv.dVal = pFile->local_->downloaded_size_;
+ db_event_setJson(F->ofd->hDbEvent, "ft", &dbv);
+
+ CMStringW wszFullName(F->ofd->wszPath);
+ int idxSlash = wszFullName.ReverseFind('\\') + 1;
+ if (wszFullName.Find('.', idxSlash) == -1) {
+ auto *pSlash = strrchr(pFile->local_->path_.c_str(), '\\');
+ if (!pSlash)
+ pSlash = pFile->local_->path_.c_str();
+ else
+ pSlash++;
+
+ if (strchr(pSlash, '.')) {
+ dbv.type = DBVT_UTF8;
+ dbv.pszVal = (char *)pSlash;
+ db_event_setJson(F->ofd->hDbEvent, "f", &dbv);
+
+ wszFullName.Truncate(idxSlash);
+ wszFullName.Append(Utf2T(pSlash));
+ F->ofd->ResetFileName(wszFullName); // resulting ofd->wszPath may differ from wszFullName
+ }
+ else {
+ int iFormat = ProtoGetAvatarFileFormat(wszExistingFile);
+ if (iFormat != PA_FORMAT_UNKNOWN) {
+ wszFullName.AppendChar('.');
+ wszFullName.Append(ProtoGetAvatarExtension(iFormat));
+ F->ofd->ResetFileName(wszFullName);
}
}
- return;
}
+
+ MoveFileW(wszExistingFile, F->ofd->wszPath);
+ F->ofd->Finish();
+
+ mir_cslock lck(m_csFiles);
+ m_arFiles.remove(F);
+ delete F;
}
+ return;
+ }
- for (auto &it : m_arUsers) {
- if (it->szAvatarHash == pFile->remote_->unique_id_.c_str()) {
- PROTO_AVATAR_INFORMATION pai;
- pai.hContact = it->hContact;
- pai.format = ProtoGetAvatarFileFormat(wszExistingFile);
- setByte(pai.hContact, DBKEY_AVATAR_TYPE, pai.format);
+ for (auto &it : m_arOwnMsg) {
+ if (it->tmpFileId == pFile->id_) {
+ if (!pFile->remote_->id_.empty()) {
+ if (auto hDbEvent = db_event_getById(m_szModuleName, it->szMsgId)) {
+ DBVARIANT dbv = { DBVT_UTF8 };
+ dbv.pszVal = (char *)pFile->remote_->id_.c_str();
+ db_event_setJson(hDbEvent, "u", &dbv);
+ }
+ }
+ return;
+ }
+ }
- CMStringW wszAvatarPath(GetAvatarFilename(it->hContact));
- wcsncpy_s(pai.filename, wszAvatarPath, _TRUNCATE);
+ for (auto &it : m_arUsers) {
+ if (it->szAvatarHash == pFile->remote_->unique_id_.c_str()) {
+ PROTO_AVATAR_INFORMATION pai;
+ pai.hContact = it->hContact;
+ pai.format = ProtoGetAvatarFileFormat(wszExistingFile);
+ setByte(pai.hContact, DBKEY_AVATAR_TYPE, pai.format);
- MoveFileW(wszExistingFile, wszAvatarPath);
+ CMStringW wszAvatarPath(GetAvatarFilename(it->hContact));
+ wcsncpy_s(pai.filename, wszAvatarPath, _TRUNCATE);
- ProtoBroadcastAck(it->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &pai);
- break;
- }
+ MoveFileW(wszExistingFile, wszAvatarPath);
+
+ ProtoBroadcastAck(it->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &pai);
+ break;
}
}
}
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index a4f8520abf..020b6d740a 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -210,7 +210,7 @@ class CTelegramProto : public PROTO<CTelegramProto>
mir_cs m_csFiles;
LIST<TG_FILE_REQUEST> m_arFiles;
- TG_FILE_REQUEST* PopFile(const char *pszUniqueId);
+ TG_FILE_REQUEST* FindFile(const char *pszUniqueId);
static INT_PTR CALLBACK EnterEmail(void *param);
static INT_PTR CALLBACK EnterEmailCode(void *param);