mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
Merge pull request #535 from pjft/count-screensaver-filedata
Change handling of screensaver to FileData only
This commit is contained in:
commit
3b461470c4
|
@ -14,10 +14,8 @@
|
|||
#include "Renderer.h"
|
||||
#include "Sound.h"
|
||||
#include "SystemData.h"
|
||||
#include <pugixml/src/pugixml.hpp>
|
||||
#include <unordered_map>
|
||||
#include <time.h>
|
||||
|
||||
#define FADE_TIME 300
|
||||
|
||||
SystemScreenSaver::SystemScreenSaver(Window* window) :
|
||||
|
@ -262,27 +260,21 @@ unsigned long SystemScreenSaver::countGameListNodes(const char *nodeName)
|
|||
std::vector<SystemData*>::const_iterator it;
|
||||
for (it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); ++it)
|
||||
{
|
||||
// We only want images and videos from game systems that are not collections
|
||||
if (!(*it)->isCollection() && (*it)->isGameSystem())
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
pugi::xml_node root;
|
||||
std::string xmlReadPath = (*it)->getGamelistPath(false);
|
||||
// We only want nodes from game systems that are not collections
|
||||
if (!(*it)->isGameSystem() || (*it)->isCollection())
|
||||
continue;
|
||||
|
||||
if(Utils::FileSystem::exists(xmlReadPath))
|
||||
FileData* rootFileData = (*it)->getRootFolder();
|
||||
|
||||
FileType type = GAME;
|
||||
std::vector<FileData*> allFiles = rootFileData->getFilesRecursive(type, true);
|
||||
std::vector<FileData*>::const_iterator itf; // declare an iterator to a vector of strings
|
||||
|
||||
for(itf=allFiles.cbegin() ; itf < allFiles.cend(); itf++) {
|
||||
if ((strcmp(nodeName, "video") == 0 && (*itf)->getVideoPath() != "") ||
|
||||
(strcmp(nodeName, "image") == 0 && (*itf)->getImagePath() != ""))
|
||||
{
|
||||
pugi::xml_parse_result result = doc.load_file(xmlReadPath.c_str());
|
||||
if (!result)
|
||||
continue;
|
||||
root = doc.child("gameList");
|
||||
if (!root)
|
||||
continue;
|
||||
for(pugi::xml_node fileNode = root.child("game"); fileNode; fileNode = fileNode.next_sibling("game"))
|
||||
{
|
||||
pugi::xml_node node = fileNode.child(nodeName);
|
||||
if (node)
|
||||
++nodeCount;
|
||||
}
|
||||
nodeCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,70 +304,31 @@ void SystemScreenSaver::pickGameListNode(unsigned long index, const char *nodeNa
|
|||
std::vector<SystemData*>::const_iterator it;
|
||||
for (it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); ++it)
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
pugi::xml_node root;
|
||||
|
||||
// We only want nodes from game systems that are not collections
|
||||
if (!(*it)->isGameSystem() || (*it)->isCollection())
|
||||
continue;
|
||||
|
||||
std::string xmlReadPath = (*it)->getGamelistPath(false);
|
||||
|
||||
if(Utils::FileSystem::exists(xmlReadPath))
|
||||
{
|
||||
pugi::xml_parse_result result = doc.load_file(xmlReadPath.c_str());
|
||||
if (!result)
|
||||
continue;
|
||||
root = doc.child("gameList");
|
||||
if (!root)
|
||||
continue;
|
||||
for(pugi::xml_node fileNode = root.child("game"); fileNode; fileNode = fileNode.next_sibling("game"))
|
||||
{
|
||||
pugi::xml_node node = fileNode.child(nodeName);
|
||||
if (node)
|
||||
{
|
||||
// See if this is the desired index
|
||||
if (index-- == 0)
|
||||
{
|
||||
// Yes. Resolve to a full path
|
||||
path = Utils::FileSystem::resolveRelativePath(node.text().get(), (*it)->getStartPath(), true);
|
||||
mSystemName = (*it)->getFullName();
|
||||
mGameName = fileNode.child("name").text().get();
|
||||
|
||||
// getting corresponding FileData
|
||||
|
||||
// try the easy way. Should work for the majority of cases, unless in subfolders
|
||||
FileData* rootFileData = (*it)->getRootFolder();
|
||||
std::string gamePath = Utils::FileSystem::resolveRelativePath(fileNode.child("path").text().get(), (*it)->getStartPath(), false);
|
||||
|
||||
std::string shortPath = gamePath;
|
||||
shortPath = shortPath.replace(0, (*it)->getStartPath().length()+1, "");
|
||||
|
||||
const std::unordered_map<std::string, FileData*>& children = rootFileData->getChildrenByFilename();
|
||||
std::unordered_map<std::string, FileData*>::const_iterator screenSaverGame = children.find(shortPath);
|
||||
|
||||
if (screenSaverGame != children.cend())
|
||||
{
|
||||
// Found the corresponding FileData
|
||||
mCurrentGame = screenSaverGame->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Couldn't find FileData. Going for the full iteration.
|
||||
// iterate on children
|
||||
FileType type = GAME;
|
||||
std::vector<FileData*> allFiles = rootFileData->getFilesRecursive(type);
|
||||
std::vector<FileData*> allFiles = rootFileData->getFilesRecursive(type, true);
|
||||
std::vector<FileData*>::const_iterator itf; // declare an iterator to a vector of strings
|
||||
|
||||
int i = 0;
|
||||
for(itf=allFiles.cbegin() ; itf < allFiles.cend(); itf++,i++ ) {
|
||||
if ((*itf)->getPath() == gamePath)
|
||||
for(itf=allFiles.cbegin() ; itf < allFiles.cend(); itf++) {
|
||||
if ((strcmp(nodeName, "video") == 0 && (*itf)->getVideoPath() != "") ||
|
||||
(strcmp(nodeName, "image") == 0 && (*itf)->getImagePath() != ""))
|
||||
{
|
||||
if (index-- == 0)
|
||||
{
|
||||
// We have it
|
||||
path = "";
|
||||
if (strcmp(nodeName, "video") == 0)
|
||||
path = (*itf)->getVideoPath();
|
||||
else if (strcmp(nodeName, "image") == 0)
|
||||
path = (*itf)->getImagePath();
|
||||
mSystemName = (*it)->getFullName();
|
||||
mGameName = (*itf)->getName();
|
||||
mCurrentGame = (*itf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// end of getting FileData
|
||||
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never")
|
||||
|
@ -386,7 +339,6 @@ void SystemScreenSaver::pickGameListNode(unsigned long index, const char *nodeNa
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SystemScreenSaver::pickRandomVideo(std::string& path)
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
|
||||
virtual FileData* getCurrentGame();
|
||||
virtual void launchGame();
|
||||
inline virtual void resetCounts() { mVideosCounted = false; mImagesCounted = false; };
|
||||
|
||||
private:
|
||||
unsigned long countGameListNodes(const char *nodeName);
|
||||
|
|
|
@ -432,6 +432,7 @@ void Window::startScreenSaver()
|
|||
{
|
||||
mScreenSaver->stopScreenSaver();
|
||||
mRenderScreenSaver = false;
|
||||
mScreenSaver->resetCounts();
|
||||
|
||||
// Tell the GUI components the screensaver has stopped
|
||||
for(auto i = mGuiStack.cbegin(); i != mGuiStack.cend(); i++)
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
virtual bool isScreenSaverActive() = 0;
|
||||
virtual FileData* getCurrentGame() = 0;
|
||||
virtual void launchGame() = 0;
|
||||
virtual void resetCounts() = 0;
|
||||
};
|
||||
|
||||
class InfoPopup {
|
||||
|
|
Loading…
Reference in a new issue