* @brief Load all filter files matching pattern from disk into internal filter set. * @param [in] dir Directory from where filters are loaded. * @param [in] szPattern Pattern for filters to load filters, for example "*.flt". * @param [in] szExt File-extension of filter files. */
| 50 | * @param [in] szExt File-extension of filter files. |
| 51 | */ |
| 52 | void FileFilterMgr::LoadFromDirectory(const String& dir, const String& szPattern, const String& szExt) |
| 53 | { |
| 54 | try |
| 55 | { |
| 56 | DirItemArray dirs, files; |
| 57 | DirTravel::LoadAndSortFiles(dir, &dirs, &files, false); |
| 58 | Glob glb(ucr::toUTF8(szPattern)); |
| 59 | |
| 60 | for (DirItem& item: files) |
| 61 | { |
| 62 | String filename = item.filename; |
| 63 | if (!glb.match(ucr::toUTF8(filename))) |
| 64 | continue; |
| 65 | if (!szExt.empty()) |
| 66 | { |
| 67 | // caller specified a specific extension |
| 68 | // (This is really a workaround for brokenness in windows, which |
| 69 | // doesn't screen correctly on extension in pattern) |
| 70 | const String ext = filename.substr(filename.length() - szExt.length()); |
| 71 | if (strutils::compare_nocase(szExt, ext) != 0) |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | String filterpath = paths::ConcatPath(dir, filename); |
| 76 | AddFilter(filterpath); |
| 77 | } |
| 78 | } |
| 79 | catch (...) |
| 80 | { |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @brief Removes filter from filterlist. |
no test coverage detected