7 DWORD attributes = GetFileAttributesW(path.c_str());
8 if (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
13 size_t pos = path.find_last_of(L
"\\/");
14 if (pos != std::wstring::npos) {
21 if (!CreateDirectoryW(path.c_str(), NULL)) {
22 DWORD error = GetLastError();
23 if (error != ERROR_ALREADY_EXISTS) {
24 std::wcerr << L
"Failed to create directory: " << path << L
". Error code: " << error << std::endl;
33 static DWORD currentFileNumber = 0;
34 static HANDLE hFile = INVALID_HANDLE_VALUE;
36 std::wstring fullPath;
41 std::wcerr << L
"Failed to create log directory" << std::endl;
45 if (hFile == INVALID_HANDLE_VALUE || GetFileSize(hFile, NULL) >=
MAX_FILE_SIZE) {
46 if (hFile != INVALID_HANDLE_VALUE) {
51 std::wostringstream oss;
53 if (currentFileNumber > 0) {
54 oss << currentFileNumber;
65 FILE_ATTRIBUTE_NORMAL,
69 if (hFile == INVALID_HANDLE_VALUE) {
70 std::wcerr << L
"Failed to open log file: " << fullPath << std::endl;
75 SetFilePointer(hFile, 0, NULL, FILE_END);
78 if (!WriteFile(hFile, message.c_str(), message.length() *
sizeof(
char), &bytesWritten, NULL)) {
79 std::wcerr << L
"Failed to write to log file" << std::endl;