diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index 79cd155cd..bba7930df 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -11,7 +11,6 @@ #include "Settings.h" #include "SystemData.h" #include "ThemeData.h" -#include #include #include @@ -884,13 +883,14 @@ std::vector CollectionSystemManager::getSystemsFromTheme() if (Utils::FileSystem::exists(themePath.generic_string())) { - boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end - for (boost::filesystem::directory_iterator itr(themePath); itr != end_itr; ++itr) + Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(themePath.generic_string()); + + for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { - if (Utils::FileSystem::isDirectory(itr->path().generic_string())) + if (Utils::FileSystem::isDirectory(*it)) { //... here you have a directory - std::string folder = itr->path().string(); + std::string folder = *it; folder = folder.substr(themePath.string().size()+1); if(Utils::FileSystem::exists(set->second.getThemePath(folder).generic_string())) @@ -944,13 +944,13 @@ std::vector CollectionSystemManager::getCollectionsFromConfigFolder if (Utils::FileSystem::exists(configPath.generic_string())) { - boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end - for (boost::filesystem::directory_iterator itr(configPath); itr != end_itr; ++itr) + Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(configPath.generic_string()); + for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { - if (Utils::FileSystem::isRegularFile(itr->path().generic_string())) + if (Utils::FileSystem::isRegularFile(*it)) { // it's a file - std::string file = itr->path().string(); + std::string file = *it; std::string filename = file.substr(configPath.string().size()); // need to confirm filename matches config format @@ -1019,7 +1019,7 @@ std::string getCustomCollectionConfigPath(std::string collectionName) std::string getCollectionsFolder() { - return getHomePath() + "/.emulationstation/collections/"; + return Utils::FileSystem::getHomePath() + "/.emulationstation/collections/"; } bool systemSort(SystemData* sys1, SystemData* sys2) diff --git a/es-app/src/Gamelist.cpp b/es-app/src/Gamelist.cpp index ecbafffe0..813d93938 100644 --- a/es-app/src/Gamelist.cpp +++ b/es-app/src/Gamelist.cpp @@ -6,7 +6,6 @@ #include "Log.h" #include "Settings.h" #include "SystemData.h" -#include #include FileData* findOrCreateFile(SystemData* system, const boost::filesystem::path& path, FileType type) @@ -232,7 +231,7 @@ void updateGamelist(SystemData* system) boost::filesystem::path nodePath = Utils::FileSystem::resolveRelativePath(pathNode.text().get(), system->getStartPath(), true); boost::filesystem::path gamePath((*fit)->getPath()); - if(nodePath == gamePath || (Utils::FileSystem::exists(nodePath.generic_string()) && Utils::FileSystem::exists(gamePath.generic_string()) && boost::filesystem::equivalent(nodePath, gamePath))) + if(nodePath == gamePath || (Utils::FileSystem::exists(nodePath.generic_string()) && Utils::FileSystem::exists(gamePath.generic_string()) && Utils::FileSystem::isEquivalent(nodePath.generic_string(), gamePath.generic_string()))) { // found it root.remove_child(fileNode); diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 7115d08bc..8a48f182d 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -9,7 +9,6 @@ #include "platform.h" #include "Settings.h" #include "ThemeData.h" -#include #include #include #ifdef WIN32 @@ -95,7 +94,7 @@ void SystemData::populateFolder(FileData* folder) if(Utils::FileSystem::isSymlink(folderPath.generic_string())) { //if this symlink resolves to somewhere that's at the beginning of our path, it's gonna recurse - if(folderStr.find(boost::filesystem::canonical(folderPath).generic_string()) == 0) + if(folderStr.find(Utils::FileSystem::getCanonicalPath(folderPath.generic_string())) == 0) { LOG(LogWarning) << "Skipping infinitely recursive symlink \"" << folderPath << "\""; return; @@ -106,9 +105,10 @@ void SystemData::populateFolder(FileData* folder) std::string extension; bool isGame; bool showHidden = Settings::getInstance()->getBool("ShowHiddenFiles"); - for(boost::filesystem::directory_iterator end, dir(folderPath); dir != end; ++dir) + Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(folderPath.generic_string()); + for(Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { - filePath = (*dir).path(); + filePath = *it; if(filePath.stem().empty()) continue; @@ -268,7 +268,7 @@ bool SystemData::loadConfig() if(path[0] == '~') { path.erase(0, 1); - path.insert(0, getHomePath()); + path.insert(0, Utils::FileSystem::getHomePath()); } //create the system runtime environment data @@ -349,7 +349,7 @@ void SystemData::deleteSystems() std::string SystemData::getConfigPath(bool forWrite) { - boost::filesystem::path path = getHomePath() + "/.emulationstation/es_systems.cfg"; + boost::filesystem::path path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_systems.cfg"; if(forWrite || Utils::FileSystem::exists(path.generic_string())) return path.generic_string(); @@ -392,7 +392,7 @@ std::string SystemData::getGamelistPath(bool forWrite) const if(Utils::FileSystem::exists(filePath.generic_string())) return filePath.generic_string(); - filePath = getHomePath() + "/.emulationstation/gamelists/" + mName + "/gamelist.xml"; + filePath = Utils::FileSystem::getHomePath() + "/.emulationstation/gamelists/" + mName + "/gamelist.xml"; if(forWrite) // make sure the directory exists if we're going to write to it, or crashes will happen Utils::FileSystem::createDirectory(filePath.parent_path().generic_string()); if(forWrite || Utils::FileSystem::exists(filePath.generic_string())) diff --git a/es-app/src/SystemScreenSaver.cpp b/es-app/src/SystemScreenSaver.cpp index afe995edc..e5ee92454 100644 --- a/es-app/src/SystemScreenSaver.cpp +++ b/es-app/src/SystemScreenSaver.cpp @@ -14,7 +14,6 @@ #include "Renderer.h" #include "Sound.h" #include "SystemData.h" -#include #include #include @@ -418,46 +417,20 @@ void SystemScreenSaver::pickRandomCustomImage(std::string& path) std::string imageDir = Settings::getInstance()->getString("SlideshowScreenSaverImageDir"); if ((imageDir != "") && (Utils::FileSystem::exists(imageDir))) { - std::string imageFilter = Settings::getInstance()->getString("SlideshowScreenSaverImageFilter"); + std::string imageFilter = Settings::getInstance()->getString("SlideshowScreenSaverImageFilter"); + std::vector matchingFiles; + Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(imageDir, Settings::getInstance()->getBool("SlideshowScreenSaverRecurse")); - std::vector matchingFiles; - - if (Settings::getInstance()->getBool("SlideshowScreenSaverRecurse")) + for(Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { - boost::filesystem::recursive_directory_iterator end_iter; - boost::filesystem::recursive_directory_iterator iter(imageDir); - - // TODO: Figure out how to remove this duplication in the else block - for (iter; iter != end_iter; ++iter) + if (Utils::FileSystem::isRegularFile(*it)) { - if (Utils::FileSystem::isRegularFile(iter->path().generic_string())) + // If the image filter is empty, or the file extension is in the filter string, + // add it to the matching files list + if ((imageFilter.length() <= 0) || + (imageFilter.find(Utils::FileSystem::getExtension(*it)) != std::string::npos)) { - // If the image filter is empty, or the file extension is in the filter string, - // add it to the matching files list - if ((imageFilter.length() <= 0) || - (imageFilter.find(iter->path().extension().string()) != std::string::npos)) - { - matchingFiles.push_back(iter->path().string()); - } - } - } - } - else - { - boost::filesystem::directory_iterator end_iter; - boost::filesystem::directory_iterator iter(imageDir); - - for (iter; iter != end_iter; ++iter) - { - if (Utils::FileSystem::isRegularFile(iter->path().generic_string())) - { - // If the image filter is empty, or the file extension is in the filter string, - // add it to the matching files list - if ((imageFilter.length() <= 0) || - (imageFilter.find(iter->path().extension().string()) != std::string::npos)) - { - matchingFiles.push_back(iter->path().string()); - } + matchingFiles.push_back(*it); } } } diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 4e4bf070f..5c119dde8 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -167,7 +167,7 @@ bool parseArgs(int argc, char* argv[]) bool verifyHomeFolderExists() { //make sure the config directory exists - std::string home = getHomePath(); + std::string home = Utils::FileSystem::getHomePath(); std::string configDir = home + "/.emulationstation"; if(!Utils::FileSystem::exists(configDir)) { diff --git a/es-app/src/scrapers/Scraper.cpp b/es-app/src/scrapers/Scraper.cpp index f6d7de776..b7f16552c 100644 --- a/es-app/src/scrapers/Scraper.cpp +++ b/es-app/src/scrapers/Scraper.cpp @@ -276,7 +276,7 @@ std::string getSaveAsPath(const ScraperSearchParams& params, const std::string& const std::string subdirectory = params.system->getName(); const std::string name = params.game->getPath().stem().generic_string() + "-" + suffix; - std::string path = getHomePath() + "/.emulationstation/downloaded_images/"; + std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/downloaded_images/"; if(!Utils::FileSystem::exists(path)) Utils::FileSystem::createDirectory(path); diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index c91adbafc..08c16865c 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -432,14 +432,14 @@ void InputManager::doOnFinish() std::string InputManager::getConfigPath() { - std::string path = getHomePath(); + std::string path = Utils::FileSystem::getHomePath(); path += "/.emulationstation/es_input.cfg"; return path; } std::string InputManager::getTemporaryConfigPath() { - std::string path = getHomePath(); + std::string path = Utils::FileSystem::getHomePath(); path += "/.emulationstation/es_temporaryinput.cfg"; return path; } diff --git a/es-core/src/Log.cpp b/es-core/src/Log.cpp index 536144aa2..951286519 100644 --- a/es-core/src/Log.cpp +++ b/es-core/src/Log.cpp @@ -1,5 +1,6 @@ #include "Log.h" +#include "utils/FileSystemUtil.h" #include "platform.h" #include @@ -13,7 +14,7 @@ LogLevel Log::getReportingLevel() std::string Log::getLogPath() { - std::string home = getHomePath(); + std::string home = Utils::FileSystem::getHomePath(); return home + "/.emulationstation/es_log.txt"; } diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 62240e7f9..4c4666c6a 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -99,9 +99,9 @@ void Settings::setDefaults() mIntMap["ScreenSaverSwapImageTimeout"] = 10000; mBoolMap["SlideshowScreenSaverStretch"] = false; - mStringMap["SlideshowScreenSaverBackgroundAudioFile"] = getHomePath() + "/.emulationstation/slideshow/audio/slideshow_bg.wav"; + mStringMap["SlideshowScreenSaverBackgroundAudioFile"] = Utils::FileSystem::getHomePath() + "/.emulationstation/slideshow/audio/slideshow_bg.wav"; mBoolMap["SlideshowScreenSaverCustomImageSource"] = false; - mStringMap["SlideshowScreenSaverImageDir"] = getHomePath() + "/.emulationstation/slideshow/image"; + mStringMap["SlideshowScreenSaverImageDir"] = Utils::FileSystem::getHomePath() + "/.emulationstation/slideshow/image"; mStringMap["SlideshowScreenSaverImageFilter"] = ".png,.jpg"; mBoolMap["SlideshowScreenSaverRecurse"] = false; @@ -166,7 +166,7 @@ void saveMap(pugi::xml_document& doc, std::map& map, const char* type) void Settings::saveFile() { LOG(LogDebug) << "Settings::saveFile() : Saving Settings to file."; - const std::string path = getHomePath() + "/.emulationstation/es_settings.cfg"; + const std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_settings.cfg"; pugi::xml_document doc; @@ -187,7 +187,7 @@ void Settings::saveFile() void Settings::loadFile() { - const std::string path = getHomePath() + "/.emulationstation/es_settings.cfg"; + const std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_settings.cfg"; if(!Utils::FileSystem::exists(path)) return; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 9f55ec944..613af3d22 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -6,7 +6,6 @@ #include "Log.h" #include "platform.h" #include "Settings.h" -#include #include std::vector ThemeData::sSupportedViews { { "system" }, { "basic" }, { "detailed" }, { "video" } }; @@ -163,7 +162,7 @@ std::string resolvePath(const char* in, const boost::filesystem::path& relative) // some directories could theoretically start with ~ or . if(*path.begin() == "~") { - path = getHomePath() + (in + 1); + path = Utils::FileSystem::getHomePath() + (in + 1); }else if(*path.begin() == ".") { path = relPath / (in + 1); @@ -484,7 +483,7 @@ const std::shared_ptr& ThemeData::getDefault() { theme = std::shared_ptr(new ThemeData()); - const std::string path = getHomePath() + "/.emulationstation/es_theme_default.xml"; + const std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_theme_default.xml"; if(Utils::FileSystem::exists(path)) { try @@ -538,19 +537,19 @@ std::map ThemeData::getThemeSets() static const size_t pathCount = 2; boost::filesystem::path paths[pathCount] = { "/etc/emulationstation/themes", - getHomePath() + "/.emulationstation/themes" + Utils::FileSystem::getHomePath() + "/.emulationstation/themes" }; - boost::filesystem::directory_iterator end; - for(size_t i = 0; i < pathCount; i++) { if(!Utils::FileSystem::isDirectory(paths[i].generic_string())) continue; - for(boost::filesystem::directory_iterator it(paths[i]); it != end; ++it) + Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(paths[i].generic_string()); + + for(Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { - if(Utils::FileSystem::isDirectory((*it).path().generic_string())) + if(Utils::FileSystem::isDirectory(*it)) { ThemeSet set = {*it}; sets[set.getName()] = set; diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 41ccbdb6d..315319c65 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -16,7 +16,7 @@ std::string getTitlePath() { } std::string getTitleFolder() { - std::string home = getHomePath(); + std::string home = Utils::FileSystem::getHomePath(); return home + "/.emulationstation/tmp/"; } diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index b698765a7..0319cf88f 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -1,44 +1,13 @@ #include "platform.h" -#include #include #ifdef WIN32 #include +#else +#include #endif #include -std::string getHomePath() -{ - std::string homePath; - - // this should give you something like "/home/YOUR_USERNAME" on Linux and "C:\Users\YOUR_USERNAME\" on Windows - const char * envHome = getenv("HOME"); - if(envHome != nullptr) - { - homePath = envHome; - } - -#ifdef WIN32 - // but does not seem to work for Windows XP or Vista, so try something else - if (homePath.empty()) { - const char * envDir = getenv("HOMEDRIVE"); - const char * envPath = getenv("HOMEPATH"); - if (envDir != nullptr && envPath != nullptr) { - homePath = envDir; - homePath += envPath; - - for(unsigned int i = 0; i < homePath.length(); i++) - if(homePath[i] == '\\') - homePath[i] = '/'; - } - } -#endif - - // convert path to generic directory seperators - boost::filesystem::path genericPath(homePath); - return genericPath.generic_string(); -} - int runShutdownCommand() { #ifdef WIN32 // windows diff --git a/es-core/src/platform.h b/es-core/src/platform.h index 98826ac29..7ffaf5d31 100644 --- a/es-core/src/platform.h +++ b/es-core/src/platform.h @@ -21,9 +21,6 @@ #define GLHEADER #endif -std::string getHomePath(); - - int runShutdownCommand(); // shut down the system (returns 0 if successful) int runRestartCommand(); // restart the system (returns 0 if successful) int runSystemCommand(const std::string& cmd_utf8); // run a utf-8 encoded in the shell (requires wstring conversion on Windows) diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 15f7bf8e8..0d6ac65e5 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -22,7 +22,7 @@ namespace Utils { namespace FileSystem { - stringList getDirContent(const std::string& _path) + stringList getDirContent(const std::string& _path, const bool _recursive) { std::string path = getGenericPath(_path); stringList contentList; @@ -44,7 +44,13 @@ namespace Utils // ignore "." and ".." if((name != ".") && (name != "..")) - contentList.push_back(name); + { + std::string fullName(path + "/" + name); + contentList.push_back(fullName); + + if(_recursive && isDirectory(fullName)) + contentList.merge(getDirContent(fullName, true)); + } } while(FindNextFile(hFind, &findData)); @@ -64,7 +70,13 @@ namespace Utils // ignore "." and ".." if((name != ".") && (name != "..")) - contentList.push_back(name); + { + std::string fullName(path + "/" + name); + contentList.push_back(fullName); + + if(_recursive && isDirectory(fullName)) + contentList.merge(getDirContent(fullName, true)); + } } closedir(dir); diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index 5d4e705c6..da623f55c 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -11,7 +11,7 @@ namespace Utils { typedef std::list stringList; - stringList getDirContent (const std::string& _path); + stringList getDirContent (const std::string& _path, const bool _recursive = false); std::string getHomePath (); std::string getCWDPath (); std::string getGenericPath (const std::string& _path);