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/Gadu-Gadu/src/avatar.cpp | 22 +++++----------------- protocols/Gadu-Gadu/src/gg.cpp | 28 +--------------------------- protocols/Gadu-Gadu/src/gg_proto.cpp | 3 +++ 3 files changed, 9 insertions(+), 44 deletions(-) (limited to 'protocols/Gadu-Gadu') 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(); } -- cgit v1.2.3