summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Skype/src/skype_contacts.cpp2
-rw-r--r--protocols/Skype/src/skype_profile.cpp2
-rw-r--r--protocols/Skype/src/skype_proto.cpp1
-rw-r--r--protocols/Skype/src/skype_proto.h3
-rw-r--r--protocols/Skype/src/skype_services.cpp4
-rw-r--r--protocols/Skype/src/skype_utils.cpp62
6 files changed, 37 insertions, 37 deletions
diff --git a/protocols/Skype/src/skype_contacts.cpp b/protocols/Skype/src/skype_contacts.cpp
index 0c809f4dfc..b15e383405 100644
--- a/protocols/Skype/src/skype_contacts.cpp
+++ b/protocols/Skype/src/skype_contacts.cpp
@@ -46,7 +46,7 @@ void CSkypeProto::UpdateContactAvatar(HANDLE hContact, CContact::Ref contact)
contact->GetPropAvatarImage(data);
if ((newTS > oldTS) || (!newTS && data.size() > 0)) //hack for avatars without timestamp
{
- wchar_t *path = this->GetContactAvatarFilePath(this->GetSettingString(hContact, "sid"));
+ wchar_t *path = this->GetContactAvatarFilePath(hContact);
FILE* fp = _wfopen(path, L"wb");
if (fp)
{
diff --git a/protocols/Skype/src/skype_profile.cpp b/protocols/Skype/src/skype_profile.cpp
index 1554c47114..a5854ab9ff 100644
--- a/protocols/Skype/src/skype_profile.cpp
+++ b/protocols/Skype/src/skype_profile.cpp
@@ -12,7 +12,7 @@ void CSkypeProto::UpdateOwnAvatar()
if (data.size() > 0)
{
- wchar_t *path = this->GetContactAvatarFilePath(this->GetSettingString("sid"));
+ wchar_t *path = this->GetContactAvatarFilePath(NULL);
FILE* fp = _wfopen(path, L"wb");
if (fp)
{
diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp
index 665a0ce854..88ba779150 100644
--- a/protocols/Skype/src/skype_proto.cpp
+++ b/protocols/Skype/src/skype_proto.cpp
@@ -25,6 +25,7 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName)
this->CreateService(PS_SETMYAVATART, &CSkypeProto::SetMyAvatar);
this->InitNetLib();
+ this->InitCustomFolders();
}
CSkypeProto::~CSkypeProto()
diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h
index ca1f70a595..b8563fa53f 100644
--- a/protocols/Skype/src/skype_proto.h
+++ b/protocols/Skype/src/skype_proto.h
@@ -233,11 +233,12 @@ protected:
// utils
static void FakeAsync(void*);
+ void InitCustomFolders();
static int DetectAvatarFormatBuffer(const char *pBuffer);
static int DetectAvatarFormat(const wchar_t *path);
- wchar_t* GetContactAvatarFilePath(wchar_t *sid);
+ wchar_t* GetContactAvatarFilePath(HANDLE hContact);
int SkypeToMirandaLoginError(CAccount::LOGOUTREASON logoutReason);
diff --git a/protocols/Skype/src/skype_services.cpp b/protocols/Skype/src/skype_services.cpp
index c0a9135443..09aa2f29f2 100644
--- a/protocols/Skype/src/skype_services.cpp
+++ b/protocols/Skype/src/skype_services.cpp
@@ -20,8 +20,8 @@ int __cdecl CSkypeProto::GetAvatarInfo(WPARAM, LPARAM lParam)
wchar_t *sid = this->GetSettingString(pai->hContact, "sid");
if (sid)
{
- wchar_t *path = this->GetContactAvatarFilePath(sid);
- if (path && !_waccess(path, 0))
+ wchar_t *path = this->GetContactAvatarFilePath(pai->hContact);
+ if (path && !_waccess(path, 0))
{
::wcsncpy(pai->filename, path, SIZEOF(pai->filename));
pai->format = PA_FORMAT_JPEG;
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;
}