| 3677 | } |
| 3678 | |
| 3679 | BFP_EXPORT BfpFindFileData* BFP_CALLTYPE BfpFindFileData_FindFirstFile(const char* path, BfpFindFileFlags flags, BfpFileResult* outResult) |
| 3680 | { |
| 3681 | Beefy::String findStr = path; |
| 3682 | Beefy::String wildcard; |
| 3683 | |
| 3684 | int lastSlashPos = std::max((int)findStr.LastIndexOf('/'), (int)findStr.LastIndexOf('\\')); |
| 3685 | if (lastSlashPos != -1) |
| 3686 | { |
| 3687 | wildcard = findStr.Substring(lastSlashPos + 1); |
| 3688 | findStr = findStr.Substring(0, lastSlashPos + 1); |
| 3689 | findStr.Append("*"); |
| 3690 | } |
| 3691 | if (wildcard == "*.*") |
| 3692 | wildcard = "*"; |
| 3693 | |
| 3694 | BfpFindFileData* findData = new BfpFindFileData(); |
| 3695 | findData->mFlags = flags; |
| 3696 | findData->mWildcard = wildcard; |
| 3697 | Beefy::MakeUpper(findData->mWildcard); |
| 3698 | |
| 3699 | FINDEX_SEARCH_OPS searchOps; |
| 3700 | if ((flags & BfpFindFileFlag_Files) == 0) |
| 3701 | searchOps = FindExSearchLimitToDirectories; |
| 3702 | else |
| 3703 | searchOps = FindExSearchNameMatch; |
| 3704 | |
| 3705 | UTF16String wPath = UTF8Decode(findStr); |
| 3706 | findData->mHandle = ::FindFirstFileExW(wPath.c_str(), FindExInfoBasic, &findData->mFindData, searchOps, NULL, 0); |
| 3707 | if (findData->mHandle == INVALID_HANDLE_VALUE) |
| 3708 | { |
| 3709 | if (outResult != NULL) |
| 3710 | { |
| 3711 | switch (GetLastError()) |
| 3712 | { |
| 3713 | default: |
| 3714 | *outResult = BfpFileResult_UnknownError; |
| 3715 | break; |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | delete findData; |
| 3720 | return NULL; |
| 3721 | } |
| 3722 | |
| 3723 | if (!BfpFindFileData_CheckFilter(findData)) |
| 3724 | { |
| 3725 | if (!BfpFindFileData_FindNextFile(findData)) |
| 3726 | { |
| 3727 | ::FindClose(findData->mHandle); |
| 3728 | if (outResult != NULL) |
| 3729 | *outResult = BfpFileResult_NoResults; |
| 3730 | delete findData; |
| 3731 | return NULL; |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | OUTRESULT(BfpFileResult_Ok); |
| 3736 | return findData; |
no test coverage detected