Files
RMG/Source/RMG-Input/Utilities/Sdl3GuidWithIndex.cpp
T

39 lines
1.2 KiB
C++

/*
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
* Copyright (C) 2020-2026 Rosalie Wanders <rosalie@mailbox.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Sdl3GuidWithIndex.hpp"
#include <string>
#include <vector>
#include <SDL3/SDL.h>
using namespace Utilities;
std::string Utilities::Sdl3GuidWithIndex(std::vector<std::string>& guidsWithoutIndex, SDL_JoystickID joystickId)
{
char guidBuffer[33] = {0};
int guidIndex = 0;
std::string guidWithoutIndex;
SDL_GUIDToString(SDL_GetJoystickGUIDForID(joystickId), guidBuffer, sizeof(guidBuffer));
guidWithoutIndex = guidBuffer;
for (const auto& otherDeviceGuidWithoutIndex : guidsWithoutIndex)
{
if (otherDeviceGuidWithoutIndex == guidWithoutIndex)
{
guidIndex++;
}
}
guidsWithoutIndex.push_back(guidWithoutIndex);
return guidWithoutIndex + "/" + std::to_string(guidIndex);
}