forked from PopRe/Pop-World-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.cpp
72 lines (49 loc) · 1.24 KB
/
log.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Alacn
http://alacn.dnsalias.org:8080/
*/
#include "std.h"
#include "popedt.h"
#include "user_storage.h"
#include "log.h"
HANDLE hLog = INVALID_HANDLE_VALUE;
char szLogFilePath[MAX_PATH];
long LogCreate()
{
if(hLog != INVALID_HANDLE_VALUE) return -1;
if(!GetApplicationUserDataFilePath(LOG_FILE, szLogFilePath)) return -1;
hLog = CreateFile(szLogFilePath, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hLog == INVALID_HANDLE_VALUE) return -1;
LogWrite(LOG_TITLE);
sprintf(str, LOG_INFO, __DATE__, __TIME__, POPEDT_VERSION);
LogWrite(str);
SYSTEMTIME time;
GetSystemTime(&time);
sprintf(str, LOG_TIME, time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond);
LogWrite(str);
return S_OK;
}
long LogClose()
{
if(hLog == INVALID_HANDLE_VALUE) return -1;
LogWrite(LOG_END);
if(!CloseHandle(hLog)) return -1;
return S_OK;
}
long LogWrite(char *str)
{
#ifdef _DEBUG
OutputDebugString(str);
OutputDebugString("\n");
#endif
if(hLog == INVALID_HANDLE_VALUE) return -1;
int len = strlen(str);
dwRW = 0;
WriteFile(hLog, str, len, &dwRW, 0);
if(dwRW != len) return -1;
dwRW = 0;
WriteFile(hLog, "\r\n", 2, &dwRW, 0);
if(dwRW != 2) return -1;
return S_OK;
}