#include #include #include #include #include #include #include #include #include #include #include #include #if defined(_WIN32) && !defined(__CYGWIN__) #include #else #include #endif using namespace osg; class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter { public: virtual const char* className() const { return "OSGTGZ Database Reader/Writer"; } virtual bool acceptsExtension(const std::string& extension) const { return osgDB::equalCaseInsensitive(extension,"osgtgz"); } virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; std::string fileName = osgDB::findDataFile( file,options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::notify(osg::INFO)<<"sgReaderWriterOSGTGZ::readNode( "< local_options = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::ReaderWriter::Options; local_options->getDatabasePathList().push_front(dirname); osgDB::DirectoryContents contents = osgDB::getDirectoryContents(dirname); for(osgDB::DirectoryContents::iterator itr = contents.begin(); itr != contents.end(); ++itr) { std::string file_ext = osgDB::getLowerCaseFileExtension(*itr); if (osgDB::equalCaseInsensitive(file_ext,"osg")) { osg::Node *node = osgDB::readNodeFile( *itr, local_options.get() ); grp->addChild( node ); } } #if defined(_WIN32) && !defined(__CYGWIN__) // note, is this the right command for windows? // is there any way of overiding the Y/N option? RO. sprintf( command, "erase %s", dirname ); system( command ); #else sprintf( command, "rm -rf %s", dirname ); system( command ); #endif if( grp->getNumChildren() == 0 ) { grp->unref(); return ReadResult::FILE_NOT_HANDLED; } return grp; } }; // now register with sgRegistry to instantiate the above // reader/writer. osgDB::RegisterReaderWriterProxy g_readerWriter_OSGTGZ_Proxy;