From 4e8f0561ad7c890e27aad39ef0831a5fbaa465d2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 13 May 2010 11:01:06 +0000 Subject: [PATCH] From Farshid Lashkari, "I modified some plugins to use the osgDB file stream functions in order to support UTF-8 encoded filenames." --- src/osgPlugins/3ds/ReaderWriter3DS.cpp | 4 ++-- src/osgPlugins/bsp/Q3BSPLoad.cpp | 4 ++-- src/osgPlugins/bvh/ReaderWriterBVH.cpp | 2 +- src/osgPlugins/dot/ReaderWriterDOT.cpp | 2 +- src/osgPlugins/exr/ReaderWriterEXR.cpp | 4 ++-- src/osgPlugins/gif/ReaderWriterGIF.cpp | 2 +- src/osgPlugins/gz/ReaderWriterGZ.cpp | 4 ++-- src/osgPlugins/imageio/ReaderWriterImageIO.cpp | 4 ++-- src/osgPlugins/jpeg/ReaderWriterJPEG.cpp | 4 ++-- src/osgPlugins/mdl/MDLReader.cpp | 4 ++-- src/osgPlugins/p3d/ReaderWriterPaths.cpp | 2 +- src/osgPlugins/ply/plyfile.cpp | 5 +++-- src/osgPlugins/png/ReaderWriterPNG.cpp | 4 ++-- src/osgPlugins/quicktime/ReaderWriterQT.cpp | 4 ++-- src/osgPlugins/revisions/ReaderWriterRevisions.cpp | 2 +- src/osgPlugins/stl/ReaderWriterSTL.cpp | 4 ++-- src/osgPlugins/tiff/ReaderWriterTIFF.cpp | 4 ++-- src/osgPlugins/vrml/ReaderWriterVRML2.cpp | 2 +- src/osgPlugins/vtf/ReaderWriterVTF.cpp | 4 ++-- src/osgPlugins/zip/ReaderWriterZIP.cpp | 2 +- 20 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/osgPlugins/3ds/ReaderWriter3DS.cpp b/src/osgPlugins/3ds/ReaderWriter3DS.cpp index 138bd3cf3..5a5f7de2d 100644 --- a/src/osgPlugins/3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/3ds/ReaderWriter3DS.cpp @@ -702,7 +702,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fil // Do not use the lib3ds_file_open() as: // 1. It relies on FILE* instead of iostreams (less safe) // 2. It doesn't allow us to set a custom log output - std::ifstream fin(fileName.c_str(), std::ios_base::in | std::ios_base::binary); + osgDB::ifstream fin(fileName.c_str(), std::ios_base::in | std::ios_base::binary); if (!fin.good()) return ReadResult::ERROR_IN_READING_FILE; return doReadNode(fin, options, fileName); /* @@ -1139,7 +1139,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriter3DS::writeNode(const osg::Node& nod if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; osgDB::makeDirectoryForFile(fileName.c_str()); - std::ofstream fout(fileName.c_str(), std::ios_base::out | std::ios_base::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios_base::out | std::ios_base::binary); if (!fout.good()) return WriteResult::ERROR_IN_WRITING_FILE; return doWriteNode(node, fout, options, fileName); /* diff --git a/src/osgPlugins/bsp/Q3BSPLoad.cpp b/src/osgPlugins/bsp/Q3BSPLoad.cpp index 18850f624..b8432be1b 100644 --- a/src/osgPlugins/bsp/Q3BSPLoad.cpp +++ b/src/osgPlugins/bsp/Q3BSPLoad.cpp @@ -1,13 +1,13 @@ #include "Q3BSPLoad.h" - +#include using namespace bsp; bool Q3BSPLoad::Load(const std::string& filename, int curveTessellation) { - std::ifstream file(filename.c_str(),std::ios::binary); + osgDB::ifstream file(filename.c_str(),std::ios::binary); if(!file.is_open()) { //errorLog.OutputError("Unable to open %s", filename); diff --git a/src/osgPlugins/bvh/ReaderWriterBVH.cpp b/src/osgPlugins/bvh/ReaderWriterBVH.cpp index 2a1242714..8d76f4ffc 100644 --- a/src/osgPlugins/bvh/ReaderWriterBVH.cpp +++ b/src/osgPlugins/bvh/ReaderWriterBVH.cpp @@ -379,7 +379,7 @@ public: std::string fileName = osgDB::findDataFile( file, options ); if ( fileName.empty() ) return ReadResult::FILE_NOT_FOUND; - std::ifstream stream( fileName.c_str(), std::ios::in|std::ios::binary ); + osgDB::ifstream stream( fileName.c_str(), std::ios::in|std::ios::binary ); if( !stream ) return ReadResult::ERROR_IN_READING_FILE; return readNode( stream, options ); } diff --git a/src/osgPlugins/dot/ReaderWriterDOT.cpp b/src/osgPlugins/dot/ReaderWriterDOT.cpp index 675514b55..7e1797ab5 100644 --- a/src/osgPlugins/dot/ReaderWriterDOT.cpp +++ b/src/osgPlugins/dot/ReaderWriterDOT.cpp @@ -26,7 +26,7 @@ class ReaderWriterDOT : public osgDB::ReaderWriter { return WriteResult::FILE_NOT_HANDLED; } - std::ofstream o( fileName.c_str(), std::ios_base::out ); + osgDB::ofstream o( fileName.c_str(), std::ios_base::out ); if ( o ) { return writeNode( node, o, options ); } diff --git a/src/osgPlugins/exr/ReaderWriterEXR.cpp b/src/osgPlugins/exr/ReaderWriterEXR.cpp index 6060979d0..ddd3ffa00 100644 --- a/src/osgPlugins/exr/ReaderWriterEXR.cpp +++ b/src/osgPlugins/exr/ReaderWriterEXR.cpp @@ -203,7 +203,7 @@ public: std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readEXRStream(istream); @@ -229,7 +229,7 @@ public: std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; bool success = writeEXRStream(img, fout, fileName); diff --git a/src/osgPlugins/gif/ReaderWriterGIF.cpp b/src/osgPlugins/gif/ReaderWriterGIF.cpp index 6838bf3b5..877157ccd 100644 --- a/src/osgPlugins/gif/ReaderWriterGIF.cpp +++ b/src/osgPlugins/gif/ReaderWriterGIF.cpp @@ -642,7 +642,7 @@ class ReaderWriterGIF : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readGIFStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); diff --git a/src/osgPlugins/gz/ReaderWriterGZ.cpp b/src/osgPlugins/gz/ReaderWriterGZ.cpp index d07b9fa6f..67fabd772 100644 --- a/src/osgPlugins/gz/ReaderWriterGZ.cpp +++ b/src/osgPlugins/gz/ReaderWriterGZ.cpp @@ -173,7 +173,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterGZ::readFile(ObjectType objectType, osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); - std::ifstream fin(fileName.c_str(), std::ios::binary|std::ios::in); + osgDB::ifstream fin(fileName.c_str(), std::ios::binary|std::ios::in); if (!fin) return ReadResult::ERROR_IN_READING_FILE; @@ -227,7 +227,7 @@ osgDB::ReaderWriter::WriteResult ReaderWriterGZ::writeFile(ObjectType objectType std::stringstream strstream; osgDB::ReaderWriter::WriteResult writeResult = writeFile(objectType, object, rw, strstream, options); - std::ofstream fout(fullFileName.c_str()); + osgDB::ofstream fout(fullFileName.c_str()); write(fout,strstream.str()); diff --git a/src/osgPlugins/imageio/ReaderWriterImageIO.cpp b/src/osgPlugins/imageio/ReaderWriterImageIO.cpp index 8ba4accca..de1e80e65 100644 --- a/src/osgPlugins/imageio/ReaderWriterImageIO.cpp +++ b/src/osgPlugins/imageio/ReaderWriterImageIO.cpp @@ -1182,7 +1182,7 @@ public: #else // Only here to help test istream backend. The file version is better because // the filenname.extension could potentially be used by ImageIO to hint what the format type is. - std::ifstream istream(full_file_name.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(full_file_name.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult read_result = readImage(istream); #endif @@ -1274,7 +1274,7 @@ public: #else // Only here to help test ostream backend. The file version is better because // the filenname.extension could potentially be used by ImageIO to hint what the format type is. - std::ofstream fout(file_name.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(file_name.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(osg_image, fout, the_options); #endif diff --git a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp index 66c9122e2..29fbf819d 100644 --- a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp +++ b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp @@ -852,7 +852,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::ERROR_IN_READING_FILE; ReadResult rr = readJPGStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -872,7 +872,7 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(img,fout,options); diff --git a/src/osgPlugins/mdl/MDLReader.cpp b/src/osgPlugins/mdl/MDLReader.cpp index 46af589dd..56a184381 100644 --- a/src/osgPlugins/mdl/MDLReader.cpp +++ b/src/osgPlugins/mdl/MDLReader.cpp @@ -255,7 +255,7 @@ ref_ptr MDLReader::readMaterialFile(std::string materialName) if (!mtlPath.empty()) { // Try to open the file, bail out if we fail - mtlFile = new std::ifstream(mtlPath.c_str(), std::ifstream::in); + mtlFile = new osgDB::ifstream(mtlPath.c_str(), std::ifstream::in); if (!mtlFile) return NULL; } @@ -569,7 +569,7 @@ bool MDLReader::readFile(const std::string & file) // Try to open the file fileName = findDataFile(file, CASE_INSENSITIVE); - mdlFile = new std::ifstream(fileName.c_str(), std::ios::binary); + mdlFile = new osgDB::ifstream(fileName.c_str(), std::ios::binary); if (!mdlFile) { osg::notify(osg::NOTICE) << "MDL file not found" << std::endl; diff --git a/src/osgPlugins/p3d/ReaderWriterPaths.cpp b/src/osgPlugins/p3d/ReaderWriterPaths.cpp index 1234b2daa..056c4b3b3 100644 --- a/src/osgPlugins/p3d/ReaderWriterPaths.cpp +++ b/src/osgPlugins/p3d/ReaderWriterPaths.cpp @@ -92,7 +92,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterPaths::readObject(const std::string& osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; local_opt->setPluginStringData("filename",fileName); - std::ifstream input(fileName.c_str()); + osgDB::ifstream input(fileName.c_str()); return readObject(input, local_opt.get()); } diff --git a/src/osgPlugins/ply/plyfile.cpp b/src/osgPlugins/ply/plyfile.cpp index 979cc94fd..0d956c063 100644 --- a/src/osgPlugins/ply/plyfile.cpp +++ b/src/osgPlugins/ply/plyfile.cpp @@ -47,6 +47,7 @@ WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. #include #include +#include #if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS) #pragma warning( disable : 4996 ) @@ -314,7 +315,7 @@ PlyFile *ply_open_for_writing( /* open the file for writing */ - fp = fopen (name, "wb"); + fp = osgDB::fopen (name, "wb"); free (name); //wjs remove memory leak// if (fp == NULL) { return (NULL); @@ -945,7 +946,7 @@ PlyFile *ply_open_for_reading( /* open the file for reading */ - fp = fopen (name, "rb"); + fp = osgDB::fopen (name, "rb"); free(name); if (fp == NULL) return (NULL); diff --git a/src/osgPlugins/png/ReaderWriterPNG.cpp b/src/osgPlugins/png/ReaderWriterPNG.cpp index 53cb3b96f..5498a7c7d 100644 --- a/src/osgPlugins/png/ReaderWriterPNG.cpp +++ b/src/osgPlugins/png/ReaderWriterPNG.cpp @@ -364,7 +364,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readPNGStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -382,7 +382,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(img,fout,options); diff --git a/src/osgPlugins/quicktime/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index b3c1d9e8e..9c6bf2e72 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -342,7 +342,7 @@ public: QuicktimeImportExport importer; - std::ifstream is; + osgDB::ifstream is; is.open (fileName.c_str(), std::ios::binary | std::ios::in ); is.seekg (0, std::ios::end); long length = is.tellg(); @@ -424,7 +424,7 @@ public: if (cur == extmap.end()) return WriteResult::FILE_NOT_HANDLED; - std::ofstream os(fileName.c_str(), std::ios::binary | std::ios::trunc | std::ios::out); + osgDB::ofstream os(fileName.c_str(), std::ios::binary | std::ios::trunc | std::ios::out); if(os.good()) { QuicktimeImportExport exporter; diff --git a/src/osgPlugins/revisions/ReaderWriterRevisions.cpp b/src/osgPlugins/revisions/ReaderWriterRevisions.cpp index e925a77b8..ca5174688 100644 --- a/src/osgPlugins/revisions/ReaderWriterRevisions.cpp +++ b/src/osgPlugins/revisions/ReaderWriterRevisions.cpp @@ -26,7 +26,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream fin(fileName.c_str()); + osgDB::ifstream fin(fileName.c_str()); if (ext=="revisions") return readRevisions(fin, file, options); else return readFileList(fin, file, options); diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index cd27deecb..0a46ca2c6 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -90,7 +90,7 @@ private: { osg::notify(osg::INFO) << "ReaderWriterSTL::writeNode: Files are seperated written" << std::endl; } else { - m_f = new std::ofstream(m_fout.c_str()); + m_f = new osgDB::ofstream(m_fout.c_str()); *m_f << "solid " << counter << std::endl; } }; @@ -106,7 +106,7 @@ private: if (m_options && (m_options->getOptionString() == "separateFiles")) { std::string sepFile = m_fout + i2s(counter); - m_f = new std::ofstream(sepFile.c_str()); + m_f = new osgDB::ofstream(sepFile.c_str()); *m_f << "solid " << std::endl; } diff --git a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp index cdb70225e..363a94327 100644 --- a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp +++ b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp @@ -868,7 +868,7 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary); if(!istream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readTIFStream(istream); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -886,7 +886,7 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(img,fout,options); diff --git a/src/osgPlugins/vrml/ReaderWriterVRML2.cpp b/src/osgPlugins/vrml/ReaderWriterVRML2.cpp index 8ac38793b..8f30699c2 100644 --- a/src/osgPlugins/vrml/ReaderWriterVRML2.cpp +++ b/src/osgPlugins/vrml/ReaderWriterVRML2.cpp @@ -194,7 +194,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterVRML2::readNode(const std::string& f resource_fetcher fetcher; openvrml::browser *b = new openvrml::browser(fetcher, null, null); - std::ifstream vrml_stream(fileName.c_str()); + osgDB::ifstream vrml_stream(fileName.c_str()); try { diff --git a/src/osgPlugins/vtf/ReaderWriterVTF.cpp b/src/osgPlugins/vtf/ReaderWriterVTF.cpp index d123f7236..dc77f2dc6 100644 --- a/src/osgPlugins/vtf/ReaderWriterVTF.cpp +++ b/src/osgPlugins/vtf/ReaderWriterVTF.cpp @@ -742,7 +742,7 @@ public: if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - std::ifstream stream(fileName.c_str(), std::ios::in | std::ios::binary); + osgDB::ifstream stream(fileName.c_str(), std::ios::in | std::ios::binary); if(!stream) return ReadResult::FILE_NOT_HANDLED; ReadResult rr = readImage(stream, options); if(rr.validImage()) rr.getImage()->setFileName(file); @@ -784,7 +784,7 @@ public: std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - std::ofstream fout(file.c_str(), std::ios::out | std::ios::binary); + osgDB::ofstream fout(file.c_str(), std::ios::out | std::ios::binary); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeImage(image,fout,options); diff --git a/src/osgPlugins/zip/ReaderWriterZIP.cpp b/src/osgPlugins/zip/ReaderWriterZIP.cpp index a6a24ea13..e69370467 100644 --- a/src/osgPlugins/zip/ReaderWriterZIP.cpp +++ b/src/osgPlugins/zip/ReaderWriterZIP.cpp @@ -52,7 +52,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "<