Added following methods to osgDB::Archive in support of work by Fradley Anderegg on .zip archive support:
/** Get the file name which represents the archived file.*/ virtual std::string getArchiveFileName() const = 0; /** return type of file. */ virtual FileType getFileType(const std::string& filename) const = 0; /** return the contents of a directory. * returns an empty array on any error.*/ virtual DirectoryContents getDirectoryContents(const std::string& dirName) const = 0; Added implementations of these new methods into src/osgPlugins/osga/OSGA_Archive.h src/osgPlugins/osga/OSGA_Archive.cpp
This commit is contained in:
parent
fb09d0e553
commit
b4353c1a8e
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include <osgDB/ReaderWriter>
|
#include <osgDB/ReaderWriter>
|
||||||
#include <osgDB/Registry>
|
#include <osgDB/Registry>
|
||||||
|
#include <osgDB/FileUtils>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -39,16 +40,27 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
|||||||
/** close the archive.*/
|
/** close the archive.*/
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
|
|
||||||
/** return true if file exists in archive.*/
|
/** Get the file name which represents the archived file.*/
|
||||||
virtual bool fileExists(const std::string& filename) const = 0;
|
virtual std::string getArchiveFileName() const = 0;
|
||||||
|
|
||||||
/** Get the file name which represents the master file recorded in the Archive.*/
|
/** Get the file name which represents the master file recorded in the Archive.*/
|
||||||
virtual std::string getMasterFileName() const = 0;
|
virtual std::string getMasterFileName() const = 0;
|
||||||
|
|
||||||
typedef std::vector<std::string> 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.*/
|
/** 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 readObject(const std::string& /*fileName*/,const Options* =NULL) const = 0;
|
||||||
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const = 0;
|
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) const = 0;
|
||||||
@ -60,8 +72,6 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
|||||||
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,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;
|
virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Open an archive for reading or writing.*/
|
/** Open an archive for reading or writing.*/
|
||||||
|
@ -330,6 +330,8 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig
|
|||||||
{
|
{
|
||||||
SERIALIZER();
|
SERIALIZER();
|
||||||
|
|
||||||
|
_archiveFileName = filename;
|
||||||
|
|
||||||
if (status==READ)
|
if (status==READ)
|
||||||
{
|
{
|
||||||
_status = status;
|
_status = status;
|
||||||
@ -413,6 +415,8 @@ bool OSGA_Archive::open(std::istream& fin)
|
|||||||
{
|
{
|
||||||
SERIALIZER();
|
SERIALIZER();
|
||||||
|
|
||||||
|
_archiveFileName = "";
|
||||||
|
|
||||||
OSG_NOTICE<<"OSGA_Archive::open"<<std::endl;
|
OSG_NOTICE<<"OSGA_Archive::open"<<std::endl;
|
||||||
static_cast<std::istream&>(_input).rdbuf(fin.rdbuf());
|
static_cast<std::istream&>(_input).rdbuf(fin.rdbuf());
|
||||||
return _open(_input);
|
return _open(_input);
|
||||||
@ -499,6 +503,12 @@ std::string OSGA_Archive::getMasterFileName() const
|
|||||||
return _masterFileName;
|
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
|
bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const
|
||||||
{
|
{
|
||||||
SERIALIZER();
|
SERIALIZER();
|
||||||
@ -514,6 +524,50 @@ bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const
|
|||||||
return !fileNameList.empty();
|
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<dirName.size(); ++i)
|
||||||
|
{
|
||||||
|
char f = filename[i];
|
||||||
|
char d = dirName[i];
|
||||||
|
if (f=='\\') f='/';
|
||||||
|
if (d=='\\') d='/';
|
||||||
|
if (f!=d) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i==dirName.size())
|
||||||
|
{
|
||||||
|
// directory name matched, but need to make sure a trailing filename exists
|
||||||
|
// and to skip over any immediate slashes
|
||||||
|
char f = filename[i];
|
||||||
|
|
||||||
|
// check for slash
|
||||||
|
if (f=='\\' || f=='/')
|
||||||
|
{
|
||||||
|
// found slash, now need to skip over it.
|
||||||
|
++i;
|
||||||
|
if (i<filename.size())
|
||||||
|
{
|
||||||
|
// still have charaters left after slash which respresent the filename
|
||||||
|
files.push_back(filename.substr(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
void OSGA_Archive::writeIndexBlocks()
|
void OSGA_Archive::writeIndexBlocks()
|
||||||
{
|
{
|
||||||
|
@ -44,17 +44,26 @@ class OSGA_Archive : public osgDB::Archive
|
|||||||
/** close the archive.*/
|
/** close the archive.*/
|
||||||
virtual void close();
|
virtual void close();
|
||||||
|
|
||||||
/** return true if file exists in archive.*/
|
/** Get the file name which represents the archived file.*/
|
||||||
virtual bool fileExists(const std::string& filename) const;
|
virtual std::string getArchiveFileName() const { return _archiveFileName; }
|
||||||
|
|
||||||
/** Get the file name which represents the master file recorded in the Archive.*/
|
/** Get the file name which represents the master file recorded in the Archive.*/
|
||||||
virtual std::string getMasterFileName() const;
|
virtual std::string getMasterFileName() const;
|
||||||
|
|
||||||
typedef std::vector<std::string> 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.*/
|
/** Get the full list of file names available in the archive.*/
|
||||||
virtual bool getFileNames(FileNameList& fileNameList) const;
|
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.*/
|
/** Read an osg::Object of specified file name from the Archive.*/
|
||||||
virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL) const;
|
virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL) const;
|
||||||
@ -207,6 +216,7 @@ class OSGA_Archive : public osgDB::Archive
|
|||||||
osgDB::ifstream _input;
|
osgDB::ifstream _input;
|
||||||
osgDB::fstream _output;
|
osgDB::fstream _output;
|
||||||
|
|
||||||
|
std::string _archiveFileName;
|
||||||
std::string _masterFileName;
|
std::string _masterFileName;
|
||||||
IndexBlockList _indexBlockList;
|
IndexBlockList _indexBlockList;
|
||||||
FileNamePositionMap _indexMap;
|
FileNamePositionMap _indexMap;
|
||||||
|
Loading…
Reference in New Issue
Block a user