From 1d18d087d47d7a54f68950f983029642a54d6f43 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 7 Jun 2015 12:10:26 +0000 Subject: - common.props divided into app.props & plugin.props; - MimCmd & CmdLine converted to Unicode; git-svn-id: http://svn.miranda-ng.org/main/trunk@14048 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/CmdLine/src/utils.cpp | 256 +++++++++++++----------------------------- 1 file changed, 75 insertions(+), 181 deletions(-) (limited to 'plugins/CmdLine/src/utils.cpp') diff --git a/plugins/CmdLine/src/utils.cpp b/plugins/CmdLine/src/utils.cpp index 7a6aad0e3e..59b0ce634c 100644 --- a/plugins/CmdLine/src/utils.cpp +++ b/plugins/CmdLine/src/utils.cpp @@ -18,52 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "commonheaders.h" - -int LogInit() -{ -#ifdef USE_LOG - //FILE *fout = fopen(LOG_FILE, "wt"); - //fclose(fout); - Log("********************** Miranda started **********************"); -#endif - return 0; -} - -int Log(char *format, ...) -{ -#ifdef USE_LOG - char str[4096]; - va_list vararg; - int tBytes; - FILE *fout = fopen(LOG_FILE, "at"); - if (!fout) - { -// MessageBox(0, "can't open file", NULL, MB_OK); - return -1; - } - time_t tNow = time(NULL); - struct tm *now = localtime(&tNow); - strftime(str, sizeof(str), "%d %b %Y @ %H:%M:%S: ", now); - fputs(str, fout); - va_start(vararg, format); - - tBytes = mir_vsnprintf(str, sizeof(str), format, vararg); - if (tBytes > 0) - { - str[tBytes] = 0; - } - - va_end(vararg); - if (str[mir_strlen(str) - 1] != '\n') - { - mir_strcat(str, "\n"); - } - fputs(str, fout); - fclose(fout); -#endif - return 0; -} +#include "stdafx.h" int Info(char *title, char *format, ...) { @@ -83,14 +38,10 @@ int Info(char *title, char *format, ...) int MyPUShowMessage(char *lpzText, BYTE kind) { if (ServiceExists(MS_POPUP_SHOWMESSAGE)) - { return PUShowMessage(lpzText, kind); - } - else{ - char *title = (kind == SM_NOTIFY) ? Translate("Notify") : Translate("Warning"); - return MessageBox(NULL, lpzText, title, MB_OK | (kind == SM_NOTIFY) ? MB_ICONINFORMATION : MB_ICONEXCLAMATION); - } + char *title = (kind == SM_NOTIFY) ? Translate("Notify") : Translate("Warning"); + return MessageBoxA(NULL, lpzText, title, MB_OK | (kind == SM_NOTIFY) ? MB_ICONINFORMATION : MB_ICONEXCLAMATION); } #define HEX_SIZE 8 @@ -107,20 +58,17 @@ char *BinToHex(int size, PBYTE data) void HexToBin(char *inData, ULONG &size, LPBYTE &outData) { char buffer[32] = {0}; - mir_strcpy(buffer, "0x"); - STRNCPY(buffer + 2, inData, HEX_SIZE); + strcpy(buffer, "0x"); + strncpy_s(buffer + 2, HEX_SIZE, inData, _TRUNCATE); sscanf(buffer, "%x", &size); outData = (unsigned char*)new char[size*2]; - UINT i; - //size = i; + char *tmp = inData + HEX_SIZE; buffer[4] = '\0'; //mark the end of the string - for (i = 0; i < size; i++) - { - STRNCPY(buffer + 2, &tmp[i * 2], 2); - sscanf(buffer, "%x", &outData[i]); - } - i = size; + for (UINT i = 0; i < size; i++) { + strncpy_s(buffer + 2, 3, &tmp[i*2], _TRUNCATE); + sscanf(buffer, "%x", &outData[i]); + } } int GetStringFromDatabase(MCONTACT hContact, char *szModule, char *szSettingName, char *szError, char *szResult, size_t size) @@ -202,43 +150,30 @@ int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, } #pragma warning (disable: 4312) -TCHAR *GetContactName(MCONTACT hContact, char *szProto) +char* GetContactName(MCONTACT hContact, char *szProto) { - CONTACTINFO ctInfo; - INT_PTR ret; char proto[200]; + CONTACTINFO ctInfo; memset(&ctInfo, 0, sizeof(ctInfo)); ctInfo.cbSize = sizeof(ctInfo); if (szProto) - { - ctInfo.szProto = szProto; - } - else{ - GetContactProto(hContact, proto, sizeof(proto)); - ctInfo.szProto = proto; - } + ctInfo.szProto = szProto; + else { + GetContactProto(hContact, proto, sizeof(proto)); + ctInfo.szProto = proto; + } ctInfo.dwFlag = CNF_DISPLAY; -#ifdef _UNICODE - ctInfo.dwFlag += CNF_UNICODE; -#endif ctInfo.hContact = hContact; + //_debug_message("retrieving contact name for %d", hContact); - ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); + INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); + if (ret) + return NULL; + //_debug_message(" contact name %s", ctInfo.pszVal); - TCHAR *buffer; - if (!ret) - { - buffer = _tcsdup(ctInfo.pszVal); - } + char *buffer = strdup((char*)ctInfo.pszVal); mir_free(ctInfo.pszVal); - if (!ret) - { - return buffer; - } - else{ - return NULL; - } return buffer; } #pragma warning (default: 4312) @@ -251,7 +186,7 @@ void GetContactProto(MCONTACT hContact, char *szProto, size_t size) #pragma warning (default: 4312) #pragma warning (disable: 4312) -TCHAR *GetContactID(MCONTACT hContact) +char* GetContactID(MCONTACT hContact) { char protocol[256]; GetContactProto(hContact, protocol, sizeof(protocol)); @@ -259,93 +194,68 @@ TCHAR *GetContactID(MCONTACT hContact) return GetContactID(hContact, protocol); } -TCHAR *GetContactID(MCONTACT hContact, char *szProto) +char* GetContactID(MCONTACT hContact, char *szProto) { CONTACTINFO ctInfo; - INT_PTR ret; - memset(&ctInfo, 0, sizeof(ctInfo)); ctInfo.cbSize = sizeof(ctInfo); ctInfo.szProto = szProto; ctInfo.dwFlag = CNF_UNIQUEID; -#ifdef _UNICODE - ctInfo.dwFlag |= CNF_UNICODE; -#endif ctInfo.hContact = hContact; - ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); - TCHAR *buffer; - if (!ret) - { - TCHAR tmp[16]; - switch (ctInfo.type) - { - case CNFT_BYTE: - { - mir_sntprintf(tmp, SIZEOF(tmp), _T("%d"), ctInfo.bVal); - buffer = _tcsdup(tmp); - - break; - } - - case CNFT_WORD: - { - mir_sntprintf(tmp, SIZEOF(tmp), _T("%d"), ctInfo.wVal); - buffer = _tcsdup(tmp); - - break; - } - - case CNFT_DWORD: - { - mir_sntprintf(tmp, SIZEOF(tmp), _T("%ld"), ctInfo.dVal); - buffer = _tcsdup(tmp); - - break; - } - - case CNFT_ASCIIZ: - default: - { - buffer = _tcsdup(ctInfo.pszVal); - - break; - } - } - + INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); + if (ret) + return NULL; + + char *buffer; + char tmp[16]; + switch (ctInfo.type) { + case CNFT_BYTE: + mir_snprintf(tmp, SIZEOF(tmp), "%d", ctInfo.bVal); + buffer = strdup(tmp); + break; + + case CNFT_WORD: + mir_snprintf(tmp, SIZEOF(tmp), "%d", ctInfo.wVal); + buffer = strdup(tmp); + break; + + case CNFT_DWORD: + mir_snprintf(tmp, SIZEOF(tmp), "%ld", ctInfo.dVal); + buffer = strdup(tmp); + break; + + case CNFT_ASCIIZ: + default: + buffer = _strdup((char*)ctInfo.pszVal); + break; + } - } mir_free(ctInfo.pszVal); - if (!ret) - { - return buffer; - } - else{ - return NULL; - } + return buffer; } #pragma warning (default: 4312) #pragma warning (disable: 4312) -MCONTACT GetContactFromID(TCHAR *szID, char *szProto) +MCONTACT GetContactFromID(char *szID, char *szProto) { - TCHAR dispName[1024]; + char dispName[1024]; char cProtocol[256]; - char *tmp; int found = 0; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { GetContactProto(hContact, cProtocol, sizeof(cProtocol)); - TCHAR *szHandle = GetContactID(hContact, cProtocol); + char *szHandle = GetContactID(hContact, cProtocol); - tmp = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, 0); - STRNCPY(dispName, tmp, sizeof(dispName)); + char *tmp = (char*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, 0); + strncpy_s(dispName, tmp, _TRUNCATE); - if ((szHandle) && ((mir_tstrcmpi(szHandle, szID) == 0) || (mir_tstrcmpi(dispName, szID) == 0)) && ((szProto == NULL) || (_stricmp(szProto, cProtocol) == 0))) + if ((szHandle) && ((mir_strcmpi(szHandle, szID) == 0) || (mir_strcmpi(dispName, szID) == 0)) && ((szProto == NULL) || (_stricmp(szProto, cProtocol) == 0))) found = 1; free(szHandle); - if (found) return hContact; + if (found) + return hContact; } return NULL; @@ -353,7 +263,7 @@ MCONTACT GetContactFromID(TCHAR *szID, char *szProto) #pragma warning (default: 4312) #pragma warning (disable: 4312) -MCONTACT GetContactFromID(TCHAR *szID, wchar_t *szProto) +MCONTACT GetContactFromID(char *szID, wchar_t *szProto) { char protocol[1024]; WideCharToMultiByte(CP_ACP, 0, szProto, -1, protocol, sizeof(protocol), NULL, NULL); @@ -381,9 +291,8 @@ void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors) RECT rChild; if (parentPos->flags & SWP_NOSIZE) - { - return; - } + return; + GetWindowRect(parentPos->hwnd, &rParent); rChild = AnchorCalcPos(window, &rParent, parentPos, anchors); MoveWindow(window, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, FALSE); @@ -400,13 +309,10 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int cx = rParent->right - rParent->left; int cy = rParent->bottom - rParent->top; if ((cx == parentPos->cx) && (cy == parentPos->cy)) - { - return rChild; - } + return rChild; + if (parentPos->flags & SWP_NOSIZE) - { - return rChild; - } + return rChild; rTmp.left = parentPos->x - rParent->left; rTmp.right = (parentPos->x + parentPos->cx) - rParent->right; @@ -420,28 +326,16 @@ RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, rChild.bottom += cy; //expanded the window accordingly, now we need to enforce the anchors if ((anchors & ANCHOR_LEFT) && (!(anchors & ANCHOR_RIGHT))) - { - rChild.right -= cx; - } + rChild.right -= cx; + if ((anchors & ANCHOR_TOP) && (!(anchors & ANCHOR_BOTTOM))) - { - rChild.bottom -= cy; - } + rChild.bottom -= cy; + if ((anchors & ANCHOR_RIGHT) && (!(anchors & ANCHOR_LEFT))) - { - rChild.left += cx; - } + rChild.left += cx; + if ((anchors & ANCHOR_BOTTOM) && (!(anchors & ANCHOR_TOP))) - { - rChild.top += cy; - } + rChild.top += cy; + return rChild; } - -inline char *STRNCPY(char *output, const char *input, size_t size) -{ - char *res = strncpy(output, input, size); - output[size - 1] = 0; - - return res; -} \ No newline at end of file -- cgit v1.2.3