diff --git a/src/win32_joystick.c b/src/win32_joystick.c index a68a9b4d1..c96937b20 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -27,6 +27,7 @@ #include "internal.h" +#include #include @@ -45,6 +46,50 @@ static float calcJoystickPos(DWORD pos, DWORD min, DWORD max) return (2.f * (fpos - fmin) / (fmax - fmin)) - 1.f; } +static int calcJoystickName( int joy, WCHAR * dest, const WCHAR *szRegKey ) +{ + HKEY hKey, hLoc; + WCHAR temp[256]; + DWORD size; + char key[256]; + int result; + + size = sizeof(temp); + _snwprintf ( temp, size, L"%s\\%s\\%s", REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR ); + hLoc = HKEY_LOCAL_MACHINE; + result = RegOpenKeyEx( hLoc, temp, 0, KEY_READ, &hKey); + if ( result != ERROR_SUCCESS ) + { + hLoc = HKEY_CURRENT_USER; + result = RegOpenKeyEx( hLoc, temp, 0, KEY_READ, &hKey); + if( result != ERROR_SUCCESS) + return 0; + } + + _snwprintf ( temp, size, L"Joystick%d%s", joy + 1, REGSTR_VAL_JOYOEMNAME ); + + size = sizeof(key); + result = RegQueryValueEx(hKey, temp, 0, 0, (LPBYTE)key, (LPDWORD)&size); + RegCloseKey ( hKey ); + + if ( result != ERROR_SUCCESS ) + return 0; + + size = sizeof(temp); + _snwprintf ( temp, size, L"%s\\%s", REGSTR_PATH_JOYOEM, key ); + result = RegOpenKeyEx ( hLoc, temp, 0, KEY_QUERY_VALUE, &hKey ); + if ( result != ERROR_SUCCESS ) + return 0; + + size = sizeof(temp); + result = RegQueryValueEx ( hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, (LPBYTE)dest, (LPDWORD)&size ); + RegCloseKey ( hKey ); + + if ( result != ERROR_SUCCESS ) + return 0; + + return 1; +} ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// @@ -164,14 +209,18 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) const char* _glfwPlatformGetJoystickName(int joy) { + WCHAR name[256]; JOYCAPS jc; if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) return NULL; free(_glfw.win32.joystick[joy].name); - _glfw.win32.joystick[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); + if(calcJoystickName(joy, name, jc.szRegKey) == 0) + return NULL; + + _glfw.win32.joystick[joy].name = _glfwCreateUTF8FromWideString(name); return _glfw.win32.joystick[joy].name; } diff --git a/src/win32_platform.h b/src/win32_platform.h index aecdf272b..335a61ccc 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -69,6 +69,7 @@ #include #include +#include #include