From bebfb51465b364d5673a3f555655213dbff0b2c6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 31 Mar 2015 11:55:37 +0000 Subject: Non-IM Contact: - fix for a crash on exit; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@12573 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Non-IM Contact/src/timer.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'plugins/Non-IM Contact/src/timer.cpp') diff --git a/plugins/Non-IM Contact/src/timer.cpp b/plugins/Non-IM Contact/src/timer.cpp index fad1057038..9d81dbd70b 100644 --- a/plugins/Non-IM Contact/src/timer.cpp +++ b/plugins/Non-IM Contact/src/timer.cpp @@ -1,6 +1,6 @@ #include "commonheaders.h" -UINT_PTR timerId; +static UINT_PTR timerId = 0; //===================================================== // Name : timerProc @@ -9,11 +9,11 @@ UINT_PTR timerId; // Description : called when the timer interval occurs //===================================================== -void timerFunc(void *di) +void timerFunc(void *di) { char text[512], fn[16], szFileName[MAX_PATH], temp[MAX_PATH]; - int timerCount = db_get_w(NULL, MODNAME, "timerCount",1)+1; + int timerCount = db_get_w(NULL, MODNAME, "timerCount", 1) + 1; if (LCStatus == ID_STATUS_OFFLINE) { killTimer(); @@ -22,9 +22,9 @@ void timerFunc(void *di) db_set_w(NULL, MODNAME, "timerCount", (WORD)timerCount); /* update the web pages*/ - for (int i=0; ;i++) { + for (int i = 0;; i++) { mir_snprintf(fn, SIZEOF(fn), "fn%d", i); - if (!db_get_static(NULL, MODNAME, fn, text)) + if (!db_get_static(NULL, MODNAME, fn, text, SIZEOF(text))) break; if (!strncmp("http://", text, strlen("http://")) || !strncmp("https://", text, strlen("https://"))) { @@ -43,7 +43,7 @@ void timerFunc(void *di) for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) { int timer = db_get_w(hContact, MODNAME, "Timer", 15); if (timer && !(timerCount % timer)) - if (db_get_static(hContact, MODNAME, "Name", text)) + if (db_get_static(hContact, MODNAME, "Name", text, SIZEOF(text))) replaceAllStrings(hContact); } } @@ -51,7 +51,7 @@ void timerFunc(void *di) void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD) { // new thread for the timer... - forkthread(timerFunc, 0, 0); + forkthread(timerFunc, 0, 0); } //===================================================== @@ -76,7 +76,10 @@ int startTimer(int interval) int killTimer() { - db_set_w(NULL, MODNAME, "timerCount",0); - KillTimer(NULL,timerId); + if (timerId != 0) { + db_set_w(NULL, MODNAME, "timerCount", 0); + KillTimer(NULL, timerId); + timerId = 0; + } return 0; } -- cgit v1.2.3