Fixed an issue with collection gamelists getting loaded in the wrong order on startup.

This commit is contained in:
Leon Styhre 2023-02-10 00:40:16 +01:00
parent f22da24486
commit 397ad15de6
3 changed files with 31 additions and 12 deletions

View file

@ -33,16 +33,14 @@
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
#include "utils/TimeUtil.h" #include "utils/TimeUtil.h"
#include "views/GamelistView.h" #include "views/GamelistView.h"
#include "views/ViewController.h"
#include <fstream> #include <fstream>
#include <pugixml.hpp> #include <pugixml.hpp>
#include <random> #include <random>
#define LAST_PLAYED_MAX 50
CollectionSystemsManager::CollectionSystemsManager() noexcept CollectionSystemsManager::CollectionSystemsManager() noexcept
: mWindow {Window::getInstance()} : mWindow {Window::getInstance()}
, mApplicationStartup {false}
{ {
// clang-format off // clang-format off
CollectionSystemDecl systemDecls[] { CollectionSystemDecl systemDecls[] {
@ -191,6 +189,7 @@ void CollectionSystemsManager::saveCustomCollection(SystemData* sys)
void CollectionSystemsManager::loadCollectionSystems() void CollectionSystemsManager::loadCollectionSystems()
{ {
mApplicationStartup = true;
initAutoCollectionSystems(); initAutoCollectionSystems();
CollectionSystemDecl decl {mCollectionSystemDeclsIndex[myCollectionsName]}; CollectionSystemDecl decl {mCollectionSystemDeclsIndex[myCollectionsName]};
mCustomCollectionsBundle = createNewCollectionEntry(decl.name, decl, false); mCustomCollectionsBundle = createNewCollectionEntry(decl.name, decl, false);
@ -205,6 +204,8 @@ void CollectionSystemsManager::loadCollectionSystems()
// Add to the main System Vector, and create Views as needed. // Add to the main System Vector, and create Views as needed.
updateSystemsList(); updateSystemsList();
} }
mApplicationStartup = false;
} }
void CollectionSystemsManager::loadEnabledListFromSettings() void CollectionSystemsManager::loadEnabledListFromSettings()
@ -259,6 +260,9 @@ void CollectionSystemsManager::updateSystemsList()
// Add auto enabled collections. // Add auto enabled collections.
addEnabledCollectionsToDisplayedSystems(&mAutoCollectionSystemsData); addEnabledCollectionsToDisplayedSystems(&mAutoCollectionSystemsData);
if (mApplicationStartup)
return;
// Create views for collections, before reload. // Create views for collections, before reload.
for (auto sysIt = SystemData::sSystemVector.cbegin(); // Line break. for (auto sysIt = SystemData::sSystemVector.cbegin(); // Line break.
sysIt != SystemData::sSystemVector.cend(); ++sysIt) { sysIt != SystemData::sSystemVector.cend(); ++sysIt) {
@ -1196,13 +1200,14 @@ void CollectionSystemsManager::populateAutoCollection(CollectionSystemData* sysD
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
Settings::getInstance()->getBool("FavoritesFirst")); Settings::getInstance()->getBool("FavoritesFirst"));
if (sysDecl.type == AUTO_LAST_PLAYED) if (!mApplicationStartup && sysDecl.type == AUTO_LAST_PLAYED)
trimCollectionCount(rootFolder, LAST_PLAYED_MAX); trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
// For the 'recent' collection we need to populate the gamelist once more as the // For the 'recent' collection we need to populate the gamelist once more as the
// collection was trimmed down to 50 items. If we don't do this, the game count will // collection was trimmed down to 50 items. If we don't do this, the game count will
// not be correct as it would include all the games prior to trimming. // not be correct as it would include all the games prior to trimming.
if (rootFolder->getName() == "recent" && !rootFolder->getChildrenRecursive().empty()) { if (!mApplicationStartup && rootFolder->getName() == "recent" &&
!rootFolder->getChildrenRecursive().empty()) {
// The following is needed to avoid a crash when repopulating the system as the previous // The following is needed to avoid a crash when repopulating the system as the previous
// cursor pointer may point to a random memory address. // cursor pointer may point to a random memory address.
auto recentGamelist = auto recentGamelist =
@ -1348,10 +1353,13 @@ void CollectionSystemsManager::addEnabledCollectionsToDisplayedSystems(
rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()), rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
Settings::getInstance()->getBool("FavFirstCustom")); Settings::getInstance()->getBool("FavFirstCustom"));
// Jump to the first row of the game list, assuming it's not empty. // Jump to the first row of the game list, assuming it's not empty.
GamelistView* gameList { if (!mApplicationStartup) {
ViewController::getInstance()->getGamelistView((it->second.system)).get()}; GamelistView* gameList {ViewController::getInstance()
if (!gameList->getCursor()->isPlaceHolder()) { ->getGamelistView((it->second.system))
gameList->setCursor(gameList->getFirstEntry()); .get()};
if (!gameList->getCursor()->isPlaceHolder()) {
gameList->setCursor(gameList->getFirstEntry());
}
} }
it->second.system->setIsGroupedCustomCollection(false); it->second.system->setIsGroupedCustomCollection(false);
} }

