summaryrefslogtreecommitdiff
path: root/plugins/Ping/src/log.cpp
blob: ea4ac56f185381081057f4be26f31a3cf84f69f1 (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
59
#include "stdafx.h"

INT_PTR Log(WPARAM wParam, LPARAM) {

	wchar_t 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, nullptr, tbuf, 512);
	GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, nullptr, dbuf, 512);

	wchar_t *line = (wchar_t *)wParam;

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

	return 0;
}

INT_PTR GetLogFilename(WPARAM wParam, LPARAM lParam) {
	DBVARIANT dbv;
	wchar_t *filename = (wchar_t *)lParam;
	if (db_get_ws(0, PLUG, "LogFilename", &dbv)) {
		Profile_GetPathW(wParam, filename);
		mir_wstrncat(filename, L"\\ping_log.txt", wParam - mir_wstrlen(filename));
	}
	else {
		mir_wstrncpy(filename, dbv.ptszVal, wParam);
		db_free(&dbv);
	}

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

	return 0;
}

INT_PTR SetLogFilename(WPARAM, LPARAM lParam) {
	db_set_ws(0, PLUG, "LogFilename", (wchar_t *)lParam);
	return 0;
}

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