From b058b987ad0f5c4c64a042459fd4719f010d313e Mon Sep 17 00:00:00 2001 From: Neil Munday Date: Mon, 30 Jan 2017 20:26:24 +0000 Subject: [PATCH] Added ability for the user to override the location of the SDL game controller db file. --- SDL/SDLJoystick.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/SDL/SDLJoystick.cpp b/SDL/SDLJoystick.cpp index 1cde440ca1..156e33fde2 100644 --- a/SDL/SDLJoystick.cpp +++ b/SDL/SDLJoystick.cpp @@ -21,15 +21,32 @@ SDLJoystick::SDLJoystick(bool init_SDL ): thread(NULL), running(true) { SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER); } + char* dbEnvPath = getenv("PPSSPP_GAME_CONTROLLER_DB_PATH"); + if (dbEnvPath != NULL) { + if (!File::Exists(dbEnvPath)) { + cout << "WARNING! " << dbEnvPath << " does not exist!" << endl; + } else { + cout << "loading control pad mappings from " << dbEnvPath << ": "; + if (SDL_GameControllerAddMappingsFromFile(dbEnvPath) == -1) { + cout << "FAILED! Will try load from your assests directory instead..." << endl; + } else { + cout << "SUCCESS!" << endl; + setUpControllers(); + return; + } + } + } + auto dbPath = File::GetExeDirectory() + "assets/gamecontrollerdb.txt"; cout << "loading control pad mappings from " << dbPath << ": "; - + if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) == -1) { cout << "FAILED! Please place gamecontrollerdb.txt in your assets directory." << endl; - } else { - cout << "SUCCESS!" << endl; - setUpControllers(); + return; } + + cout << "SUCCESS!" << endl; + setUpControllers(); } void SDLJoystick::setUpControllers() {