summaryrefslogtreecommitdiff
path: root/protocols/GTalkExt/src/popups.cpp
blob: 0f0b6c2d044efc2e773127b5e342cafe5d12bb93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//***************************************************************************************
//
//   Google Extension plugin for the Miranda IM's Jabber protocol
//   Copyright (c) 2011 bems@jabber.org, George Hazan (ghazan@jabber.ru)
//
//   This program is free software; you can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//***************************************************************************************

#include "stdafx.h"
#include "popups.h"
#include "options.h"

static const LPTSTR YAPP_WND_CLASS1 = _T("YAPPYAPPWindowClass");
static const LPTSTR YAPP_WND_CLASS2 = _T("YAPPWinClass");

extern BOOL isOriginalPopups;

LRESULT CALLBACK PopupHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	PCWPRETSTRUCT cs = (PCWPRETSTRUCT)lParam;
	if ((HC_ACTION == nCode) &&
		(WM_CREATE == cs->message) &&
		(-1 != cs->lResult) &&
		ServiceExists(MS_POPUP_GETCONTACT)) {

			// with YAPP we can't call MS_POPUP_GETCONTACT on a random window
			TCHAR ClassName[32];
			GetClassName(cs->hwnd, ClassName, sizeof(ClassName) / sizeof(TCHAR));
			if (isOriginalPopups ||
				!lstrcmp(YAPP_WND_CLASS1, ClassName) ||
				!lstrcmp(YAPP_WND_CLASS2, ClassName)) {

					HANDLE hContact = (HANDLE)CallService(MS_POPUP_GETCONTACT, (WPARAM)cs->hwnd, 0);
					if (hContact != (HANDLE)-1 &&
						hContact != (HANDLE)0x80000000 &&
						DBGetContactSettingByte(hContact, SHORT_PLUGIN_NAME, PSEUDOCONTACT_FLAG, 0)) {
							LPCSTR proto = (LPCSTR)GetContactProto(hContact);
							DWORD checkboxes = ReadCheckboxes(0, proto);
							if (ReadCheckbox(0, IDC_PSEUDOCONTACTENABLED, checkboxes) &&
								ReadCheckbox(0, IDC_SUPRESSFOREIGN, checkboxes))
									PostMessage(cs->hwnd, WM_CLOSE, 0, 0);
					}
			}
	}
	return CallNextHookEx(0, nCode, wParam, lParam);
}

typedef PLUGININFOEX* (MIRANDAPLUGININFOEX) (DWORD mirandaVersion);

static GUID POPUP_GUID1 = {0x26a9125d, 0x7863, 0x4e01, {0xaf, 0xe, 0xd1, 0x4e, 0xf9, 0x5c, 0x50, 0x54}};
static GUID POPUP_GUID2 = {0x26a9125d, 0x7863, 0x4e01, {0xaf, 0xe, 0xd1, 0x4e, 0xf9, 0x5c, 0x50, 0x53}};

DWORD g_mirandaVersion = 0;

BOOL IsOriginalPopupModule(HMODULE hMod)
{
	MIRANDAPLUGININFOEX *MirandaPluginInfoEx = (MIRANDAPLUGININFOEX*)GetProcAddress(hMod, "MirandaPluginInfoEx");
	if (!MirandaPluginInfoEx) return FALSE;

	PLUGININFOEX *PluginInfoEx = MirandaPluginInfoEx(g_mirandaVersion);
	if (!PluginInfoEx) return FALSE;

	GUID *guid1 = (GUID*)&PluginInfoEx->uuid;
	GUID *guid2 = (GUID*)&POPUP_GUID1;
	GUID *guid3 = (GUID*)&POPUP_GUID2;
	return (IsEqualGUID(*guid1, *guid2) || IsEqualGUID(*guid1, *guid3));
}

extern BOOL isOriginalPopups;

void DetectPopupModule()
{
	DWORD bytesNeeded;
	if (!EnumProcessModules(GetCurrentProcess(), NULL, 0, &bytesNeeded))
		return;

	HMODULE *mods = (HMODULE*)malloc(bytesNeeded);
	__try {
		if (!EnumProcessModules(GetCurrentProcess(), mods, bytesNeeded, &bytesNeeded))
			return;

		for (DWORD i = 0; i < (bytesNeeded / sizeof(HMODULE)); i++)
			if (IsOriginalPopupModule(mods[i])) {
				isOriginalPopups = TRUE;
				break;
			}
	}
	__finally {
		free(mods);
	}
}