annotate Engine/Registry.cpp @ 2538:c9182a87095e

.hgignore
author a.parshin
date Sat, 09 May 2015 11:29:44 +0200
parents 160e12614310
children
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 {
2512
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
100 //LSTATUS (__stdcall *v4)(HKEY); // esi@1
2499
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;
2512
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
119 result = (LSTATUS)strncpy((char *)Dest, pDefaultValue, uBufLen);
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
120 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
121 {
2512
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
122 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition))
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
123 {
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
124 if (!RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v13, &dwDisposition))
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
125 {
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
126 if( !RegCreateKeyExA(v13, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v14, &dwDisposition) )
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
127 {
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
128 if ( RegQueryValueExA(v14, lpValueName, 0, &Type, Dest, &cbData) )
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
129 GetLastError();
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
130 RegCloseKey(v14);
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
131 v14 = NULL;
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
132 }
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
133 RegCloseKey(v13);
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
134 v13 = NULL;
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
135 }
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
136 RegCloseKey(phkResult);
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
137 phkResult = NULL;
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
138 }
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
139 RegCloseKey(hKey);
160e12614310 RegOpenKeyExA
Ritor1
parents: 2499
diff changeset
140 hKey = NULL;
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
141 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
142 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
143
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
144 //----- (00464D32) --------------------------------------------------------
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
145 void __fastcall WriteWindowsRegistryInt(const char *pKey, int val)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
146 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
147 const char *lpValueName; // [sp+4h] [bp-1Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
148 BYTE Data[4]; // [sp+8h] [bp-18h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
149 DWORD dwDisposition; // [sp+Ch] [bp-14h]@2
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
150 HKEY hKey; // [sp+10h] [bp-10h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
151 HKEY phkResult; // [sp+14h] [bp-Ch]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
152 HKEY v7; // [sp+18h] [bp-8h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
153 HKEY v8; // [sp+1Ch] [bp-4h]@1
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
154
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
155 *(int *)Data = val;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
156 lpValueName = pKey;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
157 v8 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
158 v7 = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
159 hKey = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
160 phkResult = 0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
161 if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
162 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
163 if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, KEY_ALL_ACCESS, 0, &phkResult, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
164 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
165 if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, KEY_ALL_ACCESS, 0, &v7, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
166 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
167 if ( !RegCreateKeyExA(v7, "1.0", 0, "", 0, KEY_ALL_ACCESS, 0, &v8, &dwDisposition) )
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
168 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
169 RegSetValueExA(v8, lpValueName, 0, 4, Data, 4);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
170 RegCloseKey(v8);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
171 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
172 RegCloseKey(v7);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
173 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
174 RegCloseKey(phkResult);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
175 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
176 RegCloseKey(hKey);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
177 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
178 }