| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgDB/DatabaseRevisions> |
|---|
| 15 | #include <osgDB/FileUtils> |
|---|
| 16 | #include <osgDB/FileNameUtils> |
|---|
| 17 | #include <osgDB/ReadFile> |
|---|
| 18 | #include <osgDB/WriteFile> |
|---|
| 19 | |
|---|
| 20 | using namespace osgDB; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | FileList::FileList() |
|---|
| 27 | { |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | FileList::FileList(const FileList& fileList, const osg::CopyOp): |
|---|
| 31 | _files(fileList._files) |
|---|
| 32 | { |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | FileList::~FileList() |
|---|
| 36 | { |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | bool FileList::removeFile(const std::string& filename) |
|---|
| 40 | { |
|---|
| 41 | FileNames::iterator itr = _files.find(filename); |
|---|
| 42 | if (itr==_files.end()) return false; |
|---|
| 43 | |
|---|
| 44 | _files.erase(itr); |
|---|
| 45 | return true; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | void FileList::append(FileList* fileList) |
|---|
| 49 | { |
|---|
| 50 | for(FileNames::iterator itr = fileList->_files.begin(); |
|---|
| 51 | itr != fileList->_files.end(); |
|---|
| 52 | ++itr) |
|---|
| 53 | { |
|---|
| 54 | _files.insert(*itr); |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | DatabaseRevision::DatabaseRevision() |
|---|
| 64 | { |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | DatabaseRevision::DatabaseRevision(const DatabaseRevision& revision, const osg::CopyOp): |
|---|
| 68 | _databasePath(revision._databasePath), |
|---|
| 69 | _filesAdded(revision._filesAdded), |
|---|
| 70 | _filesRemoved(revision._filesRemoved), |
|---|
| 71 | _filesModified(revision._filesModified) |
|---|
| 72 | { |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | DatabaseRevision::~DatabaseRevision() |
|---|
| 76 | { |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | bool DatabaseRevision::isFileBlackListed(const std::string& filename) const |
|---|
| 80 | { |
|---|
| 81 | OSG_INFO<<"DatabaseRevision("<<getName()<<")::isFileBlackListed("<<filename<<")"<<std::endl; |
|---|
| 82 | |
|---|
| 83 | if (_databasePath.length()>=filename.length()) return false; |
|---|
| 84 | if (filename.compare(0,_databasePath.length(), _databasePath)!=0) return false; |
|---|
| 85 | |
|---|
| 86 | std::string localPath(filename, |
|---|
| 87 | _databasePath.empty() ? 0 : _databasePath.length()+1, |
|---|
| 88 | std::string::npos); |
|---|
| 89 | |
|---|
| 90 | return (_filesRemoved.valid() && _filesRemoved->containsFile(localPath)) || |
|---|
| 91 | (_filesModified.valid() && _filesModified->containsFile(localPath)); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | bool DatabaseRevision::removeFile(const std::string& filename) |
|---|
| 96 | { |
|---|
| 97 | bool removed = false; |
|---|
| 98 | if (_filesAdded.valid()) removed = _filesAdded->removeFile(filename) | removed; |
|---|
| 99 | if (_filesRemoved.valid()) removed = _filesRemoved->removeFile(filename) | removed; |
|---|
| 100 | if (_filesModified.valid()) removed = _filesModified->removeFile(filename) | removed; |
|---|
| 101 | return removed; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | DatabaseRevisions::DatabaseRevisions() |
|---|
| 109 | { |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | DatabaseRevisions::DatabaseRevisions(const DatabaseRevisions& revisions, const osg::CopyOp): |
|---|
| 113 | _databasePath(revisions._databasePath), |
|---|
| 114 | _revisionList(revisions._revisionList) |
|---|
| 115 | { |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | DatabaseRevisions::~DatabaseRevisions() |
|---|
| 119 | { |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | void DatabaseRevisions::addRevision(DatabaseRevision* revision) |
|---|
| 123 | { |
|---|
| 124 | if (!revision) return; |
|---|
| 125 | |
|---|
| 126 | for(DatabaseRevisionList::iterator itr = _revisionList.begin(); |
|---|
| 127 | itr != _revisionList.end(); |
|---|
| 128 | ++itr) |
|---|
| 129 | { |
|---|
| 130 | if (*itr == revision) return; |
|---|
| 131 | if ((*itr)->getName()==revision->getName()) |
|---|
| 132 | { |
|---|
| 133 | (*itr) = revision; |
|---|
| 134 | return; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | _revisionList.push_back(revision); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | void DatabaseRevisions::removeRevision(DatabaseRevision* revision) |
|---|
| 142 | { |
|---|
| 143 | for(DatabaseRevisionList::iterator itr = _revisionList.begin(); |
|---|
| 144 | itr != _revisionList.end(); |
|---|
| 145 | ++itr) |
|---|
| 146 | { |
|---|
| 147 | if (*itr == revision) |
|---|
| 148 | { |
|---|
| 149 | _revisionList.erase(itr); |
|---|
| 150 | return; |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | bool DatabaseRevisions::isFileBlackListed(const std::string& filename) const |
|---|
| 156 | { |
|---|
| 157 | for(DatabaseRevisionList::const_iterator itr = _revisionList.begin(); |
|---|
| 158 | itr != _revisionList.end(); |
|---|
| 159 | ++itr) |
|---|
| 160 | { |
|---|
| 161 | if ((*itr)->isFileBlackListed(filename)) |
|---|
| 162 | { |
|---|
| 163 | OSG_INFO<<"File is black listed "<<filename<<std::endl; |
|---|
| 164 | return true; |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | return false; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | bool DatabaseRevisions::removeFile(const std::string& filename) |
|---|
| 171 | { |
|---|
| 172 | OSG_INFO<<"Remove file "<<filename<<std::endl; |
|---|
| 173 | |
|---|
| 174 | bool removed = false; |
|---|
| 175 | for(DatabaseRevisionList::iterator itr = _revisionList.begin(); |
|---|
| 176 | itr != _revisionList.end(); |
|---|
| 177 | ++itr) |
|---|
| 178 | { |
|---|
| 179 | removed = (*itr)->removeFile(filename) | removed; |
|---|
| 180 | } |
|---|
| 181 | return removed; |
|---|
| 182 | } |
|---|