Browse Source

a couple more writable-vfs migrations

David Rose 14 years ago
parent
commit
278bc55d62

+ 6 - 9
panda/src/gobj/texture.cxx

@@ -3779,21 +3779,18 @@ do_store_one(PNMImage &pnmimage, int z, int n) const {
 ////////////////////////////////////////////////////////////////////
 bool Texture::
 do_write_txo_file(const Filename &fullpath) const {
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
   Filename filename = Filename::binary_filename(fullpath);
-  pofstream out;
-  if (!filename.open_write(out)) {
+  ostream *out = vfs->open_write_file(filename, true, true);
+  if (out == NULL) {
     gobj_cat.error()
       << "Unable to open " << filename << "\n";
     return false;
   }
 
-#ifdef HAVE_ZLIB
-  if (fullpath.get_extension() == "pz") {
-    OCompressStream compressor(&out, false);
-    return do_write_txo(compressor, "stream");
-  }
-#endif  // HAVE_ZLIB
-  return do_write_txo(out, fullpath);
+  bool success = do_write_txo(*out, fullpath);
+  vfs->close_write_file(out);
+  return success;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 3 - 14
panda/src/pnmimage/pnmImageHeader.cxx

@@ -285,22 +285,11 @@ make_writer(const Filename &filename, PNMFileType *type) const {
     }
 
   } else {
-    pofstream *new_ostream = new pofstream;
+    VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
     Filename actual_name = Filename::binary_filename(filename);
-    if (!actual_name.open_write(*new_ostream)) {
-      delete new_ostream;
-      
-    } else {
+    file = vfs->open_write_file(actual_name, true, true);
+    if (file != NULL) {
       owns_file = true;
-      file = new_ostream;
-
-#ifdef HAVE_ZLIB
-      if (filename.get_extension() == "pz") {
-        // The filename ends in .pz, which means to automatically
-        // compress the image file that we write.
-        file = new OCompressStream(file, true);
-      }
-#endif  // HAVE_ZLIB
     }
   }
 

+ 0 - 1
panda/src/putil/datagramInputFile.cxx

@@ -83,7 +83,6 @@ open(istream &in, const Filename &filename) {
 void DatagramInputFile::
 close() {
   _vfile.clear();
-  _in_file.close();
   if (_owns_in) {
     VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
     vfs->close_read_file(_in);

+ 0 - 1
panda/src/putil/datagramInputFile.h

@@ -56,7 +56,6 @@ private:
   bool _error;
   CPT(FileReference) _file;
   PT(VirtualFile) _vfile;
-  pifstream _in_file;
   istream *_in;
   bool _owns_in;
   Filename _filename;

+ 11 - 14
panda/src/putil/datagramOutputFile.cxx

@@ -32,19 +32,15 @@ open(const FileReference *file) {
   // DatagramOutputFiles are always binary.
   _filename.set_binary();
 
-  _out = &_out_file;
-  _owns_out = false;
-
-#ifdef HAVE_ZLIB
-  if (_filename.get_extension() == "pz") {
-    // The filename ends in .pz, which means to automatically
-    // compress the bam file that we write.
-    _out = new OCompressStream(_out, _owns_out);
-    _owns_out = true;
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+  _vfile = vfs->create_file(_filename);
+  if (_vfile == (VirtualFile *)NULL) {
+    // No such file.
+    return false;
   }
-#endif  // HAVE_ZLIB
-
-  return _filename.open_write(_out_file);
+  _out = _vfile->open_write_file(true, true);
+  _owns_out = (_out != (ostream *)NULL);
+  return _owns_out && !_out->fail();
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -79,10 +75,11 @@ open(ostream &out, const Filename &filename) {
 ////////////////////////////////////////////////////////////////////
 void DatagramOutputFile::
 close() {
+  _vfile.clear();
   if (_owns_out) {
-    delete _out;
+    VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+    vfs->close_write_file(_out);
   }
-  _out_file.close();
   _out = (ostream *)NULL;
   _owns_out = false;
 

+ 2 - 1
panda/src/putil/datagramOutputFile.h

@@ -20,6 +20,7 @@
 #include "datagramSink.h"
 #include "filename.h"
 #include "fileReference.h"
+#include "virtualFile.h"
 
 ////////////////////////////////////////////////////////////////////
 //       Class : DatagramOutputFile
@@ -54,7 +55,7 @@ private:
   bool _wrote_first_datagram;
   bool _error;
   CPT(FileReference) _file;
-  pofstream _out_file;
+  PT(VirtualFile) _vfile;
   ostream *_out;
   bool _owns_out;
   Filename _filename;