diff options
Diffstat (limited to 'plugins/FingerprintNG')
-rw-r--r-- | plugins/FingerprintNG/src/fingerprint.cpp | 746 | ||||
-rw-r--r-- | plugins/FingerprintNG/src/stdafx.h | 5 |
2 files changed, 353 insertions, 398 deletions
diff --git a/plugins/FingerprintNG/src/fingerprint.cpp b/plugins/FingerprintNG/src/fingerprint.cpp index 57613220d0..71b7f7ba98 100644 --- a/plugins/FingerprintNG/src/fingerprint.cpp +++ b/plugins/FingerprintNG/src/fingerprint.cpp @@ -39,343 +39,80 @@ static OBJLIST<FOUNDINFO> arFI(50, CompareFI); static LIST<void> arMonitoredWindows(3, PtrKeySortT);
-/* GetIconsIndexes
-* Retrieves Icons indexes by Mirver
-*/
-
-static void GetIconsIndexes(LPWSTR wszMirVer, KN_FP_MASK *&base, KN_FP_MASK *&overlay1, KN_FP_MASK *&overlay2, KN_FP_MASK *&overlay3, KN_FP_MASK *&overlay4)
-{
- base = overlay1 = overlay2 = overlay3 = overlay4 = nullptr;
-
- if (mir_wstrcmp(wszMirVer, L"?") == 0) {
- base = g_pUnknown;
- return;
- }
-
- LPWSTR wszMirVerUp = NEWWSTR_ALLOCA(wszMirVer);
- _wcsupr(wszMirVerUp);
-
- for (auto &it : g_arCommon) {
- if (it->hIcolibItem == nullptr)
- continue;
-
- if (!WildCompare(wszMirVerUp, it->szMaskUpper))
- continue;
-
- base = it;
- if (it->iIconIndex != IDI_NOTFOUND && it->iIconIndex != IDI_UNKNOWN && it->iIconIndex != IDI_UNDETECTED) {
- wchar_t destfile[MAX_PATH];
- wcsncpy_s(destfile, g_szSkinLib, _TRUNCATE);
-
- struct _stat64i32 stFileInfo;
- if (_wstat(destfile, &stFileInfo) == -1)
- base = g_pNotFound;
- }
- break;
- }
-
- if (base == nullptr)
- base = g_pUnknown;
-
- else if (!base->fNotUseOverlay) {
- for (auto &it : g_overlay1) {
- if (!WildCompare(wszMirVerUp, it->szMaskUpper))
- continue;
-
- struct _stat64i32 stFileInfo;
- if (_wstat(g_szSkinLib, &stFileInfo) != -1) {
- overlay1 = it;
- break;
- }
- }
-
- for (auto &it : g_overlay2) {
- if (WildCompare(wszMirVerUp, it->szMaskUpper)) {
- overlay2 = it;
- break;
- }
- }
-
- for (auto &it : g_overlay3) {
- if (WildCompare(wszMirVerUp, it->szMaskUpper)) {
- overlay3 = it;
- break;
- }
- }
-
- for (auto &it : g_overlay4) {
- if (it->hIcolibItem == nullptr)
- continue;
-
- if (WildCompare(wszMirVerUp, it->szMaskUpper)) {
- overlay4 = it;
- break;
- }
- }
- }
-}
-
-/*
-* CreateIconFromIndexes
-* returns hIcon of joined icon by given indexes
-*/
-
-HICON __fastcall CreateIconFromIndexes(KN_FP_MASK *base, KN_FP_MASK *overlay1, KN_FP_MASK *overlay2, KN_FP_MASK *overlay3, KN_FP_MASK *overlay4)
-{
- HICON hIcon = nullptr; // returned HICON
- HICON hTmp = nullptr;
- HICON icOverlay = nullptr;
- HICON icOverlay2 = nullptr;
- HICON icOverlay3 = nullptr;
- HICON icOverlay4 = nullptr;
-
- HICON icMain = IcoLib_GetIconByHandle(base->hIcolibItem);
- if (icMain) {
- icOverlay = (overlay1 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay1->hIcolibItem);
- icOverlay2 = (overlay2 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay2->hIcolibItem);
- icOverlay3 = (overlay3 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay3->hIcolibItem);
- icOverlay4 = (overlay4 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay4->hIcolibItem);
-
- hIcon = icMain;
-
- if (overlay1)
- hTmp = hIcon = CreateJoinedIcon(hIcon, icOverlay);
-
- if (overlay2) {
- hIcon = CreateJoinedIcon(hIcon, icOverlay2);
- if (hTmp) DestroyIcon(hTmp);
- hTmp = hIcon;
- }
-
- if (overlay3) {
- hIcon = CreateJoinedIcon(hIcon, icOverlay3);
- if (hTmp) DestroyIcon(hTmp);
- hTmp = hIcon;
- }
-
- if (overlay4) {
- hIcon = CreateJoinedIcon(hIcon, icOverlay4);
- if (hTmp) DestroyIcon(hTmp);
- }
- }
+/////////////////////////////////////////////////////////////////////////////////////////
+// Futher routines is for creating joined 'overlay' icons.
- if (hIcon == icMain)
- hIcon = CopyIcon(icMain);
-
- IcoLib_ReleaseIcon(icMain);
- IcoLib_ReleaseIcon(icOverlay);
- IcoLib_ReleaseIcon(icOverlay2);
- IcoLib_ReleaseIcon(icOverlay3);
- IcoLib_ReleaseIcon(icOverlay4);
- return hIcon;
-}
-
-/****************************************************************************************
-* ServiceGetClientIcon
-* MS_FP_GETCLIENTICONW service implementation.
-* wParam - LPWSTR MirVer value to get client for.
-* lParam - int noCopy - if wParam is equal to "1" will return icon handler without copiing icon.
-* ICON IS ALWAYS COPIED!!!
-*/
-
-static INT_PTR ServiceGetClientIcon(WPARAM wParam, LPARAM)
-{
- LPWSTR wszMirVer = (LPWSTR)wParam; // MirVer value to get client for.
- if (wszMirVer == nullptr)
- return 0;
-
- KN_FP_MASK *base, *overlay1, *overlay2, *overlay3, *overlay4;
- GetIconsIndexes(wszMirVer, base, overlay1, overlay2, overlay3, overlay4);
-
- HICON hIcon = nullptr; // returned HICON
- if (base != nullptr)
- hIcon = CreateIconFromIndexes(base, overlay1, overlay2, overlay3, overlay4);
-
- return (INT_PTR)hIcon;
-}
-
-/****************************************************************************************
-* ApplyFingerprintImage
-* 1)Try to find appropriate mask
-* 2)Register icon in extraimage list if not yet registered (EMPTY_EXTRA_ICON)
-* 3)Set ExtraImage for contact
-*/
-
-static void SetSrmmIcon(MCONTACT hContact, LPTSTR ptszMirver)
-{
- if (mir_wstrlen(ptszMirver))
- Srmm_ModifyIcon(hContact, MODULENAME, 1, (HICON)ServiceGetClientIcon((WPARAM)ptszMirver, TRUE), ptszMirver);
- else
- Srmm_SetIconFlags(hContact, MODULENAME, 1, MBF_HIDDEN);
-}
-
-int __fastcall ApplyFingerprintImage(MCONTACT hContact, LPTSTR szMirVer)
-{
- if (hContact == NULL)
- return 0;
-
- HANDLE hImage = INVALID_HANDLE_VALUE;
- if (szMirVer)
- hImage = GetIconIndexFromFI(szMirVer);
-
- ExtraIcon_SetIcon(hExtraIcon, hContact, hImage);
-
- if (arMonitoredWindows.getIndex((HANDLE)hContact) != -1)
- SetSrmmIcon(hContact, szMirVer);
-
- return 0;
-}
-
-int OnExtraIconClick(WPARAM wParam, LPARAM, LPARAM)
-{
- CallService(MS_USERINFO_SHOWDIALOG, wParam, NULL);
- return 0;
-}
-
-/*
-* WildCompare
-* Compare 'name' string with 'mask' strings.
-* Masks can contain '*' or '?' wild symbols
-* Asterics '*' symbol covers 'empty' symbol too e.g WildCompare("Tst","T*st*"), returns TRUE
-* In order to handle situation 'at least one any sybol' use "?*" combination:
-* e.g WildCompare("Tst","T?*st*"), returns FALSE, but both WildCompare("Test","T?*st*") and
-* WildCompare("Teeest","T?*st*") return TRUE.
-*
-* Function is case sensitive! so convert input or modify func to use _qtoupper()
-*
-* Mask can contain several submasks. In this case each submask (including first)
-* should start from '|' e.g: "|first*submask|second*mask".
-*
-* Dec 25, 2006 by FYR:
-* Added Exception to masks: the mask "|^mask3|mask2|mask1" means:
-* if NOT according to mask 3 AND (mask1 OR mask2)
-* EXCEPTION should be BEFORE main mask:
-* IF Exception match - the comparing stops as FALSE
-* IF Exception does not match - comparing continue
-* IF Mask match - comparing stops as TRUE
-* IF Mask does not not match comparing continue
-*/
-BOOL __fastcall WildCompare(LPWSTR wszName, LPWSTR wszMask)
-{
- if (wszMask == nullptr)
- return NULL;
-
- if (*wszMask != L'|')
- return wildcmpw(wszName, wszMask);
+// CreateBitmap32 - Create DIB 32 bitmap with sizes cx*cy and put reference
+// to new bitmap pixel image memory area to void ** bits
- size_t s = 1, e = 1;
- LPWSTR wszTemp = (LPWSTR)_alloca(mir_wstrlen(wszMask) * sizeof(wchar_t) + sizeof(wchar_t));
- BOOL bExcept;
-
- while (wszMask[e] != L'\0')
- {
- s = e;
- while (wszMask[e] != L'\0' && wszMask[e] != L'|') e++;
-
- // exception mask
- bExcept = (*(wszMask + s) == L'^');
- if (bExcept) s++;
-
- memcpy(wszTemp, wszMask + s, (e - s) * sizeof(wchar_t));
- wszTemp[e - s] = L'\0';
-
- if (wildcmpw(wszName, wszTemp))
- return !bExcept;
-
- if (wszMask[e] != L'\0')
- e++;
- else
- return FALSE;
- }
- return FALSE;
-}
-
-/******************************************************************************
- * Futher routines is for creating joined 'overlay' icons.
- ******************************************************************************/
-
- /*
- * CreateBitmap32 - Create DIB 32 bitmap with sizes cx*cy
- */
-
-HBITMAP __inline CreateBitmap32(int cx, int cy)
+HBITMAP __fastcall CreateBitmap32(int cx, int cy, LPBYTE &bits)
{
- return CreateBitmap32Point(cx, cy, nullptr);
-}
+ if (cx < 0 || cy < 0)
+ return nullptr;
-/*
-* CreateBitmap32 - Create DIB 32 bitmap with sizes cx*cy and put reference
-* to new bitmap pixel image memory area to void ** bits
-*/
-HBITMAP __fastcall CreateBitmap32Point(int cx, int cy, LPVOID* bits)
-{
LPVOID ptPixels = nullptr;
-
- if (cx < 0 || cy < 0) return nullptr;
-
BITMAPINFO bmpi = {};
bmpi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpi.bmiHeader.biWidth = cx;
bmpi.bmiHeader.biHeight = cy;
bmpi.bmiHeader.biPlanes = 1;
bmpi.bmiHeader.biBitCount = 32;
+
HBITMAP DirectBitmap = CreateDIBSection(nullptr, &bmpi, DIB_RGB_COLORS, &ptPixels, nullptr, 0);
GdiFlush();
- if (ptPixels) memset(ptPixels, 0, cx * cy * 4);
- if (bits != nullptr) *bits = ptPixels;
+ if (ptPixels)
+ memset(ptPixels, 0, cx * cy * 4);
+ bits = (LPBYTE)ptPixels;
return DirectBitmap;
}
-/*
-* checkHasAlfa - checks if image has at least one uint8_t in alpha channel
-* that is not a 0. (is image real 32 bit or just 24 bit)
-*/
-BOOL __fastcall checkHasAlfa(LPBYTE from, int width, int height)
+/////////////////////////////////////////////////////////////////////////////////////////
+// checkHasAlfa - checks if image has at least one uint8_t in alpha channel
+// that is not a 0. (is image real 32 bit or just 24 bit)
+
+static bool checkHasAlfa(LPBYTE from, int width, int height)
{
LPDWORD pt = (LPDWORD)from;
LPDWORD lim = pt + width * height;
- while (pt < lim)
- {
+ while (pt < lim) {
if (*pt & 0xFF000000)
- return TRUE;
+ return true;
pt++;
}
- return FALSE;
+ return false;
}
-/*
-* checkMaskUsed - checks if mask image has at least one that is not a 0.
-* Not sure is it required or not
-*/
-BOOL __fastcall checkMaskUsed(LPBYTE from)
+/////////////////////////////////////////////////////////////////////////////////////////
+// checkMaskUsed - checks if mask image has at least one that is not a 0.
+// Not sure is it required or not
+
+static bool checkMaskUsed(LPBYTE from)
{
- int i;
- for (i = 0; i < 16 * 16 / 8; i++)
- {
- if (from[i] != 0) return TRUE;
- }
- return FALSE;
+ for (int i = 0; i < 16 * 16 / 8; i++)
+ if (from[i] != 0)
+ return true;
+
+ return false;
}
-/*
-* GetMaskBit - return value of apropriate mask bit in line at x position
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// GetMaskBit - return value of apropriate mask bit in line at x position
+
BOOL __inline GetMaskBit(LPBYTE line, int x)
{
return ((*(line + (x >> 3))) & (0x01 << (7 - (x & 0x07)))) != 0;
}
-/*
-* blend - alpha blend ARGB values of 2 pixels. X1 - underlaying,
-* X2 - overlaying points.
-*/
-uint32_t __fastcall blend(uint32_t X1, uint32_t X2)
+/////////////////////////////////////////////////////////////////////////////////////////
+// blend - alpha blend ARGB values of 2 pixels. X1 - underlaying, X2 - overlaying points.
+
+static uint32_t blend(uint32_t X1, uint32_t X2)
{
- RGBA* q1 = (RGBA*)&X1;
- RGBA* q2 = (RGBA*)&X2;
+ RGBA *q1 = (RGBA *)&X1;
+ RGBA *q2 = (RGBA *)&X2;
uint8_t a_1 = ~q1->a;
uint8_t a_2 = ~q2->a;
uint16_t am = q1->a * a_2;
@@ -398,10 +135,10 @@ uint32_t __fastcall blend(uint32_t X1, uint32_t X2) }
}
-/*
-* CreateJoinedIcon - creates new icon by drawing hTop over hBottom.
-*/
-HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop)
+/////////////////////////////////////////////////////////////////////////////////////////
+// CreateJoinedIcon - creates new icon by drawing hTop over hBottom.
+
+static HICON CreateJoinedIcon(HICON hBottom, HICON hTop)
{
BOOL drawn = FALSE;
HDC tempDC, tempDC2, tempDC3;
@@ -413,7 +150,7 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) uint8_t p[32] = { 0 };
tempDC = CreateCompatibleDC(nullptr);
- nImage = CreateBitmap32Point(16, 16, (LPVOID*)&ptPixels);
+ nImage = CreateBitmap32(16, 16, ptPixels);
oImage = (HBITMAP)SelectObject(tempDC, nImage);
ICONINFO iciBottom = { 0 };
@@ -433,8 +170,7 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) GetObject(iciTop.hbmColor, sizeof(BITMAP), &bmp_top);
GetObject(iciTop.hbmMask, sizeof(BITMAP), &bmp_top_mask);
- if (bmp_bottom.bmBitsPixel == 32 && bmp_top.bmBitsPixel == 32)
- {
+ if (bmp_bottom.bmBitsPixel == 32 && bmp_top.bmBitsPixel == 32) {
LPBYTE BottomBuffer, TopBuffer, BottomMaskBuffer, TopMaskBuffer;
LPBYTE bb, tb, bmb, tmb;
LPBYTE db = ptPixels;
@@ -446,8 +182,7 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) if (bmp_bottom.bmBits)
bb = BottomBuffer = (LPBYTE)bmp_bottom.bmBits;
- else
- {
+ else {
BottomBuffer = (LPBYTE)_alloca(bmp_bottom.bmHeight * bmp_bottom.bmWidthBytes);
GetBitmapBits(iciBottom.hbmColor, bmp_bottom.bmHeight * bmp_bottom.bmWidthBytes, BottomBuffer);
bb = BottomBuffer + vstep_b * (bmp_bottom.bmHeight - 1);
@@ -455,8 +190,7 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) }
if (bmp_top.bmBits)
tb = TopBuffer = (LPBYTE)bmp_top.bmBits;
- else
- {
+ else {
TopBuffer = (LPBYTE)_alloca(bmp_top.bmHeight * bmp_top.bmWidthBytes);
GetBitmapBits(iciTop.hbmColor, bmp_top.bmHeight * bmp_top.bmWidthBytes, TopBuffer);
tb = TopBuffer + vstep_t * (bmp_top.bmHeight - 1);
@@ -464,8 +198,7 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) }
if (bmp_bottom_mask.bmBits)
bmb = BottomMaskBuffer = (LPBYTE)bmp_bottom_mask.bmBits;
- else
- {
+ else {
BottomMaskBuffer = (LPBYTE)_alloca(bmp_bottom_mask.bmHeight * bmp_bottom_mask.bmWidthBytes);
GetBitmapBits(iciBottom.hbmMask, bmp_bottom_mask.bmHeight * bmp_bottom_mask.bmWidthBytes, BottomMaskBuffer);
bmb = BottomMaskBuffer + vstep_bm * (bmp_bottom_mask.bmHeight - 1);
@@ -473,29 +206,24 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) }
if (bmp_top_mask.bmBits)
tmb = TopMaskBuffer = (LPBYTE)bmp_top_mask.bmBits;
- else
- {
+ else {
TopMaskBuffer = (LPBYTE)_alloca(bmp_top_mask.bmHeight * bmp_top_mask.bmWidthBytes);
GetBitmapBits(iciTop.hbmMask, bmp_top_mask.bmHeight * bmp_top_mask.bmWidthBytes, TopMaskBuffer);
tmb = TopMaskBuffer + vstep_tm * (bmp_top_mask.bmHeight - 1);
vstep_tm = -vstep_tm;
}
{
- int x; int y;
- BOOL topHasAlpha = checkHasAlfa(TopBuffer, bmp_top.bmWidth, bmp_top.bmHeight);
- BOOL bottomHasAlpha = checkHasAlfa(BottomBuffer, bmp_bottom.bmWidth, bmp_bottom.bmHeight);
- BOOL topMaskUsed = !topHasAlpha && checkMaskUsed(TopMaskBuffer);
- BOOL bottomMaskUsed = !bottomHasAlpha && checkMaskUsed(BottomMaskBuffer);
-
- for (y = 0; y < 16; y++)
- {
- for (x = 0; x < 16; x++)
- {
+ bool topHasAlpha = checkHasAlfa(TopBuffer, bmp_top.bmWidth, bmp_top.bmHeight);
+ bool bottomHasAlpha = checkHasAlfa(BottomBuffer, bmp_bottom.bmWidth, bmp_bottom.bmHeight);
+ bool topMaskUsed = !topHasAlpha && checkMaskUsed(TopMaskBuffer);
+ bool bottomMaskUsed = !bottomHasAlpha && checkMaskUsed(BottomMaskBuffer);
+
+ for (int y = 0; y < 16; y++) {
+ for (int x = 0; x < 16; x++) {
uint32_t bottom_d = ((LPDWORD)bb)[x];
uint32_t top_d = ((LPDWORD)tb)[x];
- if (topMaskUsed)
- {
+ if (topMaskUsed) {
if (GetMaskBit(tmb, x))
top_d &= 0x00FFFFFF;
else
@@ -504,8 +232,7 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) else if (!topHasAlpha)
top_d |= 0xFF000000;
- if (bottomMaskUsed)
- {
+ if (bottomMaskUsed) {
if (GetMaskBit(bmb, x))
bottom_d &= 0x00FFFFFF;
else
@@ -571,36 +298,271 @@ HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop) return res;
}
-HANDLE __fastcall GetIconIndexFromFI(LPTSTR szMirVer)
+/////////////////////////////////////////////////////////////////////////////////////////
+// CreateIconFromIndexes
+// returns hIcon of joined icon by given indexes
+
+static HICON CreateIconFromIndexes(KN_FP_MASK *base, KN_FP_MASK *overlay1, KN_FP_MASK *overlay2, KN_FP_MASK *overlay3, KN_FP_MASK *overlay4)
{
- KN_FP_MASK *base, *overlay1, *overlay2, *overlay3, *overlay4;
- GetIconsIndexes(szMirVer, base, overlay1, overlay2, overlay3, overlay4);
+ HICON hIcon = nullptr; // returned HICON
+ HICON hTmp = nullptr;
+ HICON icOverlay = nullptr;
+ HICON icOverlay2 = nullptr;
+ HICON icOverlay3 = nullptr;
+ HICON icOverlay4 = nullptr;
+
+ HICON icMain = IcoLib_GetIconByHandle(base->hIcolibItem);
+ if (icMain) {
+ icOverlay = (overlay1 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay1->hIcolibItem);
+ icOverlay2 = (overlay2 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay2->hIcolibItem);
+ icOverlay3 = (overlay3 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay3->hIcolibItem);
+ icOverlay4 = (overlay4 == nullptr) ? nullptr : IcoLib_GetIconByHandle(overlay4->hIcolibItem);
+
+ hIcon = icMain;
+
+ if (overlay1)
+ hTmp = hIcon = CreateJoinedIcon(hIcon, icOverlay);
+
+ if (overlay2) {
+ hIcon = CreateJoinedIcon(hIcon, icOverlay2);
+ if (hTmp) DestroyIcon(hTmp);
+ hTmp = hIcon;
+ }
+
+ if (overlay3) {
+ hIcon = CreateJoinedIcon(hIcon, icOverlay3);
+ if (hTmp) DestroyIcon(hTmp);
+ hTmp = hIcon;
+ }
+
+ if (overlay4) {
+ hIcon = CreateJoinedIcon(hIcon, icOverlay4);
+ if (hTmp) DestroyIcon(hTmp);
+ }
+ }
+
+ if (hIcon && hIcon == icMain)
+ hIcon = CopyIcon(icMain);
+
+ IcoLib_ReleaseIcon(icMain);
+ IcoLib_ReleaseIcon(icOverlay);
+ IcoLib_ReleaseIcon(icOverlay2);
+ IcoLib_ReleaseIcon(icOverlay3);
+ IcoLib_ReleaseIcon(icOverlay4);
+ return hIcon;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// GetIconsIndexes
+// Retrieves Icons indexes by Mirver
+
+static void GetIconsIndexes(LPWSTR wszMirVer, KN_FP_MASK *&base, KN_FP_MASK *&overlay1, KN_FP_MASK *&overlay2, KN_FP_MASK *&overlay3, KN_FP_MASK *&overlay4)
+{
+ base = overlay1 = overlay2 = overlay3 = overlay4 = nullptr;
+
+ if (mir_wstrcmp(wszMirVer, L"?") == 0) {
+ base = g_pUnknown;
+ return;
+ }
+
+ LPWSTR wszMirVerUp = NEWWSTR_ALLOCA(wszMirVer);
+ _wcsupr(wszMirVerUp);
+
+ for (auto &it : g_arCommon) {
+ if (it->hIcolibItem == nullptr)
+ continue;
+
+ if (!WildCompare(wszMirVerUp, it->szMaskUpper))
+ continue;
+
+ base = it;
+ if (it->iIconIndex != IDI_NOTFOUND && it->iIconIndex != IDI_UNKNOWN && it->iIconIndex != IDI_UNDETECTED) {
+ wchar_t destfile[MAX_PATH];
+ wcsncpy_s(destfile, g_szSkinLib, _TRUNCATE);
+
+ struct _stat64i32 stFileInfo;
+ if (_wstat(destfile, &stFileInfo) == -1)
+ base = g_pNotFound;
+ }
+ break;
+ }
+
if (base == nullptr)
- return INVALID_HANDLE_VALUE;
-
- // MAX: 256 + 64 + 64 + 64 + 64
- FOUNDINFO tmp = { base->idx, 0 };
- if (overlay1) tmp.iOverlay += ((overlay1->idx & 0xFF) << 18);
- if (overlay2) tmp.iOverlay += ((overlay2->idx & 0x3F) << 12);
- if (overlay3) tmp.iOverlay += ((overlay3->idx & 0x3F) << 6);
- if (overlay4) tmp.iOverlay += (overlay4->idx & 0x3F);
-
- auto *F = arFI.find(&tmp);
- if (F != nullptr)
- return F->hRegisteredImage;
-
- // not found - then add
- F = new FOUNDINFO(tmp);
- HICON hIcon = CreateIconFromIndexes(base, overlay1, overlay2, overlay3, overlay4);
- if (hIcon != nullptr) {
- F->hRegisteredImage = ExtraIcon_AddIcon(hIcon);
- DestroyIcon(hIcon);
+ base = g_pUnknown;
+
+ else if (!base->fNotUseOverlay) {
+ for (auto &it : g_overlay1) {
+ if (!WildCompare(wszMirVerUp, it->szMaskUpper))
+ continue;
+
+ struct _stat64i32 stFileInfo;
+ if (_wstat(g_szSkinLib, &stFileInfo) != -1) {
+ overlay1 = it;
+ break;
+ }
+ }
+
+ for (auto &it : g_overlay2) {
+ if (WildCompare(wszMirVerUp, it->szMaskUpper)) {
+ overlay2 = it;
+ break;
+ }
+ }
+
+ for (auto &it : g_overlay3) {
+ if (WildCompare(wszMirVerUp, it->szMaskUpper)) {
+ overlay3 = it;
+ break;
+ }
+ }
+
+ for (auto &it : g_overlay4) {
+ if (it->hIcolibItem == nullptr)
+ continue;
+
+ if (WildCompare(wszMirVerUp, it->szMaskUpper)) {
+ overlay4 = it;
+ break;
+ }
+ }
}
- else F->hRegisteredImage = INVALID_HANDLE_VALUE;
-
- arFI.insert(F);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// ServiceGetClientIcon
+// MS_FP_GETCLIENTICONW service implementation.
+// wParam - LPWSTR MirVer value to get client for.
+// lParam - int noCopy - if wParam is equal to "1" will return icon handler without copiing icon.
+// ICON IS ALWAYS COPIED!!!
+
+static INT_PTR ServiceGetClientIcon(WPARAM wParam, LPARAM)
+{
+ LPWSTR wszMirVer = (LPWSTR)wParam; // MirVer value to get client for.
+ if (wszMirVer == nullptr)
+ return 0;
+
+ KN_FP_MASK *base, *overlay1, *overlay2, *overlay3, *overlay4;
+ GetIconsIndexes(wszMirVer, base, overlay1, overlay2, overlay3, overlay4);
+
+ HICON hIcon = nullptr; // returned HICON
+ if (base != nullptr)
+ hIcon = CreateIconFromIndexes(base, overlay1, overlay2, overlay3, overlay4);
+
+ return (INT_PTR)hIcon;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// ApplyFingerprintImage
+// 1) Try to find appropriate mask
+// 2) Register icon in extraimage list if not yet registered (EMPTY_EXTRA_ICON)
+// 3) Set ExtraImage for contact
+
+static void SetSrmmIcon(MCONTACT hContact, LPTSTR ptszMirver)
+{
+ if (mir_wstrlen(ptszMirver))
+ Srmm_ModifyIcon(hContact, MODULENAME, 1, (HICON)ServiceGetClientIcon((WPARAM)ptszMirver, TRUE), ptszMirver);
+ else
+ Srmm_SetIconFlags(hContact, MODULENAME, 1, MBF_HIDDEN);
+}
+
+static int ApplyFingerprintImage(MCONTACT hContact, LPTSTR szMirVer)
+{
+ if (hContact == NULL)
+ return 0;
+
+ HANDLE hImage = INVALID_HANDLE_VALUE;
+ if (szMirVer) {
+ KN_FP_MASK *base, *overlay1, *overlay2, *overlay3, *overlay4;
+ GetIconsIndexes(szMirVer, base, overlay1, overlay2, overlay3, overlay4);
+ if (base) {
+ // MAX: 256 + 64 + 64 + 64 + 64
+ FOUNDINFO tmp = { base->idx, 0 };
+ if (overlay1) tmp.iOverlay += ((overlay1->idx & 0xFF) << 18);
+ if (overlay2) tmp.iOverlay += ((overlay2->idx & 0x3F) << 12);
+ if (overlay3) tmp.iOverlay += ((overlay3->idx & 0x3F) << 6);
+ if (overlay4) tmp.iOverlay += (overlay4->idx & 0x3F);
+
+ auto *F = arFI.find(&tmp); // not found - then add
+ if (F == nullptr) {
+ F = new FOUNDINFO(tmp);
+ HICON hIcon = CreateIconFromIndexes(base, overlay1, overlay2, overlay3, overlay4);
+ if (hIcon != nullptr) {
+ F->hRegisteredImage = ExtraIcon_AddIcon(hIcon);
+ DestroyIcon(hIcon);
+ }
+ else F->hRegisteredImage = INVALID_HANDLE_VALUE;
- return F->hRegisteredImage;
+ arFI.insert(F);
+ }
+
+ hImage = F->hRegisteredImage;
+ }
+ }
+
+ ExtraIcon_SetIcon(hExtraIcon, hContact, hImage);
+
+ if (arMonitoredWindows.getIndex((HANDLE)hContact) != -1)
+ SetSrmmIcon(hContact, szMirVer);
+
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// WildCompare
+// Compare 'name' string with 'mask' strings.
+// Masks can contain '*' or '?' wild symbols
+// Asterics '*' symbol covers 'empty' symbol too e.g WildCompare("Tst","T*st*"), returns TRUE
+// In order to handle situation 'at least one any sybol' use "?*" combination:
+// e.g WildCompare("Tst","T?*st*"), returns FALSE, but both WildCompare("Test","T?*st*") and
+// WildCompare("Teeest","T?*st*") return TRUE.
+//
+// Function is case sensitive! so convert input or modify func to use _qtoupper()
+//
+// Mask can contain several submasks. In this case each submask (including first)
+// should start from '|' e.g: "|first*submask|second*mask".
+//
+// Dec 25, 2006 by FYR:
+// Added Exception to masks: the mask "|^mask3|mask2|mask1" means:
+// if NOT according to mask 3 AND (mask1 OR mask2)
+// EXCEPTION should be BEFORE main mask:
+// IF Exception match - the comparing stops as FALSE
+// IF Exception does not match - comparing continue
+// IF Mask match - comparing stops as TRUE
+// IF Mask does not not match comparing continue
+
+BOOL __fastcall WildCompare(LPWSTR wszName, LPWSTR wszMask)
+{
+ if (wszMask == nullptr)
+ return NULL;
+
+ if (*wszMask != L'|')
+ return wildcmpw(wszName, wszMask);
+
+ size_t s = 1, e = 1;
+ LPWSTR wszTemp = (LPWSTR)_alloca(mir_wstrlen(wszMask) * sizeof(wchar_t) + sizeof(wchar_t));
+ BOOL bExcept;
+
+ while (wszMask[e] != L'\0')
+ {
+ s = e;
+ while (wszMask[e] != L'\0' && wszMask[e] != L'|') e++;
+
+ // exception mask
+ bExcept = (*(wszMask + s) == L'^');
+ if (bExcept) s++;
+
+ memcpy(wszTemp, wszMask + s, (e - s) * sizeof(wchar_t));
+ wszTemp[e - s] = L'\0';
+
+ if (wildcmpw(wszName, wszTemp))
+ return !bExcept;
+
+ if (wszMask[e] != L'\0')
+ e++;
+ else
+ return FALSE;
+ }
+ return FALSE;
}
VOID ClearFI()
@@ -608,13 +570,12 @@ VOID ClearFI() arFI.destroy();
}
-/****************************************************************************************
- * ServiceGetClientDescrW
- * MS_FP_GETCLIENTDESCRW service implementation.
- * wParam - LPCWSTR MirVer value
- * lParam - (NULL) unused
- * returns LPCWSTR: client description (do not destroy) or NULL
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// ServiceGetClientDescrW
+// MS_FP_GETCLIENTDESCRW service implementation.
+// wParam - LPCWSTR MirVer value
+// lParam - (NULL) unused
+// returns LPCWSTR: client description (do not destroy) or NULL
static INT_PTR ServiceGetClientDescr(WPARAM wParam, LPARAM)
{
@@ -633,13 +594,12 @@ static INT_PTR ServiceGetClientDescr(WPARAM wParam, LPARAM) return NULL;
}
-/****************************************************************************************
- * ServiceSameClientW
- * MS_FP_SAMECLIENTSW service implementation.
- * wParam - LPWSTR first MirVer value
- * lParam - LPWSTR second MirVer value
- * returns LPCWSTR: client description (do not destroy) if clients are same or NULL
- */
+/////////////////////////////////////////////////////////////////////////////////////////
+// ServiceSameClientW
+// MS_FP_SAMECLIENTSW service implementation.
+// wParam - LPWSTR first MirVer value
+// lParam - LPWSTR second MirVer value
+// returns LPCWSTR: client description (do not destroy) if clients are same or NULL
static INT_PTR ServiceSameClients(WPARAM wParam, LPARAM lParam)
{
@@ -651,10 +611,9 @@ static INT_PTR ServiceSameClients(WPARAM wParam, LPARAM lParam) return (res1 == res2 && res1 != 0) ? res1 : NULL;
}
-/****************************************************************************************
-* OnExtraIconListRebuild
-* Set all registered indexes in array to EMPTY_EXTRA_ICON (unregistered icon)
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// OnExtraIconListRebuild
+// Set all registered indexes in array to EMPTY_EXTRA_ICON (unregistered icon)
static int OnExtraIconListRebuild(WPARAM, LPARAM)
{
@@ -662,9 +621,8 @@ static int OnExtraIconListRebuild(WPARAM, LPARAM) return 0;
}
-/****************************************************************************************
-* OnIconsChanged
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// OnIconsChanged
static int OnIconsChanged(WPARAM, LPARAM)
{
@@ -672,10 +630,9 @@ static int OnIconsChanged(WPARAM, LPARAM) return 0;
}
-/****************************************************************************************
-* OnExtraImageApply
-* Try to get MirVer value from db for contact and if success calls ApplyFingerprintImage
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// OnExtraImageApply
+// Try to get MirVer value from db for contact and if success calls ApplyFingerprintImage
int OnExtraImageApply(WPARAM hContact, LPARAM)
{
@@ -691,10 +648,9 @@ int OnExtraImageApply(WPARAM hContact, LPARAM) return 0;
}
-/****************************************************************************************
-* OnContactSettingChanged
-* if contact settings changed apply new image or remove it
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// OnContactSettingChanged
+// if contact settings changed apply new image or remove it
static int OnContactSettingChanged(WPARAM hContact, LPARAM lParam)
{
@@ -720,10 +676,9 @@ static int OnContactSettingChanged(WPARAM hContact, LPARAM lParam) return 0;
}
-/****************************************************************************************
-* OnSrmmWindowEvent
-* Monitors SRMM window's creation to draw a statusbar icon
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// OnSrmmWindowEvent
+// Monitors SRMM window's creation to draw a statusbar icon
static int OnSrmmWindowEvent(WPARAM uType, LPARAM lParam)
{
@@ -746,10 +701,15 @@ static int OnSrmmWindowEvent(WPARAM uType, LPARAM lParam) return 0;
}
-/****************************************************************************************
-* OnModulesLoaded
-* Hook necessary events here
-*/
+/////////////////////////////////////////////////////////////////////////////////////////
+// OnModulesLoaded
+// Hook necessary events here
+
+static int OnExtraIconClick(WPARAM hContact, LPARAM, LPARAM)
+{
+ CallService(MS_USERINFO_SHOWDIALOG, hContact, NULL);
+ return 0;
+}
int OnModulesLoaded(WPARAM, LPARAM)
{
diff --git a/plugins/FingerprintNG/src/stdafx.h b/plugins/FingerprintNG/src/stdafx.h index d141a71d35..879a74ee0a 100644 --- a/plugins/FingerprintNG/src/stdafx.h +++ b/plugins/FingerprintNG/src/stdafx.h @@ -129,11 +129,6 @@ void UnregisterCustomIcons(); int OnOptInitialise(WPARAM wParam, LPARAM lParam);
int OnExtraImageApply(WPARAM wParam, LPARAM lParam);
-HICON __fastcall CreateJoinedIcon(HICON hBottom, HICON hTop);
-HBITMAP __inline CreateBitmap32(int cx, int cy);
-HBITMAP __fastcall CreateBitmap32Point(int cx, int cy, LPVOID* bits);
-HANDLE __fastcall GetIconIndexFromFI(LPTSTR szMirVer);
-
BOOL __fastcall WildCompare(LPWSTR name, LPWSTR mask);
void RegisterIcons();
|