30 #include "vfs/raw/rawdata.h"
31 #include "vfs/raw/rawdatafile.h"
32 #include "util/log/logger.h"
33 #include "util/base/exception.h"
35 #include "fife_boost_filesystem.h"
36 #include "vfsdirectory.h"
39 static Logger _log(LM_VFS);
42 FL_DBG(_log,
LMsg(
"VFSDirectory created with root path ") << m_root);
43 if(!m_root.empty() && *(m_root.end() - 1) !=
'/')
53 std::string fullFilename = m_root + name;
55 bfs::path fullPath(fullFilename);
56 std::ifstream file(fullPath.string().c_str());
69 return list(path,
false);
73 return list(path,
true);
76 std::set<std::string> VFSDirectory::list(
const std::string& path,
bool directorys)
const {
77 std::set<std::string> list;
78 std::string dir = m_root;
81 if(path[0] ==
'/' && m_root[m_root.size()-1] ==
'/') {
82 dir.append(path.substr(1));
89 bfs::path boost_path(dir);
90 if (!bfs::exists(boost_path) || !bfs::is_directory(boost_path))
93 bfs::directory_iterator end;
94 for (bfs::directory_iterator i(boost_path); i != end; ++i) {
95 if (bfs::is_directory(*i) != directorys)
99 if (!filename.empty())
101 list.insert(filename);
105 catch (
const bfs::filesystem_error& ex) {
106 throw Exception(ex.what());
VFSDirectory(VFS *vfs, const std::string &root="./")
virtual RawData * open(const std::string &filename) const
std::string GetFilenameFromDirectoryIterator(const bfs::directory_iterator &iter)
virtual bool fileExists(const std::string &filename) const
std::set< std::string > listFiles(const std::string &path) const
std::set< std::string > listDirectories(const std::string &path) const
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...