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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
#include "common.h"
#include "version.h"
#include "mirandaInterface.h"
//Miranda - handle from DllMain
HINSTANCE hInst;
//Miranda - Langpack
int hLangpack;
//Miranda - HANDLE to hooked protocols ACK
HANDLE hProtoAck;
//popup classes handles
HANDLE hPopupNotify;
HANDLE hPopupError;
//main add-on's object
CMirfoxMiranda mirfoxMiranda;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
__DESCRIPTION,
__AUTHOR,
__AUTHOREMAIL,
__COPYRIGHT,
__AUTHORWEB,
UNICODE_AWARE,
#ifdef _X64
{ 0xcb5d6b27, 0xb8e0, 0x484c, { 0x87, 0xb0, 0x4d, 0x46, 0x91, 0xa9, 0x4d, 0xee } }
#else
{ 0xe99a09b2, 0xe05b, 0x4633, { 0xaa, 0x3a, 0x5c, 0x83, 0xef, 0x1c, 0xba, 0xb6 } }
#endif
};
extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
hInst = hinstDLL;
return TRUE;
}
int lowVersionUserAnswer = -1;
extern "C" __declspec (dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) {
if(mirfoxMiranda.onMirandaPluginInfoExCheck(mirandaVersion)){
return &pluginInfo;
} else {
if (lowVersionUserAnswer == -1){
lowVersionUserAnswer = MessageBox(NULL
//, mfTranslate(TEXT("mirfox.too.old.miranda"), TEXT("You use old Miranda version, whitch MirFox was not tested. Do You want to load MirFox plugin ?"))
//@langpack: [mirfox.too.old.miranda] U¿ywasz starszej wersji Mirandy, dla której plugin MirFox nie zosta³ przetestowany. Czy chcesz uruchomiæ ten plugin ?
, (LPCWSTR)TEXT("You use old Miranda version, whitch MirFox was not tested. Do You want to load MirFox plugin ?") //TODO - translation crash here
, (LPCWSTR)TEXT("MirFox")
, MB_YESNO | MB_ICONWARNING );
}
if (lowVersionUserAnswer == IDYES){
return &pluginInfo;
} else {
return NULL;
}
}
}
/*
* hook on ME_SYSTEM_MODULESLOADED at Load()
*/
static int onModulesLoaded(WPARAM wParam, LPARAM lParam)
{
//init popup classes
POPUPCLASS puc = {0};
puc.cbSize = sizeof(puc);
puc.flags = PCF_TCHAR;
puc.pszName = "MirFox_Notify";
puc.ptszDescription = MirandaUtils::getInstance()->mfTranslate(LPGENT("mirfox.popup.notify.description"), TEXT("MirFox/Notification"));
puc.colorBack = RGB(173, 206, 247); //light blue
puc.colorText = GetSysColor(COLOR_WINDOWTEXT);
puc.iSeconds = 3;
puc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON_PN));
hPopupNotify = Popup_RegisterClass(&puc);
puc.pszName = "MirFox_Error";
puc.ptszDescription = MirandaUtils::getInstance()->mfTranslate(LPGENT("mirfox.popup.error.description"), TEXT("MirFox/Error"));
puc.colorBack = RGB(255, 128, 128); //light red
puc.colorText = GetSysColor(COLOR_WINDOWTEXT);
puc.iSeconds = 20;
puc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON_PE));
hPopupError = Popup_RegisterClass(&puc);
return 0;
}
static int OnShutdown(WPARAM wParam, LPARAM lParam)
{
Popup_UnregisterClass(hPopupError);
Popup_UnregisterClass(hPopupNotify);
return 0;
}
extern "C" int __declspec(dllexport) Load(void){
HookEvent(ME_SYSTEM_MODULESLOADED, onModulesLoaded);
HookEvent(ME_SYSTEM_SHUTDOWN, OnShutdown);
hProtoAck = HookEvent(ME_PROTO_ACK, MirandaUtils::onProtoAck);
//Ensure that the common control DLL is loaded. needed to use ICC_LISTVIEW_CLASSES control in options TODO move to InitOptions();?
INITCOMMONCONTROLSEX icex = {0};
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
mirfoxMiranda.getMirfoxData().Plugin_Terminated = false;
mirfoxMiranda.getMirfoxData().setPluginState(MFENUM_PLUGIN_STATE_INIT);
mirfoxMiranda.onMirandaInterfaceLoad();
/**MirandaOptions.cpp**/InitOptions();
if (mirfoxMiranda.getMirfoxData().getPluginState() != MFENUM_PLUGIN_STATE_ERROR){
mirfoxMiranda.getMirfoxData().setPluginState(MFENUM_PLUGIN_STATE_WORK);
} /*else {
mirfoxMiranda.onMirandaInterfaceUnload();
DeinitOptions();
} */ //TODO
return 0;
}
extern "C" __declspec (dllexport) int Unload(void) {
MFLogger::getInstance()->log(L"Unload: start");
//wait for csmThread, msgQueueThread and userActionThread's end
mirfoxMiranda.getMirfoxData().Plugin_Terminated = true;
UnhookEvent(hProtoAck);
int counter = 0;
const int UNLOAD_WAIT_TIME = 50; //[ms]
const int MAX_UNLOAD_WAIT_COUNTER = 10; //10 * 50ms = 0,5s
while (mirfoxMiranda.getMirfoxData().workerThreadsCount > 0 ){
MFLogger::getInstance()->log_p(L"Unload: workerThreadsCount=%d > 0, waiting. counter=%d", mirfoxMiranda.getMirfoxData().workerThreadsCount, counter);
SleepEx(UNLOAD_WAIT_TIME, TRUE);
counter++;
}
MFLogger::getInstance()->log_p(L"Unload: workerThreadsCount=%d. counter=%d", mirfoxMiranda.getMirfoxData().workerThreadsCount, counter);
MFLogger::getInstance()->log(L"Unload: last log");
mirfoxMiranda.onMirandaInterfaceUnload();
DeinitOptions();
return 0;
}
|