View file

@ -22,7 +22,10 @@
#ifndef ES_APP_COLLECTION_SYSTEM_MANAGER_H #ifndef ES_APP_COLLECTION_SYSTEM_MANAGER_H
#define ES_APP_COLLECTION_SYSTEM_MANAGER_H #define ES_APP_COLLECTION_SYSTEM_MANAGER_H
#define LAST_PLAYED_MAX 50
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
#include "views/ViewController.h"
#include <map> #include <map>
#include <string> #include <string>
@ -136,6 +139,11 @@ public:
static inline std::string myCollectionsName = "collections"; static inline std::string myCollectionsName = "collections";
protected:
void trimCollectionCount(FileData* rootFolder, int limit);
friend ViewController;
private: private:
CollectionSystemsManager() noexcept; CollectionSystemsManager() noexcept;
@ -146,6 +154,7 @@ private:
Window* mWindow; Window* mWindow;
bool mIsEditingCustom; bool mIsEditingCustom;
bool mHasEnabledCustomCollection; bool mHasEnabledCustomCollection;
bool mApplicationStartup;
std::string mEditingCollection; std::string mEditingCollection;
CollectionSystemData* mEditingCollectionSystemData; CollectionSystemData* mEditingCollectionSystemData;
SystemData* mCustomCollectionsBundle; SystemData* mCustomCollectionsBundle;
@ -180,7 +189,6 @@ private:
std::vector<std::string> getCollectionThemeFolders(bool custom); std::vector<std::string> getCollectionThemeFolders(bool custom);
// Return the theme folders in use for the user-defined custom collections. // Return the theme folders in use for the user-defined custom collections.
std::vector<std::string> getUserCollectionThemeFolders(); std::vector<std::string> getUserCollectionThemeFolders();
void trimCollectionCount(FileData* rootFolder, int limit);
// Return whether a specific folder exists in the theme. // Return whether a specific folder exists in the theme.
const bool themeFolderExists(const std::string& folder); const bool themeFolderExists(const std::string& folder);
const bool includeFileInAutoCollections(FileData* file); const bool includeFileInAutoCollections(FileData* file);

View file

@ -1144,11 +1144,14 @@ void ViewController::preload()
// Load navigation sounds, either from the theme if it supports it, or otherwise from // Load navigation sounds, either from the theme if it supports it, or otherwise from
// the bundled fallback sound files. // the bundled fallback sound files.
bool themeSoundSupport {false}; bool themeSoundSupport {false};
for (SystemData* system : SystemData::sSystemVector) { for (auto system : SystemData::sSystemVector) {
if (system->getTheme()->hasView("all")) { if (system->getTheme()->hasView("all")) {
NavigationSounds::getInstance().loadThemeNavigationSounds(system->getTheme().get()); NavigationSounds::getInstance().loadThemeNavigationSounds(system->getTheme().get());
themeSoundSupport = true; themeSoundSupport = true;
break; }
if (system->getRootFolder()->getName() == "recent") {
CollectionSystemsManager::getInstance()->trimCollectionCount(system->getRootFolder(),
LAST_PLAYED_MAX);
} }
} }
if (!SystemData::sSystemVector.empty() && !themeSoundSupport) if (!SystemData::sSystemVector.empty() && !themeSoundSupport)