2020-09-21 16:13:27 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-21 16:13:27 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-12-23 17:06:30 +00:00
|
|
|
// CollectionSystemsManager.h
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Manages collections of the following two types:
|
|
|
|
// 1) Automatically populated (All games, Favorites and Recent/Last Played)
|
|
|
|
// 2) Custom/user-created (could be any number of these)
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// The automatic collections are basically virtual systems that have no
|
|
|
|
// gamelist.xml files and that only exist in memory during the program session.
|
2020-12-23 17:06:30 +00:00
|
|
|
// SystemData sets up the basic data structures and CollectionSystemsManager
|
2020-06-21 12:25:28 +00:00
|
|
|
// populates and manages the collections.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// The custom collections have simple data files which are just lists of ROM files.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-12-23 17:06:30 +00:00
|
|
|
// In addition to this, CollectionSystemsManager also handles some logic for
|
2020-06-21 12:25:28 +00:00
|
|
|
// normal systems such as adding and removing favorite games, including triggering
|
|
|
|
// the required re-sort and refresh of the gamelists.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_APP_COLLECTION_SYSTEM_MANAGER_H
|
|
|
|
#define ES_APP_COLLECTION_SYSTEM_MANAGER_H
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-10-22 19:23:16 +00:00
|
|
|
#include "utils/StringUtil.h"
|
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <map>
|
2017-06-12 16:38:59 +00:00
|
|
|
#include <string>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class FileData;
|
|
|
|
class SystemData;
|
|
|
|
class Window;
|
|
|
|
struct SystemEnvironmentData;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
enum CollectionSystemType {
|
2021-07-07 18:03:42 +00:00
|
|
|
AUTO_ALL_GAMES, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-21 12:25:28 +00:00
|
|
|
AUTO_LAST_PLAYED,
|
|
|
|
AUTO_FAVORITES,
|
|
|
|
CUSTOM_COLLECTION
|
2017-06-12 16:38:59 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
struct CollectionSystemDecl {
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionSystemType type;
|
|
|
|
std::string name;
|
2021-09-25 09:02:27 +00:00
|
|
|
std::string fullName;
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string themeFolder;
|
|
|
|
bool isCustom;
|
2017-06-12 16:38:59 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
struct CollectionSystemData {
|
2021-11-16 21:03:34 +00:00
|
|
|
CollectionSystemData()
|
|
|
|
: system{nullptr}
|
|
|
|
, decl{}
|
|
|
|
, isEnabled{false}
|
|
|
|
, isPopulated{false}
|
|
|
|
{
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData* system;
|
|
|
|
CollectionSystemDecl decl;
|
|
|
|
bool isEnabled;
|
|
|
|
bool isPopulated;
|
2017-06-12 16:38:59 +00:00
|
|
|
};
|
|
|
|
|
2020-10-22 19:23:16 +00:00
|
|
|
struct stringComparator {
|
|
|
|
bool operator()(const std::string& a, const std::string& b) const
|
|
|
|
{
|
|
|
|
return Utils::String::toUpper(a) < Utils::String::toUpper(b);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
class CollectionSystemsManager
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-12-23 17:06:30 +00:00
|
|
|
CollectionSystemsManager(Window* window);
|
|
|
|
~CollectionSystemsManager();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
static CollectionSystemsManager* get();
|
2020-06-21 12:25:28 +00:00
|
|
|
static void init(Window* window);
|
|
|
|
static void deinit();
|
|
|
|
void saveCustomCollection(SystemData* sys);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-11-10 17:45:57 +00:00
|
|
|
// Functions to load all collections into memory, and enable the active ones:
|
|
|
|
// Load all collection systems.
|
2020-06-21 12:25:28 +00:00
|
|
|
void loadCollectionSystems();
|
2020-11-10 17:45:57 +00:00
|
|
|
// Load settings.
|
2020-06-21 12:25:28 +00:00
|
|
|
void loadEnabledListFromSettings();
|
2020-11-10 17:45:57 +00:00
|
|
|
// Update enabled system list in System View.
|
2020-06-21 12:25:28 +00:00
|
|
|
void updateSystemsList();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-11-10 17:45:57 +00:00
|
|
|
// Functions to manage collection files related to a source FileData:
|
|
|
|
// Update all collection files related to the source file.
|
2021-02-04 19:14:20 +00:00
|
|
|
void refreshCollectionSystems(FileData* file, bool refreshDisabledAutoCollections = false);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Update the collections, such as when marking or unmarking a game as favorite.
|
2020-06-21 12:25:28 +00:00
|
|
|
void updateCollectionSystem(FileData* file, CollectionSystemData sysData);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Delete all collection files from all collection systems related to the source file.
|
2020-06-21 12:25:28 +00:00
|
|
|
void deleteCollectionFiles(FileData* file);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-11-10 17:45:57 +00:00
|
|
|
// Return whether the current theme is compatible with Automatic or Custom Collections.
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool isThemeGenericCollectionCompatible(bool genericCustomCollections);
|
|
|
|
const bool isThemeCustomCollectionCompatible(const std::vector<std::string>& stringVector);
|
|
|
|
std::string getValidNewCollectionName(const std::string& name, int index = 0);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
void setEditMode(const std::string& collectionName, bool showPopup = true);
|
2020-12-31 20:54:32 +00:00
|
|
|
void exitEditMode(bool showPopup = true);
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool inCustomCollection(const std::string& collectionName, FileData* gameFile);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Add or remove a game from a specific collection.
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool toggleGameInCollection(FileData* file);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData* getSystemToView(SystemData* sys);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Used to generate a description of the collection (all other metadata fields are hidden).
|
2020-10-21 19:56:31 +00:00
|
|
|
FileData* updateCollectionFolderMetadata(SystemData* sys);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Return the unused folders from current theme path.
|
2020-11-08 21:58:06 +00:00
|
|
|
std::vector<std::string> getUnusedSystemsFromTheme();
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
SystemData* addNewCustomCollection(const std::string& name);
|
|
|
|
void deleteCustomCollection(const std::string& collectionName);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-12-31 20:54:32 +00:00
|
|
|
// Reactivate a game in all custom collections where it has an entry in the configuration file.
|
|
|
|
void reactivateCustomCollectionEntry(FileData* game);
|
|
|
|
|
2021-01-01 16:18:04 +00:00
|
|
|
// Repopulate the collection, which is basically a forced update of its complete content.
|
|
|
|
void repopulateCollection(SystemData* sysData);
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::map<std::string, CollectionSystemData, stringComparator>& // Line break.
|
|
|
|
getAutoCollectionSystems() const
|
2021-07-07 18:03:42 +00:00
|
|
|
{
|
|
|
|
return mAutoCollectionSystemsData;
|
|
|
|
}
|
2021-11-09 21:40:08 +00:00
|
|
|
const std::map<std::string, CollectionSystemData, stringComparator>&
|
|
|
|
getCustomCollectionSystems()
|
2021-07-07 18:03:42 +00:00
|
|
|
{
|
|
|
|
return mCustomCollectionSystemsData;
|
|
|
|
}
|
2021-11-09 21:40:08 +00:00
|
|
|
SystemData* getCustomCollectionsBundle() const { return mCustomCollectionsBundle; }
|
|
|
|
const bool isEditing() const { return mIsEditingCustom; }
|
|
|
|
const std::string& getEditingCollection() const { return mEditingCollection; }
|
2020-11-10 17:45:57 +00:00
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
private:
|
2020-12-23 17:06:30 +00:00
|
|
|
static CollectionSystemsManager* sInstance;
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemEnvironmentData* mCollectionEnvData;
|
2020-10-22 19:23:16 +00:00
|
|
|
std::map<std::string, CollectionSystemDecl, stringComparator> mCollectionSystemDeclsIndex;
|
|
|
|
std::map<std::string, CollectionSystemData, stringComparator> mAutoCollectionSystemsData;
|
|
|
|
std::map<std::string, CollectionSystemData, stringComparator> mCustomCollectionSystemsData;
|
2020-06-21 12:25:28 +00:00
|
|
|
Window* mWindow;
|
|
|
|
bool mIsEditingCustom;
|
|
|
|
bool mHasEnabledCustomCollection;
|
|
|
|
std::string mEditingCollection;
|
|
|
|
CollectionSystemData* mEditingCollectionSystemData;
|
2020-10-25 18:42:25 +00:00
|
|
|
SystemData* mCustomCollectionsBundle;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-11-10 17:45:57 +00:00
|
|
|
// Functions to handle the initialization and loading of collection systems:
|
|
|
|
// Loads Automatic Collection systems (All, Favorites, Last Played).
|
2020-06-21 12:25:28 +00:00
|
|
|
void initAutoCollectionSystems();
|
|
|
|
void initCustomCollectionSystems();
|
|
|
|
SystemData* getAllGamesCollection();
|
2020-11-10 17:45:57 +00:00
|
|
|
// Create a new empty collection system based on the name and declaration.
|
2021-11-09 21:40:08 +00:00
|
|
|
SystemData* createNewCollectionEntry(const std::string& name,
|
2021-07-07 18:03:42 +00:00
|
|
|
CollectionSystemDecl sysDecl,
|
|
|
|
bool index = true,
|
|
|
|
bool custom = false);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Populate an automatic collection system.
|
2020-06-21 12:25:28 +00:00
|
|
|
void populateAutoCollection(CollectionSystemData* sysData);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Populate a custom collection system.
|
2020-06-21 12:25:28 +00:00
|
|
|
void populateCustomCollection(CollectionSystemData* sysData);
|
|
|
|
|
2020-11-10 17:45:57 +00:00
|
|
|
// Functions to handle System View removal and insertion of collections:
|
2020-06-21 12:25:28 +00:00
|
|
|
void removeCollectionsFromDisplayedSystems();
|
2021-07-07 18:03:42 +00:00
|
|
|
void addEnabledCollectionsToDisplayedSystems(
|
|
|
|
std::map<std::string, CollectionSystemData, stringComparator>* colSystemData);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-11-10 17:45:57 +00:00
|
|
|
// Auxiliary functions:
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> getSystemsFromConfig();
|
|
|
|
std::vector<std::string> getSystemsFromTheme();
|
2020-11-10 17:45:57 +00:00
|
|
|
// Return which collection config files exist in the user folder.
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> getCollectionsFromConfigFolder();
|
2020-11-10 17:45:57 +00:00
|
|
|
// Return the theme folders for automatic collections (All, Favorites and Last Played)
|
|
|
|
// or a generic custom collections folder.
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> getCollectionThemeFolders(bool custom);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Return the theme folders in use for the user-defined custom collections.
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> getUserCollectionThemeFolders();
|
|
|
|
void trimCollectionCount(FileData* rootFolder, int limit);
|
2020-11-10 17:45:57 +00:00
|
|
|
// Return whether a specific folder exists in the theme.
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool themeFolderExists(const std::string& folder);
|
|
|
|
const bool includeFileInAutoCollections(FileData* file);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
std::string getCustomCollectionConfigPath(const std::string& collectionName);
|
2020-10-25 18:42:25 +00:00
|
|
|
std::string getCollectionsFolder();
|
2017-06-12 16:38:59 +00:00
|
|
|
};
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_APP_COLLECTION_SYSTEM_MANAGER_H
|