From ad7c1f95b18a323357ad02cff8609ba55a72d3e3 Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 17 Oct 2007 01:13:11 +0000 Subject: fix get avatar logic git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@368 4f64403b-2f21-0410-a795-97e2b3489a10 --- MySpace/common.h | 1 + MySpace/proto.cpp | 26 ++++++++++++++++---------- MySpace/server_con.cpp | 20 +++++++++++++------- MySpace/version.h | 4 ++-- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/MySpace/common.h b/MySpace/common.h index aaed8b4..f9bff89 100644 --- a/MySpace/common.h +++ b/MySpace/common.h @@ -55,6 +55,7 @@ #include #include #include +#include extern MM_INTERFACE mmi; diff --git a/MySpace/proto.cpp b/MySpace/proto.cpp index fbd9e69..e505d9e 100644 --- a/MySpace/proto.cpp +++ b/MySpace/proto.cpp @@ -365,17 +365,23 @@ int GetAvatarInfo(WPARAM wParam,LPARAM lParam) { bool online = (status > ID_STATUS_OFFLINE); bool force = ((wParam & GAIF_FORCE) != 0); - bool file_exists = (DBGetContactSettingString(AI->hContact, MODULE, "AvatarFilename", &dbv2) == 0) && FileExists(dbv2.pszVal); + bool free_dbv2 = (DBGetContactSettingString(AI->hContact, MODULE, "AvatarFilename", &dbv2) == 0); + bool file_exists = free_dbv2 && FileExists(dbv2.pszVal); - if(force && online) { - if(file_exists) { - DeleteFileA(dbv2.pszVal); - DBDeleteContactSetting(0, MODULE, "AvatarFilename"); - } - DownloadAvatar(AI->hContact, dbv.pszVal); - ret = GAIR_WAITFOR; - } else if(file_exists) { + if(file_exists) { strncpy(AI->filename, dbv2.pszVal, sizeof(AI->filename)); + char *ext = strrchr(AI->filename, '.'); + if(ext) ext++; + if(ext) { + AI->format = + (stricmp(ext, ".png") ? PA_FORMAT_PNG : + (stricmp(ext, ".jpg") ? PA_FORMAT_JPEG : + (stricmp(ext, ".jpeg") ? PA_FORMAT_JPEG : + (stricmp(ext, ".gif") ? PA_FORMAT_GIF : + (stricmp(ext, ".swf") ? PA_FORMAT_SWF : PA_FORMAT_UNKNOWN))))); + } else + AI->format = PA_FORMAT_UNKNOWN; + ret = GAIR_SUCCESS; } else if(online) { DownloadAvatar(AI->hContact, dbv.pszVal); @@ -385,7 +391,7 @@ int GetAvatarInfo(WPARAM wParam,LPARAM lParam) { } DBFreeVariant(&dbv); - if(file_exists) DBFreeVariant(&dbv2); + if(free_dbv2) DBFreeVariant(&dbv2); return ret; } diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp index 07d3684..d2c5916 100644 --- a/MySpace/server_con.cpp +++ b/MySpace/server_con.cpp @@ -1044,13 +1044,14 @@ void __cdecl sttDownloadAvatar(void *param) { ProtoBroadcastAck(MODULE,info->hContact,ACKTYPE_AVATAR,ACKRESULT_DATA, 0, 0); char *ext = strrchr(info->url, '.'); + if(ext) ext++; // write file int uid = DBGetContactSettingDword(info->hContact, MODULE, "UID", 0); char fn[MAX_PATH]; char buff[128], tbuff[128]; - mir_snprintf(fn, MAX_PATH, "%s_%s.%s", _itoa(uid, buff, 10), _itoa(GetTickCount(), tbuff, 10), ext); + mir_snprintf(fn, MAX_PATH, "%s_%s.%s", _itoa(uid, buff, 10), _itoa(GetTickCount(), tbuff, 10), ext ? ext : ""); if(WriteData(fn, MAX_PATH, nlhrReply->pData, nlhrReply->dataLength)) { CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply); @@ -1060,14 +1061,19 @@ void __cdecl sttDownloadAvatar(void *param) { AI.cbSize = sizeof(PROTO_AVATAR_INFORMATION); AI.hContact = info->hContact; strncpy(AI.filename, fn, MAX_PATH); - AI.format = - (stricmp(ext, ".png") ? PA_FORMAT_PNG : - (stricmp(ext, ".jpg") ? PA_FORMAT_JPEG : - (stricmp(ext, ".jpeg") ? PA_FORMAT_JPEG : - (stricmp(ext, ".gif") ? PA_FORMAT_GIF : - (stricmp(ext, ".swf") ? PA_FORMAT_SWF : PA_FORMAT_UNKNOWN))))); + if(ext) { + AI.format = + (stricmp(ext, ".png") ? PA_FORMAT_PNG : + (stricmp(ext, ".jpg") ? PA_FORMAT_JPEG : + (stricmp(ext, ".jpeg") ? PA_FORMAT_JPEG : + (stricmp(ext, ".gif") ? PA_FORMAT_GIF : + (stricmp(ext, ".swf") ? PA_FORMAT_SWF : PA_FORMAT_UNKNOWN))))); + } else + AI.format = PA_FORMAT_UNKNOWN; ProtoBroadcastAck(MODULE,info->hContact,ACKTYPE_AVATAR,ACKRESULT_SUCCESS,(HANDLE) &AI, 0); + if(!info->hContact) + CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)MODULE, 0); } else ProtoBroadcastAck(MODULE,info->hContact,ACKTYPE_AVATAR,ACKRESULT_FAILED, 0, 0); } else diff --git a/MySpace/version.h b/MySpace/version.h index ea0acc5..dc24093 100644 --- a/MySpace/version.h +++ b/MySpace/version.h @@ -4,8 +4,8 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 0 -#define __RELEASE_NUM 5 -#define __BUILD_NUM 18 +#define __RELEASE_NUM 6 +#define __BUILD_NUM 1 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM #define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM -- cgit v1.2.3