diff options
author | George Hazan <ghazan@miranda.im> | 2022-07-31 20:07:18 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-07-31 20:07:18 +0300 |
commit | 559dbc7b53b097c0beb326bf82302aaed6cfa0a8 (patch) | |
tree | a7562045ef397aec23d9aec4de150ff3a92ead17 /plugins/WhenWasIt/src/utils.cpp | |
parent | f6b30701f54f28912b19994606888e109f9ac3f4 (diff) |
fixes #3130 (WhenWasIt ведёт себя странно)
Diffstat (limited to 'plugins/WhenWasIt/src/utils.cpp')
-rw-r--r-- | plugins/WhenWasIt/src/utils.cpp | 148 |
1 files changed, 24 insertions, 124 deletions
diff --git a/plugins/WhenWasIt/src/utils.cpp b/plugins/WhenWasIt/src/utils.cpp index 1318b15a7e..5cdcc29103 100644 --- a/plugins/WhenWasIt/src/utils.cpp +++ b/plugins/WhenWasIt/src/utils.cpp @@ -71,72 +71,33 @@ int Info(char *title, char *format, ...) return MessageBoxA(nullptr, str, title, MB_OK | MB_ICONINFORMATION);
}
-#define HEX_SIZE 8
+///////////////////////////////////////////////////////////////////////////////
-char* BinToHex(int size, uint8_t *data)
+void CheckConvert(void)
{
- char *szresult = nullptr;
- char buffer[32] = { 0 }; //should be more than enough
- int maxSize = size * 2 + HEX_SIZE + 1;
- szresult = (char *) new char[maxSize];
- memset(szresult, 0, maxSize);
- mir_snprintf(buffer, "%0*X", HEX_SIZE, size);
- mir_strcpy(szresult, buffer);
-
- for (int i = 0; i < size; i++) {
- mir_snprintf(buffer, "%02X", data[i]);
- mir_strcpy(szresult + (HEX_SIZE + i * 2), buffer);
- }
- return szresult;
-}
-
-void HexToBin(char *inData, ULONG &size, LPBYTE &outData)
-{
- char buffer[32] = { 0 };
- mir_strcpy(buffer, "0x");
- strncpy(buffer + 2, inData, HEX_SIZE);
- sscanf(buffer, "%x", &size);
- outData = (unsigned char*)new char[size * 2];
-
- char *tmp = inData + HEX_SIZE;
- buffer[4] = '\0'; //mark the end of the string
- for (UINT i = 0; i < size; i++) {
- strncpy(buffer + 2, &tmp[i * 2], 2);
- sscanf(buffer, "%hhx", &outData[i]);
- }
-}
-
-int GetStringFromDatabase(MCONTACT hContact, char *szModule, char *szSettingName, char *szError, char *szResult, size_t size)
-{
- DBVARIANT dbv = { 0 };
- int res = 1;
- size_t len;
- dbv.type = DBVT_ASCIIZ;
- if (db_get(hContact, szModule, szSettingName, &dbv) == 0) {
- res = 0;
- size_t tmp = mir_strlen(dbv.pszVal);
- len = (tmp < size - 1) ? tmp : size - 1;
- strncpy(szResult, dbv.pszVal, len);
- szResult[len] = '\0';
- mir_free(dbv.pszVal);
- }
- else {
- res = 1;
- if (szError) {
- size_t tmp = mir_strlen(szError);
- len = (tmp < size - 1) ? tmp : size - 1;
- strncpy(szResult, szError, len);
- szResult[len] = '\0';
+ if (db_get_b(0, "Compatiblilty", MODULENAME) < 1) {
+ for (auto &hContact : Contacts()) {
+ int bday = db_get_dw(hContact, "UserInfo", "DOBd", -1);
+ if (bday == -1)
+ continue;
+
+ int bmonth = db_get_dw(hContact, "UserInfo", "DOBm");
+ int byear = db_get_dw(hContact, "UserInfo", "DOBy");
+
+ db_unset(hContact, "UserInfo", "DOBd");
+ db_unset(hContact, "UserInfo", "DOBm");
+ db_unset(hContact, "UserInfo", "DOBy");
+
+ db_set_dw(hContact, "UserInfo", "BirthDay", bday);
+ db_set_dw(hContact, "UserInfo", "BirthMonth", bmonth);
+ db_set_dw(hContact, "UserInfo", "BirthYear", byear);
}
- else szResult[0] = '\0';
+
+ db_set_b(0, "Compatiblilty", MODULENAME, 1);
}
- return res;
}
-int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, size_t size)
-{
- return GetStringFromDatabase(0, MODULENAME, szSettingName, szError, szResult, size);
-}
+///////////////////////////////////////////////////////////////////////////////
wchar_t* GetContactID(MCONTACT hContact)
{
@@ -149,6 +110,8 @@ wchar_t* GetContactID(MCONTACT hContact, char *szProto) return (res) ? wcsdup(res) : nullptr;
}
+///////////////////////////////////////////////////////////////////////////////
+
MCONTACT GetContactFromID(wchar_t *szID, char *szProto)
{
for (auto &hContact : Contacts()) {
@@ -171,70 +134,7 @@ MCONTACT GetContactFromID(wchar_t *szID, wchar_t *szProto) return GetContactFromID(szID, protocol);
}
-void ScreenToClient(HWND hWnd, LPRECT rect)
-{
- int cx = rect->right - rect->left;
- int cy = rect->bottom - rect->top;
- POINT pt = { rect->left, rect->top };
- ScreenToClient(hWnd, &pt);
- rect->left = pt.x;
- rect->top = pt.y;
- rect->right = pt.x + cx;
- rect->bottom = pt.y + cy;
-}
-
-void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors)
-{
- if (parentPos->flags & SWP_NOSIZE)
- return;
-
- RECT rParent;
- GetWindowRect(parentPos->hwnd, &rParent);
-
- RECT rChild = AnchorCalcPos(window, &rParent, parentPos, anchors);
- MoveWindow(window, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, FALSE);
-}
-
-RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors)
-{
- RECT rChild;
- GetWindowRect(window, &rChild);
- ScreenToClient(parentPos->hwnd, &rChild);
-
- int cx = rParent->right - rParent->left;
- int cy = rParent->bottom - rParent->top;
- if ((cx == parentPos->cx) && (cy == parentPos->cy))
- return rChild;
-
- if (parentPos->flags & SWP_NOSIZE)
- return rChild;
-
- RECT rTmp;
- rTmp.left = parentPos->x - rParent->left;
- rTmp.right = (parentPos->x + parentPos->cx) - rParent->right;
- rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom;
- rTmp.top = parentPos->y - rParent->top;
-
- cx = (rTmp.left) ? -rTmp.left : rTmp.right;
- cy = (rTmp.top) ? -rTmp.top : rTmp.bottom;
-
- rChild.right += cx;
- rChild.bottom += cy;
- //expanded the window accordingly, now we need to enforce the anchors
- if ((anchors & ANCHOR_LEFT) && (!(anchors & ANCHOR_RIGHT)))
- rChild.right -= cx;
-
- if ((anchors & ANCHOR_TOP) && (!(anchors & ANCHOR_BOTTOM)))
- rChild.bottom -= cy;
-
- if ((anchors & ANCHOR_RIGHT) && (!(anchors & ANCHOR_LEFT)))
- rChild.left += cx;
-
- if ((anchors & ANCHOR_BOTTOM) && (!(anchors & ANCHOR_TOP)))
- rChild.top += cy;
-
- return rChild;
-}
+///////////////////////////////////////////////////////////////////////////////
void CreateToolTip(HWND target, const wchar_t* tooltip, LPARAM width)
{
|