2003-03-31 21:41:55 +02:00
|
|
|
/*
|
|
|
|
* WineCfg configuration management
|
|
|
|
*
|
|
|
|
* Copyright 2002 Jaco Greeff
|
|
|
|
* Copyright 2003 Dimitrie O. Paun
|
2004-09-28 05:16:43 +02:00
|
|
|
* Copyright 2003-2004 Mike Hearn
|
2003-03-31 21:41:55 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
2004-11-23 14:50:23 +01:00
|
|
|
* TODO:
|
|
|
|
* - Use unicode
|
|
|
|
* - Icons in listviews/icons
|
|
|
|
* - Better add app dialog, scan c: for EXE files and add to list in background
|
|
|
|
* - Use [GNOME] HIG style groupboxes rather than win32 style (looks nicer, imho)
|
|
|
|
*
|
2003-03-31 21:41:55 +02:00
|
|
|
*/
|
|
|
|
|
2006-01-19 11:55:01 +01:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
2003-09-08 20:58:07 +02:00
|
|
|
#include <assert.h>
|
2003-03-31 21:41:55 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <windows.h>
|
2003-04-27 02:33:07 +02:00
|
|
|
#include <winreg.h>
|
|
|
|
#include <wine/debug.h>
|
2004-09-28 05:55:16 +02:00
|
|
|
#include <wine/list.h>
|
2003-04-27 02:33:07 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
2003-03-31 21:41:55 +02:00
|
|
|
|
|
|
|
#include "winecfg.h"
|
2005-12-17 12:30:06 +01:00
|
|
|
#include "resource.h"
|
2003-03-31 21:41:55 +02:00
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
HKEY config_key = NULL;
|
2005-12-17 12:30:06 +01:00
|
|
|
HMENU hPopupMenus = 0;
|
2003-03-31 21:41:55 +02:00
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
/* this is called from the WM_SHOWWINDOW handlers of each tab page.
|
|
|
|
*
|
|
|
|
* it's a nasty hack, necessary because the property sheet insists on resetting the window title
|
|
|
|
* to the title of the tab, which is utterly useless. dropping the property sheet is on the todo list.
|
|
|
|
*/
|
|
|
|
void set_window_title(HWND dialog)
|
|
|
|
{
|
2006-02-16 19:44:53 +01:00
|
|
|
char newtitle[256];
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
/* update the window title */
|
2004-11-23 14:50:23 +01:00
|
|
|
if (current_app)
|
2004-09-28 05:55:16 +02:00
|
|
|
{
|
2006-02-16 19:44:53 +01:00
|
|
|
char apptitle[256];
|
|
|
|
LoadString(GetModuleHandle(NULL), IDS_WINECFG_TITLE_APP, apptitle, 256);
|
|
|
|
sprintf(newtitle, apptitle, current_app);
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
else
|
|
|
|
{
|
2006-02-16 19:44:53 +01:00
|
|
|
LoadString(GetModuleHandle(NULL), IDS_WINECFG_TITLE, newtitle, 256);
|
2004-09-28 05:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WINE_TRACE("setting title to %s\n", newtitle);
|
|
|
|
SendMessage(GetParent(dialog), PSM_SETTITLE, 0, (LPARAM) newtitle);
|
2003-03-31 21:41:55 +02:00
|
|
|
}
|
|
|
|
|
2003-09-08 20:58:07 +02:00
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/**
|
2004-11-30 22:03:36 +01:00
|
|
|
* get_config_key: Retrieves a configuration value from the registry
|
2003-08-30 02:27:08 +02:00
|
|
|
*
|
2004-09-28 05:55:16 +02:00
|
|
|
* char *subkey : the name of the config section
|
|
|
|
* char *name : the name of the config value
|
|
|
|
* char *default : if the key isn't found, return this value instead
|
2003-08-30 02:27:08 +02:00
|
|
|
*
|
2004-09-28 05:55:16 +02:00
|
|
|
* Returns a buffer holding the value if successful, NULL if
|
|
|
|
* not. Caller is responsible for releasing the result.
|
2003-08-30 02:27:08 +02:00
|
|
|
*
|
2003-04-27 02:33:07 +02:00
|
|
|
*/
|
2005-06-23 13:42:54 +02:00
|
|
|
static char *get_config_key (HKEY root, const char *subkey, const char *name, const char *def)
|
2003-04-27 02:33:07 +02:00
|
|
|
{
|
2005-08-19 17:19:10 +02:00
|
|
|
LPSTR buffer = NULL;
|
2004-09-28 05:55:16 +02:00
|
|
|
DWORD len;
|
2003-08-30 02:27:08 +02:00
|
|
|
HKEY hSubKey = NULL;
|
2003-09-08 20:58:07 +02:00
|
|
|
DWORD res;
|
2003-04-27 02:33:07 +02:00
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
WINE_TRACE("subkey=%s, name=%s, def=%s\n", subkey, name, def);
|
2003-09-08 20:58:07 +02:00
|
|
|
|
2005-06-23 13:42:54 +02:00
|
|
|
res = RegOpenKey(root, subkey, &hSubKey);
|
2004-09-28 05:55:16 +02:00
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (res == ERROR_FILE_NOT_FOUND)
|
2003-04-27 02:33:07 +02:00
|
|
|
{
|
2003-08-30 02:27:08 +02:00
|
|
|
WINE_TRACE("Section key not present - using default\n");
|
2004-09-28 05:55:16 +02:00
|
|
|
return def ? strdupA(def) : NULL;
|
2003-04-27 02:33:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-08-30 02:27:08 +02:00
|
|
|
WINE_ERR("RegOpenKey failed on wine config key (res=%ld)\n", res);
|
2003-04-27 02:33:07 +02:00
|
|
|
}
|
|
|
|
goto end;
|
|
|
|
}
|
2003-09-30 02:27:55 +02:00
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
res = RegQueryValueExA(hSubKey, name, NULL, NULL, NULL, &len);
|
|
|
|
if (res == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
2003-04-27 02:33:07 +02:00
|
|
|
WINE_TRACE("Value not present - using default\n");
|
2004-09-28 05:55:16 +02:00
|
|
|
buffer = def ? strdupA(def) : NULL;
|
2003-09-08 20:58:07 +02:00
|
|
|
goto end;
|
2004-09-28 05:55:16 +02:00
|
|
|
} else if (res != ERROR_SUCCESS)
|
2003-04-27 02:33:07 +02:00
|
|
|
{
|
2004-09-28 05:55:16 +02:00
|
|
|
WINE_ERR("Couldn't query value's length (res=%ld)\n", res);
|
2003-04-27 02:33:07 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, len + 1);
|
|
|
|
|
2005-08-19 17:19:10 +02:00
|
|
|
RegQueryValueEx(hSubKey, name, NULL, NULL, (LPBYTE) buffer, &len);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
WINE_TRACE("buffer=%s\n", buffer);
|
2003-04-27 02:33:07 +02:00
|
|
|
end:
|
2005-06-23 13:42:54 +02:00
|
|
|
if (hSubKey && hSubKey != root) RegCloseKey(hSubKey);
|
2003-04-27 02:33:07 +02:00
|
|
|
|
2005-08-19 17:19:10 +02:00
|
|
|
return buffer;
|
2003-04-27 02:33:07 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/**
|
2004-11-30 22:03:36 +01:00
|
|
|
* set_config_key: convenience wrapper to set a key/value pair
|
2003-08-30 02:27:08 +02:00
|
|
|
*
|
2003-10-09 06:39:01 +02:00
|
|
|
* const char *subKey : the name of the config section
|
|
|
|
* const char *valueName : the name of the config value
|
|
|
|
* const char *value : the value to set the configuration key to
|
2003-08-30 02:27:08 +02:00
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero otherwise
|
2004-09-28 05:55:16 +02:00
|
|
|
*
|
|
|
|
* If valueName or value is NULL, an empty section will be created
|
2003-08-30 02:27:08 +02:00
|
|
|
*/
|
2005-08-19 17:19:10 +02:00
|
|
|
static int set_config_key(HKEY root, const char *subkey, const char *name, const void *value, DWORD type) {
|
2003-08-30 02:27:08 +02:00
|
|
|
DWORD res = 1;
|
|
|
|
HKEY key = NULL;
|
|
|
|
|
2005-08-19 17:19:10 +02:00
|
|
|
WINE_TRACE("subkey=%s: name=%s, value=%p, type=%ld\n", subkey, name, value, type);
|
2003-09-08 20:58:07 +02:00
|
|
|
|
|
|
|
assert( subkey != NULL );
|
2004-09-28 05:55:16 +02:00
|
|
|
|
2005-06-17 23:09:07 +02:00
|
|
|
if (subkey[0])
|
|
|
|
{
|
2005-06-23 13:42:54 +02:00
|
|
|
res = RegCreateKey(root, subkey, &key);
|
2005-06-17 23:09:07 +02:00
|
|
|
if (res != ERROR_SUCCESS) goto end;
|
|
|
|
}
|
2005-06-23 13:42:54 +02:00
|
|
|
else key = root;
|
2004-09-28 05:55:16 +02:00
|
|
|
if (name == NULL || value == NULL) goto end;
|
2003-08-30 02:27:08 +02:00
|
|
|
|
2005-08-17 13:37:34 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_SZ: res = RegSetValueEx(key, name, 0, REG_SZ, value, strlen(value) + 1); break;
|
|
|
|
case REG_DWORD: res = RegSetValueEx(key, name, 0, REG_DWORD, value, sizeof(DWORD)); break;
|
|
|
|
}
|
2003-08-30 02:27:08 +02:00
|
|
|
if (res != ERROR_SUCCESS) goto end;
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
end:
|
2005-06-23 13:42:54 +02:00
|
|
|
if (key && key != root) RegCloseKey(key);
|
2005-08-19 17:19:10 +02:00
|
|
|
if (res != 0) WINE_ERR("Unable to set configuration key %s in section %s, res=%ld\n", name, subkey, res);
|
2003-08-30 02:27:08 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/* removes the requested value from the registry, however, does not
|
|
|
|
* remove the section if empty. Returns S_OK (0) on success.
|
|
|
|
*/
|
2005-06-23 13:42:54 +02:00
|
|
|
static HRESULT remove_value(HKEY root, const char *subkey, const char *name)
|
2004-09-28 05:55:16 +02:00
|
|
|
{
|
2003-09-08 20:58:07 +02:00
|
|
|
HRESULT hr;
|
|
|
|
HKEY key;
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
WINE_TRACE("subkey=%s, name=%s\n", subkey, name);
|
2003-09-08 20:58:07 +02:00
|
|
|
|
2005-06-23 13:42:54 +02:00
|
|
|
hr = RegOpenKey(root, subkey, &key);
|
2003-09-08 20:58:07 +02:00
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
hr = RegDeleteValue(key, name);
|
2003-09-08 20:58:07 +02:00
|
|
|
if (hr != ERROR_SUCCESS) return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/* removes the requested subkey from the registry, assuming it exists */
|
2005-10-13 15:44:38 +02:00
|
|
|
static LONG remove_path(HKEY root, char *section) {
|
|
|
|
HKEY branch_key;
|
|
|
|
DWORD max_sub_key_len;
|
|
|
|
DWORD subkeys;
|
|
|
|
DWORD curr_len;
|
|
|
|
LONG ret = ERROR_SUCCESS;
|
|
|
|
long int i;
|
|
|
|
char *buffer;
|
|
|
|
|
2003-09-18 00:40:38 +02:00
|
|
|
WINE_TRACE("section=%s\n", section);
|
|
|
|
|
2005-10-13 15:44:38 +02:00
|
|
|
if ((ret = RegOpenKey(root, section, &branch_key)) != ERROR_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* get size information and resize the buffers if necessary */
|
|
|
|
if ((ret = RegQueryInfoKey(branch_key, NULL, NULL, NULL,
|
|
|
|
&subkeys, &max_sub_key_len,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL
|
|
|
|
)) != ERROR_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
curr_len = strlen(section);
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, max_sub_key_len + curr_len + 1);
|
|
|
|
strcpy(buffer, section);
|
|
|
|
|
|
|
|
buffer[curr_len] = '\\';
|
|
|
|
for (i = subkeys - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
DWORD buf_len = max_sub_key_len - curr_len - 1;
|
|
|
|
|
|
|
|
ret = RegEnumKeyEx(branch_key, i, buffer + curr_len + 1,
|
|
|
|
&buf_len, NULL, NULL, NULL, NULL);
|
|
|
|
if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA &&
|
|
|
|
ret != ERROR_NO_MORE_ITEMS)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
remove_path(root, buffer);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
RegCloseKey(branch_key);
|
|
|
|
|
2005-06-23 13:42:54 +02:00
|
|
|
return RegDeleteKey(root, section);
|
2003-09-18 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
2003-08-30 02:27:08 +02:00
|
|
|
|
2003-09-08 20:58:07 +02:00
|
|
|
/* ========================================================================= */
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
/* This code exists for the following reasons:
|
|
|
|
*
|
|
|
|
* - It makes working with the registry easier
|
|
|
|
* - By storing a mini cache of the registry, we can more easily implement
|
|
|
|
* cancel/revert and apply. The 'settings list' is an overlay on top of
|
|
|
|
* the actual registry data that we can write out at will.
|
|
|
|
*
|
|
|
|
* Rather than model a tree in memory, we simply store each absolute (rooted
|
|
|
|
* at the config key) path.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct setting
|
|
|
|
{
|
|
|
|
struct list entry;
|
2005-06-23 13:42:54 +02:00
|
|
|
HKEY root; /* the key on which path is rooted */
|
|
|
|
char *path; /* path in the registry rooted at root */
|
2005-01-03 15:45:05 +01:00
|
|
|
char *name; /* name of the registry value. if null, this means delete the key */
|
|
|
|
char *value; /* contents of the registry value. if null, this means delete the value */
|
2005-08-17 13:37:34 +02:00
|
|
|
DWORD type; /* type of registry value. REG_SZ or REG_DWORD for now */
|
2004-09-28 05:55:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct list *settings;
|
|
|
|
|
|
|
|
static void free_setting(struct setting *setting)
|
|
|
|
{
|
|
|
|
assert( setting != NULL );
|
2005-01-03 15:45:05 +01:00
|
|
|
assert( setting->path );
|
2004-09-28 05:55:16 +02:00
|
|
|
|
2005-01-03 15:45:05 +01:00
|
|
|
WINE_TRACE("destroying %p: %s\n", setting, setting->path);
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, setting->path);
|
|
|
|
HeapFree(GetProcessHeap(), 0, setting->name);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, setting->value);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
list_remove(&setting->entry);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, setting);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the contents of the value at path. If not in the settings
|
|
|
|
* list, it will be fetched from the registry - failing that, the
|
|
|
|
* default will be used.
|
|
|
|
*
|
|
|
|
* If already in the list, the contents as given there will be
|
|
|
|
* returned. You are expected to HeapFree the result.
|
|
|
|
*/
|
2005-06-23 13:42:54 +02:00
|
|
|
char *get_reg_key(HKEY root, const char *path, const char *name, const char *def)
|
2004-09-28 05:55:16 +02:00
|
|
|
{
|
|
|
|
struct list *cursor;
|
|
|
|
struct setting *s;
|
|
|
|
char *val;
|
|
|
|
|
|
|
|
WINE_TRACE("path=%s, name=%s, def=%s\n", path, name, def);
|
|
|
|
|
|
|
|
/* check if it's in the list */
|
|
|
|
LIST_FOR_EACH( cursor, settings )
|
|
|
|
{
|
|
|
|
s = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
|
2005-06-23 13:42:54 +02:00
|
|
|
if (root != s->root) continue;
|
2004-09-28 05:55:16 +02:00
|
|
|
if (strcasecmp(path, s->path) != 0) continue;
|
|
|
|
if (strcasecmp(name, s->name) != 0) continue;
|
|
|
|
|
|
|
|
WINE_TRACE("found %s:%s in settings list, returning %s\n", path, name, s->value);
|
2005-01-14 20:48:41 +01:00
|
|
|
return s->value ? strdupA(s->value) : NULL;
|
2004-09-28 05:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* no, so get from the registry */
|
2005-06-23 13:42:54 +02:00
|
|
|
val = get_config_key(root, path, name, def);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
WINE_TRACE("returning %s\n", val);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to set a registry key.
|
|
|
|
*
|
|
|
|
* path is rooted at the config key, ie use "Version" or
|
|
|
|
* "AppDefaults\\fooapp.exe\\Version". You can use keypath()
|
|
|
|
* to get such a string.
|
|
|
|
*
|
2005-01-03 15:45:05 +01:00
|
|
|
* name is the value name, or NULL to delete the path.
|
2004-09-28 05:55:16 +02:00
|
|
|
*
|
|
|
|
* value is what to set the value to, or NULL to delete it.
|
|
|
|
*
|
2005-08-17 13:37:34 +02:00
|
|
|
* type is REG_SZ or REG_DWORD.
|
|
|
|
*
|
2004-09-28 05:55:16 +02:00
|
|
|
* These values will be copied when necessary.
|
|
|
|
*/
|
2005-08-17 13:37:34 +02:00
|
|
|
static void set_reg_key_ex(HKEY root, const char *path, const char *name, const void *value, DWORD type)
|
2004-09-28 05:55:16 +02:00
|
|
|
{
|
|
|
|
struct list *cursor;
|
|
|
|
struct setting *s;
|
|
|
|
|
|
|
|
assert( path != NULL );
|
|
|
|
|
2005-08-17 13:37:34 +02:00
|
|
|
WINE_TRACE("path=%s, name=%s, value=%p\n", path, name, value);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
/* firstly, see if we already set this setting */
|
|
|
|
LIST_FOR_EACH( cursor, settings )
|
|
|
|
{
|
|
|
|
struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
|
2005-06-23 13:42:54 +02:00
|
|
|
if (root != s->root) continue;
|
2004-09-28 05:55:16 +02:00
|
|
|
if (strcasecmp(s->path, path) != 0) continue;
|
2005-01-03 15:45:05 +01:00
|
|
|
if ((s->name && name) && strcasecmp(s->name, name) != 0) continue;
|
|
|
|
|
|
|
|
/* are we attempting a double delete? */
|
|
|
|
if (!s->name && !name) return;
|
|
|
|
|
|
|
|
/* do we want to undelete this key? */
|
|
|
|
if (!s->name && name) s->name = strdupA(name);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
/* yes, we have already set it, so just replace the content and return */
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, s->value);
|
2005-08-17 13:37:34 +02:00
|
|
|
s->type = type;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
s->value = value ? strdupA(value) : NULL;
|
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
|
|
|
s->value = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
|
|
|
|
memcpy( s->value, value, sizeof(DWORD) );
|
|
|
|
break;
|
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
2005-01-03 15:45:05 +01:00
|
|
|
/* are we deleting this key? this won't remove any of the
|
|
|
|
* children from the overlay so if the user adds it again in
|
|
|
|
* that session it will appear to undelete the settings, but
|
|
|
|
* in reality only the settings actually modified by the user
|
|
|
|
* in that session will be restored. we might want to fix this
|
|
|
|
* corner case in future by actually deleting all the children
|
|
|
|
* here so that once it's gone, it's gone.
|
|
|
|
*/
|
|
|
|
if (!name) s->name = NULL;
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise add a new setting for it */
|
|
|
|
s = HeapAlloc(GetProcessHeap(), 0, sizeof(struct setting));
|
2005-06-23 13:42:54 +02:00
|
|
|
s->root = root;
|
2005-01-03 15:45:05 +01:00
|
|
|
s->path = strdupA(path);
|
|
|
|
s->name = name ? strdupA(name) : NULL;
|
2005-08-17 13:37:34 +02:00
|
|
|
s->type = type;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
|
|
|
s->value = value ? strdupA(value) : NULL;
|
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
|
|
|
s->value = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD));
|
|
|
|
memcpy( s->value, value, sizeof(DWORD) );
|
|
|
|
break;
|
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
list_add_tail(settings, &s->entry);
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
2003-08-30 02:27:08 +02:00
|
|
|
|
2005-08-17 13:37:34 +02:00
|
|
|
void set_reg_key(HKEY root, const char *path, const char *name, const char *value)
|
|
|
|
{
|
|
|
|
set_reg_key_ex(root, path, name, value, REG_SZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_reg_key_dword(HKEY root, const char *path, const char *name, DWORD value)
|
|
|
|
{
|
|
|
|
set_reg_key_ex(root, path, name, &value, REG_DWORD);
|
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/**
|
|
|
|
* enumerates the value names at the given path, taking into account
|
|
|
|
* the changes in the settings list.
|
|
|
|
*
|
|
|
|
* you are expected to HeapFree each element of the array, which is null
|
|
|
|
* terminated, as well as the array itself.
|
|
|
|
*/
|
2005-06-23 13:42:54 +02:00
|
|
|
char **enumerate_values(HKEY root, char *path)
|
2004-09-28 05:55:16 +02:00
|
|
|
{
|
|
|
|
HKEY key;
|
|
|
|
DWORD res, i = 0;
|
|
|
|
char **values = NULL;
|
|
|
|
int valueslen = 0;
|
|
|
|
struct list *cursor;
|
|
|
|
|
2005-06-23 13:42:54 +02:00
|
|
|
res = RegOpenKey(root, path, &key);
|
2004-09-28 05:55:16 +02:00
|
|
|
if (res == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
char name[1024];
|
|
|
|
DWORD namesize = sizeof(name);
|
|
|
|
BOOL removed = FALSE;
|
|
|
|
|
|
|
|
/* find out the needed size, allocate a buffer, read the value */
|
|
|
|
if ((res = RegEnumValue(key, i, name, &namesize, NULL, NULL, NULL, NULL)) != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
WINE_TRACE("name=%s\n", name);
|
|
|
|
|
|
|
|
/* check if this value name has been removed in the settings list */
|
|
|
|
LIST_FOR_EACH( cursor, settings )
|
|
|
|
{
|
|
|
|
struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
if (strcasecmp(s->path, path) != 0) continue;
|
|
|
|
if (strcasecmp(s->name, name) != 0) continue;
|
|
|
|
|
|
|
|
if (!s->value)
|
|
|
|
{
|
|
|
|
WINE_TRACE("this key has been removed, so skipping\n");
|
|
|
|
removed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removed) /* this value was deleted by the user, so don't include it */
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* grow the array if necessary, add buffer to it, iterate */
|
|
|
|
if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1));
|
|
|
|
else values = HeapAlloc(GetProcessHeap(), 0, sizeof(char*));
|
|
|
|
|
|
|
|
values[valueslen++] = strdupA(name);
|
|
|
|
WINE_TRACE("valueslen is now %d\n", valueslen);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_WARN("failed opening registry key %s, res=0x%lx\n", path, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
WINE_TRACE("adding settings in list but not registry\n");
|
|
|
|
|
|
|
|
/* now we have to add the values that aren't in the registry but are in the settings list */
|
|
|
|
LIST_FOR_EACH( cursor, settings )
|
|
|
|
{
|
|
|
|
struct setting *setting = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
if (strcasecmp(setting->path, path) != 0) continue;
|
|
|
|
|
|
|
|
if (!setting->value) continue;
|
|
|
|
|
|
|
|
for (i = 0; i < valueslen; i++)
|
|
|
|
{
|
|
|
|
if (strcasecmp(setting->name, values[i]) == 0)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) continue;
|
|
|
|
|
|
|
|
WINE_TRACE("%s in list but not registry\n", setting->name);
|
|
|
|
|
|
|
|
/* otherwise it's been set by the user but isn't in the registry */
|
|
|
|
if (values) values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1));
|
|
|
|
else values = HeapAlloc(GetProcessHeap(), 0, sizeof(char*));
|
|
|
|
|
|
|
|
values[valueslen++] = strdupA(setting->name);
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
WINE_TRACE("adding null terminator\n");
|
|
|
|
if (values)
|
|
|
|
{
|
|
|
|
values = HeapReAlloc(GetProcessHeap(), 0, values, sizeof(char*) * (valueslen + 1));
|
|
|
|
values[valueslen] = NULL;
|
2003-09-10 05:41:44 +02:00
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
return values;
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/**
|
|
|
|
* returns true if the given key/value pair exists in the registry or
|
|
|
|
* has been written to.
|
|
|
|
*/
|
2005-06-23 13:42:54 +02:00
|
|
|
BOOL reg_key_exists(HKEY root, const char *path, const char *name)
|
2004-09-28 05:55:16 +02:00
|
|
|
{
|
2005-06-23 13:42:54 +02:00
|
|
|
char *val = get_reg_key(root, path, name, NULL);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, val);
|
|
|
|
return TRUE;
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
static void process_setting(struct setting *s)
|
2003-09-10 05:41:44 +02:00
|
|
|
{
|
2004-09-28 05:55:16 +02:00
|
|
|
if (s->value)
|
|
|
|
{
|
|
|
|
WINE_TRACE("Setting %s:%s to '%s'\n", s->path, s->name, s->value);
|
2005-08-17 13:37:34 +02:00
|
|
|
set_config_key(s->root, s->path, s->name, s->value, s->type);
|
2004-09-28 05:55:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* NULL name means remove that path/section entirely */
|
2005-06-23 13:42:54 +02:00
|
|
|
if (s->path && s->name) remove_value(s->root, s->path, s->name);
|
|
|
|
else if (s->path && !s->name) remove_path(s->root, s->path);
|
2004-09-28 05:55:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(void)
|
|
|
|
{
|
|
|
|
if (list_empty(settings)) return; /* we will be called for each page when the user clicks OK */
|
|
|
|
|
|
|
|
WINE_TRACE("()\n");
|
|
|
|
|
|
|
|
while (!list_empty(settings))
|
|
|
|
{
|
|
|
|
struct setting *s = (struct setting *) list_head(settings);
|
|
|
|
process_setting(s);
|
|
|
|
free_setting(s);
|
2003-09-08 20:58:07 +02:00
|
|
|
}
|
2003-03-31 21:41:55 +02:00
|
|
|
}
|
2003-09-10 05:41:44 +02:00
|
|
|
|
|
|
|
/* ================================== utility functions ============================ */
|
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
char *current_app = NULL; /* the app we are currently editing, or NULL if editing global */
|
2004-09-28 05:16:43 +02:00
|
|
|
|
|
|
|
/* returns a registry key path suitable for passing to addTransaction */
|
2005-06-02 17:11:32 +02:00
|
|
|
char *keypath(const char *section)
|
2004-09-28 05:16:43 +02:00
|
|
|
{
|
|
|
|
static char *result = NULL;
|
2004-09-28 05:55:16 +02:00
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, result);
|
2004-09-28 05:16:43 +02:00
|
|
|
|
2004-11-23 14:50:23 +01:00
|
|
|
if (current_app)
|
2004-09-28 05:16:43 +02:00
|
|
|
{
|
2004-11-23 14:50:23 +01:00
|
|
|
result = HeapAlloc(GetProcessHeap(), 0, strlen("AppDefaults\\") + strlen(current_app) + 2 /* \\ */ + strlen(section) + 1 /* terminator */);
|
2005-06-17 23:09:07 +02:00
|
|
|
sprintf(result, "AppDefaults\\%s", current_app);
|
|
|
|
if (section[0]) sprintf( result + strlen(result), "\\%s", section );
|
2004-09-28 05:16:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = strdupA(section);
|
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
2004-09-28 05:16:43 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
void PRINTERROR(void)
|
|
|
|
{
|
|
|
|
LPSTR msg;
|
|
|
|
|
|
|
|
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
0, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
|
|
|
|
(LPSTR)&msg, 0, NULL);
|
2004-11-23 14:50:23 +01:00
|
|
|
|
|
|
|
/* eliminate trailing newline, is this a Wine bug? */
|
2005-01-10 15:26:46 +01:00
|
|
|
*(strrchr(msg, '\r')) = '\0';
|
2004-11-23 14:50:23 +01:00
|
|
|
|
2004-05-04 04:56:46 +02:00
|
|
|
WINE_TRACE("error: '%s'\n", msg);
|
|
|
|
}
|
2004-09-28 05:55:16 +02:00
|
|
|
|
2005-12-17 12:30:06 +01:00
|
|
|
int initialize(HINSTANCE hInstance)
|
|
|
|
{
|
2005-06-16 18:15:37 +02:00
|
|
|
DWORD res = RegCreateKey(HKEY_CURRENT_USER, WINE_KEY_ROOT, &config_key);
|
2004-09-28 05:55:16 +02:00
|
|
|
|
|
|
|
if (res != ERROR_SUCCESS) {
|
|
|
|
WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-12-17 12:30:06 +01:00
|
|
|
/* load any menus */
|
|
|
|
hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_WINECFG));
|
|
|
|
|
2004-09-28 05:55:16 +02:00
|
|
|
/* we could probably just have the list as static data */
|
|
|
|
settings = HeapAlloc(GetProcessHeap(), 0, sizeof(struct list));
|
|
|
|
list_init(settings);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|