MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / RecursiveFindFiles

Function RecursiveFindFiles

common/FileSystem.cpp:1428–1570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1426}
1427
1428static u32 RecursiveFindFiles(const char* origin_path, const char* parent_path, const char* path, const char* pattern,
1429 u32 flags, FileSystem::FindResultsArray* results, std::vector<std::string>& visited, ProgressCallback* cancel)
1430{
1431 if (cancel && cancel->IsCancelled())
1432 return 0;
1433
1434 std::string search_dir;
1435 if (path)
1436 {
1437 if (parent_path)
1438 search_dir = fmt::format("{}\\{}\\{}\\*", origin_path, parent_path, path);
1439 else
1440 search_dir = fmt::format("{}\\{}\\*", origin_path, path);
1441 }
1442 else
1443 {
1444 search_dir = fmt::format("{}\\*", origin_path);
1445 }
1446
1447 // holder for utf-8 conversion
1448 WIN32_FIND_DATAW wfd;
1449 std::string utf8_filename;
1450 utf8_filename.reserve((sizeof(wfd.cFileName) / sizeof(wfd.cFileName[0])) * 2);
1451
1452 const HANDLE hFind = FindFirstFileW(FileSystem::GetWin32Path(search_dir).c_str(), &wfd);
1453 if (hFind == INVALID_HANDLE_VALUE)
1454 return 0;
1455
1456 // small speed optimization for '*' case
1457 bool hasWildCards = false;
1458 bool wildCardMatchAll = false;
1459 u32 nFiles = 0;
1460 if (std::strpbrk(pattern, "*?"))
1461 {
1462 hasWildCards = true;
1463 wildCardMatchAll = !(std::strcmp(pattern, "*"));
1464 }
1465
1466 // iterate results
1467 do
1468 {
1469 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN && !(flags & FILESYSTEM_FIND_HIDDEN_FILES))
1470 continue;
1471
1472 if (wfd.cFileName[0] == L'.')
1473 {
1474 if (wfd.cFileName[1] == L'\0' || (wfd.cFileName[1] == L'.' && wfd.cFileName[2] == L'\0'))
1475 continue;
1476 }
1477
1478 if (!StringUtil::WideStringToUTF8String(utf8_filename, wfd.cFileName))
1479 continue;
1480
1481 FILESYSTEM_FIND_DATA outData;
1482 outData.Attributes = 0;
1483
1484 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1485 {

Callers 1

FindFilesMethod · 0.85

Calls 15

FindFirstFileWFunction · 0.85
WideStringToUTF8StringFunction · 0.85
WildcardMatchFunction · 0.85
FindNextFileWFunction · 0.85
FindCloseFunction · 0.85
statClass · 0.70
formatFunction · 0.50
findFunction · 0.50
IsCancelledMethod · 0.45
reserveMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected