From 18540e71624543fd0181b764a6913aa6bf8eb75d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 20 Jun 2012 08:05:51 +0000 Subject: more avatar fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@498 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/avatars.cpp | 29 +++++++++++++---------------- protocols/FacebookRM/client.h | 2 +- protocols/FacebookRM/communication.cpp | 10 +++++----- protocols/FacebookRM/proto.cpp | 6 +++--- protocols/FacebookRM/proto.h | 4 ++-- protocols/FacebookRM/utils.cpp | 14 ++++++++++++++ protocols/FacebookRM/utils.h | 13 ------------- protocols/MRA/MraAvatars.cpp | 2 +- protocols/Twitter/connection.cpp | 2 +- protocols/Twitter/proto.cpp | 17 ++++++++--------- protocols/Twitter/proto.h | 5 ++--- protocols/Twitter/utility.cpp | 10 +++++----- protocols/Twitter/utility.h | 2 +- protocols/Weather/weather_svcs.cpp | 3 +-- protocols/Yahoo/avatar.cpp | 2 +- 15 files changed, 58 insertions(+), 63 deletions(-) (limited to 'protocols') diff --git a/protocols/FacebookRM/avatars.cpp b/protocols/FacebookRM/avatars.cpp index 0b3bef5635..0ebfa7a558 100644 --- a/protocols/FacebookRM/avatars.cpp +++ b/protocols/FacebookRM/avatars.cpp @@ -27,12 +27,11 @@ Last change on : $Date: 2011-01-08 11:10:34 +0100 (so, 08 1 2011) $ #include "common.h" -bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::tstring *url) +bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url) { DBVARIANT dbv; - if (!DBGetContactSettingTString(ai.hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, &dbv)) - { - std::tstring new_url = dbv.ptszVal; + if (!DBGetContactSettingString(ai.hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, &dbv)) { + std::string new_url = dbv.pszVal; DBFreeVariant(&dbv); if (new_url.empty()) @@ -41,10 +40,9 @@ bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::tstring if (url) *url = new_url; - if (!DBGetContactSettingTString(ai.hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv)) - { - std::tstring ext = new_url.substr(new_url.rfind('.')); - std::tstring filename = GetAvatarFolder() + '\\' + dbv.ptszVal + ext; + if (!DBGetContactSettingTString(ai.hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv)) { + std::string ext = new_url.substr(new_url.rfind('.')); + std::tstring filename = GetAvatarFolder() + L'\\' + dbv.ptszVal + (TCHAR*)_A2T(ext.c_str()); DBFreeVariant(&dbv); ai.hContact = ai.hContact; @@ -58,7 +56,7 @@ bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::tstring return false; } -void FacebookProto::CheckAvatarChange(HANDLE hContact, std::tstring image_url) +void FacebookProto::CheckAvatarChange(HANDLE hContact, std::string image_url) { // Facebook contacts always have some avatar - keep avatar in database even if we have loaded empty one (e.g. for 'On Mobile' contacts) if (image_url.empty()) @@ -80,7 +78,7 @@ void FacebookProto::CheckAvatarChange(HANDLE hContact, std::tstring image_url) } if (update_required || !hContact) { - DBWriteContactSettingTString(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, image_url.c_str()); + DBWriteContactSettingString(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, image_url.c_str()); if (hContact) ProtoBroadcastAck(m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); else @@ -100,7 +98,7 @@ void FacebookProto::UpdateAvatarWorker(void *) for (;;) { - std::tstring url; + std::string url; PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai)}; ai.hContact = avatar_queue[0]; @@ -113,7 +111,7 @@ void FacebookProto::UpdateAvatarWorker(void *) if (GetDbAvatarInfo(ai, &url)) { LOG("***** Updating avatar: %s", url.c_str()); - bool success = facy.save_url(url, std::string(ai.filename), nlc); + bool success = facy.save_url(url, ai.filename, nlc); if (ai.hContact) ProtoBroadcastAck(m_szModuleName, ai.hContact, ACKTYPE_AVATAR, success ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)&ai, 0); @@ -129,10 +127,10 @@ void FacebookProto::UpdateAvatarWorker(void *) Netlib_CloseHandle(nlc); } -std::string FacebookProto::GetAvatarFolder() +std::tstring FacebookProto::GetAvatarFolder() { TCHAR path[MAX_PATH]; - if ( hAvatarFolder_ && FoldersGetCustomPathT(hAvatarFolder_, path, SIZEOF(path), "") == 0 ) + if ( hAvatarFolder_ && FoldersGetCustomPathT(hAvatarFolder_, path, SIZEOF(path), _T("")) == 0 ) return path; else return def_avatar_folder_; @@ -181,10 +179,9 @@ int FacebookProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) return GAIR_NOAVATAR; PROTO_AVATAR_INFORMATIONT* AI = (PROTO_AVATAR_INFORMATIONT*)lParam; - if (GetDbAvatarInfo(*AI, NULL)) { - bool fileExist = _access(AI->filename, 0) == 0; + bool fileExist = _taccess(AI->filename, 0) == 0; bool needLoad; if (AI->hContact) diff --git a/protocols/FacebookRM/client.h b/protocols/FacebookRM/client.h index b4874de23b..2e854c2c98 100644 --- a/protocols/FacebookRM/client.h +++ b/protocols/FacebookRM/client.h @@ -165,7 +165,7 @@ public: // HTTP communication http::response flap( const int request_type, std::string* request_data = NULL, std::string* request_get_data = NULL ); - bool save_url(const std::string &url,const std::string &filename, HANDLE &nlc); + bool save_url(const std::string &url,const std::tstring &filename, HANDLE &nlc); DWORD choose_security_level( int ); int choose_method( int ); diff --git a/protocols/FacebookRM/communication.cpp b/protocols/FacebookRM/communication.cpp index 4afb031cac..90296b18e0 100644 --- a/protocols/FacebookRM/communication.cpp +++ b/protocols/FacebookRM/communication.cpp @@ -1240,7 +1240,7 @@ bool facebook_client::set_status(const std::string &status_text) ////////////////////////////////////////////////////////////////////////////// -bool facebook_client::save_url(const std::string &url,const std::string &filename, HANDLE &nlc) +bool facebook_client::save_url(const std::string &url,const std::tstring &filename, HANDLE &nlc) { NETLIBHTTPREQUEST req = {sizeof(req)}; NETLIBHTTPREQUEST *resp; @@ -1258,12 +1258,12 @@ bool facebook_client::save_url(const std::string &url,const std::string &filenam parent->Log( "@@@@@ Saving avatar URL %s to path %s", url.c_str(), filename.c_str() ); // Create folder if necessary - std::string dir = filename.substr(0,filename.rfind('\\')); - if(_access(dir.c_str(),0)) - CallService(MS_UTILS_CREATEDIRTREE, 0, (LPARAM)dir.c_str()); + std::tstring dir = filename.substr(0,filename.rfind('\\')); + if( _taccess(dir.c_str(),0)) + CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)dir.c_str()); // Write to file - FILE *f = fopen(filename.c_str(),"wb"); + FILE *f = _tfopen(filename.c_str(), _T("wb")); fwrite(resp->pData,1,resp->dataLength,f); fclose(f); diff --git a/protocols/FacebookRM/proto.cpp b/protocols/FacebookRM/proto.cpp index f53dce96db..e51a39f1dd 100644 --- a/protocols/FacebookRM/proto.cpp +++ b/protocols/FacebookRM/proto.cpp @@ -73,10 +73,10 @@ FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) SkinAddNewSoundExT( "NewsFeed", m_tszUserName, LPGENT( "News Feed" ) ); SkinAddNewSoundExT( "OtherEvent", m_tszUserName, LPGENT( "Other Event" ) ); - char *profile = Utils_ReplaceVars("%miranda_avatarcache%"); - def_avatar_folder_ = std::string(profile)+"\\"+m_szModuleName; + TCHAR *profile = Utils_ReplaceVarsT( _T("%miranda_avatarcache%")); + def_avatar_folder_ = std::tstring(profile) + _T("\\") + m_tszUserName; mir_free(profile); - hAvatarFolder_ = FoldersRegisterCustomPath(m_szModuleName, "Avatars", def_avatar_folder_.c_str()); + hAvatarFolder_ = FoldersRegisterCustomPathT(m_szModuleName, "Avatars", def_avatar_folder_.c_str()); // Set all contacts offline -- in case we crashed SetAllContactStatuses( ID_STATUS_OFFLINE ); diff --git a/protocols/FacebookRM/proto.h b/protocols/FacebookRM/proto.h index 3ce4af74a9..c08e3aaef2 100644 --- a/protocols/FacebookRM/proto.h +++ b/protocols/FacebookRM/proto.h @@ -186,7 +186,7 @@ public: facebook_client facy; // TODO: Refactor to "client" and make dynamic // Helpers - std::string GetAvatarFolder(); + std::tstring GetAvatarFolder(); bool GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url); void CheckAvatarChange(HANDLE hContact, std::string image_url); void ToggleStatusMenuItems( BOOL bEnable ); @@ -203,7 +203,7 @@ public: HANDLE m_hNetlibUser; std::string last_status_msg_; - std::string def_avatar_folder_; + std::tstring def_avatar_folder_; HANDLE hAvatarFolder_; std::vector avatar_queue; diff --git a/protocols/FacebookRM/utils.cpp b/protocols/FacebookRM/utils.cpp index 248bb432bd..e34238a372 100644 --- a/protocols/FacebookRM/utils.cpp +++ b/protocols/FacebookRM/utils.cpp @@ -423,6 +423,20 @@ void* __fastcall utils::mem::allocate(size_t size) return mir_calloc(size); } +struct +{ + char *ext; + int fmt; +} +static formats[] = { + { ".png", PA_FORMAT_PNG }, + { ".jpg", PA_FORMAT_JPEG }, + { ".jpeg", PA_FORMAT_JPEG }, + { ".ico", PA_FORMAT_ICON }, + { ".bmp", PA_FORMAT_BMP }, + { ".gif", PA_FORMAT_GIF }, +}; + int ext_to_format(const std::string &ext) { for(size_t i=0; iurl.substr(data->url.rfind('.')); - std::tstring filename = GetAvatarFolder() + '\\' + dbv.ptszVal + ext; + std::tstring filename = GetAvatarFolder() + _T('\\') + dbv.ptszVal + (TCHAR*)_A2T(ext.c_str()); DBFreeVariant(&dbv); PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai)}; diff --git a/protocols/Twitter/proto.cpp b/protocols/Twitter/proto.cpp index ae1567e986..60f802d77c 100644 --- a/protocols/Twitter/proto.cpp +++ b/protocols/Twitter/proto.cpp @@ -50,11 +50,10 @@ TwitterProto::TwitterProto(const char *proto_name,const TCHAR *username) HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &TwitterProto::OnBuildStatusMenu, this); HookProtoEvent(ME_OPT_INITIALISE, &TwitterProto::OnOptionsInit, this); - char *profile = Utils_ReplaceVars("%miranda_avatarcache%"); - def_avatar_folder_ = std::string(profile)+"\\"+m_szModuleName; + TCHAR *profile = Utils_ReplaceVarsT( _T("%miranda_avatarcache%")); + def_avatar_folder_ = std::tstring(profile) + _T("\\") + m_tszUserName; mir_free(profile); - hAvatarFolder_ = FoldersRegisterCustomPath(m_szModuleName,"Avatars", - def_avatar_folder_.c_str()); + hAvatarFolder_ = FoldersRegisterCustomPathT(m_szModuleName, "Avatars", def_avatar_folder_.c_str()); // Initialize hotkeys char text[512]; @@ -572,13 +571,13 @@ void TwitterProto::UpdateSettings() } } -std::string TwitterProto::GetAvatarFolder() +std::tstring TwitterProto::GetAvatarFolder() { - char path[MAX_PATH]; - if(hAvatarFolder_ && FoldersGetCustomPath(hAvatarFolder_,path,sizeof(path), "") == 0) + TCHAR path[MAX_PATH]; + if(hAvatarFolder_ && FoldersGetCustomPathT(hAvatarFolder_,path,SIZEOF(path), _T("")) == 0) return path; - else - return def_avatar_folder_; + + return def_avatar_folder_; } int TwitterProto::GetAvatar(WPARAM,LPARAM) diff --git a/protocols/Twitter/proto.h b/protocols/Twitter/proto.h index 6cea35b33d..eb5b9a2198 100644 --- a/protocols/Twitter/proto.h +++ b/protocols/Twitter/proto.h @@ -157,8 +157,7 @@ private: void TwitterProto::resetOAuthKeys(); - - std::string GetAvatarFolder(); + std::tstring GetAvatarFolder(); HANDLE signon_lock_; HANDLE avatar_lock_; @@ -172,7 +171,7 @@ private: twitter_id since_id_; twitter_id dm_since_id_; - std::string def_avatar_folder_; + std::tstring def_avatar_folder_; HANDLE hAvatarFolder_; bool in_chat_; diff --git a/protocols/Twitter/utility.cpp b/protocols/Twitter/utility.cpp index 2f79a40e99..3b98944bba 100644 --- a/protocols/Twitter/utility.cpp +++ b/protocols/Twitter/utility.cpp @@ -173,7 +173,7 @@ int mir_twitter::WLOG(const char* first, const std::wstring last) return LOG(first, str1); } -bool save_url(HANDLE hNetlib,const std::string &url,const std::string &filename) +bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename) { NETLIBHTTPREQUEST req = {sizeof(req)}; NETLIBHTTPREQUEST *resp; @@ -189,12 +189,12 @@ bool save_url(HANDLE hNetlib,const std::string &url,const std::string &filename) if (resp->resultCode == 200) { // Create folder if necessary - std::string dir = filename.substr(0,filename.rfind('\\')); - if(_access(dir.c_str(),0)) - CallService(MS_UTILS_CREATEDIRTREE, 0, (LPARAM)dir.c_str()); + std::tstring dir = filename.substr(0,filename.rfind('\\')); + if( _taccess(dir.c_str(),0)) + CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)dir.c_str()); // Write to file - FILE *f = fopen(filename.c_str(),"wb"); + FILE *f = _tfopen(filename.c_str(), _T("wb")); fwrite(resp->pData,1,resp->dataLength,f); fclose(f); } diff --git a/protocols/Twitter/utility.h b/protocols/Twitter/utility.h index cc60ee15c4..a8823291d1 100644 --- a/protocols/Twitter/utility.h +++ b/protocols/Twitter/utility.h @@ -155,4 +155,4 @@ private: }; int ext_to_format(const std::string &ext); -bool save_url(HANDLE hNetlib,const std::string &url,const std::string &filename); \ No newline at end of file +bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename); \ No newline at end of file diff --git a/protocols/Weather/weather_svcs.cpp b/protocols/Weather/weather_svcs.cpp index 17d4bb7f87..0ded709fcc 100644 --- a/protocols/Weather/weather_svcs.cpp +++ b/protocols/Weather/weather_svcs.cpp @@ -144,10 +144,9 @@ INT_PTR WeatherGetAvatarInfo(WPARAM wParam, LPARAM lParam) status = (WORD)DBGetContactSettingWord(ai->hContact, WEATHERPROTONAME, "StatusIcon",0); for (i=0; i<10; i++) - { if (statusValue[i] == status) break; - } + if (i >= 10) return GAIR_NOAVATAR; diff --git a/protocols/Yahoo/avatar.cpp b/protocols/Yahoo/avatar.cpp index ad798ed687..254acfd07f 100644 --- a/protocols/Yahoo/avatar.cpp +++ b/protocols/Yahoo/avatar.cpp @@ -249,7 +249,7 @@ void __cdecl CYahooProto::recv_avatarthread(void *pavt) AI.cbSize = sizeof AI; AI.format = PA_FORMAT_PNG; AI.hContact = hContact; - WideCharToMultiByte( CP_ACP, 0, buf, -1, AI.filename, sizeof AI.filename, 0, 0 ); + _tcsncpy(AI.filename, buf, SIZEOF(AI.filename)); if (error) SetDword(hContact, "PictCK", 0); -- cgit v1.2.3