From Bradley Anderegg, "Ok, I am re-submitting this with the changes we discussed. That is, there is a default implementation of osgDB::Archive::getDirectoryContents() that uses getFileNames(), and the osgDB::ArchiveExtended header was removed as it is now unnecessary.

Here is a quick list of the modified files:

Archive - getDirectoryContents() no longer pure virtual
Archive.cpp - default getDirectoryContents() implementation
unzip.cpp - modified to fix a bug where the same file will not load twice in a row
ZipArchive.h / ZipArchive.cpp - extends osgDB::Archive and provides support for random access loading within a .zip file
ReaderWriterZip.cpp - modified to use the ZipArchive class"
This commit is contained in:
Robert Osfield
2011-05-25 09:04:44 +00:00
parent 51a9e63c55
commit 76b6cd6fa3
6 changed files with 206 additions and 236 deletions

View File

@@ -50,3 +50,73 @@ Archive::~Archive()
OSG_INFO<<"Archive::~Archive() closed"<<std::endl;
}
void cleanupFileString(std::string& strFileOrDir)
{
if (strFileOrDir.empty())
{
return;
}
// convert all separators to unix-style for conformity
for (unsigned int i = 0; i < strFileOrDir.length(); ++i)
{
if (strFileOrDir[i] == '\\')
{
strFileOrDir[i] = '/';
}
}
// get rid of trailing separators
if (strFileOrDir[strFileOrDir.length()-1] == '/')
{
strFileOrDir = strFileOrDir.substr(0, strFileOrDir.length()-1);
}
//add a beginning separator
if(strFileOrDir[0] != '/')
{
strFileOrDir.insert(0, "/");
}
}
osgDB::DirectoryContents osgDB::Archive::getDirectoryContents(const std::string& dirName) const
{
DirectoryContents filenames;
getFileNames(filenames);
std::string searchPath = dirName;
cleanupFileString(searchPath);
osgDB::DirectoryContents dirContents;
DirectoryContents::const_iterator iter = filenames.begin();
DirectoryContents::const_iterator iterEnd = filenames.end();
for(; iter != iterEnd; ++iter)
{
std::string currentFile = *iter;
cleanupFileString(currentFile);
if(currentFile.size() > searchPath.size())
{
size_t endSubElement = currentFile.find(searchPath);
//we match the whole string in the beginning of the path
if(endSubElement == 0)
{
std::string remainingFile = currentFile.substr(searchPath.size() + 1, std::string::npos);
size_t endFileToken = remainingFile.find_first_of('/');
if(endFileToken == std::string::npos)
{
dirContents.push_back(remainingFile);
}
}
}
}
return dirContents;
}