| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osg/Notify> |
|---|
| 15 | #include <osg/Endian> |
|---|
| 16 | |
|---|
| 17 | #include <osgDB/Registry> |
|---|
| 18 | #include <osgDB/FileNameUtils> |
|---|
| 19 | #include <osgDB/Archive> |
|---|
| 20 | |
|---|
| 21 | #include <streambuf> |
|---|
| 22 | |
|---|
| 23 | using namespace osgDB; |
|---|
| 24 | |
|---|
| 25 | osgDB::Archive* osgDB::openArchive(const std::string& filename, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint) |
|---|
| 26 | { |
|---|
| 27 | return openArchive(filename, status, indexBlockSizeHint, Registry::instance()->getOptions()); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | osgDB::Archive* osgDB::openArchive(const std::string& filename, ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint,Options* options) |
|---|
| 31 | { |
|---|
| 32 | |
|---|
| 33 | std::string::size_type dot = filename.find_last_of('.'); |
|---|
| 34 | if (dot != std::string::npos) |
|---|
| 35 | { |
|---|
| 36 | std::string ext = filename.substr(dot+1); |
|---|
| 37 | Registry::instance()->addArchiveExtension(ext); |
|---|
| 38 | } |
|---|
| 39 | ReaderWriter::ReadResult result = osgDB::Registry::instance()->openArchive(filename, status, indexBlockSizeHint, options); |
|---|
| 40 | return result.takeArchive(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | Archive::Archive() |
|---|
| 44 | { |
|---|
| 45 | OSG_INFO<<"Archive::Archive() open"<<std::endl; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | Archive::~Archive() |
|---|
| 49 | { |
|---|
| 50 | OSG_INFO<<"Archive::~Archive() closed"<<std::endl; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void cleanupFileString(std::string& strFileOrDir) |
|---|
| 54 | { |
|---|
| 55 | if (strFileOrDir.empty()) |
|---|
| 56 | { |
|---|
| 57 | return; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | for (unsigned int i = 0; i < strFileOrDir.length(); ++i) |
|---|
| 62 | { |
|---|
| 63 | if (strFileOrDir[i] == '\\') |
|---|
| 64 | { |
|---|
| 65 | strFileOrDir[i] = '/'; |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | if (strFileOrDir[strFileOrDir.length()-1] == '/') |
|---|
| 71 | { |
|---|
| 72 | strFileOrDir = strFileOrDir.substr(0, strFileOrDir.length()-1); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | if(strFileOrDir[0] != '/') |
|---|
| 77 | { |
|---|
| 78 | strFileOrDir.insert(0, "/"); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | osgDB::DirectoryContents osgDB::Archive::getDirectoryContents(const std::string& dirName) const |
|---|
| 83 | { |
|---|
| 84 | DirectoryContents filenames; |
|---|
| 85 | getFileNames(filenames); |
|---|
| 86 | |
|---|
| 87 | std::string searchPath = dirName; |
|---|
| 88 | cleanupFileString(searchPath); |
|---|
| 89 | |
|---|
| 90 | osgDB::DirectoryContents dirContents; |
|---|
| 91 | |
|---|
| 92 | DirectoryContents::const_iterator iter = filenames.begin(); |
|---|
| 93 | DirectoryContents::const_iterator iterEnd = filenames.end(); |
|---|
| 94 | |
|---|
| 95 | for(; iter != iterEnd; ++iter) |
|---|
| 96 | { |
|---|
| 97 | std::string currentFile = *iter; |
|---|
| 98 | |
|---|
| 99 | cleanupFileString(currentFile); |
|---|
| 100 | |
|---|
| 101 | if(currentFile.size() > searchPath.size()) |
|---|
| 102 | { |
|---|
| 103 | size_t endSubElement = currentFile.find(searchPath); |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | if(endSubElement == 0) |
|---|
| 107 | { |
|---|
| 108 | std::string remainingFile = currentFile.substr(searchPath.size() + 1, std::string::npos); |
|---|
| 109 | size_t endFileToken = remainingFile.find_first_of('/'); |
|---|
| 110 | |
|---|
| 111 | if(endFileToken == std::string::npos) |
|---|
| 112 | { |
|---|
| 113 | dirContents.push_back(remainingFile); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | return dirContents; |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | } |
|---|