From 4c60037f6852f7771ed86e0b285a872e4bbadb87 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 17 Jan 2023 14:37:50 +0300 Subject: PROTO_INTERFACE::GetAvatarPath - new helper for calculating avatars' root for an account --- protocols/Tox/src/tox_avatars.cpp | 17 +++++------------ protocols/Tox/src/tox_proto.cpp | 2 ++ 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index 5e30c5c442..701b28710a 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -2,21 +2,16 @@ wchar_t* CToxProto::GetAvatarFilePath(MCONTACT hContact) { - wchar_t *path = (wchar_t*)mir_calloc(MAX_PATH * sizeof(wchar_t) + 1); - mir_snwprintf(path, MAX_PATH, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - CreateDirectoryTreeW(path); - ptrW address(getWStringA(hContact, TOX_SETTINGS_ID)); - if (address == NULL) { - mir_free(path); + if (address == NULL) return mir_wstrdup(L""); - } if (hContact && mir_wstrlen(address) > TOX_PUBLIC_KEY_SIZE * 2) address[TOX_PUBLIC_KEY_SIZE * 2] = 0; - mir_snwprintf(path, MAX_PATH, L"%s\\%s.png", path, address.get()); - return path; + CMStringW wszPath(GetAvatarPath()); + wszPath.AppendFormat(L"\\%s.png", address.get()); + return wszPath.Detach(); } void CToxProto::SetToxAvatar(const wchar_t* path) @@ -210,9 +205,7 @@ void CToxProto::OnGotFriendAvatarInfo(Tox *tox, AvatarTransferParam *transfer) db_free(&dbv); } - wchar_t path[MAX_PATH]; - mir_snwprintf(path, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - OnFileAllow(tox, transfer->pfts.hContact, transfer, path); + OnFileAllow(tox, transfer->pfts.hContact, transfer, GetAvatarPath()); } void CToxProto::OnGotFriendAvatarData(AvatarTransferParam *transfer) diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 1862bbc926..7a231ef89d 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -20,6 +20,8 @@ CToxProto::CToxProto(const char* protoName, const wchar_t* userName) setAllContactStatuses(ID_STATUS_OFFLINE); // avatars + CreateDirectoryTreeW(GetAvatarPath()); + CreateProtoService(PS_GETAVATARCAPS, &CToxProto::GetAvatarCaps); CreateProtoService(PS_GETAVATARINFO, &CToxProto::GetAvatarInfo); CreateProtoService(PS_GETMYAVATAR, &CToxProto::GetMyAvatar); -- cgit v1.2.3