--------------------------------------------------------------------------- Code ---------------------------------------------------------------------------
| 30 | // Code |
| 31 | //--------------------------------------------------------------------------- |
| 32 | XN_C_API XnStatus xnOSGetFileList(const XnChar* cpSearchPattern, const XnChar* cpPrefixPath, XnChar cpFileList[][XN_FILE_MAX_PATH], const XnUInt32 nMaxFiles, XnUInt32* pnFoundFiles) |
| 33 | { |
| 34 | // Local function variables |
| 35 | WIN32_FIND_DATA FindFileData; |
| 36 | XN_HANDLE hFind = NULL; |
| 37 | XnUInt32 nFoundFiles = 0; |
| 38 | |
| 39 | // Validate the input/output pointers (to make sure none of them is NULL) |
| 40 | XN_VALIDATE_INPUT_PTR(cpSearchPattern); |
| 41 | XN_VALIDATE_OUTPUT_PTR(cpFileList); |
| 42 | XN_VALIDATE_OUTPUT_PTR(pnFoundFiles); |
| 43 | |
| 44 | // Reset the number of found files counter |
| 45 | *pnFoundFiles = 0; |
| 46 | |
| 47 | // Get the first file matching the search pattern |
| 48 | hFind = FindFirstFile(cpSearchPattern, &FindFileData); |
| 49 | |
| 50 | // Keep looking for files as long as we have enough space in the filelist and as long as we didnt reach the end (represented by Invalid Handle) |
| 51 | while ((hFind != INVALID_HANDLE_VALUE) && (nFoundFiles < nMaxFiles)) |
| 52 | { |
| 53 | // Copy the file string into its place in the file list |
| 54 | xnOSStrCopy(cpFileList[nFoundFiles], FindFileData.cFileName, XN_FILE_MAX_PATH); |
| 55 | |
| 56 | if (cpPrefixPath != NULL) |
| 57 | { |
| 58 | xnOSStrPrefix(cpPrefixPath, cpFileList[nFoundFiles], XN_FILE_MAX_PATH); |
| 59 | } |
| 60 | |
| 61 | // Increase the temporary number of found files counter |
| 62 | nFoundFiles++; |
| 63 | |
| 64 | // Get the next file in the list. If there are no more, FindNextFile returns FALSE and the while loop is aborted |
| 65 | if (!FindNextFile(hFind, &FindFileData)) |
| 66 | { |
| 67 | FindClose(hFind); |
| 68 | hFind = INVALID_HANDLE_VALUE; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Close the find file list |
| 73 | FindClose(hFind); |
| 74 | |
| 75 | // Return a file not found error if no files were found... |
| 76 | if (nFoundFiles == 0) |
| 77 | { |
| 78 | return (XN_STATUS_OS_FILE_NOT_FOUND); |
| 79 | } |
| 80 | |
| 81 | // Write the temporary number of found files counter into the output |
| 82 | *pnFoundFiles = nFoundFiles; |
| 83 | |
| 84 | // All is good... |
| 85 | return (XN_STATUS_OK); |
| 86 | } |
| 87 | |
| 88 | XN_C_API XnStatus xnOSOpenFile(const XnChar* cpFileName, const XnUInt32 nFlags, XN_FILE_HANDLE* pFile) |
| 89 | { |
nothing calls this directly
no test coverage detected