root/OpenSceneGraph/trunk/src/osgPlugins/zip/ZipArchive.cpp @ 12597

Revision 12597, 15.6 kB (checked in by robert, 3 years ago)

Resolved warnings reported by g++ 4.6's -Wunused-but-set-variable.

Warnings were:

/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp: In member function ‘void PrimitiveShapeVisitor::createHalfSphere(unsigned int, unsigned int, float, int, float, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1409:11: warning: variable ‘nzBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osg/ShapeDrawable.cpp:1410:11: warning: variable ‘nRatioBase’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In function ‘osgUtil::Triangle_list osgUtil::fillHole(osg::Vec3Array*, std::vector<unsigned int, std::allocator<unsigned int> >)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:569:27: warning: variable ‘ptest’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp: In member function ‘bool osgUtil::DelaunayTriangulator::triangulate()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/DelaunayTriangulator.cpp:979:45: warning: variable ‘curp’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp: In member function ‘void osgUtil::RenderStage::runCameraSetUp(osg::RenderInfo?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgUtil/RenderStage.cpp:631:18: warning: variable ‘stencilAttached’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp: In member function ‘void FadeTextPolytopeData::buildPolytope()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:74:20: warning: variable ‘edge23’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/FadeText.cpp:75:20: warning: variable ‘edge30’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp: In member function ‘void osgText::Text::computeBackdropPositions(unsigned int) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgText/Text.cpp:747:10: warning: variable ‘is_valid_size’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp: In member function ‘virtual bool osgGA::NodeTrackerManipulator::performMovementLeftMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:257:21: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/NodeTrackerManipulator.cpp:259:21: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp: In member function ‘virtual bool osgGA::TerrainManipulator::performMovementMiddleMouseButton(double, double, double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:217:11: warning: variable ‘lookVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgGA/TerrainManipulator.cpp:219:11: warning: variable ‘upVector’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp: In member function ‘virtual void osgVolume::FixedFunctionTechnique::init()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgVolume/FixedFunctionTechnique.cpp:124:30: warning: variable ‘tf’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp: In member function ‘virtual void osgParticle::FluidProgram::execute(double)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgParticle/FluidProgram.cpp:38:23: warning: variable ‘velBefore’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp: In member function ‘virtual void osgShadow::ParallelSplitShadowMap::cull(osgUtil::CullVisitor?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgShadow/ParallelSplitShadowMap.cpp:593:22: warning: variable ‘bb’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp: In member function ‘virtual void osgTerrain::GeometryTechnique::generateGeometry(osgTerrain::GeometryTechnique::BufferData?&, osgTerrain::Locator*, const osg::Vec3d&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:777:12: warning: variable ‘i_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgTerrain/GeometryTechnique.cpp:778:12: warning: variable ‘j_sampleFactor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘osg::Image* ReadDDSFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:314:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ‘bool WriteDDSFile(const osg::Image*, std::ostream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/dds/ReaderWriterDDS.cpp:721:10: warning: variable ‘is3dImage’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp: In static member function ‘static bool HDRLoader::load(const char*, bool, HDRLoaderResult&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/hdr/hdrloader.cpp:101:10: warning: variable ‘cmd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp: In function ‘osg::Image* ReadVTFFile(std::istream&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/vtf/ReaderWriterVTF.cpp:360:23: warning: variable ‘base’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp: In function ‘int putdata(jas_stream_t*, jas_image_t*, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/jp2/ReaderWriterJP2.cpp:41:13: warning: variable ‘linelen’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp: In member function ‘void ConvertToInventor::processGeometry(const osg::Geometry*, ConvertToInventor::InventorState?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertToInventor.cpp:1639:10: warning: variable ‘ok’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp: In member function ‘virtual SbBool? SoVRMLImageTextureOsg::readInstance(SoInput?*, short unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/Inventor/ConvertFromInventor.cpp:1264:16: warning: variable ‘retval’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Face::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:369:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ‘virtual void flt::Mesh::readRecord(flt::RecordInputStream?&, flt::Document&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/GeometryRecords.cpp:942:19: warning: variable ‘secondaryPackedColor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp: In member function ‘virtual osgDB::ReaderWriter::ReadResult? FLTReaderWriter::readNode(std::istream&, const Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:427:40: warning: variable ‘pos’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp: In member function ‘void ive::ShapeAttributeList::write(ive::DataOutputStream?*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ive/ShapeAttributeList.cpp:31:48: warning: variable ‘it’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp: In member function ‘void ac3d::Geode::ProcessGeometry?(std::ostream&, unsigned int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:35: warning: variable ‘fRep_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:806:43: warning: variable ‘fRep_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:35: warning: variable ‘fOffset_s’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:807:46: warning: variable ‘fOffset_t’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/ac/Geode.cpp:932:38: warning: variable ‘primLength’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp: In member function ‘virtual bool trpgGeometry::Write(trpgWriteBuffer&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_geom.cpp:615:19: warning: variable ‘u’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp: In member function ‘int trpgMatTable::AddMaterial?(const trpgMaterial&, bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_material.cpp:103:10: warning: variable ‘spaceInTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp: In member function ‘virtual bool trpgr_Archive::ReadHeader?(bool)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/txp/trpage_rarchive.cpp:261:14: warning: variable ‘headerHasTexTable’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp: In member function ‘ZRESULT TUnzip::Get(int, ZIPENTRY*)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:8: warning: variable ‘hidden’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:22: warning: variable ‘system’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/unzip.cpp:4055:36: warning: variable ‘archive’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp: In member function ‘virtual bool ZipArchive::getFileNames(osgDB::Archive::FileNameList?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/zip/ZipArchive.cpp:91:37: warning: variable ‘iterEnd’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp: In member function ‘osgDB::ReaderWriter::ReadResult? ReaderWriterPVR::readPVRStream(std::istream&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/pvr/ReaderWriterPVR.cpp:155:14: warning: variable ‘hasAlpha’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* create3DSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:737:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp: In function ‘osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1130:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/View.cpp:1118:15: warning: variable ‘dx’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp: In member function ‘virtual void osgViewer::GraphicsWindowX11::checkEvents()’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgViewer/GraphicsWindowX11.cpp:1181:10: warning: variable ‘destroyWindowRequested’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp: In member function ‘bool osgProducer::CameraConfig::parseFile(const string&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/cfg/ConfigParser.cpp:2247:13: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp: In member function ‘bool osgQt::QGraphicsViewAdapter::handlePointerEvent(int, int, int)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgQt/QGraphicsViewAdapter.cpp:344:17: warning: variable ‘viewportGeometry’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Node* createDistortionSubgraph(osg::Node*, const Vec4&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:125:19: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:126:19: warning: variable ‘texcoord’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp: In function ‘osg::Geometry* createDomeDistortionMesh(const Vec3&, const Vec3&, const Vec3&, osg::ArgumentParser?&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgdistortion/osgdistortion.cpp:358:15: warning: variable ‘cursor’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgposter/osgposter.cpp:253:31: warning: variable ‘outputTiles’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgthreadedterrain/osgthreadedterrain.cpp:669:10: warning: variable ‘readParameter’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp: In member function ‘virtual void osgText::Layout::layout(osgText::TextNode?&) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgtext3D/TextNode.cpp:80:11: warning: variable ‘characterHeightScale’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgvolume/osgvolume.cpp:678:38: warning: variable ‘internalFormatMode’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool windowMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:27:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ‘bool widgetMouseOver(osgWidget::Event&)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/examples/osgwidgetcanvas/osgwidgetcanvas.cpp:35:24: warning: variable ‘xy’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp: In member function ‘osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode?*, bool, osgDB::Options*) const’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/src/osgPlugins/p3d/ReaderWriterP3D.cpp:2121:10: warning: variable ‘readSlide’ set but not used [-Wunused-but-set-variable]
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp: In function ‘int main(int, char**)’:
/home/stephan/Dev/LibSources/OpenSceneGraph-3.0.0-rc2/applications/present3D/present3D.cpp:639:10: warning: variable ‘sizesSpecified’ set but not used [-Wunused-but-set-variable]

Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2*
3* This library is open source and may be redistributed and/or modified under 
4* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5* (at your option) any later version.  The full license is in LICENSE file
6* included with this distribution, and on the openscenegraph.org website.
7*
8* This library is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11* OpenSceneGraph Public License for more details.
12*/
13
14#include "ZipArchive.h"
15
16#include <osgDB/FileUtils>
17#include <osgDB/FileNameUtils>
18#include <osgDB/ReadFile>
19#include <osgDB/Registry>
20
21#include <sys/types.h>
22#include <sys/stat.h>
23
24#include <sstream>
25#include <cstdio>
26#include "unzip.h"
27
28#if !defined(S_ISDIR)
29if defined( _S_IFDIR) && !defined( __S_IFDIR)
30#    define __S_IFDIR _S_IFDIR
31endif
32define S_ISDIR(mode)    (mode&__S_IFDIR)
33#endif
34
35#ifndef S_ISREG
36#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
37#endif
38
39
40ZipArchive::ZipArchive()
41: mZipLoaded(false)
42, mZipRecord(NULL)
43{
44}
45
46ZipArchive::~ZipArchive()
47{
48
49}
50
51/** close the archive.*/
52void ZipArchive::close()
53{
54    if(mZipLoaded)
55    {
56        CloseZip(mZipRecord);
57
58        mZipRecord = NULL;
59        mZipIndex.clear();
60    }
61}
62
63/** return true if file exists in archive.*/
64bool ZipArchive::fileExists(const std::string& filename) const
65{
66    return GetZipEntry(filename) != NULL;
67}
68
69/** Get the file name which represents the master file recorded in the Archive.*/
70std::string ZipArchive::getMasterFileName() const
71{
72    return std::string();
73}
74
75std::string ZipArchive::getArchiveFileName() const
76{
77    std::string result;
78    if(mZipLoaded)
79    {
80        result = mMainRecord.name;
81    }
82    return result;
83}
84
85/** Get the full list of file names available in the archive.*/
86bool ZipArchive::getFileNames(osgDB::Archive::FileNameList& fileNameList) const
87{
88    if(mZipLoaded)
89    {
90        ZipEntryMap::const_iterator iter = mZipIndex.begin();
91
92        for(;iter != mZipIndex.end(); ++iter)
93        {
94            fileNameList.push_back((*iter).first);
95        }
96
97        return true;
98    }
99    else
100    {
101        return false;
102    }
103}
104
105
106
107bool ZipArchive::open(const std::string& file, ArchiveStatus status, const osgDB::ReaderWriter::Options* options)
108{
109    std::string ext = osgDB::getLowerCaseFileExtension(file);
110    if (!acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
111
112    std::string fileName = osgDB::findDataFile( file, options );
113    if (fileName.empty()) return osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND;
114
115    std::string password = ReadPassword(options);
116
117    HZIP hz = OpenZip(fileName.c_str(), password.c_str());
118
119    if(hz != NULL)
120    {
121        IndexZipFiles(hz);
122        return true;
123    }
124    else
125    {
126        return false;
127    }
128}
129
130bool ZipArchive::open(std::istream& fin, const osgDB::ReaderWriter::Options* options)
131{
132    osgDB::ReaderWriter::ReadResult result = osgDB::ReaderWriter::ReadResult(osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED);
133
134    if (fin.fail()) return false;
135
136    fin.seekg(0,std::ios_base::end);
137    unsigned int ulzipFileLength = fin.tellg();
138    fin.seekg(0,std::ios_base::beg);
139
140    // Need to decouple stream content as I can't see any other way to get access to a byte array
141    // containing the content in the stream. One saving grace here is that we know that the
142    // stream has already been fully read in, hence no need to concern ourselves with asynchronous
143    // reads.
144    char * pMemBuffer = new char [ulzipFileLength];
145    if (!pMemBuffer) return false;
146
147    std::string password = ReadPassword(options);
148
149    HZIP hz = NULL;
150    fin.read(pMemBuffer, ulzipFileLength);
151
152    if ((unsigned int)fin.gcount() == ulzipFileLength)
153    {
154        hz = OpenZip(pMemBuffer, ulzipFileLength, password.c_str());
155    }
156    delete [] pMemBuffer;
157
158    if(hz != NULL)
159    {
160        IndexZipFiles(hz);
161        return true;
162    }
163    else
164    {
165        return false;
166    }
167}
168
169osgDB::ReaderWriter::ReadResult ZipArchive::readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
170{
171    osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
172
173    std::string ext = osgDB::getLowerCaseFileExtension(file);
174    if (!mZipLoaded || !acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
175
176    const ZIPENTRY* ze = GetZipEntry(file);
177    if(ze != NULL)
178    {
179        std::stringstream buffer;
180
181        osgDB::ReaderWriter* rw = ReadFromZipEntry(ze, options, buffer);
182        if (rw != NULL)
183        {
184            // Setup appropriate options
185            osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ?
186            static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) :
187            new osgDB::ReaderWriter::Options;
188
189            local_opt->setPluginStringData("STREAM_FILENAME", osgDB::getSimpleFileName(ze->name));
190
191            osgDB::ReaderWriter::ReadResult readResult = rw->readObject(buffer,local_opt.get());
192            if (readResult.success())
193            {
194                return readResult;
195            }
196        }
197    }
198
199    return rresult;
200}
201
202osgDB::ReaderWriter::ReadResult ZipArchive::readImage(const std::string& file,const osgDB::ReaderWriter::Options* options) const
203{
204    osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
205
206    std::string ext = osgDB::getLowerCaseFileExtension(file);
207    if (!mZipLoaded || !acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
208
209    const ZIPENTRY* ze = GetZipEntry(file);
210    if(ze != NULL)
211    {
212        std::stringstream buffer;
213
214        osgDB::ReaderWriter* rw = ReadFromZipEntry(ze, options, buffer);
215        if (rw != NULL)
216        {
217            // Setup appropriate options
218            osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ?
219            static_cast<osgDB::ReaderWriter::Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) :
220            new osgDB::ReaderWriter::Options;
221
222            local_opt->setPluginStringData("STREAM_FILENAME", osgDB::getSimpleFileName(ze->name));
223
224            osgDB::ReaderWriter::ReadResult readResult = rw->readImage(buffer,local_opt.get());
225            if (readResult.success())
226            {
227                return readResult;
228            }
229        }
230    }
231
232   return rresult;
233}
234
235osgDB::ReaderWriter::ReadResult ZipArchive::readHeightField(const std::string& file,const osgDB::ReaderWriter::Options* options) const
236{
237    osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
238
239    std::string ext = osgDB::getLowerCaseFileExtension(file);
240    if (!mZipLoaded || !acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
241
242    const ZIPENTRY* ze = GetZipEntry(file);
243    if(ze != NULL)
244    {
245        std::stringstream buffer;
246
247        osgDB::ReaderWriter* rw = ReadFromZipEntry(ze, options, buffer);
248        if (rw != NULL)
249        {
250            // Setup appropriate options
251            osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ?
252            options->cloneOptions() :
253            new osgDB::ReaderWriter::Options;
254
255            local_opt->setPluginStringData("STREAM_FILENAME", osgDB::getSimpleFileName(ze->name));
256
257            osgDB::ReaderWriter::ReadResult readResult = rw->readObject(buffer,local_opt.get());
258            if (readResult.success())
259            {
260                return readResult;
261            }
262        }
263    }
264
265    return rresult;
266}
267
268osgDB::ReaderWriter::ReadResult ZipArchive::readNode(const std::string& file,const osgDB::ReaderWriter::Options* options) const
269{
270    osgDB::ReaderWriter::ReadResult rresult = osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
271
272    std::string ext = osgDB::getLowerCaseFileExtension(file);
273    if (!mZipLoaded || !acceptsExtension(ext)) return osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED;
274
275    const ZIPENTRY* ze = GetZipEntry(file);
276    if(ze != NULL)
277    {
278        std::stringstream buffer;
279
280        osgDB::ReaderWriter* rw = ReadFromZipEntry(ze, options, buffer);
281        if (rw != NULL)
282        {
283            // Setup appropriate options
284            osg::ref_ptr<osgDB::ReaderWriter::Options> local_opt = options ?
285                options->cloneOptions() :
286                new osgDB::ReaderWriter::Options;
287
288            local_opt->setPluginStringData("STREAM_FILENAME", osgDB::getSimpleFileName(ze->name));
289
290            osgDB::ReaderWriter::ReadResult readResult = rw->readNode(buffer,local_opt.get());
291            if (readResult.success())
292            {
293                return readResult;
294            }
295        }
296    }
297
298    return rresult;
299}
300
301osgDB::ReaderWriter::WriteResult ZipArchive::writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const osgDB::ReaderWriter::Options*) const
302{
303    return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED);
304}
305
306osgDB::ReaderWriter::WriteResult ZipArchive::writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const osgDB::ReaderWriter::Options*) const
307{
308    return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED);
309}
310
311osgDB::ReaderWriter::WriteResult ZipArchive::writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const osgDB::ReaderWriter::Options*) const
312{
313    return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED);
314}
315
316osgDB::ReaderWriter::WriteResult ZipArchive::writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const osgDB::ReaderWriter::Options*) const
317{
318    return osgDB::ReaderWriter::WriteResult(osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED);
319}
320
321
322osgDB::ReaderWriter* ZipArchive::ReadFromZipEntry(const ZIPENTRY* ze, const osgDB::ReaderWriter::Options* options, std::stringstream& buffer) const
323{
324    if (ze != 0)
325    {
326        char* ibuf = new (std::nothrow) char[ze->unc_size];
327        if (ibuf)
328        {
329            ZRESULT result = UnzipItem(mZipRecord, ze->index, ibuf, ze->unc_size);
330            bool unzipSuccesful = CheckZipErrorCode(result);
331            if(unzipSuccesful)
332            {
333                buffer.write(ibuf,ze->unc_size);
334            }
335
336            delete[] ibuf;
337
338            std::string file_ext = osgDB::getFileExtension(ze->name);
339
340            osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(file_ext);
341            if (rw != NULL)
342            {
343                return rw;
344            }
345        }
346        else
347        {
348            //std::cout << "Error- failed to allocate enough memory to unzip file '" << ze->name << ", with size '" << ze->unc_size << std::endl;
349        }
350    }
351
352    return NULL;
353}
354
355void CleanupFileString(std::string& strFileOrDir)
356{
357    if (strFileOrDir.empty())
358    {
359        return;
360    }
361
362    // convert all separators to unix-style for conformity
363    for (unsigned int i = 0; i < strFileOrDir.length(); ++i)
364    {
365        if (strFileOrDir[i] == '\\')
366        {
367            strFileOrDir[i] = '/';
368        }
369    }
370
371    // get rid of trailing separators
372    if (strFileOrDir[strFileOrDir.length()-1] == '/')
373    {
374        strFileOrDir = strFileOrDir.substr(0, strFileOrDir.length()-1);
375    }
376
377    //add a beginning separator
378    if(strFileOrDir[0] != '/')
379    {
380        strFileOrDir.insert(0, "/");
381    }
382}
383
384void ZipArchive::IndexZipFiles(HZIP hz)
385{
386    if(hz != NULL && !mZipLoaded)
387    {
388        mZipRecord = hz;
389
390        GetZipItem(hz,-1,&mMainRecord);
391        int numitems = mMainRecord.index;
392
393        // Now loop through each file in zip
394        for (int i = 0; i < numitems; i++)
395        {
396            ZIPENTRY* ze = new ZIPENTRY();
397
398            GetZipItem(hz, i, ze);
399            std::string name = ze->name;
400
401            CleanupFileString(name);
402
403            if(!name.empty())
404            {
405            mZipIndex.insert(ZipEntryMapping(name, ze));
406            }
407
408        }
409
410        mZipLoaded = true;
411    }
412}
413
414ZIPENTRY* ZipArchive::GetZipEntry(const std::string& filename)
415{
416    ZIPENTRY* ze = NULL;
417    std::string fileToLoad = filename;
418    CleanupFileString(fileToLoad);
419
420    ZipEntryMap::iterator iter = mZipIndex.find(fileToLoad);
421    if(iter != mZipIndex.end())
422    {
423        ze = (*iter).second;
424    }
425
426    return ze;
427}
428
429const ZIPENTRY* ZipArchive::GetZipEntry(const std::string& filename) const
430{
431    ZIPENTRY* ze = NULL;
432    std::string fileToLoad = filename;
433    CleanupFileString(fileToLoad);
434
435    ZipEntryMap::const_iterator iter = mZipIndex.find(fileToLoad);
436    if(iter != mZipIndex.end())
437    {
438        ze = (*iter).second;
439    }
440
441    return ze;
442}
443
444osgDB::FileType ZipArchive::getFileType(const std::string& filename) const
445{
446    const ZIPENTRY* ze = GetZipEntry(filename);
447    if(ze != NULL)
448    {
449    #ifdef ZIP_STD
450        if (ze->attr & S_IFDIR)
451    #else
452        if (ze->attr & FILE_ATTRIBUTE_DIRECTORY)
453    #endif
454        {
455            return osgDB::DIRECTORY;
456        }
457        else
458        {
459            return osgDB::REGULAR_FILE;
460        }
461    }
462
463    return osgDB::FILE_NOT_FOUND;
464}
465
466osgDB::DirectoryContents ZipArchive::getDirectoryContents(const std::string& dirName) const
467{
468    osgDB::DirectoryContents dirContents;
469
470    ZipEntryMap::const_iterator iter = mZipIndex.begin();
471    ZipEntryMap::const_iterator iterEnd = mZipIndex.end();
472
473    for(; iter != iterEnd; ++iter)
474    {
475        std::string searchPath = dirName;
476        CleanupFileString(searchPath);
477
478        if(iter->first.size() > searchPath.size())
479        {
480            size_t endSubElement = iter->first.find(searchPath);
481
482            //we match the whole string in the beginning of the path
483            if(endSubElement == 0)
484            {
485                std::string remainingFile = iter->first.substr(searchPath.size() + 1, std::string::npos);
486                size_t endFileToken = remainingFile.find_first_of('/');
487
488                if(endFileToken == std::string::npos)
489                {
490                    dirContents.push_back(remainingFile);
491                }
492            }
493        }
494    }
495
496    return dirContents;
497}
498
499std::string ZipArchive::ReadPassword(const osgDB::ReaderWriter::Options* options) const
500{
501    //try pulling it off the options first
502    std::string password = "";
503    if(options != NULL)
504    {
505        const osgDB::AuthenticationMap* credentials = options->getAuthenticationMap();
506        if(credentials != NULL)
507        {
508            const osgDB::AuthenticationDetails* details = credentials->getAuthenticationDetails("ZipPlugin");
509            if(details != NULL)
510            {
511                password = details->password;
512            }
513        }
514    }
515
516    //if no password, try the registry
517    if(password.empty())
518    {
519        osgDB::Registry* reg = osgDB::Registry::instance();
520        if(reg != NULL)
521        {
522            const osgDB::AuthenticationMap* credentials = reg->getAuthenticationMap();
523            if(credentials != NULL)
524            {
525                const osgDB::AuthenticationDetails* details = credentials->getAuthenticationDetails("ZipPlugin");
526                if(details != NULL)
527                {
528                    password = details->password;
529                }
530            }
531        }
532    }
533
534    return password;
535}
536
537bool ZipArchive::CheckZipErrorCode(ZRESULT result) const
538{
539    if(result == ZR_OK)
540    {
541        return true;
542    }
543    else
544    {
545        unsigned buf_size  = 1025;
546        char* buf = new (std::nothrow) char[buf_size];
547        buf[buf_size - 1] = 0;
548
549        if (buf)
550        {
551            FormatZipMessage(result, buf, buf_size - 1);
552
553            //print error message
554            //sprintf(buf, "%s");
555            OSG_WARN << "Error loading zip file: " << getArchiveFileName() << ", Zip loader returned error: " << buf << "\n";
556            delete [] buf;
557        }
558
559        return false;
560    }
561}
Note: See TracBrowser for help on using the browser.