MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / cf_FindRealFileNameCaseInsensitive

Function cf_FindRealFileNameCaseInsensitive

cfile/cfile.cpp:364–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364std::filesystem::path cf_FindRealFileNameCaseInsensitive(const std::filesystem::path &fname,
365 const std::filesystem::path &directory) {
366 // Dumb check, maybe there already all ok?
367 if (exists((directory / fname))) {
368 return fname.filename();
369 }
370
371 std::filesystem::path result, search_path, search_file;
372
373 search_path = directory / fname.parent_path();
374 search_file = fname.filename();
375
376 // If directory does not exist, nothing to search.
377 if (!std::filesystem::is_directory(search_path) || search_file.empty()) {
378 return {};
379 }
380
381
382 // Search component in search_path
383 auto const &it = std::filesystem::directory_iterator(search_path);
384
385 auto found = std::find_if(it, end(it), [&search_file, &search_path, &result](const auto& dir_entry) {
386 return stricmp(dir_entry.path().filename().u8string().c_str(), search_file.u8string().c_str()) == 0;
387 });
388
389 if (found != end(it)) {
390 // Match, append to result
391 result = found->path();
392 search_path = result;
393 } else {
394 // Component not found, mission failed
395 return {};
396 }
397
398 return result.filename();
399}
400
401// look for the file in the specified directory
402static CFILE *open_file_in_directory(const std::filesystem::path &filename, const char *mode,

Callers 4

cf_OpenLibraryFunction · 0.85
open_file_in_directoryFunction · 0.85
TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68