From bdf88550d1e2807a9c719259385917ba3d0dd91e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 22 Dec 2014 14:35:27 +0000 Subject: WUMF to use the kernel logger instead of reinventing the wheel git-svn-id: http://svn.miranda-ng.org/main/trunk@11581 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/WhoUsesMyFiles/src/Version.h | 14 ++++++------ plugins/WhoUsesMyFiles/src/wumf.cpp | 38 +++++++++++---------------------- plugins/WhoUsesMyFiles/src/wumf.h | 2 +- plugins/WhoUsesMyFiles/src/wumfplug.cpp | 3 ++- 4 files changed, 23 insertions(+), 34 deletions(-) (limited to 'plugins') diff --git a/plugins/WhoUsesMyFiles/src/Version.h b/plugins/WhoUsesMyFiles/src/Version.h index c61141f928..dbacb3b253 100644 --- a/plugins/WhoUsesMyFiles/src/Version.h +++ b/plugins/WhoUsesMyFiles/src/Version.h @@ -1,14 +1,14 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 1 +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include #define __PLUGIN_NAME "Who Use My Files" #define __FILENAME "WhoUsesMyFiles.dll" -#define __DESCRIPTION "Scans for network users of your shared files and notify you with popups." -#define __AUTHOR "Nikolay Redko" +#define __DESCRIPTION "Scans for network users of your shared files and notify you with popups." +#define __AUTHOR "Nikolay Redko" #define __AUTHOREMAIL "nike000@users.sf.net" -#define __AUTHORWEB "http://miranda-ng.org/p/WhoUsesMyFiles/" -#define __COPYRIGHT "© 2003 Nike" +#define __AUTHORWEB "http://miranda-ng.org/p/WhoUsesMyFiles/" +#define __COPYRIGHT "© 2003 Nike" diff --git a/plugins/WhoUsesMyFiles/src/wumf.cpp b/plugins/WhoUsesMyFiles/src/wumf.cpp index 5e194414b7..034d84f460 100644 --- a/plugins/WhoUsesMyFiles/src/wumf.cpp +++ b/plugins/WhoUsesMyFiles/src/wumf.cpp @@ -8,7 +8,7 @@ static PWumf list = NULL; static PWumf lst = NULL; -HANDLE hLog = INVALID_HANDLE_VALUE; +HANDLE hLogger = NULL; BOOL wumf(); static int DlgResizer(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL *urc) @@ -142,38 +142,26 @@ INT_PTR CALLBACK ConnDlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) void LogWumf(PWumf w) { - TCHAR str[256]; - LPTSTR lpstr; - TCHAR lpDateStr[20]; - TCHAR lpTimeStr[20]; - SYSTEMTIME time; - DWORD bytes; - if (!WumfOptions.LogFolders && (w->dwAttr & FILE_ATTRIBUTE_DIRECTORY)) return; - if (hLog == INVALID_HANDLE_VALUE || hLog == NULL) - { - hLog = CreateFile(WumfOptions.LogFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hLog == INVALID_HANDLE_VALUE) - { - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpstr, 0, NULL); - mir_sntprintf(str, SIZEOF(str), _T("Can't open log file %s\nError:%s"), WumfOptions.LogFile, lpstr); - LocalFree(lpstr); - MessageBox( NULL, str, TranslateT("Error opening file"), MB_OK | MB_ICONSTOP); + if (hLogger == NULL) { + hLogger = mir_createLog("wumf", _T("WhoIsUsingMyFiles log file"), WumfOptions.LogFile, 0); + if (hLogger == NULL) { + TCHAR str[256]; + mir_sntprintf(str, SIZEOF(str), _T("Can't open log file %s"), WumfOptions.LogFile); + MessageBox(NULL, str, TranslateT("Error opening file"), MB_OK | MB_ICONSTOP); WumfOptions.LogToFile = FALSE; + return; } } + + SYSTEMTIME time; GetLocalTime(&time); + + TCHAR lpDateStr[20], lpTimeStr[20]; GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, lpDateStr, 20); GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &time, NULL, lpTimeStr, 20); - mir_sntprintf(str, SIZEOF(str), _T("%s %s %20s\t%s\r\n\0"), lpDateStr, lpTimeStr, w->szUser, w->szPath); - SetFilePointer(hLog, 0, NULL, FILE_END); - WriteFile(hLog, str, (DWORD)_tcslen(str), &bytes, NULL); + mir_writeLogT(hLogger, _T("%s %s %20s\t%s\r\n"), lpDateStr, lpTimeStr, w->szUser, w->szPath); } BOOL wumf() diff --git a/plugins/WhoUsesMyFiles/src/wumf.h b/plugins/WhoUsesMyFiles/src/wumf.h index 104e6d50a2..e0707f8481 100644 --- a/plugins/WhoUsesMyFiles/src/wumf.h +++ b/plugins/WhoUsesMyFiles/src/wumf.h @@ -114,7 +114,7 @@ BOOL del_marked(PWumf* l); extern WUMF_OPTIONS WumfOptions; extern HINSTANCE hInst; -extern HANDLE hLog; +extern HANDLE hLogger; static HANDLE hWumfBut; extern PWumf list; diff --git a/plugins/WhoUsesMyFiles/src/wumfplug.cpp b/plugins/WhoUsesMyFiles/src/wumfplug.cpp index f2daa8b25f..7febec32e0 100644 --- a/plugins/WhoUsesMyFiles/src/wumfplug.cpp +++ b/plugins/WhoUsesMyFiles/src/wumfplug.cpp @@ -530,7 +530,8 @@ extern "C" __declspec(dllexport) int Load(void) extern "C" __declspec(dllexport) int Unload(void) { KillTimer(NULL, 777); - CloseHandle(hLog); + if (hLogger) + mir_closeLog(hLogger); FreeAll(); return 0; } -- cgit v1.2.3