26 #include <boost/functional.hpp>
27 #include <boost/regex.hpp>
28 #include <boost/algorithm/string.hpp>
55 type_sources::const_iterator end = sources.end();
56 for (type_sources::iterator i = sources.begin(); i != end; ++i)
59 type_providers::const_iterator end2 =
m_providers.end();
60 for (type_providers::iterator j =
m_providers.begin(); j != end2; ++j)
78 type_providers::const_iterator end =
m_providers.end();
79 for (type_providers::const_iterator i =
m_providers.begin(); i != end; ++i) {
92 FL_WARN(
_log,
LMsg(provider->
getName()) <<
" thought it could load " << path <<
" but didn't succeed (unkown exception)");
136 std::vector<std::string> tokens;
138 const std::string newpath = path +
"/";
139 boost::algorithm::split(tokens, newpath, boost::algorithm::is_any_of(
"/"));
141 std::string currentpath =
"/";
142 std::vector<std::string>::const_iterator token=tokens.begin();
143 while (token != tokens.end()) {
145 if (*token !=
"." && *token !=
".." &&
listDirectories(currentpath, *token).size() == 0) {
148 currentpath += *token +
"/";
162 throw NotFound(path);
164 return source->
open(path);
168 std::set<std::string> list;
169 type_sources::const_iterator end =
m_sources.end();
170 for (type_sources::const_iterator i =
m_sources.begin(); i != end; ++i) {
171 std::set<std::string> sourcelist = (*i)->listFiles(pathstr);
172 list.insert(sourcelist.begin(), sourcelist.end());
178 std::set<std::string>
VFS::listFiles(
const std::string& path,
const std::string& filterregex)
const {
179 std::set<std::string> list =
listFiles(path);
184 std::set<std::string> list;
185 type_sources::const_iterator end =
m_sources.end();
186 for (type_sources::const_iterator i =
m_sources.begin(); i != end; ++i) {
187 std::set<std::string> sourcelist = (*i)->listDirectories(pathstr);
188 list.insert(sourcelist.begin(), sourcelist.end());
199 std::set<std::string>
VFS::filterList(
const std::set<std::string>& list,
const std::string& fregex)
const {
200 std::set<std::string> results;
201 boost::regex regex(fregex);
202 std::set<std::string>::const_iterator end = list.end();
203 for (std::set<std::string>::const_iterator i = list.begin(); i != end;) {
205 if (boost::regex_match((*i).c_str(), match, regex)) {
#define FL_WARN(logger, msg)
bool exists(const std::string &file) const
Check if the given file exists.
std::set< std::string > listFiles(const std::string &path) const
Get a filelist of the given directory.
void addProvider(VFSSourceProvider *provider)
add new VFSSourceProvider
virtual const char * what() const
Returns the error message.
virtual bool fileExists(const std::string &file) const =0
check if the given file exists
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
VFSSource abstract baseclass.
VFSSource * getSourceForFile(const std::string &file) const
const std::string & getName() const
Returns the name of this VFSSourceProvider.
RawData * open(const std::string &path)
Open a file.
virtual VFSSource * createSource(const std::string &file) const =0
Create a new instance of a VFSSource initialized with the given file.
static Logger _log(LM_AUDIO)
virtual bool isReadable(const std::string &file) const =0
Check if a given file is readable for this VFSSource.
type_usedfiles m_usedfiles
VFSSource * createSource(const std::string &path) const
tries to create a new VFSSource for the given file
void removeSource(VFSSource *source)
remove a VFSSource
VFSSourceProvider abstract baseclass.
std::set< std::string > filterList(const std::set< std::string > &list, const std::string &fregex) const
void addSource(VFSSource *source)
Add a new VFSSource.
virtual ~VFS()
Destructor.
bool isDirectory(const std::string &path) const
Check if the given path is a directory.
VFS()
Constructor Called by the Engine on startup.
#define FL_LOG(logger, msg)
void addNewSource(const std::string &path)
create a new Source and add it to VFS
void setVFS(VFS *vfs)
Get the VFS this provider is using.
#define FL_DBG(logger, msg)
type_providers m_providers
virtual RawData * open(const std::string &file) const =0
open a file inside this source
Used to access diffrent kinds of data.
std::vector< VFSSource * > type_sources
std::set< std::string > listDirectories(const std::string &path) const
Get a directorylist of the given directory.