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.cpp
|
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-11-01 22:21:10 +00:00
|
|
|
#include "CollectionSystemManager.h"
|
|
|
|
|
|
|
|
#include "guis/GuiInfoPopup.h"
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2017-11-29 19:57:43 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/gamelist/IGameListView.h"
|
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "FileData.h"
|
|
|
|
#include "FileFilterIndex.h"
|
|
|
|
#include "Log.h"
|
|
|
|
#include "Settings.h"
|
2017-06-12 16:38:59 +00:00
|
|
|
#include "SystemData.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "ThemeData.h"
|
2020-09-21 16:13:27 +00:00
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
#include <fstream>
|
2020-09-21 16:13:27 +00:00
|
|
|
#include <pugixml.hpp>
|
2020-10-21 19:56:31 +00:00
|
|
|
#include <random>
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::string myCollectionsName = "collections";
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2018-02-27 22:40:23 +00:00
|
|
|
#define LAST_PLAYED_MAX 50
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Handles the getting, initialization, deinitialization,
|
|
|
|
// saving and deletion of a CollectionSystemManager instance.
|
2020-06-18 17:49:47 +00:00
|
|
|
CollectionSystemManager* CollectionSystemManager::sInstance = nullptr;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
|
|
|
CollectionSystemManager::CollectionSystemManager(Window* window) : mWindow(window)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionSystemDecl systemDecls[] = {
|
|
|
|
// Type Name Long name Theme folder isCustom
|
|
|
|
{ AUTO_ALL_GAMES, "all", "all games", "auto-allgames", false },
|
|
|
|
{ AUTO_LAST_PLAYED, "recent", "last played", "auto-lastplayed", false },
|
|
|
|
{ AUTO_FAVORITES, "favorites", "favorites", "auto-favorites", false },
|
|
|
|
{ CUSTOM_COLLECTION, myCollectionsName, "collections", "custom-collections", true }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a map of the collections.
|
|
|
|
std::vector<CollectionSystemDecl> tempSystemDecl = std::vector<CollectionSystemDecl>
|
|
|
|
(systemDecls, systemDecls + sizeof(systemDecls) / sizeof(systemDecls[0]));
|
|
|
|
|
|
|
|
for (std::vector<CollectionSystemDecl>::const_iterator it = tempSystemDecl.cbegin();
|
|
|
|
it != tempSystemDecl.cend(); ++it )
|
|
|
|
mCollectionSystemDeclsIndex[(*it).name] = (*it);
|
|
|
|
|
|
|
|
// Setup the standard environment.
|
|
|
|
mCollectionEnvData = new SystemEnvironmentData;
|
|
|
|
mCollectionEnvData->mStartPath = "";
|
|
|
|
std::vector<std::string> exts;
|
|
|
|
mCollectionEnvData->mSearchExtensions = exts;
|
|
|
|
mCollectionEnvData->mLaunchCommand = "";
|
|
|
|
std::vector<PlatformIds::PlatformId> allPlatformIds;
|
|
|
|
allPlatformIds.push_back(PlatformIds::PLATFORM_IGNORE);
|
|
|
|
mCollectionEnvData->mPlatformIds = allPlatformIds;
|
|
|
|
|
|
|
|
std::string path = getCollectionsFolder();
|
|
|
|
if (!Utils::FileSystem::exists(path))
|
|
|
|
Utils::FileSystem::createDirectory(path);
|
|
|
|
|
|
|
|
mIsEditingCustom = false;
|
|
|
|
mEditingCollection = "Favorites";
|
2020-06-23 18:07:00 +00:00
|
|
|
mEditingCollectionSystemData = nullptr;
|
|
|
|
mCustomCollectionsBundle = nullptr;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectionSystemManager::~CollectionSystemManager()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(sInstance == this);
|
|
|
|
|
|
|
|
// Don't attempt to remove any collections if no systems exist.
|
|
|
|
if (SystemData::sSystemVector.size() > 0)
|
|
|
|
removeCollectionsFromDisplayedSystems();
|
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
// Delete all custom collections.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mCustomCollectionSystemsData.cbegin();
|
2020-10-19 18:58:00 +00:00
|
|
|
it != mCustomCollectionSystemsData.cend() ; it++)
|
2020-06-21 12:25:28 +00:00
|
|
|
delete it->second.system;
|
2020-10-11 16:57:37 +00:00
|
|
|
|
2020-10-18 20:28:18 +00:00
|
|
|
// Delete the custom collections bundle.
|
|
|
|
if (mCustomCollectionsBundle)
|
|
|
|
delete mCustomCollectionsBundle;
|
|
|
|
|
2020-10-11 16:57:37 +00:00
|
|
|
// Delete the auto collections systems.
|
|
|
|
for (auto it = mAutoCollectionSystemsData.cbegin();
|
|
|
|
it != mAutoCollectionSystemsData.cend(); it++) {
|
|
|
|
delete (*it).second.system;
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:28:18 +00:00
|
|
|
delete mCollectionEnvData;
|
2020-06-21 12:25:28 +00:00
|
|
|
sInstance = nullptr;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
CollectionSystemManager* CollectionSystemManager::get()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(sInstance);
|
|
|
|
return sInstance;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::init(Window* window)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(!sInstance);
|
|
|
|
sInstance = new CollectionSystemManager(window);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::deinit()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (sInstance)
|
|
|
|
delete sInstance;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::saveCustomCollection(SystemData* sys)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string rompath = FileData::getROMDirectory();
|
|
|
|
std::string name = sys->getName();
|
|
|
|
std::unordered_map<std::string, FileData*>
|
|
|
|
games = sys->getRootFolder()->getChildrenByFilename();
|
|
|
|
bool found = mCustomCollectionSystemsData.find(name) != mCustomCollectionSystemsData.cend();
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
CollectionSystemData sysData = mCustomCollectionSystemsData.at(name);
|
2020-10-19 18:58:00 +00:00
|
|
|
// Read back any entries from the configuration file for game files that are
|
|
|
|
// currently missing, and combine them with the active content. If we wouldn't do
|
|
|
|
// this, they would be purged from the collection. Maybe a directory has been
|
|
|
|
// temporarily moved or the files are not reachable for whatever reason. It would
|
|
|
|
// be incredibly annoying to have entries purged from the collection in such
|
|
|
|
// instances. Using the logic below, the handling of custom collections corresponds
|
|
|
|
// to the handling of gamelist.xml files, i.e. it's up to the user to make a
|
|
|
|
// conscious decision of what entries to remove.
|
|
|
|
std::vector<std::string> fileGameEntries;
|
|
|
|
std::vector<std::string> activeGameEntries;
|
|
|
|
std::ifstream configFileIn;
|
|
|
|
std::ofstream configFileOut;
|
|
|
|
|
|
|
|
#if defined(_WIN64)
|
|
|
|
configFileIn.open(Utils::String::
|
|
|
|
stringToWideString(getCustomCollectionConfigPath(name)).c_str());
|
|
|
|
#else
|
|
|
|
configFileIn.open(getCustomCollectionConfigPath(name));
|
|
|
|
#endif
|
|
|
|
for (std::string gameEntry; getline(configFileIn, gameEntry); ) {
|
|
|
|
std::string gamePath = Utils::String::replace(gameEntry, "%ROMPATH%", rompath);
|
|
|
|
gamePath = Utils::String::replace(gamePath, "//", "/");
|
|
|
|
// Only add the entry if it's not a regular file or a symlink, in other words
|
|
|
|
// only add missing files.
|
|
|
|
if (!Utils::FileSystem::isRegularFile(gamePath) &&
|
|
|
|
!Utils::FileSystem::isSymlink(gamePath))
|
|
|
|
fileGameEntries.push_back(gameEntry);
|
|
|
|
}
|
|
|
|
configFileIn.close();
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
for (std::unordered_map<std::string, FileData*>::const_iterator
|
|
|
|
iter = games.cbegin(); iter != games.cend(); ++iter) {
|
|
|
|
std::string path = iter->first;
|
|
|
|
// If the ROM path of the game begins with the path from the setting
|
|
|
|
// ROMDirectory (or the default ROM directory), then replace it with %ROMPATH%.
|
|
|
|
if (path.find(rompath) == 0)
|
|
|
|
path.replace(0, rompath.size(), "%ROMPATH%/");
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
activeGameEntries.push_back(path);
|
|
|
|
}
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
fileGameEntries.insert(fileGameEntries.cend(), activeGameEntries.cbegin(),
|
|
|
|
activeGameEntries.cend());
|
|
|
|
std::sort(fileGameEntries.begin(), fileGameEntries.end());
|
|
|
|
auto last = std::unique(fileGameEntries.begin(), fileGameEntries.end());
|
|
|
|
fileGameEntries.erase(last, fileGameEntries.end());
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
#if defined(_WIN64)
|
2020-10-19 20:03:30 +00:00
|
|
|
configFileOut.open(Utils::String::
|
2020-10-19 18:58:00 +00:00
|
|
|
stringToWideString(getCustomCollectionConfigPath(name)).c_str());
|
|
|
|
#else
|
|
|
|
configFileOut.open(getCustomCollectionConfigPath(name));
|
|
|
|
#endif
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
for (auto it = fileGameEntries.cbegin(); it != fileGameEntries.cend(); it++)
|
|
|
|
configFileOut << (*it) << std::endl;
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2020-10-19 18:58:00 +00:00
|
|
|
configFileOut.close();
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogError) << "Couldn't find collection to save: " << name;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Functions below to load all collections into memory, and to enable the active ones.
|
|
|
|
|
|
|
|
// Load all collection systems.
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::loadCollectionSystems()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
initAutoCollectionSystems();
|
|
|
|
CollectionSystemDecl decl = mCollectionSystemDeclsIndex[myCollectionsName];
|
|
|
|
mCustomCollectionsBundle = createNewCollectionEntry(decl.name, decl, false);
|
|
|
|
|
|
|
|
// We will also load custom systems here.
|
|
|
|
initCustomCollectionSystems();
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getString("CollectionSystemsAuto") != "" ||
|
|
|
|
Settings::getInstance()->getString("CollectionSystemsCustom") != "") {
|
|
|
|
// Now see which ones are enabled.
|
|
|
|
loadEnabledListFromSettings();
|
|
|
|
// Add to the main System Vector, and create Views as needed.
|
|
|
|
updateSystemsList();
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Load settings.
|
2017-06-12 16:38:59 +00:00
|
|
|
void CollectionSystemManager::loadEnabledListFromSettings()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// We parse the auto collection settings list.
|
|
|
|
std::vector<std::string> autoSelected = Utils::String::commaStringToVector(
|
|
|
|
Settings::getInstance()->getString("CollectionSystemsAuto"), true);
|
|
|
|
|
|
|
|
// Iterate the map.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mAutoCollectionSystemsData.begin();
|
|
|
|
it != mAutoCollectionSystemsData.end() ; it++ ) {
|
|
|
|
|
|
|
|
it->second.isEnabled = (std::find(autoSelected.cbegin(),
|
|
|
|
autoSelected.cend(), it->first) != autoSelected.cend());
|
|
|
|
}
|
|
|
|
|
|
|
|
mHasEnabledCustomCollection = false;
|
|
|
|
|
|
|
|
// Parse the custom collection settings list.
|
|
|
|
std::vector<std::string> customSelected = Utils::String::commaStringToVector(
|
|
|
|
Settings::getInstance()->getString("CollectionSystemsCustom"), true);
|
|
|
|
|
|
|
|
// Iterate the map.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mCustomCollectionSystemsData.begin();
|
|
|
|
it != mCustomCollectionSystemsData.end() ; it++ ) {
|
|
|
|
|
|
|
|
it->second.isEnabled = (std::find(customSelected.cbegin(),
|
|
|
|
customSelected.cend(), it->first) != customSelected.cend());
|
|
|
|
if (it->second.isEnabled)
|
|
|
|
mHasEnabledCustomCollection = true;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Update enabled system list in System View.
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::updateSystemsList()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Remove all collection systems.
|
|
|
|
removeCollectionsFromDisplayedSystems();
|
|
|
|
// Add custom enabled collections.
|
|
|
|
addEnabledCollectionsToDisplayedSystems(&mCustomCollectionSystemsData);
|
|
|
|
|
|
|
|
// Don't sort bundled collections unless at least one collection is enabled.
|
|
|
|
if (!mIsEditingCustom && mHasEnabledCustomCollection) {
|
2020-09-17 20:18:13 +00:00
|
|
|
FileData* rootFolder = mCustomCollectionsBundle->getRootFolder();
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sort the bundled custom collections.
|
2020-09-17 20:18:13 +00:00
|
|
|
if (rootFolder->getChildren().size() > 0) {
|
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->
|
|
|
|
getSortTypeString()), Settings::getInstance()->getBool("FavFirstCustom"));
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData::sSystemVector.push_back(mCustomCollectionsBundle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add auto enabled collections.
|
|
|
|
addEnabledCollectionsToDisplayedSystems(&mAutoCollectionSystemsData);
|
|
|
|
|
|
|
|
// Create views for collections, before reload.
|
|
|
|
for (auto sysIt = SystemData::sSystemVector.cbegin();
|
|
|
|
sysIt != SystemData::sSystemVector.cend(); sysIt++) {
|
|
|
|
if ((*sysIt)->isCollection())
|
|
|
|
ViewController::get()->getGameListView((*sysIt));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were editing a custom collection, and it's no longer enabled, exit edit mode.
|
2020-09-21 16:13:27 +00:00
|
|
|
if (mIsEditingCustom && !mEditingCollectionSystemData->isEnabled) {
|
2020-06-21 12:25:28 +00:00
|
|
|
exitEditMode();
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Functions below to manage collection files related to a source FileData.
|
|
|
|
|
|
|
|
// Update all collection files related to the source file.
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::refreshCollectionSystems(FileData* file)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!file->getSystem()->isGameSystem() || file->getType() != GAME)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If not a collection but rather a real system, then pretend to be a
|
|
|
|
// collection in order to be properly processed by updateCollectionSystem().
|
|
|
|
// It's seemingly a bit strange, but without rewriting a lot of code for how
|
|
|
|
// systems and collections are handled, it's likely the best approach.
|
|
|
|
if (!file->getSystem()->isCollection()) {
|
|
|
|
CollectionSystemData realSys;
|
|
|
|
realSys.system = file->getSystem();
|
|
|
|
realSys.isEnabled = true;
|
|
|
|
realSys.isPopulated = true;
|
|
|
|
realSys.decl.isCustom = false;
|
|
|
|
|
|
|
|
updateCollectionSystem(file, realSys);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string, CollectionSystemData> allCollections;
|
|
|
|
allCollections.insert(mAutoCollectionSystemsData.cbegin(),
|
|
|
|
mAutoCollectionSystemsData.cend());
|
|
|
|
allCollections.insert(mCustomCollectionSystemsData.cbegin(),
|
|
|
|
mCustomCollectionSystemsData.cend());
|
|
|
|
|
|
|
|
for (auto sysDataIt = allCollections.cbegin();
|
|
|
|
sysDataIt != allCollections.cend(); sysDataIt++) {
|
|
|
|
if (sysDataIt->second.isEnabled)
|
|
|
|
updateCollectionSystem(file, sysDataIt->second);
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionSystemData sysData)
|
|
|
|
{
|
2020-08-06 20:11:55 +00:00
|
|
|
if (sysData.isPopulated) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Collection files use the full path as key, to avoid clashes.
|
|
|
|
std::string key = file->getFullPath();
|
|
|
|
|
|
|
|
SystemData* curSys = sysData.system;
|
|
|
|
bool mFavoritesSorting = false;
|
|
|
|
|
|
|
|
// Read the applicable favorite sorting setting depending on whether the
|
|
|
|
// system is a custom collection or not.
|
|
|
|
if (sysData.decl.isCustom)
|
|
|
|
mFavoritesSorting = Settings::getInstance()->getBool("FavFirstCustom");
|
|
|
|
else
|
|
|
|
mFavoritesSorting = Settings::getInstance()->getBool("FavoritesFirst");
|
|
|
|
|
|
|
|
const std::unordered_map<std::string, FileData*>&children =
|
|
|
|
curSys->getRootFolder()->getChildrenByFilename();
|
|
|
|
|
|
|
|
bool found = children.find(key) != children.cend();
|
|
|
|
FileData* rootFolder = curSys->getRootFolder();
|
|
|
|
FileFilterIndex* fileIndex = curSys->getIndex();
|
|
|
|
std::string name = curSys->getName();
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
// If we found it, we need to update it.
|
|
|
|
FileData* collectionEntry = children.at(key);
|
|
|
|
// Remove it from the index, so we can re-index the metadata after refreshing.
|
|
|
|
fileIndex->removeFromIndex(collectionEntry);
|
|
|
|
collectionEntry->refreshMetadata();
|
|
|
|
// Found it, and we are removing it.
|
|
|
|
if (name == "favorites" && file->metadata.get("favorite") == "false") {
|
|
|
|
// Need to check if it is still marked as favorite, if not remove it.
|
|
|
|
ViewController::get()->
|
|
|
|
getGameListView(curSys).get()->remove(collectionEntry, false);
|
|
|
|
}
|
2020-08-06 20:11:55 +00:00
|
|
|
else if (curSys->isCollection() && !file->getCountAsGame()) {
|
2020-07-29 17:01:49 +00:00
|
|
|
// If the countasgame flag has been set to false, then remove the game.
|
|
|
|
ViewController::get()->
|
|
|
|
getGameListView(curSys).get()->remove(collectionEntry, false);
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
else {
|
|
|
|
// Re-index with new metadata.
|
|
|
|
fileIndex->addToIndex(collectionEntry);
|
|
|
|
ViewController::get()->onFileChanged(collectionEntry, FILE_METADATA_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-07-29 17:01:49 +00:00
|
|
|
bool addGame = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
// We didn't find it here - we need to check if we should add it.
|
2020-08-06 20:11:55 +00:00
|
|
|
if ((name == "recent" && file->metadata.get("playcount") > "0" &&
|
|
|
|
file->getCountAsGame() && includeFileInAutoCollections(file)) ||
|
|
|
|
(name == "favorites" && file->metadata.get("favorite") == "true" &&
|
|
|
|
file->getCountAsGame()))
|
2020-07-29 17:01:49 +00:00
|
|
|
addGame = true;
|
|
|
|
else if (name == "all" && file->getCountAsGame())
|
|
|
|
addGame = true;
|
|
|
|
if (addGame) {
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionFileData* newGame = new CollectionFileData(file, curSys);
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
fileIndex->addToIndex(newGame);
|
|
|
|
ViewController::get()->onFileChanged(file, FILE_METADATA_CHANGED);
|
|
|
|
ViewController::get()->
|
|
|
|
getGameListView(curSys)->onFileChanged(newGame, FILE_METADATA_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "recent") {
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString("last played, descending"));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else if (sysData.decl.isCustom &&
|
|
|
|
!Settings::getInstance()->getBool("UseCustomCollectionsSystem")) {
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2020-06-21 12:25:28 +00:00
|
|
|
mFavoritesSorting);
|
|
|
|
}
|
|
|
|
// If the game doesn't exist in the current system and it's a custom
|
|
|
|
// collection, then skip the sorting.
|
|
|
|
else if (sysData.decl.isCustom &&
|
|
|
|
children.find(file->getFullPath()) != children.cend()) {
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2020-06-21 12:25:28 +00:00
|
|
|
mFavoritesSorting);
|
|
|
|
}
|
|
|
|
else if (!sysData.decl.isCustom) {
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2020-06-21 12:25:28 +00:00
|
|
|
mFavoritesSorting);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "recent") {
|
|
|
|
trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
|
|
|
|
ViewController::get()->onFileChanged(rootFolder, FILE_METADATA_CHANGED);
|
|
|
|
|
|
|
|
// Select the first row of the gamelist (the game just played).
|
|
|
|
IGameListView* gameList =
|
|
|
|
ViewController::get()->getGameListView(getSystemToView(sysData.system)).get();
|
|
|
|
gameList->setCursor(gameList->getFirstEntry());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ViewController::get()->onFileChanged(rootFolder, FILE_SORTED);
|
|
|
|
// If it's a custom collection and the setting to group the collections is
|
|
|
|
// enabled, we may have to update the parent instead.
|
|
|
|
// However it may not necessarily be so if some collections are themed and
|
|
|
|
// some are not, so we always need to check whether a parent exists.
|
|
|
|
if (sysData.decl.isCustom &&
|
|
|
|
Settings::getInstance()->getBool("UseCustomCollectionsSystem")) {
|
|
|
|
// In case of a returned null pointer, we know there is no parent.
|
2020-09-21 16:13:27 +00:00
|
|
|
if (rootFolder->getParent() == nullptr) {
|
2020-06-21 12:25:28 +00:00
|
|
|
ViewController::get()->onFileChanged(rootFolder, FILE_METADATA_CHANGED);
|
2020-09-21 16:13:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-06-21 12:25:28 +00:00
|
|
|
ViewController::get()->onFileChanged(
|
|
|
|
rootFolder->getParent(), FILE_METADATA_CHANGED);
|
2020-09-21 16:13:27 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 22:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::trimCollectionCount(FileData* rootFolder, int limit)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData* curSys = rootFolder->getSystem();
|
2020-10-25 18:42:25 +00:00
|
|
|
while (static_cast<int>(rootFolder->getChildrenListToDisplay().size()) > limit) {
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionFileData* gameToRemove =
|
|
|
|
(CollectionFileData*)rootFolder->getChildrenListToDisplay().back();
|
|
|
|
ViewController::get()->getGameListView(curSys).get()->remove(gameToRemove, false);
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Delete all collection files from collection systems related to the source file.
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::deleteCollectionFiles(FileData* file)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Collection files use the full path as key, to avoid clashes.
|
|
|
|
std::string key = file->getFullPath();
|
|
|
|
|
|
|
|
// Find games in collection systems.
|
|
|
|
std::map<std::string, CollectionSystemData> allCollections;
|
|
|
|
allCollections.insert(mAutoCollectionSystemsData.cbegin(),
|
|
|
|
mAutoCollectionSystemsData.cend());
|
|
|
|
allCollections.insert(mCustomCollectionSystemsData.cbegin(),
|
|
|
|
mCustomCollectionSystemsData.cend());
|
|
|
|
|
|
|
|
for (auto sysDataIt = allCollections.begin(); sysDataIt != allCollections.end(); sysDataIt++) {
|
|
|
|
if (sysDataIt->second.isPopulated) {
|
|
|
|
const std::unordered_map<std::string, FileData*>& children =
|
|
|
|
(sysDataIt->second.system)->getRootFolder()->getChildrenByFilename();
|
|
|
|
|
|
|
|
bool found = children.find(key) != children.cend();
|
|
|
|
if (found) {
|
|
|
|
FileData* collectionEntry = children.at(key);
|
|
|
|
SystemData* systemViewToUpdate = getSystemToView(sysDataIt->second.system);
|
|
|
|
ViewController::get()->getGameListView(systemViewToUpdate).get()->
|
|
|
|
remove(collectionEntry, false);
|
2020-10-19 18:58:00 +00:00
|
|
|
if (sysDataIt->second.decl.isCustom)
|
|
|
|
saveCustomCollection(sysDataIt->second.system);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return whether the current theme is compatible with Automatic or Custom Collections.
|
2017-07-18 09:45:50 +00:00
|
|
|
bool CollectionSystemManager::isThemeGenericCollectionCompatible(bool genericCustomCollections)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> cfgSys = getCollectionThemeFolders(genericCustomCollections);
|
|
|
|
for (auto sysIt = cfgSys.cbegin(); sysIt != cfgSys.cend(); sysIt++) {
|
|
|
|
if (!themeFolderExists(*sysIt))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
bool CollectionSystemManager::isThemeCustomCollectionCompatible(
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> stringVector)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (isThemeGenericCollectionCompatible(true))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Get theme path.
|
|
|
|
auto themeSets = ThemeData::getThemeSets();
|
|
|
|
auto set = themeSets.find(Settings::getInstance()->getString("ThemeSet"));
|
|
|
|
if (set != themeSets.cend()) {
|
|
|
|
std::string defaultThemeFilePath = set->second.path + "/theme.xml";
|
|
|
|
if (Utils::FileSystem::exists(defaultThemeFilePath))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto sysIt = stringVector.cbegin(); sysIt != stringVector.cend(); sysIt++) {
|
|
|
|
if (!themeFolderExists(*sysIt))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::string CollectionSystemManager::getValidNewCollectionName(std::string inName, int index)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string name = inName;
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
size_t remove = std::string::npos;
|
|
|
|
|
|
|
|
// Get valid name.
|
|
|
|
while ((remove = name.find_first_not_of(
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-[]() "))
|
|
|
|
!= std::string::npos)
|
|
|
|
name.erase(remove, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name += " (" + std::to_string(index) + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "") {
|
|
|
|
name = "New Collection";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name != inName) {
|
|
|
|
LOG(LogInfo) << "Had to change name, from: " << inName << " to: " << name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get used systems from es_systems.cfg.
|
|
|
|
std::vector<std::string> systemsInUse = getSystemsFromConfig();
|
|
|
|
// Get folders assigned to custom collections.
|
|
|
|
std::vector<std::string> autoSys = getCollectionThemeFolders(false);
|
|
|
|
// Get folder assigned to custom collections.
|
|
|
|
std::vector<std::string> customSys = getCollectionThemeFolders(true);
|
|
|
|
// Get folders assigned to user collections.
|
|
|
|
std::vector<std::string> userSys = getUserCollectionThemeFolders();
|
|
|
|
// Add them all to the list of systems in use.
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), autoSys.cbegin(), autoSys.cend());
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), customSys.cbegin(), customSys.cend());
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), userSys.cbegin(), userSys.cend());
|
|
|
|
|
|
|
|
for (auto sysIt = systemsInUse.cbegin(); sysIt != systemsInUse.cend(); sysIt++) {
|
|
|
|
if (*sysIt == name) {
|
|
|
|
if (index > 0)
|
|
|
|
name = name.substr(0, name.size()-4);
|
|
|
|
return getValidNewCollectionName(name, index+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If it matches one of the custom collections reserved names then return it.
|
|
|
|
if (mCollectionSystemDeclsIndex.find(name) != mCollectionSystemDeclsIndex.cend())
|
|
|
|
return getValidNewCollectionName(name, index+1);
|
|
|
|
return name;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::setEditMode(std::string collectionName)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mCustomCollectionSystemsData.find(collectionName) == mCustomCollectionSystemsData.cend()) {
|
|
|
|
LOG(LogError) << "Tried to edit a non-existing collection: " << collectionName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsEditingCustom = true;
|
|
|
|
mEditingCollection = collectionName;
|
|
|
|
|
|
|
|
CollectionSystemData* sysData = &(mCustomCollectionSystemsData.at(mEditingCollection));
|
|
|
|
if (!sysData->isPopulated) {
|
|
|
|
populateCustomCollection(sysData);
|
|
|
|
}
|
|
|
|
// If it's bundled, this needs to be the bundle system.
|
|
|
|
mEditingCollectionSystemData = sysData;
|
|
|
|
|
2020-10-20 19:01:24 +00:00
|
|
|
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "EDITING THE '" +
|
2020-06-21 12:25:28 +00:00
|
|
|
Utils::String::toUpper(collectionName) +
|
2020-10-20 19:01:24 +00:00
|
|
|
"' COLLECTION, ADD/REMOVE GAMES WITH 'Y'", 10000);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
mWindow->setInfoPopup(s);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::exitEditMode()
|
|
|
|
{
|
2020-10-20 19:01:24 +00:00
|
|
|
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "FINISHED EDITING THE '" +
|
|
|
|
Utils::String::toUpper(mEditingCollection) + "' COLLECTION", 4000);
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mWindow->setInfoPopup(s);
|
|
|
|
mIsEditingCustom = false;
|
|
|
|
mEditingCollection = "Favorites";
|
2019-08-24 14:22:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mEditingCollectionSystemData->system->onMetaDataSavePoint();
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Add or remove a game from a specific collection.
|
2017-07-18 09:45:50 +00:00
|
|
|
bool CollectionSystemManager::toggleGameInCollection(FileData* file)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (file->getType() == GAME) {
|
|
|
|
GuiInfoPopup* s;
|
|
|
|
bool adding = true;
|
|
|
|
std::string name = file->getName();
|
|
|
|
std::string sysName = mEditingCollection;
|
|
|
|
if (mIsEditingCustom) {
|
|
|
|
SystemData* sysData = mEditingCollectionSystemData->system;
|
|
|
|
|
|
|
|
if (!mEditingCollectionSystemData->isPopulated)
|
|
|
|
populateCustomCollection(mEditingCollectionSystemData);
|
|
|
|
|
|
|
|
std::string key = file->getFullPath();
|
|
|
|
FileData* rootFolder = sysData->getRootFolder();
|
|
|
|
const std::unordered_map<std::string, FileData*>&
|
|
|
|
children = rootFolder->getChildrenByFilename();
|
|
|
|
bool found = children.find(key) != children.cend();
|
|
|
|
FileFilterIndex* fileIndex = sysData->getIndex();
|
|
|
|
std::string name = sysData->getName();
|
|
|
|
|
|
|
|
SystemData* systemViewToUpdate = getSystemToView(sysData);
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
adding = false;
|
|
|
|
// If we found it, we need to remove it.
|
|
|
|
FileData* collectionEntry = children.at(key);
|
|
|
|
// Remove from index.
|
|
|
|
fileIndex->removeFromIndex(collectionEntry);
|
|
|
|
// Remove from bundle index as well, if needed.
|
|
|
|
if (systemViewToUpdate != sysData)
|
|
|
|
systemViewToUpdate->getIndex()->removeFromIndex(collectionEntry);
|
|
|
|
|
|
|
|
ViewController::get()->getGameListView(systemViewToUpdate).get()->
|
|
|
|
remove(collectionEntry, false);
|
2020-09-21 16:13:27 +00:00
|
|
|
systemViewToUpdate->getRootFolder()->sort(rootFolder->getSortTypeFromString(
|
|
|
|
rootFolder->getSortTypeString()),
|
|
|
|
Settings::getInstance()->getBool("FavFirstCustom"));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We didn't find it here, so we should add it.
|
|
|
|
CollectionFileData* newGame = new CollectionFileData(file, sysData);
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
fileIndex->addToIndex(newGame);
|
|
|
|
ViewController::get()->getGameListView(systemViewToUpdate)->
|
|
|
|
onFileChanged(newGame, FILE_METADATA_CHANGED);
|
|
|
|
if (name == "recent")
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString("last played, descending"));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
ViewController::get()->onFileChanged(systemViewToUpdate->
|
|
|
|
getRootFolder(), FILE_SORTED);
|
|
|
|
|
|
|
|
// Add to bundle index as well, if needed.
|
|
|
|
if (systemViewToUpdate != sysData)
|
|
|
|
systemViewToUpdate->getIndex()->addToIndex(newGame);
|
2020-09-21 16:13:27 +00:00
|
|
|
refreshCollectionSystems(newGame);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2020-10-19 18:58:00 +00:00
|
|
|
saveCustomCollection(sysData);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
file->getSourceFileData()->getSystem()->getIndex()->removeFromIndex(file);
|
|
|
|
MetaDataList* md = &file->getSourceFileData()->metadata;
|
|
|
|
std::string value = md->get("favorite");
|
|
|
|
if (value == "false") {
|
|
|
|
md->set("favorite", "true");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
adding = false;
|
|
|
|
md->set("favorite", "false");
|
|
|
|
}
|
|
|
|
|
|
|
|
file->getSourceFileData()->getSystem()->getIndex()->addToIndex(file);
|
|
|
|
file->getSourceFileData()->getSystem()->onMetaDataSavePoint();
|
|
|
|
refreshCollectionSystems(file->getSourceFileData());
|
|
|
|
}
|
|
|
|
if (adding)
|
2020-10-20 19:01:24 +00:00
|
|
|
s = new GuiInfoPopup(mWindow, "ADDED '" +
|
|
|
|
Utils::String::toUpper(Utils::String::removeParenthesis(name)) +
|
|
|
|
"' TO '" + Utils::String::toUpper(sysName) + "'", 4000);
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2020-10-20 19:01:24 +00:00
|
|
|
s = new GuiInfoPopup(mWindow, "REMOVED '" +
|
|
|
|
Utils::String::toUpper(Utils::String::removeParenthesis(name)) +
|
|
|
|
"' FROM '" + Utils::String::toUpper(sysName) + "'", 4000);
|
2020-06-21 12:25:28 +00:00
|
|
|
mWindow->setInfoPopup(s);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
SystemData* CollectionSystemManager::getSystemToView(SystemData* sys)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData* systemToView = sys;
|
|
|
|
FileData* rootFolder = sys->getRootFolder();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
FileData* bundleRootFolder = mCustomCollectionsBundle->getRootFolder();
|
|
|
|
const std::unordered_map<std::string, FileData*>&
|
|
|
|
bundleChildren = bundleRootFolder->getChildrenByFilename();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Is the rootFolder bundled in the "My Collections" system?
|
|
|
|
bool sysFoundInBundle = bundleChildren.find(rootFolder->getKey()) != bundleChildren.cend();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (sysFoundInBundle && sys->isCollection())
|
|
|
|
systemToView = mCustomCollectionsBundle;
|
|
|
|
return systemToView;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Functions below to Handle loading of collection systems, creating empty ones,
|
|
|
|
// and populating on demand.
|
|
|
|
|
|
|
|
// Loads Automatic Collection systems (All, Favorites, Last Played).
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::initAutoCollectionSystems()
|
|
|
|
{
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemDecl, stringComparator>::const_iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mCollectionSystemDeclsIndex.cbegin();
|
|
|
|
it != mCollectionSystemDeclsIndex.cend() ; it++ ) {
|
|
|
|
CollectionSystemDecl sysDecl = it->second;
|
|
|
|
|
|
|
|
if (!sysDecl.isCustom)
|
|
|
|
createNewCollectionEntry(sysDecl.name, sysDecl);
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 19:01:24 +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* CollectionSystemManager::updateCollectionFolderMetadata(SystemData* sys)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
FileData* rootFolder = sys->getRootFolder();
|
|
|
|
std::string desc = "This collection is empty.";
|
2020-10-20 19:01:24 +00:00
|
|
|
std::vector<FileData*> gamesList = rootFolder->getChildren();
|
2020-10-21 19:56:31 +00:00
|
|
|
std::vector<FileData*> gamesListRandom;
|
2020-10-20 19:01:24 +00:00
|
|
|
unsigned int gameCount = gamesList.size();
|
|
|
|
|
2020-10-21 19:56:31 +00:00
|
|
|
// If there is more than 1 game in the collection, then randomize the example game names.
|
|
|
|
if (gameCount > 1) {
|
|
|
|
std::random_device randDev;
|
|
|
|
// Mersenne Twister pseudorandom number generator.
|
|
|
|
std::mt19937 engine{randDev()};
|
|
|
|
unsigned int target;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < 3; i++) {
|
|
|
|
std::uniform_int_distribution<int> uniform_dist(0, gameCount - 1 - i);
|
|
|
|
target = uniform_dist(engine);
|
|
|
|
gamesListRandom.push_back(gamesList[target]);
|
|
|
|
std::vector<FileData*>::iterator it = (gamesList.begin() + target);
|
|
|
|
gamesList.erase(it);
|
|
|
|
if (gamesList.size() == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gamesList.clear();
|
|
|
|
gamesList.insert(gamesList.end(), gamesListRandom.begin(), gamesListRandom.end());
|
|
|
|
gamesListRandom.clear();
|
|
|
|
}
|
|
|
|
|
2020-10-20 19:01:24 +00:00
|
|
|
if (gameCount > 0) {
|
|
|
|
switch (gameCount) {
|
|
|
|
case 1:
|
|
|
|
desc = "This collection contains 1 game: '" + gamesList[0]->metadata.get("name") +
|
|
|
|
" [" + gamesList[0]->getSourceFileData()->getSystem()->getName() + "]'.";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
desc = "This collection contains 2 games: '" + gamesList[0]->metadata.get("name") +
|
|
|
|
" [" + gamesList[0]->getSourceFileData()->getSystem()->getName() +
|
|
|
|
"]' and '" + gamesList[1]->metadata.get("name") + " [" +
|
|
|
|
gamesList[1]->getSourceFileData()->getSystem()->getName() + "]'.";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
desc = "This collection contains " + std::to_string(gameCount) +
|
|
|
|
" games: '" + gamesList[0]->metadata.get("name") +
|
|
|
|
" [" + gamesList[0]->getSourceFileData()->getSystem()->getName() +
|
|
|
|
"]', '" + gamesList[1]->metadata.get("name") + " [" +
|
|
|
|
gamesList[1]->getSourceFileData()->getSystem()->getName() + "]' and '" +
|
|
|
|
gamesList[2]->metadata.get("name") + " [" +
|
|
|
|
gamesList[2]->getSourceFileData()->getSystem()->getName() + "]'";
|
|
|
|
desc += (gameCount == 3 ? "." : ", among others.");
|
|
|
|
break;
|
2020-07-28 13:19:54 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rootFolder->metadata.set("desc", desc);
|
2020-10-21 19:56:31 +00:00
|
|
|
// Return a pointer to the first game so that its
|
|
|
|
// game media can be displayed in the gamelist.
|
|
|
|
if (gamesList.size() > 0)
|
|
|
|
return gamesList.front();
|
|
|
|
else
|
|
|
|
return nullptr;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::initCustomCollectionSystems()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems = getCollectionsFromConfigFolder();
|
|
|
|
for (auto nameIt = systems.cbegin(); nameIt != systems.cend(); nameIt++) {
|
|
|
|
addNewCustomCollection(*nameIt);
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
SystemData* CollectionSystemManager::getAllGamesCollection()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionSystemData* allSysData = &mAutoCollectionSystemsData["all"];
|
|
|
|
if (!allSysData->isPopulated)
|
|
|
|
populateAutoCollection(allSysData);
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return allSysData->system;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemData* CollectionSystemManager::addNewCustomCollection(std::string name)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionSystemDecl decl = mCollectionSystemDeclsIndex[myCollectionsName];
|
|
|
|
decl.themeFolder = name;
|
|
|
|
decl.name = name;
|
|
|
|
decl.longName = name;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-09-21 16:13:27 +00:00
|
|
|
return createNewCollectionEntry(name, decl, true, true);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Create a new empty collection system based on the name and declaration.
|
|
|
|
SystemData* CollectionSystemManager::createNewCollectionEntry(
|
2020-09-21 16:13:27 +00:00
|
|
|
std::string name, CollectionSystemDecl sysDecl, bool index, bool custom)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-10-22 19:23:16 +00:00
|
|
|
SystemData* newSys = new SystemData(name, sysDecl.longName,
|
|
|
|
mCollectionEnvData, sysDecl.themeFolder, true, custom);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
CollectionSystemData newCollectionData;
|
|
|
|
newCollectionData.system = newSys;
|
|
|
|
newCollectionData.decl = sysDecl;
|
|
|
|
newCollectionData.isEnabled = false;
|
|
|
|
newCollectionData.isPopulated = false;
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
if (!sysDecl.isCustom)
|
|
|
|
mAutoCollectionSystemsData[name] = newCollectionData;
|
|
|
|
else
|
|
|
|
mCustomCollectionSystemsData[name] = newCollectionData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newSys;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Populate an automatic collection system.
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::populateAutoCollection(CollectionSystemData* sysData)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData* newSys = sysData->system;
|
|
|
|
CollectionSystemDecl sysDecl = sysData->decl;
|
|
|
|
FileData* rootFolder = newSys->getRootFolder();
|
|
|
|
FileFilterIndex* index = newSys->getIndex();
|
|
|
|
for (auto sysIt = SystemData::sSystemVector.cbegin();
|
|
|
|
sysIt != SystemData::sSystemVector.cend(); sysIt++) {
|
|
|
|
// We won't iterate all collections.
|
|
|
|
if ((*sysIt)->isGameSystem() && !(*sysIt)->isCollection()) {
|
|
|
|
std::vector<FileData*> files = (*sysIt)->getRootFolder()->getFilesRecursive(GAME);
|
|
|
|
for (auto gameIt = files.cbegin(); gameIt != files.cend(); gameIt++) {
|
|
|
|
bool include = includeFileInAutoCollections((*gameIt));
|
|
|
|
|
|
|
|
switch (sysDecl.type) {
|
|
|
|
case AUTO_LAST_PLAYED:
|
|
|
|
include = include && (*gameIt)->metadata.get("playcount") > "0";
|
|
|
|
break;
|
|
|
|
case AUTO_FAVORITES:
|
|
|
|
// We may still want to add files we don't
|
|
|
|
// want in auto collections in "favorites"
|
|
|
|
include = (*gameIt)->metadata.get("favorite") == "true";
|
|
|
|
break;
|
2020-06-25 17:52:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (include) {
|
2020-07-29 17:01:49 +00:00
|
|
|
// Exclude files that are set not to be counted as games.
|
2020-08-06 20:11:55 +00:00
|
|
|
if (!(*gameIt)->getCountAsGame())
|
2020-07-29 17:01:49 +00:00
|
|
|
continue;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
CollectionFileData* newGame = new CollectionFileData(*gameIt, newSys);
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
index->addToIndex(newGame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rootFolder->getName() == "recent")
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString("last played, descending"));
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2020-06-21 12:25:28 +00:00
|
|
|
Settings::getInstance()->getBool("FavoritesFirst"));
|
|
|
|
|
|
|
|
if (sysDecl.type == AUTO_LAST_PLAYED)
|
|
|
|
trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
|
|
|
|
sysData->isPopulated = true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 16:32:23 +00:00
|
|
|
// Populate a custom collection system.
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::populateCustomCollection(CollectionSystemData* sysData)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData* newSys = sysData->system;
|
|
|
|
sysData->isPopulated = true;
|
|
|
|
CollectionSystemDecl sysDecl = sysData->decl;
|
|
|
|
std::string path = getCustomCollectionConfigPath(newSys->getName());
|
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(path)) {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogInfo) << "Couldn't find custom collection config file \"" << path << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogInfo) << "Parsing custom collection file \"" << path << "\"...";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
FileData* rootFolder = newSys->getRootFolder();
|
|
|
|
FileFilterIndex* index = newSys->getIndex();
|
|
|
|
|
|
|
|
// Get configuration for this custom collection.
|
2020-07-10 16:32:23 +00:00
|
|
|
#if _WIN64
|
|
|
|
std::ifstream input(Utils::String::stringToWideString(path).c_str());
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
std::ifstream input(path);
|
2020-07-10 16:32:23 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Get all files map.
|
|
|
|
std::unordered_map<std::string,FileData*>
|
|
|
|
allFilesMap = getAllGamesCollection()->getRootFolder()->getChildrenByFilename();
|
|
|
|
|
|
|
|
// Get the ROM directory, either as configured in es_settings.cfg, or if no value
|
|
|
|
// is set there, then use the default hardcoded path.
|
2020-07-26 20:19:29 +00:00
|
|
|
const std::string rompath = FileData::getROMDirectory();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Iterate list of files in the config file.
|
|
|
|
for (std::string gameKey; getline(input, gameKey); ) {
|
|
|
|
// If there is a %ROMPATH% variable set for the game, expand it. By doing this
|
|
|
|
// it's possible to use either absolute ROM paths in the collection files or using
|
|
|
|
// the path variable. The absolute ROM paths are only used for backward compatibility
|
|
|
|
// with old custom collections. All custom collections saved by EmulationStation-DE
|
|
|
|
// will use the %ROMPATH% variable instead.
|
|
|
|
gameKey = Utils::String::replace(gameKey, "%ROMPATH%", rompath);
|
|
|
|
gameKey = Utils::String::replace(gameKey, "//", "/");
|
|
|
|
|
|
|
|
std::unordered_map<std::string,FileData*>::const_iterator it = allFilesMap.find(gameKey);
|
|
|
|
if (it != allFilesMap.cend()) {
|
|
|
|
CollectionFileData* newGame = new CollectionFileData(it->second, newSys);
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
index->addToIndex(newGame);
|
|
|
|
}
|
|
|
|
else {
|
2020-10-20 19:01:24 +00:00
|
|
|
LOG(LogWarning) << "File \"" << gameKey <<
|
|
|
|
"\" does not exist, is hidden, or is not counted as a game, ignoring entry";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Functions below to handle System View removal and insertion of collections.
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::removeCollectionsFromDisplayedSystems()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Remove all collection Systems.
|
|
|
|
for (auto sysIt = SystemData::sSystemVector.cbegin();
|
|
|
|
sysIt != SystemData::sSystemVector.cend(); ) {
|
|
|
|
if ((*sysIt)->isCollection())
|
|
|
|
sysIt = SystemData::sSystemVector.erase(sysIt);
|
|
|
|
else
|
|
|
|
sysIt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all custom collections in bundle.
|
|
|
|
// This should not delete the objects from memory!
|
|
|
|
FileData* customRoot = mCustomCollectionsBundle->getRootFolder();
|
|
|
|
std::vector<FileData*> mChildren = customRoot->getChildren();
|
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
|
|
|
|
customRoot->removeChild(*it);
|
|
|
|
}
|
|
|
|
// Clear index.
|
|
|
|
mCustomCollectionsBundle->getIndex()->resetIndex();
|
|
|
|
// Remove view so it's re-created as needed.
|
|
|
|
ViewController::get()->removeGameListView(mCustomCollectionsBundle);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems(
|
2020-10-22 19:23:16 +00:00
|
|
|
std::map<std::string, CollectionSystemData, stringComparator>* colSystemData)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Add auto enabled collections.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = colSystemData->begin() ; it != colSystemData->end() ; it++ ) {
|
|
|
|
if (it->second.isEnabled) {
|
|
|
|
// Check if populated, otherwise populate.
|
|
|
|
if (!it->second.isPopulated) {
|
|
|
|
if (it->second.decl.isCustom)
|
|
|
|
populateCustomCollection(&(it->second));
|
|
|
|
else
|
|
|
|
populateAutoCollection(&(it->second));
|
|
|
|
}
|
|
|
|
// Check if it has its own view.
|
|
|
|
if (!it->second.decl.isCustom || themeFolderExists(it->first) ||
|
|
|
|
!Settings::getInstance()->getBool("UseCustomCollectionsSystem")) {
|
|
|
|
// Theme folder exists, or we chose not to bundle it under the
|
|
|
|
// custom-collections system. So we need to create a view.
|
|
|
|
SystemData::sSystemVector.push_back(it->second.system);
|
|
|
|
// If this is a non-bundled custom collection, then sort it.
|
|
|
|
if (it->second.decl.isCustom == true) {
|
|
|
|
FileData* rootFolder = it->second.system->getRootFolder();
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(
|
|
|
|
rootFolder->getSortTypeString()),
|
2020-06-21 12:25:28 +00:00
|
|
|
Settings::getInstance()->getBool("FavFirstCustom"));
|
|
|
|
// Jump to the first row of the game list, assuming it's not empty.
|
|
|
|
IGameListView* gameList = ViewController::get()->
|
|
|
|
getGameListView((it->second.system)).get();
|
|
|
|
if (!gameList->getCursor()->isPlaceHolder()) {
|
|
|
|
gameList->setCursor(gameList->getFirstEntry());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FileData* newSysRootFolder = it->second.system->getRootFolder();
|
|
|
|
mCustomCollectionsBundle->getRootFolder()->addChild(newSysRootFolder);
|
|
|
|
mCustomCollectionsBundle->getIndex()->importIndex(it->second.system->getIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Auxiliary functions below to get available custom collection possibilities.
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> CollectionSystemManager::getSystemsFromConfig()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
|
|
|
std::string path = SystemData::getConfigPath(false);
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Utils::FileSystem::exists(path))
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_document doc;
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(Utils::String::stringToWideString(path).c_str());
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(path.c_str());
|
2020-07-10 16:32:23 +00:00
|
|
|
#endif
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!res)
|
|
|
|
return systems;
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Actually read the file.
|
|
|
|
pugi::xml_node systemList = doc.child("systemList");
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!systemList)
|
|
|
|
return systems;
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (pugi::xml_node system = systemList.child("system");
|
|
|
|
system; system = system.next_sibling("system")) {
|
|
|
|
// Theme folder.
|
|
|
|
std::string themeFolder = system.child("theme").text().get();
|
|
|
|
systems.push_back(themeFolder);
|
|
|
|
}
|
|
|
|
std::sort(systems.begin(), systems.end());
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Get all folders from the current theme path.
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> CollectionSystemManager::getSystemsFromTheme()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
|
|
|
|
|
|
|
auto themeSets = ThemeData::getThemeSets();
|
|
|
|
if (themeSets.empty())
|
|
|
|
return systems; // No theme sets available.
|
|
|
|
|
|
|
|
std::map<std::string, ThemeSet>::const_iterator
|
|
|
|
set = themeSets.find(Settings::getInstance()->getString("ThemeSet"));
|
|
|
|
if (set == themeSets.cend()) {
|
|
|
|
// Currently selected theme set is missing, so just pick the first available set.
|
|
|
|
set = themeSets.cbegin();
|
|
|
|
Settings::getInstance()->setString("ThemeSet", set->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string themePath = set->second.path;
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(themePath)) {
|
|
|
|
Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(themePath);
|
|
|
|
|
|
|
|
for (Utils::FileSystem::stringList::const_iterator
|
|
|
|
it = dirContent.cbegin(); it != dirContent.cend(); ++it) {
|
|
|
|
if (Utils::FileSystem::isDirectory(*it)) {
|
|
|
|
// ... here you have a directory.
|
|
|
|
std::string folder = *it;
|
|
|
|
folder = folder.substr(themePath.size()+1);
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(set->second.getThemePath(folder)))
|
|
|
|
systems.push_back(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::sort(systems.begin(), systems.end());
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return the unused folders from current theme path.
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> CollectionSystemManager::getUnusedSystemsFromTheme()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Get used systems in es_systems.cfg.
|
|
|
|
std::vector<std::string> systemsInUse = getSystemsFromConfig();
|
|
|
|
// Get available folders in theme.
|
|
|
|
std::vector<std::string> themeSys = getSystemsFromTheme();
|
|
|
|
// Get folders assigned to custom collections.
|
|
|
|
std::vector<std::string> autoSys = getCollectionThemeFolders(false);
|
|
|
|
// Get folder assigned to custom collections.
|
|
|
|
std::vector<std::string> customSys = getCollectionThemeFolders(true);
|
|
|
|
// Get folders assigned to user collections.
|
|
|
|
std::vector<std::string> userSys = getUserCollectionThemeFolders();
|
|
|
|
// Add them all to the list of systems in use.
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), autoSys.cbegin(), autoSys.cend());
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), customSys.cbegin(), customSys.cend());
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), userSys.cbegin(), userSys.cend());
|
|
|
|
|
|
|
|
for (auto sysIt = themeSys.cbegin(); sysIt != themeSys.cend(); ) {
|
|
|
|
if (std::find(systemsInUse.cbegin(), systemsInUse.cend(), *sysIt) != systemsInUse.cend())
|
|
|
|
sysIt = themeSys.erase(sysIt);
|
|
|
|
else
|
|
|
|
sysIt++;
|
|
|
|
}
|
|
|
|
return themeSys;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return which collection config files exist in the user folder.
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> CollectionSystemManager::getCollectionsFromConfigFolder()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
|
|
|
std::string configPath = getCollectionsFolder();
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(configPath))
|
|
|
|
{
|
|
|
|
Utils::FileSystem::stringList dirContent =
|
|
|
|
Utils::FileSystem::getDirContent(configPath);
|
|
|
|
for (Utils::FileSystem::stringList::const_iterator
|
|
|
|
it = dirContent.cbegin(); it != dirContent.cend(); ++it) {
|
|
|
|
if (Utils::FileSystem::isRegularFile(*it)) {
|
|
|
|
// It's a file.
|
|
|
|
std::string filename = Utils::FileSystem::getFileName(*it);
|
|
|
|
// Need to confirm filename matches config format.
|
|
|
|
if (filename != "custom-.cfg" && Utils::String::startsWith(
|
|
|
|
filename, "custom-") && Utils::String::endsWith(filename, ".cfg")) {
|
|
|
|
filename = filename.substr(7, filename.size()-11);
|
|
|
|
systems.push_back(filename);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogInfo) << "Found non-collection config file in collections folder: "
|
|
|
|
<< filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return the theme folders for automatic collections (All, Favorites, Last Played)
|
|
|
|
// or a generic custom collections folder.
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> CollectionSystemManager::getCollectionThemeFolders(bool custom)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemDecl, stringComparator>::const_iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mCollectionSystemDeclsIndex.cbegin();
|
|
|
|
it != mCollectionSystemDeclsIndex.cend() ; it++ ) {
|
|
|
|
CollectionSystemDecl sysDecl = it->second;
|
|
|
|
if (sysDecl.isCustom == custom)
|
|
|
|
systems.push_back(sysDecl.themeFolder);
|
|
|
|
}
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return the theme folders in use for the user-defined custom collections.
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> CollectionSystemManager::getUserCollectionThemeFolders()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mCustomCollectionSystemsData.cbegin();
|
|
|
|
it != mCustomCollectionSystemsData.cend() ; it++ )
|
|
|
|
systems.push_back(it->second.decl.themeFolder);
|
|
|
|
return systems;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return whether a specific folder exists in the theme.
|
2017-07-18 09:45:50 +00:00
|
|
|
bool CollectionSystemManager::themeFolderExists(std::string folder)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> themeSys = getSystemsFromTheme();
|
|
|
|
return std::find(themeSys.cbegin(), themeSys.cend(), folder) != themeSys.cend();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CollectionSystemManager::includeFileInAutoCollections(FileData* file)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// We exclude non-game files from collections (i.e. "kodi", entries from non-game systems).
|
|
|
|
// If/when there are more in the future, maybe this can be a more complex method, with a
|
|
|
|
// proper list, but for now a simple string comparison is more performant.
|
|
|
|
return file->getName() != "kodi" && file->getSystem()->isGameSystem();
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 18:42:25 +00:00
|
|
|
std::string CollectionSystemManager::getCustomCollectionConfigPath(std::string collectionName)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return getCollectionsFolder() + "/custom-" + collectionName + ".cfg";
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 18:42:25 +00:00
|
|
|
std::string CollectionSystemManager::getCollectionsFolder()
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return Utils::FileSystem::getGenericPath(Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/collections");
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Return whether the system is a custom collection.
|
|
|
|
bool CollectionSystemManager::getIsCustomCollection(SystemData* system)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Iterate the map.
|
2020-10-22 19:23:16 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, stringComparator>::const_iterator
|
2020-06-21 12:25:28 +00:00
|
|
|
it = mCustomCollectionSystemsData.cbegin();
|
|
|
|
it != mCustomCollectionSystemsData.cend() ; it++) {
|
|
|
|
if (it->second.system == system)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-05-24 08:29:29 +00:00
|
|
|
}
|