From d27dd211c34bb1f54233a8e74de1400e9178d948 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 20 Jul 2023 21:59:28 +0200 Subject: [PATCH] Added a utility to the menu for rescanning the ROM directory Also added a new Utilities menu to the main menu --- es-app/src/CollectionSystemsManager.cpp | 23 ++++++--- es-app/src/CollectionSystemsManager.h | 6 +-- es-app/src/guis/GuiMenu.cpp | 69 +++++++++++++++++++++++++ es-app/src/guis/GuiMenu.h | 1 + es-app/src/main.cpp | 2 +- es-app/src/views/ViewController.cpp | 12 ++++- es-app/src/views/ViewController.h | 3 ++ 7 files changed, 102 insertions(+), 14 deletions(-) diff --git a/es-app/src/CollectionSystemsManager.cpp b/es-app/src/CollectionSystemsManager.cpp index ea6275b4f..b996df14c 100644 --- a/es-app/src/CollectionSystemsManager.cpp +++ b/es-app/src/CollectionSystemsManager.cpp @@ -88,29 +88,36 @@ CollectionSystemsManager* CollectionSystemsManager::getInstance() return &instance; } -void CollectionSystemsManager::deinit() +void CollectionSystemsManager::deinit(const bool shutdown) { // Don't attempt to remove any collections if no systems exist. if (SystemData::sSystemVector.size() > 0) { removeCollectionsFromDisplayedSystems(); // Delete all custom collections. - for (std::map::const_iterator it = - mCustomCollectionSystemsData.cbegin(); - it != mCustomCollectionSystemsData.cend(); ++it) + for (std::map::iterator it = + mCustomCollectionSystemsData.begin(); + it != mCustomCollectionSystemsData.end(); ++it) { delete it->second.system; + it->second.system = nullptr; + } // Delete the custom collections bundle. - if (mCustomCollectionsBundle) + if (mCustomCollectionsBundle) { delete mCustomCollectionsBundle; + mCustomCollectionsBundle = nullptr; + } // Delete the auto collections systems. - for (auto it = mAutoCollectionSystemsData.cbegin(); // Line break. - it != mAutoCollectionSystemsData.cend(); ++it) + for (auto it = mAutoCollectionSystemsData.begin(); // Line break. + it != mAutoCollectionSystemsData.end(); ++it) { delete (*it).second.system; + (*it).second.system = nullptr; + } } - delete mCollectionEnvData; + if (shutdown) + delete mCollectionEnvData; } void CollectionSystemsManager::saveCustomCollection(SystemData* sys) diff --git a/es-app/src/CollectionSystemsManager.h b/es-app/src/CollectionSystemsManager.h index c680e94e4..6157cc3be 100644 --- a/es-app/src/CollectionSystemsManager.h +++ b/es-app/src/CollectionSystemsManager.h @@ -78,8 +78,8 @@ public: static CollectionSystemsManager* getInstance(); void saveCustomCollection(SystemData* sys); - // Clean up all systems, called during application shutdown. - void deinit(); + // Clean up all systems, called during application shutdown and ROM directory rescan. + void deinit(const bool shutdown); // Functions to load all collections into memory, and enable the active ones: // Load all collection systems. @@ -137,7 +137,7 @@ public: const bool isEditing() const { return mIsEditingCustom; } const std::string& getEditingCollection() const { return mEditingCollection; } - static inline std::string myCollectionsName = "collections"; + static inline std::string myCollectionsName {"collections"}; protected: void trimCollectionCount(FileData* rootFolder, int limit); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index de9bc1f31..d5f81568a 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -65,6 +65,9 @@ GuiMenu::GuiMenu() if (isFullUI) addEntry("OTHER SETTINGS", mMenuColorPrimary, true, [this] { openOtherOptions(); }); + if (isFullUI) + addEntry("UTILITIES", mMenuColorPrimary, true, [this] { openUtilities(); }); + if (!Settings::getInstance()->getBool("ForceKiosk") && Settings::getInstance()->getString("UIMode") != "kiosk") { #if defined(__APPLE__) @@ -1727,6 +1730,72 @@ void GuiMenu::openOtherOptions() mWindow->pushGui(s); } +void GuiMenu::openUtilities() +{ + auto s = new GuiSettings("UTILITIES"); + + Window* window {mWindow}; + HelpStyle style {getHelpStyle()}; + + ComponentListRow row; + + row.makeAcceptInputHandler([s, window, this] { + window->pushGui(new GuiMsgBox( + this->getHelpStyle(), + "THIS WILL RESCAN YOUR ROM DIRECTORY\n" + "FOR CHANGES SUCH AS ADDED OR REMOVED\n" + "GAMES AND SYSTEMS, PROCEED?", + "YES", + [this, window] { + if (CollectionSystemsManager::getInstance()->isEditing()) + CollectionSystemsManager::getInstance()->exitEditMode(); + window->stopInfoPopup(); + GuiMenu::close(true); + // Write any gamelist.xml changes before proceeding with the reload. + if (Settings::getInstance()->getString("SaveGamelistsMode") != "never") { + for (auto system : SystemData::sSystemVector) + system->writeMetaData(); + } + window->renderSplashScreen(Window::SplashScreenState::SCANNING, 0.0f); + ViewController::getInstance()->resetAll(); + CollectionSystemsManager::getInstance()->deinit(false); + SystemData::loadConfig(); + if (SystemData::sStartupExitSignal) { + SDL_Event quit; + quit.type = SDL_QUIT; + SDL_PushEvent(&quit); + return; + } + if (SystemData::sSystemVector.empty()) { + // It's possible that there are no longer any games. + window->invalidateCachedBackground(); + ViewController::getInstance()->noGamesDialog(); + } + else { + ViewController::getInstance()->preload(); + if (SystemData::sStartupExitSignal) { + SDL_Event quit; + quit.type = SDL_QUIT; + SDL_PushEvent(&quit); + return; + } + ViewController::getInstance()->goToStart(false); + } + }, + "NO", nullptr)); + }); + auto rescanROMDirectory = std::make_shared( + "RESCAN ROM DIRECTORY", Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary); + rescanROMDirectory->setSelectable(true); + row.addElement(rescanROMDirectory, true); + s->addRow(row); + + row.elements.clear(); + + s->setSize(mSize); + mWindow->pushGui(s); +} + void GuiMenu::openQuitMenu() { if (!Settings::getInstance()->getBool("ShowQuitMenu")) { diff --git a/es-app/src/guis/GuiMenu.h b/es-app/src/guis/GuiMenu.h index 1b9c3cd4e..b48a11349 100644 --- a/es-app/src/guis/GuiMenu.h +++ b/es-app/src/guis/GuiMenu.h @@ -44,6 +44,7 @@ private: void openConfigInput(GuiSettings* settings); void openCollectionSystemOptions(); void openOtherOptions(); + void openUtilities(); void openQuitMenu(); Renderer* mRenderer; diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 41600f629..b354a96a3 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -855,7 +855,7 @@ int main(int argc, char* argv[]) delete window->peekGui(); window->deinit(); - CollectionSystemsManager::getInstance()->deinit(); + CollectionSystemsManager::getInstance()->deinit(true); SystemData::deleteSystems(); NavigationSounds::getInstance().deinit(); diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 500054e18..0d8d3e489 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -1209,8 +1209,7 @@ void ViewController::render(const glm::mat4& parentTrans) void ViewController::preload() { - unsigned int systemCount {static_cast(SystemData::sSystemVector.size())}; - + const unsigned int systemCount {static_cast(SystemData::sSystemVector.size())}; // This reduces the amount of texture pop-in when loading theme extras. if (!SystemData::sSystemVector.empty()) getSystemListView(); @@ -1409,6 +1408,15 @@ void ViewController::reloadAll() updateHelpPrompts(); } +void ViewController::resetAll() +{ + mGamelistViews.clear(); + mSystemListView.reset(); + mCurrentView.reset(); + mPreviousView.reset(); + mSkipView.reset(); +} + std::vector ViewController::getHelpPrompts() { std::vector prompts; diff --git a/es-app/src/views/ViewController.h b/es-app/src/views/ViewController.h index 49253573c..3dd1e13bf 100644 --- a/es-app/src/views/ViewController.h +++ b/es-app/src/views/ViewController.h @@ -54,6 +54,9 @@ public: // Used when the "ThemeSet" setting changes. void reloadAll(); + // Reset all views, which is needed when rescanning the ROM directory. + void resetAll(); + // Navigation. void goToNextGamelist(); void goToPrevGamelist();