#include <Windows.h>
#include <string>
#include <ctime>
Go to the source code of this file.
◆ FileExists()
| bool FileExists |
( |
const char * |
filename | ) |
|
Definition at line 33 of file utils.cpp.
33 {
34 HANDLE hFile = CreateFileA(filename,
35 GENERIC_READ,
36 FILE_SHARE_READ,
37 NULL,
38 OPEN_EXISTING,
39 FILE_ATTRIBUTE_NORMAL,
40 NULL);
41
42 if (hFile == INVALID_HANDLE_VALUE) {
43 return false;
44 }
45
46 CloseHandle(hFile);
47 return true;
48}
◆ FormatTime()
| std::string FormatTime |
( |
const std::time_t & |
time | ) |
|
Definition at line 87 of file utils.cpp.
87 {
88 std::tm timeinfo;
89 localtime_s(&timeinfo, &time);
90
91 char buffer[80];
92 std::strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &timeinfo);
93
94 return std::string(buffer);
95}
Referenced by CleanUpProtobufMessage().
◆ GetBaseName()
| std::string GetBaseName |
( |
const std::string & |
path | ) |
|
Definition at line 82 of file utils.cpp.
82 {
83 const char* fileName = PathFindFileNameA(path.c_str());
84 return std::string(fileName);
85}
◆ GetCurrentPath()
| std::string GetCurrentPath |
( |
| ) |
|
◆ IsRunningAsAdmin()
| bool IsRunningAsAdmin |
( |
| ) |
|
Definition at line 9 of file utils.cpp.
9 {
11 PSID adminGroup = NULL;
12
13
14 SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
15 if (AllocateAndInitializeSid(
16 &NtAuthority,
17 2,
18 SECURITY_BUILTIN_DOMAIN_RID,
19 DOMAIN_ALIAS_RID_ADMINS,
20 0, 0, 0, 0, 0, 0,
21 &adminGroup)) {
22
23
24 if (!CheckTokenMembership(NULL, adminGroup, &isAdmin)) {
25 isAdmin = FALSE;
26 }
27 FreeSid(adminGroup);
28 }
29
30 return isAdmin != FALSE;
31}
Referenced by WinMain().
◆ ToLower()
| std::string ToLower |
( |
std::string |
str | ) |
|
Definition at line 62 of file utils.cpp.
62 {
63 std::transform(str.begin(), str.end(), str.begin(),
64 [](unsigned char c) { return std::tolower(c); });
65 return str;
66}
◆ ToString()
| std::string ToString |
( |
const std::wstring & |
wstr | ) |
|
Definition at line 50 of file utils.cpp.
51{
52 if (wstr.empty())
53 {
54 return std::string();
55 }
56 int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
57 std::string str(size_needed, 0);
58 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL);
59 return str;
60}
Referenced by DisplayEventInfo().