Ticket #8917: searchmanager.patch
File searchmanager.patch, 2.6 KB (added by , 16 years ago) |
---|
-
archive.cpp
293 293 return 0; 294 294 } 295 295 296 297 298 299 DECLARE_SINGLETON(SearchManager); 300 301 void SearchManager::addArchive(const String &name, ArchivePtr archive) { 302 _searchSet.add(name, archive); 303 } 304 305 void SearchManager::addDirectory(const String &name, const String &directory) { 306 addDirectoryRecursive(name, 1); 307 } 308 309 void SearchManager::addDirectoryRecursive(const String &name, const String &directory, int depth) { 310 _searchSet.add(name, SharedPtr<FSDirectory>(new FSDirectory(directory, depth))); 311 } 312 313 void SearchManager::remove(const String &name) { 314 _searchSet.remove(name); 315 } 316 317 void SearchManager::clear() { 318 _searchSet.clear(); 319 } 320 321 bool SearchManager::hasFile(const String &name) { 322 return _searchSet.hasFile(name); 323 } 324 325 SeekableReadStream *SearchManager::openFile(const String &name) { 326 return _searchSet.openFile(name); 327 } 328 329 296 330 } // namespace Common -
archive.h
31 31 #include "common/hash-str.h" 32 32 #include "common/list.h" 33 33 #include "common/ptr.h" 34 #include "common/singleton.h" 34 35 #include "common/stream.h" 35 36 36 37 namespace Common { … … 202 203 virtual SeekableReadStream *openFile(const String &name); 203 204 }; 204 205 206 207 208 209 class SearchManager : public Singleton<SearchManager>, public Archive { 210 211 SearchSet _searchSet; 212 213 public: 214 /** 215 * Add an existing Archive. This is meant to support searching in system-specific 216 * archives, namely the MACOSX/IPHONE bundles. 217 */ 218 void addArchive(const String &name, ArchivePtr archive); 219 220 /** 221 * Create and add a FSDirectory by name 222 */ 223 void addDirectory(const String &name, const String &directory); 224 225 /** 226 * Create and add a FSDirectory and its subdirectories by name 227 */ 228 void addDirectoryRecursive(const String &name, const String &directory, int depth = 4); 229 230 /** 231 * Remove an archive from the pool. 232 */ 233 void remove(const String &name); 234 235 /** 236 * Clears the archive 237 */ 238 void clear(); 239 240 241 virtual bool hasFile(const String &name); 242 virtual int getAllNames(StringList &list) { 243 return matchPattern(list, "*"); 244 } 245 246 /** 247 * Implements openFile from Archive base class. The current policy is 248 * opening the first file encountered that matches the name. 249 */ 250 virtual SeekableReadStream *openFile(const String &name); 251 }; 252 253 /** Shortcut for accessing the search manager. */ 254 #define SearchMan Common::SearchManager::instance() 255 205 256 } // namespace Common 206 257 207 258 #endif