summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-06 21:10:28 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-06 21:10:28 +0000
commit7bea1db1766147e4294f92c55dc94f247f7ff0e1 (patch)
treebbb3673e3c822be04202841352bb11be3dfd3ee3 /protocols
parent28543611a67b88a42e36a26c3cd2fd7f367b40b4 (diff)
Tox: fast fix for contacts avatar changing
git-svn-id: http://svn.miranda-ng.org/main/trunk@13472 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Tox/src/tox_avatars.cpp37
-rw-r--r--protocols/Tox/src/tox_transfer.cpp45
-rw-r--r--protocols/Tox/src/tox_transfer.h4
3 files changed, 52 insertions, 34 deletions
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp
index 643e447853..33bde952d8 100644
--- a/protocols/Tox/src/tox_avatars.cpp
+++ b/protocols/Tox/src/tox_avatars.cpp
@@ -153,7 +153,7 @@ INT_PTR CToxProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
return -2;
}
- std::tstring path(GetAvatarFilePath());
+ std::tstring path = GetAvatarFilePath();
if (IsFileExists(path))
{
_tcsncpy((TCHAR*)wParam, path.c_str(), (int)lParam);
@@ -218,11 +218,11 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
void CToxProto::OnGotFriendAvatarInfo(FileTransferParam *transfer, const uint8_t *hash)
{
MCONTACT hContact = transfer->pfts.hContact;
- std::tstring path = GetAvatarFilePath();
if (transfer->pfts.totalBytes == 0)
{
delSetting(hContact, TOX_SETTINGS_AVATAR_HASH);
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, 0, 0);
+ std::tstring path = GetAvatarFilePath();
if (IsFileExists(path))
{
DeleteFile(path.c_str());
@@ -242,33 +242,8 @@ void CToxProto::OnGotFriendAvatarInfo(FileTransferParam *transfer, const uint8_t
}
db_free(&dbv);
}
- OnFileAllow(hContact, transfer, path.c_str());
+ TCHAR path[MAX_PATH];
+ mir_sntprintf(path, SIZEOF(path), _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName);
+ OnFileAllow(hContact, transfer, path);
}
-}
-
-/*void CToxProto::OnGotFriendAvatarData(Tox *, int32_t number, uint8_t, uint8_t *hash, uint8_t *data, uint32_t length, void *arg)
-{
-CToxProto *proto = (CToxProto*)arg;
-
-MCONTACT hContact = proto->GetContact(number);
-if (hContact)
-{
-db_set_blob(hContact, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, hash, TOX_HASH_LENGTH);
-
-std::tstring path = proto->GetAvatarFilePath(hContact);
-FILE *hFile = _tfopen(path.c_str(), L"wb");
-if (hFile)
-{
-if (fwrite(data, sizeof(uint8_t), length, hFile) == length)
-{
-PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) };
-pai.format = PA_FORMAT_PNG;
-pai.hContact = hContact;
-_tcscpy(pai.filename, path.c_str());
-
-proto->ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
-}
-fclose(hFile);
-}
-}
-}*/ \ No newline at end of file
+} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index c54bc28181..3d140b5e5c 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -13,6 +13,13 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
switch (kind)
{
case TOX_FILE_KIND_AVATAR:
+ {
+ ptrA id(proto->getStringA(hContact, TOX_SETTINGS_ID));
+ char avatarName[MAX_PATH];
+ mir_snprintf(avatarName, MAX_PATH, "%s.png", id);
+ fileName = (const uint8_t*)avatarName;
+ filenameLength = mir_strlen(avatarName);
+ }
case TOX_FILE_KIND_DATA:
{
ptrA rawName((char*)mir_alloc(filenameLength + 1));
@@ -24,9 +31,13 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
transfer->pfts.hContact = hContact;
proto->transfers.Add(transfer);
- if (kind == TOX_FILE_KIND_AVATAR)
+ if(kind == TOX_FILE_KIND_AVATAR)
{
- proto->OnGotFriendAvatarInfo(transfer, fileName);
+ transfer->isAvatar = true;
+ uint8_t hash[TOX_HASH_LENGTH];
+ TOX_ERR_FILE_GET error;
+ tox_file_get_file_id(proto->tox, friendNumber, fileNumber, hash, &error);
+ proto->OnGotFriendAvatarInfo(transfer, hash);
return;
}
@@ -152,6 +163,34 @@ void CToxProto::OnFileReceiveData(Tox*, uint32_t friendNumber, uint32_t fileNumb
{
proto->debugLogA(__FUNCTION__": file (%d) is transferred not completely", fileNumber);
}
+
+ if(transfer->isAvatar)
+ {
+ uint8_t *avatar = (uint8_t*)mir_alloc(length);
+ if (fread(avatar, sizeof(uint8_t), length, transfer->hFile) != length)
+ {
+ proto->debugLogA(__FUNCTION__": failed to read avatar file");
+ mir_free(avatar);
+ return;
+ }
+
+ uint8_t hash[TOX_HASH_LENGTH];
+ tox_hash(hash, avatar, TOX_HASH_LENGTH);
+ db_set_blob(transfer->pfts.hContact, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, hash, TOX_HASH_LENGTH);
+ mir_free(avatar);
+
+ fclose(transfer->hFile);
+ transfer->hFile = NULL;
+
+ PROTO_AVATAR_INFORMATIONT pai = { sizeof(pai) };
+ pai.format = PA_FORMAT_PNG;
+ pai.hContact = transfer->pfts.hContact;
+ mir_tstrcpy(pai.filename, transfer->pfts.tszCurrentFile);
+ proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
+ proto->transfers.Remove(transfer);
+ return;
+ }
+
proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, isFileFullyTransfered ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)transfer, 0);
proto->transfers.Remove(transfer);
}
@@ -220,7 +259,7 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **pp
transfer->pfts.tszWorkingDir = fileDir;
transfer->hFile = hFile;
transfers.Add(transfer);
-
+
mir_free(name);
return (HANDLE)transfer;
}
diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h
index c185209091..2ac2726b9d 100644
--- a/protocols/Tox/src/tox_transfer.h
+++ b/protocols/Tox/src/tox_transfer.h
@@ -22,6 +22,8 @@ struct FileTransferParam
uint32_t fileNumber;
uint64_t transferNumber;
+ bool isAvatar;
+
FileTransferParam(uint32_t friendNumber, uint32_t fileNumber, const TCHAR *fileName, uint64_t fileSize)
{
status = NONE;
@@ -40,6 +42,8 @@ struct FileTransferParam
pfts.totalProgress = pfts.currentFileProgress = 0;
pfts.currentFileNumber = 0;
pfts.tszWorkingDir = NULL;
+
+ isAvatar = false;
}
bool OpenFile(const TCHAR *mode)