comparison OSAPI.cpp @ 2575:a76d408c5132 tip

DrawTranslucent -> DrawTextureGrayShade Removed old texture drawing stuff
author a.parshin
date Wed, 09 Mar 2016 01:39:52 +0200
parents d87bfbd3bb3b
children
comparison
equal deleted inserted replaced
2574:dd36326a9994 2575:a76d408c5132
12 OSVERSIONINFOA OSInfo::info; 12 OSVERSIONINFOA OSInfo::info;
13 13
14 14
15 15
16 16
17
18
19 bool ReadWindowsRegistryStringRecursive(HKEY parent_key, const char *path, char *out_string, int out_string_size)
20 {
21 char current_key[128];
22 char path_tail[1024];
23
24 const char *delimiter = strstr(path, "/");
25 if (delimiter)
26 {
27 strncpy(current_key, path, delimiter - path);
28 current_key[delimiter - path] = '\0';
29
30 strcpy(path_tail, delimiter + 1);
31
32 if (!parent_key)
33 {
34 if (!strcmpi(current_key, "HKEY_CLASSES_ROOT"))
35 parent_key = HKEY_CLASSES_ROOT;
36 else if (!strcmpi(current_key, "HKEY_CURRENT_CONFIG"))
37 parent_key = HKEY_CURRENT_CONFIG;
38 else if (!strcmpi(current_key, "HKEY_CURRENT_USER"))
39 parent_key = HKEY_CURRENT_USER;
40 else if (!strcmpi(current_key, "HKEY_LOCAL_MACHINE"))
41 parent_key = HKEY_LOCAL_MACHINE;
42 else if (!strcmpi(current_key, "HKEY_USERS"))
43 parent_key = HKEY_USERS;
44 else return false;
45
46 delimiter = strstr(path_tail, "/");
47 if (delimiter)
48 {
49 strncpy(current_key, path_tail, delimiter - path_tail);
50 current_key[delimiter - path_tail] = '\0';
51
52 strcpy(path_tail, delimiter + 1);
53 }
54 else return false;
55 }
56
57 bool result = false;
58 HKEY key;
59 if (!RegOpenKeyExA(parent_key, current_key, 0, KEY_READ | KEY_WOW64_32KEY, &key))
60 {
61 /*int idx = 0, r;
62 do {
63 char value_name[1024];
64 DWORD value_name_size = sizeof(value_name);
65 r = RegEnumValueA(key, idx++, value_name, &value_name_size, nullptr, nullptr, nullptr, nullptr);
66 __debugbreak();
67 } while (r == ERROR_SUCCESS);*/
68
69 result = ReadWindowsRegistryStringRecursive(key, path_tail, out_string, out_string_size);
70 RegCloseKey(key);
71 }
72
73 return result;
74 }
75 else
76 {
77 DWORD data_size = out_string_size;
78 if (RegQueryValueExA(parent_key, path, nullptr, nullptr, (LPBYTE)out_string, &data_size))
79 return false;
80 return true;
81 }
82 }
83
84 bool ReadWindowsRegistryString(const char *path, char *out_string, int out_string_size)
85 {
86 return ReadWindowsRegistryStringRecursive(nullptr, path, out_string, out_string_size);
87 }
88
89
90
17 //----- (00462C94) -------------------------------------------------------- 91 //----- (00462C94) --------------------------------------------------------
18 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hprevinstance, wchar_t *lpCmdLine, int nShowCmd) 92 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hprevinstance, wchar_t *lpCmdLine, int nShowCmd)
19 { 93 {
20 #ifndef NDEBUG 94 #ifndef NDEBUG
21 { 95 {
22 //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF); 96 //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF);
23 } 97 }
24 #endif 98 #endif
25 99
26 Log::Initialize(); 100 Log::Initialize();
27 101
28 //if (HWND hMM7Window = FindWindowW(L"MM7", 0)) 102 bool mm7_installation_found = false;
103 char mm7_path[2048];
104
105 // standard 1.0 installation
106 if (!mm7_installation_found)
107 mm7_installation_found = ReadWindowsRegistryString("HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic VII/1.0/AppPath", mm7_path, sizeof(mm7_path));
108
109 // GoG version
110 if (!mm7_installation_found)
111 mm7_installation_found = ReadWindowsRegistryString("HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM7/PATH", mm7_path, sizeof(mm7_path));
112
113
29 if (HWND hMM7Window = FindWindowW(L"M&MTrilogy", 0))//check whether the window is open 114 if (HWND hMM7Window = FindWindowW(L"M&MTrilogy", 0))//check whether the window is open
30 { 115 {
31 if (IsIconic(hMM7Window)) 116 if (IsIconic(hMM7Window))
32 ShowWindow(hMM7Window, SW_RESTORE); 117 ShowWindow(hMM7Window, SW_RESTORE);
33 SetForegroundWindow(GetLastActivePopup(hMM7Window)); 118 SetForegroundWindow(GetLastActivePopup(hMM7Window));
52 137
53 void MsgBox(const wchar_t *msg, const wchar_t *title) 138 void MsgBox(const wchar_t *msg, const wchar_t *title)
54 { 139 {
55 MessageBoxW(nullptr, msg, title, 0); 140 MessageBoxW(nullptr, msg, title, 0);
56 } 141 }
142
143
144
145
146 //----- (004649EF) --------------------------------------------------------
147 int ReadWindowsRegistryInt(const char *pKey, int uDefValue)
148 {
149 DWORD cbData; // [sp+8h] [bp-20h]@1
150 LPCSTR lpValueName; // [sp+Ch] [bp-1Ch]@1
151 DWORD dwDisposition; // [sp+10h] [bp-18h]@2
152 BYTE Data[4]; // [sp+14h] [bp-14h]@5
153 HKEY hKey; // [sp+18h] [bp-10h]@1
154 HKEY phkResult; // [sp+1Ch] [bp-Ch]@1
155 HKEY v10; // [sp+20h] [bp-8h]@1
156 HKEY v11; // [sp+24h] [bp-4h]@1
157
158 lpValueName = pKey;
159 v11 = 0;
160 v10 = 0;
161 hKey = 0;
162 phkResult = 0;
163 cbData = 4;
164 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ | KEY_WOW64_32KEY, &hKey))// for 64 bit
165 {
166 if (!RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition))
167 {
168 if (!RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v10, &dwDisposition))
169 {
170 if (!RegCreateKeyExA(v10, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v11, &dwDisposition))
171 {
172 LSTATUS status;
173 if (status = RegQueryValueExA(v11, lpValueName, 0, 0, Data, &cbData))
174 {
175 status;
176 GetLastError();
177
178 *(int *)Data = uDefValue;
179 RegSetValueExA(v11, lpValueName, 0, 4, Data, 4);
180 }
181 RegCloseKey(v11);
182 }
183 RegCloseKey(v10);
184 }
185 RegCloseKey(phkResult);
186 }
187 RegCloseKey(hKey);
188 }
189 return *(int *)Data;
190 }
191
192 //----- (00464B02) --------------------------------------------------------
193 void WriteWindowsRegistryString(const char *pKey, const char *pString)
194 {
195 size_t v2; // eax@5
196 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
197 const char *Str; // [sp+8h] [bp-18h]@1
198 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
199 HKEY hKey; // [sp+10h] [bp-10h]@1
200 HKEY phkResult; // [sp+14h] [bp-Ch]@1
201 HKEY v8; // [sp+18h] [bp-8h]@1
202 HKEY v9; // [sp+1Ch] [bp-4h]@1
203
204 Str = pString;
205 lpValueName = pKey;
206 v9 = 0;
207 v8 = 0;
208 hKey = 0;
209 phkResult = 0;
210 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ | KEY_WOW64_32KEY, &hKey))
211 {
212 if (!RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition))
213 {
214 if (!RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v8, &dwDisposition))
215 {
216 if (!RegCreateKeyExA(v8, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v9, &dwDisposition))
217 {
218 v2 = strlen(Str);
219 RegSetValueExA(v9, lpValueName, 0, 1, (const BYTE *)Str, v2 + 1);
220 RegCloseKey(v9);
221 }
222 RegCloseKey(v8);
223 }
224 RegCloseKey(phkResult);
225 }
226 RegCloseKey(hKey);
227 }
228 }
229
230
231 //----- (00464BEF) --------------------------------------------------------
232 void ReadWindowsRegistryString(const char *pKeyName, char *pOutString, int uBufLen, const char *pDefaultValue)
233 {
234 //LSTATUS (__stdcall *v4)(HKEY); // esi@1
235 LSTATUS result; // eax@7
236 DWORD Type; // [sp+Ch] [bp-24h]@5
237 LPCSTR lpValueName; // [sp+10h] [bp-20h]@1
238 DWORD cbData; // [sp+14h] [bp-1Ch]@1
239 LPBYTE Dest; // [sp+18h] [bp-18h]@1
240 DWORD dwDisposition; // [sp+1Ch] [bp-14h]@2
241 HKEY phkResult; // [sp+20h] [bp-10h]@1
242 HKEY hKey; // [sp+24h] [bp-Ch]@1
243 HKEY v13; // [sp+28h] [bp-8h]@1
244 HKEY v14; // [sp+2Ch] [bp-4h]@1
245
246 cbData = uBufLen;
247 Dest = (LPBYTE)pOutString;
248 lpValueName = pKeyName;
249 v14 = 0;
250 v13 = 0;
251 hKey = 0;
252 phkResult = 0;
253 result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
254 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ | KEY_WOW64_32KEY, &hKey))
255 {
256 if (!RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition))
257 {
258 if (!RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v13, &dwDisposition))
259 {
260 if (!RegCreateKeyExA(v13, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v14, &dwDisposition))
261 {
262 if (RegQueryValueExA(v14, lpValueName, 0, &Type, Dest, &cbData))
263 GetLastError();
264 RegCloseKey(v14);
265 v14 = NULL;
266 }
267 RegCloseKey(v13);
268 v13 = NULL;
269 }
270 RegCloseKey(phkResult);
271 phkResult = NULL;
272 }
273 RegCloseKey(hKey);
274 hKey = NULL;
275 }
276 }
277
278 //----- (00464D32) --------------------------------------------------------
279 void WriteWindowsRegistryInt(const char *pKey, int val)
280 {
281 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
282 BYTE Data[4]; // [sp+8h] [bp-18h]@1
283 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
284 HKEY hKey; // [sp+10h] [bp-10h]@1
285 HKEY phkResult; // [sp+14h] [bp-Ch]@1
286 HKEY v7; // [sp+18h] [bp-8h]@1
287 HKEY v8; // [sp+1Ch] [bp-4h]@1
288
289 *(int *)Data = val;
290 lpValueName = pKey;
291 v8 = 0;
292 v7 = 0;
293 hKey = 0;
294 phkResult = 0;
295 if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ | KEY_WOW64_32KEY, &hKey))
296 {
297 if (!RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition))
298 {
299 if (!RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v7, &dwDisposition))
300 {
301 if (!RegCreateKeyExA(v7, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v8, &dwDisposition))
302 {
303 RegSetValueExA(v8, lpValueName, 0, 4, Data, 4);
304 RegCloseKey(v8);
305 }
306 RegCloseKey(v7);
307 }
308 RegCloseKey(phkResult);
309 }
310 RegCloseKey(hKey);
311 }
312 }