summaryrefslogtreecommitdiff
path: root/plugins/Ping/src/log.cpp
blob: c95c49a91044d644a49147dceaa028e80326e80b (plain)
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
#include "common.h"

INT_PTR Log(WPARAM wParam, LPARAM lParam) {

	TCHAR buf[1024], tbuf[512], dbuf[512];
	CallService(PLUG "/GetLogFilename", (WPARAM)1024, (LPARAM)buf);

	//char TBcapt[255];
	SYSTEMTIME systime;
	
	GetLocalTime(&systime);

	GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, tbuf, 512);
	GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, dbuf, 512);

	char *line = (char *)wParam;

	FILE *f = _tfopen(buf, _T("a+"));
	if(f) {
		if(options.log_csv) {
			fprintf(f, "%s, %s, %s\n", dbuf, tbuf, line);
		} else {
			fprintf(f, "%s, %s: %s\n", dbuf, tbuf, line);
		}
		fclose(f);
	}

	return 0;
}

INT_PTR GetLogFilename(WPARAM wParam, LPARAM lParam) {
	DBVARIANT dbv;
	char *filename = (char *)lParam;
	if(DBGetContactSetting(0, PLUG, "LogFilename", &dbv)) {
		CallService(MS_DB_GETPROFILEPATH, (WPARAM)wParam, (LPARAM)filename);
		strcat(filename, "\\");
		strcat(filename, "ping_log.txt");
	} else {
		strncpy(filename, dbv.pszVal, wParam);
		DBFreeVariant(&dbv);
	}

	((char *)lParam)[wParam - 1] = 0;

	return 0;
}

INT_PTR SetLogFilename(WPARAM wParam, LPARAM lParam) {
	DBWriteContactSettingString(0, PLUG, "LogFilename", (char *)lParam);
	return 0;
}

INT_PTR ViewLogData(WPARAM wParam, LPARAM lParam) {
	char buf[1024];
	CallService(PLUG "/GetLogFilename", (WPARAM)MAX_PATH, (LPARAM)buf);
	return (INT_PTR)ShellExecute((HWND)wParam, _T("edit"), buf, _T(""), _T(""), SW_SHOW);	
}