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."
This commit is contained in:
parent
f49c026803
commit
8e2b2031e2
@ -20,6 +20,28 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
virtual const char* className() const { return "ZIP Database Reader/Writer"; }
|
||||
|
||||
virtual ReadResult readNode(const std::string& file, const osgDB::Options* options) const
|
||||
{
|
||||
ReadResult rresult = ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
//Check to see if option is to load and extract to filesystem
|
||||
bool bExtractToFileSystem = false;
|
||||
if (options)
|
||||
{
|
||||
std::string optExtractTo = options->getPluginStringData("zipextract");
|
||||
if (!(optExtractTo.empty()))
|
||||
{
|
||||
if (osgDB::convertToLowerCase(optExtractTo)=="filesystem")
|
||||
{
|
||||
bExtractToFileSystem = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bExtractToFileSystem)
|
||||
{
|
||||
rresult = original_readNode(file,options);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(file);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
@ -29,8 +51,6 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
|
||||
osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
ReadResult rresult = ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
// First open file as stream
|
||||
std::ifstream srcFileStrm(fileName.c_str(),std::ios::in|std::ios::binary);
|
||||
if (!srcFileStrm.fail())
|
||||
@ -56,6 +76,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
// Clean up options
|
||||
local_opt->getDatabasePathList().pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
return rresult;
|
||||
}
|
||||
@ -63,7 +84,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
virtual ReadResult readNode(std::istream& fin,const osgDB::Options* options =NULL) const
|
||||
{
|
||||
ReadResult result = ReadResult(ReadResult::FILE_NOT_HANDLED);
|
||||
std::stringstream buffer;
|
||||
|
||||
|
||||
if (!fin.fail())
|
||||
{
|
||||
@ -102,6 +123,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter
|
||||
{
|
||||
GetZipItem(hz,i,&ze);
|
||||
std::string StreamName = ze.name;
|
||||
std::stringstream buffer;
|
||||
|
||||
char *ibuf = new char[ze.unc_size];
|
||||
if (ibuf)
|
||||
|
Loading…
Reference in New Issue
Block a user