]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/packsource.cpp
Remove the loaded flag from PackSource files
[libs/datafile.git] / source / packsource.cpp
index 00af3ad129079aa71d7d415a39f16a67bf54b5b6..1accdb0fc3a384c456f4535db23e164a89efb5b7 100644 (file)
@@ -24,16 +24,38 @@ void PackSource::add_pack_file(const string &fn)
 }
 
 void PackSource::add_pack_file(const string &fn, const string &filter)
+{
+       add_pack(0, fn, filter);
+}
+
+void PackSource::add_pack_io(IO::Seekable &io, const string &fn)
+{
+       add_pack(&io, fn, string());
+}
+
+void PackSource::add_pack_io(IO::Seekable &io, const string &fn, const string &filter)
+{
+       add_pack(&io, fn, filter);
+}
+
+void PackSource::add_pack(IO::Seekable *io, const string &fn, const string &filter)
 {
        Pack *pack = 0;
        for(list<Pack>::iterator i=packs.begin(); (!pack && i!=packs.end()); ++i)
-               if(i->get_filename()==fn)
+               if(i->get_filename()==fn || (io && i->get_io()==io))
                        pack = &*i;
        if(!pack)
        {
-               packs.push_back(Pack(fn));
+               packs.push_back(Pack(io, fn));
                pack = &packs.back();
-               DataFile::load(*pack, fn);
+               if(io)
+               {
+                       DataFile::Parser parser(*io, fn);
+                       Pack::Loader loader(*pack);
+                       loader.load(parser);
+               }
+               else
+                       DataFile::load(*pack, fn);
        }
 
        FileMap pack_files;
@@ -90,9 +112,6 @@ void PackSource::load(Collection &coll, const CollectionItemTypeBase &type, cons
                return;
 
        File &file = i->second->get_file();
-       if(file.is_loaded())
-               return;
-       file.set_loaded();
 
        RefPtr<IO::Base> in = file.open();
        Parser parser(*in, file.get_full_name());
@@ -115,8 +134,9 @@ IO::Seekable *PackSource::open(const string &fn) const
 }
 
 
-PackSource::Pack::Pack(const string &fn):
+PackSource::Pack::Pack(IO::Seekable *i, const string &fn):
        filename(fn),
+       io(i),
        base_offset(0)
 { }
 
@@ -142,16 +162,21 @@ PackSource::File::File(const Pack &p, const string &fn):
        filename(fn),
        offset(0),
        length(0),
-       collection(false),
-       loaded(false)
+       collection(false)
 { }
 
 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);
-       io_slice->signal_deleted.connect(sigc::bind(sigc::ptr_fun(delete_io), io_file));
-       return io_slice;
+       if(pack.get_io())
+               // TODO Performance may be poor without buffering
+               return new IO::Slice(*pack.get_io(), pack.get_base_offset()+offset, length);
+       else
+       {
+               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);
+               io_slice->signal_deleted.connect(sigc::bind(sigc::ptr_fun(delete_io), io_file));
+               return io_slice;
+       }
 }
 
 PackSource::FileInfo PackSource::File::get_info() const
@@ -167,11 +192,6 @@ string PackSource::File::get_full_name() const
        return format("%s/%s", pack.get_filename(), filename);
 }
 
-void PackSource::File::set_loaded()
-{
-       loaded = true;
-}
-
 void PackSource::File::collect_objects(ObjectMap &objs) const
 {
        for(list<Object>::const_iterator i=objects.begin(); i!=objects.end(); ++i)