From ae470b566ef8e3e6222a717c53a45a38c8c43bbd Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 24 Jul 2014 17:15:23 +0000 Subject: - AVS_path* functions replaced with the core analogs; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@9934 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AVS/src/services.cpp | 369 +++++++++++++++++++------------------------ 1 file changed, 164 insertions(+), 205 deletions(-) (limited to 'plugins/AVS/src/services.cpp') diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp index 7c9354ea06..24d4579e6b 100644 --- a/plugins/AVS/src/services.cpp +++ b/plugins/AVS/src/services.cpp @@ -67,28 +67,29 @@ INT_PTR ProtectAvatar(WPARAM hContact, LPARAM lParam) * image filename (will be checked for existance, though) */ -struct OpenFileSubclassData { +struct OpenFileSubclassData +{ BYTE *locking_request; BYTE setView; }; UINT_PTR CALLBACK OpenFileSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - OpenFileSubclassData *data= (OpenFileSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + OpenFileSubclassData *data = (OpenFileSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - switch(msg) { + switch (msg) { case WM_INITDIALOG: - { - OPENFILENAME *ofn = (OPENFILENAME *)lParam; + { + OPENFILENAME *ofn = (OPENFILENAME *)lParam; - data = (OpenFileSubclassData *) malloc(sizeof(OpenFileSubclassData)); - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data); - data->locking_request = (BYTE *)ofn->lCustData; - data->setView = TRUE; + data = (OpenFileSubclassData *)malloc(sizeof(OpenFileSubclassData)); + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data); + data->locking_request = (BYTE *)ofn->lCustData; + data->setView = TRUE; - TranslateDialogDefault(hwnd); - CheckDlgButton(hwnd, IDC_PROTECTAVATAR, *(data->locking_request)); - } + TranslateDialogDefault(hwnd); + CheckDlgButton(hwnd, IDC_PROTECTAVATAR, *(data->locking_request)); + } break; case WM_COMMAND: @@ -99,7 +100,7 @@ UINT_PTR CALLBACK OpenFileSubclass(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP case WM_NOTIFY: if (data->setView) { HWND hwndParent = GetParent(hwnd); - HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL) ; + HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL); if (hwndLv != NULL) { SendMessage(hwndLv, WM_COMMAND, SHVIEW_THUMBNAIL, 0); data->setView = FALSE; @@ -129,12 +130,12 @@ static INT_PTR avSetAvatar(MCONTACT hContact, TCHAR *tszPath) is_locked = db_get_b(hContact, "ContactPhoto", "Locked", 0); - if ( tszPath == NULL ) { - OPENFILENAME ofn = {0}; + if (tszPath == NULL) { + OPENFILENAME ofn = { 0 }; TCHAR filter[256]; filter[0] = '\0'; - CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), ( LPARAM )filter); + CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), (LPARAM)filter); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = 0; @@ -172,7 +173,7 @@ static INT_PTR avSetAvatar(MCONTACT hContact, TCHAR *tszPath) CloseHandle(hFile); - AVS_pathToRelative(szFinalName, szBackupName); + PathToRelativeT(szFinalName, szBackupName, g_szDataPath); db_set_ts(hContact, "ContactPhoto", "Backup", szBackupName); db_set_b(hContact, "ContactPhoto", "Locked", is_locked); @@ -200,7 +201,7 @@ INT_PTR SetAvatarW(WPARAM wParam, LPARAM lParam) static INT_PTR CanSetMyAvatar(WPARAM wParam, LPARAM lParam) { - char *protocol = (char *) wParam; + char *protocol = (char *)wParam; if (protocol == NULL || fei == NULL) return 0; @@ -219,40 +220,36 @@ static int InternalRemoveMyAvatar(char *protocol) // Remove avatar int ret = 0; - if (protocol != NULL) - { - if ( ProtoServiceExists(protocol, PS_SETMYAVATAR)) + if (protocol != NULL) { + if (ProtoServiceExists(protocol, PS_SETMYAVATAR)) ret = SaveAvatar(protocol, NULL); else ret = -3; - if (ret == 0) - { + if (ret == 0) { // Has global avatar? - DBVARIANT dbv = {0}; - if ( !db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv)) { + DBVARIANT dbv = { 0 }; + if (!db_get_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", &dbv)) { db_free(&dbv); db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); DeleteGlobalUserAvatar(); } } } - else - { + else { PROTOACCOUNT **accs; - int i,count; + int i, count; - ProtoEnumAccounts( &count, &accs ); - for (i = 0; i < count; i++) - { - if ( !ProtoServiceExists( accs[i]->szModuleName, PS_SETMYAVATAR)) + ProtoEnumAccounts(&count, &accs); + for (i = 0; i < count; i++) { + if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR)) continue; - if (!Proto_IsAvatarsEnabled( accs[i]->szModuleName )) + if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName)) continue; // Found a protocol - int retTmp = SaveAvatar( accs[i]->szModuleName, NULL); + int retTmp = SaveAvatar(accs[i]->szModuleName, NULL); if (retTmp != 0) ret = retTmp; } @@ -267,7 +264,7 @@ static int InternalRemoveMyAvatar(char *protocol) SetIgnoreNotify(protocol, FALSE); - ReportMyAvatarChanged(WPARAM((protocol == NULL ) ? "" : protocol), 0); + ReportMyAvatarChanged(WPARAM((protocol == NULL) ? "" : protocol), 0); return ret; } @@ -276,60 +273,58 @@ static void FilterGetStrings(TCHAR *filter, int bytesLeft, BOOL xml, BOOL swf) TCHAR *pfilter; int wParam = bytesLeft; - lstrcpyn(filter, TranslateT("All Files"), bytesLeft); bytesLeft-=lstrlen(filter); + lstrcpyn(filter, TranslateT("All Files"), bytesLeft); bytesLeft -= lstrlen(filter); _tcsncat(filter, _T(" (*.bmp;*.jpg;*.gif;*.png"), bytesLeft); if (swf) _tcscat(filter, _T(";*.swf")); if (xml) _tcscat(filter, _T(";*.xml")); _tcscat(filter, _T(")")); - pfilter=filter+lstrlen(filter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter = filter + lstrlen(filter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.BMP;*.RLE;*.JPG;*.JPEG;*.GIF;*.PNG"), bytesLeft); if (swf) _tcscat(pfilter, _T(";*.SWF")); if (xml) _tcscat(pfilter, _T(";*.XML")); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); - lstrcpyn(pfilter, TranslateT("Windows Bitmaps"), bytesLeft); bytesLeft-=lstrlen(pfilter); + lstrcpyn(pfilter, TranslateT("Windows Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter); _tcsncat(pfilter, _T(" (*.bmp;*.rle)"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.BMP;*.RLE"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); - lstrcpyn(pfilter,TranslateT("JPEG Bitmaps"),bytesLeft); bytesLeft-=lstrlen(pfilter); + lstrcpyn(pfilter, TranslateT("JPEG Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter); _tcsncat(pfilter, _T(" (*.jpg;*.jpeg)"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.JPG;*.JPEG"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); - lstrcpyn(pfilter,TranslateT("GIF Bitmaps"),bytesLeft); bytesLeft-=lstrlen(pfilter); + lstrcpyn(pfilter, TranslateT("GIF Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter); _tcsncat(pfilter, _T(" (*.gif)"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.GIF"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); - lstrcpyn(pfilter,TranslateT("PNG Bitmaps"), bytesLeft); bytesLeft-=lstrlen(pfilter); + lstrcpyn(pfilter, TranslateT("PNG Bitmaps"), bytesLeft); bytesLeft -= lstrlen(pfilter); _tcsncat(pfilter, _T(" (*.png)"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.PNG"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); - if (swf) - { - lstrcpyn(pfilter,TranslateT("Flash Animations"), bytesLeft); bytesLeft-=lstrlen(pfilter); + if (swf) { + lstrcpyn(pfilter, TranslateT("Flash Animations"), bytesLeft); bytesLeft -= lstrlen(pfilter); _tcsncat(pfilter, _T(" (*.swf)"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.SWF"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); } - if (xml) - { - lstrcpyn(pfilter, TranslateT("XML Files"), bytesLeft); bytesLeft-=lstrlen(pfilter); + if (xml) { + lstrcpyn(pfilter, TranslateT("XML Files"), bytesLeft); bytesLeft -= lstrlen(pfilter); _tcsncat(pfilter, _T(" (*.xml)"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); lstrcpyn(pfilter, _T("*.XML"), bytesLeft); - pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter); + pfilter += lstrlen(pfilter) + 1; bytesLeft = wParam - (pfilter - filter); } - if (bytesLeft) *pfilter='\0'; + if (bytesLeft) *pfilter = '\0'; } /* @@ -337,59 +332,58 @@ static void FilterGetStrings(TCHAR *filter, int bytesLeft, BOOL xml, BOOL swf) */ static UINT_PTR CALLBACK SetMyAvatarHookProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: - { - hwndSetMyAvatar = hwnd; + { + hwndSetMyAvatar = hwnd; - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam); - OPENFILENAME *ofn = (OPENFILENAME *)lParam; - SetMyAvatarHookData *data = (SetMyAvatarHookData *) ofn->lCustData; - data->thumbnail = TRUE; + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam); + OPENFILENAME *ofn = (OPENFILENAME *)lParam; + SetMyAvatarHookData *data = (SetMyAvatarHookData *)ofn->lCustData; + data->thumbnail = TRUE; - SetWindowText(GetDlgItem(hwnd, IDC_MAKE_SQUARE), TranslateT("Make the avatar square")); - SetWindowText(GetDlgItem(hwnd, IDC_GROW), TranslateT("Grow avatar to fit max allowed protocol size")); + SetWindowText(GetDlgItem(hwnd, IDC_MAKE_SQUARE), TranslateT("Make the avatar square")); + SetWindowText(GetDlgItem(hwnd, IDC_GROW), TranslateT("Grow avatar to fit max allowed protocol size")); - CheckDlgButton(hwnd, IDC_MAKE_SQUARE, data->square ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwnd, IDC_GROW, data->grow ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, IDC_MAKE_SQUARE, data->square ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwnd, IDC_GROW, data->grow ? BST_CHECKED : BST_UNCHECKED); - if (data->protocol != NULL && (Proto_AvatarImageProportion(data->protocol) & PIP_SQUARE)) - EnableWindow(GetDlgItem(hwnd, IDC_MAKE_SQUARE), FALSE); - } + if (data->protocol != NULL && (Proto_AvatarImageProportion(data->protocol) & PIP_SQUARE)) + EnableWindow(GetDlgItem(hwnd, IDC_MAKE_SQUARE), FALSE); + } break; case WM_NOTIFY: - { - OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - SetMyAvatarHookData *data = (SetMyAvatarHookData *) ofn->lCustData; - if (data->thumbnail) - { - HWND hwndParent = GetParent(hwnd); - HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL) ; - if (hwndLv != NULL) - { - SendMessage(hwndLv, WM_COMMAND, SHVIEW_THUMBNAIL, 0); - data->thumbnail = FALSE; - } + { + OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + SetMyAvatarHookData *data = (SetMyAvatarHookData *)ofn->lCustData; + if (data->thumbnail) { + HWND hwndParent = GetParent(hwnd); + HWND hwndLv = FindWindowEx(hwndParent, NULL, _T("SHELLDLL_DefView"), NULL); + if (hwndLv != NULL) { + SendMessage(hwndLv, WM_COMMAND, SHVIEW_THUMBNAIL, 0); + data->thumbnail = FALSE; } - break; } + break; + } case WM_DESTROY: - { - OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - SetMyAvatarHookData *data = (SetMyAvatarHookData *) ofn->lCustData; - data->square = IsDlgButtonChecked(hwnd, IDC_MAKE_SQUARE); - data->grow = IsDlgButtonChecked(hwnd, IDC_GROW); - - hwndSetMyAvatar = NULL; - break; - } + { + OPENFILENAME *ofn = (OPENFILENAME *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + SetMyAvatarHookData *data = (SetMyAvatarHookData *)ofn->lCustData; + data->square = IsDlgButtonChecked(hwnd, IDC_MAKE_SQUARE); + data->grow = IsDlgButtonChecked(hwnd, IDC_GROW); + + hwndSetMyAvatar = NULL; + break; + } } return 0; } -struct SaveProtocolData { +struct SaveProtocolData +{ DWORD max_size; TCHAR image_file_name[MAX_PATH]; BOOL saved; @@ -402,11 +396,11 @@ struct SaveProtocolData { void SaveImage(SaveProtocolData &d, char *protocol, int format) { - if ( !Proto_IsAvatarFormatSupported(protocol, format)) + if (!Proto_IsAvatarFormatSupported(protocol, format)) return; mir_sntprintf(d.image_file_name, SIZEOF(d.image_file_name), _T("%s%s"), d.temp_file, ProtoGetAvatarExtension(format)); - if ( BmpFilterSaveBitmapT(d.hBmpProto, d.image_file_name, format == PA_FORMAT_JPEG ? JPEG_QUALITYSUPERB : 0)) + if (BmpFilterSaveBitmapT(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) { @@ -434,16 +428,14 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam // If is swf or xml, just set it - if (originalFormat == PA_FORMAT_SWF) - { + if (originalFormat == PA_FORMAT_SWF) { if (!Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_SWF)) return -1; return SaveAvatar(protocol, originalFilename); } - if (originalFormat == PA_FORMAT_XML) - { + if (originalFormat == PA_FORMAT_XML) { if (!Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_XML)) return -1; @@ -451,9 +443,9 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam } // Get protocol info - SaveProtocolData d = {0}; + SaveProtocolData d = { 0 }; - d.max_size = (DWORD) Proto_GetAvatarMaxFileSize(protocol); + d.max_size = (DWORD)Proto_GetAvatarMaxFileSize(protocol); Proto_GetAvatarMaxSize(protocol, &d.width, &d.height); int orig_width = d.width; @@ -472,12 +464,11 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam rb.max_height = d.height; rb.max_width = d.width; rb.fit = (grow ? 0 : RESIZEBITMAP_FLAG_DONT_GROW) - | (square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS); + | (square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS); - d.hBmpProto = (HBITMAP) BmpFilterResizeBitmap((WPARAM)&rb, 0); + d.hBmpProto = (HBITMAP)BmpFilterResizeBitmap((WPARAM)&rb, 0); - if (d.hBmpProto == NULL) - { + if (d.hBmpProto == NULL) { if (d.temp_file[0] != '\0') DeleteFile(d.temp_file); return -1; @@ -485,9 +476,8 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam // Check if can use original image if (d.hBmpProto == hBmp - && Proto_IsAvatarFormatSupported(protocol, originalFormat) - && (d.max_size == 0 || GetFileSize(originalFilename) < d.max_size)) - { + && Proto_IsAvatarFormatSupported(protocol, originalFormat) + && (d.max_size == 0 || GetFileSize(originalFilename) < d.max_size)) { if (d.temp_file[0] != '\0') DeleteFile(d.temp_file); @@ -496,12 +486,10 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam } // Create a temporary file (if was not created already) - if (d.temp_file[0] == '\0') - { + if (d.temp_file[0] == '\0') { d.temp_file[0] = '\0'; if (GetTempPath(MAX_PATH, d.temp_file) == 0 - || GetTempFileName(d.temp_file, _T("mir_av_"), 0, d.temp_file) == 0) - { + || GetTempFileName(d.temp_file, _T("mir_av_"), 0, d.temp_file) == 0) { DeleteObject(d.hBmpProto); return -1; } @@ -526,8 +514,7 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam SaveImage(d, protocol, PA_FORMAT_BMP); num_tries++; - if (!d.saved && d.need_smaller_size && num_tries < 4) - { + if (!d.saved && d.need_smaller_size && num_tries < 4) { // Cleanup if (d.hBmpProto != hBmp) DeleteObject(d.hBmpProto); @@ -537,18 +524,17 @@ static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilenam d.height = orig_height * (4 - num_tries) / 4; } - } while(!d.saved && d.need_smaller_size && num_tries < 4); + } + while (!d.saved && d.need_smaller_size && num_tries < 4); int ret; - if (d.saved) - { + if (d.saved) { // Call proto service ret = SaveAvatar(protocol, d.image_file_name); DeleteFile(d.image_file_name); } - else - { + else { ret = -1; } @@ -575,20 +561,17 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo HBITMAP hBmp = NULL; - if (format == PA_FORMAT_SWF) - { + if (format == PA_FORMAT_SWF) { if (!allAcceptSWF) return -4; } - else if (format == PA_FORMAT_XML) - { + else if (format == PA_FORMAT_XML) { if (!allAcceptXML) return -4; } - else - { + else { // Try to open if is not a flash or XML - hBmp = (HBITMAP) CallService(MS_IMG_LOAD, (WPARAM) szFinalName, IMGL_TCHAR); + hBmp = (HBITMAP)CallService(MS_IMG_LOAD, (WPARAM)szFinalName, IMGL_TCHAR); if (hBmp == NULL) return -4; } @@ -596,103 +579,88 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo SetIgnoreNotify(protocol, TRUE); int ret = 0; - if (protocol != NULL) - { + if (protocol != NULL) { ret = SetProtoMyAvatar(protocol, hBmp, szFinalName, format, data.square, data.grow); - if (ret == 0) - { + if (ret == 0) { DeleteGlobalUserAvatar(); db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); } } - else - { + else { PROTOACCOUNT **accs; - int i,count; + int i, count; - ProtoEnumAccounts( &count, &accs ); - for (i = 0; i < count; i++) - { - if ( !ProtoServiceExists( accs[i]->szModuleName, PS_SETMYAVATAR)) + ProtoEnumAccounts(&count, &accs); + for (i = 0; i < count; i++) { + if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR)) continue; - if ( !Proto_IsAvatarsEnabled( accs[i]->szModuleName )) + if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName)) continue; - int retTmp = SetProtoMyAvatar( accs[i]->szModuleName, hBmp, szFinalName, format, data.square, data.grow); + int retTmp = SetProtoMyAvatar(accs[i]->szModuleName, hBmp, szFinalName, format, data.square, data.grow); if (retTmp != 0) ret = retTmp; } DeleteGlobalUserAvatar(); - if (ret) - { + if (ret) { db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); } - else - { + else { // Copy avatar file to store as global one TCHAR globalFile[1024]; BOOL saved = TRUE; - if (FoldersGetCustomPathT(hGlobalAvatarFolder, globalFile, SIZEOF(globalFile), _T(""))) - { - mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\%s"), g_szDataPath, _T("GlobalAvatar")); + if (FoldersGetCustomPathT(hGlobalAvatarFolder, globalFile, SIZEOF(globalFile), _T(""))) { + mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s%s"), g_szDataPath, _T("GlobalAvatar")); CreateDirectory(globalFile, NULL); } TCHAR *ext = _tcsrchr(szFinalName, _T('.')); // Can't be NULL here - if (format == PA_FORMAT_XML || format == PA_FORMAT_SWF) - { + if (format == PA_FORMAT_XML || format == PA_FORMAT_SWF) { mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\my_global_avatar%s"), globalFile, ext); CopyFile(szFinalName, globalFile, FALSE); } - else - { + else { // Resize (to avoid too big avatars) - ResizeBitmap rb = {0}; + ResizeBitmap rb = { 0 }; rb.size = sizeof(ResizeBitmap); rb.hBmp = hBmp; rb.max_height = 300; rb.max_width = 300; rb.fit = (data.grow ? 0 : RESIZEBITMAP_FLAG_DONT_GROW) - | (data.square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS); + | (data.square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS); - HBITMAP hBmpTmp = (HBITMAP) BmpFilterResizeBitmap((WPARAM)&rb, 0); + HBITMAP hBmpTmp = (HBITMAP)BmpFilterResizeBitmap((WPARAM)&rb, 0); // Check if need to resize - if (hBmpTmp == hBmp || hBmpTmp == NULL) - { + if (hBmpTmp == hBmp || hBmpTmp == NULL) { // Use original image mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\my_global_avatar%s"), globalFile, ext); CopyFile(szFinalName, globalFile, FALSE); } - else - { + else { // Save as PNG mir_sntprintf(globalFile, SIZEOF(globalFile), _T("%s\\my_global_avatar.png"), globalFile); - if (BmpFilterSaveBitmap((WPARAM) hBmpTmp, (LPARAM) globalFile)) + if (BmpFilterSaveBitmap((WPARAM)hBmpTmp, (LPARAM)globalFile)) saved = FALSE; DeleteObject(hBmpTmp); } } - if (saved) - { + if (saved) { TCHAR relFile[1024]; - if (AVS_pathToRelative(globalFile, relFile)) + if (PathToRelativeT(globalFile, relFile, g_szDataPath)) db_set_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", relFile); else db_set_ts(NULL, AVS_MODULE, "GlobalUserAvatarFile", globalFile); db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 0); } - else - { - db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); - } + else db_set_b(NULL, AVS_MODULE, "GlobalUserAvatarNotConsistent", 1); } } @@ -704,7 +672,7 @@ static int InternalSetMyAvatar(char *protocol, TCHAR *szFinalName, SetMyAvatarHo return ret; } -INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) +INT_PTR avSetMyAvatar(char* protocol, TCHAR* tszPath) { TCHAR FileName[MAX_PATH]; TCHAR *szFinalName = NULL; @@ -725,41 +693,38 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) SetMyAvatarHookData data = { 0 }; // Check for XML and SWF - if (protocol == NULL) - { + if (protocol == NULL) { allAcceptXML = TRUE; allAcceptSWF = TRUE; PROTOACCOUNT **accs; - int i,count; + int i, count; - ProtoEnumAccounts( &count, &accs ); - for (i = 0; i < count; i++) - { - if ( !ProtoServiceExists( accs[i]->szModuleName, PS_SETMYAVATAR)) + ProtoEnumAccounts(&count, &accs); + for (i = 0; i < count; i++) { + if (!ProtoServiceExists(accs[i]->szModuleName, PS_SETMYAVATAR)) continue; - if ( !Proto_IsAvatarsEnabled( accs[i]->szModuleName )) + if (!Proto_IsAvatarsEnabled(accs[i]->szModuleName)) continue; - allAcceptXML = allAcceptXML && Proto_IsAvatarFormatSupported( accs[i]->szModuleName, PA_FORMAT_XML); - allAcceptSWF = allAcceptSWF && Proto_IsAvatarFormatSupported( accs[i]->szModuleName, PA_FORMAT_SWF); + allAcceptXML = allAcceptXML && Proto_IsAvatarFormatSupported(accs[i]->szModuleName, PA_FORMAT_XML); + allAcceptSWF = allAcceptSWF && Proto_IsAvatarFormatSupported(accs[i]->szModuleName, PA_FORMAT_SWF); } data.square = db_get_b(0, AVS_MODULE, "SetAllwaysMakeSquare", 0); } - else - { + else { allAcceptXML = Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_XML); allAcceptSWF = Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_SWF); data.protocol = protocol; data.square = (Proto_AvatarImageProportion(protocol) & PIP_SQUARE) - || db_get_b(0, AVS_MODULE, "SetAllwaysMakeSquare", 0); + || db_get_b(0, AVS_MODULE, "SetAllwaysMakeSquare", 0); } if (tszPath == NULL) { - OPENFILENAME ofn = {0}; + OPENFILENAME ofn = { 0 }; TCHAR filter[512]; TCHAR inipath[1024]; @@ -780,7 +745,7 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) ofn.lpstrInitialDir = inipath; ofn.lpTemplateName = MAKEINTRESOURCE(IDD_SET_OWN_SUBCLASS); ofn.lpfnHook = SetMyAvatarHookProc; - ofn.lCustData = (LPARAM) &data; + ofn.lCustData = (LPARAM)&data; *FileName = '\0'; ofn.lpstrDefExt = _T(""); @@ -789,8 +754,7 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) TCHAR title[256]; if (protocol == NULL) mir_sntprintf(title, SIZEOF(title), TranslateT("Set My Avatar")); - else - { + else { TCHAR* prototmp = mir_a2t(protocol); mir_sntprintf(title, SIZEOF(title), TranslateT("Set My Avatar for %s"), prototmp); mir_free(prototmp); @@ -802,27 +766,23 @@ INT_PTR avSetMyAvatar( char* protocol, TCHAR* tszPath ) else return 1; } - else - szFinalName = (TCHAR *)tszPath; - - /* - * filename is now set, check it and perform all needed action - */ + else szFinalName = (TCHAR*)tszPath; + // filename is now set, check it and perform all needed action if (szFinalName[0] == '\0') return InternalRemoveMyAvatar(protocol); return InternalSetMyAvatar(protocol, szFinalName, data, allAcceptXML, allAcceptSWF); } -static INT_PTR SetMyAvatar( WPARAM wParam, LPARAM lParam ) +static INT_PTR SetMyAvatar(WPARAM wParam, LPARAM lParam) { - return avSetMyAvatar(( char* )wParam, _A2T(( const char* )lParam )); + return avSetMyAvatar((char*)wParam, _A2T((const char*)lParam)); } -static INT_PTR SetMyAvatarW( WPARAM wParam, LPARAM lParam ) +static INT_PTR SetMyAvatarW(WPARAM wParam, LPARAM lParam) { - return avSetMyAvatar(( char* )wParam, ( TCHAR* )lParam ); + return avSetMyAvatar((char*)wParam, (TCHAR*)lParam); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -840,9 +800,9 @@ static INT_PTR ContactOptions(WPARAM wParam, LPARAM lParam) INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam) { - AVATARDRAWREQUEST *r = (AVATARDRAWREQUEST *)lParam; AVATARCACHEENTRY *ace = NULL; + AVATARDRAWREQUEST *r = (AVATARDRAWREQUEST*)lParam; if (fei == NULL || r == NULL || IsBadReadPtr((void *)r, sizeof(AVATARDRAWREQUEST))) return 0; @@ -855,7 +815,7 @@ INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam) for (int i = 0; i < g_ProtoPictures.getCount(); i++) { protoPicCacheEntry& p = g_ProtoPictures[i]; - if ( !lstrcmpA(p.szProtoname, r->szProto) && lstrlenA(r->szProto) == lstrlenA(p.szProtoname) && p.hbmPic != 0) { + if (!lstrcmpA(p.szProtoname, r->szProto) && lstrlenA(r->szProto) == lstrlenA(p.szProtoname) && p.hbmPic != 0) { ace = (AVATARCACHEENTRY *)&g_ProtoPictures[i]; break; } @@ -870,8 +830,7 @@ INT_PTR DrawAvatarPicture(WPARAM wParam, LPARAM lParam) ace = (AVATARCACHEENTRY *)GetMyAvatar(0, (LPARAM)r->szProto); } - else - ace = (AVATARCACHEENTRY *)GetAvatarBitmap((WPARAM)r->hContact, 0); + else ace = (AVATARCACHEENTRY *)GetAvatarBitmap((WPARAM)r->hContact, 0); if (ace && (!(r->dwFlags & AVDRQ_RESPECTHIDDEN) || !(ace->dwFlags & AVS_HIDEONCLIST))) { ace->t_lastAccess = time(NULL); @@ -917,9 +876,9 @@ static void ReloadMyAvatar(LPVOID lpParam) if (szProto[0] == 0) { // Notify to all possibles if (lstrcmpA(myAvatarProto, szProto)) { - if (!ProtoServiceExists( myAvatarProto, PS_SETMYAVATAR)) + if (!ProtoServiceExists(myAvatarProto, PS_SETMYAVATAR)) continue; - if (!Proto_IsAvatarsEnabled( myAvatarProto )) + if (!Proto_IsAvatarsEnabled(myAvatarProto)) continue; } @@ -949,7 +908,7 @@ INT_PTR ReportMyAvatarChanged(WPARAM wParam, LPARAM lParam) if (g_MyAvatars[i].dwFlags & AVS_IGNORENOTIFY) continue; - if ( !lstrcmpA(g_MyAvatars[i].szProtoname, proto)) { + if (!lstrcmpA(g_MyAvatars[i].szProtoname, proto)) { LPVOID lpParam = (void *)malloc(lstrlenA(g_MyAvatars[i].szProtoname) + 2); strcpy((char *)lpParam, g_MyAvatars[i].szProtoname); mir_forkthread(ReloadMyAvatar, lpParam); -- cgit v1.2.3