Changeset 10281

Show
Ignore:
Timestamp:
05/28/09 14:25:35 (5 years ago)
Author:
robert
Message:

From Neil Hughes, "Two changes here...

1. I've implemented an option controlled route by which users can still access the old method of extracting the zip content to the local filesystem. This is in response to Ulrich's comments about zip files encorporating files other than those that OSG knows about, but which an application may require.

To access this the user makes the following call on their options object that they pass to the reader. Without it, the plugin will extract by default to memory.

local_opt->setPluginStrData("zipextract","filesystem");

2. The second change is that I've moved the declaration of one of the variables to within the numitems loop so that if loading of a specific file within the zip fails, subsequent files still load correctly. This was the issue that Ulrich raised."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/zip/ReaderWriterZIP.cpp

    r10239 r10281  
    2222        virtual ReadResult readNode(const std::string& file, const osgDB::Options* options) const 
    2323        { 
    24             std::string ext = osgDB::getLowerCaseFileExtension(file); 
    25             if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; 
    26  
    27             std::string fileName = osgDB::findDataFile( file, options ); 
    28             if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 
    29  
    30             osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "<<fileName.c_str()<<" )\n"; 
    31  
    3224            ReadResult rresult = ReadResult::FILE_NOT_HANDLED; 
    3325 
    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                } 
    5879            } 
    5980 
     
    6485        { 
    6586            ReadResult result = ReadResult(ReadResult::FILE_NOT_HANDLED); 
    66             std::stringstream buffer; 
     87 
    6788     
    6889            if (!fin.fail()) 
     
    103124                                GetZipItem(hz,i,&ze); 
    104125                                std::string StreamName = ze.name; 
    105      
     126                                std::stringstream buffer; 
     127 
    106128                                char *ibuf = new char[ze.unc_size]; 
    107129                                if (ibuf)