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-06-21 12:25:28 +00:00
|
|
|
// CollectionSystemManager.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.
|
|
|
|
// SystemData sets up the basic data structures and CollectionSystemManager
|
|
|
|
// 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-06-21 12:25:28 +00:00
|
|
|
// In addition to this, CollectionSystemManager also handles some logic for
|
|
|
|
// 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 {
|
2020-06-21 12:25:28 +00:00
|
|
|
AUTO_ALL_GAMES,
|
|
|
|
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;
|
|
|
|
std::string longName;
|
|
|
|
std::string themeFolder;
|
|
|
|
bool isCustom;
|
2017-06-12 16:38:59 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
struct CollectionSystemData {
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
class CollectionSystemManager
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionSystemManager(Window* window);
|
|
|
|
~CollectionSystemManager();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static CollectionSystemManager* get();
|
|
|
|
static void init(Window* window);
|
|
|
|
static void deinit();
|
|
|
|
void saveCustomCollection(SystemData* sys);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void loadCollectionSystems();
|
|
|
|
void loadEnabledListFromSettings();
|
|
|
|
void updateSystemsList();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void refreshCollectionSystems(FileData* file);
|
|
|
|
void updateCollectionSystem(FileData* file, CollectionSystemData sysData);
|
|
|
|
void deleteCollectionFiles(FileData* file);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-10-22 19:23:16 +00:00
|
|
|
inline std::map<std::string, CollectionSystemData, stringComparator>
|
|
|
|
getAutoCollectionSystems() { return mAutoCollectionSystemsData; };
|
|
|
|
inline std::map<std::string, CollectionSystemData, stringComparator>
|
|
|
|
getCustomCollectionSystems() { return mCustomCollectionSystemsData; };
|
2020-06-21 12:25:28 +00:00
|
|
|
inline SystemData* getCustomCollectionsBundle() { return mCustomCollectionsBundle; };
|
|
|
|
std::vector<std::string> getUnusedSystemsFromTheme();
|
|
|
|
SystemData* addNewCustomCollection(std::string name);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool isThemeGenericCollectionCompatible(bool genericCustomCollections);
|
|
|
|
bool isThemeCustomCollectionCompatible(std::vector<std::string> stringVector);
|
|
|
|
std::string getValidNewCollectionName(std::string name, int index = 0);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void setEditMode(std::string collectionName);
|
|
|
|
void exitEditMode();
|
|
|
|
inline bool isEditing() { return mIsEditingCustom; };
|
|
|
|
inline std::string getEditingCollection() { return mEditingCollection; };
|
|
|
|
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-10-21 19:56:31 +00:00
|
|
|
FileData* updateCollectionFolderMetadata(SystemData* sys);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool getIsCustomCollection(SystemData* system);
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
static CollectionSystemManager* sInstance;
|
|
|
|
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
|
|
|
|
|
|
|
void initAutoCollectionSystems();
|
|
|
|
void initCustomCollectionSystems();
|
|
|
|
SystemData* getAllGamesCollection();
|
|
|
|
SystemData* createNewCollectionEntry(std::string name,
|
2020-09-21 16:13:27 +00:00
|
|
|
CollectionSystemDecl sysDecl, bool index = true, bool custom = false);
|
2020-06-21 12:25:28 +00:00
|
|
|
void populateAutoCollection(CollectionSystemData* sysData);
|
|
|
|
void populateCustomCollection(CollectionSystemData* sysData);
|
|
|
|
|
|
|
|
void removeCollectionsFromDisplayedSystems();
|
|
|
|
void addEnabledCollectionsToDisplayedSystems(std::map<std::string,
|
2020-10-22 19:23:16 +00:00
|
|
|
CollectionSystemData, stringComparator>* colSystemData);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
std::vector<std::string> getSystemsFromConfig();
|
|
|
|
std::vector<std::string> getSystemsFromTheme();
|
|
|
|
std::vector<std::string> getCollectionsFromConfigFolder();
|
|
|
|
std::vector<std::string> getCollectionThemeFolders(bool custom);
|
|
|
|
std::vector<std::string> getUserCollectionThemeFolders();
|
|
|
|
|
|
|
|
void trimCollectionCount(FileData* rootFolder, int limit);
|
|
|
|
bool themeFolderExists(std::string folder);
|
|
|
|
bool includeFileInAutoCollections(FileData* file);
|
|
|
|
|
2020-10-25 18:42:25 +00:00
|
|
|
std::string getCustomCollectionConfigPath(std::string collectionName);
|
|
|
|
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
|