2017-11-01 22:21:10 +00:00
|
|
|
#include "CollectionSystemManager.h"
|
|
|
|
|
|
|
|
#include "guis/GuiInfoPopup.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"
|
2017-06-12 16:38:59 +00:00
|
|
|
#include "Util.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <boost/filesystem/operations.hpp>
|
2017-11-10 19:16:42 +00:00
|
|
|
#include <pugixml/src/pugixml.hpp>
|
2017-06-12 16:38:59 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::string myCollectionsName = "collections";
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
/* Handling the getting, initialization, deinitialization, saving and deletion of
|
|
|
|
* a CollectionSystemManager Instance */
|
2017-06-12 16:38:59 +00:00
|
|
|
CollectionSystemManager* CollectionSystemManager::sInstance = NULL;
|
|
|
|
|
|
|
|
CollectionSystemManager::CollectionSystemManager(Window* window) : mWindow(window)
|
|
|
|
{
|
|
|
|
CollectionSystemDecl systemDecls[] = {
|
2017-07-18 09:45:50 +00:00
|
|
|
//type name long name //default sort // theme folder // isCustom
|
|
|
|
{ AUTO_ALL_GAMES, "all", "all games", "filename, ascending", "auto-allgames", false },
|
|
|
|
{ AUTO_LAST_PLAYED, "recent", "last played", "last played, descending", "auto-lastplayed", false },
|
|
|
|
{ AUTO_FAVORITES, "favorites", "favorites", "filename, ascending", "auto-favorites", false },
|
|
|
|
{ CUSTOM_COLLECTION, myCollectionsName, "collections", "filename, ascending", "custom-collections", true }
|
2017-06-12 16:38:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// create a map
|
|
|
|
std::vector<CollectionSystemDecl> tempSystemDecl = std::vector<CollectionSystemDecl>(systemDecls, systemDecls + sizeof(systemDecls) / sizeof(systemDecls[0]));
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for (std::vector<CollectionSystemDecl>::const_iterator it = tempSystemDecl.cbegin(); it != tempSystemDecl.cend(); ++it )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
mCollectionSystemDeclsIndex[(*it).name] = (*it);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// creating standard environment data
|
|
|
|
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;
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::string path = getCollectionsFolder();
|
2017-12-04 23:30:25 +00:00
|
|
|
if(!boost::filesystem::exists(path))
|
|
|
|
boost::filesystem::create_directory(path);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
mIsEditingCustom = false;
|
|
|
|
mEditingCollection = "Favorites";
|
|
|
|
mEditingCollectionSystemData = NULL;
|
|
|
|
mCustomCollectionsBundle = NULL;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectionSystemManager::~CollectionSystemManager()
|
|
|
|
{
|
|
|
|
assert(sInstance == this);
|
2017-07-18 09:45:50 +00:00
|
|
|
removeCollectionsFromDisplayedSystems();
|
|
|
|
|
|
|
|
// iterate the map
|
2017-11-11 14:56:22 +00:00
|
|
|
for(std::map<std::string, CollectionSystemData>::const_iterator it = mCustomCollectionSystemsData.cbegin() ; it != mCustomCollectionSystemsData.cend() ; it++ )
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
if (it->second.isPopulated)
|
|
|
|
{
|
|
|
|
saveCustomCollection(it->second.system);
|
|
|
|
}
|
|
|
|
delete it->second.system;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
sInstance = NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
CollectionSystemManager* CollectionSystemManager::get()
|
|
|
|
{
|
|
|
|
assert(sInstance);
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::init(Window* window)
|
|
|
|
{
|
|
|
|
assert(!sInstance);
|
|
|
|
sInstance = new CollectionSystemManager(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::deinit()
|
|
|
|
{
|
|
|
|
if (sInstance)
|
|
|
|
{
|
|
|
|
delete sInstance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::saveCustomCollection(SystemData* sys)
|
|
|
|
{
|
|
|
|
std::string name = sys->getName();
|
|
|
|
std::unordered_map<std::string, FileData*> games = sys->getRootFolder()->getChildrenByFilename();
|
2017-11-11 14:56:22 +00:00
|
|
|
bool found = mCustomCollectionSystemsData.find(name) != mCustomCollectionSystemsData.cend();
|
2017-07-18 09:45:50 +00:00
|
|
|
if (found) {
|
|
|
|
CollectionSystemData sysData = mCustomCollectionSystemsData.at(name);
|
|
|
|
if (sysData.needsSave)
|
|
|
|
{
|
|
|
|
std::ofstream configFile;
|
|
|
|
configFile.open(getCustomCollectionConfigPath(name));
|
2017-11-11 14:56:22 +00:00
|
|
|
for(std::unordered_map<std::string, FileData*>::const_iterator iter = games.cbegin(); iter != games.cend(); ++iter)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
std::string path = iter->first;
|
|
|
|
configFile << path << std::endl;
|
|
|
|
}
|
|
|
|
configFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Couldn't find collection to save! " << name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Methods to load all Collections into memory, and handle enabling the active ones */
|
|
|
|
// loads all Collection Systems
|
|
|
|
void CollectionSystemManager::loadCollectionSystems()
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// loads settings
|
2017-06-12 16:38:59 +00:00
|
|
|
void CollectionSystemManager::loadEnabledListFromSettings()
|
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// we parse the auto collection settings list
|
|
|
|
std::vector<std::string> autoSelected = commaStringToVector(Settings::getInstance()->getString("CollectionSystemsAuto"));
|
2017-06-12 16:38:59 +00:00
|
|
|
|
|
|
|
// iterate the map
|
2017-07-18 09:45:50 +00:00
|
|
|
for(std::map<std::string, CollectionSystemData>::iterator it = mAutoCollectionSystemsData.begin() ; it != mAutoCollectionSystemsData.end() ; it++ )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
it->second.isEnabled = (std::find(autoSelected.cbegin(), autoSelected.cend(), it->first) != autoSelected.cend());
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// we parse the custom collection settings list
|
|
|
|
std::vector<std::string> customSelected = commaStringToVector(Settings::getInstance()->getString("CollectionSystemsCustom"));
|
|
|
|
|
|
|
|
// iterate the map
|
|
|
|
for(std::map<std::string, CollectionSystemData>::iterator it = mCustomCollectionSystemsData.begin() ; it != mCustomCollectionSystemsData.end() ; it++ )
|
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
it->second.isEnabled = (std::find(customSelected.cbegin(), customSelected.cend(), it->first) != customSelected.cend());
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// updates enabled system list in System View
|
|
|
|
void CollectionSystemManager::updateSystemsList()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// remove all Collection Systems
|
|
|
|
removeCollectionsFromDisplayedSystems();
|
|
|
|
// add custom enabled ones
|
|
|
|
addEnabledCollectionsToDisplayedSystems(&mCustomCollectionSystemsData);
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
if(Settings::getInstance()->getBool("SortAllSystems"))
|
|
|
|
{
|
|
|
|
// sort custom individual systems with other systems
|
|
|
|
std::sort(SystemData::sSystemVector.begin(), SystemData::sSystemVector.end(), systemSort);
|
|
|
|
|
|
|
|
// move RetroPie system to end, before auto collections
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = SystemData::sSystemVector.cbegin(); sysIt != SystemData::sSystemVector.cend(); )
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
if ((*sysIt)->getName() == "retropie")
|
|
|
|
{
|
|
|
|
SystemData* retroPieSystem = (*sysIt);
|
|
|
|
sysIt = SystemData::sSystemVector.erase(sysIt);
|
|
|
|
SystemData::sSystemVector.push_back(retroPieSystem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sysIt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mCustomCollectionsBundle->getRootFolder()->getChildren().size() > 0)
|
|
|
|
{
|
|
|
|
mCustomCollectionsBundle->getRootFolder()->sort(getSortTypeFromString(mCollectionSystemDeclsIndex[myCollectionsName].defaultSort));
|
|
|
|
SystemData::sSystemVector.push_back(mCustomCollectionsBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add auto enabled ones
|
|
|
|
addEnabledCollectionsToDisplayedSystems(&mAutoCollectionSystemsData);
|
|
|
|
|
|
|
|
// create views for collections, before reload
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = SystemData::sSystemVector.cbegin(); sysIt != SystemData::sSystemVector.cend(); sysIt++)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
if ((*sysIt)->isCollection())
|
|
|
|
{
|
|
|
|
ViewController::get()->getGameListView((*sysIt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we were editing a custom collection, and it's no longer enabled, exit edit mode
|
|
|
|
if(mIsEditingCustom && !mEditingCollectionSystemData->isEnabled)
|
|
|
|
{
|
|
|
|
exitEditMode();
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
/* Methods to manage collection files related to a source FileData */
|
|
|
|
// updates all collection files related to the source file
|
|
|
|
void CollectionSystemManager::refreshCollectionSystems(FileData* file)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
if (!file->getSystem()->isGameSystem())
|
|
|
|
return;
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
std::map<std::string, CollectionSystemData> allCollections;
|
2017-11-11 14:56:22 +00:00
|
|
|
allCollections.insert(mAutoCollectionSystemsData.cbegin(), mAutoCollectionSystemsData.cend());
|
|
|
|
allCollections.insert(mCustomCollectionSystemsData.cbegin(), mCustomCollectionSystemsData.cend());
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysDataIt = allCollections.cbegin(); sysDataIt != allCollections.cend(); sysDataIt++)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
updateCollectionSystem(file, sysDataIt->second);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (sysData.isPopulated)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// collection files use the full path as key, to avoid clashes
|
|
|
|
std::string key = file->getFullPath();
|
|
|
|
|
|
|
|
SystemData* curSys = sysData.system;
|
|
|
|
const std::unordered_map<std::string, FileData*>& children = curSys->getRootFolder()->getChildrenByFilename();
|
2017-11-11 14:56:22 +00:00
|
|
|
bool found = children.find(key) != children.cend();
|
2017-07-18 09:45:50 +00:00
|
|
|
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 from index, so we can re-index metadata after refreshing
|
|
|
|
fileIndex->removeFromIndex(collectionEntry);
|
|
|
|
collectionEntry->refreshMetadata();
|
|
|
|
// found and we are removing
|
|
|
|
if (name == "favorites" && file->metadata.get("favorite") == "false") {
|
|
|
|
// need to check if still marked as favorite, if not remove
|
|
|
|
ViewController::get()->getGameListView(curSys).get()->remove(collectionEntry, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// re-index with new metadata
|
|
|
|
fileIndex->addToIndex(collectionEntry);
|
|
|
|
ViewController::get()->onFileChanged(collectionEntry, FILE_METADATA_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we didn't find it here - we need to check if we should add it
|
|
|
|
if (name == "recent" && file->metadata.get("playcount") > "0" && includeFileInAutoCollections(file) ||
|
|
|
|
name == "favorites" && file->metadata.get("favorite") == "true") {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rootFolder->sort(getSortTypeFromString(mCollectionSystemDeclsIndex[name].defaultSort));
|
|
|
|
ViewController::get()->onFileChanged(rootFolder, FILE_SORTED);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// deletes all collection files from collection systems related to the source file
|
|
|
|
void CollectionSystemManager::deleteCollectionFiles(FileData* file)
|
|
|
|
{
|
|
|
|
// 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;
|
2017-11-11 14:56:22 +00:00
|
|
|
allCollections.insert(mAutoCollectionSystemsData.cbegin(), mAutoCollectionSystemsData.cend());
|
|
|
|
allCollections.insert(mCustomCollectionSystemsData.cbegin(), mCustomCollectionSystemsData.cend());
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
for(auto sysDataIt = allCollections.begin(); sysDataIt != allCollections.end(); sysDataIt++)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
if (sysDataIt->second.isPopulated)
|
|
|
|
{
|
|
|
|
const std::unordered_map<std::string, FileData*>& children = (sysDataIt->second.system)->getRootFolder()->getChildrenByFilename();
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
bool found = children.find(key) != children.cend();
|
2017-07-18 09:45:50 +00:00
|
|
|
if (found) {
|
|
|
|
sysDataIt->second.needsSave = true;
|
|
|
|
FileData* collectionEntry = children.at(key);
|
2017-11-07 23:24:51 +00:00
|
|
|
SystemData* systemViewToUpdate = getSystemToView(sysDataIt->second.system);
|
|
|
|
ViewController::get()->getGameListView(systemViewToUpdate).get()->remove(collectionEntry, false);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// returns whether the current theme is compatible with Automatic or Custom Collections
|
|
|
|
bool CollectionSystemManager::isThemeGenericCollectionCompatible(bool genericCustomCollections)
|
|
|
|
{
|
|
|
|
std::vector<std::string> cfgSys = getCollectionThemeFolders(genericCustomCollections);
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = cfgSys.cbegin(); sysIt != cfgSys.cend(); sysIt++)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
if(!themeFolderExists(*sysIt))
|
|
|
|
return false;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
return true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
bool CollectionSystemManager::isThemeCustomCollectionCompatible(std::vector<std::string> stringVector)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
if (isThemeGenericCollectionCompatible(true))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// get theme path
|
2017-06-12 16:38:59 +00:00
|
|
|
auto themeSets = ThemeData::getThemeSets();
|
2017-07-18 09:45:50 +00:00
|
|
|
auto set = themeSets.find(Settings::getInstance()->getString("ThemeSet"));
|
2017-11-11 14:56:22 +00:00
|
|
|
if(set != themeSets.cend())
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::string defaultThemeFilePath = set->second.path.string() + "/theme.xml";
|
2017-12-04 23:30:25 +00:00
|
|
|
if (boost::filesystem::exists(defaultThemeFilePath))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = stringVector.cbegin(); sysIt != stringVector.cend(); sysIt++)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
if(!themeFolderExists(*sysIt))
|
|
|
|
return false;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
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)
|
|
|
|
{
|
2017-11-29 19:57:43 +00:00
|
|
|
std::string name = inName;
|
|
|
|
|
|
|
|
if(index == 0)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-11-29 19:57:43 +00:00
|
|
|
size_t remove = std::string::npos;
|
|
|
|
|
|
|
|
// get valid name
|
|
|
|
while((remove = name.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-[]() ")) != std::string::npos)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-11-29 19:57:43 +00:00
|
|
|
name.erase(remove, 1);
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-29 19:57:43 +00:00
|
|
|
name += " (" + std::to_string(index) + ")";
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
2017-11-29 19:57:43 +00:00
|
|
|
|
|
|
|
if(name == "")
|
|
|
|
{
|
|
|
|
name = "New Collection";
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
if(name != inName)
|
|
|
|
{
|
|
|
|
LOG(LogInfo) << "Had to change name, from: " << inName << " to: " << name;
|
|
|
|
}
|
2017-11-29 19:57:43 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// get used systems in 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
|
2017-11-11 14:56:22 +00:00
|
|
|
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++)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
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
|
2017-11-11 14:56:22 +00:00
|
|
|
if (mCollectionSystemDeclsIndex.find(name) != mCollectionSystemDeclsIndex.cend())
|
2017-07-18 09:45:50 +00:00
|
|
|
return getValidNewCollectionName(name, index+1);
|
|
|
|
return name;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void CollectionSystemManager::setEditMode(std::string collectionName)
|
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
if (mCustomCollectionSystemsData.find(collectionName) == mCustomCollectionSystemsData.cend())
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Editing the '" + strToUpper(collectionName) + "' Collection. Add/remove games with Y.", 10000);
|
|
|
|
mWindow->setInfoPopup(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::exitEditMode()
|
|
|
|
{
|
|
|
|
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Finished editing the '" + mEditingCollection + "' Collection.", 4000);
|
|
|
|
mWindow->setInfoPopup(s);
|
|
|
|
mIsEditingCustom = false;
|
|
|
|
mEditingCollection = "Favorites";
|
|
|
|
}
|
|
|
|
|
|
|
|
// adds or removes a game from a specific collection
|
|
|
|
bool CollectionSystemManager::toggleGameInCollection(FileData* file)
|
|
|
|
{
|
|
|
|
if (file->getType() == GAME)
|
|
|
|
{
|
|
|
|
GuiInfoPopup* s;
|
|
|
|
bool adding = true;
|
|
|
|
std::string name = file->getName();
|
|
|
|
std::string sysName = mEditingCollection;
|
|
|
|
if (mIsEditingCustom)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
SystemData* sysData = mEditingCollectionSystemData->system;
|
|
|
|
mEditingCollectionSystemData->needsSave = true;
|
|
|
|
if (!mEditingCollectionSystemData->isPopulated)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
populateCustomCollection(mEditingCollectionSystemData);
|
|
|
|
}
|
|
|
|
std::string key = file->getFullPath();
|
|
|
|
FileData* rootFolder = sysData->getRootFolder();
|
|
|
|
const std::unordered_map<std::string, FileData*>& children = rootFolder->getChildrenByFilename();
|
2017-11-11 14:56:22 +00:00
|
|
|
bool found = children.find(key) != children.cend();
|
2017-07-18 09:45:50 +00:00
|
|
|
FileFilterIndex* fileIndex = sysData->getIndex();
|
|
|
|
std::string name = sysData->getName();
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
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)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
systemViewToUpdate->getIndex()->removeFromIndex(collectionEntry);
|
|
|
|
}
|
|
|
|
ViewController::get()->getGameListView(systemViewToUpdate).get()->remove(collectionEntry, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we didn't find it here, 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);
|
|
|
|
rootFolder->sort(getSortTypeFromString(mEditingCollectionSystemData->decl.defaultSort));
|
|
|
|
ViewController::get()->onFileChanged(systemViewToUpdate->getRootFolder(), FILE_SORTED);
|
|
|
|
// add to bundle index as well, if needed
|
|
|
|
if(systemViewToUpdate != sysData)
|
|
|
|
{
|
|
|
|
systemViewToUpdate->getIndex()->addToIndex(newGame);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
updateCollectionFolderMetadata(sysData);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
else
|
|
|
|
{
|
2018-01-20 21:26:21 +00:00
|
|
|
file->getSourceFileData()->getSystem()->getIndex()->removeFromIndex(file);
|
2017-07-18 09:45:50 +00:00
|
|
|
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");
|
|
|
|
}
|
2018-01-20 21:26:21 +00:00
|
|
|
file->getSourceFileData()->getSystem()->getIndex()->addToIndex(file);
|
2017-07-18 09:45:50 +00:00
|
|
|
refreshCollectionSystems(file->getSourceFileData());
|
|
|
|
}
|
|
|
|
if (adding)
|
|
|
|
{
|
|
|
|
s = new GuiInfoPopup(mWindow, "Added '" + removeParenthesis(name) + "' to '" + strToUpper(sysName) + "'", 4000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = new GuiInfoPopup(mWindow, "Removed '" + removeParenthesis(name) + "' from '" + strToUpper(sysName) + "'", 4000);
|
|
|
|
}
|
|
|
|
mWindow->setInfoPopup(s);
|
|
|
|
return true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
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
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
SystemData* systemToView = sys;
|
|
|
|
FileData* rootFolder = sys->getRootFolder();
|
|
|
|
|
|
|
|
FileData* bundleRootFolder = mCustomCollectionsBundle->getRootFolder();
|
|
|
|
const std::unordered_map<std::string, FileData*>& bundleChildren = bundleRootFolder->getChildrenByFilename();
|
|
|
|
|
|
|
|
// is the rootFolder bundled in the "My Collections" system?
|
2017-11-11 14:56:22 +00:00
|
|
|
bool sysFoundInBundle = bundleChildren.find(rootFolder->getKey()) != bundleChildren.cend();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
|
|
|
if (sysFoundInBundle && sys->isCollection())
|
|
|
|
{
|
|
|
|
systemToView = mCustomCollectionsBundle;
|
|
|
|
}
|
|
|
|
return systemToView;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles loading a collection system, creating an empty one, and populating on demand */
|
|
|
|
// loads Automatic Collection systems (All, Favorites, Last Played)
|
|
|
|
void CollectionSystemManager::initAutoCollectionSystems()
|
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for(std::map<std::string, CollectionSystemDecl>::const_iterator it = mCollectionSystemDeclsIndex.cbegin() ; it != mCollectionSystemDeclsIndex.cend() ; it++ )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
|
|
|
CollectionSystemDecl sysDecl = it->second;
|
|
|
|
if (!sysDecl.isCustom)
|
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
createNewCollectionEntry(sysDecl.name, sysDecl);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// this may come in handy if at any point in time in the future we want to
|
|
|
|
// automatically generate metadata for a folder
|
|
|
|
void CollectionSystemManager::updateCollectionFolderMetadata(SystemData* sys)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
FileData* rootFolder = sys->getRootFolder();
|
|
|
|
|
|
|
|
std::string desc = "This collection is empty.";
|
|
|
|
std::string rating = "0";
|
|
|
|
std::string players = "1";
|
|
|
|
std::string releasedate = "N/A";
|
|
|
|
std::string developer = "None";
|
|
|
|
std::string genre = "None";
|
|
|
|
std::string video = "";
|
|
|
|
std::string thumbnail = "";
|
|
|
|
|
|
|
|
std::unordered_map<std::string, FileData*> games = rootFolder->getChildrenByFilename();
|
|
|
|
|
|
|
|
if(games.size() > 0)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::string games_list = "";
|
|
|
|
int games_counter = 0;
|
2017-11-11 14:56:22 +00:00
|
|
|
for(std::unordered_map<std::string, FileData*>::const_iterator iter = games.cbegin(); iter != games.cend(); ++iter)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
games_counter++;
|
|
|
|
FileData* file = iter->second;
|
|
|
|
|
|
|
|
std::string new_rating = file->metadata.get("rating");
|
|
|
|
std::string new_releasedate = file->metadata.get("releasedate");
|
|
|
|
std::string new_developer = file->metadata.get("developer");
|
|
|
|
std::string new_genre = file->metadata.get("genre");
|
|
|
|
std::string new_players = file->metadata.get("players");
|
|
|
|
|
|
|
|
rating = (new_rating > rating ? (new_rating != "" ? new_rating : rating) : rating);
|
|
|
|
players = (new_players > players ? (new_players != "" ? new_players : players) : players);
|
|
|
|
releasedate = (new_releasedate < releasedate ? (new_releasedate != "" ? new_releasedate : releasedate) : releasedate);
|
|
|
|
developer = (developer == "None" ? new_developer : (new_developer != developer ? "Various" : new_developer));
|
|
|
|
genre = (genre == "None" ? new_genre : (new_genre != genre ? "Various" : new_genre));
|
|
|
|
|
|
|
|
switch(games_counter)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
games_list += ", ";
|
|
|
|
case 1:
|
|
|
|
games_list += "'" + file->getName() + "'";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
games_list += " among other titles.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = "This collection contains " + std::to_string(games_counter) + " games, including " + games_list;
|
|
|
|
|
|
|
|
FileData* randomGame = sys->getRandomGame();
|
|
|
|
|
|
|
|
video = randomGame->getVideoPath();
|
|
|
|
thumbnail = randomGame->getThumbnailPath();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
rootFolder->metadata.set("desc", desc);
|
|
|
|
rootFolder->metadata.set("rating", rating);
|
|
|
|
rootFolder->metadata.set("players", players);
|
|
|
|
rootFolder->metadata.set("genre", genre);
|
|
|
|
rootFolder->metadata.set("releasedate", releasedate);
|
|
|
|
rootFolder->metadata.set("developer", developer);
|
|
|
|
rootFolder->metadata.set("video", video);
|
|
|
|
rootFolder->metadata.set("image", thumbnail);
|
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
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> systems = getCollectionsFromConfigFolder();
|
2017-11-11 14:56:22 +00:00
|
|
|
for (auto nameIt = systems.cbegin(); nameIt != systems.cend(); nameIt++)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
CollectionSystemData* allSysData = &mAutoCollectionSystemsData["all"];
|
|
|
|
if (!allSysData->isPopulated)
|
|
|
|
{
|
|
|
|
populateAutoCollection(allSysData);
|
|
|
|
}
|
|
|
|
return allSysData->system;
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemData* CollectionSystemManager::addNewCustomCollection(std::string name)
|
|
|
|
{
|
|
|
|
CollectionSystemDecl decl = mCollectionSystemDeclsIndex[myCollectionsName];
|
|
|
|
decl.themeFolder = name;
|
|
|
|
decl.name = name;
|
|
|
|
decl.longName = name;
|
|
|
|
return createNewCollectionEntry(name, decl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// creates a new, empty Collection system, based on the name and declaration
|
|
|
|
SystemData* CollectionSystemManager::createNewCollectionEntry(std::string name, CollectionSystemDecl sysDecl, bool index)
|
|
|
|
{
|
|
|
|
SystemData* newSys = new SystemData(name, sysDecl.longName, mCollectionEnvData, sysDecl.themeFolder, true);
|
|
|
|
|
|
|
|
CollectionSystemData newCollectionData;
|
|
|
|
newCollectionData.system = newSys;
|
|
|
|
newCollectionData.decl = sysDecl;
|
|
|
|
newCollectionData.isEnabled = false;
|
|
|
|
newCollectionData.isPopulated = false;
|
|
|
|
newCollectionData.needsSave = false;
|
|
|
|
|
|
|
|
if (index)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
if (!sysDecl.isCustom)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
mAutoCollectionSystemsData[name] = newCollectionData;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
mCustomCollectionSystemsData[name] = newCollectionData;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
|
|
|
|
return newSys;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// populates an Automatic Collection System
|
|
|
|
void CollectionSystemManager::populateAutoCollection(CollectionSystemData* sysData)
|
|
|
|
{
|
|
|
|
SystemData* newSys = sysData->system;
|
|
|
|
CollectionSystemDecl sysDecl = sysData->decl;
|
|
|
|
FileData* rootFolder = newSys->getRootFolder();
|
|
|
|
FileFilterIndex* index = newSys->getIndex();
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = SystemData::sSystemVector.cbegin(); sysIt != SystemData::sSystemVector.cend(); sysIt++)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// we won't iterate all collections
|
|
|
|
if ((*sysIt)->isGameSystem() && !(*sysIt)->isCollection()) {
|
|
|
|
std::vector<FileData*> files = (*sysIt)->getRootFolder()->getFilesRecursive(GAME);
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto gameIt = files.cbegin(); gameIt != files.cend(); gameIt++)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (include) {
|
|
|
|
CollectionFileData* newGame = new CollectionFileData(*gameIt, newSys);
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
index->addToIndex(newGame);
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
rootFolder->sort(getSortTypeFromString(sysDecl.defaultSort));
|
|
|
|
sysData->isPopulated = true;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// populates a Custom Collection System
|
|
|
|
void CollectionSystemManager::populateCustomCollection(CollectionSystemData* sysData)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
SystemData* newSys = sysData->system;
|
|
|
|
sysData->isPopulated = true;
|
|
|
|
CollectionSystemDecl sysDecl = sysData->decl;
|
|
|
|
std::string path = getCustomCollectionConfigPath(newSys->getName());
|
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
if(!boost::filesystem::exists(path))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
LOG(LogInfo) << "Couldn't find custom collection config file at " << path;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG(LogInfo) << "Loading custom collection config file at " << path;
|
|
|
|
|
|
|
|
FileData* rootFolder = newSys->getRootFolder();
|
|
|
|
FileFilterIndex* index = newSys->getIndex();
|
|
|
|
|
|
|
|
// get Configuration for this Custom System
|
|
|
|
std::ifstream input(path);
|
|
|
|
|
|
|
|
// get all files map
|
|
|
|
std::unordered_map<std::string,FileData*> allFilesMap = getAllGamesCollection()->getRootFolder()->getChildrenByFilename();
|
|
|
|
|
|
|
|
// iterate list of files in config file
|
|
|
|
|
|
|
|
for(std::string gameKey; getline(input, gameKey); )
|
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
std::unordered_map<std::string,FileData*>::const_iterator it = allFilesMap.find(gameKey);
|
|
|
|
if (it != allFilesMap.cend()) {
|
2017-07-18 09:45:50 +00:00
|
|
|
CollectionFileData* newGame = new CollectionFileData(it->second, newSys);
|
|
|
|
rootFolder->addChild(newGame);
|
|
|
|
index->addToIndex(newGame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LogInfo) << "Couldn't find game referenced at '" << gameKey << "' for system config '" << path << "'";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rootFolder->sort(getSortTypeFromString(sysDecl.defaultSort));
|
|
|
|
updateCollectionFolderMetadata(newSys);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
/* Handle System View removal and insertion of Collections */
|
|
|
|
void CollectionSystemManager::removeCollectionsFromDisplayedSystems()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
|
|
|
// remove all Collection Systems
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = SystemData::sSystemVector.cbegin(); sysIt != SystemData::sSystemVector.cend(); )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
|
|
|
if ((*sysIt)->isCollection())
|
|
|
|
{
|
|
|
|
sysIt = SystemData::sSystemVector.erase(sysIt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sysIt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// remove all custom collections in bundle
|
|
|
|
// this should not delete the objects from memory!
|
|
|
|
FileData* customRoot = mCustomCollectionsBundle->getRootFolder();
|
|
|
|
std::vector<FileData*> mChildren = customRoot->getChildren();
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto it = mChildren.cbegin(); it != mChildren.cend(); it++)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
customRoot->removeChild(*it);
|
|
|
|
}
|
|
|
|
// clear index
|
|
|
|
mCustomCollectionsBundle->getIndex()->resetIndex();
|
|
|
|
// remove view so it's re-created as needed
|
|
|
|
ViewController::get()->removeGameListView(mCustomCollectionsBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionSystemManager::addEnabledCollectionsToDisplayedSystems(std::map<std::string, CollectionSystemData>* colSystemData)
|
|
|
|
{
|
|
|
|
// add auto enabled ones
|
|
|
|
for(std::map<std::string, CollectionSystemData>::iterator it = colSystemData->begin() ; it != colSystemData->end() ; it++ )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
|
|
|
if(it->second.isEnabled)
|
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// 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"))
|
|
|
|
{
|
|
|
|
// exists theme folder, 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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileData* newSysRootFolder = it->second.system->getRootFolder();
|
|
|
|
mCustomCollectionsBundle->getRootFolder()->addChild(newSysRootFolder);
|
|
|
|
mCustomCollectionsBundle->getIndex()->importIndex(it->second.system->getIndex());
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Auxiliary methods to get available custom collection possibilities */
|
|
|
|
std::vector<std::string> CollectionSystemManager::getSystemsFromConfig()
|
|
|
|
{
|
|
|
|
std::vector<std::string> systems;
|
|
|
|
std::string path = SystemData::getConfigPath(false);
|
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
if(!boost::filesystem::exists(path))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
return systems;
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
pugi::xml_document doc;
|
|
|
|
pugi::xml_parse_result res = doc.load_file(path.c_str());
|
|
|
|
|
|
|
|
if(!res)
|
|
|
|
{
|
|
|
|
return systems;
|
|
|
|
}
|
|
|
|
|
|
|
|
//actually read the file
|
|
|
|
pugi::xml_node systemList = doc.child("systemList");
|
|
|
|
|
|
|
|
if(!systemList)
|
|
|
|
{
|
|
|
|
return systems;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// gets all folders from the current theme path
|
|
|
|
std::vector<std::string> CollectionSystemManager::getSystemsFromTheme()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> systems;
|
|
|
|
|
|
|
|
auto themeSets = ThemeData::getThemeSets();
|
|
|
|
if(themeSets.empty())
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// no theme sets available
|
|
|
|
return systems;
|
|
|
|
}
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
std::map<std::string, ThemeSet>::const_iterator set = themeSets.find(Settings::getInstance()->getString("ThemeSet"));
|
|
|
|
if(set == themeSets.cend())
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
// currently selected theme set is missing, so just pick the first available set
|
2017-11-11 14:56:22 +00:00
|
|
|
set = themeSets.cbegin();
|
2017-07-18 09:45:50 +00:00
|
|
|
Settings::getInstance()->setString("ThemeSet", set->first);
|
|
|
|
}
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
boost::filesystem::path themePath = set->second.path;
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
if (boost::filesystem::exists(themePath))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-12-04 23:30:25 +00:00
|
|
|
boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
|
|
|
|
for (boost::filesystem::directory_iterator itr(themePath); itr != end_itr; ++itr)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-12-04 23:30:25 +00:00
|
|
|
if (boost::filesystem::is_directory(itr->status()))
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
//... here you have a directory
|
|
|
|
std::string folder = itr->path().string();
|
|
|
|
folder = folder.substr(themePath.string().size()+1);
|
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
if(boost::filesystem::exists(set->second.getThemePath(folder)))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
systems.push_back(folder);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
std::sort(systems.begin(), systems.end());
|
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// returns the unused folders from current theme path
|
|
|
|
std::vector<std::string> CollectionSystemManager::getUnusedSystemsFromTheme()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +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
|
2017-11-11 14:56:22 +00:00
|
|
|
systemsInUse.insert(systemsInUse.cend(), autoSys.cbegin(), autoSys.cend());
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), customSys.cbegin(), customSys.cend());
|
|
|
|
systemsInUse.insert(systemsInUse.cend(), userSys.cbegin(), userSys.cend());
|
2017-06-12 16:38:59 +00:00
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto sysIt = themeSys.cbegin(); sysIt != themeSys.cend(); )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
if (std::find(systemsInUse.cbegin(), systemsInUse.cend(), *sysIt) != systemsInUse.cend())
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
sysIt = themeSys.erase(sysIt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sysIt++;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
return themeSys;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// returns which collection config files exist in the user folder
|
|
|
|
std::vector<std::string> CollectionSystemManager::getCollectionsFromConfigFolder()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> systems;
|
2017-12-04 23:30:25 +00:00
|
|
|
boost::filesystem::path configPath = getCollectionsFolder();
|
2017-07-18 09:45:50 +00:00
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
if (boost::filesystem::exists(configPath))
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-12-04 23:30:25 +00:00
|
|
|
boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
|
|
|
|
for (boost::filesystem::directory_iterator itr(configPath); itr != end_itr; ++itr)
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
2017-12-04 23:30:25 +00:00
|
|
|
if (boost::filesystem::is_regular_file(itr->status()))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
// it's a file
|
|
|
|
std::string file = itr->path().string();
|
|
|
|
std::string filename = file.substr(configPath.string().size());
|
|
|
|
|
|
|
|
// need to confirm filename matches config format
|
2017-11-29 19:57:43 +00:00
|
|
|
if (filename != "custom-.cfg" && Utils::String::startsWith(filename, "custom-") && Utils::String::endsWith(filename, ".cfg"))
|
2017-07-18 09:45:50 +00:00
|
|
|
{
|
|
|
|
filename = filename.substr(7, filename.size()-11);
|
|
|
|
systems.push_back(filename);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
LOG(LogInfo) << "Found non-collection config file in collections folder: " << filename;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// returns the theme folders for Automatic Collections (All, Favorites, Last Played) or generic Custom Collections folder
|
|
|
|
std::vector<std::string> CollectionSystemManager::getCollectionThemeFolders(bool custom)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> systems;
|
2017-11-11 14:56:22 +00:00
|
|
|
for(std::map<std::string, CollectionSystemDecl>::const_iterator it = mCollectionSystemDeclsIndex.cbegin() ; it != mCollectionSystemDeclsIndex.cend() ; it++ )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
CollectionSystemDecl sysDecl = it->second;
|
|
|
|
if (sysDecl.isCustom == custom)
|
|
|
|
{
|
|
|
|
systems.push_back(sysDecl.themeFolder);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
return systems;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
// returns the theme folders in use for the user-defined Custom Collections
|
|
|
|
std::vector<std::string> CollectionSystemManager::getUserCollectionThemeFolders()
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
std::vector<std::string> systems;
|
2017-11-11 14:56:22 +00:00
|
|
|
for(std::map<std::string, CollectionSystemData>::const_iterator it = mCustomCollectionSystemsData.cbegin() ; it != mCustomCollectionSystemsData.cend() ; it++ )
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
systems.push_back(it->second.decl.themeFolder);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
return systems;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns whether a specific folder exists in the theme
|
|
|
|
bool CollectionSystemManager::themeFolderExists(std::string folder)
|
|
|
|
{
|
|
|
|
std::vector<std::string> themeSys = getSystemsFromTheme();
|
2017-11-11 14:56:22 +00:00
|
|
|
return std::find(themeSys.cbegin(), themeSys.cend(), folder) != themeSys.cend();
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CollectionSystemManager::includeFileInAutoCollections(FileData* file)
|
|
|
|
{
|
2017-07-18 09:45:50 +00:00
|
|
|
// we exclude non-game files from collections (i.e. "kodi", entries from non-game systems)
|
2017-06-12 16:38:59 +00:00
|
|
|
// 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
|
2017-07-18 09:45:50 +00:00
|
|
|
return file->getName() != "kodi" && file->getSystem()->isGameSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string getCustomCollectionConfigPath(std::string collectionName)
|
|
|
|
{
|
2017-12-04 23:30:25 +00:00
|
|
|
boost::filesystem::path path = getCollectionsFolder() + "custom-" + collectionName + ".cfg";
|
2017-07-18 09:45:50 +00:00
|
|
|
return path.generic_string();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getCollectionsFolder()
|
|
|
|
{
|
|
|
|
return getHomePath() + "/.emulationstation/collections/";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool systemSort(SystemData* sys1, SystemData* sys2)
|
|
|
|
{
|
2018-01-09 21:59:23 +00:00
|
|
|
std::string name1 = Utils::String::toUpper(sys1->getName());
|
|
|
|
std::string name2 = Utils::String::toUpper(sys2->getName());
|
2017-07-18 09:45:50 +00:00
|
|
|
return name1.compare(name2) < 0;
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|