From 00f7de90210080e231b2f8c2a0bf39c8b0a048ac Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 18 Mar 2013 09:37:22 +0000 Subject: - major design flaw fixed in LastSeen plugin; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@4089 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SeenPlugin/src/main.cpp | 32 +++++++++++++++++------------- plugins/SeenPlugin/src/utils.cpp | 42 +++++++++++++++++++++------------------- plugins/SeenPlugin/src/version.h | 2 +- 3 files changed, 42 insertions(+), 34 deletions(-) (limited to 'plugins/SeenPlugin') diff --git a/plugins/SeenPlugin/src/main.cpp b/plugins/SeenPlugin/src/main.cpp index 101681cb66..650382c8b6 100644 --- a/plugins/SeenPlugin/src/main.cpp +++ b/plugins/SeenPlugin/src/main.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. HINSTANCE hInstance; HANDLE ehmissed = NULL, ehuserinfo = NULL, ehmissed_proto = NULL; +HANDLE g_hShutdownEvent; int hLangpack; @@ -91,6 +92,23 @@ int MainInit(WPARAM wparam,LPARAM lparam) return 0; } +static int OnShutdown(WPARAM, LPARAM) +{ + SetEvent(g_hShutdownEvent); + return 0; +} + +extern "C" __declspec(dllexport) int Load(void) +{ + mir_getLP(&pluginInfo); + + g_hShutdownEvent = CreateEvent(0, TRUE, FALSE, 0); + + HookEvent(ME_SYSTEM_MODULESLOADED, MainInit); + HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown); + return 0; +} + extern "C" __declspec(dllexport) PLUGININFOEX * MirandaPluginInfoEx(DWORD mirandaVersion) { return &pluginInfo; @@ -101,6 +119,7 @@ extern "C" __declspec(dllexport) int Unload(void) if (ehmissed) UnhookEvent(ehmissed); + CloseHandle(g_hShutdownEvent); UninitMenuitem(); return 0; } @@ -110,16 +129,3 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved) hInstance=hinst; return 1; } - -extern "C" __declspec(dllexport) int Load(void) -{ - - mir_getLP(&pluginInfo); - // this isn't required for most events - // but the ME_USERINFO_INITIALISE - // I decided to hook all events after - // everything is loaded because it seems - // to be safer in my opinion - HookEvent(ME_SYSTEM_MODULESLOADED,MainInit); - return 0; -} \ No newline at end of file diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index 0fc11a7c90..8eb1f01f37 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void FileWrite(HANDLE); void HistoryWrite(HANDLE hcontact); +extern HANDLE g_hShutdownEvent; char * courProtoName = 0; /* @@ -675,30 +676,31 @@ static void cleanThread(void *param) { logthread_info* infoParam = (logthread_info*)param; - Sleep(10000); // I hope in 10 secons all logged-in contacts will be listed - - HANDLE hcontact = db_find_first(); - while(hcontact != NULL) { - char *contactProto = GetContactProto(hcontact); - if (contactProto) { - if ( !strncmp(infoParam->sProtoName, contactProto, MAXMODULELABELLENGTH)) { - WORD oldStatus = db_get_w(hcontact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE) | 0x8000; - if (oldStatus > ID_STATUS_OFFLINE) { - if (db_get_w(hcontact,contactProto,"Status",ID_STATUS_OFFLINE)==ID_STATUS_OFFLINE){ - db_set_w(hcontact,S_MOD,"OldStatus",(WORD)(oldStatus|0x8000)); - if (includeIdle)db_set_b(hcontact,S_MOD,"OldIdle",(BYTE)((oldStatus&0x8000)?0:1)); - db_set_w(hcontact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE); + // I hope in 10 secons all logged-in contacts will be listed + if ( WaitForSingleObject(g_hShutdownEvent, 10000) == WAIT_TIMEOUT) { + HANDLE hcontact = db_find_first(); + while(hcontact != NULL) { + char *contactProto = GetContactProto(hcontact); + if (contactProto) { + if ( !strncmp(infoParam->sProtoName, contactProto, MAXMODULELABELLENGTH)) { + WORD oldStatus = db_get_w(hcontact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE) | 0x8000; + if (oldStatus > ID_STATUS_OFFLINE) { + if (db_get_w(hcontact,contactProto,"Status",ID_STATUS_OFFLINE)==ID_STATUS_OFFLINE){ + db_set_w(hcontact,S_MOD,"OldStatus",(WORD)(oldStatus|0x8000)); + if (includeIdle)db_set_b(hcontact,S_MOD,"OldIdle",(BYTE)((oldStatus&0x8000)?0:1)); + db_set_w(hcontact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE); + } } } } + hcontact = db_find_next(hcontact); } - hcontact = db_find_next(hcontact); - } - char *str = (char *)malloc(MAXMODULELABELLENGTH+9); - mir_snprintf(str,MAXMODULELABELLENGTH+8,"OffTime-%s",infoParam->sProtoName); - db_unset(NULL,S_MOD,str); - free(str); + char *str = (char *)malloc(MAXMODULELABELLENGTH+9); + mir_snprintf(str,MAXMODULELABELLENGTH+8,"OffTime-%s",infoParam->sProtoName); + db_unset(NULL,S_MOD,str); + free(str); + } free(infoParam); } @@ -719,7 +721,7 @@ int ModeChange(WPARAM wparam,LPARAM lparam) if ((isetting>ID_STATUS_OFFLINE)&&((WORD)ack->hProcess<=ID_STATUS_OFFLINE)) { //we have just loged-in db_set_dw(NULL, "UserOnline", ack->szModule, GetTickCount()); - if (IsWatchedProtocol(ack->szModule)) { + if (!Miranda_Terminated() && IsWatchedProtocol(ack->szModule)) { logthread_info *info = (logthread_info *)malloc(sizeof(logthread_info)); strncpy(info->sProtoName,courProtoName,MAXMODULELABELLENGTH); info->hContact = 0; diff --git a/plugins/SeenPlugin/src/version.h b/plugins/SeenPlugin/src/version.h index 3160733a93..62449330f6 100644 --- a/plugins/SeenPlugin/src/version.h +++ b/plugins/SeenPlugin/src/version.h @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __MAJOR_VERSION 5 #define __MINOR_VERSION 0 #define __RELEASE_NUM 4 -#define __BUILD_NUM 7 +#define __BUILD_NUM 8 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM -- cgit v1.2.3