Remove the last traces of boost::filesystem::operational, this is PR 4 of 5 in the boost::filesystem removal quest

This commit is contained in:
Tomas Jakobsson 2018-01-27 21:04:08 +01:00
parent 5e031b7961
commit 403b798572
15 changed files with 64 additions and 114 deletions

View file

@ -11,7 +11,6 @@
#include "Settings.h"
#include "SystemData.h"
#include "ThemeData.h"
#include <boost/filesystem/operations.hpp>
#include <pugixml/src/pugixml.hpp>
#include <fstream>
@ -884,13 +883,14 @@ std::vector<std::string> 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<std::string> 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)

View file

@ -6,7 +6,6 @@
#include "Log.h"
#include "Settings.h"
#include "SystemData.h"
#include <boost/filesystem/operations.hpp>
#include <pugixml/src/pugixml.hpp>
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);

View file

@ -9,7 +9,6 @@
#include "platform.h"
#include "Settings.h"
#include "ThemeData.h"
#include <boost/filesystem/operations.hpp>
#include <pugixml/src/pugixml.hpp>
#include <fstream>
#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()))

View file

@ -14,7 +14,6 @@
#include "Renderer.h"
#include "Sound.h"
#include "SystemData.h"
#include <boost/filesystem/operations.hpp>
#include <pugixml/src/pugixml.hpp>
#include <unordered_map>
@ -419,45 +418,19 @@ void SystemScreenSaver::pickRandomCustomImage(std::string& path)
if ((imageDir != "") && (Utils::FileSystem::exists(imageDir)))
{
std::string imageFilter = Settings::getInstance()->getString("SlideshowScreenSaverImageFilter");
std::vector<std::string> matchingFiles;
Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(imageDir, Settings::getInstance()->getBool("SlideshowScreenSaverRecurse"));
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(iter->path().generic_string()))
if (Utils::FileSystem::isRegularFile(*it))
{
// 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))
(imageFilter.find(Utils::FileSystem::getExtension(*it)) != 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);
}
}
}

View file

@ -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))
{

View file

@ -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);

View file

@ -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;
}

View file

@ -1,5 +1,6 @@
#include "Log.h"
#include "utils/FileSystemUtil.h"
#include "platform.h"
#include <iostream>
@ -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";
}

View file

@ -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<K, V>& 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;

View file

@ -6,7 +6,6 @@
#include "Log.h"
#include "platform.h"
#include "Settings.h"
#include <boost/filesystem/operations.hpp>
#include <pugixml/src/pugixml.hpp>
std::vector<std::string> 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>& ThemeData::getDefault()
{
theme = std::shared_ptr<ThemeData>(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<std::string, ThemeSet> 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;

View file

@ -16,7 +16,7 @@ std::string getTitlePath() {
}
std::string getTitleFolder() {
std::string home = getHomePath();
std::string home = Utils::FileSystem::getHomePath();
return home + "/.emulationstation/tmp/";
}

View file

@ -1,44 +1,13 @@
#include "platform.h"
#include <boost/filesystem/path.hpp>
#include <SDL_events.h>
#ifdef WIN32
#include <codecvt>
#else
#include <unistd.h>
#endif
#include <fcntl.h>
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

View file

@ -21,9 +21,6 @@
#define GLHEADER <SDL_opengl.h>
#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)

View file

@ -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);

View file

@ -11,7 +11,7 @@ namespace Utils
{
typedef std::list<std::string> 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);