summaryrefslogtreecommitdiff
path: root/plugins/AVS/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-11 10:41:37 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-11 10:41:37 +0000
commit94dcc72f13094157f344f284aec4edf0c0f5faa1 (patch)
tree74c078daadd4abe5aea9e9e0a73b4dd7c4a7fde1 /plugins/AVS/src/utils.cpp
parent42ff2169dbddd25d06404623dba2fff222d17c73 (diff)
ProtoGetAvatarFormat, ProtoGetAvatarFileFormat, ProtoGetBufferFormat, ProtoGetAvatarExtension - standard helpers for protocol avatars' processing instead of the zoo that existed previously
git-svn-id: http://svn.miranda-ng.org/main/trunk@5645 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AVS/src/utils.cpp')
-rw-r--r--plugins/AVS/src/utils.cpp82
1 files changed, 8 insertions, 74 deletions
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp
index 1d0494e258..7aa9f205d3 100644
--- a/plugins/AVS/src/utils.cpp
+++ b/plugins/AVS/src/utils.cpp
@@ -398,6 +398,8 @@ void protoPicCacheEntry::clear()
memset(this, 0, sizeof(avatarCacheEntry));
}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
BOOL Proto_IsAvatarsEnabled(const char *proto)
{
if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
@@ -451,13 +453,8 @@ void Proto_GetAvatarMaxSize(const char *proto, int *width, int *height)
BOOL Proto_NeedDelaysForAvatars(const char *proto)
{
- if ( ProtoServiceExists(proto, PS_GETAVATARCAPS)) {
- int ret = CallProtoService(proto, PS_GETAVATARCAPS, AF_DONTNEEDDELAYS, 0);
- if (ret > 0)
- return FALSE;
- else
- return TRUE;
- }
+ if ( ProtoServiceExists(proto, PS_GETAVATARCAPS))
+ return CallProtoService(proto, PS_GETAVATARCAPS, AF_DONTNEEDDELAYS, 0) <= 0;
return TRUE;
}
@@ -492,7 +489,7 @@ protoPicCacheEntry *GetProtoDefaultAvatar(HANDLE hContact)
{
char *szProto = GetContactProto(hContact);
if (szProto) {
- for(int i = 0; i < g_ProtoPictures.getCount(); i++) {
+ for (int i = 0; i < g_ProtoPictures.getCount(); i++) {
protoPicCacheEntry& p = g_ProtoPictures[i];
if ( !lstrcmpA(p.szProtoname, szProto) && p.hbmPic != NULL)
return &g_ProtoPictures[i];
@@ -552,7 +549,7 @@ void DeleteGlobalUserAvatar()
void SetIgnoreNotify(char *protocol, BOOL ignore)
{
- for(int i = 0; i < g_MyAvatars.getCount(); i++) {
+ for (int i = 0; i < g_MyAvatars.getCount(); i++) {
if (protocol == NULL || !lstrcmpA(g_MyAvatars[i].szProtoname, protocol)) {
if (ignore)
g_MyAvatars[i].dwFlags |= AVS_IGNORENOTIFY;
@@ -562,73 +559,10 @@ void SetIgnoreNotify(char *protocol, BOOL ignore)
}
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-const TCHAR *GetFormatExtension(int format)
-{
- if (format == PA_FORMAT_PNG)
- return _T(".png");
- if (format == PA_FORMAT_JPEG)
- return _T(".jpg");
- if (format == PA_FORMAT_ICON)
- return _T(".ico");
- if (format == PA_FORMAT_BMP)
- return _T(".bmp");
- if (format == PA_FORMAT_GIF)
- return _T(".gif");
- if (format == PA_FORMAT_SWF)
- return _T(".swf");
- if (format == PA_FORMAT_XML)
- return _T(".xml");
-
- return NULL;
-}
-
-int GetImageFormat(TCHAR *filename)
-{
- size_t len = lstrlen(filename);
-
- if (len < 5)
- return PA_FORMAT_UNKNOWN;
-
- if (_tcsicmp(_T(".png"), &filename[len-4]) == 0)
- return PA_FORMAT_PNG;
-
- if (_tcsicmp(_T(".jpg"), &filename[len-4]) == 0 || _tcsicmp(_T(".jpeg"), &filename[len-4]) == 0)
- return PA_FORMAT_JPEG;
-
- if (_tcsicmp(_T(".ico"), &filename[len-4]) == 0)
- return PA_FORMAT_ICON;
-
- if (_tcsicmp(_T(".bmp"), &filename[len-4]) == 0 || _tcsicmp(_T(".rle"), &filename[len-4]) == 0)
- return PA_FORMAT_BMP;
-
- if (_tcsicmp(_T(".gif"), &filename[len-4]) == 0)
- return PA_FORMAT_GIF;
-
- if (_tcsicmp(_T(".swf"), &filename[len-4]) == 0)
- return PA_FORMAT_SWF;
-
- if (_tcsicmp(_T(".xml"), &filename[len-4]) == 0)
- return PA_FORMAT_XML;
-
- return PA_FORMAT_UNKNOWN;
-}
-
///////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD GetFileSize(TCHAR *szFilename)
{
- HANDLE hFile = CreateFile(szFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- return 0;
-
- DWORD low = GetFileSize(hFile, NULL);
-
- CloseHandle(hFile);
-
- if (low == INVALID_FILE_SIZE)
- return 0;
-
- return low;
+ struct _stat info;
+ return ( _tstat(szFilename, &info) == -1) ? 0 : info.st_size;
}