summaryrefslogtreecommitdiff
path: root/protocols/Tox
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-07 19:15:57 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-07 19:15:57 +0000
commit7e78293fcbabc945a8a9e5bcaab121fbbf697c4c (patch)
tree68a371d8f9b8ca5604ce5359e681f9461a956c71 /protocols/Tox
parent81c987f5b850447389b2621037a364c3fcb0ba73 (diff)
Tox: fixed avatar work
git-svn-id: http://svn.miranda-ng.org/main/trunk@13480 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r--protocols/Tox/src/tox_avatars.cpp15
-rw-r--r--protocols/Tox/src/tox_contacts.cpp7
-rw-r--r--protocols/Tox/src/tox_transfer.cpp17
-rw-r--r--protocols/Tox/src/tox_transfer.h2
4 files changed, 20 insertions, 21 deletions
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp
index cfab678533..5e9ddacef7 100644
--- a/protocols/Tox/src/tox_avatars.cpp
+++ b/protocols/Tox/src/tox_avatars.cpp
@@ -78,7 +78,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash)
}
TOX_ERR_FILE_SEND error;
- uint32_t fileNumber = tox_file_send(tox, friendNumber, TOX_FILE_KIND_AVATAR, length, NULL, hash, TOX_HASH_LENGTH, &error);
+ uint32_t fileNumber = tox_file_send(tox, friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error);
if (error != TOX_ERR_FILE_SEND_OK)
{
mir_free(data);
@@ -86,7 +86,8 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash)
return;
}
- FileTransferParam *transfer = new FileTransferParam(friendNumber, fileNumber, _T("avatar"), length);
+ AvatarTransferParam *transfer = new AvatarTransferParam(friendNumber, fileNumber, NULL, length);
+ memcpy(transfer->hash, hash, TOX_HASH_LENGTH);
transfer->pfts.hContact = hContact;
transfer->hFile = _tfopen(path.c_str(), L"rb");
transfers.Add(transfer);
@@ -136,7 +137,7 @@ INT_PTR CToxProto::GetAvatarInfo(WPARAM, LPARAM lParam)
std::tstring path = GetAvatarFilePath(pai->hContact);
if (IsFileExists(path))
{
- _tcsncpy(pai->filename, path.c_str(), SIZEOF(pai->filename));
+ mir_tstrncpy(pai->filename, path.c_str(), SIZEOF(pai->filename));
pai->format = PA_FORMAT_PNG;
return GAIR_SUCCESS;
@@ -156,7 +157,7 @@ INT_PTR CToxProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
std::tstring path = GetAvatarFilePath();
if (IsFileExists(path))
{
- _tcsncpy((TCHAR*)wParam, path.c_str(), (int)lParam);
+ mir_tstrncpy((TCHAR*)wParam, path.c_str(), (int)lParam);
return 0;
}
@@ -196,7 +197,7 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
}
TOX_ERR_FILE_SEND error;
- if (!tox_file_send(tox, NULL, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error))
+ if (!tox_file_send(tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error))
{
debugLogA(__FUNCTION__": failed to unset avatar");
return -1;
@@ -205,11 +206,9 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
}
if (IsFileExists(avatarPath))
- {
DeleteFile(avatarPath.c_str());
- }
- db_unset(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH);
+ delSetting(TOX_SETTINGS_AVATAR_HASH);
}
return 0;
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 2c410f4cad..2e123ca6a3 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -381,20 +381,21 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE
}
TOX_ERR_FILE_SEND error;
- uint32_t fileNumber = tox_file_send(proto->tox, friendNumber, TOX_FILE_KIND_AVATAR, length, NULL, hash, TOX_HASH_LENGTH, &error);
+ uint32_t fileNumber = tox_file_send(proto->tox, friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error);
if (error != TOX_ERR_FILE_SEND_OK)
{
proto->debugLogA(__FUNCTION__": failed to set new avatar");
return;
}
- FileTransferParam *transfer = new FileTransferParam(friendNumber, fileNumber, _T("avatar"), length);
+ AvatarTransferParam *transfer = new AvatarTransferParam(friendNumber, fileNumber, NULL, length);
+ memcpy(transfer->hash, hash, TOX_HASH_LENGTH);
transfer->pfts.hContact = hContact;
transfer->hFile = hFile;
proto->transfers.Add(transfer);
}
else
- tox_file_send(proto->tox, NULL, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL);
+ tox_file_send(proto->tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL);
}
else
{
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp
index 110b1fc895..90d61a4d87 100644
--- a/protocols/Tox/src/tox_transfer.cpp
+++ b/protocols/Tox/src/tox_transfer.cpp
@@ -14,13 +14,11 @@ void CToxProto::OnFriendFile(Tox*, uint32_t friendNumber, uint32_t fileNumber, u
{
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);
+ ptrT id(proto->getTStringA(hContact, TOX_SETTINGS_ID));
+ TCHAR avatarName[MAX_PATH];
+ mir_sntprintf(avatarName, MAX_PATH, _T("%s.png"), id);
- AvatarTransferParam *transfer = new AvatarTransferParam(friendNumber, fileNumber, NULL, fileSize);
+ AvatarTransferParam *transfer = new AvatarTransferParam(friendNumber, fileNumber, avatarName, fileSize);
transfer->pfts.hContact = hContact;
proto->transfers.Add(transfer);
@@ -81,9 +79,10 @@ HANDLE CToxProto::OnFileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCH
{
int action = FILERESUME_OVERWRITE;
const TCHAR **szFilename = (const TCHAR**)mir_alloc(sizeof(TCHAR) * 2);
- szFilename[0] = &fullPath[0];
+ szFilename[0] = fullPath;
szFilename[1] = NULL;
OnFileResume(hTransfer, &action, szFilename);
+ //mir_free(szFilename);
}
return hTransfer;
@@ -94,14 +93,14 @@ int CToxProto::OnFileResume(HANDLE hTransfer, int *action, const PROTOCHAR **szF
{
FileTransferParam *transfer = (FileTransferParam*)hTransfer;
- if (*action = FILERESUME_SKIP)
+ if (*action == FILERESUME_SKIP)
{
tox_file_control(tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
transfers.Remove(transfer);
return 0;
}
- if (*action = FILERESUME_RENAME)
+ if (*action == FILERESUME_RENAME)
transfer->ChangeName(*szFilename);
TCHAR *mode = *action == FILERESUME_OVERWRITE ? _T("wb") : _T("ab");
diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h
index b8511779f3..12d651339a 100644
--- a/protocols/Tox/src/tox_transfer.h
+++ b/protocols/Tox/src/tox_transfer.h
@@ -69,7 +69,7 @@ struct AvatarTransferParam : public FileTransferParam
uint8_t hash[TOX_HASH_LENGTH];
AvatarTransferParam(uint32_t friendNumber, uint32_t fileNumber, const TCHAR *fileName, uint64_t fileSize)
- : FileTransferParam(friendNumber, fileNumber, NULL, fileSize)
+ : FileTransferParam(friendNumber, fileNumber, fileName, fileSize)
{
transferType = TOX_FILE_KIND_AVATAR;
}