Skip to content
Snippets Groups Projects
Commit 3bbb7fd2 authored by Michael Jung's avatar Michael Jung Committed by Alexandre Julliard
Browse files

Made the registry cache more general.

parent f192bb60
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,7 @@ static void update_comboboxes(HWND dialog)
char *winver;
/* retrieve the registry values */
winver = get_reg_key(keypath(""), "Version", "");
winver = get_reg_key(config_key, keypath(""), "Version", "");
/* empty winver means use automatic mode (ie the builtin dll linkage heuristics) */
WINE_TRACE("winver is %s\n", *winver != '\0' ? winver : "null (automatic mode)");
......@@ -279,7 +279,7 @@ static void on_remove_app_click(HWND dialog)
assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
section[strlen(section)] = '\0'; /* remove last backslash */
set_reg_key(section, NULL, NULL); /* delete the section */
set_reg_key(config_key, section, NULL, NULL); /* delete the section */
ListView_DeleteItem(listview, selection);
ListView_SetItemState(listview, selection - 1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
......@@ -296,12 +296,12 @@ static void on_winver_change(HWND dialog)
if (selection == 0)
{
WINE_TRACE("automatic/default selected so removing current setting\n");
set_reg_key(keypath(""), "Version", NULL);
set_reg_key(config_key, keypath(""), "Version", NULL);
}
else
{
WINE_TRACE("setting Version key to value '%s'\n", ver[selection - 1].szVersion);
set_reg_key(keypath(""), "Version", ver[selection - 1].szVersion);
set_reg_key(config_key, keypath(""), "Version", ver[selection - 1].szVersion);
}
/* enable the apply button */
......
......@@ -55,7 +55,7 @@ static void selectAudioDriver(HWND hDlg, const char *drivername)
{
if (!strcmp (pAudioDrv->szDriver, drivername))
{
set_reg_key("Drivers", "Audio", (char *) pAudioDrv->szDriver);
set_reg_key(config_key, "Drivers", "Audio", (char *) pAudioDrv->szDriver);
SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM) hDlg, 0); /* enable apply button */
SendDlgItemMessage(hDlg, IDC_AUDIO_DRIVER, CB_SETCURSEL,
(WPARAM) i, 0);
......@@ -66,7 +66,7 @@ static void selectAudioDriver(HWND hDlg, const char *drivername)
static void initAudioDlg (HWND hDlg)
{
char *curAudioDriver = get_reg_key("Drivers", "Audio", "alsa");
char *curAudioDriver = get_reg_key(config_key, "Drivers", "Audio", "alsa");
const AUDIO_DRIVER *pAudioDrv = NULL;
int i;
......
......@@ -310,14 +310,14 @@ static int fill_drives_list(HWND dialog)
static void on_options_click(HWND dialog)
{
if (IsDlgButtonChecked(dialog, IDC_SHOW_DIRSYM_LINK) == BST_CHECKED)
set_reg_key("", "ShowDirSymLinks", "Y");
set_reg_key(config_key, "", "ShowDirSymLinks", "Y");
else
set_reg_key("", "ShowDirSymLinks", "N");
set_reg_key(config_key, "", "ShowDirSymLinks", "N");
if (IsDlgButtonChecked(dialog, IDC_SHOW_DOT_FILES) == BST_CHECKED)
set_reg_key("", "ShowDotFiles", "Y");
set_reg_key(config_key, "", "ShowDotFiles", "Y");
else
set_reg_key("", "ShowDotFiles", "N");
set_reg_key(config_key, "", "ShowDotFiles", "N");
}
static void on_add_click(HWND dialog)
......@@ -684,10 +684,10 @@ static void init_listview_columns(HWND dialog)
static void load_drive_options(HWND dialog)
{
if (!strcmp(get_reg_key("", "ShowDirSymLinks", "N"), "Y"))
if (!strcmp(get_reg_key(config_key, "", "ShowDirSymLinks", "N"), "Y"))
CheckDlgButton(dialog, IDC_SHOW_DIRSYM_LINK, BST_CHECKED);
if (!strcmp(get_reg_key("", "ShowDotFiles", "N"), "Y"))
if (!strcmp(get_reg_key(config_key, "", "ShowDotFiles", "N"), "Y"))
CheckDlgButton(dialog, IDC_SHOW_DOT_FILES, BST_CHECKED);
}
......
......@@ -174,7 +174,7 @@ static void clear_settings(HWND dialog)
static void load_library_settings(HWND dialog)
{
char **overrides = enumerate_values(keypath("DllOverrides"));
char **overrides = enumerate_values(config_key, keypath("DllOverrides"));
char **p;
int sel, count = 0;
......@@ -201,7 +201,7 @@ static void load_library_settings(HWND dialog)
const char *label;
struct dll *dll;
value = get_reg_key(keypath("DllOverrides"), *p, NULL);
value = get_reg_key(config_key, keypath("DllOverrides"), *p, NULL);
label = mode_to_label(string_to_mode(value));
......@@ -273,7 +273,7 @@ static void set_dllmode(HWND dialog, DWORD id)
WINE_TRACE("Setting %s to %s\n", dll->name, str);
SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
set_reg_key(keypath("DllOverrides"), dll->name, str);
set_reg_key(config_key, keypath("DllOverrides"), dll->name, str);
load_library_settings(dialog); /* ... and refresh */
}
......@@ -292,7 +292,7 @@ static void on_add_click(HWND dialog)
WINE_TRACE("Adding %s as native, builtin", buffer);
SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
set_reg_key(keypath("DllOverrides"), buffer, "native,builtin");
set_reg_key(config_key, keypath("DllOverrides"), buffer, "native,builtin");
load_library_settings(dialog);
......@@ -313,7 +313,7 @@ static void on_remove_click(HWND dialog)
SendDlgItemMessage(dialog, IDC_DLLS_LIST, LB_DELETESTRING, sel, 0);
SendMessage(GetParent(dialog), PSM_CHANGED, 0, 0);
set_reg_key(keypath("DllOverrides"), dll->name, NULL);
set_reg_key(config_key, keypath("DllOverrides"), dll->name, NULL);
HeapFree(GetProcessHeap(), 0, dll->name);
HeapFree(GetProcessHeap(), 0, dll);
......
......@@ -81,7 +81,7 @@ void set_window_title(HWND dialog)
* not. Caller is responsible for releasing the result.
*
*/
static char *get_config_key (const char *subkey, const char *name, const char *def)
static char *get_config_key (HKEY root, const char *subkey, const char *name, const char *def)
{
LPBYTE buffer = NULL;
DWORD len;
......@@ -90,7 +90,7 @@ static char *get_config_key (const char *subkey, const char *name, const char *d
WINE_TRACE("subkey=%s, name=%s, def=%s\n", subkey, name, def);
res = RegOpenKey(config_key, subkey, &hSubKey);
res = RegOpenKey(root, subkey, &hSubKey);
if (res != ERROR_SUCCESS)
{
if (res == ERROR_FILE_NOT_FOUND)
......@@ -123,7 +123,7 @@ static char *get_config_key (const char *subkey, const char *name, const char *d
WINE_TRACE("buffer=%s\n", buffer);
end:
if (hSubKey && hSubKey != config_key) RegCloseKey(hSubKey);
if (hSubKey && hSubKey != root) RegCloseKey(hSubKey);
return (char*)buffer;
}
......@@ -139,7 +139,7 @@ end:
*
* If valueName or value is NULL, an empty section will be created
*/
static int set_config_key(const char *subkey, const char *name, const char *value) {
static int set_config_key(HKEY root, const char *subkey, const char *name, const char *value) {
DWORD res = 1;
HKEY key = NULL;
......@@ -149,10 +149,10 @@ static int set_config_key(const char *subkey, const char *name, const char *valu
if (subkey[0])
{
res = RegCreateKey(config_key, subkey, &key);
res = RegCreateKey(root, subkey, &key);
if (res != ERROR_SUCCESS) goto end;
}
else key = config_key;
else key = root;
if (name == NULL || value == NULL) goto end;
res = RegSetValueEx(key, name, 0, REG_SZ, value, strlen(value) + 1);
......@@ -160,7 +160,7 @@ static int set_config_key(const char *subkey, const char *name, const char *valu
res = 0;
end:
if (key && key != config_key) RegCloseKey(key);
if (key && key != root) RegCloseKey(key);
if (res != 0) WINE_ERR("Unable to set configuration key %s in section %s to %s, res=%ld\n", name, subkey, value, res);
return res;
}
......@@ -168,14 +168,14 @@ end:
/* removes the requested value from the registry, however, does not
* remove the section if empty. Returns S_OK (0) on success.
*/
static HRESULT remove_value(const char *subkey, const char *name)
static HRESULT remove_value(HKEY root, const char *subkey, const char *name)
{
HRESULT hr;
HKEY key;
WINE_TRACE("subkey=%s, name=%s\n", subkey, name);
hr = RegOpenKey(config_key, subkey, &key);
hr = RegOpenKey(root, subkey, &key);
if (hr != S_OK) return hr;
hr = RegDeleteValue(key, name);
......@@ -185,10 +185,10 @@ static HRESULT remove_value(const char *subkey, const char *name)
}
/* removes the requested subkey from the registry, assuming it exists */
static HRESULT remove_path(char *section) {
static HRESULT remove_path(HKEY root, char *section) {
WINE_TRACE("section=%s\n", section);
return RegDeleteKey(config_key, section);
return RegDeleteKey(root, section);
}
......@@ -209,7 +209,8 @@ static HRESULT remove_path(char *section) {
struct setting
{
struct list entry;
char *path; /* path in the registry rooted at the config key */
HKEY root; /* the key on which path is rooted */
char *path; /* path in the registry rooted at root */
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 */
};
......@@ -240,7 +241,7 @@ static void free_setting(struct setting *setting)
* If already in the list, the contents as given there will be
* returned. You are expected to HeapFree the result.
*/
char *get_reg_key(const char *path, const char *name, const char *def)
char *get_reg_key(HKEY root, const char *path, const char *name, const char *def)
{
struct list *cursor;
struct setting *s;
......@@ -253,6 +254,7 @@ char *get_reg_key(const char *path, const char *name, const char *def)
{
s = LIST_ENTRY(cursor, struct setting, entry);
if (root != s->root) continue;
if (strcasecmp(path, s->path) != 0) continue;
if (strcasecmp(name, s->name) != 0) continue;
......@@ -261,7 +263,7 @@ char *get_reg_key(const char *path, const char *name, const char *def)
}
/* no, so get from the registry */
val = get_config_key(path, name, def);
val = get_config_key(root, path, name, def);
WINE_TRACE("returning %s\n", val);
......@@ -281,7 +283,7 @@ char *get_reg_key(const char *path, const char *name, const char *def)
*
* These values will be copied when necessary.
*/
void set_reg_key(const char *path, const char *name, const char *value)
void set_reg_key(HKEY root, const char *path, const char *name, const char *value)
{
struct list *cursor;
struct setting *s;
......@@ -295,6 +297,7 @@ void set_reg_key(const char *path, const char *name, const char *value)
{
struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
if (root != s->root) continue;
if (strcasecmp(s->path, path) != 0) continue;
if ((s->name && name) && strcasecmp(s->name, name) != 0) continue;
......@@ -323,6 +326,7 @@ void set_reg_key(const char *path, const char *name, const char *value)
/* otherwise add a new setting for it */
s = HeapAlloc(GetProcessHeap(), 0, sizeof(struct setting));
s->root = root;
s->path = strdupA(path);
s->name = name ? strdupA(name) : NULL;
s->value = value ? strdupA(value) : NULL;
......@@ -337,7 +341,7 @@ void set_reg_key(const char *path, const char *name, const char *value)
* you are expected to HeapFree each element of the array, which is null
* terminated, as well as the array itself.
*/
char **enumerate_values(char *path)
char **enumerate_values(HKEY root, char *path)
{
HKEY key;
DWORD res, i = 0;
......@@ -345,7 +349,7 @@ char **enumerate_values(char *path)
int valueslen = 0;
struct list *cursor;
res = RegOpenKey(config_key, path, &key);
res = RegOpenKey(root, path, &key);
if (res == ERROR_SUCCESS)
{
while (TRUE)
......@@ -444,9 +448,9 @@ char **enumerate_values(char *path)
* returns true if the given key/value pair exists in the registry or
* has been written to.
*/
BOOL reg_key_exists(const char *path, const char *name)
BOOL reg_key_exists(HKEY root, const char *path, const char *name)
{
char *val = get_reg_key(path, name, NULL);
char *val = get_reg_key(root, path, name, NULL);
if (val)
{
......@@ -462,13 +466,13 @@ static void process_setting(struct setting *s)
if (s->value)
{
WINE_TRACE("Setting %s:%s to '%s'\n", s->path, s->name, s->value);
set_config_key(s->path, s->name, s->value);
set_config_key(s->root, s->path, s->name, s->value);
}
else
{
/* NULL name means remove that path/section entirely */
if (s->path && s->name) remove_value(s->path, s->name);
else if (s->path && !s->name) remove_path(s->path);
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);
}
}
......
......@@ -44,15 +44,18 @@ extern char *current_app; /* NULL means editing global settings */
set_reg_key won't be committed to the registry until process_all_settings is called,
however get_reg_key will still return accurate information.
The root HKEY has to be non-ambiguous. So only the registry roots (HKCU, HKLM, ...) or
the global config_key are allowed here.
You are expected to HeapFree the result of get_reg_key. The parameters to set_reg_key will
be copied, so free them too when necessary.
*/
void set_reg_key(const char *path, const char *name, const char *value);
char *get_reg_key(const char *path, const char *name, const char *def);
BOOL reg_key_exists(const char *path, const char *name);
void set_reg_key(HKEY root, const char *path, const char *name, const char *value);
char *get_reg_key(HKEY root, const char *path, const char *name, const char *def);
BOOL reg_key_exists(HKEY root, const char *path, const char *name);
void apply(void);
char **enumerate_values(char *path);
char **enumerate_values(HKEY root, char *path);
/* returns a string of the form "AppDefaults\\appname.exe\\section", or just "section" if
the user is editing the global settings.
......
......@@ -44,7 +44,7 @@ static void update_gui_for_desktop_mode(HWND dialog) {
updating_ui = TRUE;
/* do we have desktop mode enabled? */
if (reg_key_exists(keypath("X11 Driver"), "Desktop"))
if (reg_key_exists(config_key, keypath("X11 Driver"), "Desktop"))
{
char* buf, *bufindex;
CheckDlgButton(dialog, IDC_ENABLE_DESKTOP, BST_CHECKED);
......@@ -54,7 +54,7 @@ static void update_gui_for_desktop_mode(HWND dialog) {
enable(IDC_DESKTOP_SIZE);
enable(IDC_DESKTOP_BY);
buf = get_reg_key(keypath("X11 Driver"), "Desktop", "640x480");
buf = get_reg_key(config_key, keypath("X11 Driver"), "Desktop", "640x480");
bufindex = strchr(buf, 'x');
if (bufindex) {
*bufindex = 0;
......@@ -99,7 +99,7 @@ static void init_dialog (HWND dialog)
SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "24 bit");
SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_ADDSTRING, 0, (LPARAM) "32 bit"); /* is this valid? */
buf = get_reg_key(keypath("X11 Driver"), "ScreenDepth", "24");
buf = get_reg_key(config_key, keypath("X11 Driver"), "ScreenDepth", "24");
if (strcmp(buf, "8") == 0)
SendDlgItemMessage(dialog, IDC_SCREEN_DEPTH, CB_SETCURSEL, 0, 0);
else if (strcmp(buf, "16") == 0)
......@@ -115,14 +115,14 @@ static void init_dialog (HWND dialog)
SendDlgItemMessage(dialog, IDC_DESKTOP_WIDTH, EM_LIMITTEXT, RES_MAXLEN, 0);
SendDlgItemMessage(dialog, IDC_DESKTOP_HEIGHT, EM_LIMITTEXT, RES_MAXLEN, 0);
buf = get_reg_key(keypath("X11 Driver"), "DXGrab", "Y");
buf = get_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
if (IS_OPTION_TRUE(*buf))
CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_CHECKED);
else
CheckDlgButton(dialog, IDC_DX_MOUSE_GRAB, BST_UNCHECKED);
HeapFree(GetProcessHeap(), 0, buf);
buf = get_reg_key(keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
buf = get_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
if (IS_OPTION_TRUE(*buf))
CheckDlgButton(dialog, IDC_DOUBLE_BUFFER, BST_CHECKED);
else
......@@ -154,7 +154,7 @@ static void set_from_desktop_edits(HWND dialog) {
new = HeapAlloc(GetProcessHeap(), 0, strlen(width) + strlen(height) + 2 /* x + terminator */);
sprintf(new, "%sx%s", width, height);
set_reg_key(keypath("X11 Driver"), "Desktop", new);
set_reg_key(config_key, keypath("X11 Driver"), "Desktop", new);
HeapFree(GetProcessHeap(), 0, width);
HeapFree(GetProcessHeap(), 0, height);
......@@ -167,7 +167,7 @@ static void on_enable_desktop_clicked(HWND dialog) {
if (IsDlgButtonChecked(dialog, IDC_ENABLE_DESKTOP) == BST_CHECKED) {
set_from_desktop_edits(dialog);
} else {
set_reg_key(keypath("X11 Driver"), "Desktop", NULL);
set_reg_key(config_key, keypath("X11 Driver"), "Desktop", NULL);
}
update_gui_for_desktop_mode(dialog);
......@@ -181,23 +181,23 @@ static void on_screen_depth_changed(HWND dialog) {
if (updating_ui) return;
*spaceIndex = '\0';
set_reg_key(keypath("X11 Driver"), "ScreenDepth", newvalue);
set_reg_key(config_key, keypath("X11 Driver"), "ScreenDepth", newvalue);
HeapFree(GetProcessHeap(), 0, newvalue);
}
static void on_dx_mouse_grab_clicked(HWND dialog) {
if (IsDlgButtonChecked(dialog, IDC_DX_MOUSE_GRAB) == BST_CHECKED)
set_reg_key(keypath("X11 Driver"), "DXGrab", "Y");
set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "Y");
else
set_reg_key(keypath("X11 Driver"), "DXGrab", "N");
set_reg_key(config_key, keypath("X11 Driver"), "DXGrab", "N");
}
static void on_double_buffer_clicked(HWND dialog) {
if (IsDlgButtonChecked(dialog, IDC_DOUBLE_BUFFER) == BST_CHECKED)
set_reg_key(keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "Y");
else
set_reg_key(keypath("X11 Driver"), "DesktopDoubleBuffered", "N");
set_reg_key(config_key, keypath("X11 Driver"), "DesktopDoubleBuffered", "N");
}
INT_PTR CALLBACK
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment