diff options
Diffstat (limited to 'common/archive.cpp')
-rw-r--r-- | common/archive.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/common/archive.cpp b/common/archive.cpp index 2c6e10ec01..96ecb52315 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -159,6 +159,29 @@ void FSDirectory::cacheDirectoryRecursive(FilesystemNode node, int depth, const } +int FSDirectory::matchPattern(StringList &list, const String &pattern) { + if (!_node.isDirectory()) + return 0; + + // Cache dir data + if (!_cached) { + cacheDirectoryRecursive(_node, _depth, ""); + _cached = true; + } + + // Small optimization: Ensure the StringList has to grow at most once + list.reserve(list.size() + _fileCache.size()); + + // Add all filenames from our cache + NodeCache::iterator it = _fileCache.begin(); + for ( ; it != _fileCache.end(); it++) { + if (it->_key.matchString(pattern)); + list.push_back(it->_key); + } + + return _fileCache.size(); +} + int FSDirectory::getAllNames(StringList &list) { if (!_node.isDirectory()) return 0; @@ -266,8 +289,6 @@ bool SearchSet::hasFile(const String &name) { } int SearchSet::matchPattern(StringList &list, const String &pattern) { - // Shall we short circuit out if pattern is empty? - int matches = 0; ArchiveList::iterator it = _list.begin(); @@ -278,6 +299,17 @@ int SearchSet::matchPattern(StringList &list, const String &pattern) { return matches; } +int SearchSet::getAllNames(StringList &list) { + int matches = 0; + + ArchiveList::iterator it = _list.begin(); + for ( ; it != _list.end(); it++) { + matches += (*it)._arc->getAllNames(list); + } + + return matches; +} + SeekableReadStream *SearchSet::openFile(const String &name) { if (name.empty()) { return 0; @@ -294,8 +326,6 @@ SeekableReadStream *SearchSet::openFile(const String &name) { } - - DECLARE_SINGLETON(SearchManager); void SearchManager::addArchive(const String &name, ArchivePtr archive) { |