source: trunk/gsinstaller/registry.cpp@ 1475

Last change on this file since 1475 was 1475, checked in by cs025, 24 years ago

Updated sources with most of uninstall added

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1#include "registry.h"
2#include <stdlib.h>
3
4bool registry_createkey(HKEY key, const char *name, PHKEY keyout)
5{ LONG reply;
6 DWORD disposition;
7
8 reply = RegCreateKeyEx( key, name, NULL, NULL,
9 REG_OPTION_NON_VOLATILE,
10 KEY_ALL_ACCESS, NULL,
11 keyout, &disposition);
12 if (reply != ERROR_SUCCESS)
13 { return FALSE;
14 }
15 return TRUE;
16}
17
18bool registry_openkey(HKEY key, const char *name, PHKEY keyout)
19{ LONG reply;
20
21 reply = RegOpenKeyEx(key, name, NULL, KEY_QUERY_VALUE, keyout);
22 if (reply != ERROR_SUCCESS)
23 { return false;
24 }
25 return true;
26}
27
28bool registry_deletekey(HKEY key, const char *name)
29{ if (RegDeleteKey(key, name) != ERROR_SUCCESS)
30 { return false;
31 }
32 return true;
33}
34
35bool registry_closekey(HKEY key)
36{ LONG reply;
37 reply = RegCloseKey(key);
38 if (reply != ERROR_SUCCESS)
39 { return FALSE;
40 }
41 return TRUE;
42}
43
44bool registry_keyExists(HKEY key, const char *name)
45{ HKEY local;
46
47 if (!registry_openkey(key, name, &local))
48 { return false;
49 }
50 registry_closekey(local);
51 return true;
52}
53
54bool registry_ensureKeyExists(HKEY key, const char *name)
55{ HKEY local;
56
57 if (!registry_openkey(key, name, &local))
58 { if (!registry_createkey(key, name, &local))
59 { return false;
60 }
61 }
62 registry_closekey(local);
63 return true;
64}
65
66bool registry_deleteitem(HKEY key, const char *name)
67{ if (RegDeleteValue(key, name) != ERROR_SUCCESS)
68 { return false;
69 }
70 return true;
71}
72
73bool registry_setstring(HKEY key, const char *name, const char *value)
74{ LONG reply;
75
76 reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_SZ, (CONST BYTE *) value, strlen(value) + 1);
77 if (reply != ERROR_SUCCESS)
78 { return false;
79 }
80 return true;
81}
82
83bool registry_setlong(HKEY key, char *name, LONG value)
84{ LONG reply;
85 DWORD word;
86
87 word = (DWORD) value;
88 reply = RegSetValueEx(key, (LPCTSTR) name, NULL, REG_DWORD, (CONST BYTE *) &word, sizeof(DWORD));
89 if (reply != ERROR_SUCCESS)
90 { return FALSE;
91 }
92 return TRUE;
93}
94
95bool registry_setblock(HKEY key, char *name, char *data, int size)
96{ LONG reply;
97
98 reply = RegSetValueEx(key, name, NULL, REG_BINARY, (CONST BYTE *) data, size);
99 if (reply != ERROR_SUCCESS)
100 { // display_error();
101 return FALSE;
102 }
103 return TRUE;
104}
105
106bool registry_setint(HKEY key, char *name, int value)
107{ return registry_setlong(key, name, (LONG) value);
108}
109
110bool registry_getstring(HKEY key, char *name, char **string)
111{ LONG reply;
112 DWORD type;
113 DWORD size;
114 BYTE buffer[128];
115 int tries = 0;
116
117 do
118 {
119 reply = RegQueryValueEx(key, name, NULL, &type, buffer, &size);
120 if (reply != ERROR_SUCCESS)
121 { //display_error();
122 //sprintf(buffer, "%x {%s}", key, name);
123 //MessageBox(0, buffer, name, MB_OK);
124 }
125 tries ++;
126 } while (reply != ERROR_SUCCESS && tries < 3);
127
128 if (reply != ERROR_SUCCESS)
129 { return FALSE;
130 }
131
132 *string = (char *) malloc(size);
133 if (*string == NULL)
134 { return FALSE;
135 }
136 strcpy(*string, (char *) buffer);
137 return TRUE;
138}
139
140bool registry_getint(HKEY key, char *name, int *out)
141{ DWORD type;
142 DWORD size;
143 LONG reply;
144
145 reply = RegQueryValueEx(key, (LPTSTR) name, NULL, &type, (LPBYTE) out, &size);
146 if (reply != ERROR_SUCCESS)
147 { return FALSE;
148 }
149 return TRUE;
150}
151
152bool registry_getlong(HKEY key, char *name, LONG *out)
153{ DWORD type;
154 DWORD size;
155 LONG reply;
156 DWORD got;
157
158 size = sizeof(DWORD);
159
160 reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) &got, &size);
161 if (reply != ERROR_SUCCESS)
162 { return FALSE;
163 }
164 *out = (LONG) got;
165 return TRUE;
166}
167
168int registry_getblock(HKEY key, char *name, char *data, int size)
169{ DWORD type;
170 DWORD lsize;
171 LONG reply;
172
173 lsize = size;
174
175 reply = RegQueryValueEx(key, name, NULL, &type, (LPBYTE) data, &lsize);
176 if (reply != ERROR_SUCCESS)
177 { return -1;
178 }
179 return lsize;
180}
181
182bool registry_fetchlong(char *keystr, LONG *lptr)
183{ HKEY key;
184
185 if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
186 { return FALSE;
187 }
188 if (!registry_getlong(key, keystr, lptr))
189 { return FALSE;
190 }
191 if (registry_closekey(key) == FALSE)
192 { return FALSE;
193 }
194 return TRUE;
195}
196
197bool registry_fetchblock(char *keystr, char *data, int size)
198{ HKEY key;
199 int read;
200
201 if (!registry_openkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
202 { return FALSE;
203 }
204 read = registry_getblock(key, keystr, data, size);
205 if (read < 0)
206 { return FALSE;
207 }
208 if (registry_closekey(key) == FALSE)
209 { return FALSE;
210 }
211 return TRUE;
212}
213
214bool registry_storelong(char *keystr, LONG value)
215{ HKEY key;
216
217 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
218 { return FALSE;
219 }
220 if (!registry_setlong(key, keystr, value))
221 { return FALSE;
222 }
223 if (!registry_closekey(key))
224 { return FALSE;
225 }
226 return TRUE;
227}
228
229bool registry_storeint(char *keystr, int value)
230{ HKEY key;
231
232 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
233 { return FALSE;
234 }
235 if (!registry_setint(key, keystr, value))
236 { return FALSE;
237 }
238 if (!registry_closekey(key))
239 { return FALSE;
240 }
241 return TRUE;
242}
243
244bool registry_storeblock(char *keystr, char *data, int size)
245{ HKEY key;
246
247 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
248 { return FALSE;
249 }
250 if (!registry_setblock(key, keystr, data, size))
251 { return FALSE;
252 }
253 if (!registry_closekey(key))
254 { return FALSE;
255 }
256 return TRUE;
257}
258
259bool registry_storestring(char *keystr, char *value)
260{ HKEY key;
261
262 if (!registry_createkey(HKEY_LOCAL_MACHINE, "Software\\Kudlian Soft\\ReTreeval", &key))
263 { return FALSE;
264 }
265 if (!registry_setstring(key, keystr, value))
266 { return FALSE;
267 }
268 if (!registry_closekey(key))
269 { return FALSE;
270 }
271 return TRUE;
272}
Note: See TracBrowser for help on using the repository browser.