From 518048bc64c6bda0aaec85daaecc46c7380bc2c6 Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Fri, 5 Jan 2018 19:57:41 +0100 Subject: [PATCH 1/2] allow read of zipped script --- src/osgPlugins/zip/ZipArchive.cpp | 37 +++++++++++++++++++++++++++++++ src/osgPlugins/zip/ZipArchive.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/src/osgPlugins/zip/ZipArchive.cpp b/src/osgPlugins/zip/ZipArchive.cpp index 4a4eead7d..9dd7b4545 100644 --- a/src/osgPlugins/zip/ZipArchive.cpp +++ b/src/osgPlugins/zip/ZipArchive.cpp @@ -310,6 +310,38 @@ osgDB::ReaderWriter::ReadResult ZipArchive::readNode(const std::string& file,con return rresult; } +osgDB::ReaderWriter::ReadResult ZipArchive::readScript(const std::string& file,const osgDB::ReaderWriter::Options* options) const{ + osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; + + std::string ext = osgDB::getLowerCaseFileExtension(file); + if (!_zipLoaded || !acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; + + const ZIPENTRY* ze = GetZipEntry(file); + if(ze != NULL) + { + std::stringstream buffer; + + osgDB::ReaderWriter* rw = ReadFromZipEntry(ze, options, buffer); + if (rw != NULL) + { + // Setup appropriate options + osg::ref_ptr local_opt = options ? + options->cloneOptions() : + new osgDB::ReaderWriter::Options; + + local_opt->setPluginStringData("STREAM_FILENAME", osgDB::getSimpleFileName(ze->name)); + + osgDB::ReaderWriter::ReadResult readResult = rw->readScript(buffer,local_opt.get()); + if (readResult.success()) + { + return readResult; + } + } + } + + return rresult; +} + osgDB::ReaderWriter::ReadResult ZipArchive::readShader(const std::string& file,const osgDB::ReaderWriter::Options* options) const @@ -350,6 +382,11 @@ osgDB::ReaderWriter::WriteResult ZipArchive::writeObject(const osg::Object& /*ob return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED); } +osgDB::ReaderWriter::WriteResult ZipArchive::writeScript(const osg::Script& /*obj*/,const std::string& /*fileName*/,const osgDB::ReaderWriter::Options*) const +{ + return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED); +} + osgDB::ReaderWriter::WriteResult ZipArchive::writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const osgDB::ReaderWriter::Options*) const { return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED); diff --git a/src/osgPlugins/zip/ZipArchive.h b/src/osgPlugins/zip/ZipArchive.h index cdaf0a633..c1d6e1e78 100644 --- a/src/osgPlugins/zip/ZipArchive.h +++ b/src/osgPlugins/zip/ZipArchive.h @@ -55,12 +55,14 @@ class ZipArchive : public osgDB::Archive virtual osgDB::ReaderWriter::ReadResult readHeightField(const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& /*fileName*/, const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::ReadResult readShader(const std::string& /*fileName*/, const osgDB::ReaderWriter::Options* =NULL) const; + virtual osgDB::ReaderWriter::ReadResult readScript(const std::string& /*fileName*/, const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::WriteResult writeObject(const osg::Object& /*obj*/, const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image& /*image*/, const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::WriteResult writeHeightField(const osg::HeightField& /*heightField*/, const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& /*node*/, const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; virtual osgDB::ReaderWriter::WriteResult writeShader(const osg::Shader& /*shader*/, const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; + virtual osgDB::ReaderWriter::WriteResult writeScript(const osg::Script& /*script*/, const std::string& /*fileName*/,const osgDB::ReaderWriter::Options* =NULL) const; protected: From 4d4b02848bcd8a34a097609fb0d04f6491c8ce11 Mon Sep 17 00:00:00 2001 From: OpenSceneGraph git repository Date: Sat, 6 Jan 2018 12:31:23 +0000 Subject: [PATCH 2/2] Had to fix spacing and bracket position yet again... --- src/osgPlugins/zip/ZipArchive.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/zip/ZipArchive.cpp b/src/osgPlugins/zip/ZipArchive.cpp index 9dd7b4545..70d15a31d 100644 --- a/src/osgPlugins/zip/ZipArchive.cpp +++ b/src/osgPlugins/zip/ZipArchive.cpp @@ -310,14 +310,16 @@ osgDB::ReaderWriter::ReadResult ZipArchive::readNode(const std::string& file,con return rresult; } -osgDB::ReaderWriter::ReadResult ZipArchive::readScript(const std::string& file,const osgDB::ReaderWriter::Options* options) const{ + +osgDB::ReaderWriter::ReadResult ZipArchive::readScript(const std::string& file,const osgDB::ReaderWriter::Options* options) const +{ osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; std::string ext = osgDB::getLowerCaseFileExtension(file); if (!_zipLoaded || !acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED; const ZIPENTRY* ze = GetZipEntry(file); - if(ze != NULL) + if (ze != NULL) { std::stringstream buffer; @@ -342,8 +344,6 @@ osgDB::ReaderWriter::ReadResult ZipArchive::readScript(const std::string& file,c return rresult; } - - osgDB::ReaderWriter::ReadResult ZipArchive::readShader(const std::string& file,const osgDB::ReaderWriter::Options* options) const { osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;