From b56c4ba2c45b62c1c9c175933d2ffc26c61bf6f3 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sat, 24 Nov 2012 17:01:04 +0000 Subject: more correct work with folders git-svn-id: http://svn.miranda-ng.org/main/trunk@2466 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/skype_utils.cpp | 62 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 32 deletions(-) (limited to 'protocols/Skype/src/skype_utils.cpp') diff --git a/protocols/Skype/src/skype_utils.cpp b/protocols/Skype/src/skype_utils.cpp index 2af0a496cf..bfe155178e 100644 --- a/protocols/Skype/src/skype_utils.cpp +++ b/protocols/Skype/src/skype_utils.cpp @@ -264,46 +264,44 @@ int CSkypeProto::DetectAvatarFormat(const wchar_t *path) return CSkypeProto::DetectAvatarFormatBuffer(pBuf); } -wchar_t* CSkypeProto::GetContactAvatarFilePath(wchar_t *sid) +static HANDLE hAvatarsFolder = NULL; +static bool bInitDone = false; + +void CSkypeProto::InitCustomFolders() { - wchar_t* path = new wchar_t[MAX_PATH * 2]; - - FOLDERSGETDATA fgd = {0}; - fgd.cbSize = sizeof(FOLDERSGETDATA); - fgd.nMaxPathSize = MAX_PATH * 2; - fgd.szPathT = path; - fgd.flags = FF_UNICODE; - - HANDLE hAvatarsFolder; - if (::ServiceExists(MS_FOLDERS_REGISTER_PATH)) - { - wchar_t tszPath[MAX_PATH * 2]; - ::mir_sntprintf( - tszPath, - MAX_PATH * 2, - _T("%%miranda_avatarcache%%\\") _T(TCHAR_STR_PARAM) _T("\\"), - this->m_szModuleName); - - hAvatarsFolder = ::FoldersRegisterCustomPathT(this->m_szModuleName, "Avatars Cache", tszPath); - } + if (bInitDone) + return; + + bInitDone = true; + if (ServiceExists(MS_FOLDERS_REGISTER_PATH)) { + TCHAR AvatarsFolder[MAX_PATH]; + mir_sntprintf(AvatarsFolder, SIZEOF(AvatarsFolder), _T("%%miranda_avatarcache%%\\") _T(TCHAR_STR_PARAM), this->m_szModuleName); + hAvatarsFolder = FoldersRegisterCustomPathT(this->m_szModuleName, "Avatars", AvatarsFolder); + } +} + +wchar_t* CSkypeProto::GetContactAvatarFilePath(HANDLE hContact) +{ + wchar_t* path = new wchar_t[MAX_PATH]; - if (::CallService(MS_FOLDERS_GET_PATH, (WPARAM)hAvatarsFolder, (LPARAM)&fgd)) + this->InitCustomFolders(); + + if (hAvatarsFolder == NULL || FoldersGetCustomPathT(hAvatarsFolder, path, MAX_PATH, _T(""))) { wchar_t *tmpPath = ::Utils_ReplaceVarsT(L"%miranda_avatarcache%"); - ::mir_sntprintf(path, MAX_PATH * 2, _T("%s\\") _T(TCHAR_STR_PARAM) _T("\\"), tmpPath, this->m_szModuleName); + ::mir_sntprintf(path, MAX_PATH, _T("%s\\") _T(TCHAR_STR_PARAM), tmpPath, this->m_szModuleName); mir_free(tmpPath); } - else - wcscat(path, L"\\"); - // make sure the avatar cache directory exists - ::CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)path); + DWORD dwAttributes = GetFileAttributes(path); + if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) + CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)path); - if (sid) { - ::wcscat(path, sid); - ::wcscat(path, L".jpg"); - } else - path = NULL; + wchar_t *sid = this->GetSettingString(hContact, "sid"); + if (hContact != NULL) + ::mir_sntprintf(path, MAX_PATH, _T("%s\\%s.jpg"), path, sid); + else if (sid != NULL) + ::mir_sntprintf(path, MAX_PATH, _T("%s\\%s avatar.jpg"), path, sid); return path; } -- cgit v1.2.3