From 36614540fdd631642c7de7e9aeafdc7c402807cb Mon Sep 17 00:00:00 2001 From: harry Date: Tue, 20 Feb 2024 04:54:07 -0500 Subject: [PATCH] Minor config improvements. Modified Qt recent ROM menu to drop file entries that no longer exist on disk. --- src/drivers/Qt/ConsoleWindow.cpp | 23 ++++++++++++++--- src/drivers/common/configSys.cpp | 42 ++++++++++++++++++++++++++++++++ src/drivers/common/configSys.h | 4 +++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 67d9b3e8..d6c16fc8 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -317,6 +317,9 @@ consoleWin_t::~consoleWin_t(void) #ifdef __FCEU_QSCRIPT_ENABLE__ QtScriptManager::destroy(); #endif + + NetPlayCloseSession(); + // The closeApp function call stops all threads. // Calling quit on threads should not happen here. //printf("Thread Finished: %i \n", emulatorThread->isFinished() ); @@ -931,9 +934,9 @@ void consoleWin_t::createMainMenu(void) movieMenu = menubar->addMenu(tr("&Movie")); optMenu = menubar->addMenu(tr("&Options")); emuMenu = menubar->addMenu(tr("&Emulation")); - netPlayMenu = menubar->addMenu(tr("&NetPlay")); toolsMenu = menubar->addMenu(tr("&Tools")); debugMenu = menubar->addMenu(tr("&Debug")); + netPlayMenu = menubar->addMenu(tr("&NetPlay")); helpMenu = menubar->addMenu(tr("&Help")); //----------------------------------------------------------------------- @@ -2219,8 +2222,9 @@ void consoleWin_t::buildRecentRomMenu(void) g_config->getOption( buf, &s); //printf("Recent Rom:%i '%s'\n", i, s.c_str() ); + bool fileExists = !s.empty() && QFile::exists(tr(s.c_str())); - if ( s.size() > 0 ) + if ( fileExists ) { act = new consoleRecentRomAction( tr(s.c_str()), recentRomMenu); @@ -2234,6 +2238,13 @@ void consoleWin_t::buildRecentRomMenu(void) romList.push_front( sptr ); } + else + { + // Clear the option if file does not exist + s.clear(); + + g_config->setOption( buf, s); + } } } //--------------------------------------------------------------------------- @@ -2251,11 +2262,17 @@ void consoleWin_t::saveRecentRomMenu(void) s = *it; sprintf(buf, "SDL.RecentRom%02i", i); - g_config->setOption( buf, s->c_str() ); + g_config->setOption( buf, *s ); //printf("Recent Rom:%u '%s'\n", i, s->c_str() ); i--; } + for (i = romList.size(); i < 10; i++) + { + sprintf(buf, "SDL.RecentRom%02i", i); + g_config->setOption( buf, ""); + } + } //--------------------------------------------------------------------------- void consoleWin_t::addRecentRom( const char *rom ) diff --git a/src/drivers/common/configSys.cpp b/src/drivers/common/configSys.cpp index 46270601..ea5dc7a0 100644 --- a/src/drivers/common/configSys.cpp +++ b/src/drivers/common/configSys.cpp @@ -355,6 +355,26 @@ Config::setOption(const std::string &name, return 0; } +/** + * Sets the specified option to the given string value. + */ +int +Config::setOption(const std::string &name, + const char *value) +{ + std::map::iterator opt_i; + + // confirm that the option exists + opt_i = _strOptMap.find(name); + if(opt_i == _strOptMap.end()) { + return -1; + } + + // set the option + opt_i->second = value; + return 0; +} + /** * Sets the specified option to the given string value. */ @@ -375,6 +395,28 @@ Config::setOption(const std::string &name, return 0; } +#ifdef __QT_DRIVER__ +/** + * Sets the specified option to the given string value. + */ +int +Config::setOption(const std::string &name, + const QString &value) +{ + std::map::iterator opt_i; + + // confirm that the option exists + opt_i = _strOptMap.find(name); + if(opt_i == _strOptMap.end()) { + return -1; + } + + // set the option + opt_i->second = value.toLocal8Bit().constData(); + return 0; +} +#endif + /** * Sets the specified option to the given function. */ diff --git a/src/drivers/common/configSys.h b/src/drivers/common/configSys.h index 5beda053..6883825b 100644 --- a/src/drivers/common/configSys.h +++ b/src/drivers/common/configSys.h @@ -65,10 +65,14 @@ public: /** * Sets a configuration option. Can be called at any time. */ + int setOption(const std::string &, const char *); int setOption(const std::string &, const std::string &); int setOption(const std::string &, int); int setOption(const std::string &, double); int setOption(const std::string &, void (*)(const std::string &)); +#ifdef __QT_DRIVER__ + int setOption(const std::string &, const QString &); +#endif #ifdef __QT_DRIVER__ int getOption(const std::string &, QString *) const;