2003-03-31 19:41:55 +00:00
|
|
|
/*
|
|
|
|
* WineCfg configuration management
|
|
|
|
*
|
|
|
|
* Copyright 2002 Jaco Greeff
|
|
|
|
* Copyright 2003 Dimitrie O. Paun
|
2004-09-28 03:16:43 +00:00
|
|
|
* Copyright 2003-2004 Mike Hearn
|
2003-03-31 19:41:55 +00: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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-03-31 19:41:55 +00:00
|
|
|
*
|
2004-11-23 13:50:23 +00: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 19:41:55 +00:00
|
|
|
*/
|
|
|
|
|
2006-01-19 10:55:01 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
#include <assert.h>
|
2003-03-31 19:41:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <windows.h>
|
2003-04-27 00:33:07 +00:00
|
|
|
#include <winreg.h>
|
|
|
|
#include <wine/debug.h>
|
2004-09-28 03:55:16 +00:00
|
|
|
#include <wine/list.h>
|
2003-04-27 00:33:07 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
|
2003-03-31 19:41:55 +00:00
|
|
|
|
|
|
|
#include "winecfg.h"
|
2005-12-17 11:30:06 +00:00
|
|
|
#include "resource.h"
|
2003-03-31 19:41:55 +00:00
|
|
|
|
2013-10-08 22:06:18 +00:00
|
|
|
static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
|
2010-12-15 21:30:18 +00:00
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
HKEY config_key = NULL;
|
2005-12-17 11:30:06 +00:00
|
|
|
HMENU hPopupMenus = 0;
|
2003-03-31 19:41:55 +00:00
|
|
|
|
2004-09-28 03:55:16 +00: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-08-16 16:30:48 +00:00
|
|
|
WCHAR newtitle[256];
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
/* update the window title */
|
2004-11-23 13:50:23 +00:00
|
|
|
if (current_app)
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
2006-08-16 16:30:48 +00:00
|
|
|
WCHAR apptitle[256];
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_WINECFG_TITLE_APP, apptitle, ARRAY_SIZE(apptitle));
|
2021-09-07 15:14:22 +00:00
|
|
|
swprintf(newtitle, ARRAY_SIZE(newtitle), apptitle, current_app);
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
else
|
|
|
|
{
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), IDS_WINECFG_TITLE, newtitle, ARRAY_SIZE(newtitle));
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
|
2006-08-16 16:30:48 +00:00
|
|
|
WINE_TRACE("setting title to %s\n", wine_dbgstr_w (newtitle));
|
|
|
|
SendMessageW (GetParent(dialog), PSM_SETTITLEW, 0, (LPARAM) newtitle);
|
2003-03-31 19:41:55 +00:00
|
|
|
}
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
|
2006-08-16 04:22:54 +00:00
|
|
|
WCHAR* load_string (UINT id)
|
|
|
|
{
|
2006-08-23 10:01:35 +00:00
|
|
|
WCHAR buf[1024];
|
2006-08-16 04:22:54 +00:00
|
|
|
int len;
|
|
|
|
WCHAR* newStr;
|
|
|
|
|
2018-05-17 22:17:06 +00:00
|
|
|
LoadStringW(GetModuleHandleW(NULL), id, buf, ARRAY_SIZE(buf));
|
2006-08-16 04:22:54 +00:00
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
len = wcslen(buf);
|
|
|
|
newStr = malloc((len + 1) * sizeof(WCHAR));
|
|
|
|
memcpy(newStr, buf, len * sizeof(WCHAR));
|
2006-08-16 04:22:54 +00:00
|
|
|
newStr[len] = 0;
|
|
|
|
return newStr;
|
|
|
|
}
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
/**
|
2004-11-30 21:03:36 +00:00
|
|
|
* get_config_key: Retrieves a configuration value from the registry
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
2004-09-28 03:55:16 +00: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 00:27:08 +00:00
|
|
|
*
|
2004-09-28 03:55:16 +00:00
|
|
|
* Returns a buffer holding the value if successful, NULL if
|
|
|
|
* not. Caller is responsible for releasing the result.
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
2003-04-27 00:33:07 +00:00
|
|
|
*/
|
2007-08-02 23:33:24 +00:00
|
|
|
static WCHAR *get_config_key (HKEY root, const WCHAR *subkey, const WCHAR *name, const WCHAR *def)
|
2003-04-27 00:33:07 +00:00
|
|
|
{
|
2007-08-02 23:33:24 +00:00
|
|
|
LPWSTR buffer = NULL;
|
2004-09-28 03:55:16 +00:00
|
|
|
DWORD len;
|
2003-08-30 00:27:08 +00:00
|
|
|
HKEY hSubKey = NULL;
|
2003-09-08 18:58:07 +00:00
|
|
|
DWORD res;
|
2003-04-27 00:33:07 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("subkey=%s, name=%s, def=%s\n", wine_dbgstr_w(subkey),
|
|
|
|
wine_dbgstr_w(name), wine_dbgstr_w(def));
|
2003-09-08 18:58:07 +00:00
|
|
|
|
2011-03-11 08:04:37 +00:00
|
|
|
res = RegOpenKeyExW(root, subkey, 0, MAXIMUM_ALLOWED, &hSubKey);
|
2004-09-28 03:55:16 +00:00
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (res == ERROR_FILE_NOT_FOUND)
|
2003-04-27 00:33:07 +00:00
|
|
|
{
|
2003-08-30 00:27:08 +00:00
|
|
|
WINE_TRACE("Section key not present - using default\n");
|
2022-12-05 03:36:22 +00:00
|
|
|
return wcsdup(def);
|
2003-04-27 00:33:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_ERR("RegOpenKey failed on wine config key (res=%ld)\n", res);
|
2003-04-27 00:33:07 +00:00
|
|
|
}
|
|
|
|
goto end;
|
|
|
|
}
|
2003-09-30 00:27:55 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
res = RegQueryValueExW(hSubKey, name, NULL, NULL, NULL, &len);
|
2004-09-28 03:55:16 +00:00
|
|
|
if (res == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
2003-04-27 00:33:07 +00:00
|
|
|
WINE_TRACE("Value not present - using default\n");
|
2022-12-05 03:36:22 +00:00
|
|
|
buffer = wcsdup(def);
|
2003-09-08 18:58:07 +00:00
|
|
|
goto end;
|
2004-09-28 03:55:16 +00:00
|
|
|
} else if (res != ERROR_SUCCESS)
|
2003-04-27 00:33:07 +00:00
|
|
|
{
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_ERR("Couldn't query value's length (res=%ld)\n", res);
|
2003-04-27 00:33:07 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
buffer = malloc(len + sizeof(WCHAR));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
RegQueryValueExW(hSubKey, name, NULL, NULL, (LPBYTE) buffer, &len);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("buffer=%s\n", wine_dbgstr_w(buffer));
|
2003-04-27 00:33:07 +00:00
|
|
|
end:
|
2011-03-11 08:04:37 +00:00
|
|
|
RegCloseKey(hSubKey);
|
2003-04-27 00:33:07 +00:00
|
|
|
|
2005-08-19 15:19:10 +00:00
|
|
|
return buffer;
|
2003-04-27 00:33:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
/**
|
2004-11-30 21:03:36 +00:00
|
|
|
* set_config_key: convenience wrapper to set a key/value pair
|
2003-08-30 00:27:08 +00:00
|
|
|
*
|
2003-10-09 04:39:01 +00: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 00:27:08 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero otherwise
|
2004-09-28 03:55:16 +00:00
|
|
|
*
|
|
|
|
* If valueName or value is NULL, an empty section will be created
|
2003-08-30 00:27:08 +00:00
|
|
|
*/
|
2010-12-15 21:30:18 +00:00
|
|
|
static int set_config_key(HKEY root, const WCHAR *subkey, REGSAM access, const WCHAR *name, const void *value, DWORD type)
|
|
|
|
{
|
2003-08-30 00:27:08 +00:00
|
|
|
DWORD res = 1;
|
|
|
|
HKEY key = NULL;
|
|
|
|
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_TRACE("subkey=%s: name=%s, value=%p, type=%ld\n", wine_dbgstr_w(subkey),
|
2007-08-02 23:33:24 +00:00
|
|
|
wine_dbgstr_w(name), value, type);
|
2003-09-08 18:58:07 +00:00
|
|
|
|
|
|
|
assert( subkey != NULL );
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2005-06-17 21:09:07 +00:00
|
|
|
if (subkey[0])
|
|
|
|
{
|
2010-12-15 21:30:18 +00:00
|
|
|
res = RegCreateKeyExW( root, subkey, 0, NULL, REG_OPTION_NON_VOLATILE,
|
|
|
|
access, NULL, &key, NULL );
|
2005-06-17 21:09:07 +00:00
|
|
|
if (res != ERROR_SUCCESS) goto end;
|
|
|
|
}
|
2005-06-23 11:42:54 +00:00
|
|
|
else key = root;
|
2004-09-28 03:55:16 +00:00
|
|
|
if (name == NULL || value == NULL) goto end;
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2005-08-17 11:37:34 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
2007-08-02 23:33:24 +00:00
|
|
|
case REG_SZ: res = RegSetValueExW(key, name, 0, REG_SZ, value, (lstrlenW(value)+1)*sizeof(WCHAR)); break;
|
|
|
|
case REG_DWORD: res = RegSetValueExW(key, name, 0, REG_DWORD, value, sizeof(DWORD)); break;
|
2005-08-17 11:37:34 +00:00
|
|
|
}
|
2003-08-30 00:27:08 +00:00
|
|
|
if (res != ERROR_SUCCESS) goto end;
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
end:
|
2005-06-23 11:42:54 +00:00
|
|
|
if (key && key != root) RegCloseKey(key);
|
2007-08-02 23:33:24 +00:00
|
|
|
if (res != 0)
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_ERR("Unable to set configuration key %s in section %s, res=%ld\n",
|
2007-08-02 23:33:24 +00:00
|
|
|
wine_dbgstr_w(name), wine_dbgstr_w(subkey), res);
|
2003-08-30 00:27:08 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-09-08 18:58:07 +00:00
|
|
|
/* ========================================================================= */
|
2004-09-28 03:55:16 +00: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 11:42:54 +00:00
|
|
|
HKEY root; /* the key on which path is rooted */
|
2007-08-02 23:33:24 +00:00
|
|
|
WCHAR *path; /* path in the registry rooted at root */
|
|
|
|
WCHAR *name; /* name of the registry value. if null, this means delete the key */
|
|
|
|
WCHAR *value; /* contents of the registry value. if null, this means delete the value */
|
2005-08-17 11:37:34 +00:00
|
|
|
DWORD type; /* type of registry value. REG_SZ or REG_DWORD for now */
|
2004-09-28 03:55:16 +00:00
|
|
|
};
|
|
|
|
|
2016-11-26 21:51:42 +00:00
|
|
|
static struct list settings = LIST_INIT(settings);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
static void free_setting(struct setting *setting)
|
|
|
|
{
|
|
|
|
assert( setting != NULL );
|
2005-01-03 14:45:05 +00:00
|
|
|
assert( setting->path );
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("destroying %p: %s\n", setting,
|
|
|
|
wine_dbgstr_w(setting->path));
|
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
free(setting->path);
|
|
|
|
free(setting->name);
|
|
|
|
free(setting->value);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
list_remove(&setting->entry);
|
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
free(setting);
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2022-12-05 03:36:22 +00:00
|
|
|
* returned. You are expected to free the result.
|
2004-09-28 03:55:16 +00:00
|
|
|
*/
|
2021-09-07 15:14:22 +00:00
|
|
|
WCHAR *get_reg_key(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR *def)
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
struct list *cursor;
|
|
|
|
struct setting *s;
|
2007-08-02 23:33:24 +00:00
|
|
|
WCHAR *val;
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("path=%s, name=%s, def=%s\n", wine_dbgstr_w(path),
|
|
|
|
wine_dbgstr_w(name), wine_dbgstr_w(def));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
/* check if it's in the list */
|
2016-11-26 21:51:42 +00:00
|
|
|
LIST_FOR_EACH( cursor, &settings )
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
s = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
|
2005-06-23 11:42:54 +00:00
|
|
|
if (root != s->root) continue;
|
2007-08-02 23:33:24 +00:00
|
|
|
if (lstrcmpiW(path, s->path) != 0) continue;
|
2006-08-16 16:30:48 +00:00
|
|
|
if (!s->name) continue;
|
2007-08-02 23:33:24 +00:00
|
|
|
if (lstrcmpiW(name, s->name) != 0) continue;
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("found %s:%s in settings list, returning %s\n",
|
|
|
|
wine_dbgstr_w(path), wine_dbgstr_w(name),
|
|
|
|
wine_dbgstr_w(s->value));
|
2022-12-05 03:36:22 +00:00
|
|
|
return wcsdup(s->value);
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* no, so get from the registry */
|
2005-06-23 11:42:54 +00:00
|
|
|
val = get_config_key(root, path, name, def);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("returning %s\n", wine_dbgstr_w(val));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
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 14:45:05 +00:00
|
|
|
* name is the value name, or NULL to delete the path.
|
2004-09-28 03:55:16 +00:00
|
|
|
*
|
|
|
|
* value is what to set the value to, or NULL to delete it.
|
|
|
|
*
|
2005-08-17 11:37:34 +00:00
|
|
|
* type is REG_SZ or REG_DWORD.
|
|
|
|
*
|
2004-09-28 03:55:16 +00:00
|
|
|
* These values will be copied when necessary.
|
|
|
|
*/
|
2007-08-02 23:33:24 +00:00
|
|
|
static void set_reg_key_ex(HKEY root, const WCHAR *path, const WCHAR *name, const void *value, DWORD type)
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
struct list *cursor;
|
|
|
|
struct setting *s;
|
|
|
|
|
|
|
|
assert( path != NULL );
|
|
|
|
|
2007-08-07 10:38:11 +00:00
|
|
|
WINE_TRACE("path=%s, name=%s, value=%s\n", wine_dbgstr_w(path),
|
2007-08-02 23:33:24 +00:00
|
|
|
wine_dbgstr_w(name), wine_dbgstr_w(value));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
/* firstly, see if we already set this setting */
|
2016-11-26 21:51:42 +00:00
|
|
|
LIST_FOR_EACH( cursor, &settings )
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
|
2005-06-23 11:42:54 +00:00
|
|
|
if (root != s->root) continue;
|
2007-08-02 23:33:24 +00:00
|
|
|
if (lstrcmpiW(s->path, path) != 0) continue;
|
|
|
|
if ((s->name && name) && lstrcmpiW(s->name, name) != 0) continue;
|
2005-01-03 14:45:05 +00:00
|
|
|
|
|
|
|
/* are we attempting a double delete? */
|
|
|
|
if (!s->name && !name) return;
|
|
|
|
|
|
|
|
/* do we want to undelete this key? */
|
2022-12-05 03:36:22 +00:00
|
|
|
if (!s->name && name) s->name = wcsdup(name);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
/* yes, we have already set it, so just replace the content and return */
|
2022-12-05 03:36:22 +00:00
|
|
|
free(s->value);
|
2005-08-17 11:37:34 +00:00
|
|
|
s->type = type;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
2022-12-05 03:36:22 +00:00
|
|
|
s->value = wcsdup(value);
|
2005-08-17 11:37:34 +00:00
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
2022-12-05 03:36:22 +00:00
|
|
|
s->value = malloc(sizeof(DWORD));
|
2005-08-17 11:37:34 +00:00
|
|
|
memcpy( s->value, value, sizeof(DWORD) );
|
|
|
|
break;
|
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2005-01-03 14:45:05 +00: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 03:55:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise add a new setting for it */
|
2022-12-05 03:36:22 +00:00
|
|
|
s = malloc(sizeof(struct setting));
|
2005-06-23 11:42:54 +00:00
|
|
|
s->root = root;
|
2022-12-05 03:36:22 +00:00
|
|
|
s->path = wcsdup(path);
|
|
|
|
s->name = wcsdup(name);
|
2005-08-17 11:37:34 +00:00
|
|
|
s->type = type;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_SZ:
|
2022-12-05 03:36:22 +00:00
|
|
|
s->value = wcsdup(value);
|
2005-08-17 11:37:34 +00:00
|
|
|
break;
|
|
|
|
case REG_DWORD:
|
2022-12-05 03:36:22 +00:00
|
|
|
s->value = malloc(sizeof(DWORD));
|
2005-08-17 11:37:34 +00:00
|
|
|
memcpy( s->value, value, sizeof(DWORD) );
|
|
|
|
break;
|
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2016-11-26 21:51:42 +00:00
|
|
|
list_add_tail(&settings, &s->entry);
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
2003-08-30 00:27:08 +00:00
|
|
|
|
2021-09-07 15:14:22 +00:00
|
|
|
void set_reg_key(HKEY root, const WCHAR *path, const WCHAR *name, const WCHAR *value)
|
2008-04-25 12:36:25 +00:00
|
|
|
{
|
|
|
|
set_reg_key_ex(root, path, name, value, REG_SZ);
|
|
|
|
}
|
|
|
|
|
2021-09-07 15:14:22 +00:00
|
|
|
void set_reg_key_dword(HKEY root, const WCHAR *path, const WCHAR *name, DWORD value)
|
2008-03-10 15:54:16 +00:00
|
|
|
{
|
|
|
|
set_reg_key_ex(root, path, name, &value, REG_DWORD);
|
|
|
|
}
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
/**
|
|
|
|
* enumerates the value names at the given path, taking into account
|
|
|
|
* the changes in the settings list.
|
|
|
|
*
|
2022-12-05 03:36:22 +00:00
|
|
|
* you are expected to free each element of the array, which is null
|
2004-09-28 03:55:16 +00:00
|
|
|
* terminated, as well as the array itself.
|
|
|
|
*/
|
2021-09-07 15:14:22 +00:00
|
|
|
WCHAR **enumerate_values(HKEY root, const WCHAR *path)
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
HKEY key;
|
2008-07-05 12:15:17 +00:00
|
|
|
DWORD res, i = 0, valueslen = 0;
|
2007-08-02 23:33:24 +00:00
|
|
|
WCHAR **values = NULL;
|
2004-09-28 03:55:16 +00:00
|
|
|
struct list *cursor;
|
|
|
|
|
2011-03-11 08:04:37 +00:00
|
|
|
res = RegOpenKeyExW(root, path, 0, MAXIMUM_ALLOWED, &key);
|
2004-09-28 03:55:16 +00:00
|
|
|
if (res == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2007-08-02 23:33:24 +00:00
|
|
|
WCHAR name[1024];
|
2018-05-17 22:17:06 +00:00
|
|
|
DWORD namesize = ARRAY_SIZE(name);
|
2004-09-28 03:55:16 +00:00
|
|
|
BOOL removed = FALSE;
|
|
|
|
|
|
|
|
/* find out the needed size, allocate a buffer, read the value */
|
2007-08-02 23:33:24 +00:00
|
|
|
if ((res = RegEnumValueW(key, i, name, &namesize, NULL, NULL, NULL, NULL)) != ERROR_SUCCESS)
|
2004-09-28 03:55:16 +00:00
|
|
|
break;
|
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("name=%s\n", wine_dbgstr_w(name));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
/* check if this value name has been removed in the settings list */
|
2016-11-26 21:51:42 +00:00
|
|
|
LIST_FOR_EACH( cursor, &settings )
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
struct setting *s = LIST_ENTRY(cursor, struct setting, entry);
|
2007-08-02 23:33:24 +00:00
|
|
|
if (lstrcmpiW(s->path, path) != 0) continue;
|
|
|
|
if (lstrcmpiW(s->name, name) != 0) continue;
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* grow the array if necessary, add buffer to it, iterate */
|
2022-12-05 03:36:22 +00:00
|
|
|
values = realloc(values, sizeof(WCHAR*) * (valueslen + 1));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
values[valueslen++] = wcsdup(name);
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_TRACE("valueslen is now %ld\n", valueslen);
|
2004-09-28 03:55:16 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_WARN("failed opening registry key %s, res=0x%lx\n",
|
2007-08-02 23:33:24 +00:00
|
|
|
wine_dbgstr_w(path), res);
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2016-11-26 21:51:42 +00:00
|
|
|
LIST_FOR_EACH( cursor, &settings )
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
struct setting *setting = LIST_ENTRY(cursor, struct setting, entry);
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
if (lstrcmpiW(setting->path, path) != 0) continue;
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
if (!setting->value) continue;
|
|
|
|
|
|
|
|
for (i = 0; i < valueslen; i++)
|
|
|
|
{
|
2007-08-02 23:33:24 +00:00
|
|
|
if (lstrcmpiW(setting->name, values[i]) == 0)
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) continue;
|
|
|
|
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("%s in list but not registry\n", wine_dbgstr_w(setting->name));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
/* otherwise it's been set by the user but isn't in the registry */
|
2022-12-05 03:36:22 +00:00
|
|
|
values = realloc(values, sizeof(WCHAR*) * (valueslen + 1));
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
values[valueslen++] = wcsdup(setting->name);
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
WINE_TRACE("adding null terminator\n");
|
|
|
|
if (values)
|
|
|
|
{
|
2022-12-05 03:36:22 +00:00
|
|
|
values = realloc(values, sizeof(WCHAR*) * (valueslen + 1));
|
2004-09-28 03:55:16 +00:00
|
|
|
values[valueslen] = NULL;
|
2003-09-10 03:41:44 +00:00
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
return values;
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
/**
|
|
|
|
* returns true if the given key/value pair exists in the registry or
|
|
|
|
* has been written to.
|
|
|
|
*/
|
2021-09-07 15:14:22 +00:00
|
|
|
BOOL reg_key_exists(HKEY root, const WCHAR *path, const WCHAR *name)
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
2021-09-07 15:14:22 +00:00
|
|
|
WCHAR *val = get_reg_key(root, path, name, NULL);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
free(val);
|
2021-09-07 15:14:22 +00:00
|
|
|
return val != NULL;
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
static void process_setting(struct setting *s)
|
2003-09-10 03:41:44 +00:00
|
|
|
{
|
2010-12-15 21:30:18 +00:00
|
|
|
HKEY key;
|
|
|
|
BOOL needs_wow64 = (is_win64 && s->root == HKEY_LOCAL_MACHINE && s->path &&
|
2021-09-07 11:41:35 +00:00
|
|
|
!wcsnicmp(s->path, L"Software\\", wcslen(L"Software\\")));
|
2010-12-15 21:30:18 +00:00
|
|
|
|
2004-09-28 03:55:16 +00:00
|
|
|
if (s->value)
|
|
|
|
{
|
2007-08-02 23:33:24 +00:00
|
|
|
WINE_TRACE("Setting %s:%s to '%s'\n", wine_dbgstr_w(s->path),
|
|
|
|
wine_dbgstr_w(s->name), wine_dbgstr_w(s->value));
|
2010-12-15 21:30:18 +00:00
|
|
|
set_config_key(s->root, s->path, MAXIMUM_ALLOWED, s->name, s->value, s->type);
|
|
|
|
if (needs_wow64)
|
|
|
|
{
|
|
|
|
WINE_TRACE("Setting 32-bit %s:%s to '%s'\n", wine_dbgstr_w(s->path),
|
|
|
|
wine_dbgstr_w(s->name), wine_dbgstr_w(s->value));
|
|
|
|
set_config_key(s->root, s->path, MAXIMUM_ALLOWED | KEY_WOW64_32KEY, s->name, s->value, s->type);
|
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-15 21:30:18 +00:00
|
|
|
WINE_TRACE("Removing %s:%s\n", wine_dbgstr_w(s->path), wine_dbgstr_w(s->name));
|
2011-03-11 08:04:37 +00:00
|
|
|
if (!RegOpenKeyExW( s->root, s->path, 0, MAXIMUM_ALLOWED, &key ))
|
2010-12-15 21:30:18 +00:00
|
|
|
{
|
|
|
|
/* NULL name means remove that path/section entirely */
|
|
|
|
if (s->name) RegDeleteValueW( key, s->name );
|
2011-08-26 12:28:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RegDeleteTreeW( key, NULL );
|
|
|
|
RegDeleteKeyW( s->root, s->path );
|
|
|
|
}
|
2010-12-15 21:30:18 +00:00
|
|
|
RegCloseKey( key );
|
|
|
|
}
|
|
|
|
if (needs_wow64)
|
|
|
|
{
|
|
|
|
WINE_TRACE("Removing 32-bit %s:%s\n", wine_dbgstr_w(s->path), wine_dbgstr_w(s->name));
|
|
|
|
if (!RegOpenKeyExW( s->root, s->path, 0, MAXIMUM_ALLOWED | KEY_WOW64_32KEY, &key ))
|
|
|
|
{
|
|
|
|
if (s->name) RegDeleteValueW( key, s->name );
|
2011-08-26 12:28:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RegDeleteTreeW( key, NULL );
|
|
|
|
RegDeleteKeyExW( s->root, s->path, KEY_WOW64_32KEY, 0 );
|
|
|
|
}
|
2010-12-15 21:30:18 +00:00
|
|
|
RegCloseKey( key );
|
|
|
|
}
|
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(void)
|
|
|
|
{
|
2016-11-26 21:51:42 +00:00
|
|
|
if (list_empty(&settings)) return; /* we will be called for each page when the user clicks OK */
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
WINE_TRACE("()\n");
|
|
|
|
|
2016-11-26 21:51:42 +00:00
|
|
|
while (!list_empty(&settings))
|
2004-09-28 03:55:16 +00:00
|
|
|
{
|
2016-11-26 21:51:42 +00:00
|
|
|
struct setting *s = (struct setting *) list_head(&settings);
|
2004-09-28 03:55:16 +00:00
|
|
|
process_setting(s);
|
|
|
|
free_setting(s);
|
2003-09-08 18:58:07 +00:00
|
|
|
}
|
2003-03-31 19:41:55 +00:00
|
|
|
}
|
2003-09-10 03:41:44 +00:00
|
|
|
|
|
|
|
/* ================================== utility functions ============================ */
|
|
|
|
|
2006-08-16 16:30:48 +00:00
|
|
|
WCHAR* current_app = NULL; /* the app we are currently editing, or NULL if editing global */
|
2004-09-28 03:16:43 +00:00
|
|
|
|
|
|
|
/* returns a registry key path suitable for passing to addTransaction */
|
2021-09-07 15:14:22 +00:00
|
|
|
WCHAR *keypath(const WCHAR *section)
|
2008-04-25 12:36:25 +00:00
|
|
|
{
|
|
|
|
static WCHAR *result = NULL;
|
|
|
|
|
2022-12-05 03:36:22 +00:00
|
|
|
free(result);
|
2008-04-25 12:36:25 +00:00
|
|
|
|
|
|
|
if (current_app)
|
|
|
|
{
|
2021-09-07 11:41:35 +00:00
|
|
|
DWORD len = sizeof(L"AppDefaults\\") + (lstrlenW(current_app) + lstrlenW(section) + 1) * sizeof(WCHAR);
|
2022-12-05 03:36:22 +00:00
|
|
|
result = malloc(len);
|
2021-09-07 11:41:35 +00:00
|
|
|
lstrcpyW( result, L"AppDefaults\\" );
|
2008-04-25 12:36:25 +00:00
|
|
|
lstrcatW( result, current_app );
|
|
|
|
if (section[0])
|
|
|
|
{
|
|
|
|
len = lstrlenW(result);
|
|
|
|
result[len++] = '\\';
|
|
|
|
lstrcpyW( result + len, section );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-05 03:36:22 +00:00
|
|
|
result = wcsdup(section);
|
2008-04-25 12:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-05-04 02:56:46 +00: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 13:50:23 +00:00
|
|
|
|
|
|
|
/* eliminate trailing newline, is this a Wine bug? */
|
2005-01-10 14:26:46 +00:00
|
|
|
*(strrchr(msg, '\r')) = '\0';
|
2004-11-23 13:50:23 +00:00
|
|
|
|
2004-05-04 02:56:46 +00:00
|
|
|
WINE_TRACE("error: '%s'\n", msg);
|
|
|
|
}
|
2004-09-28 03:55:16 +00:00
|
|
|
|
2013-10-16 21:38:33 +00:00
|
|
|
BOOL initialize(HINSTANCE hInstance)
|
2005-12-17 11:30:06 +00:00
|
|
|
{
|
2021-09-07 15:14:22 +00:00
|
|
|
DWORD res = RegCreateKeyW(HKEY_CURRENT_USER, WINE_KEY_ROOT, &config_key);
|
2004-09-28 03:55:16 +00:00
|
|
|
|
|
|
|
if (res != ERROR_SUCCESS) {
|
2022-02-07 07:40:37 +00:00
|
|
|
WINE_ERR("RegOpenKey failed on wine config key (%ld)\n", res);
|
2013-10-16 21:38:33 +00:00
|
|
|
return TRUE;
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 21:38:33 +00:00
|
|
|
return FALSE;
|
2004-09-28 03:55:16 +00:00
|
|
|
}
|