/* Archive::findAll * Returns a list of entries matching the search criteria in * [options] *******************************************************************/ vector<ArchiveEntry*> Archive::findAll(search_options_t& options) { // Init search variables ArchiveTreeNode* dir = options.dir; if (!dir) dir = dir_root; vector<ArchiveEntry*> ret; options.match_name.MakeLower(); // Force case-insensitive // Begin search // Search entries for (unsigned a = 0; a < dir->numEntries(); a++) { ArchiveEntry* entry = dir->getEntry(a); // Check type if (options.match_type) { if (entry->getType() == EntryType::unknownType()) { if (!options.match_type->isThisType(entry)) continue; } else if (options.match_type != entry->getType()) continue; } // Check name if (!options.match_name.IsEmpty()) { // Cut extension if ignoring wxFileName fn(entry->getName()); if (options.ignore_ext) { if (!fn.GetName().MakeLower().Matches(options.match_name)) continue; } else if (!fn.GetFullName().MakeLower().Matches(options.match_name)) continue; } // Check namespace if (!options.match_namespace.IsEmpty()) { if (!(S_CMPNOCASE(detectNamespace(entry), options.match_namespace))) continue; } // Entry passed all checks so far, so we found a match ret.push_back(entry); } // Search subdirectories (if needed) if (options.search_subdirs) { for (unsigned a = 0; a < dir->nChildren(); a++) { search_options_t opt = options; opt.dir = (ArchiveTreeNode*)dir->getChild(a); // Add any matches to the list vector<ArchiveEntry*> vec = findAll(opt); ret.insert(ret.end(), vec.begin(), vec.end()); } } // Return matches return ret; }
/* Archive::findLast * Returns the last entry matching the search criteria in [options], * or NULL if no matching entry was found *******************************************************************/ ArchiveEntry* Archive::findLast(search_options_t& options) { // Init search variables ArchiveTreeNode* dir = options.dir; if (!dir) dir = dir_root; options.match_name.MakeLower(); // Force case-insensitive // Begin search // Search subdirectories (if needed) (bottom-up) if (options.search_subdirs) { for (int a = dir->nChildren() - 1; a >= 0; a--) { search_options_t opt = options; opt.dir = (ArchiveTreeNode*)dir->getChild(a); ArchiveEntry* match = findLast(opt); // If a match was found in this subdir, return it if (match) return match; } } // Search entries (bottom-up) for (int a = dir->numEntries() - 1; a >= 0; a--) { ArchiveEntry* entry = dir->getEntry(a); // Check type if (options.match_type) { if (entry->getType() == EntryType::unknownType()) { if (!options.match_type->isThisType(entry)) continue; } else if (options.match_type != entry->getType()) continue; } // Check name if (!options.match_name.IsEmpty()) { // Cut extension if ignoring wxFileName fn(entry->getName()); if (options.ignore_ext) { if (!options.match_name.Matches(fn.GetName().MakeLower())) continue; } else if (!options.match_name.Matches(fn.GetFullName().MakeLower())) continue; } // Check namespace if (!options.match_namespace.IsEmpty()) { if (!(S_CMPNOCASE(detectNamespace(entry), options.match_namespace))) continue; } // Entry passed all checks so far, so we found a match return entry; } // No matches found return NULL; }