I find this clearer, especially with respect to how device_path_guid is handled.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/joystick_hid.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 5fdc563054b..e54d50f8bfa 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2035,19 +2035,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
*out = NULL; - instance.guidProduct.Data1 = dinput_pidvid_guid.Data1; - instance.guidInstance.Data1 = hid_joystick_guid.Data1; - if (IsEqualGUID( &dinput_pidvid_guid, &instance.guidProduct )) - instance.guidProduct = *guid; - else if (IsEqualGUID( &hid_joystick_guid, &instance.guidInstance )) - instance.guidInstance = *guid; - else - { - instance.guidInstance.Data1 = device_path_guid.Data1; - instance.guidInstance.Data2 = device_path_guid.Data2; - instance.guidInstance.Data3 = device_path_guid.Data3; - if (!IsEqualGUID( &device_path_guid, &instance.guidInstance )) return DIERR_DEVICENOTREG; - }
if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; dinput_device_init( &impl->base, &hid_joystick_vtbl, guid, dinput ); @@ -2056,15 +2043,31 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi impl->base.read_event = CreateEventW( NULL, TRUE, FALSE, NULL ); impl->internal_ref = 1;
- if (!IsEqualGUID( &device_path_guid, &instance.guidInstance )) + instance.guidProduct.Data1 = dinput_pidvid_guid.Data1; + instance.guidInstance.Data1 = hid_joystick_guid.Data1; + if (IsEqualGUID( &dinput_pidvid_guid, &instance.guidProduct )) + { + instance.guidProduct = *guid; hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed, &attrs, &impl->caps, dinput->dwVersion ); - else + } + else if (IsEqualGUID( &hid_joystick_guid, &instance.guidInstance )) + { + instance.guidInstance = *guid; + hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed, + &attrs, &impl->caps, dinput->dwVersion ); + } + else if (!memcmp( &device_path_guid.Data4, instance.guidInstance.Data4, sizeof(device_path_guid.Data4) )) { wcscpy( impl->device_path, *(const WCHAR **)guid ); hr = hid_joystick_device_try_open( 0, impl->device_path, &impl->device, &impl->preparsed, &attrs, &impl->caps, &instance, dinput->dwVersion ); } + else + { + hr = DIERR_DEVICENOTREG; + } + if (hr != DI_OK) goto failed;
impl->base.instance = instance;
We set the instance and product IDs for all joysticks to match the latter parts of hid_joystick_guid and dinput_pidvid_guid, respectively. Therefore there is no need to manually check which one we are matching against.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/joystick_hid.c | 51 +++++++++++--------------------------- 1 file changed, 14 insertions(+), 37 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index e54d50f8bfa..f9f34d0e5e3 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1564,15 +1564,14 @@ failed: return DIERR_DEVICENOTREG; }
-static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, WCHAR *device_path, - HANDLE *device, PHIDP_PREPARSED_DATA *preparsed, +static HRESULT hid_joystick_device_open( int index, const GUID *guid, DIDEVICEINSTANCEW *instance, + WCHAR *device_path, HANDLE *device, PHIDP_PREPARSED_DATA *preparsed, HIDD_ATTRIBUTES *attrs, HIDP_CAPS *caps, DWORD version ) { char buffer[sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W) + MAX_PATH * sizeof(WCHAR)]; SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail = (void *)buffer; SP_DEVICE_INTERFACE_DATA iface = {.cbSize = sizeof(iface)}; SP_DEVINFO_DATA devinfo = {.cbSize = sizeof(devinfo)}; - DIDEVICEINSTANCEW instance = *filter; WCHAR device_id[MAX_PATH], *tmp; HDEVINFO set, xi_set; UINT32 i = 0, handle; @@ -1580,8 +1579,7 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W DWORD type; GUID hid;
- TRACE( "index %d, product %s, instance %s\n", index, debugstr_guid( &filter->guidProduct ), - debugstr_guid( &filter->guidInstance ) ); + TRACE( "index %d, guid %s\n", index, debugstr_guid( guid ) );
HidD_GetHidGuid( &hid );
@@ -1601,10 +1599,10 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W type != DEVPROP_TYPE_UINT32) continue; if (FAILED(hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed, - attrs, caps, &instance, version ))) + attrs, caps, instance, version ))) continue;
- if (device_instance_is_disabled( &instance, &override )) + if (device_instance_is_disabled( instance, &override )) goto next;
if (override && SetupDiGetDeviceInstanceIdW( set, &devinfo, device_id, MAX_PATH, NULL ) && @@ -1621,13 +1619,13 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W CloseHandle( *device ); HidD_FreePreparsedData( *preparsed ); if (FAILED(hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed, - attrs, caps, &instance, version ))) + attrs, caps, instance, version ))) continue; }
/* enumerate device by GUID */ - if (index < 0 && IsEqualGUID( &filter->guidProduct, &instance.guidProduct )) break; - if (index < 0 && IsEqualGUID( &filter->guidInstance, &instance.guidInstance )) break; + if (guid && (IsEqualGUID( guid, &instance->guidProduct ) || IsEqualGUID( guid, &instance->guidInstance ))) + break;
/* enumerate all devices */ if (index >= 0 && !index--) break; @@ -1644,7 +1642,6 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W if (!*device || !*preparsed) return DIERR_DEVICENOTREG;
lstrcpynW( device_path, detail->DevicePath, MAX_PATH ); - *filter = instance; return DI_OK; }
@@ -1659,7 +1656,7 @@ HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *in
TRACE( "type %#lx, flags %#lx, instance %p, version %#lx, index %d\n", type, flags, instance, version, index );
- hr = hid_joystick_device_open( index, instance, device_path, &device, &preparsed, + hr = hid_joystick_device_open( index, NULL, instance, device_path, &device, &preparsed, &attrs, &caps, version ); if (hr != DI_OK) return hr;
@@ -2008,12 +2005,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi .dwHeaderSize = sizeof(filter), .dwHow = DIPH_DEVICE, }; - DIDEVICEINSTANCEW instance = - { - .dwSize = sizeof(instance), - .guidProduct = *guid, - .guidInstance = *guid - }; DIPROPRANGE range = { .diph = @@ -2043,35 +2034,21 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi impl->base.read_event = CreateEventW( NULL, TRUE, FALSE, NULL ); impl->internal_ref = 1;
- instance.guidProduct.Data1 = dinput_pidvid_guid.Data1; - instance.guidInstance.Data1 = hid_joystick_guid.Data1; - if (IsEqualGUID( &dinput_pidvid_guid, &instance.guidProduct )) - { - instance.guidProduct = *guid; - hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed, - &attrs, &impl->caps, dinput->dwVersion ); - } - else if (IsEqualGUID( &hid_joystick_guid, &instance.guidInstance )) - { - instance.guidInstance = *guid; - hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed, - &attrs, &impl->caps, dinput->dwVersion ); - } - else if (!memcmp( &device_path_guid.Data4, instance.guidInstance.Data4, sizeof(device_path_guid.Data4) )) + if (!memcmp( device_path_guid.Data4, guid->Data4, sizeof(device_path_guid.Data4) )) { wcscpy( impl->device_path, *(const WCHAR **)guid ); hr = hid_joystick_device_try_open( 0, impl->device_path, &impl->device, &impl->preparsed, &attrs, - &impl->caps, &instance, dinput->dwVersion ); + &impl->caps, &impl->base.instance, dinput->dwVersion ); } else { - hr = DIERR_DEVICENOTREG; + hr = hid_joystick_device_open( -1, guid, &impl->base.instance, impl->device_path, &impl->device, + &impl->preparsed, &attrs, &impl->caps, dinput->dwVersion ); }
if (hr != DI_OK) goto failed;
- impl->base.instance = instance; - impl->base.caps.dwDevType = instance.dwDevType; + impl->base.caps.dwDevType = impl->base.instance.dwDevType; impl->attrs = attrs; list_init( &impl->effect_list );