1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include "collection.h"
4 #include "directorysource.h"
11 void DirectorySource::add_directory(const FS::Path &d, bool replace)
13 for(const string &f: FS::list_files(d))
14 if(!objects.count(f) || replace)
18 bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string &name) const
20 return objects.count(name);
23 CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const
26 for(const auto &kvp: objects)
27 if(type.match_name(kvp.first))
28 names.push_back(kvp.first);
32 void DirectorySource::load(Collection &coll, const CollectionItemTypeBase &type, const string &name) const
35 if(lookup_file(name, file))
37 IO::BufferedFile in(file.str());
38 Parser parser(in, file.str());
39 type.load_item(coll, parser, name);
43 IO::Seekable *DirectorySource::open(const string &name) const
46 if(lookup_file(name, file))
47 return new IO::BufferedFile(file.str());
52 bool DirectorySource::lookup_file(const string &name, FS::Path &result) const
54 ObjectMap::const_iterator i = objects.find(name);
62 } // namespace DataFile