diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-10 16:02:43 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-10 16:02:43 +0000 |
commit | eccb6b6709bc39d512e14e420d2ba3bd1c4ccbd4 (patch) | |
tree | d405a6e624e88e8171ab2c5f9ddc890ae0d4086e /src/modules/netlib/netliblog.cpp | |
parent | 3755b0d6dff0b36f11e2de4841130c75394c91bc (diff) |
- log file path gets expanded;
- log file name can't be changed on the flow
git-svn-id: http://svn.miranda-ng.org/main/trunk@8546 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/netlib/netliblog.cpp')
-rw-r--r-- | src/modules/netlib/netliblog.cpp | 109 |
1 files changed, 58 insertions, 51 deletions
diff --git a/src/modules/netlib/netliblog.cpp b/src/modules/netlib/netliblog.cpp index 21c0bf6231..a1dbd871d9 100644 --- a/src/modules/netlib/netliblog.cpp +++ b/src/modules/netlib/netliblog.cpp @@ -34,29 +34,55 @@ extern HANDLE hConnectionHeaderMutex; #define TIMEFORMAT_MILLISECONDS 2
#define TIMEFORMAT_MICROSECONDS 3
struct {
- HWND hwndOpts;
- int toOutputDebugString;
- int toFile;
- int toLog;
- TCHAR *szFile;
- TCHAR *szUserFile;
- int timeFormat;
- int showUser;
- int dumpSent, dumpRecv, dumpProxy, dumpSsl;
- int textDumps, autoDetectText;
+ HWND hwndOpts;
+ int toOutputDebugString;
+ int toFile;
+ int toLog;
+ int timeFormat;
+ int showUser;
+ int dumpSent, dumpRecv, dumpProxy, dumpSsl;
+ int textDumps, autoDetectText;
+ CMString tszFile, tszUserFile;
}
-logOptions = {0};
+static logOptions = { 0 };
-typedef struct {
+struct LOGMSG
+{
const char* pszHead;
const char* pszMsg;
-} LOGMSG;
+};
static __int64 mirandaStartTime, perfCounterFreq;
static int bIsActive = TRUE;
static HANDLE hLogEvent = NULL;
static HANDLE hLogger = NULL;
+static void InitLog()
+{
+ if (hLogger) {
+ mir_closeLog(hLogger);
+ hLogger = NULL;
+ }
+
+ if (!logOptions.toFile)
+ return;
+
+ ptrT szBuf(db_get_tsa(NULL, "Netlib", "File"));
+ if (szBuf) {
+ logOptions.tszUserFile = szBuf;
+
+ TCHAR path[MAX_PATH];
+ PathToAbsoluteT(VARST(szBuf), path);
+ logOptions.tszFile = path;
+ }
+ else {
+ logOptions.tszUserFile = _T("%miranda_logpath%\\netlog.txt");
+ logOptions.tszFile = Utils_ReplaceVarsT(logOptions.tszUserFile);
+ }
+
+ hLogger = mir_createLog("Netlib", LPGENT("Standard netlib log"), logOptions.tszFile, 0);
+}
+
static const TCHAR* szTimeFormats[] =
{
LPGENT("No times"),
@@ -87,15 +113,13 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa CheckDlgButton(hwndDlg, IDC_SHOWNAMES, logOptions.showUser ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_TOOUTPUTDEBUGSTRING, logOptions.toOutputDebugString ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_TOFILE, logOptions.toFile ? BST_CHECKED : BST_UNCHECKED);
- SetDlgItemText(hwndDlg, IDC_FILENAME, logOptions.szUserFile);
- SetDlgItemText(hwndDlg, IDC_PATH, logOptions.szFile);
+ SetDlgItemText(hwndDlg, IDC_FILENAME, logOptions.tszUserFile);
+ SetDlgItemText(hwndDlg, IDC_PATH, logOptions.tszFile);
CheckDlgButton(hwndDlg, IDC_SHOWTHISDLGATSTART, db_get_b(NULL, "Netlib", "ShowLogOptsAtStart", 0) ? BST_CHECKED : BST_UNCHECKED);
{
- DBVARIANT dbv;
- if (!db_get_s(NULL, "Netlib", "RunAtStart", &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_RUNATSTART, dbv.pszVal);
- db_free(&dbv);
- }
+ ptrA szRun(db_get_sa(NULL, "Netlib", "RunAtStart"));
+ if (szRun)
+ SetDlgItemTextA(hwndDlg, IDC_RUNATSTART, szRun);
TVINSERTSTRUCT tvis = { 0 };
HWND hwndFilter = GetDlgItem(hwndDlg, IDC_FILTER);
@@ -190,11 +214,13 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa db_set_b(NULL, "Netlib", "ShowLogOptsAtStart", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWTHISDLGATSTART));
GetWindowText(GetDlgItem(hwndDlg, IDC_FILENAME), str, MAX_PATH);
- replaceStrT(logOptions.szUserFile, str);
+ logOptions.tszUserFile = rtrimt(str);
+ db_set_ts(NULL, "Netlib", "File", str);
GetWindowText(GetDlgItem(hwndDlg, IDC_PATH), str, MAX_PATH);
- replaceStrT(logOptions.szFile, str);
- db_set_ts(NULL, "Netlib", "File", logOptions.szFile);
+ logOptions.tszFile = rtrimt(str);
+
+ InitLog();
db_set_b(NULL, "Netlib", "DumpRecv", logOptions.dumpRecv = IsDlgButtonChecked(hwndDlg, IDC_DUMPRECV));
db_set_b(NULL, "Netlib", "DumpSent", logOptions.dumpSent = IsDlgButtonChecked(hwndDlg, IDC_DUMPSENT));
@@ -326,9 +352,9 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam) OutputDebugStringA("\n");
}
- if (logOptions.toFile && logOptions.szFile[0]) {
+ if (logOptions.toFile && !logOptions.tszFile.IsEmpty()) {
size_t len = strlen(pszMsg);
- mir_writeLogA(hLogger, "%s%s%s", szHead, pszMsg, pszMsg[len - 1] == '\n' ? "" : "\r\n");
+ mir_writeLogA(hLogger, "%s%s%s", szHead, pszMsg, pszMsg[len-1] == '\n' ? "" : "\r\n");
}
LOGMSG logMsg = { szHead, pszMsg };
@@ -380,7 +406,7 @@ void NetlibDumpData(NetlibConnection *nlc, PBYTE buf, int len, int sent, int fla return;
// Check user's log settings
- if (!(logOptions.toOutputDebugString || GetSubscribersCount(hLogEvent) != 0 || (logOptions.toFile && logOptions.szFile[0])))
+ if (!(logOptions.toOutputDebugString || GetSubscribersCount(hLogEvent) != 0 || (logOptions.toFile && !logOptions.tszFile.IsEmpty())))
return;
if ((sent && !logOptions.dumpSent) || (!sent && !logOptions.dumpRecv))
return;
@@ -500,33 +526,16 @@ void NetlibLogInit(void) logOptions.toFile = db_get_b(NULL, "Netlib", "ToFile", 0);
logOptions.toLog = db_get_dw(NULL, "Netlib", "NLlog", 1);
- DBVARIANT dbv;
- if (!db_get_ts(NULL, "Netlib", "File", &dbv)) {
- logOptions.szUserFile = mir_tstrdup(dbv.ptszVal);
-
- TCHAR path[MAX_PATH];
- PathToAbsoluteT( VARST(dbv.ptszVal), path);
- logOptions.szFile = mir_tstrdup(path);
-
- db_free(&dbv);
- }
- else {
- logOptions.szUserFile = mir_tstrdup(_T("%miranda_logpath%\\netlog.txt"));
- logOptions.szFile = Utils_ReplaceVarsT(logOptions.szUserFile);
- }
-
- hLogger = mir_createLog("Netlib", LPGENT("Standard netlib log"), logOptions.szFile, 0);
+ InitLog();
if (db_get_b(NULL, "Netlib", "ShowLogOptsAtStart", 0))
NetlibLogShowOptions();
- if (!db_get_ts(NULL, "Netlib", "RunAtStart", &dbv)) {
- if (dbv.ptszVal[0]) {
- STARTUPINFO si = { sizeof(si) };
- PROCESS_INFORMATION pi;
- CreateProcess(NULL, dbv.ptszVal, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
- }
- db_free(&dbv);
+ ptrT szBuf(db_get_tsa(NULL, "Netlib", "RunAtStart"));
+ if (szBuf) {
+ STARTUPINFO si = { sizeof(si) };
+ PROCESS_INFORMATION pi;
+ CreateProcess(NULL, szBuf, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
}
}
@@ -536,6 +545,4 @@ void NetlibLogShutdown(void) DestroyHookableEvent(hLogEvent); hLogEvent = NULL;
if (IsWindow(logOptions.hwndOpts))
DestroyWindow(logOptions.hwndOpts);
- mir_free(logOptions.szFile);
- mir_free(logOptions.szUserFile);
}
|