Although not completely correct it should be usable already, and running the tests would require setting the registry key before and cleaning it up after otherwise.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 9 +++---- dlls/dinput/device_private.h | 2 +- dlls/dinput/joystick.c | 44 ++++++++++++++++++++++++---------- dlls/dinput/joystick_hid.c | 3 +-- dlls/dinput/joystick_private.h | 1 + dlls/dinput/mouse.c | 11 +++++---- 6 files changed, 44 insertions(+), 26 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 25084f82a9c..e04d40e5a7c 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -305,14 +305,11 @@ BOOL get_app_key(HKEY *defkey, HKEY *appkey) /****************************************************************************** * Get a config key from either the app-specific or the default config */ -DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name, - char *buffer, DWORD size ) +DWORD get_config_key( HKEY defkey, HKEY appkey, const WCHAR *name, WCHAR *buffer, DWORD size ) { - if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) - return 0; + if (appkey && !RegQueryValueExW( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
- if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) - return 0; + if (defkey && !RegQueryValueExW( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
return ERROR_FILE_NOT_FOUND; } diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 0e72ee77bf1..90eab627c26 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -97,7 +97,7 @@ extern HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8 extern const IDirectInputDevice8AVtbl dinput_device_a_vtbl DECLSPEC_HIDDEN;
extern BOOL get_app_key(HKEY*, HKEY*) DECLSPEC_HIDDEN; -extern DWORD get_config_key(HKEY, HKEY, const char*, char*, DWORD) DECLSPEC_HIDDEN; +extern DWORD get_config_key( HKEY, HKEY, const WCHAR *, WCHAR *, DWORD ) DECLSPEC_HIDDEN;
/* Routines to do DataFormat / WineFormat conversions */ extern void fill_DataFormat(void *out, DWORD size, const void *in, const DataFormat *df) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c index 60153d0d0f3..d4f5b819471 100644 --- a/dlls/dinput/joystick.c +++ b/dlls/dinput/joystick.c @@ -273,10 +273,18 @@ void dump_DIEFFECT(LPCDIEFFECT eff, REFGUID guid, DWORD dwFlags)
BOOL device_disabled_registry(const char* name, BOOL disable) { - static const char disabled_str[] = "disabled"; - static const char enabled_str[] = "enabled"; - static const char joystick_key[] = "Joysticks"; - char buffer[MAX_PATH]; + DIDEVICEINSTANCEW instance; + + MultiByteToWideChar( CP_ACP, 0, name, -1, instance.tszInstanceName, MAX_PATH ); + return device_instance_is_disabled( &instance, disable ); +} + +BOOL device_instance_is_disabled( DIDEVICEINSTANCEW *instance, BOOL disable ) +{ + static const WCHAR disabled_str[] = {'d', 'i', 's', 'a', 'b', 'l', 'e', 'd', 0}; + static const WCHAR enabled_str[] = {'e', 'n', 'a', 'b', 'l', 'e', 'd', 0}; + static const WCHAR joystick_key[] = {'J', 'o', 'y', 's', 't', 'i', 'c', 'k', 's', 0}; + WCHAR buffer[MAX_PATH]; HKEY hkey, appkey, temp;
get_app_key(&hkey, &appkey); @@ -284,28 +292,29 @@ BOOL device_disabled_registry(const char* name, BOOL disable) /* Joystick settings are in the 'joysticks' subkey */ if (appkey) { - if (RegOpenKeyA(appkey, joystick_key, &temp)) temp = 0; + if (RegOpenKeyW( appkey, joystick_key, &temp )) temp = 0; RegCloseKey(appkey); appkey = temp; } + if (hkey) { - if (RegOpenKeyA(hkey, joystick_key, &temp)) temp = 0; + if (RegOpenKeyW( hkey, joystick_key, &temp )) temp = 0; RegCloseKey(hkey); hkey = temp; }
/* Look for the "controllername"="disabled" key */ - if (!get_config_key(hkey, appkey, name, buffer, sizeof(buffer))) + if (!get_config_key( hkey, appkey, instance->tszInstanceName, buffer, sizeof(buffer) )) { - if (!disable && !strcmp(disabled_str, buffer)) + if (!disable && !strcmpW( disabled_str, buffer )) { - TRACE("Disabling joystick '%s' based on registry key.\n", name); + TRACE( "Disabling joystick '%s' based on registry key.\n", debugstr_w(instance->tszInstanceName) ); disable = TRUE; } - else if (disable && !strcmp(enabled_str, buffer)) + else if (disable && !strcmpW( enabled_str, buffer )) { - TRACE("Enabling joystick '%s' based on registry key.\n", name); + TRACE( "Enabling joystick '%s' based on registry key.\n", debugstr_w(instance->tszInstanceName) ); disable = FALSE; } } @@ -854,6 +863,15 @@ DWORD joystick_map_pov(const POINTL *p) return p->y < 0 ? 0 : !p->y ? -1 : 18000; }
+static DWORD get_config_key_a( HKEY defkey, HKEY appkey, const char *name, char *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; + + return ERROR_FILE_NOT_FOUND; +} + /* * Setup the dinput options. */ @@ -870,7 +888,7 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_
/* get options */
- if (!get_config_key(hkey, appkey, "DefaultDeadZone", buffer, sizeof(buffer))) + if (!get_config_key_a( hkey, appkey, "DefaultDeadZone", buffer, sizeof(buffer) )) { This->deadzone = atoi(buffer); TRACE("setting default deadzone to: "%s" %d\n", buffer, This->deadzone); @@ -879,7 +897,7 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_ This->axis_map = HeapAlloc(GetProcessHeap(), 0, This->device_axis_count * sizeof(int)); if (!This->axis_map) return DIERR_OUTOFMEMORY;
- if (!get_config_key(hkey, appkey, This->name, buffer, sizeof(buffer))) + if (!get_config_key_a( hkey, appkey, This->name, buffer, sizeof(buffer) )) { static const char *axis_names[] = {"X", "Y", "Z", "Rx", "Ry", "Rz", "Slider1", "Slider2", diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 3c69c74b4fc..3ef6f0db9cc 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1043,8 +1043,7 @@ static HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTAN if (version >= 0x0800 && type != DI8DEVCLASS_ALL && type != DI8DEVCLASS_GAMECTRL) return S_FALSE;
- if (device_disabled_registry( "HID", TRUE )) - return DIERR_DEVICENOTREG; + if (device_instance_is_disabled( instance, FALSE )) return DIERR_DEVICENOTREG;
TRACE( "found device %s, usage %04x:%04x, product %s, instance %s, name %s\n", debugstr_w(device_path), instance->wUsagePage, instance->wUsage, debugstr_guid( &instance->guidProduct ), diff --git a/dlls/dinput/joystick_private.h b/dlls/dinput/joystick_private.h index 9cc30605234..4fe51d17067 100644 --- a/dlls/dinput/joystick_private.h +++ b/dlls/dinput/joystick_private.h @@ -58,6 +58,7 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_ DWORD joystick_map_pov(const POINTL *p) DECLSPEC_HIDDEN;
BOOL device_disabled_registry(const char* name, BOOL disable) DECLSPEC_HIDDEN; +BOOL device_instance_is_disabled( DIDEVICEINSTANCEW *instance, BOOL disable ) DECLSPEC_HIDDEN;
ULONG WINAPI JoystickWGenericImpl_Release(LPDIRECTINPUTDEVICE8W iface);
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 145a792f396..9f696cb414a 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -140,10 +140,13 @@ static HRESULT mousedev_enum_device(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEIN
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseImpl **out ) { + static const WCHAR mouse_wrap_override_w[] = {'M','o','u','s','e','W','a','r','p','O','v','e','r','r','i','d','e',0}; + static const WCHAR disable_w[] = {'d','i','s','a','b','l','e',0}; + static const WCHAR force_w[] = {'f','o','r','c','e',0}; SysMouseImpl* newDevice; LPDIDATAFORMAT df = NULL; unsigned i; - char buffer[20]; + WCHAR buffer[20]; HKEY hkey, appkey; HRESULT hr;
@@ -155,11 +158,11 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
get_app_key(&hkey, &appkey); - if (!get_config_key(hkey, appkey, "MouseWarpOverride", buffer, sizeof(buffer))) + if (!get_config_key(hkey, appkey, mouse_wrap_override_w, buffer, sizeof(buffer))) { - if (!_strnicmp(buffer, "disable", -1)) + if (!strncmpiW(buffer, disable_w, -1)) newDevice->warp_override = WARP_DISABLE; - else if (!_strnicmp(buffer, "force", -1)) + else if (!strncmpiW(buffer, force_w, -1)) newDevice->warp_override = WARP_FORCE_ON; } if (appkey) RegCloseKey(appkey);