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.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.
|
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
|
|
|
//
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
#include "CollectionSystemsManager.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
#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"
|
2022-01-17 20:53:23 +00:00
|
|
|
#include "UIModeController.h"
|
2021-10-07 16:31:40 +00:00
|
|
|
#include "Window.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
|
|
|
#include "utils/StringUtil.h"
|
|
|
|
#include "utils/TimeUtil.h"
|
2022-01-18 19:42:50 +00:00
|
|
|
#include "views/GamelistView.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
|
|
|
|
2023-07-28 20:19:33 +00:00
|
|
|
#define INVALID_COLLECTION_CHARACTERS "*\",./:;<>\\|\n\t\r"
|
2023-07-28 19:55:39 +00:00
|
|
|
|
2022-01-04 20:21:26 +00:00
|
|
|
CollectionSystemsManager::CollectionSystemsManager() noexcept
|
2022-01-16 17:18:28 +00:00
|
|
|
: mWindow {Window::getInstance()}
|
2023-02-09 23:40:16 +00:00
|
|
|
, mApplicationStartup {false}
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
// clang-format off
|
2022-01-16 17:18:28 +00:00
|
|
|
CollectionSystemDecl systemDecls[] {
|
2021-08-24 16:29:46 +00:00
|
|
|
// Type Name Long name Theme folder isCustom
|
2021-08-17 16:41:45 +00:00
|
|
|
{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 }
|
2020-06-21 12:25:28 +00:00
|
|
|
};
|
2021-07-07 18:03:42 +00:00
|
|
|
// clang-format on
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Create a map of the collections.
|
2022-01-16 17:18:28 +00:00
|
|
|
std::vector<CollectionSystemDecl> tempSystemDecl {std::vector<CollectionSystemDecl>(
|
|
|
|
systemDecls, systemDecls + sizeof(systemDecls) / sizeof(systemDecls[0]))};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
for (std::vector<CollectionSystemDecl>::const_iterator it = tempSystemDecl.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != tempSystemDecl.cend(); ++it)
|
2020-06-21 12:25:28 +00:00
|
|
|
mCollectionSystemDeclsIndex[(*it).name] = (*it);
|
|
|
|
|
|
|
|
// Setup the standard environment.
|
|
|
|
mCollectionEnvData = new SystemEnvironmentData;
|
|
|
|
mCollectionEnvData->mStartPath = "";
|
|
|
|
std::vector<std::string> exts;
|
|
|
|
mCollectionEnvData->mSearchExtensions = exts;
|
2021-08-22 13:26:38 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> commands;
|
|
|
|
mCollectionEnvData->mLaunchCommands = commands;
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<PlatformIds::PlatformId> allPlatformIds;
|
|
|
|
allPlatformIds.push_back(PlatformIds::PLATFORM_IGNORE);
|
|
|
|
mCollectionEnvData->mPlatformIds = allPlatformIds;
|
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string path {getCollectionsFolder()};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Utils::FileSystem::exists(path))
|
|
|
|
Utils::FileSystem::createDirectory(path);
|
|
|
|
|
|
|
|
mIsEditingCustom = false;
|
2021-03-15 17:28:32 +00:00
|
|
|
mHasEnabledCustomCollection = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
mEditingCollection = "Favorites";
|
2020-06-23 18:07:00 +00:00
|
|
|
mEditingCollectionSystemData = nullptr;
|
|
|
|
mCustomCollectionsBundle = nullptr;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 22:14:12 +00:00
|
|
|
CollectionSystemsManager* CollectionSystemsManager::getInstance()
|
|
|
|
{
|
|
|
|
static CollectionSystemsManager instance;
|
|
|
|
return &instance;
|
|
|
|
}
|
|
|
|
|
2023-07-20 19:59:28 +00:00
|
|
|
void CollectionSystemsManager::deinit(const bool shutdown)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Don't attempt to remove any collections if no systems exist.
|
2022-01-04 22:14:12 +00:00
|
|
|
if (SystemData::sSystemVector.size() > 0) {
|
2020-06-21 12:25:28 +00:00
|
|
|
removeCollectionsFromDisplayedSystems();
|
|
|
|
|
2022-01-04 22:14:12 +00:00
|
|
|
// Delete all custom collections.
|
2023-07-20 19:59:28 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, StringComparator>::iterator it =
|
|
|
|
mCustomCollectionSystemsData.begin();
|
|
|
|
it != mCustomCollectionSystemsData.end(); ++it) {
|
2022-01-04 22:14:12 +00:00
|
|
|
delete it->second.system;
|
2023-07-20 19:59:28 +00:00
|
|
|
it->second.system = nullptr;
|
|
|
|
}
|
2020-10-11 16:57:37 +00:00
|
|
|
|
2023-07-28 21:04:41 +00:00
|
|
|
mCustomCollectionSystemsData.clear();
|
|
|
|
|
2022-01-04 22:14:12 +00:00
|
|
|
// Delete the custom collections bundle.
|
2023-07-20 19:59:28 +00:00
|
|
|
if (mCustomCollectionsBundle) {
|
2022-01-04 22:14:12 +00:00
|
|
|
delete mCustomCollectionsBundle;
|
2023-07-20 19:59:28 +00:00
|
|
|
mCustomCollectionsBundle = nullptr;
|
|
|
|
}
|
2020-10-18 20:28:18 +00:00
|
|
|
|
2022-01-04 22:14:12 +00:00
|
|
|
// Delete the auto collections systems.
|
2023-07-20 19:59:28 +00:00
|
|
|
for (auto it = mAutoCollectionSystemsData.begin(); // Line break.
|
|
|
|
it != mAutoCollectionSystemsData.end(); ++it) {
|
2022-01-04 22:14:12 +00:00
|
|
|
delete (*it).second.system;
|
2023-07-20 19:59:28 +00:00
|
|
|
(*it).second.system = nullptr;
|
|
|
|
}
|
2022-01-04 22:14:12 +00:00
|
|
|
}
|
2020-10-11 16:57:37 +00:00
|
|
|
|
2023-07-20 19:59:28 +00:00
|
|
|
if (shutdown)
|
|
|
|
delete mCollectionEnvData;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::saveCustomCollection(SystemData* sys)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2023-07-29 21:53:01 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
std::string rompath {Utils::String::replace(FileData::getROMDirectory(), "\\", "/")};
|
|
|
|
#else
|
|
|
|
std::string rompath {FileData::getROMDirectory()};
|
|
|
|
#endif
|
|
|
|
rompath = Utils::String::replace(rompath, "//", "/");
|
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string name {sys->getName()};
|
|
|
|
std::unordered_map<std::string, FileData*> games {
|
|
|
|
sys->getRootFolder()->getChildrenByFilename()};
|
|
|
|
bool found {mCustomCollectionSystemsData.find(name) != mCustomCollectionSystemsData.cend()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (found) {
|
2023-07-29 21:53:01 +00:00
|
|
|
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;
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
configFileIn.open(
|
2023-08-10 21:13:55 +00:00
|
|
|
Utils::String::stringToWideString(getCustomCollectionConfigPath(name)).c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2023-08-10 21:13:55 +00:00
|
|
|
configFileIn.open(getCustomCollectionConfigPath(name));
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
|
|
|
for (std::string gameEntry; getline(configFileIn, gameEntry);) {
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string gamePath {Utils::String::replace(gameEntry, "%ROMPATH%", rompath)};
|
2020-10-19 18:58:00 +00:00
|
|
|
gamePath = Utils::String::replace(gamePath, "//", "/");
|
2023-07-29 21:56:44 +00:00
|
|
|
// Only add the entry if it doesn't exist, i.e. only add missing files.
|
|
|
|
if (!Utils::FileSystem::exists(gamePath))
|
2020-10-19 18:58:00 +00:00
|
|
|
fileGameEntries.push_back(gameEntry);
|
|
|
|
}
|
|
|
|
configFileIn.close();
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
for (std::unordered_map<std::string, FileData*>::const_iterator it = games.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != games.cend(); ++it) {
|
2023-07-29 21:53:01 +00:00
|
|
|
std::string path {it->first};
|
2020-10-19 18:58:00 +00:00
|
|
|
// 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(),
|
2021-07-07 18:03:42 +00:00
|
|
|
activeGameEntries.cend());
|
2020-10-19 18:58:00 +00:00
|
|
|
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
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
configFileOut.open(
|
2023-08-10 21:02:36 +00:00
|
|
|
Utils::String::stringToWideString(getCustomCollectionConfigPath(name)).c_str(),
|
|
|
|
std::ios::binary);
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2023-08-10 21:02:36 +00:00
|
|
|
configFileOut.open(getCustomCollectionConfigPath(name), std::ios::binary);
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-10-19 17:51:19 +00:00
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = fileGameEntries.cbegin(); it != fileGameEntries.cend(); ++it)
|
2020-10-19 18:58:00 +00:00
|
|
|
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-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::loadCollectionSystems()
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2023-02-09 23:40:16 +00:00
|
|
|
mApplicationStartup = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
initAutoCollectionSystems();
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemDecl decl {mCollectionSystemDeclsIndex[myCollectionsName]};
|
2020-06-21 12:25:28 +00:00
|
|
|
mCustomCollectionsBundle = createNewCollectionEntry(decl.name, decl, false);
|
|
|
|
|
|
|
|
// We will also load custom systems here.
|
|
|
|
initCustomCollectionSystems();
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getString("CollectionSystemsAuto") != "" ||
|
2021-07-07 18:03:42 +00:00
|
|
|
Settings::getInstance()->getString("CollectionSystemsCustom") != "") {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Now see which ones are enabled.
|
|
|
|
loadEnabledListFromSettings();
|
|
|
|
// Add to the main System Vector, and create Views as needed.
|
|
|
|
updateSystemsList();
|
|
|
|
}
|
2023-02-09 23:40:16 +00:00
|
|
|
|
|
|
|
mApplicationStartup = false;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::loadEnabledListFromSettings()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// We parse the auto collection settings list.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> autoSelected {Utils::String::delimitedStringToVector(
|
|
|
|
Settings::getInstance()->getString("CollectionSystemsAuto"), ",", true)};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Iterate the map.
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, StringComparator>::iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
mAutoCollectionSystemsData.begin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mAutoCollectionSystemsData.end(); ++it) {
|
2021-07-07 18:03:42 +00:00
|
|
|
it->second.isEnabled = (std::find(autoSelected.cbegin(), autoSelected.cend(), it->first) !=
|
|
|
|
autoSelected.cend());
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mHasEnabledCustomCollection = false;
|
|
|
|
|
|
|
|
// Parse the custom collection settings list.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> customSelected {Utils::String::delimitedStringToVector(
|
|
|
|
Settings::getInstance()->getString("CollectionSystemsCustom"), ",", true)};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Iterate the map.
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, StringComparator>::iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
mCustomCollectionSystemsData.begin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mCustomCollectionSystemsData.end(); ++it) {
|
2021-07-07 18:03:42 +00:00
|
|
|
it->second.isEnabled = (std::find(customSelected.cbegin(), customSelected.cend(),
|
|
|
|
it->first) != customSelected.cend());
|
2020-06-21 12:25:28 +00:00
|
|
|
if (it->second.isEnabled)
|
|
|
|
mHasEnabledCustomCollection = true;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::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) {
|
2021-07-07 18:03:42 +00:00
|
|
|
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);
|
|
|
|
|
2023-02-09 23:40:16 +00:00
|
|
|
if (mApplicationStartup)
|
|
|
|
return;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Create views for collections, before reload.
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto sysIt = SystemData::sSystemVector.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
sysIt != SystemData::sSystemVector.cend(); ++sysIt) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*sysIt)->isCollection())
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView((*sysIt));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2021-02-04 19:14:20 +00:00
|
|
|
void CollectionSystemsManager::refreshCollectionSystems(FileData* file,
|
2021-07-07 18:03:42 +00:00
|
|
|
bool refreshDisabledAutoCollections)
|
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;
|
2021-07-07 18:03:42 +00:00
|
|
|
allCollections.insert(mAutoCollectionSystemsData.cbegin(), mAutoCollectionSystemsData.cend());
|
2020-06-21 12:25:28 +00:00
|
|
|
allCollections.insert(mCustomCollectionSystemsData.cbegin(),
|
2021-07-07 18:03:42 +00:00
|
|
|
mCustomCollectionSystemsData.cend());
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto sysDataIt = allCollections.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
sysDataIt != allCollections.cend(); ++sysDataIt) {
|
2021-02-04 19:14:20 +00:00
|
|
|
if (sysDataIt->second.isEnabled || (refreshDisabledAutoCollections &&
|
2021-07-07 18:03:42 +00:00
|
|
|
!sysDataIt->second.system->isGroupedCustomCollection()))
|
2020-06-21 12:25:28 +00:00
|
|
|
updateCollectionSystem(file, sysDataIt->second);
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::updateCollectionSystem(FileData* file, CollectionSystemData sysData)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-08-06 20:11:55 +00:00
|
|
|
if (sysData.isPopulated) {
|
2020-10-26 20:53:11 +00:00
|
|
|
// Skip all custom collections where the game does not exist.
|
|
|
|
if (sysData.decl.isCustom) {
|
|
|
|
if (!inCustomCollection(sysData.system->getFullName(), file))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Collection files use the full path as key, to avoid clashes.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string key {file->getFullPath()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* curSys {sysData.system};
|
2023-01-01 14:31:03 +00:00
|
|
|
bool favoritesSorting {false};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Read the applicable favorite sorting setting depending on whether the
|
|
|
|
// system is a custom collection or not.
|
|
|
|
if (sysData.decl.isCustom)
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting = Settings::getInstance()->getBool("FavFirstCustom");
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting = Settings::getInstance()->getBool("FavoritesFirst");
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2023-01-12 18:45:54 +00:00
|
|
|
const std::unordered_map<std::string, FileData*>& children {
|
|
|
|
curSys->getRootFolder()->getChildrenByFilename()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
bool found {children.find(key) != children.cend()};
|
|
|
|
FileData* rootFolder {curSys->getRootFolder()};
|
|
|
|
FileFilterIndex* fileIndex {curSys->getIndex()};
|
|
|
|
std::string name {curSys->getName()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (found) {
|
|
|
|
// If we found it, we need to update it.
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* collectionEntry {children.at(key)};
|
2020-06-21 12:25:28 +00:00
|
|
|
// 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.
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(curSys).get()->remove(
|
2022-01-04 20:49:22 +00:00
|
|
|
collectionEntry, false);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-03-12 19:06:50 +00:00
|
|
|
else if (name == "recent" && file->metadata.get("lastplayed") == "0") {
|
|
|
|
// If lastplayed is set to 0 it means the entry has been cleared, and the
|
|
|
|
// game should therefore be removed.
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(curSys).get()->remove(
|
2022-01-04 20:49:22 +00:00
|
|
|
collectionEntry, false);
|
|
|
|
ViewController::getInstance()->onFileChanged(rootFolder, true);
|
2021-03-12 19:06:50 +00:00
|
|
|
}
|
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.
|
2021-01-01 12:06:05 +00:00
|
|
|
if (curSys->isGroupedCustomCollection()) {
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()
|
2022-01-15 12:38:09 +00:00
|
|
|
->getGamelistView(curSys->getRootFolder()->getParent()->getSystem())
|
2021-07-07 18:03:42 +00:00
|
|
|
.get()
|
|
|
|
->remove(collectionEntry, false);
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* parentRootFolder {
|
|
|
|
rootFolder->getParent()->getSystem()->getRootFolder()};
|
2021-01-01 12:06:05 +00:00
|
|
|
parentRootFolder->sort(parentRootFolder->getSortTypeFromString(
|
2021-07-07 18:03:42 +00:00
|
|
|
parentRootFolder->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2021-10-07 16:31:40 +00:00
|
|
|
mWindow->queueInfoPopup(
|
2021-09-21 15:22:32 +00:00
|
|
|
"DISABLED '" +
|
|
|
|
Utils::String::toUpper(
|
|
|
|
Utils::String::removeParenthesis(file->getName())) +
|
|
|
|
"' IN '" + Utils::String::toUpper(sysData.system->getName()) + "'",
|
|
|
|
4000);
|
2021-01-01 12:06:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(curSys).get()->remove(
|
2022-01-04 20:49:22 +00:00
|
|
|
collectionEntry, false);
|
2021-01-01 12:06:05 +00:00
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2020-07-29 17:01:49 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
else {
|
|
|
|
// Re-index with new metadata.
|
|
|
|
fileIndex->addToIndex(collectionEntry);
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()->onFileChanged(collectionEntry, true);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2022-09-25 11:03:39 +00:00
|
|
|
bool addGame {false};
|
2020-12-31 20:54:32 +00:00
|
|
|
// We didn't find the entry in the collection, so 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" &&
|
2021-07-07 18:03:42 +00:00
|
|
|
file->getCountAsGame() && includeFileInAutoCollections(file)) ||
|
|
|
|
(name == "favorites" && file->metadata.get("favorite") == "true" &&
|
|
|
|
file->getCountAsGame())) {
|
2020-07-29 17:01:49 +00:00
|
|
|
addGame = true;
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
|
|
|
else if (name == "all" && file->getCountAsGame()) {
|
2020-07-29 17:01:49 +00:00
|
|
|
addGame = true;
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
2020-07-29 17:01:49 +00:00
|
|
|
if (addGame) {
|
2023-01-12 18:45:54 +00:00
|
|
|
CollectionFileData* newGame {new CollectionFileData(file, curSys)};
|
2020-06-21 12:25:28 +00:00
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
fileIndex->addToIndex(newGame);
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(curSys)->onFileChanged(newGame,
|
2022-01-04 20:49:22 +00:00
|
|
|
true);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "recent") {
|
2021-01-12 17:34:23 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString("last played, ascending"));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2023-01-12 18:45:54 +00:00
|
|
|
else if (sysData.decl.isCustom) {
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
// If the game doesn't exist in the current system and it's a custom
|
|
|
|
// collection, then skip the sorting.
|
2021-07-07 18:03:42 +00:00
|
|
|
else if (sysData.decl.isCustom && children.find(file->getFullPath()) != children.cend()) {
|
2022-01-14 16:27:42 +00:00
|
|
|
// For custom collections, depending on whether the collection is grouped or not,
|
|
|
|
// update either only the actual system or both the actual system and its parent.
|
2020-10-30 09:34:37 +00:00
|
|
|
if (rootFolder->getSystem()->isGroupedCustomCollection()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
rootFolder->getParent()->sort(rootFolder->getParent()->getSortTypeFromString(
|
|
|
|
rootFolder->getParent()->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2022-01-14 16:27:42 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2020-10-30 09:34:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2020-10-30 09:34:37 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else if (!sysData.decl.isCustom) {
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2023-01-01 14:31:03 +00:00
|
|
|
favoritesSorting);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "recent") {
|
|
|
|
trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()->onFileChanged(rootFolder, false);
|
2020-10-26 20:53:11 +00:00
|
|
|
// This is a bit of a hack to prevent a jump to the first line of the gamelist
|
|
|
|
// if an entry is manually adjusted from within the 'recent' gamelist, for example
|
|
|
|
// by toggling a game as favorite. If the time since the last played timestamp is
|
|
|
|
// less than two seconds, then assume that the game was actually just launched,
|
|
|
|
// and therefore jump to the first line. The two seconds is incredibly generous
|
|
|
|
// as normally it would rather be some milliseconds, but who knows what special
|
|
|
|
// circumstances could cause a slight delay so let's keep a large margin.
|
2021-07-07 18:03:42 +00:00
|
|
|
auto nTime = Utils::Time::now();
|
|
|
|
if (nTime - Utils::Time::stringToTime(file->metadata.get("lastplayed")) < 2) {
|
2020-10-26 20:53:11 +00:00
|
|
|
// Select the first row of the gamelist (the game just played).
|
2023-01-12 18:45:54 +00:00
|
|
|
GamelistView* gameList {ViewController::getInstance()
|
|
|
|
->getGamelistView(getSystemToView(sysData.system))
|
|
|
|
.get()};
|
2020-10-26 20:53:11 +00:00
|
|
|
gameList->setCursor(gameList->getFirstEntry());
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-10-30 09:12:15 +00:00
|
|
|
if (sysData.decl.isCustom) {
|
2023-01-01 14:31:03 +00:00
|
|
|
// For custom collections, update either the actual system or its parent depending
|
|
|
|
// on whether the collection is grouped or not.
|
|
|
|
ViewController::getInstance()->onFileChanged(rootFolder, true);
|
2020-10-30 09:12:15 +00:00
|
|
|
if (rootFolder->getSystem()->isGroupedCustomCollection())
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()->onFileChanged(rootFolder->getParent(), true);
|
2020-10-30 09:12:15 +00:00
|
|
|
else
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()->onFileChanged(rootFolder, true);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2023-01-12 18:45:54 +00:00
|
|
|
else {
|
2023-01-01 14:31:03 +00:00
|
|
|
ViewController::getInstance()->onFileChanged(rootFolder, true);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-27 22:40:23 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::deleteCollectionFiles(FileData* file)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Collection files use the full path as key, to avoid clashes.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string key {file->getFullPath()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Find games in collection systems.
|
|
|
|
std::map<std::string, CollectionSystemData> allCollections;
|
2021-07-07 18:03:42 +00:00
|
|
|
allCollections.insert(mAutoCollectionSystemsData.cbegin(), mAutoCollectionSystemsData.cend());
|
2020-06-21 12:25:28 +00:00
|
|
|
allCollections.insert(mCustomCollectionSystemsData.cbegin(),
|
2021-07-07 18:03:42 +00:00
|
|
|
mCustomCollectionSystemsData.cend());
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto sysDataIt = allCollections.begin(); sysDataIt != allCollections.end(); ++sysDataIt) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (sysDataIt->second.isPopulated) {
|
|
|
|
const std::unordered_map<std::string, FileData*>& children =
|
2021-07-07 18:03:42 +00:00
|
|
|
(sysDataIt->second.system)->getRootFolder()->getChildrenByFilename();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
bool found = children.find(key) != children.cend();
|
|
|
|
if (found) {
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* collectionEntry {children.at(key)};
|
|
|
|
SystemData* systemViewToUpdate {getSystemToView(sysDataIt->second.system)};
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()
|
2022-01-15 12:38:09 +00:00
|
|
|
->getGamelistView(systemViewToUpdate)
|
2021-07-07 18:03:42 +00:00
|
|
|
.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
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool CollectionSystemsManager::isThemeGenericCollectionCompatible(
|
|
|
|
bool genericCustomCollections)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2022-09-25 11:03:39 +00:00
|
|
|
std::vector<std::string> cfgSys {getCollectionThemeFolders(genericCustomCollections)};
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto sysIt = cfgSys.cbegin(); sysIt != cfgSys.cend(); ++sysIt) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!themeFolderExists(*sysIt))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool CollectionSystemsManager::isThemeCustomCollectionCompatible(
|
|
|
|
const 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.
|
2023-08-14 20:40:32 +00:00
|
|
|
auto themes = ThemeData::getThemes();
|
|
|
|
auto theme = themes.find(Settings::getInstance()->getString("Theme"));
|
|
|
|
if (theme != themes.cend()) {
|
|
|
|
std::string defaultThemeFilePath {theme->second.path + "/theme.xml"};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Utils::FileSystem::exists(defaultThemeFilePath))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto sysIt = stringVector.cbegin(); sysIt != stringVector.cend(); ++sysIt) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!themeFolderExists(*sysIt))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
std::string CollectionSystemsManager::getValidNewCollectionName(const std::string& inName,
|
|
|
|
int index)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string name {inName};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2023-08-05 08:33:07 +00:00
|
|
|
if (name.length() > 160) {
|
|
|
|
LOG(LogWarning) << "Requested custom collection name is too long, shortening it";
|
|
|
|
name = name.substr(0, 160);
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (index == 0) {
|
2022-09-25 11:03:39 +00:00
|
|
|
size_t remove {std::string::npos};
|
2023-07-28 19:55:39 +00:00
|
|
|
// Remove invalid characters.
|
|
|
|
while ((remove = name.find_first_of(INVALID_COLLECTION_CHARACTERS)) != std::string::npos)
|
2020-06-21 12:25:28 +00:00
|
|
|
name.erase(remove, 1);
|
|
|
|
}
|
|
|
|
else {
|
2023-07-28 19:55:39 +00:00
|
|
|
name.append(" (").append(std::to_string(index)).append(")");
|
|
|
|
LOG(LogInfo)
|
|
|
|
<< "A custom collection with the requested name already exists, changing name from \""
|
|
|
|
<< inName << "\" to \"" << name << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-28 19:55:39 +00:00
|
|
|
// Trim leading and trailing whitespaces.
|
|
|
|
name = Utils::String::trim(name);
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
if (name == "")
|
2020-10-28 16:36:23 +00:00
|
|
|
name = "new collection";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2023-07-28 19:55:39 +00:00
|
|
|
if (index == 0 && (Utils::String::toLower(name) != Utils::String::toLower(inName))) {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "Requested custom collection name contained one or more invalid characters, name "
|
|
|
|
"was changed from \""
|
|
|
|
<< inName << "\" to \"" << name << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 16:54:04 +00:00
|
|
|
// Get used systems from es_systems.xml.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> systemsInUse {getSystemsFromConfig()};
|
2020-06-21 12:25:28 +00:00
|
|
|
// Get folders assigned to custom collections.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> autoSys {getCollectionThemeFolders(false)};
|
2020-06-21 12:25:28 +00:00
|
|
|
// Get folder assigned to custom collections.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> customSys {getCollectionThemeFolders(true)};
|
2020-06-21 12:25:28 +00:00
|
|
|
// Get folders assigned to user collections.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> userSys {getUserCollectionThemeFolders()};
|
2020-06-21 12:25:28 +00:00
|
|
|
// 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());
|
|
|
|
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto sysIt = systemsInUse.cbegin(); sysIt != systemsInUse.cend(); ++sysIt) {
|
2023-01-12 18:45:54 +00:00
|
|
|
if (Utils::String::toLower(*sysIt) == Utils::String::toLower(name)) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (index > 0)
|
2021-07-07 18:03:42 +00:00
|
|
|
name = name.substr(0, name.size() - 4);
|
|
|
|
return getValidNewCollectionName(name, index + 1);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// If it matches one of the custom collections reserved names then return it.
|
|
|
|
if (mCollectionSystemDeclsIndex.find(name) != mCollectionSystemDeclsIndex.cend())
|
2021-07-07 18:03:42 +00:00
|
|
|
return getValidNewCollectionName(name, index + 1);
|
2020-06-21 12:25:28 +00:00
|
|
|
return name;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
void CollectionSystemsManager::setEditMode(const std::string& collectionName, bool showPopup)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemData* sysData {&(mCustomCollectionSystemsData.at(mEditingCollection))};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!sysData->isPopulated) {
|
|
|
|
populateCustomCollection(sysData);
|
|
|
|
}
|
|
|
|
// If it's bundled, this needs to be the bundle system.
|
|
|
|
mEditingCollectionSystemData = sysData;
|
|
|
|
|
2020-12-31 20:54:32 +00:00
|
|
|
if (showPopup) {
|
2021-10-07 16:31:40 +00:00
|
|
|
mWindow->queueInfoPopup("EDITING '" + Utils::String::toUpper(collectionName) +
|
|
|
|
"' COLLECTION, ADD/REMOVE GAMES WITH 'Y'",
|
|
|
|
10000);
|
2020-12-31 20:54:32 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-31 20:54:32 +00:00
|
|
|
void CollectionSystemsManager::exitEditMode(bool showPopup)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-12-31 20:54:32 +00:00
|
|
|
if (showPopup) {
|
2021-10-07 16:31:40 +00:00
|
|
|
mWindow->queueInfoPopup("FINISHED EDITING '" + Utils::String::toUpper(mEditingCollection) +
|
|
|
|
"' COLLECTION",
|
|
|
|
4000);
|
2020-12-31 20:54:32 +00:00
|
|
|
}
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mIsEditingCustom = false;
|
|
|
|
mEditingCollection = "Favorites";
|
2019-08-24 14:22:02 +00:00
|
|
|
|
2021-01-01 09:28:42 +00:00
|
|
|
// Remove all tick marks from the games that are part of the collection.
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); ++it) {
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView((*it))->onFileChanged(
|
|
|
|
ViewController::getInstance()->getGamelistView((*it))->getCursor(), false);
|
2021-01-01 09:28:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mEditingCollectionSystemData->system->onMetaDataSavePoint();
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool CollectionSystemsManager::inCustomCollection(const std::string& collectionName,
|
|
|
|
FileData* gameFile)
|
2020-10-26 20:53:11 +00:00
|
|
|
{
|
|
|
|
auto collectionEntry = mCustomCollectionSystemsData.find(collectionName);
|
|
|
|
|
|
|
|
if (collectionEntry != mCustomCollectionSystemsData.end()) {
|
2022-09-25 11:03:39 +00:00
|
|
|
const std::unordered_map<std::string, FileData*>& children {
|
|
|
|
collectionEntry->second.system->getRootFolder()->getChildrenByFilename()};
|
2020-10-26 20:53:11 +00:00
|
|
|
return children.find(gameFile->getFullPath()) != children.cend();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool CollectionSystemsManager::toggleGameInCollection(FileData* file)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (file->getType() == GAME) {
|
2022-09-25 11:03:39 +00:00
|
|
|
bool adding {true};
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string name {file->getName()};
|
|
|
|
std::string sysName {mEditingCollection};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mIsEditingCustom) {
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* sysData {mEditingCollectionSystemData->system};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!mEditingCollectionSystemData->isPopulated)
|
|
|
|
populateCustomCollection(mEditingCollectionSystemData);
|
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string key {file->getFullPath()};
|
|
|
|
FileData* rootFolder {sysData->getRootFolder()};
|
|
|
|
const std::unordered_map<std::string, FileData*>& children {
|
|
|
|
rootFolder->getChildrenByFilename()};
|
2022-09-25 11:03:39 +00:00
|
|
|
bool found {children.find(key) != children.cend()};
|
2022-04-09 14:32:47 +00:00
|
|
|
FileFilterIndex* fileIndex {sysData->getIndex()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* systemViewToUpdate {getSystemToView(sysData)};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (found) {
|
|
|
|
adding = false;
|
|
|
|
// If we found it, we need to remove it.
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* collectionEntry {children.at(key)};
|
2021-09-26 09:14:52 +00:00
|
|
|
fileIndex->removeFromIndex(collectionEntry);
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()
|
2022-01-15 12:38:09 +00:00
|
|
|
->getGamelistView(systemViewToUpdate)
|
2021-07-07 18:03:42 +00:00
|
|
|
.get()
|
|
|
|
->remove(collectionEntry, false);
|
|
|
|
systemViewToUpdate->getRootFolder()->sort(
|
|
|
|
rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
|
|
|
Settings::getInstance()->getBool("FavFirstCustom"));
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->reloadGamelistView(systemViewToUpdate);
|
2020-10-26 20:53:11 +00:00
|
|
|
|
|
|
|
updateCollectionFolderMetadata(systemViewToUpdate);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We didn't find it here, so we should add it.
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionFileData* newGame {new CollectionFileData(file, sysData)};
|
2020-06-21 12:25:28 +00:00
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
systemViewToUpdate->getRootFolder()->sort(
|
|
|
|
rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
|
|
|
Settings::getInstance()->getBool("FavFirstCustom"));
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()->onFileChanged(systemViewToUpdate->getRootFolder(),
|
|
|
|
true);
|
2020-10-26 20:53:11 +00:00
|
|
|
fileIndex->addToIndex(newGame);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Add to bundle index as well, if needed.
|
|
|
|
if (systemViewToUpdate != sysData)
|
|
|
|
systemViewToUpdate->getIndex()->addToIndex(newGame);
|
|
|
|
}
|
2020-10-19 18:58:00 +00:00
|
|
|
saveCustomCollection(sysData);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-02-05 16:01:45 +00:00
|
|
|
file->getSourceFileData()->getSystem()->getIndex()->removeFromIndex(
|
2021-07-07 18:03:42 +00:00
|
|
|
file->getSourceFileData());
|
2022-04-09 14:32:47 +00:00
|
|
|
MetaDataList* md {&file->getSourceFileData()->metadata};
|
|
|
|
std::string value {md->get("favorite")};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (value == "false") {
|
|
|
|
md->set("favorite", "true");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
adding = false;
|
|
|
|
md->set("favorite", "false");
|
|
|
|
}
|
|
|
|
|
2021-02-05 16:01:45 +00:00
|
|
|
file->getSourceFileData()->getSystem()->getIndex()->addToIndex(
|
2021-07-07 18:03:42 +00:00
|
|
|
file->getSourceFileData());
|
2020-06-21 12:25:28 +00:00
|
|
|
file->getSourceFileData()->getSystem()->onMetaDataSavePoint();
|
|
|
|
refreshCollectionSystems(file->getSourceFileData());
|
2021-02-04 19:14:20 +00:00
|
|
|
if (mAutoCollectionSystemsData["favorites"].isEnabled)
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->reloadGamelistView(
|
2021-07-07 18:03:42 +00:00
|
|
|
mAutoCollectionSystemsData["favorites"].system);
|
|
|
|
}
|
|
|
|
if (adding) {
|
2021-10-07 16:31:40 +00:00
|
|
|
mWindow->queueInfoPopup(
|
2021-07-07 18:03:42 +00:00
|
|
|
"ADDED '" + Utils::String::toUpper(Utils::String::removeParenthesis(name)) +
|
|
|
|
"' TO '" + Utils::String::toUpper(sysName) + "'",
|
|
|
|
4000);
|
|
|
|
}
|
|
|
|
else {
|
2021-10-07 16:31:40 +00:00
|
|
|
mWindow->queueInfoPopup(
|
2021-07-07 18:03:42 +00:00
|
|
|
"REMOVED '" + Utils::String::toUpper(Utils::String::removeParenthesis(name)) +
|
|
|
|
"' FROM '" + Utils::String::toUpper(sysName) + "'",
|
|
|
|
4000);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
SystemData* CollectionSystemsManager::getSystemToView(SystemData* sys)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* systemToView {sys};
|
|
|
|
FileData* rootFolder {sys->getRootFolder()};
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2022-04-09 14:32:47 +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?
|
2022-04-09 14:32:47 +00:00
|
|
|
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-12-23 17:06:30 +00:00
|
|
|
FileData* CollectionSystemsManager::updateCollectionFolderMetadata(SystemData* sys)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2023-01-14 13:05:24 +00:00
|
|
|
if (sys->getRootFolder()->getParent() == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
|
2022-01-29 17:16:30 +00:00
|
|
|
FileData* rootFolder {sys->getRootFolder()};
|
|
|
|
FileFilterIndex* idx {rootFolder->getSystem()->getIndex()};
|
|
|
|
std::string desc {"This collection is empty"};
|
2021-02-04 19:47:56 +00:00
|
|
|
std::vector<FileData*> gamesList;
|
2020-10-21 19:56:31 +00:00
|
|
|
std::vector<FileData*> gamesListRandom;
|
2021-02-04 19:47:56 +00:00
|
|
|
|
|
|
|
if (UIModeController::getInstance()->isUIModeKid()) {
|
2023-01-14 13:05:24 +00:00
|
|
|
for (auto game : rootFolder->getChildrenListToDisplay()) {
|
2021-02-04 19:47:56 +00:00
|
|
|
if (game->getKidgame())
|
|
|
|
gamesList.push_back(game);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-06-21 20:12:51 +00:00
|
|
|
gamesList = rootFolder->getChildrenListToDisplay();
|
2021-02-04 19:47:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-25 11:03:39 +00:00
|
|
|
int gameCount {static_cast<int>(gamesList.size())};
|
2020-10-20 19:01:24 +00:00
|
|
|
|
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.
|
2022-01-16 11:09:55 +00:00
|
|
|
std::mt19937 engine {randDev()};
|
2022-09-25 11:03:39 +00:00
|
|
|
int target;
|
2020-10-21 19:56:31 +00:00
|
|
|
|
2023-01-14 13:05:24 +00:00
|
|
|
for (int i {0}; i < 3; ++i) {
|
2022-09-25 11:03:39 +00:00
|
|
|
std::uniform_int_distribution<int> uniform_dist {0, gameCount - 1 - i};
|
2020-10-21 19:56:31 +00:00
|
|
|
target = uniform_dist(engine);
|
|
|
|
gamesListRandom.push_back(gamesList[target]);
|
2023-01-14 13:05:24 +00:00
|
|
|
std::vector<FileData*>::iterator it {gamesList.begin() + target};
|
2020-10-21 19:56:31 +00:00
|
|
|
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) {
|
2023-01-14 13:05:24 +00:00
|
|
|
auto nameSuffix = ViewController::getInstance()
|
|
|
|
->getGamelistView(sys->getRootFolder()->getParent()->getSystem())
|
|
|
|
->getDescriptionSystemNameSuffix();
|
|
|
|
if (nameSuffix.first) {
|
|
|
|
auto caseConversion = [nameSuffix](std::string name) -> std::string {
|
|
|
|
if (nameSuffix.second == LetterCase::UPPERCASE)
|
|
|
|
return Utils::String::toUpper(name);
|
|
|
|
else if (nameSuffix.second == LetterCase::CAPITALIZE)
|
|
|
|
return Utils::String::toCapitalized(name);
|
|
|
|
else
|
|
|
|
return Utils::String::toLower(name);
|
|
|
|
};
|
2020-10-25 20:29:54 +00:00
|
|
|
switch (gameCount) {
|
2021-07-07 18:03:42 +00:00
|
|
|
case 1: {
|
2023-01-14 13:05:24 +00:00
|
|
|
desc = "This collection contains 1 game: '";
|
|
|
|
desc.append(gamesList[0]->metadata.get("name"))
|
|
|
|
.append(" [")
|
|
|
|
.append(caseConversion(
|
|
|
|
gamesList[0]->getSourceFileData()->getSystem()->getName()))
|
|
|
|
.append("]'");
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: {
|
2023-01-14 13:05:24 +00:00
|
|
|
desc = "This collection contains 2 games: '";
|
|
|
|
desc.append(gamesList[0]->metadata.get("name"))
|
|
|
|
.append(" [")
|
|
|
|
.append(caseConversion(
|
|
|
|
gamesList[0]->getSourceFileData()->getSystem()->getName()))
|
|
|
|
.append("]' and '")
|
|
|
|
.append(gamesList[1]->metadata.get("name"))
|
|
|
|
.append(" [")
|
|
|
|
.append(caseConversion(
|
|
|
|
gamesList[1]->getSourceFileData()->getSystem()->getName()))
|
|
|
|
.append("]'");
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2023-01-14 13:05:24 +00:00
|
|
|
desc = "This collection contains ";
|
|
|
|
desc.append(std::to_string(gameCount))
|
|
|
|
.append(" games: '")
|
|
|
|
.append(gamesList[0]->metadata.get("name"))
|
|
|
|
.append(" [")
|
|
|
|
.append(caseConversion(
|
|
|
|
gamesList[0]->getSourceFileData()->getSystem()->getName()))
|
|
|
|
.append("]', '")
|
|
|
|
.append(gamesList[1]->metadata.get("name"))
|
|
|
|
.append(" [")
|
|
|
|
.append(caseConversion(
|
|
|
|
gamesList[1]->getSourceFileData()->getSystem()->getName()))
|
|
|
|
.append("]' and '")
|
|
|
|
.append(gamesList[2]->metadata.get("name"))
|
|
|
|
.append(" [")
|
|
|
|
.append(caseConversion(
|
|
|
|
gamesList[2]->getSourceFileData()->getSystem()->getName()))
|
|
|
|
.append("]'");
|
|
|
|
desc.append(gameCount == 3 ? "" : ", among others");
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-10-25 20:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (gameCount) {
|
2021-07-07 18:03:42 +00:00
|
|
|
case 1: {
|
2023-01-14 13:05:24 +00:00
|
|
|
desc = "This collection contains 1 game: '";
|
|
|
|
desc.append(gamesList[0]->metadata.get("name")).append("'");
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: {
|
2023-01-14 13:05:24 +00:00
|
|
|
desc = "This collection contains 2 games: '";
|
|
|
|
desc.append(gamesList[0]->metadata.get("name"))
|
|
|
|
.append("' and '")
|
|
|
|
.append(gamesList[1]->metadata.get("name"))
|
|
|
|
.append("'");
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2023-01-14 13:05:24 +00:00
|
|
|
desc = "This collection contains ";
|
|
|
|
desc.append(std::to_string(gameCount))
|
|
|
|
.append(" games: '")
|
|
|
|
.append(gamesList[0]->metadata.get("name"))
|
|
|
|
.append("', '")
|
|
|
|
.append(gamesList[1]->metadata.get("name"))
|
|
|
|
.append("' and '")
|
|
|
|
.append(gamesList[2]->metadata.get("name"))
|
|
|
|
.append("'");
|
|
|
|
desc.append(gameCount == 3 ? "" : ", among others");
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-10-25 20:29:54 +00:00
|
|
|
}
|
2020-07-28 13:19:54 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 13:05:24 +00:00
|
|
|
if (idx->isFiltered()) {
|
|
|
|
desc.append("\n\n'")
|
|
|
|
.append(rootFolder->getSystem()->getFullName())
|
|
|
|
.append("' is filtered so there may be more games available");
|
|
|
|
}
|
2021-06-21 20:12:51 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
rootFolder->metadata.set("desc", desc);
|
2021-06-21 20:12:51 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
std::vector<std::string> CollectionSystemsManager::getUnusedSystemsFromTheme()
|
2020-11-08 21:58:06 +00:00
|
|
|
{
|
2021-06-16 16:54:04 +00:00
|
|
|
// Get used systems in es_systems.xml.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> systemsInUse {getSystemsFromConfig()};
|
2020-11-08 21:58:06 +00:00
|
|
|
// Get available folders in theme.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> themeSys {getSystemsFromTheme()};
|
2020-11-08 21:58:06 +00:00
|
|
|
// Get folders assigned to custom collections.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> autoSys {getCollectionThemeFolders(false)};
|
2020-11-08 21:58:06 +00:00
|
|
|
// Get folder assigned to custom collections.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> customSys {getCollectionThemeFolders(true)};
|
2020-11-08 21:58:06 +00:00
|
|
|
// Get folders assigned to user collections.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> userSys {getUserCollectionThemeFolders()};
|
2020-11-08 21:58:06 +00:00
|
|
|
// 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());
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto sysIt = themeSys.cbegin(); sysIt != themeSys.cend();) {
|
2020-11-08 21:58:06 +00:00
|
|
|
if (std::find(systemsInUse.cbegin(), systemsInUse.cend(), *sysIt) != systemsInUse.cend())
|
|
|
|
sysIt = themeSys.erase(sysIt);
|
|
|
|
else
|
2021-11-17 16:35:34 +00:00
|
|
|
++sysIt;
|
2020-11-08 21:58:06 +00:00
|
|
|
}
|
|
|
|
return themeSys;
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
SystemData* CollectionSystemsManager::addNewCustomCollection(const std::string& name)
|
2020-11-08 21:58:06 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemDecl decl {mCollectionSystemDeclsIndex[myCollectionsName]};
|
2023-01-12 18:45:54 +00:00
|
|
|
decl.themeFolder = Utils::String::toLower(name);
|
2020-11-08 21:58:06 +00:00
|
|
|
decl.name = name;
|
2021-09-25 09:02:27 +00:00
|
|
|
decl.fullName = name;
|
2021-11-16 21:03:34 +00:00
|
|
|
decl.isCustom = true;
|
2020-11-08 21:58:06 +00:00
|
|
|
|
|
|
|
return createNewCollectionEntry(name, decl, true, true);
|
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
void CollectionSystemsManager::deleteCustomCollection(const std::string& collectionName)
|
2020-11-09 16:50:02 +00:00
|
|
|
{
|
|
|
|
auto collectionEntry = mCustomCollectionSystemsData.find(collectionName);
|
|
|
|
|
|
|
|
// The window deletion needs to be located here instead of in GuiCollectionSystemsOptions
|
|
|
|
// (where the custom collection deletions are initiated), as there seems to be some random
|
|
|
|
// issue with accessing mWindow via the lambda expression.
|
2022-01-04 20:49:22 +00:00
|
|
|
while (mWindow->peekGui() && mWindow->peekGui() != ViewController::getInstance())
|
2020-11-09 16:50:02 +00:00
|
|
|
delete mWindow->peekGui();
|
|
|
|
|
|
|
|
if (collectionEntry != mCustomCollectionSystemsData.end()) {
|
2022-01-04 20:21:26 +00:00
|
|
|
CollectionSystemsManager::getInstance()->loadEnabledListFromSettings();
|
|
|
|
CollectionSystemsManager::getInstance()->updateSystemsList();
|
2020-11-09 16:50:02 +00:00
|
|
|
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->removeGamelistView(collectionEntry->second.system);
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()->reloadAll();
|
2020-11-09 16:50:02 +00:00
|
|
|
|
|
|
|
delete collectionEntry->second.system;
|
|
|
|
mCustomCollectionSystemsData.erase(collectionName);
|
|
|
|
|
|
|
|
// Remove the collection configuration file.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string configFile {getCustomCollectionConfigPath(collectionName)};
|
2020-11-09 16:50:02 +00:00
|
|
|
Utils::FileSystem::removeFile(configFile);
|
2023-07-28 19:55:39 +00:00
|
|
|
LOG(LogInfo) << "Deleted custom collection \"" << collectionName << "\"";
|
|
|
|
LOG(LogDebug) << "CollectionSystemsManager::deleteCustomCollection(): Deleted "
|
|
|
|
"configuration file \""
|
|
|
|
#if defined(_WIN64)
|
|
|
|
<< Utils::String::replace(configFile, "/", "\\") << "\"";
|
|
|
|
#else
|
|
|
|
<< configFile << "\"";
|
|
|
|
#endif
|
2021-10-07 16:31:40 +00:00
|
|
|
mWindow->queueInfoPopup(
|
|
|
|
"DELETED COLLECTION '" + Utils::String::toUpper(collectionName) + "'", 5000);
|
2020-11-09 16:50:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-07-28 19:55:39 +00:00
|
|
|
LOG(LogError) << "Attempted to delete custom collection \"" + collectionName + "\" " +
|
2021-07-07 18:03:42 +00:00
|
|
|
"which doesn't exist.";
|
2020-11-09 16:50:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-31 20:54:32 +00:00
|
|
|
void CollectionSystemsManager::reactivateCustomCollectionEntry(FileData* game)
|
|
|
|
{
|
2023-07-29 21:53:01 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
std::string rompath {Utils::String::replace(FileData::getROMDirectory(), "\\", "/")};
|
|
|
|
#else
|
|
|
|
std::string rompath {FileData::getROMDirectory()};
|
|
|
|
#endif
|
|
|
|
rompath = Utils::String::replace(rompath, "//", "/");
|
|
|
|
|
|
|
|
std::string gamePath {Utils::String::replace(game->getFullPath(), rompath, "%ROMPATH%/")};
|
2020-12-31 20:54:32 +00:00
|
|
|
|
|
|
|
// Try to read from all custom collection configuration files to see if there are any
|
|
|
|
// matching entries for the game passed as the parameter. If so, then enable it in each
|
|
|
|
// of those collections. This is done also for disabled collections, as otherwise the
|
|
|
|
// game would be missing if the collection was enabled during the program session.
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, StringComparator>::const_iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
mCustomCollectionSystemsData.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mCustomCollectionSystemsData.cend(); ++it) {
|
2022-09-25 11:03:39 +00:00
|
|
|
if (!it->second.isEnabled)
|
|
|
|
continue;
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string path {getCustomCollectionConfigPath(it->first)};
|
2020-12-31 20:54:32 +00:00
|
|
|
if (Utils::FileSystem::exists(path)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2023-08-10 21:13:55 +00:00
|
|
|
std::ifstream input {Utils::String::stringToWideString(path).c_str()};
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2023-08-10 21:13:55 +00:00
|
|
|
std::ifstream input {path};
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-12-31 20:54:32 +00:00
|
|
|
for (std::string gameKey; getline(input, gameKey);) {
|
|
|
|
if (gameKey == gamePath) {
|
|
|
|
setEditMode(it->first, false);
|
|
|
|
toggleGameInCollection(game);
|
|
|
|
exitEditMode(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (input.is_open())
|
|
|
|
input.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 16:18:04 +00:00
|
|
|
void CollectionSystemsManager::repopulateCollection(SystemData* sysData)
|
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto it = mAutoCollectionSystemsData.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mAutoCollectionSystemsData.cend(); ++it) {
|
2021-01-01 16:18:04 +00:00
|
|
|
if ((*it).second.system == sysData) {
|
|
|
|
LOG(LogDebug) << "CollectionSystemsManager::repopulateCollection(): "
|
2021-07-07 18:03:42 +00:00
|
|
|
"Repopulating auto collection \""
|
|
|
|
<< it->first << "\"";
|
2021-01-01 16:18:04 +00:00
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemData* autoSystem {&mAutoCollectionSystemsData[it->first]};
|
|
|
|
std::vector<FileData*> systemEntries {
|
|
|
|
autoSystem->system->getRootFolder()->getFilesRecursive(true, true, false)};
|
2021-01-01 16:18:04 +00:00
|
|
|
|
2021-02-04 19:14:20 +00:00
|
|
|
// Flag the collection as not populated so it gets repopulated.
|
|
|
|
autoSystem->isPopulated = false;
|
|
|
|
|
2021-01-01 16:18:04 +00:00
|
|
|
if (systemEntries.empty())
|
|
|
|
return;
|
|
|
|
|
2021-02-04 22:56:39 +00:00
|
|
|
// Delete all children from the system.
|
2021-01-01 16:18:04 +00:00
|
|
|
for (FileData* entry : systemEntries) {
|
|
|
|
autoSystem->system->getRootFolder()->removeChild(entry);
|
|
|
|
delete entry;
|
|
|
|
}
|
|
|
|
|
2021-02-04 22:56:39 +00:00
|
|
|
// Reset the filters so that they get rebuilt correctly when populating the collection.
|
|
|
|
autoSystem->system->getIndex()->resetIndex();
|
|
|
|
|
2021-01-01 16:18:04 +00:00
|
|
|
populateAutoCollection(autoSystem);
|
|
|
|
|
|
|
|
// The cursor value is now pointing to some random memory address so we need to set
|
2021-02-04 19:14:20 +00:00
|
|
|
// it to something valid. For empty collections we need to first create a placeholder
|
|
|
|
// and then point to this, and for collections with games in them we select the first
|
|
|
|
// entry.
|
2022-01-04 20:49:22 +00:00
|
|
|
auto autoView =
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(autoSystem->system).get();
|
2021-02-04 19:14:20 +00:00
|
|
|
if (autoSystem->system->getRootFolder()->getChildren().size() == 0) {
|
|
|
|
autoView->addPlaceholder(autoSystem->system->getRootFolder());
|
|
|
|
autoView->setCursor(autoView->getLastEntry());
|
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:03:42 +00:00
|
|
|
autoView->setCursor(
|
|
|
|
autoSystem->system->getRootFolder()->getChildrenRecursive().front());
|
2021-02-04 19:14:20 +00:00
|
|
|
autoView->setCursor(autoView->getFirstEntry());
|
|
|
|
}
|
2021-01-01 16:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto it = mCustomCollectionSystemsData.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mCustomCollectionSystemsData.cend(); ++it) {
|
2021-01-01 16:18:04 +00:00
|
|
|
if ((*it).second.system == sysData) {
|
|
|
|
LOG(LogDebug) << "CollectionSystemsManager::repopulateCollection(): "
|
2022-10-29 10:56:35 +00:00
|
|
|
"Repopulating custom collection \""
|
|
|
|
<< it->first << "\"";
|
2021-01-01 16:18:04 +00:00
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemData* customSystem {&mCustomCollectionSystemsData[it->first]};
|
|
|
|
std::vector<FileData*> systemEntries {
|
|
|
|
customSystem->system->getRootFolder()->getFilesRecursive(true, true, false)};
|
2021-01-01 16:18:04 +00:00
|
|
|
|
|
|
|
if (systemEntries.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (FileData* entry : systemEntries) {
|
|
|
|
customSystem->system->getIndex()->removeFromIndex(entry);
|
|
|
|
customSystem->system->getRootFolder()->removeChild(entry);
|
|
|
|
delete entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
customSystem->isPopulated = false;
|
|
|
|
populateCustomCollection(customSystem);
|
|
|
|
|
2022-01-04 20:49:22 +00:00
|
|
|
auto autoView =
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(customSystem->system).get();
|
2021-07-07 18:03:42 +00:00
|
|
|
autoView->setCursor(
|
|
|
|
customSystem->system->getRootFolder()->getChildrenRecursive().front());
|
2021-01-01 16:18:04 +00:00
|
|
|
autoView->setCursor(autoView->getFirstEntry());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::initAutoCollectionSystems()
|
2020-11-08 21:58:06 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemDecl, StringComparator>::const_iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
mCollectionSystemDeclsIndex.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mCollectionSystemDeclsIndex.cend(); ++it) {
|
2020-11-08 21:58:06 +00:00
|
|
|
CollectionSystemDecl sysDecl = it->second;
|
|
|
|
|
|
|
|
if (!sysDecl.isCustom)
|
|
|
|
createNewCollectionEntry(sysDecl.name, sysDecl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::initCustomCollectionSystems()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> systems {getCollectionsFromConfigFolder()};
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto nameIt = systems.cbegin(); nameIt != systems.cend(); ++nameIt) {
|
2020-06-21 12:25:28 +00:00
|
|
|
addNewCustomCollection(*nameIt);
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
SystemData* CollectionSystemsManager::getAllGamesCollection()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemData* allSysData {&mAutoCollectionSystemsData["all"]};
|
2020-06-21 12:25:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
SystemData* CollectionSystemsManager::createNewCollectionEntry(const std::string& name,
|
2021-07-07 18:03:42 +00:00
|
|
|
CollectionSystemDecl sysDecl,
|
|
|
|
bool index,
|
|
|
|
bool custom)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* newSys {new SystemData(name, sysDecl.fullName, "", 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-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::populateAutoCollection(CollectionSystemData* sysData)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* newSys {sysData->system};
|
|
|
|
CollectionSystemDecl sysDecl {sysData->decl};
|
|
|
|
FileData* rootFolder {newSys->getRootFolder()};
|
|
|
|
FileFilterIndex* index {newSys->getIndex()};
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto sysIt = SystemData::sSystemVector.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
sysIt != SystemData::sSystemVector.cend(); ++sysIt) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// We won't iterate all collections.
|
|
|
|
if ((*sysIt)->isGameSystem() && !(*sysIt)->isCollection()) {
|
|
|
|
std::vector<FileData*> files = (*sysIt)->getRootFolder()->getFilesRecursive(GAME);
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto gameIt = files.cbegin(); gameIt != files.cend(); ++gameIt) {
|
2022-04-09 14:32:47 +00:00
|
|
|
bool include {includeFileInAutoCollections((*gameIt))};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
switch (sysDecl.type) {
|
2021-07-07 18:03:42 +00:00
|
|
|
case AUTO_LAST_PLAYED: {
|
2020-06-21 12:25:28 +00:00
|
|
|
include = include && (*gameIt)->metadata.get("playcount") > "0";
|
|
|
|
break;
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
|
|
|
case AUTO_FAVORITES: {
|
2021-02-04 22:56:39 +00:00
|
|
|
// We may still want to add files we don't want in auto collections
|
|
|
|
// to "favorites".
|
2020-06-21 12:25:28 +00:00
|
|
|
include = (*gameIt)->metadata.get("favorite") == "true";
|
|
|
|
break;
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
|
|
|
default: {
|
2020-06-25 17:52:38 +00:00
|
|
|
break;
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2023-01-14 13:05:24 +00:00
|
|
|
CollectionFileData* newGame {new CollectionFileData(*gameIt, newSys)};
|
2020-06-21 12:25:28 +00:00
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
index->addToIndex(newGame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (rootFolder->getName() == "recent")
|
2021-01-12 17:34:23 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString("last played, ascending"));
|
2020-06-21 12:25:28 +00:00
|
|
|
else
|
2020-09-17 20:18:13 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
2021-07-07 18:03:42 +00:00
|
|
|
Settings::getInstance()->getBool("FavoritesFirst"));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2023-02-09 23:40:16 +00:00
|
|
|
if (!mApplicationStartup && sysDecl.type == AUTO_LAST_PLAYED)
|
2020-06-21 12:25:28 +00:00
|
|
|
trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
|
2020-10-30 13:19:21 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// not be correct as it would include all the games prior to trimming.
|
2023-02-09 23:40:16 +00:00
|
|
|
if (!mApplicationStartup && rootFolder->getName() == "recent" &&
|
|
|
|
!rootFolder->getChildrenRecursive().empty()) {
|
2021-01-01 16:18:04 +00:00
|
|
|
// The following is needed to avoid a crash when repopulating the system as the previous
|
|
|
|
// cursor pointer may point to a random memory address.
|
2022-01-04 20:49:22 +00:00
|
|
|
auto recentGamelist =
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(rootFolder->getSystem()).get();
|
2021-07-07 18:03:42 +00:00
|
|
|
recentGamelist->setCursor(
|
|
|
|
rootFolder->getSystem()->getRootFolder()->getChildrenRecursive().front());
|
2021-01-01 16:18:04 +00:00
|
|
|
recentGamelist->setCursor(recentGamelist->getFirstEntry());
|
2021-02-05 16:03:43 +00:00
|
|
|
if (rootFolder->getChildren().size() > 0)
|
2022-01-04 20:49:22 +00:00
|
|
|
ViewController::getInstance()
|
2022-01-15 12:38:09 +00:00
|
|
|
->getGamelistView(rootFolder->getSystem())
|
2021-07-07 18:03:42 +00:00
|
|
|
.get()
|
|
|
|
->onFileChanged(rootFolder->getChildren().front(), false);
|
2020-10-30 13:19:21 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
sysData->isPopulated = true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::populateCustomCollection(CollectionSystemData* sysData)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* newSys {sysData->system};
|
2020-06-21 12:25:28 +00:00
|
|
|
sysData->isPopulated = true;
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemDecl sysDecl {sysData->decl};
|
|
|
|
std::string path {getCustomCollectionConfigPath(newSys->getName())};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-02-27 19:29:37 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
LOG(LogInfo) << "Parsing custom collection file \"" << Utils::String::replace(path, "/", "\\")
|
|
|
|
<< "\"...";
|
|
|
|
#else
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogInfo) << "Parsing custom collection file \"" << path << "\"...";
|
2023-02-27 19:29:37 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* rootFolder {newSys->getRootFolder()};
|
|
|
|
FileFilterIndex* index {newSys->getIndex()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Get configuration for this custom collection.
|
2021-07-07 18:03:42 +00:00
|
|
|
|
|
|
|
#if defined(_WIN64)
|
2023-08-10 21:13:55 +00:00
|
|
|
std::ifstream input {Utils::String::stringToWideString(path).c_str()};
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2023-08-10 21:13:55 +00:00
|
|
|
std::ifstream input {path};
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Get all files map.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::unordered_map<std::string, FileData*> allFilesMap {
|
|
|
|
getAllGamesCollection()->getRootFolder()->getChildrenByFilename()};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-06-16 17:05:24 +00:00
|
|
|
// Get the ROM directory, either as configured in es_settings.xml, or if no value
|
2020-06-21 12:25:28 +00:00
|
|
|
// is set there, then use the default hardcoded path.
|
2023-07-29 21:53:01 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
std::string rompath {Utils::String::replace(FileData::getROMDirectory(), "\\", "/")};
|
|
|
|
#else
|
|
|
|
std::string rompath {FileData::getROMDirectory()};
|
|
|
|
#endif
|
|
|
|
rompath = Utils::String::replace(rompath, "//", "/");
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Iterate list of files in the config file.
|
2020-12-31 20:54:32 +00:00
|
|
|
for (std::string gameKey; getline(input, gameKey);) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// 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
|
2023-07-27 10:11:17 +00:00
|
|
|
// with old custom collections. All custom collections saved by ES-DE will use the
|
|
|
|
// %ROMPATH% variable instead.
|
2020-06-21 12:25:28 +00:00
|
|
|
gameKey = Utils::String::replace(gameKey, "%ROMPATH%", rompath);
|
|
|
|
gameKey = Utils::String::replace(gameKey, "//", "/");
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
std::unordered_map<std::string, FileData*>::const_iterator it = allFilesMap.find(gameKey);
|
2020-06-21 12:25:28 +00:00
|
|
|
if (it != allFilesMap.cend()) {
|
|
|
|
CollectionFileData* newGame = new CollectionFileData(it->second, newSys);
|
2022-09-25 11:03:39 +00:00
|
|
|
if (!newGame->getCountAsGame()) {
|
|
|
|
LOG(LogWarning)
|
2023-06-26 20:38:40 +00:00
|
|
|
|
|
|
|
#if defined(_WIN64)
|
|
|
|
<< "File \"" << Utils::String::replace(gameKey, "/", "\\")
|
|
|
|
#else
|
2022-09-25 11:03:39 +00:00
|
|
|
<< "File \"" << gameKey
|
2023-06-26 20:38:40 +00:00
|
|
|
#endif
|
2022-09-25 11:03:39 +00:00
|
|
|
<< "\" does not exist, is hidden, or is not counted as a game, ignoring entry";
|
|
|
|
delete newGame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
index->addToIndex(newGame);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning)
|
2023-06-26 20:38:40 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
<< "File \"" << Utils::String::replace(gameKey, "/", "\\")
|
|
|
|
#else
|
2021-07-07 18:03:42 +00:00
|
|
|
<< "File \"" << gameKey
|
2023-06-26 20:38:40 +00:00
|
|
|
#endif
|
2021-07-07 18:03:42 +00:00
|
|
|
<< "\" does not exist, is hidden, or is not counted as a game, ignoring entry";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-31 20:54:32 +00:00
|
|
|
|
|
|
|
if (input.is_open())
|
|
|
|
input.close();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::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();
|
2021-07-07 18:03:42 +00:00
|
|
|
sysIt != SystemData::sSystemVector.cend();) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if ((*sysIt)->isCollection())
|
|
|
|
sysIt = SystemData::sSystemVector.erase(sysIt);
|
|
|
|
else
|
2021-11-17 16:35:34 +00:00
|
|
|
++sysIt;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all custom collections in bundle.
|
|
|
|
// This should not delete the objects from memory!
|
2023-01-23 22:38:25 +00:00
|
|
|
if (mCustomCollectionsBundle == nullptr)
|
|
|
|
return;
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* customRoot {mCustomCollectionsBundle->getRootFolder()};
|
|
|
|
std::vector<FileData*> mChildren {customRoot->getChildren()};
|
2021-11-17 16:35:34 +00:00
|
|
|
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
customRoot->removeChild(*it);
|
|
|
|
}
|
|
|
|
// Clear index.
|
|
|
|
mCustomCollectionsBundle->getIndex()->resetIndex();
|
|
|
|
// Remove view so it's re-created as needed.
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->removeGamelistView(mCustomCollectionsBundle);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::addEnabledCollectionsToDisplayedSystems(
|
2022-04-09 14:32:47 +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.
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, StringComparator>::iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
colSystemData->begin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != colSystemData->end(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
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));
|
|
|
|
}
|
2023-01-12 18:45:54 +00:00
|
|
|
// Check if we should create a separate system instead of grouping it.
|
|
|
|
bool createSystem {false};
|
|
|
|
if (!it->second.decl.isCustom)
|
|
|
|
createSystem = true;
|
|
|
|
else if (Settings::getInstance()->getString("CollectionCustomGrouping") == "always")
|
|
|
|
createSystem = false;
|
|
|
|
else if (Settings::getInstance()->getString("CollectionCustomGrouping") == "never")
|
|
|
|
createSystem = true;
|
|
|
|
else if (themeFolderExists(Utils::String::toLower(it->first)))
|
|
|
|
createSystem = true;
|
|
|
|
|
|
|
|
if (createSystem) {
|
2020-06-21 12:25:28 +00:00
|
|
|
SystemData::sSystemVector.push_back(it->second.system);
|
2023-01-12 18:45:54 +00:00
|
|
|
// If this is a non-grouped custom collection, then sort it.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (it->second.decl.isCustom == true) {
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* rootFolder {it->second.system->getRootFolder()};
|
2021-07-07 18:03:42 +00:00
|
|
|
rootFolder->sort(
|
|
|
|
rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
|
|
|
Settings::getInstance()->getBool("FavFirstCustom"));
|
2020-06-21 12:25:28 +00:00
|
|
|
// Jump to the first row of the game list, assuming it's not empty.
|
2023-02-09 23:40:16 +00:00
|
|
|
if (!mApplicationStartup) {
|
|
|
|
GamelistView* gameList {ViewController::getInstance()
|
|
|
|
->getGamelistView((it->second.system))
|
|
|
|
.get()};
|
|
|
|
if (!gameList->getCursor()->isPlaceHolder()) {
|
|
|
|
gameList->setCursor(gameList->getFirstEntry());
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2020-10-30 09:34:37 +00:00
|
|
|
it->second.system->setIsGroupedCustomCollection(false);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2022-04-09 14:32:47 +00:00
|
|
|
FileData* newSysRootFolder {it->second.system->getRootFolder()};
|
2020-06-21 12:25:28 +00:00
|
|
|
mCustomCollectionsBundle->getRootFolder()->addChild(newSysRootFolder);
|
|
|
|
mCustomCollectionsBundle->getIndex()->importIndex(it->second.system->getIndex());
|
2020-10-30 09:12:15 +00:00
|
|
|
it->second.system->setIsGroupedCustomCollection(true);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
std::vector<std::string> CollectionSystemsManager::getSystemsFromConfig()
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
2023-07-30 10:27:27 +00:00
|
|
|
std::vector<std::string> configPaths {SystemData::getConfigPath()};
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2021-09-05 15:39:11 +00:00
|
|
|
// Here we don't honor the <loadExclusive> tag which may be present in the custom es_systems.xml
|
|
|
|
// file under ~/.emulationstation/custom_systems as we really want to include all the themes
|
|
|
|
// supported by ES-DE. Otherwise a user may accidentally create a custom collection that
|
|
|
|
// corresponds to a supported theme.
|
|
|
|
for (auto path : configPaths) {
|
|
|
|
if (!Utils::FileSystem::exists(path))
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2021-09-05 15:39:11 +00:00
|
|
|
pugi::xml_document doc;
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2022-09-25 11:03:39 +00:00
|
|
|
pugi::xml_parse_result res {doc.load_file(Utils::String::stringToWideString(path).c_str())};
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2022-09-25 11:03:39 +00:00
|
|
|
pugi::xml_parse_result res {doc.load_file(path.c_str())};
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2021-09-05 15:39:11 +00:00
|
|
|
if (!res)
|
|
|
|
return systems;
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2021-09-05 15:39:11 +00:00
|
|
|
// Actually read the file.
|
2022-04-09 14:32:47 +00:00
|
|
|
pugi::xml_node systemList {doc.child("systemList")};
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2021-09-05 15:39:11 +00:00
|
|
|
if (!systemList)
|
|
|
|
return systems;
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2022-09-25 11:03:39 +00:00
|
|
|
for (pugi::xml_node system {systemList.child("system")}; system;
|
2021-09-05 15:39:11 +00:00
|
|
|
system = system.next_sibling("system")) {
|
|
|
|
// Theme folder.
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string themeFolder {system.child("theme").text().get()};
|
2021-09-05 15:39:11 +00:00
|
|
|
if (std::find(systems.cbegin(), systems.cend(), themeFolder) == systems.cend())
|
|
|
|
systems.push_back(themeFolder);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-09-05 15:39:11 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
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.
|
2020-12-23 17:06:30 +00:00
|
|
|
std::vector<std::string> CollectionSystemsManager::getSystemsFromTheme()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
|
|
|
|
2023-08-14 20:40:32 +00:00
|
|
|
auto themes = ThemeData::getThemes();
|
|
|
|
if (themes.empty())
|
|
|
|
return systems; // No themes available.
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2023-08-14 20:40:32 +00:00
|
|
|
std::map<std::string, ThemeData::Theme, ThemeData::StringComparator>::const_iterator theme {
|
|
|
|
themes.find(Settings::getInstance()->getString("Theme"))};
|
|
|
|
if (theme == themes.cend()) {
|
|
|
|
// Currently selected theme is missing, so just pick the first available one.
|
|
|
|
theme = themes.cbegin();
|
|
|
|
Settings::getInstance()->setString("Theme", theme->first);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:40:32 +00:00
|
|
|
std::string themePath {theme->second.path};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(themePath)) {
|
2022-04-09 14:32:47 +00:00
|
|
|
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(themePath)};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-11 20:57:00 +00:00
|
|
|
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != dirContent.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Utils::FileSystem::isDirectory(*it)) {
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string folder {*it};
|
2021-07-07 18:03:42 +00:00
|
|
|
folder = folder.substr(themePath.size() + 1);
|
2023-08-14 20:40:32 +00:00
|
|
|
if (Utils::FileSystem::exists(theme->second.getThemePath(folder)))
|
2020-06-21 12:25:28 +00:00
|
|
|
systems.push_back(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::sort(systems.begin(), systems.end());
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
std::vector<std::string> CollectionSystemsManager::getCollectionsFromConfigFolder()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string configPath {getCollectionsFolder()};
|
2023-01-12 18:45:54 +00:00
|
|
|
std::vector<std::string> filenames;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
if (Utils::FileSystem::exists(configPath)) {
|
2023-01-12 18:45:54 +00:00
|
|
|
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(configPath)};
|
2022-01-11 20:57:00 +00:00
|
|
|
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != dirContent.cend(); ++it) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(*it)) {
|
2022-04-09 14:32:47 +00:00
|
|
|
std::string filename {Utils::FileSystem::getFileName(*it)};
|
2023-07-28 19:55:39 +00:00
|
|
|
|
|
|
|
if (Utils::FileSystem::getStem(filename).find_first_of(
|
|
|
|
INVALID_COLLECTION_CHARACTERS) != std::string::npos) {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "Found a custom collection configuration file name with at least one "
|
|
|
|
"invalid character, skipping file \""
|
|
|
|
<< filename << "\"";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-01-12 18:45:54 +00:00
|
|
|
if (std::find(filenames.cbegin(), filenames.cend(),
|
|
|
|
Utils::String::toLower(filename)) != filenames.cend()) {
|
|
|
|
LOG(LogWarning)
|
2023-02-07 17:05:11 +00:00
|
|
|
<< "Found a custom collection configuration file name conflict (mixed "
|
2023-01-12 18:45:54 +00:00
|
|
|
"case filenames), skipping file \""
|
|
|
|
<< filename << "\"";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
filenames.emplace_back(Utils::String::toLower(filename));
|
2020-06-21 12:25:28 +00:00
|
|
|
// Need to confirm filename matches config format.
|
2021-07-07 18:03:42 +00:00
|
|
|
if (filename != "custom-.cfg" && Utils::String::startsWith(filename, "custom-") &&
|
|
|
|
Utils::String::endsWith(filename, ".cfg")) {
|
2023-01-12 18:45:54 +00:00
|
|
|
const std::string origFilename {filename};
|
2021-07-07 18:03:42 +00:00
|
|
|
filename = filename.substr(7, filename.size() - 11);
|
2023-01-12 18:45:54 +00:00
|
|
|
if (std::find_if(
|
|
|
|
SystemData::sSystemVector.cbegin(), SystemData::sSystemVector.cend(),
|
|
|
|
[filename](SystemData* system) {
|
|
|
|
return system->getThemeFolder() == Utils::String::toLower(filename);
|
|
|
|
}) != SystemData::sSystemVector.cend()) {
|
|
|
|
LOG(LogWarning)
|
2023-02-07 17:05:11 +00:00
|
|
|
<< "Custom collection name conflicts with a theme folder for one of "
|
2023-01-12 18:45:54 +00:00
|
|
|
"the systems defined in es_systems.xml, skipping file \""
|
|
|
|
<< origFilename << "\"";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
systems.push_back(filename);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogInfo) << "Found non-collection config file in collections folder: "
|
2021-07-07 18:03:42 +00:00
|
|
|
<< filename;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
std::vector<std::string> CollectionSystemsManager::getCollectionThemeFolders(bool custom)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemDecl, StringComparator>::const_iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
mCollectionSystemDeclsIndex.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mCollectionSystemDeclsIndex.cend(); ++it) {
|
2022-04-09 14:32:47 +00:00
|
|
|
CollectionSystemDecl sysDecl {it->second};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (sysDecl.isCustom == custom)
|
|
|
|
systems.push_back(sysDecl.themeFolder);
|
|
|
|
}
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
std::vector<std::string> CollectionSystemsManager::getUserCollectionThemeFolders()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> systems;
|
2022-04-09 14:32:47 +00:00
|
|
|
for (std::map<std::string, CollectionSystemData, StringComparator>::const_iterator it =
|
2021-07-07 18:03:42 +00:00
|
|
|
mCustomCollectionSystemsData.cbegin();
|
2021-11-17 16:35:34 +00:00
|
|
|
it != mCustomCollectionSystemsData.cend(); ++it)
|
2020-06-21 12:25:28 +00:00
|
|
|
systems.push_back(it->second.decl.themeFolder);
|
|
|
|
return systems;
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
void CollectionSystemsManager::trimCollectionCount(FileData* rootFolder, int limit)
|
2020-11-08 21:58:06 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
SystemData* curSys {rootFolder->getSystem()};
|
2020-11-08 21:58:06 +00:00
|
|
|
while (static_cast<int>(rootFolder->getChildrenListToDisplay().size()) > limit) {
|
2022-09-25 11:03:39 +00:00
|
|
|
CollectionFileData* gameToRemove {
|
2023-01-12 18:45:54 +00:00
|
|
|
reinterpret_cast<CollectionFileData*>(rootFolder->getChildrenListToDisplay().back())};
|
2022-01-15 12:38:09 +00:00
|
|
|
ViewController::getInstance()->getGamelistView(curSys).get()->remove(gameToRemove, false);
|
2020-11-08 21:58:06 +00:00
|
|
|
}
|
2022-02-13 19:03:34 +00:00
|
|
|
// Also update the lists of last played and most played games as these could otherwise
|
|
|
|
// contain dangling pointers.
|
|
|
|
rootFolder->updateLastPlayedList();
|
|
|
|
rootFolder->updateMostPlayedList();
|
2020-11-08 21:58:06 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool CollectionSystemsManager::themeFolderExists(const std::string& folder)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
std::vector<std::string> themeSys {getSystemsFromTheme()};
|
2020-06-21 12:25:28 +00:00
|
|
|
return std::find(themeSys.cbegin(), themeSys.cend(), folder) != themeSys.cend();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
const bool CollectionSystemsManager::includeFileInAutoCollections(FileData* file)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2022-04-09 14:32:47 +00:00
|
|
|
return file->getSystem()->isGameSystem();
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 21:40:08 +00:00
|
|
|
std::string CollectionSystemsManager::getCustomCollectionConfigPath(
|
|
|
|
const 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-12-23 17:06:30 +00:00
|
|
|
std::string CollectionSystemsManager::getCollectionsFolder()
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return Utils::FileSystem::getGenericPath(Utils::FileSystem::getHomePath() +
|
2021-07-07 18:03:42 +00:00
|
|
|
"/.emulationstation/collections");
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|