| 53 | } |
| 54 | |
| 55 | DWORD ScanDirectory( |
| 56 | LPCTSTR szDirectory, |
| 57 | DIRECTORY_CALLBACK PfnFolderCallback, |
| 58 | DIRECTORY_CALLBACK PfnFileCallback, |
| 59 | void * pvContext) |
| 60 | { |
| 61 | #ifdef CASCLIB_PLATFORM_WINDOWS |
| 62 | |
| 63 | CASC_PATH<TCHAR> SearchMask(szDirectory, _T("*"), NULL); |
| 64 | WIN32_FIND_DATA wf; |
| 65 | HANDLE hFind; |
| 66 | |
| 67 | // Prepare directory search |
| 68 | hFind = FindFirstFile(SearchMask, &wf); |
| 69 | if(hFind != INVALID_HANDLE_VALUE) |
| 70 | { |
| 71 | // Skip the first file as it's always just "." or ".." |
| 72 | while(FindNextFile(hFind, &wf)) |
| 73 | { |
| 74 | // If we found a folder, we call the directory callback |
| 75 | if(wf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 76 | { |
| 77 | if(PfnFolderCallback != NULL) |
| 78 | { |
| 79 | if(!PfnFolderCallback(wf.cFileName, pvContext)) |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | if(PfnFileCallback != NULL) |
| 86 | { |
| 87 | if(!PfnFileCallback(wf.cFileName, pvContext)) |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Close the search handle |
| 94 | FindClose(hFind); |
| 95 | return ERROR_SUCCESS; |
| 96 | } |
| 97 | |
| 98 | #else // CASCLIB_PLATFORM_WINDOWS |
| 99 | |
| 100 | struct dirent * dir_entry; |
| 101 | DIR * dir; |
| 102 | |
| 103 | // Prepare directory search |
| 104 | if((dir = opendir(szDirectory)) != NULL) |
| 105 | { |
| 106 | // Read (the next) directory entry |
| 107 | while((dir_entry = readdir(dir)) != NULL) |
| 108 | { |
| 109 | if(dir_entry->d_type == DT_DIR) |
| 110 | { |
| 111 | if(PfnFolderCallback != NULL) |
| 112 | { |
no outgoing calls
no test coverage detected