Open a directory to read a file list. Returns true if it contains any files, false otherwise. If this returns true then the file system mutex is owned. The caller must subsequently release the mutex either by calling FindNext until it returns false, or by calling AbandonFindNext.
| 798 | // If this returns true then the file system mutex is owned. The caller must subsequently release the mutex either |
| 799 | // by calling FindNext until it returns false, or by calling AbandonFindNext. |
| 800 | bool MassStorage::FindFirst(const char *_ecv_array directory, FileInfo &file_info) noexcept |
| 801 | { |
| 802 | // Remove any trailing '/' from the directory name, it sometimes (but not always) confuses f_opendir |
| 803 | String<MaxFilenameLength> loc; |
| 804 | loc.copy(directory); |
| 805 | const size_t len = loc.strlen(); |
| 806 | if (len != 0 && (loc[len - 1] == '/' || loc[len - 1] == '\\')) |
| 807 | { |
| 808 | loc.Truncate(len - 1); |
| 809 | } |
| 810 | |
| 811 | if (!dirMutex.Take(10000)) |
| 812 | { |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | #if HAS_MASS_STORAGE |
| 817 | if (f_opendir(&findDir, loc.c_str()) == FR_OK) |
| 818 | { |
| 819 | FILINFO entry; |
| 820 | for (;;) |
| 821 | { |
| 822 | const FRESULT res = f_readdir(&findDir, &entry); |
| 823 | if (res != FR_OK || entry.fname[0] == 0) break; |
| 824 | if (!StringEqualsIgnoreCase(entry.fname, ".") && !StringEqualsIgnoreCase(entry.fname, "..")) |
| 825 | { |
| 826 | file_info.isDirectory = (entry.fattrib & AM_DIR); |
| 827 | file_info.fileName.copy(entry.fname); |
| 828 | file_info.size = entry.fsize; |
| 829 | file_info.lastModified = ConvertTimeStamp(entry.fdate, entry.ftime); |
| 830 | return true; |
| 831 | } |
| 832 | } |
| 833 | f_closedir(&findDir); |
| 834 | } |
| 835 | #elif HAS_EMBEDDED_FILES |
| 836 | if (EmbeddedFiles::FindFirst(directory, file_info)) |
| 837 | { |
| 838 | return true; |
| 839 | } |
| 840 | #endif |
| 841 | |
| 842 | dirMutex.Release(); |
| 843 | return false; |
| 844 | } |
| 845 | |
| 846 | // Find the next file in a directory. Returns true if another file has been read. |
| 847 | // If it returns false then it also releases the mutex. |
nothing calls this directly
no test coverage detected