void CJabberProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen) { int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName); DWORD dwAttributes = GetFileAttributes(pszDest); if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) CreateDirectoryTreeT(pszDest); pszDest[ tPathLen++ ] = '\\'; const TCHAR* szFileType = ProtoGetAvatarExtension( getByte(hContact, "AvatarType", PA_FORMAT_PNG)); if (hContact != NULL) { char str[ 256 ]; DBVARIANT dbv; if (!db_get_utf(hContact, m_szModuleName, "jid", &dbv)) { strncpy(str, dbv.pszVal, sizeof str); str[ sizeof(str)-1 ] = 0; db_free(&dbv); } else _i64toa((LONG_PTR)hContact, str, 10); mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S%s"), ptrA(JabberSha1(str)), szFileType); } else if (m_ThreadInfo != NULL) { mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%s@%S avatar%s"), m_ThreadInfo->username, m_ThreadInfo->server, szFileType); } else { ptrA res1( getStringA("LoginName")), res2( getStringA("LoginServer")); mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%S@%S avatar%s"), (res1) ? (LPSTR)res1 : "noname", (res2) ? (LPSTR)res2 : m_szModuleName, szFileType); } }
void SaveImage(SaveProtocolData &d, char *protocol, int format) { if (!Proto_IsAvatarFormatSupported(protocol, format)) return; mir_sntprintf(d.image_file_name, _T("%s%s"), d.temp_file, ProtoGetAvatarExtension(format)); if (BmpFilterSaveBitmap(d.hBmpProto, d.image_file_name, format == PA_FORMAT_JPEG ? JPEG_QUALITYSUPERB : 0)) return; if (d.max_size != 0 && GetFileSize(d.image_file_name) > d.max_size) { DeleteFile(d.image_file_name); if (format == PA_FORMAT_JPEG) { // Try with lower quality if (!BmpFilterSaveBitmap(d.hBmpProto, d.image_file_name, JPEG_QUALITYGOOD)) { if (GetFileSize(d.image_file_name) > d.max_size) { DeleteFile(d.image_file_name); d.need_smaller_size = TRUE; } else d.saved = TRUE; } } else d.need_smaller_size = TRUE; } else d.saved = TRUE; }
void TlenGetAvatarFileName(TlenProtocol *proto, TLEN_LIST_ITEM *item, TCHAR* ptszDest, int cbLen) { int tPathLen = mir_sntprintf(ptszDest, cbLen, TEXT("%s\\%S"), VARST( TEXT("%miranda_avatarcache%")), proto->m_szModuleName); if (_taccess(ptszDest, 0)) { int ret = CreateDirectoryTreeT(ptszDest); if (ret == 0) proto->debugLog(_T("getAvatarFilename(): Created new directory for avatar cache: %s."), ptszDest); else { proto->debugLog(_T("getAvatarFilename(): Can not create directory for avatar cache: %s. errno=%d: %s"), ptszDest, errno, strerror(errno)); TCHAR buffer[512]; mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("Cannot create avatars cache directory. ERROR: %d: %s\n%s"), errno, _tcserror(errno), ptszDest); PUShowMessageT(buffer, SM_WARNING); } } int format = PA_FORMAT_PNG; ptszDest[ tPathLen++ ] = '\\'; if (item != NULL) format = item->avatarFormat; else if (proto->threadData != NULL) format = proto->threadData->avatarFormat; else format = db_get_dw(NULL, proto->m_szModuleName, "AvatarFormat", PA_FORMAT_UNKNOWN); const TCHAR *tszFileType = ProtoGetAvatarExtension(format); if ( item != NULL ) mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S%s"), ptrA( TlenSha1(item->jid)), tszFileType); else mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S_avatar%s"), proto->m_szModuleName, tszFileType); }
DWORD CMraProto::MraAvatarsGetFileName(HANDLE hAvatarsQueueHandle, MCONTACT hContact, DWORD dwFormat, CMStringW &res) { res.Empty(); if (hAvatarsQueueHandle == NULL) return ERROR_INVALID_HANDLE; if (IsContactChatAgent(hContact)) return ERROR_NOT_SUPPORTED; TCHAR tszBase[MAX_PATH]; mir_sntprintf(tszBase, SIZEOF(tszBase), _T("%s\\%s\\"), VARST(_T("%miranda_avatarcache%")), m_tszUserName); res = tszBase; // some path in buff and free space for file name is avaible CreateDirectoryTreeT(res); if (dwFormat != PA_FORMAT_DEFAULT) { CMStringW szEmail; if (mraGetStringW(hContact, "e-mail", szEmail)) { szEmail.MakeLower(); res += szEmail + ProtoGetAvatarExtension(dwFormat); return NO_ERROR; } } else { CMStringW szDefName; if (!DB_GetStringW(NULL, MRA_AVT_SECT_NAME, "DefaultAvatarFileName", szDefName)) { res += MRA_AVT_DEFAULT_AVT_FILENAME; return NO_ERROR; } } return ERROR_INSUFFICIENT_BUFFER; }
void AddAvatarExt(int dwFormat, TCHAR *pszDest) { const TCHAR *ext = ProtoGetAvatarExtension(dwFormat); mir_tstrcat(pszDest, (*ext == 0) ? _T(".dat") : ext); }