diff --git a/common/archive.cpp b/common/archive.cpp index 44e3e701be1..934c13551fc 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -293,4 +293,38 @@ SeekableReadStream *SearchSet::openFile(const String &name) { return 0; } + + + +DECLARE_SINGLETON(SearchManager); + +void SearchManager::addArchive(const String &name, ArchivePtr archive) { + _searchSet.add(name, archive); +} + +void SearchManager::addDirectory(const String &name, const String &directory) { + addDirectoryRecursive(name, 1); +} + +void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) { + _searchSet.add(name, SharedPtr(new FSDirectory(directory, depth))); +} + +void SearchManager::remove(const String &name) { + _searchSet.remove(name); +} + +void SearchManager::clear() { + _searchSet.clear(); +} + +bool SearchManager::hasFile(const String &name) { + return _searchSet.hasFile(name); +} + +SeekableReadStream *SearchManager::openFile(const String &name) { + return _searchSet.openFile(name); +} + + } // namespace Common diff --git a/common/archive.h b/common/archive.h index ac68a7f33d8..c418eae0635 100644 --- a/common/archive.h +++ b/common/archive.h @@ -31,6 +31,7 @@ #include "common/hash-str.h" #include "common/list.h" #include "common/ptr.h" +#include "common/singleton.h" #include "common/stream.h" namespace Common { @@ -202,6 +203,56 @@ public: virtual SeekableReadStream *openFile(const String &name); }; + + + +class SearchManager : public Singleton, public Archive { + + SearchSet _searchSet; + +public: + /** + * Add an existing Archive. This is meant to support searching in system-specific + * archives, namely the MACOSX/IPHONE bundles. + */ + void addArchive(const String &name, ArchivePtr archive); + + /** + * Create and add a FSDirectory by name + */ + void addDirectory(const String &name, const String &directory); + + /** + * Create and add a FSDirectory and its subdirectories by name + */ + void addDirectoryRecursive(const String &name, const String &directory, int depth = 4); + + /** + * Remove an archive from the pool. + */ + void remove(const String &name); + + /** + * Clears the archive + */ + void clear(); + + + virtual bool hasFile(const String &name); + virtual int getAllNames(StringList &list) { + return matchPattern(list, "*"); + } + + /** + * Implements openFile from Archive base class. The current policy is + * opening the first file encountered that matches the name. + */ + virtual SeekableReadStream *openFile(const String &name); +}; + +/** Shortcut for accessing the search manager. */ +#define SearchMan Common::SearchManager::instance() + } // namespace Common #endif