From 278bc55d62999740764273e8a12cafb827952e9d Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 17 Sep 2011 00:40:29 +0000 Subject: [PATCH] a couple more writable-vfs migrations --- panda/src/gobj/texture.cxx | 15 ++++++--------- panda/src/pnmimage/pnmImageHeader.cxx | 17 +++-------------- panda/src/putil/datagramInputFile.cxx | 1 - panda/src/putil/datagramInputFile.h | 1 - panda/src/putil/datagramOutputFile.cxx | 25 +++++++++++-------------- panda/src/putil/datagramOutputFile.h | 3 ++- 6 files changed, 22 insertions(+), 40 deletions(-) diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 3234ee8ae9..08e44f4681 100644 --- a/panda/src/gobj/texture.cxx +++ b/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; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pnmimage/pnmImageHeader.cxx b/panda/src/pnmimage/pnmImageHeader.cxx index e501d160aa..f4f002a87c 100644 --- a/panda/src/pnmimage/pnmImageHeader.cxx +++ b/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 } } diff --git a/panda/src/putil/datagramInputFile.cxx b/panda/src/putil/datagramInputFile.cxx index 5c41470a9d..4d2864e26c 100644 --- a/panda/src/putil/datagramInputFile.cxx +++ b/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); diff --git a/panda/src/putil/datagramInputFile.h b/panda/src/putil/datagramInputFile.h index b5e2b0d856..88056d996b 100644 --- a/panda/src/putil/datagramInputFile.h +++ b/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; diff --git a/panda/src/putil/datagramOutputFile.cxx b/panda/src/putil/datagramOutputFile.cxx index c44c7fde47..345f5404a5 100644 --- a/panda/src/putil/datagramOutputFile.cxx +++ b/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; diff --git a/panda/src/putil/datagramOutputFile.h b/panda/src/putil/datagramOutputFile.h index f4df769f17..7c40d2b37a 100644 --- a/panda/src/putil/datagramOutputFile.h +++ b/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;