diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-05-16 19:48:58 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-05-16 19:48:58 +0000 |
commit | d5ccefb48ac1818e9e8c5700aa019d17892d933b (patch) | |
tree | 627c94545552ec4eddae7f883c59980d9db7cdf5 /protocols/Tox | |
parent | c286424ea035f96133fc17f98710cdd905023364 (diff) |
Tox: avatars tuning
git-svn-id: http://svn.miranda-ng.org/main/trunk@13655 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox')
-rw-r--r-- | protocols/Tox/src/stdafx.h | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_avatars.cpp | 80 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 2 |
3 files changed, 30 insertions, 54 deletions
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h index be70a8bf6b..c9470524b2 100644 --- a/protocols/Tox/src/stdafx.h +++ b/protocols/Tox/src/stdafx.h @@ -94,7 +94,7 @@ enum TOX_DB_EVENT #define PSR_AUDIO "/RecvAudio"
-#define TOX_MAX_AVATAR_SIZE 1024 * 1024
+#define TOX_MAX_AVATAR_SIZE 1 << 16 // 2 ^ 16 bytes
extern HMODULE g_hToxLibrary;
diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index d93f62584a..2837502959 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -20,7 +20,7 @@ std::tstring CToxProto::GetAvatarFilePath(MCONTACT hContact) return path;
}
-void CToxProto::SetToxAvatar(std::tstring path, bool checkHash)
+void CToxProto::SetToxAvatar(std::tstring path)
{
FILE *hFile = _tfopen(path.c_str(), L"rb");
if (!hFile)
@@ -52,7 +52,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) DBVARIANT dbv;
uint8_t hash[TOX_HASH_LENGTH];
tox_hash(hash, data, TOX_HASH_LENGTH);
- if (checkHash && !db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
+ if (!db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
{
if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) == 0)
{
@@ -64,6 +64,8 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) db_free(&dbv);
}
+ db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH);
+
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
@@ -95,26 +97,12 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) }
mir_free(data);
-
- if (checkHash)
- db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH);
}
INT_PTR CToxProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
- case AF_MAXSIZE:
- {
- POINT *size = (POINT *)lParam;
- if (size)
- {
- size->x = 300;
- size->y = 300;
- }
- }
- break;
-
case AF_ENABLED:
return 1;
@@ -150,20 +138,11 @@ INT_PTR CToxProto::GetAvatarInfo(WPARAM, LPARAM lParam) INT_PTR CToxProto::GetMyAvatar(WPARAM wParam, LPARAM lParam)
{
- if (!wParam)
- {
- return -2;
- }
-
std::tstring path = GetAvatarFilePath();
if (IsFileExists(path))
- {
mir_tstrncpy((TCHAR*)wParam, path.c_str(), (int)lParam);
- return 0;
- }
-
- return -1;
+ return 0;
}
INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam)
@@ -175,43 +154,40 @@ INT_PTR CToxProto::SetMyAvatar(WPARAM, LPARAM lParam) if (!CopyFile(path, avatarPath.c_str(), FALSE))
{
debugLogA("CToxProto::SetMyAvatar: failed to copy new avatar to avatar cache");
- return -1;
+ return 0;
}
if (IsOnline())
- SetToxAvatar(avatarPath, true);
+ SetToxAvatar(avatarPath);
+
+ return 0;
}
- else
+
+ if (IsOnline())
{
- if (IsOnline())
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
+ continue;
+
+ int32_t friendNumber = GetToxFriendNumber(hContact);
+ if (friendNumber == UINT32_MAX)
+ continue;
+
+ TOX_ERR_FILE_SEND error;
+ tox_file_send(tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error);
+ if (error != TOX_ERR_FILE_SEND_OK)
{
- if (GetContactStatus(hContact) == ID_STATUS_OFFLINE)
- continue;
-
- int32_t friendNumber = GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
- debugLogA(__FUNCTION__": failed to unset avatar");
- return -1;
- }
-
- TOX_ERR_FILE_SEND error;
- tox_file_send(tox, friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, &error);
- if (error != TOX_ERR_FILE_SEND_OK)
- {
- debugLogA(__FUNCTION__": failed to unset avatar");
- return -1;
- }
+ debugLogA(__FUNCTION__": failed to unset avatar (%d)", error);
+ return 0;
}
}
+ }
- if (IsFileExists(avatarPath))
- DeleteFile(avatarPath.c_str());
+ if (IsFileExists(avatarPath))
+ DeleteFile(avatarPath.c_str());
- delSetting(TOX_SETTINGS_AVATAR_HASH);
- }
+ delSetting(TOX_SETTINGS_AVATAR_HASH);
return 0;
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 37a41138c9..0431a5b264 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -237,7 +237,7 @@ private: // avatars
std::tstring GetAvatarFilePath(MCONTACT hContact = NULL);
- void SetToxAvatar(std::tstring path, bool checkHash = false);
+ void SetToxAvatar(std::tstring path);
INT_PTR __cdecl GetAvatarCaps(WPARAM wParam, LPARAM lParam);
INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM lParam);
|