|
8 | 8 |
|
9 | 9 | using namespace std; |
10 | 10 |
|
11 | | -Registry::WindowsBit Registry::GetWindowsBit() |
| 11 | +namespace Windows |
12 | 12 | { |
13 | | - HKEY rKey; |
14 | | - WindowsBit windowsBit; |
15 | | - |
16 | | - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WOW6432Node"), 0, KEY_QUERY_VALUE, &rKey) == ERROR_SUCCESS) |
17 | | - windowsBit = WindowsBit::Win64; |
18 | | - else |
19 | | - windowsBit = WindowsBit::Win32; |
20 | | - |
21 | | - RegCloseKey(rKey); |
22 | | - |
23 | | - return windowsBit; |
24 | | -} |
25 | | - |
26 | | -string Registry::GetTextFromKeyA(const Registry::RootFolder Folder, const char* pPathToFolder, const char* pKeyName) |
27 | | -{ |
28 | | - HKEY rKey; |
29 | | - DWORD Size = 256; |
30 | | - TCHAR Reget[Size] = { 0 }; |
31 | | - |
32 | | - switch (Folder) |
| 13 | + Registry::WindowsBit Registry::GetWindowsBit() |
33 | 14 | { |
34 | | - case Registry::RootFolder::HKCU : |
35 | | - RegOpenKeyExA(HKEY_CURRENT_USER, pPathToFolder, 0, KEY_READ, &rKey); |
36 | | - break; |
37 | | - |
38 | | - case Registry::RootFolder::HKLM : |
39 | | - RegOpenKeyExA(HKEY_LOCAL_MACHINE, pPathToFolder, 0, KEY_READ, &rKey); |
40 | | - break; |
41 | | - } |
| 15 | + HKEY rKey; |
| 16 | + WindowsBit windowsBit; |
42 | 17 |
|
43 | | - RegQueryValueExA(rKey, pKeyName, NULL, NULL, (LPBYTE)&Reget, &Size); |
44 | | - RegCloseKey(rKey); |
45 | | - |
46 | | - string returnValue(Reget); |
47 | | - returnValue.shrink_to_fit(); |
48 | | - |
49 | | - return returnValue; |
50 | | -} |
| 18 | + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WOW6432Node"), 0, KEY_QUERY_VALUE, &rKey) == ERROR_SUCCESS) |
| 19 | + windowsBit = WindowsBit::Win64; |
| 20 | + else |
| 21 | + windowsBit = WindowsBit::Win32; |
51 | 22 |
|
52 | | -wstring Registry::GetTextFromKeyW(const Registry::RootFolder Folder, const wchar_t* pPathToFolder, const wchar_t* pKeyName) |
53 | | -{ |
54 | | - HKEY rKey; |
55 | | - DWORD Size = 256; |
56 | | - WCHAR Reget[Size] = { 0 }; |
| 23 | + RegCloseKey(rKey); |
57 | 24 |
|
58 | | - switch (Folder) |
59 | | - { |
60 | | - case Registry::RootFolder::HKCU : |
61 | | - RegOpenKeyExW(HKEY_CURRENT_USER, pPathToFolder, 0, KEY_READ, &rKey); |
62 | | - break; |
63 | | - |
64 | | - case Registry::RootFolder::HKLM : |
65 | | - RegOpenKeyExW(HKEY_LOCAL_MACHINE, pPathToFolder, 0, KEY_READ, &rKey); |
66 | | - break; |
| 25 | + return windowsBit; |
67 | 26 | } |
68 | 27 |
|
69 | | - RegQueryValueExW(rKey, pKeyName, NULL, NULL, (LPBYTE)&Reget, &Size); |
70 | | - RegCloseKey(rKey); |
71 | | - |
72 | | - wstring returnValue(Reget); |
73 | | - returnValue.shrink_to_fit(); |
74 | | - |
75 | | - return returnValue; |
76 | | -} |
77 | | - |
78 | | -wstring Registry::GetPathToGame(const Games game) |
79 | | -{ |
80 | | - wstring Key = L"InstallPath"; |
81 | | - wstring Path = Registry::PATHS_TO_GAMES.find(game)->second.find(GetWindowsBit())->second; |
82 | | - return GetTextFromKeyW(Registry::RootFolder::HKLM, Path.c_str(), Key.c_str()); |
83 | | -} |
84 | | - |
85 | | -string Registry::ToString(Games game) |
86 | | -{ |
87 | | - string returnValue; |
88 | | - |
89 | | - switch (game) |
| 28 | + string Registry::GetTextFromKeyA(const Registry::RootFolder Folder, const char* pPathToFolder, const char* pKeyName) |
90 | 29 | { |
91 | | - case Games::Generals: |
92 | | - returnValue = "Generals"; |
93 | | - break; |
94 | | - case Games::GeneralsZeroHour: |
95 | | - returnValue = "Generals Zero Hour"; |
96 | | - break; |
97 | | - } |
98 | | - |
99 | | - return returnValue; |
100 | | -} |
101 | | - |
102 | | -QString Registry::ToQString(Games game) { return QString::fromStdString(Registry::ToString(game)); } |
103 | | - |
104 | | -bool Registry::IsWindow64bit() { return GetWindowsBit() == WindowsBit::Win64; } |
105 | | -bool Registry::IsWindow32bit() { return GetWindowsBit() == WindowsBit::Win32; } |
106 | | - |
107 | | -#pragma region Logger methods |
108 | | - string Registry::GetCurrentUserLanguage() |
109 | | - { |
110 | | - const char Path[] = {"Control Panel\\International"}; |
111 | | - const char Key[] = {"LocaleName"}; |
112 | | - return GetTextFromKeyA(Registry::RootFolder::HKCU, &Path[0], &Key[0]).substr(0, 2); |
| 30 | + HKEY rKey; |
| 31 | + DWORD Size = 256; |
| 32 | + TCHAR Reget[Size] = { 0 }; |
| 33 | + |
| 34 | + switch (Folder) |
| 35 | + { |
| 36 | + case Registry::RootFolder::HKCU : |
| 37 | + RegOpenKeyExA(HKEY_CURRENT_USER, pPathToFolder, 0, KEY_READ, &rKey); |
| 38 | + break; |
| 39 | + |
| 40 | + case Registry::RootFolder::HKLM : |
| 41 | + RegOpenKeyExA(HKEY_LOCAL_MACHINE, pPathToFolder, 0, KEY_READ, &rKey); |
| 42 | + break; |
| 43 | + } |
| 44 | + |
| 45 | + RegQueryValueExA(rKey, pKeyName, NULL, NULL, (LPBYTE)&Reget, &Size); |
| 46 | + RegCloseKey(rKey); |
| 47 | + |
| 48 | + string returnValue(Reget); |
| 49 | + returnValue.shrink_to_fit(); |
| 50 | + |
| 51 | + return returnValue; |
113 | 52 | } |
114 | 53 |
|
115 | | - string Registry::GetWindowsVersion() |
| 54 | + wstring Registry::GetTextFromKeyW(const Registry::RootFolder Folder, const wchar_t* pPathToFolder, const wchar_t* pKeyName) |
116 | 55 | { |
117 | | - const char Path[] = {"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"}; |
118 | | - const char Key[] = {"ProductName"}; |
119 | | - return GetTextFromKeyA(Registry::RootFolder::HKLM, &Path[0], &Key[0]); |
| 56 | + HKEY rKey; |
| 57 | + DWORD Size = 256; |
| 58 | + WCHAR Reget[Size] = { 0 }; |
| 59 | + |
| 60 | + switch (Folder) |
| 61 | + { |
| 62 | + case Registry::RootFolder::HKCU : |
| 63 | + RegOpenKeyExW(HKEY_CURRENT_USER, pPathToFolder, 0, KEY_READ, &rKey); |
| 64 | + break; |
| 65 | + |
| 66 | + case Registry::RootFolder::HKLM : |
| 67 | + RegOpenKeyExW(HKEY_LOCAL_MACHINE, pPathToFolder, 0, KEY_READ, &rKey); |
| 68 | + break; |
| 69 | + } |
| 70 | + |
| 71 | + RegQueryValueExW(rKey, pKeyName, NULL, NULL, (LPBYTE)&Reget, &Size); |
| 72 | + RegCloseKey(rKey); |
| 73 | + |
| 74 | + wstring returnValue(Reget); |
| 75 | + returnValue.shrink_to_fit(); |
| 76 | + |
| 77 | + return returnValue; |
120 | 78 | } |
121 | 79 |
|
122 | | - string Registry::GetProcessorInfo() |
| 80 | + wstring Registry::GetPathToGame(const Games game) |
123 | 81 | { |
124 | | - const char Path[] = {"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"}; |
125 | | - const char Value[] = {"ProcessorNameString"}; |
126 | | - return GetTextFromKeyA(Registry::RootFolder::HKLM, &Path[0], &Value[0]); |
| 82 | + wstring Key = L"InstallPath"; |
| 83 | + wstring Path = Registry::PATHS_TO_GAMES.find(game)->second.find(GetWindowsBit())->second; |
| 84 | + return GetTextFromKeyW(Registry::RootFolder::HKLM, Path.c_str(), Key.c_str()); |
127 | 85 | } |
128 | 86 |
|
129 | | - string Registry::GetMemoryInfo() |
| 87 | + string Registry::ToString(Games game) |
130 | 88 | { |
131 | | - stringstream ss; |
132 | | - MEMORYSTATUSEX MemStat; |
133 | | - MemStat.dwLength = sizeof (MemStat); |
134 | | - GlobalMemoryStatusEx(&MemStat); |
135 | | - |
136 | | - ss << (MemStat.ullTotalPhys/1024)/1024 << "MiB"; |
137 | | - return ss.str(); |
| 89 | + string returnValue; |
| 90 | + |
| 91 | + switch (game) |
| 92 | + { |
| 93 | + case Games::Generals: |
| 94 | + returnValue = "Generals"; |
| 95 | + break; |
| 96 | + case Games::GeneralsZeroHour: |
| 97 | + returnValue = "Generals Zero Hour"; |
| 98 | + break; |
| 99 | + } |
| 100 | + |
| 101 | + return returnValue; |
138 | 102 | } |
139 | 103 |
|
140 | | - string Registry::GetUUID() |
141 | | - { |
142 | | - // Magic code by stackoverflow: https://stackoverflow.com/questions/24365331/how-can-i-generate-uuid-in-c-without-using-boost-library |
143 | | - stringstream ss; |
| 104 | + QString Registry::ToQString(Games game) { return QString::fromStdString(Registry::ToString(game)); } |
144 | 105 |
|
145 | | - UUID uuid; |
146 | | - auto tmpUuidCreate = UuidCreate(&uuid); |
147 | | - char* str; |
148 | | - auto tmpUuidToStringA = UuidToStringA(&uuid, reinterpret_cast<RPC_CSTR*>(&str)); |
149 | | - ss << str; |
150 | | - RpcStringFreeA(reinterpret_cast<RPC_CSTR*>(&str)); |
| 106 | + bool Registry::IsWindow64bit() { return GetWindowsBit() == WindowsBit::Win64; } |
| 107 | + bool Registry::IsWindow32bit() { return GetWindowsBit() == WindowsBit::Win32; } |
151 | 108 |
|
152 | | - return ss.str(); |
153 | | - } |
| 109 | +#pragma region Logger methods |
| 110 | + string Registry::GetCurrentUserLanguage() |
| 111 | + { |
| 112 | + const char Path[] = {"Control Panel\\International"}; |
| 113 | + const char Key[] = {"LocaleName"}; |
| 114 | + return GetTextFromKeyA(Registry::RootFolder::HKCU, &Path[0], &Key[0]).substr(0, 2); |
| 115 | + } |
| 116 | + |
| 117 | + string Registry::GetWindowsVersion() |
| 118 | + { |
| 119 | + const char Path[] = {"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"}; |
| 120 | + const char Key[] = {"ProductName"}; |
| 121 | + return GetTextFromKeyA(Registry::RootFolder::HKLM, &Path[0], &Key[0]); |
| 122 | + } |
| 123 | + |
| 124 | + string Registry::GetProcessorInfo() |
| 125 | + { |
| 126 | + const char Path[] = {"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"}; |
| 127 | + const char Value[] = {"ProcessorNameString"}; |
| 128 | + return GetTextFromKeyA(Registry::RootFolder::HKLM, &Path[0], &Value[0]); |
| 129 | + } |
| 130 | + |
| 131 | + string Registry::GetMemoryInfo() |
| 132 | + { |
| 133 | + stringstream ss; |
| 134 | + MEMORYSTATUSEX MemStat; |
| 135 | + MemStat.dwLength = sizeof (MemStat); |
| 136 | + GlobalMemoryStatusEx(&MemStat); |
| 137 | + |
| 138 | + ss << (MemStat.ullTotalPhys/1024)/1024 << "MiB"; |
| 139 | + return ss.str(); |
| 140 | + } |
| 141 | + |
| 142 | + string Registry::GetUUID() |
| 143 | + { |
| 144 | + // Magic code by stackoverflow: https://stackoverflow.com/questions/24365331/how-can-i-generate-uuid-in-c-without-using-boost-library |
| 145 | + stringstream ss; |
| 146 | + |
| 147 | + UUID uuid; |
| 148 | + auto tmpUuidCreate = UuidCreate(&uuid); |
| 149 | + char* str; |
| 150 | + auto tmpUuidToStringA = UuidToStringA(&uuid, reinterpret_cast<RPC_CSTR*>(&str)); |
| 151 | + ss << str; |
| 152 | + RpcStringFreeA(reinterpret_cast<RPC_CSTR*>(&str)); |
| 153 | + |
| 154 | + return ss.str(); |
| 155 | + } |
154 | 156 | #pragma endregion |
| 157 | +} |
0 commit comments