mirror of https://github.com/libsdl-org/SDL
Don't clobber an existing entry with a different version when adding a gamepad mapping
This commit is contained in:
parent
9e14559e80
commit
727c7d4e2f
|
@ -772,7 +772,7 @@ static GamepadMapping_t *SDL_PrivateMatchGamepadMappingForGUID(SDL_JoystickGUID
|
|||
/*
|
||||
* Helper function to scan the mappings database for a gamepad with the specified GUID
|
||||
*/
|
||||
static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_JoystickGUID guid, SDL_bool create_mapping)
|
||||
static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_JoystickGUID guid, SDL_bool adding_mapping)
|
||||
{
|
||||
GamepadMapping_t *mapping;
|
||||
Uint16 vendor, product, crc;
|
||||
|
@ -792,6 +792,13 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_JoystickGUID gu
|
|||
return mapping;
|
||||
}
|
||||
|
||||
if (adding_mapping) {
|
||||
/* We didn't find an existing mapping */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Try harder to get the best match, or create a mapping */
|
||||
|
||||
if (vendor && product) {
|
||||
/* Try again, ignoring the version */
|
||||
if (crc) {
|
||||
|
@ -807,30 +814,24 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_JoystickGUID gu
|
|||
}
|
||||
}
|
||||
|
||||
if (!create_mapping) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if SDL_JOYSTICK_XINPUT
|
||||
if (SDL_IsJoystickXInput(guid)) {
|
||||
/* This is an XInput device */
|
||||
return s_pXInputMapping;
|
||||
}
|
||||
#endif
|
||||
if (mapping == NULL) {
|
||||
if (SDL_IsJoystickHIDAPI(guid)) {
|
||||
mapping = SDL_CreateMappingForHIDAPIGamepad(guid);
|
||||
} else if (SDL_IsJoystickRAWINPUT(guid)) {
|
||||
mapping = SDL_CreateMappingForRAWINPUTGamepad(guid);
|
||||
} else if (SDL_IsJoystickWGI(guid)) {
|
||||
mapping = SDL_CreateMappingForWGIGamepad(guid);
|
||||
} else if (SDL_IsJoystickVIRTUAL(guid)) {
|
||||
/* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
|
||||
if (SDL_IsJoystickHIDAPI(guid)) {
|
||||
mapping = SDL_CreateMappingForHIDAPIGamepad(guid);
|
||||
} else if (SDL_IsJoystickRAWINPUT(guid)) {
|
||||
mapping = SDL_CreateMappingForRAWINPUTGamepad(guid);
|
||||
} else if (SDL_IsJoystickWGI(guid)) {
|
||||
mapping = SDL_CreateMappingForWGIGamepad(guid);
|
||||
} else if (SDL_IsJoystickVIRTUAL(guid)) {
|
||||
/* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
|
||||
#ifdef __ANDROID__
|
||||
} else {
|
||||
mapping = SDL_CreateMappingForAndroidGamepad(guid);
|
||||
} else {
|
||||
mapping = SDL_CreateMappingForAndroidGamepad(guid);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
|
@ -1278,7 +1279,7 @@ static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, co
|
|||
}
|
||||
}
|
||||
|
||||
pGamepadMapping = SDL_PrivateGetGamepadMappingForGUID(jGUID, SDL_FALSE);
|
||||
pGamepadMapping = SDL_PrivateGetGamepadMappingForGUID(jGUID, SDL_TRUE);
|
||||
if (pGamepadMapping) {
|
||||
/* Only overwrite the mapping if the priority is the same or higher. */
|
||||
if (pGamepadMapping->priority <= priority) {
|
||||
|
@ -1340,7 +1341,7 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForNameAndGUID(const char *
|
|||
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_TRUE);
|
||||
mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_FALSE);
|
||||
#ifdef __LINUX__
|
||||
if (mapping == NULL && name) {
|
||||
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
|
||||
|
@ -1772,7 +1773,7 @@ char *SDL_GetGamepadMappingForGUID(SDL_JoystickGUID guid)
|
|||
|
||||
SDL_LockJoysticks();
|
||||
{
|
||||
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_TRUE);
|
||||
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMappingForGUID(guid, SDL_FALSE);
|
||||
if (mapping) {
|
||||
retval = CreateMappingString(mapping, guid);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue