26 #include <boost/functional.hpp>
27 #include <boost/regex.hpp>
28 #include <boost/algorithm/string.hpp>
34 #include "vfs/raw/rawdata.h"
35 #include "util/base/exception.h"
36 #include "util/log/logger.h"
39 #include "vfssource.h"
40 #include "vfssourceprovider.h"
43 static Logger _log(LM_VFS);
53 type_sources sources = m_sources;
54 type_sources::const_iterator end = sources.end();
55 for (type_sources::iterator i = sources.begin(); i != end; ++i)
58 type_providers::const_iterator end2 = m_providers.end();
59 for (type_providers::iterator j = m_providers.begin(); j != end2; ++j)
67 m_providers.push_back(provider);
68 FL_LOG(_log,
LMsg(
"new provider: ") << provider->
getName());
72 if ( m_usedfiles.count(path) ) {
73 FL_WARN(_log,
LMsg(path) <<
" is already used as VFS source");
77 type_providers::const_iterator end = m_providers.end();
78 for (type_providers::const_iterator i = m_providers.begin(); i != end; ++i) {
85 m_usedfiles.insert(path);
88 FL_WARN(_log,
LMsg(provider->
getName()) <<
" thought it could load " << path <<
" but didn't succeed (" << ex.
what() <<
")");
91 FL_WARN(_log,
LMsg(provider->
getName()) <<
" thought it could load " << path <<
" but didn't succeed (unkown exception)");
96 FL_WARN(_log,
LMsg(
"no provider for ") << path <<
" found");
105 FL_WARN(_log,
LMsg(
"Failed to add new VFS source: ") << path);
110 m_sources.push_back(source);
114 type_sources::iterator i = std::find(m_sources.begin(), m_sources.end(), source);
115 if (i != m_sources.end())
119 VFSSource* VFS::getSourceForFile(
const std::string& file)
const {
120 type_sources::const_iterator i = std::find_if(m_sources.begin(), m_sources.end(),
122 if (i == m_sources.end()) {
123 FL_WARN(_log,
LMsg(
"no source for ") << file <<
" found");
131 return getSourceForFile(file);
135 std::vector<std::string> tokens;
137 const std::string newpath = path +
"/";
138 boost::algorithm::split(tokens, newpath, boost::algorithm::is_any_of(
"/"));
140 std::string currentpath =
"/";
141 std::vector<std::string>::const_iterator token=tokens.begin();
142 while (token != tokens.end()) {
144 if (*token !=
"." && *token !=
".." &&
listDirectories(currentpath, *token).size() == 0) {
147 currentpath += *token +
"/";
157 FL_DBG(_log,
LMsg(
"Opening: ") << path);
159 VFSSource* source = getSourceForFile(path);
161 throw NotFound(path);
163 return source->
open(path);
167 std::set<std::string> list;
168 type_sources::const_iterator end = m_sources.end();
169 for (type_sources::const_iterator i = m_sources.begin(); i != end; ++i) {
170 std::set<std::string> sourcelist = (*i)->listFiles(pathstr);
171 list.insert(sourcelist.begin(), sourcelist.end());
177 std::set<std::string>
VFS::listFiles(
const std::string& path,
const std::string& filterregex)
const {
178 std::set<std::string> list =
listFiles(path);
179 return filterList(list, filterregex);
183 std::set<std::string> list;
184 type_sources::const_iterator end = m_sources.end();
185 for (type_sources::const_iterator i = m_sources.begin(); i != end; ++i) {
186 std::set<std::string> sourcelist = (*i)->listDirectories(pathstr);
187 list.insert(sourcelist.begin(), sourcelist.end());
195 return filterList(list, filterregex);
198 std::set<std::string> VFS::filterList(
const std::set<std::string>& list,
const std::string& fregex)
const {
199 std::set<std::string> results;
200 boost::regex regex(fregex);
201 std::set<std::string>::const_iterator end = list.end();
202 for (std::set<std::string>::const_iterator i = list.begin(); i != end;) {
204 if (boost::regex_match((*i).c_str(), match, regex)) {