diff --git a/es-app/src/SystemScreenSaver.cpp b/es-app/src/SystemScreenSaver.cpp index 3fde90109..1837b94aa 100644 --- a/es-app/src/SystemScreenSaver.cpp +++ b/es-app/src/SystemScreenSaver.cpp @@ -14,10 +14,8 @@ #include "Renderer.h" #include "Sound.h" #include "SystemData.h" -#include #include #include - #define FADE_TIME 300 SystemScreenSaver::SystemScreenSaver(Window* window) : @@ -262,27 +260,21 @@ unsigned long SystemScreenSaver::countGameListNodes(const char *nodeName) std::vector::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 allFiles = rootFileData->getFilesRecursive(type, true); + std::vector::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::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 allFiles = rootFileData->getFilesRecursive(type, true); + std::vector::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& children = rootFileData->getChildrenByFilename(); - std::unordered_map::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 allFiles = rootFileData->getFilesRecursive(type); - std::vector::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; } } } diff --git a/es-app/src/SystemScreenSaver.h b/es-app/src/SystemScreenSaver.h index e96a6b01e..a26f4407e 100644 --- a/es-app/src/SystemScreenSaver.h +++ b/es-app/src/SystemScreenSaver.h @@ -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); diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index d7d0af708..2716792a0 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -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++) diff --git a/es-core/src/Window.h b/es-core/src/Window.h index 143a36cc2..738dcda98 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -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;