Avoid using advapi32.
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/macdrv.h | 17 +++++ dlls/winemac.drv/macdrv_main.c | 127 ++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 19 deletions(-)
diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index d13a2277e61..bded3500bee 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -293,4 +293,21 @@ extern void macdrv_im_set_text(const macdrv_event *event) DECLSPEC_HIDDEN; extern void macdrv_sent_text_input(const macdrv_event *event) DECLSPEC_HIDDEN; extern BOOL query_ime_char_rect(macdrv_query* query) DECLSPEC_HIDDEN;
+/* string helpers */ + +static inline void ascii_to_unicode(WCHAR *dst, const char *src, size_t len) +{ + while (len--) *dst++ = (unsigned char)*src++; +} + +static inline UINT asciiz_to_unicode(WCHAR *dst, const char *src) +{ + WCHAR *p = dst; + while ((*p++ = *src++)); + return (p - dst) * sizeof(WCHAR); +} + +/* FIXME: remove once we use unixlib */ +#define wcsrchr strrchrW + #endif /* __WINE_MACDRV_H */ diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index fff72589417..fccd588c271 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -28,6 +28,7 @@ #include "winuser.h" #include "winreg.h" #include "wine/server.h" +#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL(macdrv);
@@ -102,16 +103,97 @@ const char* debugstr_cf(CFTypeRef t) }
+static HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len) +{ + UNICODE_STRING nameW = { name_len, name_len, (WCHAR *)name }; + OBJECT_ATTRIBUTES attr; + HANDLE ret; + + attr.Length = sizeof(attr); + attr.RootDirectory = root; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + + return NtOpenKeyEx(&ret, MAXIMUM_ALLOWED, &attr, 0) ? 0 : ret; +} + + +static HKEY open_hkcu_key(const char *name) +{ + WCHAR bufferW[256]; + static HKEY hkcu; + + if (!hkcu) + { + char buffer[256]; + DWORD_PTR sid_data[(sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE) / sizeof(DWORD_PTR)]; + DWORD i, len = sizeof(sid_data); + SID *sid; + + if (NtQueryInformationToken(GetCurrentThreadEffectiveToken(), TokenUser, sid_data, len, &len)) + return 0; + + sid = ((TOKEN_USER *)sid_data)->User.Sid; + len = sprintf(buffer, "\Registry\User\S-%u-%u", sid->Revision, + MAKELONG(MAKEWORD(sid->IdentifierAuthority.Value[5], + sid->IdentifierAuthority.Value[4]), + MAKEWORD(sid->IdentifierAuthority.Value[3], + sid->IdentifierAuthority.Value[2]))); + for (i = 0; i < sid->SubAuthorityCount; i++) + len += sprintf(buffer + len, "-%u", sid->SubAuthority[i]); + + ascii_to_unicode(bufferW, buffer, len); + hkcu = reg_open_key(NULL, bufferW, len * sizeof(WCHAR)); + } + + return reg_open_key(hkcu, bufferW, asciiz_to_unicode(bufferW, name) - sizeof(WCHAR)); +} + + +static ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) +{ + UNICODE_STRING str; + + RtlInitUnicodeString(&str, name); + if (NtQueryValueKey(hkey, &str, KeyValuePartialInformation, info, size, &size)) + return 0; + + return size - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data); +} + + /*********************************************************************** * get_config_key * * Get a config key from either the app-specific or the default config */ static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char *name, - char *buffer, DWORD size) + WCHAR *buffer, DWORD size) { - if (appkey && !RegQueryValueExA(appkey, name, 0, NULL, (LPBYTE)buffer, &size)) return 0; - if (defkey && !RegQueryValueExA(defkey, name, 0, NULL, (LPBYTE)buffer, &size)) return 0; + WCHAR nameW[128]; + char buf[2048]; + KEY_VALUE_PARTIAL_INFORMATION *info = (void *)buf; + + asciiz_to_unicode(nameW, name); + + if (appkey && query_reg_value(appkey, nameW, info, sizeof(buf))) + { + size = min(info->DataLength, size - sizeof(WCHAR)); + memcpy(buffer, info->Data, size); + buffer[size / sizeof(WCHAR)] = 0; + return 0; + } + + if (defkey && query_reg_value(defkey, nameW, info, sizeof(buf))) + { + size = min(info->DataLength, size - sizeof(WCHAR)); + memcpy(buffer, info->Data, size); + buffer[size / sizeof(WCHAR)] = 0; + return 0; + } + return ERROR_FILE_NOT_FOUND; }
@@ -123,36 +205,41 @@ static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char *name, */ static void setup_options(void) { - char buffer[MAX_PATH + 16]; + static const WCHAR macdriverW[] = {'\','M','a','c',' ','D','r','i','v','e','r',0}; + WCHAR buffer[MAX_PATH + 16], *p, *appname; HKEY hkey, appkey = 0; DWORD len;
/* @@ Wine registry key: HKCU\Software\Wine\Mac Driver */ - if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\Wine\Mac Driver", &hkey)) hkey = 0; + hkey = open_hkcu_key("Software\Wine\Mac Driver");
/* open the app-specific key */
- len = GetModuleFileNameA(0, buffer, MAX_PATH); + appname = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer; + if ((p = wcsrchr(appname, '/'))) appname = p + 1; + if ((p = wcsrchr(appname, '\'))) appname = p + 1; + len = lstrlenW(appname); + if (len && len < MAX_PATH) { HKEY tmpkey; - char *p, *appname = buffer; - if ((p = strrchr(appname, '/'))) appname = p + 1; - if ((p = strrchr(appname, '\'))) appname = p + 1; - strcat(appname, "\Mac Driver"); + memcpy(buffer, appname, len * sizeof(WCHAR)); + memcpy(buffer + len, macdriverW, sizeof(macdriverW)); /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Mac Driver */ - if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\Wine\AppDefaults", &tmpkey)) + if ((tmpkey = open_hkcu_key("Software\Wine\AppDefaults"))) { - if (RegOpenKeyA(tmpkey, appname, &appkey)) appkey = 0; - RegCloseKey(tmpkey); + appkey = reg_open_key(tmpkey, buffer, lstrlenW(buffer) * sizeof(WCHAR)); + NtClose(tmpkey); } }
if (!get_config_key(hkey, appkey, "WindowsFloatWhenInactive", buffer, sizeof(buffer))) { - if (!strcmp(buffer, "none")) + static const WCHAR noneW[] = {'n','o','n','e',0}; + static const WCHAR allW[] = {'a','l','l',0}; + if (!lstrcmpW(buffer, noneW)) topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONE; - else if (!strcmp(buffer, "all")) + else if (!lstrcmpW(buffer, allW)) topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_ALL; else topmost_float_inactive = TOPMOST_FLOAT_INACTIVE_NONFULLSCREEN; @@ -206,9 +293,11 @@ static void setup_options(void)
if (!get_config_key(hkey, appkey, "OpenGLSurfaceMode", buffer, sizeof(buffer))) { - if (!strcmp(buffer, "transparent")) + static const WCHAR transparentW[] = {'t','r','a','n','s','p','a','r','e','n','t',0}; + static const WCHAR behindW[] = {'b','e','h','i','n','d',0}; + if (!lstrcmpW(buffer, transparentW)) gl_surface_mode = GL_SURFACE_IN_FRONT_TRANSPARENT; - else if (!strcmp(buffer, "behind")) + else if (!lstrcmpW(buffer, behindW)) gl_surface_mode = GL_SURFACE_BEHIND; else gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE; @@ -222,8 +311,8 @@ static void setup_options(void) if (!get_config_key(hkey, NULL, "RetinaMode", buffer, sizeof(buffer))) retina_enabled = IS_OPTION_TRUE(buffer[0]);
- if (appkey) RegCloseKey(appkey); - if (hkey) RegCloseKey(hkey); + if (appkey) NtClose(appkey); + if (hkey) NtClose(hkey); }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 45 ++++++++++++++++++++-------------- dlls/winemac.drv/macdrv.h | 5 ++++ dlls/winemac.drv/macdrv_main.c | 2 +- 3 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index 8e616652198..d81b0d5f606 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -117,12 +117,27 @@ static BOOL get_display_device_reg_key(const WCHAR *device_name, WCHAR *key, uns }
+static BOOL query_display_setting(HKEY hkey, const char *name, DWORD *ret) +{ + char buffer[1024]; + WCHAR nameW[128]; + KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer; + + asciiz_to_unicode(nameW, name); + if (query_reg_value(hkey, nameW, value, sizeof(buffer)) != sizeof(DWORD) || + value->Type != REG_DWORD) + return FALSE; + + *ret = *(DWORD *)value->Data; + return TRUE; +} + + static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm) { WCHAR wine_mac_reg_key[MAX_PATH]; HANDLE mutex; HKEY hkey; - DWORD type, size; BOOL ret = TRUE;
dm->dmFields = 0; @@ -140,32 +155,24 @@ static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm) return FALSE; }
-#define query_value(name, data) \ - size = sizeof(DWORD); \ - if (RegQueryValueExA(hkey, name, 0, &type, (LPBYTE)(data), &size) || \ - type != REG_DWORD || size != sizeof(DWORD)) \ - ret = FALSE - - query_value("DefaultSettings.BitsPerPel", &dm->dmBitsPerPel); + ret &= query_display_setting(hkey, "DefaultSettings.BitsPerPel", &dm->dmBitsPerPel); dm->dmFields |= DM_BITSPERPEL; - query_value("DefaultSettings.XResolution", &dm->dmPelsWidth); + ret &= query_display_setting(hkey, "DefaultSettings.XResolution", &dm->dmPelsWidth); dm->dmFields |= DM_PELSWIDTH; - query_value("DefaultSettings.YResolution", &dm->dmPelsHeight); + ret &= query_display_setting(hkey, "DefaultSettings.YResolution", &dm->dmPelsHeight); dm->dmFields |= DM_PELSHEIGHT; - query_value("DefaultSettings.VRefresh", &dm->dmDisplayFrequency); + ret &= query_display_setting(hkey, "DefaultSettings.VRefresh", &dm->dmDisplayFrequency); dm->dmFields |= DM_DISPLAYFREQUENCY; - query_value("DefaultSettings.Flags", &dm->dmDisplayFlags); + ret &= query_display_setting(hkey, "DefaultSettings.Flags", &dm->dmDisplayFlags); dm->dmFields |= DM_DISPLAYFLAGS; - query_value("DefaultSettings.XPanning", &dm->dmPosition.x); - query_value("DefaultSettings.YPanning", &dm->dmPosition.y); + ret &= query_display_setting(hkey, "DefaultSettings.XPanning", (DWORD *)&dm->dmPosition.x); + ret &= query_display_setting(hkey, "DefaultSettings.YPanning", (DWORD *)&dm->dmPosition.y); dm->dmFields |= DM_POSITION; - query_value("DefaultSettings.Orientation", &dm->dmDisplayOrientation); + ret &= query_display_setting(hkey, "DefaultSettings.Orientation", &dm->dmDisplayOrientation); dm->dmFields |= DM_DISPLAYORIENTATION; - query_value("DefaultSettings.FixedOutput", &dm->dmDisplayFixedOutput); - -#undef query_value + ret &= query_display_setting(hkey, "DefaultSettings.FixedOutput", &dm->dmDisplayFixedOutput);
- RegCloseKey(hkey); + NtClose(hkey); release_display_device_init_mutex(mutex); return ret; } diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index bded3500bee..931561a8209 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -293,6 +293,11 @@ extern void macdrv_im_set_text(const macdrv_event *event) DECLSPEC_HIDDEN; extern void macdrv_sent_text_input(const macdrv_event *event) DECLSPEC_HIDDEN; extern BOOL query_ime_char_rect(macdrv_query* query) DECLSPEC_HIDDEN;
+/* registry helpers */ + +extern ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, + ULONG size) DECLSPEC_HIDDEN; + /* string helpers */
static inline void ascii_to_unicode(WCHAR *dst, const char *src, size_t len) diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index fccd588c271..eb693ba968d 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -152,7 +152,7 @@ static HKEY open_hkcu_key(const char *name) }
-static ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) +ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) { UNICODE_STRING str;
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index d81b0d5f606..75904bd6f5f 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -178,6 +178,14 @@ static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm) }
+static BOOL set_setting_value(HKEY hkey, const char *name, DWORD val) +{ + WCHAR nameW[128]; + UNICODE_STRING str = { asciiz_to_unicode(nameW, name) - sizeof(WCHAR), sizeof(nameW), nameW }; + return !NtSetValueKey(hkey, &str, 0, REG_DWORD, &val, sizeof(val)); +} + + static BOOL write_registry_settings(const WCHAR *device_name, const DEVMODEW *dm) { WCHAR wine_mac_reg_key[MAX_PATH]; @@ -199,23 +207,17 @@ static BOOL write_registry_settings(const WCHAR *device_name, const DEVMODEW *dm return FALSE; }
-#define set_value(name, data) \ - if (RegSetValueExA(hkey, name, 0, REG_DWORD, (const BYTE*)(data), sizeof(DWORD))) \ - ret = FALSE + ret &= set_setting_value(hkey, "DefaultSettings.BitsPerPel", dm->dmBitsPerPel); + ret &= set_setting_value(hkey, "DefaultSettings.XResolution", dm->dmPelsWidth); + ret &= set_setting_value(hkey, "DefaultSettings.YResolution", dm->dmPelsHeight); + ret &= set_setting_value(hkey, "DefaultSettings.VRefresh", dm->dmDisplayFrequency); + ret &= set_setting_value(hkey, "DefaultSettings.Flags", dm->dmDisplayFlags); + ret &= set_setting_value(hkey, "DefaultSettings.XPanning", dm->dmPosition.x); + ret &= set_setting_value(hkey, "DefaultSettings.YPanning", dm->dmPosition.y); + ret &= set_setting_value(hkey, "DefaultSettings.Orientation", dm->dmDisplayOrientation); + ret &= set_setting_value(hkey, "DefaultSettings.FixedOutput", dm->dmDisplayFixedOutput);
- set_value("DefaultSettings.BitsPerPel", &dm->dmBitsPerPel); - set_value("DefaultSettings.XResolution", &dm->dmPelsWidth); - set_value("DefaultSettings.YResolution", &dm->dmPelsHeight); - set_value("DefaultSettings.VRefresh", &dm->dmDisplayFrequency); - set_value("DefaultSettings.Flags", &dm->dmDisplayFlags); - set_value("DefaultSettings.XPanning", &dm->dmPosition.x); - set_value("DefaultSettings.YPanning", &dm->dmPosition.y); - set_value("DefaultSettings.Orientation", &dm->dmDisplayOrientation); - set_value("DefaultSettings.FixedOutput", &dm->dmDisplayFixedOutput); - -#undef set_value - - RegCloseKey(hkey); + NtClose(hkey); release_display_device_init_mutex(mutex); return ret; }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index 75904bd6f5f..a5abf426cc5 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -74,17 +74,21 @@ static BOOL inited_original_display_mode;
static HANDLE get_display_device_init_mutex(void) { - static const WCHAR init_mutexW[] = {'d','i','s','p','l','a','y','_','d','e','v','i','c','e','_','i','n','i','t',0}; - HANDLE mutex = CreateMutexW(NULL, FALSE, init_mutexW); - - WaitForSingleObject(mutex, INFINITE); + static const WCHAR init_mutexW[] = {'d','i','s','p','l','a','y','_','d','e','v','i','c','e','_','i','n','i','t'}; + UNICODE_STRING name = { sizeof(init_mutexW), sizeof(init_mutexW), (WCHAR *)init_mutexW }; + OBJECT_ATTRIBUTES attr; + HANDLE mutex = 0; + + InitializeObjectAttributes(&attr, &name, OBJ_OPENIF, NULL, NULL); + NtCreateMutant(&mutex, MUTEX_ALL_ACCESS, &attr, FALSE); + if (mutex) NtWaitForSingleObject(mutex, FALSE, NULL); return mutex; }
static void release_display_device_init_mutex(HANDLE mutex) { - ReleaseMutex(mutex); - CloseHandle(mutex); + NtReleaseMutant(mutex, NULL); + NtClose(mutex); }
static BOOL get_display_device_reg_key(const WCHAR *device_name, WCHAR *key, unsigned len)
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 79 ++++++++++++++++------------------ dlls/winemac.drv/macdrv.h | 3 ++ dlls/winemac.drv/macdrv_main.c | 2 +- 3 files changed, 41 insertions(+), 43 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index a5abf426cc5..182d5f122a5 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -48,15 +48,6 @@ BOOL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode, LPDEVMODEW devmod
static const char initial_mode_key[] = "Initial Display Mode"; static const WCHAR pixelencodingW[] = {'P','i','x','e','l','E','n','c','o','d','i','n','g',0}; -static const WCHAR adapter_prefixW[] = {'\','\','.','\','D','I','S','P','L','A','Y'}; -static const WCHAR video_keyW[] = { - 'H','A','R','D','W','A','R','E','\', - 'D','E','V','I','C','E','M','A','P','\', - 'V','I','D','E','O',0}; -static const WCHAR device_video_fmtW[] = { - '\','D','e','v','i','c','e','\', - 'V','i','d','e','o','%','d',0}; -
static CFArrayRef modes; static BOOL modes_has_8bpp, modes_has_16bpp; @@ -91,33 +82,52 @@ static void release_display_device_init_mutex(HANDLE mutex) NtClose(mutex); }
-static BOOL get_display_device_reg_key(const WCHAR *device_name, WCHAR *key, unsigned len) +static HKEY get_display_device_reg_key(const WCHAR *device_name) { - WCHAR value_name[MAX_PATH], buffer[MAX_PATH], *end_ptr; + static const WCHAR display[] = {'\','\','.','\','D','I','S','P','L','A','Y'}; + static const WCHAR video_key[] = { + '\','R','e','g','i','s','t','r','y', + '\','M','a','c','h','i','n','e', + '\','H','A','R','D','W','A','R','E', + '\','D','E','V','I','C','E','M','A','P', + '\','V','I','D','E','O'}; + static const WCHAR current_config_key[] = { + '\','R','e','g','i','s','t','r','y', + '\','M','a','c','h','i','n','e', + '\','S','y','s','t','e','m', + '\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t', + '\','H','a','r','d','w','a','r','e',' ','P','r','o','f','i','l','e','s', + '\','C','u','r','r','e','n','t'}; + WCHAR value_name[MAX_PATH], buffer[4096], *end_ptr; + KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer; DWORD adapter_index, size; + char adapter_name[100]; + HKEY hkey;
/* Device name has to be \.\DISPLAY%d */ - if (strncmpiW(device_name, adapter_prefixW, ARRAY_SIZE(adapter_prefixW))) + if (wcsnicmp(device_name, display, ARRAY_SIZE(display))) return FALSE;
/* Parse \.\DISPLAY* */ - adapter_index = strtolW(device_name + ARRAY_SIZE(adapter_prefixW), &end_ptr, 10) - 1; + adapter_index = wcstol(device_name + ARRAY_SIZE(display), &end_ptr, 10) - 1; if (*end_ptr) return FALSE;
/* Open \Device\Video* in HKLM\HARDWARE\DEVICEMAP\VIDEO\ */ - sprintfW(value_name, device_video_fmtW, adapter_index); - size = sizeof(buffer); - if (RegGetValueW(HKEY_LOCAL_MACHINE, video_keyW, value_name, RRF_RT_REG_SZ, NULL, buffer, &size)) - return FALSE; - - if (len < lstrlenW(buffer + 18) + 1) - return FALSE; - - /* Skip \Registry\Machine\ prefix */ - lstrcpyW(key, buffer + 18); - TRACE("display device %s registry settings key %s.\n", wine_dbgstr_w(device_name), wine_dbgstr_w(key)); - return TRUE; + if (!(hkey = reg_open_key(NULL, video_key, sizeof(video_key)))) return FALSE; + sprintf(adapter_name, "\Device\Video%d", adapter_index); + asciiz_to_unicode(value_name, adapter_name); + size = query_reg_value(hkey, value_name, value, sizeof(buffer)); + NtClose(hkey); + if (!size || value->Type != REG_SZ) return FALSE; + + /* Replace \Registry\Machine\ prefix with HKEY_CURRENT_CONFIG */ + memmove(buffer + ARRAYSIZE(current_config_key), (const WCHAR *)value->Data + 17, + size - 17 * sizeof(WCHAR)); + memcpy(buffer, current_config_key, sizeof(current_config_key)); + TRACE("display device %s registry settings key %s.\n", wine_dbgstr_w(device_name), + wine_dbgstr_w(buffer)); + return reg_open_key(NULL, buffer, lstrlenW(buffer) * sizeof(WCHAR)); }
@@ -139,7 +149,6 @@ static BOOL query_display_setting(HKEY hkey, const char *name, DWORD *ret)
static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm) { - WCHAR wine_mac_reg_key[MAX_PATH]; HANDLE mutex; HKEY hkey; BOOL ret = TRUE; @@ -147,13 +156,7 @@ static BOOL read_registry_settings(const WCHAR *device_name, DEVMODEW *dm) dm->dmFields = 0;
mutex = get_display_device_init_mutex(); - if (!get_display_device_reg_key(device_name, wine_mac_reg_key, ARRAY_SIZE(wine_mac_reg_key))) - { - release_display_device_init_mutex(mutex); - return FALSE; - } - - if (RegOpenKeyExW(HKEY_CURRENT_CONFIG, wine_mac_reg_key, 0, KEY_READ, &hkey)) + if (!(hkey = get_display_device_reg_key(device_name))) { release_display_device_init_mutex(mutex); return FALSE; @@ -192,20 +195,12 @@ static BOOL set_setting_value(HKEY hkey, const char *name, DWORD val)
static BOOL write_registry_settings(const WCHAR *device_name, const DEVMODEW *dm) { - WCHAR wine_mac_reg_key[MAX_PATH]; HANDLE mutex; HKEY hkey; BOOL ret = TRUE;
mutex = get_display_device_init_mutex(); - if (!get_display_device_reg_key(device_name, wine_mac_reg_key, ARRAY_SIZE(wine_mac_reg_key))) - { - release_display_device_init_mutex(mutex); - return FALSE; - } - - if (RegCreateKeyExW(HKEY_CURRENT_CONFIG, wine_mac_reg_key, 0, NULL, - REG_OPTION_VOLATILE, KEY_WRITE, NULL, &hkey, NULL)) + if (!(hkey = get_display_device_reg_key(device_name))) { release_display_device_init_mutex(mutex); return FALSE; diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index 931561a8209..c216cfb994f 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -297,6 +297,7 @@ extern BOOL query_ime_char_rect(macdrv_query* query) DECLSPEC_HIDDEN;
extern ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) DECLSPEC_HIDDEN; +extern HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len) DECLSPEC_HIDDEN;
/* string helpers */
@@ -313,6 +314,8 @@ static inline UINT asciiz_to_unicode(WCHAR *dst, const char *src) }
/* FIXME: remove once we use unixlib */ +#define wcsnicmp strncmpiW #define wcsrchr strrchrW +#define wcstol strtolW
#endif /* __WINE_MACDRV_H */ diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index eb693ba968d..134842bbbfb 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -103,7 +103,7 @@ const char* debugstr_cf(CFTypeRef t) }
-static HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len) +HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len) { UNICODE_STRING nameW = { name_len, name_len, (WCHAR *)name }; OBJECT_ATTRIBUTES attr;
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 18 ++++---- dlls/winemac.drv/macdrv.h | 5 +++ dlls/winemac.drv/macdrv_main.c | 79 ++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 8 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index 182d5f122a5..7913c5ed7bc 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -46,7 +46,8 @@ struct display_mode_descriptor
BOOL macdrv_EnumDisplaySettingsEx(LPCWSTR devname, DWORD mode, LPDEVMODEW devmode, DWORD flags);
-static const char initial_mode_key[] = "Initial Display Mode"; +static const WCHAR initial_mode_keyW[] = {'I','n','i','t','i','a','l',' ','D','i','s','p','l','a','y', + ' ','M','o','d','e'}; static const WCHAR pixelencodingW[] = {'P','i','x','e','l','E','n','c','o','d','i','n','g',0};
static CFArrayRef modes; @@ -301,13 +302,14 @@ static void init_original_display_mode(void) return;
/* @@ Wine registry key: HKLM\Software\Wine\Mac Driver */ - if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\Wine\Mac Driver", 0, NULL, - 0, KEY_ALL_ACCESS, NULL, &mac_driver_hkey, NULL)) + mac_driver_hkey = reg_create_ascii_key(NULL, "\Registry\Machine\Software\Wine\Mac Driver", + 0, NULL); + if (!mac_driver_hkey) return;
/* @@ Wine registry key: HKLM\Software\Wine\Mac Driver\Initial Display Mode */ - if (RegCreateKeyExA(mac_driver_hkey, initial_mode_key, 0, NULL, - REG_OPTION_VOLATILE, KEY_WRITE, NULL, &parent_hkey, &disposition)) + if (!(parent_hkey = reg_create_key(mac_driver_hkey, initial_mode_keyW, sizeof(initial_mode_keyW), + REG_OPTION_VOLATILE, &disposition))) { parent_hkey = NULL; goto fail; @@ -332,10 +334,10 @@ done:
fail: macdrv_free_displays(displays); - RegCloseKey(parent_hkey); + NtClose(parent_hkey); if (!success && parent_hkey) - RegDeleteTreeA(mac_driver_hkey, initial_mode_key); - RegCloseKey(mac_driver_hkey); + reg_delete_tree(mac_driver_hkey, initial_mode_keyW, sizeof(initial_mode_keyW)); + NtClose(mac_driver_hkey); if (success) inited_original_display_mode = TRUE; } diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index c216cfb994f..922a2df75cb 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -297,6 +297,11 @@ extern BOOL query_ime_char_rect(macdrv_query* query) DECLSPEC_HIDDEN;
extern ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) DECLSPEC_HIDDEN; +extern HKEY reg_create_ascii_key(HKEY root, const char *name, DWORD options, + DWORD *disposition) DECLSPEC_HIDDEN; +extern HKEY reg_create_key(HKEY root, const WCHAR *name, ULONG name_len, + DWORD options, DWORD *disposition) DECLSPEC_HIDDEN; +extern BOOL reg_delete_tree(HKEY parent, const WCHAR *name, ULONG name_len) DECLSPEC_HIDDEN; extern HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len) DECLSPEC_HIDDEN;
/* string helpers */ diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index 134842bbbfb..b168e12439c 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -24,6 +24,8 @@ #include <Security/AuthSession.h> #include <IOKit/pwr_mgt/IOPMLib.h>
+#include "ntstatus.h" +#define WIN32_NO_STATUS #include "macdrv.h" #include "winuser.h" #include "winreg.h" @@ -152,6 +154,83 @@ static HKEY open_hkcu_key(const char *name) }
+/* wrapper for NtCreateKey that creates the key recursively if necessary */ +HKEY reg_create_key(HKEY root, const WCHAR *name, ULONG name_len, + DWORD options, DWORD *disposition) +{ + UNICODE_STRING nameW = { name_len, name_len, (WCHAR *)name }; + OBJECT_ATTRIBUTES attr; + NTSTATUS status; + HANDLE ret; + + attr.Length = sizeof(attr); + attr.RootDirectory = root; + attr.ObjectName = &nameW; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + + status = NtCreateKey(&ret, MAXIMUM_ALLOWED, &attr, 0, NULL, options, disposition); + if (status == STATUS_OBJECT_NAME_NOT_FOUND) + { + static const WCHAR registry_rootW[] = { '\','R','e','g','i','s','t','r','y','\' }; + DWORD pos = 0, i = 0, len = name_len / sizeof(WCHAR); + + /* don't try to create registry root */ + if (!root && len > ARRAY_SIZE(registry_rootW) && + !memcmp(name, registry_rootW, sizeof(registry_rootW))) + i += ARRAY_SIZE(registry_rootW); + + while (i < len && name[i] != '\') i++; + if (i == len) return 0; + for (;;) + { + unsigned int subkey_options = options; + if (i < len) subkey_options &= ~(REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK); + nameW.Buffer = (WCHAR *)name + pos; + nameW.Length = (i - pos) * sizeof(WCHAR); + status = NtCreateKey(&ret, MAXIMUM_ALLOWED, &attr, 0, NULL, subkey_options, disposition); + + if (attr.RootDirectory != root) NtClose(attr.RootDirectory); + if (!NT_SUCCESS(status)) return 0; + if (i == len) break; + attr.RootDirectory = ret; + while (i < len && name[i] == '\') i++; + pos = i; + while (i < len && name[i] != '\') i++; + } + } + return ret; +} + + +HKEY reg_create_ascii_key(HKEY root, const char *name, DWORD options, DWORD *disposition) +{ + WCHAR buf[256]; + return reg_create_key(root, buf, asciiz_to_unicode(buf, name) - sizeof(WCHAR), + options, disposition); +} + + +BOOL reg_delete_tree(HKEY parent, const WCHAR *name, ULONG name_len) +{ + char buffer[4096]; + KEY_NODE_INFORMATION *key_info = (KEY_NODE_INFORMATION *)buffer; + DWORD size; + HKEY key; + BOOL ret = TRUE; + + if (!(key = reg_open_key(parent, name, name_len))) return FALSE; + + while (ret && !NtEnumerateKey(key, 0, KeyNodeInformation, key_info, sizeof(buffer), &size)) + ret = reg_delete_tree(key, key_info->Name, key_info->NameLength); + + if (ret) ret = !NtDeleteKey(key); + NtClose(key); + return ret; +} + + ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) { UNICODE_STRING str;
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index 7913c5ed7bc..dc294df65ff 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -229,6 +229,7 @@ static BOOL write_display_settings(HKEY parent_hkey, CGDirectDisplayID displayID char display_key_name[19]; HKEY display_hkey; CGDisplayModeRef display_mode; + UNICODE_STRING str; DWORD val; CFStringRef pixel_encoding; size_t len; @@ -236,8 +237,7 @@ static BOOL write_display_settings(HKEY parent_hkey, CGDirectDisplayID displayID
snprintf(display_key_name, sizeof(display_key_name), "Display 0x%08x", CGDisplayUnitNumber(displayID)); /* @@ Wine registry key: HKLM\Software\Wine\Mac Driver\Initial Display Mode\Display 0xnnnnnnnn */ - if (RegCreateKeyExA(parent_hkey, display_key_name, 0, NULL, - REG_OPTION_VOLATILE, KEY_WRITE, NULL, &display_hkey, NULL)) + if (!(display_hkey = reg_create_ascii_key(parent_hkey, display_key_name, REG_OPTION_VOLATILE, NULL))) return FALSE;
display_mode = CGDisplayCopyDisplayMode(displayID); @@ -245,26 +245,26 @@ static BOOL write_display_settings(HKEY parent_hkey, CGDirectDisplayID displayID goto fail;
val = CGDisplayModeGetWidth(display_mode); - if (RegSetValueExA(display_hkey, "Width", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) + if (!set_setting_value(display_hkey, "Width", val)) goto fail; val = CGDisplayModeGetHeight(display_mode); - if (RegSetValueExA(display_hkey, "Height", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) + if (!set_setting_value(display_hkey, "Height", val)) goto fail; val = CGDisplayModeGetRefreshRate(display_mode) * 100; - if (RegSetValueExA(display_hkey, "RefreshRateTimes100", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) + if (!set_setting_value(display_hkey, "RefreshRateTimes100", val)) goto fail; val = CGDisplayModeGetIOFlags(display_mode); - if (RegSetValueExA(display_hkey, "IOFlags", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) + if (!set_setting_value(display_hkey, "IOFlags", val)) goto fail;
#if defined(MAC_OS_X_VERSION_10_8) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 if (&CGDisplayModeGetPixelWidth != NULL && &CGDisplayModeGetPixelHeight != NULL) { val = CGDisplayModeGetPixelWidth(display_mode); - if (RegSetValueExA(display_hkey, "PixelWidth", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) + if (!set_setting_value(display_hkey, "PixelWidth", val)) goto fail; val = CGDisplayModeGetPixelHeight(display_mode); - if (RegSetValueExA(display_hkey, "PixelHeight", 0, REG_DWORD, (const BYTE*)&val, sizeof(val))) + if (!set_setting_value(display_hkey, "PixelHeight", val)) goto fail; } #endif @@ -275,7 +275,8 @@ static BOOL write_display_settings(HKEY parent_hkey, CGDirectDisplayID displayID CFStringGetCharacters(pixel_encoding, CFRangeMake(0, len), (UniChar*)buf); buf[len] = 0; CFRelease(pixel_encoding); - if (RegSetValueExW(display_hkey, pixelencodingW, 0, REG_SZ, (const BYTE*)buf, (len + 1) * sizeof(WCHAR))) + RtlInitUnicodeString(&str, pixelencodingW); + if (NtSetValueKey(display_hkey, &str, 0, REG_SZ, (const BYTE*)buf, (len + 1) * sizeof(WCHAR))) goto fail;
ret = TRUE; @@ -283,9 +284,12 @@ static BOOL write_display_settings(HKEY parent_hkey, CGDirectDisplayID displayID fail: HeapFree(GetProcessHeap(), 0, buf); if (display_mode) CGDisplayModeRelease(display_mode); - RegCloseKey(display_hkey); + NtClose(display_hkey); if (!ret) - RegDeleteKeyA(parent_hkey, display_key_name); + { + WCHAR nameW[64]; + reg_delete_tree(parent_hkey, nameW, asciiz_to_unicode(nameW, display_key_name) - sizeof(WCHAR)); + } return ret; }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/display.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/dlls/winemac.drv/display.c b/dlls/winemac.drv/display.c index dc294df65ff..c6b54c5fd82 100644 --- a/dlls/winemac.drv/display.c +++ b/dlls/winemac.drv/display.c @@ -349,9 +349,13 @@ fail:
static BOOL read_dword(HKEY hkey, const char* name, DWORD* val) { - DWORD type, size = sizeof(*val); - if (RegQueryValueExA(hkey, name, 0, &type, (BYTE*)val, &size) || type != REG_DWORD || size != sizeof(*val)) + char buffer[offsetof(KEY_VALUE_PARTIAL_INFORMATION, Data[sizeof(*val)])]; + KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer; + WCHAR nameW[64]; + asciiz_to_unicode(nameW, name); + if (query_reg_value(hkey, nameW, value, sizeof(buffer)) != sizeof(*val) || value->Type != REG_DWORD) return FALSE; + *val = *(DWORD *)value->Data; return TRUE; }
@@ -369,20 +373,22 @@ static void free_display_mode_descriptor(struct display_mode_descriptor* desc)
static struct display_mode_descriptor* create_original_display_mode_descriptor(CGDirectDisplayID displayID) { - static const char display_key_format[] = "Software\Wine\Mac Driver\Initial Display Mode\Display 0x%08x"; + static const char display_key_format[] = + "\Registry\Machine\Software\Wine\Mac Driver\Initial Display Mode\Display 0x%08x"; struct display_mode_descriptor* ret = NULL; struct display_mode_descriptor* desc; char display_key[sizeof(display_key_format) + 10]; + WCHAR nameW[ARRAYSIZE(display_key)]; + char buffer[4096]; + KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer; HKEY hkey; - DWORD type, size; DWORD refresh100; - WCHAR* pixel_encoding = NULL;
init_original_display_mode();
snprintf(display_key, sizeof(display_key), display_key_format, CGDisplayUnitNumber(displayID)); /* @@ Wine registry key: HKLM\Software\Wine\Mac Driver\Initial Display Mode\Display 0xnnnnnnnn */ - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, display_key, 0, KEY_READ, &hkey)) + if (!(hkey = reg_open_key(NULL, nameW, asciiz_to_unicode(nameW, display_key)))) return NULL;
desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc)); @@ -405,22 +411,17 @@ static struct display_mode_descriptor* create_original_display_mode_descriptor(C desc->pixel_height = desc->height; }
- size = 0; - if (RegQueryValueExW(hkey, pixelencodingW, 0, &type, NULL, &size) || type != REG_SZ) + if (!query_reg_value(hkey, pixelencodingW, value, sizeof(buffer)) || value->Type != REG_SZ) goto done; - size += sizeof(WCHAR); - pixel_encoding = HeapAlloc(GetProcessHeap(), 0, size); - if (RegQueryValueExW(hkey, pixelencodingW, 0, &type, (BYTE*)pixel_encoding, &size) || type != REG_SZ) - goto done; - desc->pixel_encoding = CFStringCreateWithCharacters(NULL, (const UniChar*)pixel_encoding, strlenW(pixel_encoding)); + desc->pixel_encoding = CFStringCreateWithCharacters(NULL, (const UniChar*)value->Data, + lstrlenW((const WCHAR *)value->Data));
ret = desc;
done: if (!ret) free_display_mode_descriptor(desc); - HeapFree(GetProcessHeap(), 0, pixel_encoding); - RegCloseKey(hkey); + NtClose(hkey); return ret; }
From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winemac.drv/Makefile.in | 2 +- dlls/winemac.drv/macdrv.h | 1 + dlls/winemac.drv/macdrv_main.c | 2 +- dlls/winemac.drv/mouse.c | 16 ++++++++-------- 4 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/dlls/winemac.drv/Makefile.in b/dlls/winemac.drv/Makefile.in index da2e5eaf4c4..e345249aac7 100644 --- a/dlls/winemac.drv/Makefile.in +++ b/dlls/winemac.drv/Makefile.in @@ -1,6 +1,6 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES MODULE = winemac.drv -IMPORTS = uuid rpcrt4 user32 gdi32 advapi32 win32u +IMPORTS = uuid rpcrt4 user32 gdi32 win32u DELAYIMPORTS = ole32 shell32 imm32 EXTRALIBS = -framework AppKit -framework Carbon -framework Security -framework OpenGL -framework IOKit -framework CoreVideo -framework QuartzCore $(METAL_LIBS)
diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index 922a2df75cb..0a0c42aefd0 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -295,6 +295,7 @@ extern BOOL query_ime_char_rect(macdrv_query* query) DECLSPEC_HIDDEN;
/* registry helpers */
+extern HKEY open_hkcu_key( const char *name ) DECLSPEC_HIDDEN; extern ULONG query_reg_value(HKEY hkey, const WCHAR *name, KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size) DECLSPEC_HIDDEN; extern HKEY reg_create_ascii_key(HKEY root, const char *name, DWORD options, diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c index b168e12439c..5f61c9491b7 100644 --- a/dlls/winemac.drv/macdrv_main.c +++ b/dlls/winemac.drv/macdrv_main.c @@ -122,7 +122,7 @@ HKEY reg_open_key(HKEY root, const WCHAR *name, ULONG name_len) }
-static HKEY open_hkcu_key(const char *name) +HKEY open_hkcu_key(const char *name) { WCHAR bufferW[256]; static HKEY hkcu; diff --git a/dlls/winemac.drv/mouse.c b/dlls/winemac.drv/mouse.c index 34d6febdefa..55bed52ae8e 100644 --- a/dlls/winemac.drv/mouse.c +++ b/dlls/winemac.drv/mouse.c @@ -195,17 +195,17 @@ CFStringRef copy_system_cursor_name(ICONINFOEXW *info) else sprintfW(p, idW, info->wResID);
/* @@ Wine registry key: HKCU\Software\Wine\Mac Driver\Cursors */ - if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\Wine\Mac Driver\Cursors", &key)) + if (!(key = open_hkcu_key("Software\Wine\Mac Driver\Cursors"))) { - WCHAR value[64]; - DWORD size, ret; + char buffer[2048]; + KEY_VALUE_PARTIAL_INFORMATION *info = (void *)buffer; + DWORD ret;
- value[0] = 0; - size = sizeof(value); - ret = RegQueryValueExW(key, name, NULL, NULL, (BYTE *)value, &size); - RegCloseKey(key); - if (!ret) + ret = query_reg_value(key, name, info, sizeof(buffer)); + NtClose(key); + if (ret) { + const WCHAR *value = (const WCHAR *)info->Data; if (!value[0]) { TRACE("registry forces standard cursor for %s\n", debugstr_w(name));
This merge request was approved by Huw Davies.