* Recurse the entire directory to find the newest file. * This may take a very long time so watch out for watchdog reset. * It may be best to only look at root for reasonable boot and mount times. */
| 1038 | * It may be best to only look at root for reasonable boot and mount times. |
| 1039 | */ |
| 1040 | void CardReader::diveToNewestFile(MediaFile parent, uint32_t &compareDateTime, MediaFile &outdir, char * const outname) { |
| 1041 | // Iterate the given parent dir |
| 1042 | parent.rewind(); |
| 1043 | for (dir_t p; parent.readDir(&p, longFilename) > 0;) { |
| 1044 | |
| 1045 | // If the item is a dir, recurse into it |
| 1046 | if (DIR_IS_SUBDIR(&p)) { |
| 1047 | // Get the name of the dir for opening |
| 1048 | char dirname[FILENAME_LENGTH]; |
| 1049 | createFilename(dirname, p); |
| 1050 | |
| 1051 | // Open the item in a new MediaFile |
| 1052 | MediaFile child; // child.close() in destructor |
| 1053 | if (child.open(&parent, dirname, O_READ)) |
| 1054 | diveToNewestFile(child, compareDateTime, outdir, outname); |
| 1055 | } |
| 1056 | else if (is_visible_entity(p)) { |
| 1057 | // Get the newer of the modified/created date and time |
| 1058 | const uint32_t modDateTime = uint32_t(p.lastWriteDate) << 16 | p.lastWriteTime, |
| 1059 | createDateTime = uint32_t(p.creationDate) << 16 | p.creationTime, |
| 1060 | newerDateTime = _MAX(modDateTime, createDateTime); |
| 1061 | // If a newer item is found overwrite the outdir and outname |
| 1062 | if (newerDateTime > compareDateTime) { |
| 1063 | compareDateTime = newerDateTime; |
| 1064 | outdir = parent; |
| 1065 | createFilename(outname, p); |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * Recurse the entire directory to find the newest file. |
nothing calls this directly
no test coverage detected