diff options
| author | George Hazan <george.hazan@gmail.com> | 2024-01-03 19:15:44 +0300 | 
|---|---|---|
| committer | George Hazan <george.hazan@gmail.com> | 2024-01-03 19:15:44 +0300 | 
| commit | 09a49cfe0925494f7fd516657df7fe327c7370dd (patch) | |
| tree | 44d9d0e278fe250282bbe73b082a8952bb4645c0 /protocols/Telegram | |
| parent | 756cbebea5281171c32d62a599cedd9657db7999 (diff) | |
fixes #3946 (Прогресс скачивания крупных файлов)
Diffstat (limited to 'protocols/Telegram')
| -rw-r--r-- | protocols/Telegram/src/avatars.cpp | 176 | ||||
| -rw-r--r-- | protocols/Telegram/src/proto.h | 2 | 
2 files changed, 99 insertions, 79 deletions
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);  | 
