blob: 712bb661e2c214590dc55174d8e09a25fd741357 [file] [log] [blame]
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +00001/*
2 * WineCfg configuration management
3 *
4 * Copyright 2002 Jaco Greeff
5 * Copyright 2003 Dimitrie O. Paun
Mike Hearna5ce4ee2004-09-28 03:16:43 +00006 * Copyright 2003-2004 Mike Hearn
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +00007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
Mike Hearn7d8711e2004-11-23 13:50:23 +000022 * TODO:
23 * - Use unicode
24 * - Icons in listviews/icons
25 * - Better add app dialog, scan c: for EXE files and add to list in background
26 * - Use [GNOME] HIG style groupboxes rather than win32 style (looks nicer, imho)
27 *
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +000028 */
29
Mike Hearncd0b7892003-09-08 18:58:07 +000030#include <assert.h>
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +000031#include <stdio.h>
32#include <limits.h>
33#include <windows.h>
Matthew Davison5101dfc2003-04-27 00:33:07 +000034#include <winreg.h>
35#include <wine/debug.h>
Mike Hearn0af614e2004-09-28 03:55:16 +000036#include <wine/list.h>
Matthew Davison5101dfc2003-04-27 00:33:07 +000037
38WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +000039
40#include "winecfg.h"
41
Mike Hearn0af614e2004-09-28 03:55:16 +000042HKEY config_key = NULL;
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +000043
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +000044
Mike Hearn0af614e2004-09-28 03:55:16 +000045
46/* this is called from the WM_SHOWWINDOW handlers of each tab page.
47 *
48 * it's a nasty hack, necessary because the property sheet insists on resetting the window title
49 * to the title of the tab, which is utterly useless. dropping the property sheet is on the todo list.
50 */
51void set_window_title(HWND dialog)
52{
53 char *newtitle;
54
55 /* update the window title */
Mike Hearn7d8711e2004-11-23 13:50:23 +000056 if (current_app)
Mike Hearn0af614e2004-09-28 03:55:16 +000057 {
Mike McCormackae511352005-06-02 15:11:32 +000058 const char *template = "Wine Configuration for %s";
Mike Hearn7d8711e2004-11-23 13:50:23 +000059 newtitle = HeapAlloc(GetProcessHeap(), 0, strlen(template) + strlen(current_app) + 1);
60 sprintf(newtitle, template, current_app);
Mike Hearncd0b7892003-09-08 18:58:07 +000061 }
Mike Hearn0af614e2004-09-28 03:55:16 +000062 else
63 {
64 newtitle = strdupA("Wine Configuration");
65 }
66
67 WINE_TRACE("setting title to %s\n", newtitle);
68 SendMessage(GetParent(dialog), PSM_SETTITLE, 0, (LPARAM) newtitle);
69 HeapFree(GetProcessHeap(), 0, newtitle);
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +000070}
71
Mike Hearncd0b7892003-09-08 18:58:07 +000072
Mike Hearn0af614e2004-09-28 03:55:16 +000073/**
Gerald Pfeifer61f8e122004-11-30 21:03:36 +000074 * get_config_key: Retrieves a configuration value from the registry
Mike Hearn4e1afc62003-08-30 00:27:08 +000075 *
Mike Hearn0af614e2004-09-28 03:55:16 +000076 * char *subkey : the name of the config section
77 * char *name : the name of the config value
78 * char *default : if the key isn't found, return this value instead
Mike Hearn4e1afc62003-08-30 00:27:08 +000079 *
Mike Hearn0af614e2004-09-28 03:55:16 +000080 * Returns a buffer holding the value if successful, NULL if
81 * not. Caller is responsible for releasing the result.
Mike Hearn4e1afc62003-08-30 00:27:08 +000082 *
Matthew Davison5101dfc2003-04-27 00:33:07 +000083 */
Mike McCormackae511352005-06-02 15:11:32 +000084static char *get_config_key (const char *subkey, const char *name, const char *def)
Matthew Davison5101dfc2003-04-27 00:33:07 +000085{
Mike Hearn0af614e2004-09-28 03:55:16 +000086 LPBYTE buffer = NULL;
87 DWORD len;
Mike Hearn4e1afc62003-08-30 00:27:08 +000088 HKEY hSubKey = NULL;
Mike Hearncd0b7892003-09-08 18:58:07 +000089 DWORD res;
Matthew Davison5101dfc2003-04-27 00:33:07 +000090
Mike Hearn0af614e2004-09-28 03:55:16 +000091 WINE_TRACE("subkey=%s, name=%s, def=%s\n", subkey, name, def);
Mike Hearncd0b7892003-09-08 18:58:07 +000092
Mike Hearn0af614e2004-09-28 03:55:16 +000093 res = RegOpenKeyEx(config_key, subkey, 0, KEY_READ, &hSubKey);
94 if (res != ERROR_SUCCESS)
95 {
96 if (res == ERROR_FILE_NOT_FOUND)
Matthew Davison5101dfc2003-04-27 00:33:07 +000097 {
Mike Hearn4e1afc62003-08-30 00:27:08 +000098 WINE_TRACE("Section key not present - using default\n");
Mike Hearn0af614e2004-09-28 03:55:16 +000099 return def ? strdupA(def) : NULL;
Matthew Davison5101dfc2003-04-27 00:33:07 +0000100 }
101 else
102 {
Mike Hearn4e1afc62003-08-30 00:27:08 +0000103 WINE_ERR("RegOpenKey failed on wine config key (res=%ld)\n", res);
Matthew Davison5101dfc2003-04-27 00:33:07 +0000104 }
105 goto end;
106 }
Mike Hearn498e1ce2003-09-30 00:27:55 +0000107
Mike Hearn0af614e2004-09-28 03:55:16 +0000108 res = RegQueryValueExA(hSubKey, name, NULL, NULL, NULL, &len);
109 if (res == ERROR_FILE_NOT_FOUND)
110 {
Matthew Davison5101dfc2003-04-27 00:33:07 +0000111 WINE_TRACE("Value not present - using default\n");
Mike Hearn0af614e2004-09-28 03:55:16 +0000112 buffer = def ? strdupA(def) : NULL;
Mike Hearncd0b7892003-09-08 18:58:07 +0000113 goto end;
Mike Hearn0af614e2004-09-28 03:55:16 +0000114 } else if (res != ERROR_SUCCESS)
115 {
116 WINE_ERR("Couldn't query value's length (res=%ld)\n", res);
Matthew Davison5101dfc2003-04-27 00:33:07 +0000117 goto end;
118 }
119
Mike Hearn0af614e2004-09-28 03:55:16 +0000120 buffer = HeapAlloc(GetProcessHeap(), 0, len + 1);
121
122 RegQueryValueEx(hSubKey, name, NULL, NULL, buffer, &len);
123
124 WINE_TRACE("buffer=%s\n", buffer);
Matthew Davison5101dfc2003-04-27 00:33:07 +0000125end:
Mike Hearn0af614e2004-09-28 03:55:16 +0000126 if (hSubKey) RegCloseKey(hSubKey);
Matthew Davison5101dfc2003-04-27 00:33:07 +0000127
Eric Pouech05413fc2005-04-18 09:54:03 +0000128 return (char*)buffer;
Matthew Davison5101dfc2003-04-27 00:33:07 +0000129}
130
Mike Hearn0af614e2004-09-28 03:55:16 +0000131/**
Gerald Pfeifer61f8e122004-11-30 21:03:36 +0000132 * set_config_key: convenience wrapper to set a key/value pair
Mike Hearn4e1afc62003-08-30 00:27:08 +0000133 *
Daniel Marmier8e5bb202003-10-09 04:39:01 +0000134 * const char *subKey : the name of the config section
135 * const char *valueName : the name of the config value
136 * const char *value : the value to set the configuration key to
Mike Hearn4e1afc62003-08-30 00:27:08 +0000137 *
138 * Returns 0 on success, non-zero otherwise
Mike Hearn0af614e2004-09-28 03:55:16 +0000139 *
140 * If valueName or value is NULL, an empty section will be created
Mike Hearn4e1afc62003-08-30 00:27:08 +0000141 */
Mike McCormackae511352005-06-02 15:11:32 +0000142static int set_config_key(const char *subkey, const char *name, const char *value) {
Mike Hearn4e1afc62003-08-30 00:27:08 +0000143 DWORD res = 1;
144 HKEY key = NULL;
145
Mike Hearn0af614e2004-09-28 03:55:16 +0000146 WINE_TRACE("subkey=%s: name=%s, value=%s\n", subkey, name, value);
Mike Hearncd0b7892003-09-08 18:58:07 +0000147
148 assert( subkey != NULL );
Mike Hearn4e1afc62003-08-30 00:27:08 +0000149
Mike Hearn0af614e2004-09-28 03:55:16 +0000150 res = RegCreateKey(config_key, subkey, &key);
151 if (res != ERROR_SUCCESS) goto end;
152 if (name == NULL || value == NULL) goto end;
153
154 res = RegSetValueEx(key, name, 0, REG_SZ, value, strlen(value) + 1);
Mike Hearn4e1afc62003-08-30 00:27:08 +0000155 if (res != ERROR_SUCCESS) goto end;
156
157 res = 0;
158end:
159 if (key) RegCloseKey(key);
Mike Hearn0af614e2004-09-28 03:55:16 +0000160 if (res != 0) WINE_ERR("Unable to set configuration key %s in section %s to %s, res=%ld\n", name, subkey, value, res);
Mike Hearn4e1afc62003-08-30 00:27:08 +0000161 return res;
162}
163
Mike Hearn0af614e2004-09-28 03:55:16 +0000164/* removes the requested value from the registry, however, does not
165 * remove the section if empty. Returns S_OK (0) on success.
166 */
167static HRESULT remove_value(const char *subkey, const char *name)
168{
Mike Hearncd0b7892003-09-08 18:58:07 +0000169 HRESULT hr;
170 HKEY key;
171
Mike Hearn0af614e2004-09-28 03:55:16 +0000172 WINE_TRACE("subkey=%s, name=%s\n", subkey, name);
Mike Hearncd0b7892003-09-08 18:58:07 +0000173
Mike Hearn0af614e2004-09-28 03:55:16 +0000174 hr = RegOpenKeyEx(config_key, subkey, 0, KEY_READ, &key);
Mike Hearncd0b7892003-09-08 18:58:07 +0000175 if (hr != S_OK) return hr;
176
Mike Hearn0af614e2004-09-28 03:55:16 +0000177 hr = RegDeleteValue(key, name);
Mike Hearncd0b7892003-09-08 18:58:07 +0000178 if (hr != ERROR_SUCCESS) return hr;
179
180 return S_OK;
181}
182
Mike Hearn0af614e2004-09-28 03:55:16 +0000183/* removes the requested subkey from the registry, assuming it exists */
184static HRESULT remove_path(char *section) {
Mike Hearn5a2cde62003-09-17 22:40:38 +0000185 WINE_TRACE("section=%s\n", section);
186
Mike Hearn0af614e2004-09-28 03:55:16 +0000187 return RegDeleteKey(config_key, section);
Mike Hearn5a2cde62003-09-17 22:40:38 +0000188}
189
Mike Hearn4e1afc62003-08-30 00:27:08 +0000190
Mike Hearncd0b7892003-09-08 18:58:07 +0000191/* ========================================================================= */
Mike Hearncd0b7892003-09-08 18:58:07 +0000192
Mike Hearn0af614e2004-09-28 03:55:16 +0000193/* This code exists for the following reasons:
194 *
195 * - It makes working with the registry easier
196 * - By storing a mini cache of the registry, we can more easily implement
197 * cancel/revert and apply. The 'settings list' is an overlay on top of
198 * the actual registry data that we can write out at will.
199 *
200 * Rather than model a tree in memory, we simply store each absolute (rooted
201 * at the config key) path.
202 *
203 */
Mike Hearncd0b7892003-09-08 18:58:07 +0000204
Mike Hearn0af614e2004-09-28 03:55:16 +0000205struct setting
Mike Hearn0f4c6c92003-09-10 03:41:44 +0000206{
Mike Hearn0af614e2004-09-28 03:55:16 +0000207 struct list entry;
208 char *path; /* path in the registry rooted at the config key */
Mike Hearnc6191522005-01-03 14:45:05 +0000209 char *name; /* name of the registry value. if null, this means delete the key */
210 char *value; /* contents of the registry value. if null, this means delete the value */
Mike Hearn0af614e2004-09-28 03:55:16 +0000211};
212
213struct list *settings;
214
215static void free_setting(struct setting *setting)
216{
217 assert( setting != NULL );
Mike Hearnc6191522005-01-03 14:45:05 +0000218 assert( setting->path );
Mike Hearn0af614e2004-09-28 03:55:16 +0000219
Mike Hearnc6191522005-01-03 14:45:05 +0000220 WINE_TRACE("destroying %p: %s\n", setting, setting->path);
221
Mike Hearn0af614e2004-09-28 03:55:16 +0000222 HeapFree(GetProcessHeap(), 0, setting->path);
223 HeapFree(GetProcessHeap(), 0, setting->name);
Michael Stefaniuc5ad7d852004-12-23 17:06:43 +0000224 HeapFree(GetProcessHeap(), 0, setting->value);
Mike Hearn0af614e2004-09-28 03:55:16 +0000225
226 list_remove(&setting->entry);
227
228 HeapFree(GetProcessHeap(), 0, setting);
229}
230
231/**
232 * Returns the contents of the value at path. If not in the settings
233 * list, it will be fetched from the registry - failing that, the
234 * default will be used.
235 *
236 * If already in the list, the contents as given there will be
237 * returned. You are expected to HeapFree the result.
238 */
Alexandre Julliard6e92d382005-06-13 18:49:23 +0000239char *get_reg_key(const char *path, const char *name, const char *def)
Mike Hearn0af614e2004-09-28 03:55:16 +0000240{
241 struct list *cursor;
242 struct setting *s;
243 char *val;
244
245 WINE_TRACE("path=%s, name=%s, def=%s\n", path, name, def);
246
247 /* check if it's in the list */
248 LIST_FOR_EACH( cursor, settings )
249 {
250 s = LIST_ENTRY(cursor, struct setting, entry);
251
252 if (strcasecmp(path, s->path) != 0) continue;
253 if (strcasecmp(name, s->name) != 0) continue;
254
255 WINE_TRACE("found %s:%s in settings list, returning %s\n", path, name, s->value);
Crestez Leonard3e55df32005-01-14 19:48:41 +0000256 return s->value ? strdupA(s->value) : NULL;
Mike Hearn0af614e2004-09-28 03:55:16 +0000257 }
258
259 /* no, so get from the registry */
Gerald Pfeifer61f8e122004-11-30 21:03:36 +0000260 val = get_config_key(path, name, def);
Mike Hearn0af614e2004-09-28 03:55:16 +0000261
262 WINE_TRACE("returning %s\n", val);
263
264 return val;
265}
266
267/**
268 * Used to set a registry key.
269 *
270 * path is rooted at the config key, ie use "Version" or
271 * "AppDefaults\\fooapp.exe\\Version". You can use keypath()
272 * to get such a string.
273 *
Mike Hearnc6191522005-01-03 14:45:05 +0000274 * name is the value name, or NULL to delete the path.
Mike Hearn0af614e2004-09-28 03:55:16 +0000275 *
276 * value is what to set the value to, or NULL to delete it.
277 *
278 * These values will be copied when necessary.
279 */
Alexandre Julliard6e92d382005-06-13 18:49:23 +0000280void set_reg_key(const char *path, const char *name, const char *value)
Mike Hearn0af614e2004-09-28 03:55:16 +0000281{
282 struct list *cursor;
283 struct setting *s;
284
285 assert( path != NULL );
Mike Hearn0af614e2004-09-28 03:55:16 +0000286
287 WINE_TRACE("path=%s, name=%s, value=%s\n", path, name, value);
288
289 /* firstly, see if we already set this setting */
290 LIST_FOR_EACH( cursor, settings )
291 {
292 struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
293
294 if (strcasecmp(s->path, path) != 0) continue;
Mike Hearnc6191522005-01-03 14:45:05 +0000295 if ((s->name && name) && strcasecmp(s->name, name) != 0) continue;
296
297 /* are we attempting a double delete? */
298 if (!s->name && !name) return;
299
300 /* do we want to undelete this key? */
301 if (!s->name && name) s->name = strdupA(name);
Mike Hearn0af614e2004-09-28 03:55:16 +0000302
303 /* yes, we have already set it, so just replace the content and return */
Michael Stefaniuc5ad7d852004-12-23 17:06:43 +0000304 HeapFree(GetProcessHeap(), 0, s->value);
Mike Hearn0af614e2004-09-28 03:55:16 +0000305 s->value = value ? strdupA(value) : NULL;
306
Mike Hearnc6191522005-01-03 14:45:05 +0000307 /* are we deleting this key? this won't remove any of the
308 * children from the overlay so if the user adds it again in
309 * that session it will appear to undelete the settings, but
310 * in reality only the settings actually modified by the user
311 * in that session will be restored. we might want to fix this
312 * corner case in future by actually deleting all the children
313 * here so that once it's gone, it's gone.
314 */
315 if (!name) s->name = NULL;
316
Mike Hearn0af614e2004-09-28 03:55:16 +0000317 return;
318 }
319
320 /* otherwise add a new setting for it */
321 s = HeapAlloc(GetProcessHeap(), 0, sizeof(struct setting));
Mike Hearnc6191522005-01-03 14:45:05 +0000322 s->path = strdupA(path);
323 s->name = name ? strdupA(name) : NULL;
Mike Hearn0af614e2004-09-28 03:55:16 +0000324 s->value = value ? strdupA(value) : NULL;
325
326 list_add_tail(settings, &s->entry);
327}
328
329/**
330 * enumerates the value names at the given path, taking into account
331 * the changes in the settings list.
332 *
333 * you are expected to HeapFree each element of the array, which is null
334 * terminated, as well as the array itself.
335 */
336char **enumerate_values(char *path)
337{
338 HKEY key;
339 DWORD res, i = 0;
340 char **values = NULL;
341 int valueslen = 0;
342 struct list *cursor;
343
344 res = RegOpenKeyEx(config_key, path, 0, KEY_READ, &key);
345 if (res == ERROR_SUCCESS)
346 {
347 while (TRUE)
348 {
349 char name[1024];
350 DWORD namesize = sizeof(name);
351 BOOL removed = FALSE;
352
353 /* find out the needed size, allocate a buffer, read the value */
354 if ((res = RegEnumValue(key, i, name, &namesize, NULL, NULL, NULL, NULL)) != ERROR_SUCCESS)
355 break;
356
357 WINE_TRACE("name=%s\n", name);
358
359 /* check if this value name has been removed in the settings list */
360 LIST_FOR_EACH( cursor, settings )
361 {
362 struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
363 if (strcasecmp(s->path, path) != 0) continue;
364 if (strcasecmp(s->name, name) != 0) continue;
365
366 if (!s->value)
367 {
368 WINE_TRACE("this key has been removed, so skipping\n");
369 removed = TRUE;
370 break;
371 }
372 }
373
374 if (removed) /* this value was deleted by the user, so don't include it */
375 {
376 HeapFree(GetProcessHeap(), 0, name);
377 i++;
378 continue;
379 }
380
381 /* grow the array if necessary, add buffer to it, iterate */
382 if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1));
383 else values = HeapAlloc(GetProcessHeap(), 0, sizeof(char*));
384
385 values[valueslen++] = strdupA(name);
386 WINE_TRACE("valueslen is now %d\n", valueslen);
387 i++;
388 }
389 }
390 else
391 {
392 WINE_WARN("failed opening registry key %s, res=0x%lx\n", path, res);
393 }
394
395 WINE_TRACE("adding settings in list but not registry\n");
396
397 /* now we have to add the values that aren't in the registry but are in the settings list */
398 LIST_FOR_EACH( cursor, settings )
399 {
400 struct setting *setting = LIST_ENTRY(cursor, struct setting, entry);
401 BOOL found = FALSE;
402
403 if (strcasecmp(setting->path, path) != 0) continue;
404
405 if (!setting->value) continue;
406
407 for (i = 0; i < valueslen; i++)
408 {
409 if (strcasecmp(setting->name, values[i]) == 0)
410 {
411 found = TRUE;
412 break;
413 }
414 }
415
416 if (found) continue;
417
418 WINE_TRACE("%s in list but not registry\n", setting->name);
419
420 /* otherwise it's been set by the user but isn't in the registry */
421 if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1));
422 else values = HeapAlloc(GetProcessHeap(), 0, sizeof(char*));
423
424 values[valueslen++] = strdupA(setting->name);
425 }
426
427 WINE_TRACE("adding null terminator\n");
428 if (values)
429 {
430 values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1));
431 values[valueslen] = NULL;
432 }
433
434 RegCloseKey(key);
435
436 return values;
437}
438
439/**
440 * returns true if the given key/value pair exists in the registry or
441 * has been written to.
442 */
Alexandre Julliard6e92d382005-06-13 18:49:23 +0000443BOOL reg_key_exists(const char *path, const char *name)
Mike Hearn0af614e2004-09-28 03:55:16 +0000444{
Alexandre Julliard6e92d382005-06-13 18:49:23 +0000445 char *val = get_reg_key(path, name, NULL);
Mike Hearn0af614e2004-09-28 03:55:16 +0000446
447 if (val)
448 {
449 HeapFree(GetProcessHeap(), 0, val);
450 return TRUE;
451 }
452
453 return FALSE;
454}
455
456static void process_setting(struct setting *s)
457{
458 if (s->value)
459 {
460 WINE_TRACE("Setting %s:%s to '%s'\n", s->path, s->name, s->value);
Gerald Pfeifer61f8e122004-11-30 21:03:36 +0000461 set_config_key(s->path, s->name, s->value);
Mike Hearn0af614e2004-09-28 03:55:16 +0000462 }
463 else
464 {
465 /* NULL name means remove that path/section entirely */
466 if (s->path && s->name) remove_value(s->path, s->name);
467 else if (s->path && !s->name) remove_path(s->path);
468 }
469}
470
471void apply(void)
472{
473 if (list_empty(settings)) return; /* we will be called for each page when the user clicks OK */
474
475 WINE_TRACE("()\n");
476
477 while (!list_empty(settings))
478 {
479 struct setting *s = (struct setting *) list_head(settings);
480 process_setting(s);
481 free_setting(s);
Mike Hearncd0b7892003-09-08 18:58:07 +0000482 }
Dimitrie O. Paun82ce2cc2003-03-31 19:41:55 +0000483}
Mike Hearn0f4c6c92003-09-10 03:41:44 +0000484
Mike Hearn0f4c6c92003-09-10 03:41:44 +0000485/* ================================== utility functions ============================ */
486
Mike Hearn7d8711e2004-11-23 13:50:23 +0000487char *current_app = NULL; /* the app we are currently editing, or NULL if editing global */
Mike Hearna5ce4ee2004-09-28 03:16:43 +0000488
489/* returns a registry key path suitable for passing to addTransaction */
Mike McCormackae511352005-06-02 15:11:32 +0000490char *keypath(const char *section)
Mike Hearna5ce4ee2004-09-28 03:16:43 +0000491{
492 static char *result = NULL;
Mike Hearn0af614e2004-09-28 03:55:16 +0000493
Michael Stefaniuc5ad7d852004-12-23 17:06:43 +0000494 HeapFree(GetProcessHeap(), 0, result);
Mike Hearna5ce4ee2004-09-28 03:16:43 +0000495
Mike Hearn7d8711e2004-11-23 13:50:23 +0000496 if (current_app)
Mike Hearna5ce4ee2004-09-28 03:16:43 +0000497 {
Mike Hearn7d8711e2004-11-23 13:50:23 +0000498 result = HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(current_app) + 2 /* \\ */ + strlen(section) + 1 /* terminator */);
499 sprintf(result, "AppDefaults\\%s\\%s", current_app, section);
Mike Hearna5ce4ee2004-09-28 03:16:43 +0000500 }
501 else
502 {
503 result = strdupA(section);
504 }
Mike Hearn0af614e2004-09-28 03:55:16 +0000505
Mike Hearna5ce4ee2004-09-28 03:16:43 +0000506 return result;
507}
508
Chris Morgan49f0dd32004-05-04 02:56:46 +0000509void PRINTERROR(void)
510{
511 LPSTR msg;
512
513 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
514 0, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
515 (LPSTR)&msg, 0, NULL);
Mike Hearn7d8711e2004-11-23 13:50:23 +0000516
517 /* eliminate trailing newline, is this a Wine bug? */
Mike Hearnfd14bde2005-01-10 14:26:46 +0000518 *(strrchr(msg, '\r')) = '\0';
Mike Hearn7d8711e2004-11-23 13:50:23 +0000519
Chris Morgan49f0dd32004-05-04 02:56:46 +0000520 WINE_TRACE("error: '%s'\n", msg);
521}
Mike Hearn0af614e2004-09-28 03:55:16 +0000522
523int initialize(void) {
Alexandre Julliarda18f2062005-06-16 16:15:37 +0000524 DWORD res = RegCreateKey(HKEY_CURRENT_USER, WINE_KEY_ROOT, &config_key);
Mike Hearn0af614e2004-09-28 03:55:16 +0000525
526 if (res != ERROR_SUCCESS) {
527 WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
528 return 1;
529 }
530
531 /* we could probably just have the list as static data */
532 settings = HeapAlloc(GetProcessHeap(), 0, sizeof(struct list));
533 list_init(settings);
534
535 return 0;
536}