* Scan for files with the given extension in the given search path. * @param extension the extension of files to search for. * @param sd the sub directory to search in. * @param tars whether to search in the tars too. * @param recursive whether to search recursively * @return the number of found files, i.e. the number of times that * AddFile returned true. */
| 1113 | * AddFile returned true. |
| 1114 | */ |
| 1115 | uint FileScanner::Scan(std::string_view extension, Subdirectory sd, bool tars, bool recursive) |
| 1116 | { |
| 1117 | this->subdir = sd; |
| 1118 | |
| 1119 | uint num = 0; |
| 1120 | |
| 1121 | for (Searchpath sp : _valid_searchpaths) { |
| 1122 | /* Don't search in the working directory */ |
| 1123 | if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue; |
| 1124 | |
| 1125 | std::string path = FioGetDirectory(sp, sd); |
| 1126 | num += ScanPath(this, extension, OTTD2FS(path), path.size(), recursive); |
| 1127 | } |
| 1128 | |
| 1129 | if (tars && sd != NO_DIRECTORY) { |
| 1130 | for (const auto &tar : _tar_filelist[sd]) { |
| 1131 | num += ScanTar(this, extension, tar); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | switch (sd) { |
| 1136 | case BASESET_DIR: |
| 1137 | num += this->Scan(extension, OLD_GM_DIR, tars, recursive); |
| 1138 | [[fallthrough]]; |
| 1139 | case NEWGRF_DIR: |
| 1140 | num += this->Scan(extension, OLD_DATA_DIR, tars, recursive); |
| 1141 | break; |
| 1142 | |
| 1143 | default: break; |
| 1144 | } |
| 1145 | |
| 1146 | return num; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Scan for files with the given extension in the given search path. |
no test coverage detected