Rémi Bernon : dinput: Delete the action mapping registry key on SetActionMap.
Module: wine Branch: master Commit: b95c820557499ad52a386fcc2354a7590573f7c7 URL: https://gitlab.winehq.org/wine/wine/-/commit/b95c820557499ad52a386fcc2354a75... Author: Rémi Bernon <rbernon(a)codeweavers.com> Date: Fri May 19 17:09:52 2023 +0200 dinput: Delete the action mapping registry key on SetActionMap. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54917 --- dlls/dinput/device.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 4db8bd943cb..4f76168a1a3 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -323,19 +323,20 @@ int dinput_device_object_index_from_id( IDirectInputDevice8W *iface, DWORD id ) * Retrieves an open registry key to save the mapping, parametrized for an username, * specific device and specific action mapping guid. */ -static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WCHAR *guid) +static HKEY get_mapping_key( const WCHAR *device, const WCHAR *username, const WCHAR *guid, BOOL delete ) { - static const WCHAR *subkey = L"Software\\Wine\\DirectInput\\Mappings\\%s\\%s\\%s"; - HKEY hkey; + static const WCHAR format[] = L"Software\\Wine\\DirectInput\\Mappings\\%s\\%s\\%s"; + SIZE_T len = wcslen( format ) + wcslen( username ) + wcslen( device ) + wcslen( guid ) + 1; WCHAR *keyname; + HKEY hkey; - SIZE_T len = wcslen( subkey ) + wcslen( username ) + wcslen( device ) + wcslen( guid ) + 1; - keyname = malloc( sizeof(WCHAR) * len ); - swprintf( keyname, len, subkey, username, device, guid ); + if (!(keyname = malloc( sizeof(WCHAR) * len ))) return 0; /* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */ - if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey)) - hkey = 0; + swprintf( keyname, len, format, username, device, guid ); + + if (delete) RegDeleteTreeW( HKEY_CURRENT_USER, keyname ); + if (RegCreateKeyW( HKEY_CURRENT_USER, keyname, &hkey )) hkey = 0; free( keyname ); @@ -355,9 +356,7 @@ static HRESULT save_mapping_settings(IDirectInputDevice8W *iface, LPDIACTIONFORM if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK) return DI_SETTINGSNOTSAVED; - hkey = get_mapping_key(didev.tszInstanceName, lpszUsername, guid_str); - - if (!hkey) + if (!(hkey = get_mapping_key( didev.tszInstanceName, lpszUsername, guid_str, TRUE ))) { CoTaskMemFree(guid_str); return DI_SETTINGSNOTSAVED; @@ -398,9 +397,7 @@ static BOOL load_mapping_settings( struct dinput_device *This, LPDIACTIONFORMATW if (StringFromCLSID(&lpdiaf->guidActionMap, &guid_str) != S_OK) return FALSE; - hkey = get_mapping_key(didev.tszInstanceName, username, guid_str); - - if (!hkey) + if (!(hkey = get_mapping_key( didev.tszInstanceName, username, guid_str, FALSE ))) { CoTaskMemFree(guid_str); return FALSE;
participants (1)
-
Alexandre Julliard