annotate Engine/Registry.cpp @ 2511:fb1c61a82a55

uHouseID - 1
author Ritor1
date Thu, 02 Oct 2014 17:35:50 +0600
parents 68cdef6879a0
children 160e12614310
rev   line source
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
1 #define _CRTDBG_MAP_ALLOC
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
2 #include <stdlib.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
3 #include <crtdbg.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
4
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
6 #include <stdio.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
7 #include <array>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
8 #include <windows.h>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
9
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
10 #include "Registry.h"
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
11 #include "Engine/ErrorHandling.h"
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
12
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
13 //----- (004649EF) --------------------------------------------------------
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
14 int __fastcall ReadWindowsRegistryInt(const char *pKey, int uDefValue)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
15 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
16 DWORD cbData; // [sp+8h] [bp-20h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
17 LPCSTR lpValueName; // [sp+Ch] [bp-1Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
18 DWORD dwDisposition; // [sp+10h] [bp-18h]@2
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
19 BYTE Data[4]; // [sp+14h] [bp-14h]@5
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
20 HKEY hKey; // [sp+18h] [bp-10h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
21 HKEY phkResult; // [sp+1Ch] [bp-Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
22 HKEY v10; // [sp+20h] [bp-8h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
23 HKEY v11; // [sp+24h] [bp-4h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
24
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
25 lpValueName = pKey;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
26 v11 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
27 v10 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
28 hKey = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
29 phkResult = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
30 cbData = 4;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
31 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )// for 64 bit
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
32 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
33 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
34 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
35 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v10, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
36 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
37 if ( !RegCreateKeyExA(v10, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v11, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
38 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
39 LSTATUS status;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
40 if ( status = RegQueryValueExA(v11, lpValueName, 0, 0, Data, &cbData) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
41 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
42 status;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
43 GetLastError();
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
44
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
45 *(int *)Data = uDefValue;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
46 RegSetValueExA(v11, lpValueName, 0, 4, Data, 4);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
47 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
48 RegCloseKey(v11);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
49 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
50 RegCloseKey(v10);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
51 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
52 RegCloseKey(phkResult);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
53 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
54 RegCloseKey(hKey);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
55 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
56 return *(int *)Data;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
57 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
58
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
59 //----- (00464B02) --------------------------------------------------------
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
60 void __fastcall WriteWindowsRegistryString(const char *pKey, const char *pString)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
61 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
62 size_t v2; // eax@5
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
63 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
64 const char *Str; // [sp+8h] [bp-18h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
65 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
66 HKEY hKey; // [sp+10h] [bp-10h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
67 HKEY phkResult; // [sp+14h] [bp-Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
68 HKEY v8; // [sp+18h] [bp-8h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
69 HKEY v9; // [sp+1Ch] [bp-4h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
70
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
71 Str = pString;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
72 lpValueName = pKey;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
73 v9 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
74 v8 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
75 hKey = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
76 phkResult = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
77 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
78 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
79 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
80 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
81 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v8, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
82 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
83 if ( !RegCreateKeyExA(v8, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v9, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
84 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
85 v2 = strlen(Str);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
86 RegSetValueExA(v9, lpValueName, 0, 1, (const BYTE *)Str, v2 + 1);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
87 RegCloseKey(v9);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
88 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
89 RegCloseKey(v8);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
90 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
91 RegCloseKey(phkResult);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
92 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
93 RegCloseKey(hKey);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
94 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
95 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
96
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
97 //----- (00464BEF) --------------------------------------------------------
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
98 void __fastcall ReadWindowsRegistryString(const char *pKeyName, char *pOutString, int uBufLen, const char *pDefaultValue)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
99 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
100 LSTATUS (__stdcall *v4)(HKEY); // esi@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
101 LSTATUS result; // eax@7
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
102 DWORD Type; // [sp+Ch] [bp-24h]@5
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
103 LPCSTR lpValueName; // [sp+10h] [bp-20h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
104 DWORD cbData; // [sp+14h] [bp-1Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
105 LPBYTE Dest; // [sp+18h] [bp-18h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
106 DWORD dwDisposition; // [sp+1Ch] [bp-14h]@2
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
107 HKEY phkResult; // [sp+20h] [bp-10h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
108 HKEY hKey; // [sp+24h] [bp-Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
109 HKEY v13; // [sp+28h] [bp-8h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
110 HKEY v14; // [sp+2Ch] [bp-4h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
111
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
112 cbData = uBufLen;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
113 Dest = (LPBYTE)pOutString;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
114 lpValueName = pKeyName;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
115 v14 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
116 v13 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
117 hKey = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
118 phkResult = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
119 v4 = RegCloseKey;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
120 if ( RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
121 || RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
122 || RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v13, &dwDisposition)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
123 || RegCreateKeyExA(v13, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v14, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
124 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
125 result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
126 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
127 else if ( RegQueryValueExA(v14, lpValueName, 0, &Type, Dest, &cbData) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
128 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
129 RegCloseKey(v14);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
130 v14 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
131 result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
132 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
133 else
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
134 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
135 v4 = RegCloseKey;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
136 RegCloseKey(v14);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
137 v14 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
138 RegCloseKey(v13);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
139 v13 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
140 RegCloseKey(phkResult);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
141 phkResult = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
142 result = RegCloseKey(hKey);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
143 hKey = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
144 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
145 if ( v14 )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
146 result = v4(v14);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
147 if ( v13 )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
148 result = v4(v13);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
149 if ( hKey )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
150 result = v4(hKey);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
151 if ( phkResult )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
152 result = v4(phkResult);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
153 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
154
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
155 //----- (00464D32) --------------------------------------------------------
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
156 void __fastcall WriteWindowsRegistryInt(const char *pKey, int val)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
157 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
158 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
159 BYTE Data[4]; // [sp+8h] [bp-18h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
160 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
161 HKEY hKey; // [sp+10h] [bp-10h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
162 HKEY phkResult; // [sp+14h] [bp-Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
163 HKEY v7; // [sp+18h] [bp-8h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
164 HKEY v8; // [sp+1Ch] [bp-4h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
165
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
166 *(int *)Data = val;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
167 lpValueName = pKey;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
168 v8 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
169 v7 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
170 hKey = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
171 phkResult = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
172 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
173 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
174 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
175 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
176 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v7, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
177 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
178 if ( !RegCreateKeyExA(v7, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v8, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
179 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
180 RegSetValueExA(v8, lpValueName, 0, 4, Data, 4);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
181 RegCloseKey(v8);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
182 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
183 RegCloseKey(v7);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
184 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
185 RegCloseKey(phkResult);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
186 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
187 RegCloseKey(hKey);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
188 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
189 }