Added a utility to the menu for rescanning the ROM directory

Also added a new Utilities menu to the main menu
This commit is contained in:
Leon Styhre 2023-07-20 21:59:28 +02:00
parent 07d390ccda
commit d27dd211c3
7 changed files with 102 additions and 14 deletions

View file

@ -88,29 +88,36 @@ CollectionSystemsManager* CollectionSystemsManager::getInstance()
return &instance; return &instance;
} }
void CollectionSystemsManager::deinit() void CollectionSystemsManager::deinit(const bool shutdown)
{ {
// Don't attempt to remove any collections if no systems exist. // Don't attempt to remove any collections if no systems exist.
if (SystemData::sSystemVector.size() > 0) { if (SystemData::sSystemVector.size() > 0) {
removeCollectionsFromDisplayedSystems(); removeCollectionsFromDisplayedSystems();
// Delete all custom collections. // Delete all custom collections.
for (std::map<std::string, CollectionSystemData, StringComparator>::const_iterator it = for (std::map<std::string, CollectionSystemData, StringComparator>::iterator it =
mCustomCollectionSystemsData.cbegin(); mCustomCollectionSystemsData.begin();
it != mCustomCollectionSystemsData.cend(); ++it) it != mCustomCollectionSystemsData.end(); ++it) {
delete it->second.system; delete it->second.system;
it->second.system = nullptr;
}
// Delete the custom collections bundle. // Delete the custom collections bundle.
if (mCustomCollectionsBundle) if (mCustomCollectionsBundle) {
delete mCustomCollectionsBundle; delete mCustomCollectionsBundle;
mCustomCollectionsBundle = nullptr;
}
// Delete the auto collections systems. // Delete the auto collections systems.
for (auto it = mAutoCollectionSystemsData.cbegin(); // Line break. for (auto it = mAutoCollectionSystemsData.begin(); // Line break.
it != mAutoCollectionSystemsData.cend(); ++it) it != mAutoCollectionSystemsData.end(); ++it) {
delete (*it).second.system; delete (*it).second.system;
(*it).second.system = nullptr;
}
} }
delete mCollectionEnvData; if (shutdown)
delete mCollectionEnvData;
} }
void CollectionSystemsManager::saveCustomCollection(SystemData* sys) void CollectionSystemsManager::saveCustomCollection(SystemData* sys)

View file

@ -78,8 +78,8 @@ public:
static CollectionSystemsManager* getInstance(); static CollectionSystemsManager* getInstance();
void saveCustomCollection(SystemData* sys); void saveCustomCollection(SystemData* sys);
// Clean up all systems, called during application shutdown. // Clean up all systems, called during application shutdown and ROM directory rescan.
void deinit(); void deinit(const bool shutdown);
// Functions to load all collections into memory, and enable the active ones: // Functions to load all collections into memory, and enable the active ones:
// Load all collection systems. // Load all collection systems.
@ -137,7 +137,7 @@ public:
const bool isEditing() const { return mIsEditingCustom; } const bool isEditing() const { return mIsEditingCustom; }
const std::string& getEditingCollection() const { return mEditingCollection; } const std::string& getEditingCollection() const { return mEditingCollection; }
static inline std::string myCollectionsName = "collections"; static inline std::string myCollectionsName {"collections"};
protected: protected:
void trimCollectionCount(FileData* rootFolder, int limit); void trimCollectionCount(FileData* rootFolder, int limit);

View file

@ -65,6 +65,9 @@ GuiMenu::GuiMenu()
if (isFullUI) if (isFullUI)
addEntry("OTHER SETTINGS", mMenuColorPrimary, true, [this] { openOtherOptions(); }); addEntry("OTHER SETTINGS", mMenuColorPrimary, true, [this] { openOtherOptions(); });
if (isFullUI)
addEntry("UTILITIES", mMenuColorPrimary, true, [this] { openUtilities(); });
if (!Settings::getInstance()->getBool("ForceKiosk") && if (!Settings::getInstance()->getBool("ForceKiosk") &&
Settings::getInstance()->getString("UIMode") != "kiosk") { Settings::getInstance()->getString("UIMode") != "kiosk") {
#if defined(__APPLE__) #if defined(__APPLE__)
@ -1727,6 +1730,72 @@ void GuiMenu::openOtherOptions()
mWindow->pushGui(s); 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<TextComponent>(
"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() void GuiMenu::openQuitMenu()
{ {
if (!Settings::getInstance()->getBool("ShowQuitMenu")) { if (!Settings::getInstance()->getBool("ShowQuitMenu")) {

View file

@ -44,6 +44,7 @@ private:
void openConfigInput(GuiSettings* settings); void openConfigInput(GuiSettings* settings);
void openCollectionSystemOptions(); void openCollectionSystemOptions();
void openOtherOptions(); void openOtherOptions();
void openUtilities();
void openQuitMenu(); void openQuitMenu();
Renderer* mRenderer; Renderer* mRenderer;

View file

@ -855,7 +855,7 @@ int main(int argc, char* argv[])
delete window->peekGui(); delete window->peekGui();
window->deinit(); window->deinit();
CollectionSystemsManager::getInstance()->deinit(); CollectionSystemsManager::getInstance()->deinit(true);
SystemData::deleteSystems(); SystemData::deleteSystems();
NavigationSounds::getInstance().deinit(); NavigationSounds::getInstance().deinit();

View file

@ -1209,8 +1209,7 @@ void ViewController::render(const glm::mat4& parentTrans)
void ViewController::preload() void ViewController::preload()
{ {
unsigned int systemCount {static_cast<unsigned int>(SystemData::sSystemVector.size())}; const unsigned int systemCount {static_cast<unsigned int>(SystemData::sSystemVector.size())};
// This reduces the amount of texture pop-in when loading theme extras. // This reduces the amount of texture pop-in when loading theme extras.
if (!SystemData::sSystemVector.empty()) if (!SystemData::sSystemVector.empty())
getSystemListView(); getSystemListView();
@ -1409,6 +1408,15 @@ void ViewController::reloadAll()
updateHelpPrompts(); updateHelpPrompts();
} }
void ViewController::resetAll()
{
mGamelistViews.clear();
mSystemListView.reset();
mCurrentView.reset();
mPreviousView.reset();
mSkipView.reset();
}
std::vector<HelpPrompt> ViewController::getHelpPrompts() std::vector<HelpPrompt> ViewController::getHelpPrompts()
{ {
std::vector<HelpPrompt> prompts; std::vector<HelpPrompt> prompts;

View file

@ -54,6 +54,9 @@ public:
// Used when the "ThemeSet" setting changes. // Used when the "ThemeSet" setting changes.
void reloadAll(); void reloadAll();
// Reset all views, which is needed when rescanning the ROM directory.
void resetAll();
// Navigation. // Navigation.
void goToNextGamelist(); void goToNextGamelist();
void goToPrevGamelist(); void goToPrevGamelist();