Skip to content

Commit

Permalink
Merge branch 'RetroPie:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemba authored Feb 10, 2024
2 parents e0db667 + a5cc5ce commit 8faed5f
Show file tree
Hide file tree
Showing 19 changed files with 358 additions and 256 deletions.
184 changes: 84 additions & 100 deletions es-app/src/CollectionSystemManager.cpp

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions es-app/src/CollectionSystemManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ class Window;
struct SystemEnvironmentData;
class FileFilterIndex;

#define RANDOM_SYSTEM_MAX 5
#define DEFAULT_RANDOM_SYSTEM_GAMES 1
#define DEFAULT_RANDOM_COLLECTIONS_GAMES 0
static const std::string CUSTOM_COLL_ID = "collections";
static const std::string RANDOM_COLL_ID = "random";
constexpr int LAST_PLAYED_MAX = 50;

constexpr int RANDOM_SYSTEM_MAX = 5;
constexpr int DEFAULT_RANDOM_SYSTEM_GAMES = 1;
constexpr int DEFAULT_RANDOM_COLLECTIONS_GAMES = 0;

enum CollectionSystemType
{
Expand Down Expand Up @@ -45,8 +49,6 @@ struct CollectionSystemData
bool needsSave;
};

std::map<std::string, int> stringToRandomSettingsMap(std::string sourceStr);

class CollectionSystemManager
{
public:
Expand Down Expand Up @@ -109,8 +111,8 @@ class CollectionSystemManager
void populateAutoCollection(CollectionSystemData* sysData);
void populateCustomCollection(CollectionSystemData* sysData);
void addRandomGames(SystemData* newSys, SystemData* sourceSystem, FileData* rootFolder, FileFilterIndex* index,
std::map<std::string, int> settingsValues, int defaultValue);
void populateRandomCollectionFromCollections(std::map<std::string, int> settingsValues);
std::map<std::string, std::map<std::string, int>> mapsForRandomColl, int defaultValue);
void populateRandomCollectionFromCollections(std::map<std::string, std::map<std::string, int>> mapsForRandomColl);

void removeCollectionsFromDisplayedSystems();
void addEnabledCollectionsToDisplayedSystems(std::map<std::string, CollectionSystemData>* colSystemData, bool processRandom);
Expand Down
55 changes: 33 additions & 22 deletions es-app/src/Gamelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@

