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/Discord/src/avatars.cpp | 4 +--- protocols/Discord/src/proto.cpp | 3 +++ protocols/Facebook/src/avatars.cpp | 7 ++----- protocols/Facebook/src/proto.cpp | 3 +++ protocols/Gadu-Gadu/src/avatar.cpp | 22 +++++----------------- protocols/Gadu-Gadu/src/gg.cpp | 28 +--------------------------- protocols/Gadu-Gadu/src/gg_proto.cpp | 3 +++ protocols/ICQ-WIM/src/proto.cpp | 5 ++++- protocols/ICQ-WIM/src/server.cpp | 2 +- protocols/ICQ-WIM/src/utils.cpp | 9 +++++---- protocols/JabberG/src/jabber_misc.cpp | 19 ++++++++----------- protocols/JabberG/src/jabber_proto.cpp | 3 +++ protocols/SkypeWeb/src/skype_avatars.cpp | 9 +++++---- protocols/SkypeWeb/src/skype_proto.cpp | 5 ++--- protocols/SkypeWeb/src/skype_proto.h | 2 -- protocols/Steam/src/steam_avatars.cpp | 12 ++++-------- protocols/Steam/src/steam_proto.cpp | 2 ++ protocols/Telegram/src/avatars.cpp | 10 ++++++++++ protocols/Telegram/src/proto.cpp | 5 ++++- protocols/Telegram/src/proto.h | 12 ++++++++---- protocols/Tox/src/tox_avatars.cpp | 17 +++++------------ protocols/Tox/src/tox_proto.cpp | 2 ++ protocols/VKontakte/src/vk_avatars.cpp | 10 +++++----- protocols/VKontakte/src/vk_proto.cpp | 3 +++ protocols/WhatsApp/src/avatars.cpp | 4 ++-- protocols/WhatsApp/src/proto.cpp | 5 +---- protocols/WhatsApp/src/proto.h | 1 - 27 files changed, 92 insertions(+), 115 deletions(-) (limited to 'protocols') diff --git a/protocols/Discord/src/avatars.cpp b/protocols/Discord/src/avatars.cpp index fc49a7ec1a..a131b23856 100644 --- a/protocols/Discord/src/avatars.cpp +++ b/protocols/Discord/src/avatars.cpp @@ -19,9 +19,7 @@ along with this program. If not, see . CMStringW CDiscordProto::GetAvatarFilename(MCONTACT hContact) { - CMStringW wszResult(FORMAT, L"%s\\%S", VARSW(L"%miranda_avatarcache%"), m_szModuleName); - CreateDirectoryTreeW(wszResult); - + auto wszResult(GetAvatarPath()); wszResult.AppendChar('\\'); const wchar_t* szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_PNG)); diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 2bd02f704d..470dbdf7b5 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -75,6 +75,9 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : HookProtoEvent(PE_VOICE_CALL_STATE, &CDiscordProto::OnVoiceState); + // avatars + CreateDirectoryTreeW(GetAvatarPath()); + // database db_set_resident(m_szModuleName, "XStatusMsg"); diff --git a/protocols/Facebook/src/avatars.cpp b/protocols/Facebook/src/avatars.cpp index f8fd4fb73e..43b12dcdac 100644 --- a/protocols/Facebook/src/avatars.cpp +++ b/protocols/Facebook/src/avatars.cpp @@ -24,12 +24,9 @@ along with this program. If not, see . void FacebookProto::GetAvatarFilename(MCONTACT hContact, wchar_t *pwszFileName) { - wchar_t wszPath[MAX_PATH]; - mir_snwprintf(wszPath, MAX_PATH, L"%s\\%S", VARSW(L"%miranda_avatarcache%"), m_szModuleName); - CreateDirectoryTreeW(wszPath); - + CMStringW wszPath(GetAvatarPath()); CMStringW id(getMStringW(hContact, DBKEY_ID)); - mir_snwprintf(pwszFileName, MAX_PATH, L"%s\\%s.jpg", wszPath, id.c_str()); + mir_snwprintf(pwszFileName, MAX_PATH, L"%s\\%s.jpg", wszPath.c_str(), id.c_str()); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp index db2d401e21..b773e6b7b0 100644 --- a/protocols/Facebook/src/proto.cpp +++ b/protocols/Facebook/src/proto.cpp @@ -87,6 +87,9 @@ FacebookProto::FacebookProto(const char *proto_name, const wchar_t *username) : m_sid = _atoi64(getMStringA(DBKEY_SID)); m_szSyncToken = getMStringA(DBKEY_SYNC_TOKEN); + // Avatars + CreateDirectoryTreeW(GetAvatarPath()); + // Create standard network connection NETLIBUSER nlu = {}; nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_UNICODE; diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index 48db5027c7..0b713871c3 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -28,32 +28,20 @@ // void GaduProto::getAvatarFilename(MCONTACT hContact, wchar_t *pszDest, int cbLen) { - int tPathLen = mir_snwprintf(pszDest, cbLen, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - - if (_waccess(pszDest, 0)) { - int ret = CreateDirectoryTreeW(pszDest); - if (ret == 0) - debugLogW(L"getAvatarFilename(): Created new directory for avatar cache: %s.", pszDest); - else { - debugLogW(L"getAvatarFilename(): Can not create directory for avatar cache: %s. errno=%d: %s", pszDest, errno, ws_strerror(errno)); - wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot create avatars cache directory. ERROR: %d: %s\n%s"), errno, ws_strerror(errno), pszDest); - showpopup(m_tszUserName, error, GG_POPUP_ERROR | GG_POPUP_ALLOW_MSGBOX | GG_POPUP_ONCE); - } - } + CMStringW wszPath(GetAvatarPath()); const wchar_t *avatartype = ProtoGetAvatarExtension(getByte(hContact, GG_KEY_AVATARTYPE, GG_KEYDEF_AVATARTYPE)); if (hContact != NULL) { DBVARIANT dbv; if (!getString(hContact, GG_KEY_AVATARHASH, &dbv)) { - wchar_t* avatarHashT = mir_a2u(dbv.pszVal); - mir_snwprintf(pszDest + tPathLen, cbLen - tPathLen, L"\\%s%s", avatarHashT, avatartype); - mir_free(avatarHashT); + wszPath.AppendFormat(L"\\%S%s", dbv.pszVal, avatartype); db_free(&dbv); } } - else mir_snwprintf(pszDest + tPathLen, cbLen - tPathLen, L"\\%S avatar%s", m_szModuleName, avatartype); + else wszPath.AppendFormat(L"\\%S avatar%s", m_szModuleName, avatartype); + + wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE); } bool GaduProto::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts) diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 9b4e1ff1b1..34b7e1b8fa 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -162,33 +162,7 @@ void GaduProto::cleanuplastplugin(uint32_t version) // Store current plugin version setDword(GG_PLUGINVERSION, pluginInfoEx.version); - //1. clean files: %miranda_avatarcache%\GG\*.(null) - if (version < PLUGIN_MAKE_VERSION(0, 11, 0, 2)) { - debugLogA("cleanuplastplugin() 1: version=%d Cleaning junk avatar files from < 0.11.0.2", version); - - wchar_t avatarsPath[MAX_PATH]; - mir_snwprintf(avatarsPath, L"%s\\%s", VARSW(L"%miranda_avatarcache%").get(), m_tszUserName); - - debugLogW(L"cleanuplastplugin() 1: miranda_avatarcache = %s", avatarsPath); - - wchar_t spec[MAX_PATH + 10]; - mir_snwprintf(spec, L"%s\\*.(null)", avatarsPath); - WIN32_FIND_DATA ffd; - HANDLE hFind = FindFirstFile(spec, &ffd); - if (hFind != INVALID_HANDLE_VALUE) { - do { - wchar_t filePathT[2 * MAX_PATH + 10]; - mir_snwprintf(filePathT, L"%s\\%s", avatarsPath, ffd.cFileName); - if (!_waccess(filePathT, 0)) { - debugLogW(L"cleanuplastplugin() 1: remove file = %s", filePathT); - _wremove(filePathT); - } - } while (FindNextFile(hFind, &ffd) != 0); - FindClose(hFind); - } - } - - //2. force SSL and keepalive; overwrite old server list; + // force SSL and keepalive; overwrite old server list; if (version < PLUGIN_MAKE_VERSION(0, 11, 0, 4)) { setWString("ServerHosts", GG_KEYDEF_SERVERHOSTS); m_useManualHosts = 1; diff --git a/protocols/Gadu-Gadu/src/gg_proto.cpp b/protocols/Gadu-Gadu/src/gg_proto.cpp index ee0222f8c3..3df051bdb6 100644 --- a/protocols/Gadu-Gadu/src/gg_proto.cpp +++ b/protocols/Gadu-Gadu/src/gg_proto.cpp @@ -90,6 +90,9 @@ GaduProto::GaduProto(const char *pszProtoName, const wchar_t *tszUserName) : gc_init(); links_instance_init(); + + // Avatars + CreateDirectoryTreeW(GetAvatarPath()); initavatarrequestthread(); } diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index 3078cf836f..e71e2dc053 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -88,6 +88,9 @@ CIcqProto::CIcqProto(const char *aProtoName, const wchar_t *aUserName) : gcr.pszModule = m_szModuleName; Chat_Register(&gcr); + // avatars + CreateDirectoryTreeW(GetAvatarPath()); + // netlib handle NETLIBUSER nlu = {}; nlu.szSettingsModule = m_szModuleName; @@ -132,7 +135,7 @@ void CIcqProto::OnModulesLoaded() HookProtoEvent(ME_USERINFO_INITIALISE, &CIcqProto::OnUserInfoInit); // load custom smilies - CMStringW wszPath(FORMAT, L"%s\\%S\\Stickers\\*.png", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); + CMStringW wszPath(GetAvatarPath()); SMADD_CONT cont = { 2, m_szModuleName, wszPath }; CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, LPARAM(&cont)); } diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index 3a0e198280..ce3dad53bb 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -934,7 +934,7 @@ void CIcqProto::OnGetSticker(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) CMStringW wszPath(FORMAT, L"%s\\%S\\Stickers", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); CreateDirectoryTreeW(wszPath); - CMStringW wszFileName(FORMAT, L"%s\\STK{%s}.png", wszPath.c_str(), pReq->pUserInfo); + CMStringW wszFileName(FORMAT, L"%s\\STK{%s}.png", wszPath.c_str(), (wchar_t*)pReq->pUserInfo); FILE *out = _wfopen(wszFileName, L"wb"); fwrite(pReply->pData, 1, pReply->dataLength, out); fclose(out); diff --git a/protocols/ICQ-WIM/src/utils.cpp b/protocols/ICQ-WIM/src/utils.cpp index dfa73b8fb4..9a2e0b35ef 100644 --- a/protocols/ICQ-WIM/src/utils.cpp +++ b/protocols/ICQ-WIM/src/utils.cpp @@ -150,13 +150,14 @@ void CIcqProto::Json2string(MCONTACT hContact, const JSONNode &node, const char void CIcqProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen) { - int tPathLen = mir_snwprintf(pszDest, cbLen, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - CreateDirectoryTreeW(pszDest); - pszDest[tPathLen++] = '\\'; + CMStringW wszPath(GetAvatarPath()); + wszPath += '\\'; CMStringW wszFileName(getMStringW(hContact, "IconId")); const wchar_t* szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_PNG)); - mir_snwprintf(pszDest + tPathLen, MAX_PATH - tPathLen, L"%s%s", wszFileName.c_str(), szFileType); + wszPath.AppendFormat(L"%s%s", wszFileName.c_str(), szFileType); + + wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE); } INT_PTR __cdecl CIcqProto::GetAvatar(WPARAM wParam, LPARAM lParam) diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index 71115ef87a..68f83280bf 100644 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -135,13 +135,10 @@ bool CJabberProto::AddDbPresenceEvent(MCONTACT hContact, uint8_t btEventType) /////////////////////////////////////////////////////////////////////////////// // JabberGetAvatarFileName() - gets a file name for the avatar image -void CJabberProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen) +void CJabberProto::GetAvatarFileName(MCONTACT hContact, wchar_t *pszDest, size_t cbLen) { - size_t tPathLen = mir_snwprintf(pszDest, cbLen, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - - CreateDirectoryTreeW(pszDest); - - pszDest[tPathLen++] = '\\'; + CMStringW wszPath(GetAvatarPath()); + wszPath += '\\'; const wchar_t* szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_PNG)); @@ -153,17 +150,17 @@ void CJabberProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t strncpy_s(str, szJid, _TRUNCATE); else _i64toa((LONG_PTR)hContact, str, 10); - mir_snwprintf(pszDest + tPathLen, MAX_PATH - tPathLen, L"%S%s", JabberSha1(str, buf), szFileType); + wszPath.AppendFormat(L"%S%s", JabberSha1(str, buf), szFileType); } else if (m_ThreadInfo != nullptr) { - mir_snwprintf(pszDest + tPathLen, MAX_PATH - tPathLen, L"%s@%s avatar%s", - Utf2T(m_ThreadInfo->conn.username).get(), Utf2T(m_ThreadInfo->conn.server).get(), szFileType); + wszPath.AppendFormat(L"%s@%s avatar%s", Utf2T(m_ThreadInfo->conn.username).get(), Utf2T(m_ThreadInfo->conn.server).get(), szFileType); } else { ptrA res1(getStringA("LoginName")), res2(getStringA("LoginServer")); - mir_snwprintf(pszDest + tPathLen, MAX_PATH - tPathLen, L"%S@%S avatar%s", - (res1) ? (LPSTR)res1 : "noname", (res2) ? (LPSTR)res2 : m_szModuleName, szFileType); + wszPath.AppendFormat(L"%S@%S avatar%s", (res1) ? (LPSTR)res1 : "noname", (res2) ? (LPSTR)res2 : m_szModuleName, szFileType); } + + wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE); } /////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 4fb6dbf5a9..9762a297f8 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -218,6 +218,9 @@ CJabberProto::CJabberProto(const char *aProtoName, const wchar_t *aUserName) : OmemoInitDevice(); } + // avatars + CreateDirectoryTreeW(GetAvatarPath()); + // network initialization NETLIBUSER nlu = {}; nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_UNICODE; diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index 015b56965b..94d097c852 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -122,15 +122,16 @@ INT_PTR CSkypeProto::SvcGetMyAvatar(WPARAM wParam, LPARAM lParam) void CSkypeProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t cbLen) { - int tPathLen = mir_snwprintf(pszDest, cbLen, L"%s\\%s", VARSW(L"%miranda_avatarcache%").get(), m_tszUserName); - CreateDirectoryTreeW(pszDest); - pszDest[tPathLen++] = '\\'; + CMStringW wszPath(GetAvatarPath()); + wszPath += '\\'; const wchar_t* szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_JPEG)); CMStringA username(getId(hContact)); username.Replace("live:", "__live_"); username.Replace("facebook:", "__facebook_"); - mir_snwprintf(pszDest + tPathLen, MAX_PATH - tPathLen, L"%S%s", username.c_str(), szFileType); + wszPath.AppendFormat(L"%S%s", username.c_str(), szFileType); + + wcsncpy_s(pszDest, cbLen, wszPath, _TRUNCATE); } void CSkypeProto::SetAvatarUrl(MCONTACT hContact, CMStringW &tszUrl) diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 5eb23d11ca..5288ea81ac 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -51,10 +51,9 @@ CSkypeProto::CSkypeProto(const char* protoName, const wchar_t* userName) : HookProtoEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit); HookProtoEvent(ME_DB_EVENT_MARKED_READ, &CSkypeProto::OnDbEventRead); - m_tszAvatarFolder = std::wstring(VARSW(L"%miranda_avatarcache%")) + L"\\" + m_tszUserName; - CreateDirectoryTreeW(m_tszAvatarFolder.c_str()); + CreateDirectoryTreeW(GetAvatarPath()); - //sounds + // sounds g_plugin.addSound("skype_inc_call", L"SkypeWeb", LPGENW("Incoming call")); g_plugin.addSound("skype_call_canceled", L"SkypeWeb", LPGENW("Incoming call canceled")); diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 3517ae742a..4977bb71d3 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -189,8 +189,6 @@ private: INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM); - std::wstring m_tszAvatarFolder; - INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM); INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM); INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM); diff --git a/protocols/Steam/src/steam_avatars.cpp b/protocols/Steam/src/steam_avatars.cpp index 9a72b6fec0..cee909ed30 100644 --- a/protocols/Steam/src/steam_avatars.cpp +++ b/protocols/Steam/src/steam_avatars.cpp @@ -2,17 +2,13 @@ wchar_t* CSteamProto::GetAvatarFilePath(MCONTACT hContact) { - wchar_t path[MAX_PATH]; - mir_snwprintf(path, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - CreateDirectoryTreeW(path); - ptrA steamId(getStringA(hContact, "SteamID")); - if (steamId != NULL) - mir_snwprintf(path, MAX_PATH, L"%s\\%S.jpg", path, steamId.get()); - else + if (steamId == NULL) return nullptr; - return mir_wstrdup(path); + CMStringW wszPath(GetAvatarPath()); + wszPath.AppendFormat(L"\\%S.jpg", steamId.get()); + return wszPath.Detach(); } bool CSteamProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATION &pai) diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index f185171edd..8a2959f84a 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -49,6 +49,8 @@ CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : SetAllContactStatuses(ID_STATUS_OFFLINE); // avatar API + CreateDirectoryTreeW(GetAvatarPath()); + CreateProtoService(PS_GETAVATARINFO, &CSteamProto::GetAvatarInfo); CreateProtoService(PS_GETAVATARCAPS, &CSteamProto::GetAvatarCaps); CreateProtoService(PS_GETMYAVATAR, &CSteamProto::GetMyAvatar); diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index 6aacd51190..71ee97f3d6 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -17,6 +17,16 @@ along with this program. If not, see . #include "stdafx.h" +CMStringW CTelegramProto::GetAvatarFilename(MCONTACT hContact) +{ + CMStringW wszResult(GetAvatarPath()); + wszResult.AppendChar('\\'); + + const wchar_t *szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_JPEG)); + wszResult.AppendFormat(L"%s%s", getMStringW(hContact, DBKEY_ID).c_str(), szFileType); + return wszResult; +} + INT_PTR CTelegramProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam) { switch (wParam) { diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 2dd667314b..2767e7c059 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -38,12 +38,15 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) : HookProtoEvent(ME_OPT_INITIALISE, &CTelegramProto::OnOptionsInit); HookProtoEvent(ME_DB_EVENT_MARKED_READ, &CTelegramProto::OnDbMarkedRead); + // avatar + CreateDirectoryTreeW(GetAvatarPath()); + // default contacts group if (m_wszDefaultGroup == NULL) m_wszDefaultGroup = mir_wstrdup(L"WhatsApp"); m_iBaseGroup = Clist_GroupCreate(0, m_wszDefaultGroup); - // Create standard network connection + // create standard network connection NETLIBUSER nlu = {}; nlu.flags = NUF_UNICODE; nlu.szSettingsModule = m_szModuleName; diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index a303f81eb9..5ffe9e4222 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -151,6 +151,14 @@ class CTelegramProto : public PROTO void UpdateString(MCONTACT hContact, const char *pszSetting, const std::string &str); + // Avatars + CMStringW GetAvatarFilename(MCONTACT hContact); + + INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM); + INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM); + INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM); + INT_PTR __cdecl SvcSetMyAvatar(WPARAM, LPARAM); + // Users int64_t m_iOwnId; MGROUP m_iBaseGroup; @@ -187,10 +195,6 @@ public: // Services ////////////////////////////////////////////////////////////////////////// INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM); - INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM); - INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM); - INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM); - INT_PTR __cdecl SvcSetMyAvatar(WPARAM, LPARAM); // Events //////////////////////////////////////////////////////////////////////////// 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); diff --git a/protocols/VKontakte/src/vk_avatars.cpp b/protocols/VKontakte/src/vk_avatars.cpp index b7829cd58a..f6e02d8c2c 100644 --- a/protocols/VKontakte/src/vk_avatars.cpp +++ b/protocols/VKontakte/src/vk_avatars.cpp @@ -130,9 +130,8 @@ INT_PTR CVkProto::SvcGetMyAvatar(WPARAM wParam, LPARAM lParam) void CVkProto::GetAvatarFileName(MCONTACT hContact, wchar_t *pwszDest, size_t cbLen) { - int tPathLen = mir_snwprintf(pwszDest, cbLen, L"%s\\%S", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); - CreateDirectoryTreeW(pwszDest); - pwszDest[tPathLen++] = '\\'; + CMStringW wszPath(GetAvatarPath()); + wszPath += '\\'; const wchar_t *szFileType = L".jpg"; ptrW wszUrl(getWStringA(hContact, "AvatarUrl")); @@ -144,11 +143,12 @@ void CVkProto::GetAvatarFileName(MCONTACT hContact, wchar_t *pwszDest, size_t cb p = wcsrchr(wszUrl, '.'); if (p != nullptr) szFileType = p; - } LONG id = getDword(hContact, "ID", VK_INVALID_USER); - mir_snwprintf(pwszDest + tPathLen, MAX_PATH - tPathLen, L"%d%s", id, szFileType); + wszPath.AppendFormat(L"%d%s", id, szFileType); + + wcsncpy_s(pwszDest, cbLen, wszPath, _TRUNCATE); } void CVkProto::SetAvatarUrl(MCONTACT hContact, CMStringW &wszUrl) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index b894b36a64..f16be722f7 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -70,6 +70,9 @@ CVkProto::CVkProto(const char *szModuleName, const wchar_t *pwszUserName) : // Set all contacts offline -- in case we crashed SetAllContactStatuses(ID_STATUS_OFFLINE); + // Avatars + CreateDirectoryTreeW(GetAvatarPath()); + // Group chats GCREGISTER gcr = {}; gcr.ptszDispName = m_tszUserName; diff --git a/protocols/WhatsApp/src/avatars.cpp b/protocols/WhatsApp/src/avatars.cpp index dfe45817b7..fd4bbfde1f 100644 --- a/protocols/WhatsApp/src/avatars.cpp +++ b/protocols/WhatsApp/src/avatars.cpp @@ -90,7 +90,7 @@ INT_PTR WhatsAppProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) CMStringW WhatsAppProto::GetAvatarFileName(MCONTACT hContact) { - CMStringW result = m_tszAvatarFolder + L"\\"; + CMStringW result = GetAvatarPath() + L"\\"; CMStringA jid; if (hContact != NULL) { @@ -107,7 +107,7 @@ CMStringW WhatsAppProto::GetAvatarFileName(MCONTACT hContact) INT_PTR WhatsAppProto::GetMyAvatar(WPARAM wParam, LPARAM lParam) { - std::wstring tszOwnAvatar(m_tszAvatarFolder + L"\\myavatar.jpg"); + CMStringW tszOwnAvatar(GetAvatarPath() + L"\\myavatar.jpg"); wcsncpy_s((wchar_t*)wParam, lParam, tszOwnAvatar.c_str(), _TRUNCATE); return 0; } diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 8fabeb098b..40ab1336b8 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -85,10 +85,7 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) : CreateDirectoryTreeW(CMStringW(VARSW(L"%miranda_userdata%")) + L"\\" + _A2T(m_szModuleName)); // Avatars folder - m_tszAvatarFolder = CMStringW(VARSW(L"%miranda_avatarcache%")) + L"\\" + _A2T(m_szModuleName); - DWORD dwAttributes = GetFileAttributes(m_tszAvatarFolder.c_str()); - if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) - CreateDirectoryTreeW(m_tszAvatarFolder.c_str()); + CreateDirectoryTreeW(GetAvatarPath()); // default contacts group if (m_tszDefaultGroup == NULL) diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 8ec4593767..4edc296d3f 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -289,7 +289,6 @@ class WhatsAppProto : public PROTO ptrW m_tszDefaultGroup; CMStringA m_szJid; - CMStringW m_tszAvatarFolder; EVP_PKEY *m_pKeys; // private & public keys WANoise *m_noise; -- cgit v1.2.3