MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ScanPath

Function ScanPath

src/fileio.cpp:1069–1089  ·  view source on GitHub ↗

* Scan a single directory (and recursively its children) and add * any graphics sets that are found. * @param fs the file scanner to add the files to * @param extension the extension of files to search for. * @param path full path we're currently at * @param basepath_length from where in the path are we 'based' on the search path * @param recursive whether

Source from the content-addressed store, hash-verified

1067 * @param recursive whether to recursively search the sub directories
1068 */
1069static uint ScanPath(FileScanner *fs, std::string_view extension, const std::filesystem::path &path, size_t basepath_length, bool recursive)
1070{
1071 uint num = 0;
1072
1073 std::error_code error_code;
1074 for (const auto &dir_entry : std::filesystem::directory_iterator(path, error_code)) {
1075 if (dir_entry.is_directory()) {
1076 if (!recursive) continue;
1077 num += ScanPath(fs, extension, dir_entry.path(), basepath_length, recursive);
1078 } else if (dir_entry.is_regular_file()) {
1079 std::string file = FS2OTTD(dir_entry.path().native());
1080 if (!MatchesExtension(extension, file)) continue;
1081 if (fs->AddFile(file, basepath_length, {})) num++;
1082 }
1083 }
1084 if (error_code) {
1085 Debug(misc, 9, "Unable to read directory {}: {}", path.string(), error_code.message());
1086 }
1087
1088 return num;
1089}
1090
1091/**
1092 * Scan the given tar and add graphics sets when it finds one.

Callers 1

ScanMethod · 0.85

Calls 5

MatchesExtensionFunction · 0.85
messageMethod · 0.80
FS2OTTDFunction · 0.70
AddFileMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected