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,77 +304,37 @@ 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);
|
||||
FileData* rootFileData = (*it)->getRootFolder();
|
||||
|
||||
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"))
|
||||
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_node node = fileNode.child(nodeName);
|
||||
if (node)
|
||||
if (index-- == 0)
|
||||
{
|
||||
// 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();
|
||||
// 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);
|
||||
|
||||
// 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*>::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)
|
||||
{
|
||||
mCurrentGame = (*itf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// end of getting FileData
|
||||
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never")
|
||||
writeSubtitle(mGameName.c_str(), mSystemName.c_str(),
|
||||
(Settings::getInstance()->getString("ScreenSaverGameInfo") == "always"));
|
||||
return;
|
||||
}
|
||||
// end of getting FileData
|
||||
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never")
|
||||
writeSubtitle(mGameName.c_str(), mSystemName.c_str(),
|
||||
(Settings::getInstance()->getString("ScreenSaverGameInfo") == "always"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -82,7 +83,7 @@ private:
|
|||
|
||||
// Returns true if at least one component on the stack is processing
|
||||
bool isProcessing();
|
||||
|
||||
|
||||
HelpComponent* mHelp;
|
||||
ImageComponent* mBackgroundOverlay;
|
||||
ScreenSaver* mScreenSaver;
|
||||
|
|
Loading…
Reference in a new issue