| 34 | | // First open file as stream |
| 35 | | std::ifstream srcFileStrm(fileName.c_str(),std::ios::in|std::ios::binary); |
| 36 | | if (!srcFileStrm.fail()) |
| 37 | | { |
| 38 | | // Now read entire zip file into stream buffer |
| 39 | | std::stringstream tmpStrmBuffer; |
| 40 | | srcFileStrm.seekg(0,std::ios_base::beg); |
| 41 | | tmpStrmBuffer.operator <<(srcFileStrm.rdbuf()); |
| 42 | | srcFileStrm.close(); |
| 43 | | |
| 44 | | // Setup appropriate options |
| 45 | | osg::ref_ptr<Options> local_opt = options ? |
| 46 | | static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : |
| 47 | | new Options; |
| 48 | | |
| 49 | | // minor issue associated with database path list, as in context of zip file it |
| 50 | | // doesn't make sense. Need to set to empty path for other plugins to access |
| 51 | | local_opt->getDatabasePathList().push_front(osgDB::getFilePath(file)); |
| 52 | | |
| 53 | | // Now pass through to memory zip handler |
| 54 | | rresult = readNode(tmpStrmBuffer,local_opt); |
| 55 | | |
| 56 | | // Clean up options |
| 57 | | local_opt->getDatabasePathList().pop_front(); |
| | 26 | //Check to see if option is to load and extract to filesystem |
| | 27 | bool bExtractToFileSystem = false; |
| | 28 | if (options) |
| | 29 | { |
| | 30 | std::string optExtractTo = options->getPluginStringData("zipextract"); |
| | 31 | if (!(optExtractTo.empty())) |
| | 32 | { |
| | 33 | if (osgDB::convertToLowerCase(optExtractTo)=="filesystem") |
| | 34 | { |
| | 35 | bExtractToFileSystem = true; |
| | 36 | } |
| | 37 | } |
| | 38 | } |
| | 39 | |
| | 40 | if (bExtractToFileSystem) |
| | 41 | { |
| | 42 | rresult = original_readNode(file,options); |
| | 43 | } |
| | 44 | else |
| | 45 | { |
| | 46 | std::string ext = osgDB::getLowerCaseFileExtension(file); |
| | 47 | if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; |
| | 48 | |
| | 49 | std::string fileName = osgDB::findDataFile( file, options ); |
| | 50 | if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; |
| | 51 | |
| | 52 | osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "<<fileName.c_str()<<" )\n"; |
| | 53 | |
| | 54 | // First open file as stream |
| | 55 | std::ifstream srcFileStrm(fileName.c_str(),std::ios::in|std::ios::binary); |
| | 56 | if (!srcFileStrm.fail()) |
| | 57 | { |
| | 58 | // Now read entire zip file into stream buffer |
| | 59 | std::stringstream tmpStrmBuffer; |
| | 60 | srcFileStrm.seekg(0,std::ios_base::beg); |
| | 61 | tmpStrmBuffer.operator <<(srcFileStrm.rdbuf()); |
| | 62 | srcFileStrm.close(); |
| | 63 | |
| | 64 | // Setup appropriate options |
| | 65 | osg::ref_ptr<Options> local_opt = options ? |
| | 66 | static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : |
| | 67 | new Options; |
| | 68 | |
| | 69 | // minor issue associated with database path list, as in context of zip file it |
| | 70 | // doesn't make sense. Need to set to empty path for other plugins to access |
| | 71 | local_opt->getDatabasePathList().push_front(osgDB::getFilePath(file)); |
| | 72 | |
| | 73 | // Now pass through to memory zip handler |
| | 74 | rresult = readNode(tmpStrmBuffer,local_opt); |
| | 75 | |
| | 76 | // Clean up options |
| | 77 | local_opt->getDatabasePathList().pop_front(); |
| | 78 | } |