From 7153df848a92d76f1fed069c71ec7314204ab144 Mon Sep 17 00:00:00 2001 From: Pieter Hulshoff Date: Sun, 19 Apr 2020 12:37:04 +0200 Subject: [PATCH] Added support for reboot key. --- RetroFE/Source/Control/UserInput.cpp | 1 + RetroFE/Source/Control/UserInput.h | 1 + RetroFE/Source/Database/Configuration.cpp | 7 ++++++ RetroFE/Source/Database/Configuration.h | 1 + RetroFE/Source/Main.cpp | 23 +++++++++++--------- RetroFE/Source/RetroFE.cpp | 26 ++++++++++++++++------- RetroFE/Source/RetroFE.h | 3 ++- RetroFE/Source/Version.cpp | 2 +- 8 files changed, 44 insertions(+), 20 deletions(-) diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index 659210f..89eb3b5 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -75,6 +75,7 @@ bool UserInput::initialize() MapKey("removePlaylist", KeyCodeRemovePlaylist, false); MapKey("random", KeyCodeRandom, false); MapKey("menu", KeyCodeMenu, false); + MapKey("reboot", KeyCodeReboot, false); bool retVal = true; diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index 12559fd..c280811 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -62,6 +62,7 @@ public: KeyCodeAdminMode, KeyCodeHideItem, KeyCodeQuit, + KeyCodeReboot, KeyCodeMax }; diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index 3a656d1..c58478a 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -96,6 +96,13 @@ void Configuration::initialize() } } + +void Configuration::clearProperties( ) +{ + properties_.clear( ); +} + + bool Configuration::import(std::string keyPrefix, std::string file) { return import("", keyPrefix, file); diff --git a/RetroFE/Source/Database/Configuration.h b/RetroFE/Source/Database/Configuration.h index 1ab8c63..dd0be7f 100644 --- a/RetroFE/Source/Database/Configuration.h +++ b/RetroFE/Source/Database/Configuration.h @@ -27,6 +27,7 @@ public: static void initialize(); static std::string convertToAbsolutePath(std::string prefix, std::string path); static std::string trimEnds(std::string str); + void clearProperties( ); // gets the global configuration bool import(std::string keyPrefix, std::string file); bool import(std::string collection, std::string keyPrefix, std::string file, bool mustExist = true); diff --git a/RetroFE/Source/Main.cpp b/RetroFE/Source/Main.cpp index a7eb66a..8ea8055 100644 --- a/RetroFE/Source/Main.cpp +++ b/RetroFE/Source/Main.cpp @@ -90,19 +90,22 @@ int main(int argc, char **argv) return 0; } - - if(!ImportConfiguration(&config)) + while (true) { - // Exit with a heads up... - std::string logFile = Utils::combinePath(Configuration::absolutePath, "log.txt"); - fprintf(stderr, "RetroFE has failed to start due to configuration error.\nCheck log for details: %s\n", logFile.c_str()); - return -1; + if(!ImportConfiguration(&config)) + { + // Exit with a heads up... + std::string logFile = Utils::combinePath(Configuration::absolutePath, "log.txt"); + fprintf(stderr, "RetroFE has failed to start due to configuration error.\nCheck log for details: %s\n", logFile.c_str()); + return -1; + } + RetroFE p(config); + if (p.run()) // Check if we need to reboot after running + config.clearProperties( ); + else + break; } - RetroFE p(config); - - p.run(); - Logger::deInitialize(); return 0; diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 8a1ac8d..36f5db1 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -69,6 +69,7 @@ RetroFE::RetroFE( Configuration &c ) , lastLaunchReturnTime_(0) , keyLastTime_(0) , keyDelayTime_(.3f) + , reboot_(false) { menuMode_ = false; attractMode_ = false; @@ -260,18 +261,21 @@ bool RetroFE::deInitialize( ) initialized = false; - Logger::write( Logger::ZONE_INFO, "RetroFE", "Exiting" ); + if ( reboot_ ) + Logger::write( Logger::ZONE_INFO, "RetroFE", "Rebooting" ); + else + Logger::write( Logger::ZONE_INFO, "RetroFE", "Exiting" ); return retVal; } // Run RetroFE -void RetroFE::run( ) +bool RetroFE::run( ) { // Initialize SDL - if(! SDL::initialize( config_ ) ) return; + if(! SDL::initialize( config_ ) ) return false; fontcache_.initialize( ); // Define control configuration @@ -279,7 +283,7 @@ void RetroFE::run( ) if ( !config_.import( "controls", controlsConfPath ) ) { Logger::write( Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + controlsConfPath + "\"" ); - return; + return false; } float preloadTime = 0; @@ -299,7 +303,7 @@ void RetroFE::run( ) if ( !initializeThread ) { Logger::write( Logger::ZONE_INFO, "RetroFE", "Could not initialize RetroFE" ); - return; + return false; } int attractModeTime = 0; @@ -1172,9 +1176,7 @@ void RetroFE::run( ) // Wait for onExit animation to finish before quitting RetroFE case RETROFE_QUIT: if ( currentPage_->isGraphicsIdle( ) ) - { - running = false; - } + running = false; break; } @@ -1252,6 +1254,7 @@ void RetroFE::run( ) render( ); } } + return reboot_; } @@ -1515,6 +1518,13 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page ) attract_.reset( ); state = RETROFE_QUIT_REQUEST; } + + else if (input_.keystate(UserInput::KeyCodeReboot)) + { + attract_.reset( ); + reboot_ = true; + state = RETROFE_QUIT_REQUEST; + } } // Check if we're done scrolling diff --git a/RetroFE/Source/RetroFE.h b/RetroFE/Source/RetroFE.h index ad9928e..33b0e3f 100644 --- a/RetroFE/Source/RetroFE.h +++ b/RetroFE/Source/RetroFE.h @@ -44,7 +44,7 @@ public: RetroFE( Configuration &c ); virtual ~RetroFE( ); bool deInitialize( ); - void run( ); + bool run( ); void freeGraphicsMemory( ); void allocateGraphicsMemory( ); void launchEnter( ); @@ -134,6 +134,7 @@ private: AttractMode attract_; bool menuMode_; bool attractMode_; + bool reboot_; std::map lastMenuOffsets_; std::map lastMenuPlaylists_; diff --git a/RetroFE/Source/Version.cpp b/RetroFE/Source/Version.cpp index a0ab4a8..869a8a5 100644 --- a/RetroFE/Source/Version.cpp +++ b/RetroFE/Source/Version.cpp @@ -21,7 +21,7 @@ std::string retrofe_version_major = "0"; std::string retrofe_version_minor = "9"; -std::string retrofe_version_build = "32"; +std::string retrofe_version_build = "33"; std::string Version::getString( )