diff --git a/include/osgDB/Archive b/include/osgDB/Archive index 98b8701ee..bed3bf6ad 100644 --- a/include/osgDB/Archive +++ b/include/osgDB/Archive @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -35,20 +36,31 @@ class OSGDB_EXPORT Archive : public ReaderWriter virtual const char* className() const { return "Archive"; } virtual bool acceptsExtension(const std::string& /*extension*/) const { return true; } - + /** close the archive.*/ virtual void close() = 0; - /** return true if file exists in archive.*/ - virtual bool fileExists(const std::string& filename) const = 0; - + /** Get the file name which represents the archived file.*/ + virtual std::string getArchiveFileName() const = 0; + /** Get the file name which represents the master file recorded in the Archive.*/ virtual std::string getMasterFileName() const = 0; - - typedef std::vector FileNameList; - + + /** return true if file exists in archive.*/ + virtual bool fileExists(const std::string& filename) const = 0; + + /** return type of file. */ + virtual FileType getFileType(const std::string& filename) const = 0; + + typedef osgDB::DirectoryContents FileNameList; + /** Get the full list of file names available in the archive.*/ - virtual bool getFileNames(FileNameList& fileNameList) const = 0; + virtual bool getFileNames(FileNameList& fileNames) const = 0; + + /** return the contents of a directory. + * returns an empty array on any error.*/ + virtual DirectoryContents getDirectoryContents(const std::string& dirName) const = 0; + virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) const = 0; virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const = 0; @@ -59,8 +71,6 @@ class OSGDB_EXPORT Archive : public ReaderWriter virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const = 0; - - }; diff --git a/src/osgPlugins/osga/OSGA_Archive.cpp b/src/osgPlugins/osga/OSGA_Archive.cpp index 192ca2b09..49881c48a 100644 --- a/src/osgPlugins/osga/OSGA_Archive.cpp +++ b/src/osgPlugins/osga/OSGA_Archive.cpp @@ -330,6 +330,8 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig { SERIALIZER(); + _archiveFileName = filename; + if (status==READ) { _status = status; @@ -413,6 +415,8 @@ bool OSGA_Archive::open(std::istream& fin) { SERIALIZER(); + _archiveFileName = ""; + OSG_NOTICE<<"OSGA_Archive::open"<(_input).rdbuf(fin.rdbuf()); return _open(_input); @@ -499,6 +503,12 @@ std::string OSGA_Archive::getMasterFileName() const return _masterFileName; } +osgDB::FileType OSGA_Archive::getFileType(const std::string& filename) const +{ + if (_indexMap.count(filename)!=0) return osgDB::REGULAR_FILE; + return osgDB::FILE_NOT_FOUND; +} + bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const { SERIALIZER(); @@ -514,6 +524,50 @@ bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const return !fileNameList.empty(); } +osgDB::DirectoryContents OSGA_Archive::getDirectoryContents(const std::string& dirName) const +{ + osgDB::DirectoryContents files; + for(FileNamePositionMap::const_iterator itr=_indexMap.begin(); + itr!=_indexMap.end(); + ++itr) + { + const std::string& filename = itr->first; + if (filename.size()>dirName.size()) + { + // check for match of directory name while accounting for potential + // differences in types of slashes + unsigned int i=0; + for(; i FileNameList; - + /** return true if file exists in archive.*/ + virtual bool fileExists(const std::string& filename) const; + + /** return type of file. */ + virtual osgDB::FileType getFileType(const std::string& filename) const; + /** Get the full list of file names available in the archive.*/ virtual bool getFileNames(FileNameList& fileNameList) const; + /** return the contents of a directory. + * returns an empty array on any error.*/ + virtual osgDB::DirectoryContents getDirectoryContents(const std::string& dirName) const; + + /** Read an osg::Object of specified file name from the Archive.*/ virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL) const; @@ -206,7 +215,8 @@ class OSGA_Archive : public osgDB::Archive ArchiveStatus _status; osgDB::ifstream _input; osgDB::fstream _output; - + + std::string _archiveFileName; std::string _masterFileName; IndexBlockList _indexBlockList; FileNamePositionMap _indexMap;