FileData* findOrCreateFile(SystemData* system, const std::string& path, FileType type)
{
// first, verify that path is within the system's root folder
FileData* root = system->getRootFolder();
bool contains = false;
std::string relative = Utils::FileSystem::removeCommonPath(path, root->getPath(), contains, true);
const std::string systemPath = root->getPath();

// first, verify that path is within the system's root folder
std::string relative = Utils::FileSystem::removeCommonPath(path, systemPath, contains, true);
if(!contains)
{
LOG(LogError) << "File path \"" << path << "\" is outside system path \"" << system->getStartPath() << "\"";
return NULL;
}

Utils::FileSystem::stringList pathList = Utils::FileSystem::getPathList(relative);

auto path_it = pathList.begin();
FileData* treeNode = root;
bool found = false;

// iterate over all subpaths below the provided path
while(path_it != pathList.end())
{
const std::unordered_map<std::string, FileData*>& children = treeNode->getChildrenByFilename();

std::string key = *path_it;
found = children.find(key) != children.cend();
std::string pathSegment = *path_it;
auto candidate = children.find(pathSegment);
found = candidate != children.cend();
if (found) {
treeNode = children.at(key);
treeNode = candidate->second;
}

// this is the end
Expand Down Expand Up @@ -65,12 +70,16 @@ FileData* findOrCreateFile(SystemData* system, const std::string& path, FileType
// if type is a folder it's gonna be empty, so don't bother
if(type == FOLDER)
{
LOG(LogWarning) << "gameList: folder doesn't already exist, won't create";
std::string absFolder = Utils::FileSystem::getAbsolutePath(pathSegment, systemPath);
LOG(LogWarning) << "gameList: folder " << absFolder << " absent on fs, no FileData object created. Do remove leftover in gamelist.xml to remediate this warning.";
return NULL;
}

// create missing folder
FileData* folder = new FileData(FOLDER, Utils::FileSystem::getStem(treeNode->getPath()) + "/" + *path_it, system->getSystemEnvData(), system);
// create folder filedata object
std::string absPath = Utils::FileSystem::resolveRelativePath(treeNode->getPath() + "/" + pathSegment, systemPath, false, true);
FileData* folder = new FileData(FOLDER, absPath, system->getSystemEnvData(), system);
LOG(LogDebug) << "folder not found as FileData, adding: " << folder->getPath();

treeNode->addChild(folder);
treeNode = folder;
}
Expand Down Expand Up @@ -118,7 +127,8 @@ void parseGamelist(SystemData* system)
FileType type = typeList[i];
for(pugi::xml_node fileNode = root.child(tag); fileNode; fileNode = fileNode.next_sibling(tag))
{
const std::string path = Utils::FileSystem::resolveRelativePath(fileNode.child("path").text().get(), relativeTo, false, true);
std::string path = fileNode.child("path").text().get();
path = Utils::FileSystem::resolveRelativePath(path, relativeTo, false, true);

if(!trustGamelist && !Utils::FileSystem::exists(path))
{
Expand All @@ -127,7 +137,7 @@ void parseGamelist(SystemData* system)
}

// Check whether the file's extension is allowed in the system
if (std::find(allowedExtensions.cbegin(), allowedExtensions.cend(), Utils::FileSystem::getExtension(path)) == allowedExtensions.cend())
if (i == 0 /*game*/ && std::find(allowedExtensions.cbegin(), allowedExtensions.cend(), Utils::FileSystem::getExtension(path)) == allowedExtensions.cend())
{
LOG(LogDebug) << "file " << path << " found in gamelist, but has unregistered extension";
continue;
Expand All @@ -142,7 +152,7 @@ void parseGamelist(SystemData* system)
else if(!file->isArcadeAsset())
{
std::string defaultName = file->metadata.get("name");
file->metadata = MetaDataList::createFromXML(GAME_METADATA, fileNode, relativeTo);
file->metadata = MetaDataList::createFromXML(i == 0 ? GAME_METADATA : FOLDER_METADATA, fileNode, relativeTo);

//make sure name gets set if one didn't exist
if(file->metadata.get("name").empty())
Expand Down Expand Up @@ -173,7 +183,8 @@ void addFileDataNode(pugi::xml_node& parent, const FileData* file, const char* t
//there's something useful in there so we'll keep the node, add the path

// try and make the path relative if we can so things still work if we change the rom folder location in the future
newNode.prepend_child("path").text().set(Utils::FileSystem::createRelativePath(file->getPath(), system->getStartPath(), false, true).c_str());
std::string relPath = Utils::FileSystem::createRelativePath(file->getPath(), system->getStartPath(), false, true);
newNode.prepend_child("path").text().set(relPath.c_str());
}
}

Expand Down Expand Up @@ -224,23 +235,22 @@ void updateGamelist(SystemData* system)
{
int numUpdated = 0;

//get only files, no folders
std::vector<FileData*> files = rootFolder->getFilesRecursive(GAME | FOLDER);

// Stage 1: iterate through all files in memory, checking for changes
for(std::vector<FileData*>::const_iterator fit = files.cbegin(); fit != files.cend(); ++fit)
{

// do not touch if it wasn't changed anyway
if (!(*fit)->metadata.wasChanged())
continue;

// adding item to changed list
if ((*fit)->getType() == GAME)
if ((*fit)->getType() == GAME)
{
changedGames.push_back((*fit));
changedGames.push_back((*fit));
}
else
else
{
changedFolders.push_back((*fit));
}
Expand All @@ -251,13 +261,13 @@ void updateGamelist(SystemData* system)
const char* tagList[2] = { "game", "folder" };
FileType typeList[2] = { GAME, FOLDER };
std::vector<FileData*> changedList[2] = { changedGames, changedFolders };

for(int i = 0; i < 2; i++)
{
const char* tag = tagList[i];
std::vector<FileData*> changes = changedList[i];

// if changed items of this type
// check for changed items of this type
if (changes.size() > 0) {
// check if the item already exists in the XML
// if it does, remove all corresponding items before adding
Expand All @@ -274,9 +284,10 @@ void updateGamelist(SystemData* system)
continue;
}

std::string xmlpath = pathNode.text().get();
// apply the same transformation as in Gamelist::parseGamelist
std::string xmlpath = Utils::FileSystem::resolveRelativePath(pathNode.text().get(), relativeTo, false, true);
xmlpath = Utils::FileSystem::resolveRelativePath(xmlpath, relativeTo, false, true);

for(std::vector<FileData*>::const_iterator cfit = changes.cbegin(); cfit != changes.cend(); ++cfit)
{
if(xmlpath == (*cfit)->getPath())
Expand Down
19 changes: 13 additions & 6 deletions es-app/src/MetaData.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "MetaData.h"

#include "utils/FileSystemUtil.h"
#include "utils/TimeUtil.h"
#include "Log.h"
#include <pugixml.hpp>

Expand All @@ -27,6 +28,12 @@ MetaDataDecl gameDecls[] = {
};
const std::vector<MetaDataDecl> gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0]));

const inline std::string blankDate() {
// blank date (1970-01-02) is used to render "" (see DateTimeComponent.cpp) for
// folder metadata when no date is provided (=default case)
return Utils::Time::timeToString(Utils::Time::BLANK_DATE, "%Y%m%d");
}

MetaDataDecl folderDecls[] = {
{"name", MD_STRING, "", false, "name", "enter game name"},
{"sortname", MD_STRING, "", false, "sortname", "enter game sort name"},
Expand All @@ -35,12 +42,12 @@ MetaDataDecl folderDecls[] = {
{"thumbnail", MD_PATH, "", false, "thumbnail", "enter path to thumbnail"},
{"video", MD_PATH, "", false, "video", "enter path to video"},
{"marquee", MD_PATH, "", false, "marquee", "enter path to marquee"},
{"rating", MD_RATING, "0.000000", false, "rating", "enter rating"},
{"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date"},
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer"},
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"},
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},
{"players", MD_INT, "1", false, "players", "enter number of players"}
{"rating", MD_RATING, "", false, "rating", "enter rating"},
{"releasedate", MD_DATE, blankDate(), true, "release date", "enter release date"},
{"developer", MD_STRING, "", false, "developer", "enter game developer"},
{"publisher", MD_STRING, "", false, "publisher", "enter game publisher"},
{"genre", MD_STRING, "", false, "genre", "enter game genre"},
{"players", MD_INT, "", false, "players", "enter number of players"}
};
const std::vector<MetaDataDecl> folderMDD(folderDecls, folderDecls + sizeof(folderDecls) / sizeof(folderDecls[0]));

Expand Down
2 changes: 1 addition & 1 deletion es-app/src/MetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct MetaDataDecl
std::string key;
MetaDataType type;
std::string defaultValue;
bool isStatistic; //if true, ignore scraper values for this metadata
bool isStatistic; // if true: ignore in scraping and hide in metadata edits for this key
std::string displayName; // displayed as this in editors
std::string displayPrompt; // phrase displayed in editors when prompted to enter value (currently only for strings)
};
Expand Down
8 changes: 4 additions & 4 deletions es-app/src/SystemScreenSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void SystemScreenSaver::setVideoScreensaver(std::string& path)
mVideoScreensaver->setScreensaverMode(true);
mVideoScreensaver->onShow();

setupScreenSaverEditingCollection();
handleScreenSaverEditingCollection();
PowerSaver::runningScreenSaver(true);
mTimer = 0;
}
Expand All @@ -172,7 +172,7 @@ void SystemScreenSaver::setImageScreensaver(std::string& path)
mImageScreensaver->setMaxSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
}

setupScreenSaverEditingCollection();
handleScreenSaverEditingCollection();
PowerSaver::runningScreenSaver(true);
mTimer = 0;
}
Expand All @@ -187,7 +187,7 @@ bool SystemScreenSaver::isFileVideo(std::string& path)
return pathFilter.find(pathExtension) != std::string::npos;
}

void SystemScreenSaver::setupScreenSaverEditingCollection()
void SystemScreenSaver::handleScreenSaverEditingCollection()
{
std::string screensaverCollection = Settings::getInstance()->getString("DefaultScreenSaverCollection");
std::string currentEditingCollection = CollectionSystemManager::get()->getEditingCollection();
Expand Down Expand Up @@ -339,7 +339,7 @@ void SystemScreenSaver::stopScreenSaver(bool toResume)

// we need this to loop through different videos
mState = STATE_INACTIVE;
setupScreenSaverEditingCollection();
handleScreenSaverEditingCollection();
PowerSaver::runningScreenSaver(false);
}

Expand Down
2 changes: 1 addition & 1 deletion es-app/src/SystemScreenSaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SystemScreenSaver : public Window::ScreenSaver
void getAllGamelistNodesForSystem(SystemData* system);
void backgroundIndexing();
void setBackground();
void setupScreenSaverEditingCollection();
void handleScreenSaverEditingCollection();
void input(InputConfig* config, Input input);

enum STATE {
Expand Down
Loading

0 comments on commit 8faed5f

Please sign in to comment.