mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 00:20:01 +00:00
(task_autodetect_blissbox) Cleanups
This commit is contained in:
parent
917aba4800
commit
cae5328294
@ -157,7 +157,7 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
/* HID API is available since Windows 2000 */
|
/* HID API is available since Windows 2000 */
|
||||||
#if defined(_WIN32) && !defined(_XBOX) && !defined(_MSC_VER) && _WIN32_WINNT >= 0x0500
|
#if defined(_WIN32) && !defined(_XBOX) && !defined(_MSC_VER) && _WIN32_WINNT >= 0x0500
|
||||||
HDEVINFO hDeviceInfo;
|
HDEVINFO hDeviceInfo;
|
||||||
SP_DEVINFO_DATA DeviceInfoData;
|
SP_DEVINFO_DATA device_info_data;
|
||||||
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
|
SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
|
||||||
HANDLE hDeviceHandle = INVALID_HANDLE_VALUE;
|
HANDLE hDeviceHandle = INVALID_HANDLE_VALUE;
|
||||||
BOOL bResult = TRUE;
|
BOOL bResult = TRUE;
|
||||||
@ -165,12 +165,11 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
GUID guidDeviceInterface = {0};
|
GUID guidDeviceInterface = {0};
|
||||||
PSP_DEVICE_INTERFACE_DETAIL_DATA
|
PSP_DEVICE_INTERFACE_DETAIL_DATA
|
||||||
pInterfaceDetailData = NULL;
|
pInterfaceDetailData = NULL;
|
||||||
ULONG requiredLength = 0;
|
ULONG required_length = 0;
|
||||||
LPTSTR lpDevicePath = NULL;
|
LPTSTR lp_device_path = NULL;
|
||||||
char *devicePath = NULL;
|
char *device_path = NULL;
|
||||||
DWORD index = 0;
|
DWORD index = 0;
|
||||||
DWORD intIndex = 0;
|
DWORD intIndex = 0;
|
||||||
size_t nLength = 0;
|
|
||||||
unsigned len = 0;
|
unsigned len = 0;
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
char vidPidString[32] = {0};
|
char vidPidString[32] = {0};
|
||||||
@ -211,17 +210,17 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Enumerate all the device interfaces in the device information set. */
|
/* Enumerate all the device interfaces in the device information set. */
|
||||||
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
device_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
|
||||||
|
|
||||||
while (!success)
|
while (!success)
|
||||||
{
|
{
|
||||||
success = SetupDiEnumDeviceInfo(hDeviceInfo, index, &DeviceInfoData);
|
success = SetupDiEnumDeviceInfo(hDeviceInfo, index, &device_info_data);
|
||||||
|
|
||||||
/* Reset for this iteration */
|
/* Reset for this iteration */
|
||||||
if (lpDevicePath)
|
if (lp_device_path)
|
||||||
{
|
{
|
||||||
LocalFree(lpDevicePath);
|
LocalFree(lp_device_path);
|
||||||
lpDevicePath = NULL;
|
lp_device_path = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInterfaceDetailData)
|
if (pInterfaceDetailData)
|
||||||
@ -239,7 +238,7 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
/* Get information about the device interface. */
|
/* Get information about the device interface. */
|
||||||
for (intIndex = 0; (bResult = SetupDiEnumDeviceInterfaces(
|
for (intIndex = 0; (bResult = SetupDiEnumDeviceInterfaces(
|
||||||
hDeviceInfo,
|
hDeviceInfo,
|
||||||
&DeviceInfoData,
|
&device_info_data,
|
||||||
&guidDeviceInterface,
|
&guidDeviceInterface,
|
||||||
intIndex,
|
intIndex,
|
||||||
&deviceInterfaceData)); intIndex++)
|
&deviceInterfaceData)); intIndex++)
|
||||||
@ -265,16 +264,18 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
hDeviceInfo,
|
hDeviceInfo,
|
||||||
&deviceInterfaceData,
|
&deviceInterfaceData,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
&requiredLength,
|
&required_length,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* Check for some other error */
|
/* Check for some other error */
|
||||||
if (!bResult)
|
if (!bResult)
|
||||||
{
|
{
|
||||||
if ((ERROR_INSUFFICIENT_BUFFER == GetLastError()) && (requiredLength > 0))
|
if ( (ERROR_INSUFFICIENT_BUFFER == GetLastError())
|
||||||
|
&& (required_length > 0))
|
||||||
{
|
{
|
||||||
/* we got the size, now allocate buffer */
|
/* we got the size, now allocate buffer */
|
||||||
pInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, requiredLength);
|
pInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)
|
||||||
|
LocalAlloc(LPTR, required_length);
|
||||||
|
|
||||||
if (!pInterfaceDetailData)
|
if (!pInterfaceDetailData)
|
||||||
{
|
{
|
||||||
@ -297,28 +298,31 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
hDeviceInfo,
|
hDeviceInfo,
|
||||||
&deviceInterfaceData,
|
&deviceInterfaceData,
|
||||||
pInterfaceDetailData,
|
pInterfaceDetailData,
|
||||||
requiredLength,
|
required_length,
|
||||||
NULL,
|
NULL,
|
||||||
&DeviceInfoData);
|
&device_info_data);
|
||||||
|
|
||||||
/* Check for some other error */
|
/* Check for some other error */
|
||||||
if (!bResult)
|
if (!bResult)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* copy device path */
|
/* copy device path */
|
||||||
nLength = _tcslen(pInterfaceDetailData->DevicePath) + 1;
|
{
|
||||||
lpDevicePath = (TCHAR*)LocalAlloc(LPTR, nLength * sizeof(TCHAR));
|
size_t nLength = _tcslen(pInterfaceDetailData->DevicePath) + 1;
|
||||||
|
lp_device_path = (TCHAR*)LocalAlloc(LPTR, nLength * sizeof(TCHAR));
|
||||||
|
|
||||||
StringCchCopy(lpDevicePath, nLength, pInterfaceDetailData->DevicePath);
|
strlcpy(lp_device_path,
|
||||||
|
pInterfaceDetailData->DevicePath, nLength);
|
||||||
|
|
||||||
devicePath = (char*)malloc(nLength);
|
device_path = (char*)malloc(nLength);
|
||||||
|
|
||||||
for (len = 0; len < nLength; len++)
|
for (len = 0; len < nLength; len++)
|
||||||
devicePath[len] = lpDevicePath[len];
|
device_path[len] = lp_device_path[len];
|
||||||
|
|
||||||
lpDevicePath[nLength - 1] = 0;
|
lp_device_path[nLength - 1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (strstr(devicePath, vidPidString))
|
if (strstr(device_path, vidPidString))
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +330,7 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lpDevicePath)
|
if (!lp_device_path)
|
||||||
{
|
{
|
||||||
RARCH_ERR("[Autoconf]: No devicepath. Error %d.", GetLastError());
|
RARCH_ERR("[Autoconf]: No devicepath. Error %d.", GetLastError());
|
||||||
goto done;
|
goto done;
|
||||||
@ -335,7 +339,7 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_win3
|
|||||||
found:
|
found:
|
||||||
/* Open the device */
|
/* Open the device */
|
||||||
hDeviceHandle = CreateFileA(
|
hDeviceHandle = CreateFileA(
|
||||||
devicePath,
|
device_path,
|
||||||
GENERIC_READ, /* | GENERIC_WRITE,*/
|
GENERIC_READ, /* | GENERIC_WRITE,*/
|
||||||
FILE_SHARE_READ, /* | FILE_SHARE_WRITE,*/
|
FILE_SHARE_READ, /* | FILE_SHARE_WRITE,*/
|
||||||
NULL,
|
NULL,
|
||||||
@ -352,7 +356,7 @@ found:
|
|||||||
|
|
||||||
/* Open the device */
|
/* Open the device */
|
||||||
hDeviceHandle = CreateFileA(
|
hDeviceHandle = CreateFileA(
|
||||||
devicePath,
|
device_path,
|
||||||
GENERIC_READ | GENERIC_WRITE,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
NULL,
|
NULL,
|
||||||
@ -369,23 +373,20 @@ found:
|
|||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
free(devicePath);
|
free(device_path);
|
||||||
LocalFree(lpDevicePath);
|
LocalFree(lp_device_path);
|
||||||
LocalFree(pInterfaceDetailData);
|
LocalFree(pInterfaceDetailData);
|
||||||
bResult = SetupDiDestroyDeviceInfoList(hDeviceInfo);
|
bResult = SetupDiDestroyDeviceInfoList(hDeviceInfo);
|
||||||
|
device_path = NULL;
|
||||||
devicePath = NULL;
|
lp_device_path = NULL;
|
||||||
lpDevicePath = NULL;
|
|
||||||
pInterfaceDetailData = NULL;
|
pInterfaceDetailData = NULL;
|
||||||
|
|
||||||
if (!bResult)
|
if (!bResult)
|
||||||
RARCH_ERR("[Autoconf]: Could not destroy device info list.\n");
|
RARCH_ERR("[Autoconf]: Could not destroy device info list.\n");
|
||||||
|
|
||||||
|
/* Device is not connected */
|
||||||
if (!hDeviceHandle || hDeviceHandle == INVALID_HANDLE_VALUE)
|
if (!hDeviceHandle || hDeviceHandle == INVALID_HANDLE_VALUE)
|
||||||
{
|
|
||||||
/* device is not connected */
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
report[0] = BLISSBOX_USB_FEATURE_REPORT_ID;
|
report[0] = BLISSBOX_USB_FEATURE_REPORT_ID;
|
||||||
|
|
||||||
@ -393,7 +394,7 @@ done:
|
|||||||
|
|
||||||
CloseHandle(hDeviceHandle);
|
CloseHandle(hDeviceHandle);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(blissbox_pad_types) / sizeof(blissbox_pad_types[0]); i++)
|
for (i = 0; i < ARRAY_SIZE(blissbox_pad_types); i++)
|
||||||
{
|
{
|
||||||
const blissbox_pad_type_t *pad = &blissbox_pad_types[i];
|
const blissbox_pad_type_t *pad = &blissbox_pad_types[i];
|
||||||
|
|
||||||
@ -465,7 +466,7 @@ static const blissbox_pad_type_t* input_autoconfigure_get_blissbox_pad_type_libu
|
|||||||
libusb_close(autoconfig_libusb_handle);
|
libusb_close(autoconfig_libusb_handle);
|
||||||
libusb_exit(NULL);
|
libusb_exit(NULL);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(blissbox_pad_types) / sizeof(blissbox_pad_types[0]); i++)
|
for (i = 0; i < ARRAY_SIZE(blissbox_pad_types); i++)
|
||||||
{
|
{
|
||||||
const blissbox_pad_type_t *pad = &blissbox_pad_types[i];
|
const blissbox_pad_type_t *pad = &blissbox_pad_types[i];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user