From eac8a077941b7f2d91bf16fe46c24bb87d21e3fd Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 31 May 2014 18:00:42 -0500 Subject: [PATCH] Added in-ES messagebox when es_systems.cfg errors occur. Fixed an error being caused by HelpStyle initializing before the renderer leading to a Font::get(0) command. Fixed a bug that caused unconfigured inputs to be inserted into InputConfig. --- src/HelpStyle.cpp | 6 +++- src/InputConfig.cpp | 17 +++++++--- src/InputConfig.h | 7 +++-- src/guis/GuiMsgBox.cpp | 9 ++++++ src/main.cpp | 71 +++++++++++++++++++++++++++++++----------- 5 files changed, 84 insertions(+), 26 deletions(-) diff --git a/src/HelpStyle.cpp b/src/HelpStyle.cpp index d14aaf8cf..184bc7bca 100644 --- a/src/HelpStyle.cpp +++ b/src/HelpStyle.cpp @@ -8,7 +8,11 @@ HelpStyle::HelpStyle() position = Eigen::Vector2f(12.0f, Renderer::getScreenHeight() * 0.9515f); iconColor = 0x777777FF; textColor = 0x777777FF; - font = Font::get(FONT_SIZE_SMALL); + + if(FONT_SIZE_SMALL != 0) + font = Font::get(FONT_SIZE_SMALL); + else + font = nullptr; } void HelpStyle::applyTheme(const std::shared_ptr& theme, const std::string& view) diff --git a/src/InputConfig.cpp b/src/InputConfig.cpp index 1c6035fe3..90b272939 100644 --- a/src/InputConfig.cpp +++ b/src/InputConfig.cpp @@ -75,15 +75,24 @@ void InputConfig::unmapInput(const std::string& name) mNameMap.erase(it); } -Input InputConfig::getInputByName(const std::string& name) +bool InputConfig::getInputByName(const std::string& name, Input* result) { - return mNameMap[toLower(name)]; + auto it = mNameMap.find(toLower(name)); + if(it != mNameMap.end()) + { + *result = it->second; + return true; + } + + return false; } bool InputConfig::isMappedTo(const std::string& name, Input input) { - Input comp = getInputByName(name); - + Input comp; + if(!getInputByName(name, &comp)) + return false; + if(comp.configured && comp.type == input.type && comp.id == input.id) { if(comp.type == TYPE_HAT) diff --git a/src/InputConfig.h b/src/InputConfig.h index e498edba5..b007f008a 100644 --- a/src/InputConfig.h +++ b/src/InputConfig.h @@ -93,9 +93,6 @@ public: inline const std::string& getDeviceName() { return mDeviceName; } inline const std::string& getDeviceGUIDString() { return mDeviceGUID; } - //Returns the input mapped to this name. - Input getInputByName(const std::string& name); - //Returns true if Input is mapped to this name, false otherwise. bool isMappedTo(const std::string& name, Input input); @@ -108,6 +105,10 @@ public: bool isConfigured(); private: + // Returns true if there is an Input mapped to this name, false otherwise. + // Writes Input mapped to this name to result if true. + bool getInputByName(const std::string& name, Input* result); + std::map mNameMap; const int mDeviceId; const std::string mDeviceName; diff --git a/src/guis/GuiMsgBox.cpp b/src/guis/GuiMsgBox.cpp index 24fb2574e..abf1c430b 100644 --- a/src/guis/GuiMsgBox.cpp +++ b/src/guis/GuiMsgBox.cpp @@ -4,6 +4,7 @@ #include "../components/ButtonComponent.h" #include "../components/MenuComponent.h" // for makeButtonGrid #include "../Util.h" +#include "../Log.h" #define HORIZONTAL_PADDING_PX 20 @@ -67,6 +68,14 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, bool GuiMsgBox::input(InputConfig* config, Input input) { + // special case for when GuiMsgBox comes up to report errors before anything has been configured + if(config->getDeviceId() == DEVICE_KEYBOARD && !config->isConfigured() && input.value && + (input.id == SDLK_RETURN || input.id == SDLK_ESCAPE || input.id == SDLK_SPACE)) + { + mAcceleratorFunc(); + return true; + } + if(mAcceleratorFunc && config->isMappedTo("b", input) && input.value != 0) { mAcceleratorFunc(); diff --git a/src/main.cpp b/src/main.cpp index 9edcce994..f6125f67b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include "SystemData.h" #include #include "guis/GuiDetectDevice.h" +#include "guis/GuiMsgBox.h" #include "AudioManager.h" #include "platform.h" #include "Log.h" @@ -121,6 +122,32 @@ bool verifyHomeFolderExists() return true; } +// Returns true if everything is OK, +bool loadSystemConfigFile(const char** errorString) +{ + *errorString = NULL; + + if(!SystemData::loadConfig()) + { + LOG(LogError) << "Error while parsing systems configuration file!"; + *errorString = "IT LOOKS LIKE YOUR SYSTEMS CONFIGURATION FILE HAS NOT BEEN SET UP OR IS INVALID. YOU'LL NEED TO DO THIS BY HAND, UNFORTUNATELY.\n\n" + "VISIT EMULATIONSTATION.ORG FOR MORE INFORMATION."; + return false; + } + + if(SystemData::sSystemVector.size() == 0) + { + LOG(LogError) << "No systems found! Does at least one system have a game present? (check that extensions match!)\n(Also, make sure you've updated your es_systems.cfg for XML!)"; + *errorString = "WE CAN'T FIND ANY SYSTEMS!\n" + "CHECK THAT YOUR PATHS ARE CORRECT IN THE SYSTEMS CONFIGURATION FILE, " + "AND YOUR GAME DIRECTORY HAS AT LEAST ONE GAME WITH THE CORRECT EXTENSION.\n\n" + "VISIT EMULATIONSTATION.ORG FOR MORE INFORMATION."; + return false; + } + + return true; +} + //called on exit, assuming we get far enough to have the log initialized void onExit() { @@ -161,22 +188,26 @@ int main(int argc, char* argv[]) window.renderLoadingScreen(); } - //try loading the system config file - if(!SystemData::loadConfig()) + const char* errorMsg = NULL; + if(!loadSystemConfigFile(&errorMsg)) { - LOG(LogError) << "Error parsing system config file!"; - if(!scrape_cmdline) - Renderer::deinit(); - return 1; - } + // something went terribly wrong + if(errorMsg == NULL) + { + LOG(LogError) << "Unknown error occured while parsing system config file."; + if(!scrape_cmdline) + Renderer::deinit(); + return 1; + } - //make sure it wasn't empty - if(SystemData::sSystemVector.size() == 0) - { - LOG(LogError) << "No systems found! Does at least one system have a game present? (check that extensions match!)\n(Also, make sure you've updated your es_systems.cfg for XML!)"; - if(!scrape_cmdline) - Renderer::deinit(); - return 1; + // we can't handle es_systems.cfg file problems inside ES itself, so display the error message then quit + window.pushGui(new GuiMsgBox(&window, + errorMsg, + "QUIT", [] { + SDL_Event* quit = new SDL_Event(); + quit->type = SDL_QUIT; + SDL_PushEvent(quit); + })); } //run the command line scraper then quit @@ -193,11 +224,15 @@ int main(int argc, char* argv[]) window.getViewController()->preload(); //choose which GUI to open depending on if an input configuration already exists - if(fs::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0) + if(errorMsg == NULL) { - window.getViewController()->goToStart(); - }else{ - window.pushGui(new GuiDetectDevice(&window, true)); + if(fs::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0) + { + window.getViewController()->goToStart(); + } + else{ + window.pushGui(new GuiDetectDevice(&window, true)); + } } //generate joystick events since we're done loading