]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/packsource.cpp
Add an API to open files from a collection's sources
[libs/datafile.git] / source / packsource.cpp
index d22c7dc4235990591fffbf7c9d2dafba0eca3aaa..c8968665d41d23c936ef8efbc87fa1b5dca5bd7a 100644 (file)
@@ -38,6 +38,7 @@ void PackSource::add_pack_file(const string &fn, const string &filter)
 
        FileMap pack_files;
        pack->collect_files(pack_files, filter);
+       files.insert(pack_files.begin(), pack_files.end());
        for(FileMap::const_iterator i=pack_files.begin(); i!=pack_files.end(); ++i)
                i->second->collect_objects(objects);
 }
@@ -96,6 +97,15 @@ void PackSource::load(Collection &coll, const CollectionItemTypeBase &type, cons
                type.load_item(coll, parser, name);
 }
 
+IO::Seekable *PackSource::open(const string &fn) const
+{
+       FileMap::const_iterator i = files.find(fn);
+       if(i!=files.end())
+               return i->second->open().release();
+
+       return 0;
+}
+
 
 PackSource::Pack::Pack(const string &fn):
        filename(fn),
@@ -128,7 +138,7 @@ PackSource::File::File(const Pack &p, const string &fn):
        loaded(false)
 { }
 
-RefPtr<IO::Base> PackSource::File::open() const
+RefPtr<IO::Seekable> PackSource::File::open() const
 {
        IO::BufferedFile *io_file = new IO::BufferedFile(pack.get_filename());
        IO::Slice *io_slice = new IO::Slice(*io_file, pack.get_base_offset()+offset, length);