MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / DirectoryList

Method DirectoryList

Source/ResourceMan.cpp:519–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517}
518
519std::vector<std::string> cResourceMan::DirectoryList(const std::string& pPath, const std::string& pExtension) {
520 WIN32_FIND_DATA fdata;
521 HANDLE dhandle;
522 std::vector<std::string> results;
523
524 // Build the file path
525 std::stringstream finalPath;
526
527 if (pPath.size())
528 finalPath << pPath;
529
530 finalPath << "/*" << pExtension;
531
532 size_t size = MultiByteToWideChar(0, 0, finalPath.str().c_str(), (int)finalPath.str().length(), 0, 0);
533 WCHAR *pathFin = new WCHAR[size + 1];
534 memset(pathFin, 0, size + 1);
535
536 size = MultiByteToWideChar(0, 0, finalPath.str().c_str(), (int)size, pathFin, (int)size);
537 pathFin[size] = 0;
538
539 if ((dhandle = FindFirstFile(pathFin, &fdata)) == INVALID_HANDLE_VALUE) {
540 delete pathFin;
541 return results;
542 }
543
544 delete pathFin;
545 size_t tmp = 0;
546
547 {
548 char *file = new char[wcslen(fdata.cFileName) + 1];
549 memset(file, 0, wcslen(fdata.cFileName) + 1);
550
551 wcstombs_s(&tmp, file, wcslen(fdata.cFileName) + 1, fdata.cFileName, wcslen(fdata.cFileName));
552 results.push_back(std::string(file));
553 delete file;
554 }
555
556 while (1) {
557 if (FindNextFile(dhandle, &fdata)) {
558 char *file = new char[wcslen(fdata.cFileName) + 1];
559 memset(file, 0, wcslen(fdata.cFileName) + 1);
560
561 wcstombs_s(&tmp, file, wcslen(fdata.cFileName) + 1, fdata.cFileName, wcslen(fdata.cFileName));
562 results.push_back(std::string(file));
563 delete file;
564
565 }
566 else {
567 if (GetLastError() == ERROR_NO_MORE_FILES) {
568 break;
569 }
570 else {
571 FindClose(dhandle);
572 return results;
573 }
574 }
575 }
576

Callers 1

scriptsLoadFolderMethod · 0.80

Calls 4

sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected