15template <
size_t max_slots>
25 for(
auto &item : table)
43 bool Fill(
const char *path,
const char *endswith =
nullptr)
51 res = f_opendir(&dir, path);
57 res = f_readdir(&dir, &fno);
60 bool valid_file_attrs = !(fno.fattrib & AM_HID)
61 && !(fno.fattrib & AM_DIR)
62 && !(fno.fattrib & AM_SYS);
64 bool valid_size = fno.fsize > 0;
66 bool valid_name =
false;
67 if(endswith !=
nullptr)
69 uint32_t suffix_len = strlen(endswith);
70 valid_name = strstr(fno.fname, endswith) !=
nullptr
71 && strlen(fno.fname) > suffix_len
79 if(valid_file_attrs && valid_size && valid_name)
82 strcpy(table[cnt].name, fno.fname);
83 table[cnt].size = fno.fsize;
91 num_files_found = cnt;
104 = f_open(&file, log_file_name, (FA_CREATE_ALWAYS | FA_WRITE));
107 if(num_files_found > 0)
109 for(
size_t i = 0; i < num_files_found; i++)
112 std::fill(line_buff, line_buff +
sizeof(line_buff), 0x00);
114 "%d:\t%s\t%d bytes\n",
119 res = f_write(&file, line_buff, strlen(line_buff), &bw);
122 return f_close(&file) == FR_OK;
128 const char *text =
"No matching files found...";
130 res = f_write(&file, text, strlen(text), &bw);
138 inline bool IsFileInSlot(
size_t idx)
const {
return table[idx].size > 0; }
141 inline size_t GetFileSize(
size_t idx)
const {
return table[idx].size; }
144 inline const char *
GetFileName(
size_t idx)
const {
return table[idx].name; }
160 load_pending_ =
false;
161 slot_for_load_save_ = -1;
165 load_pending_ =
true;
166 slot_for_load_save_ = slot;
173 save_pending_ =
false;
174 slot_for_load_save_ = -1;
178 save_pending_ =
true;
179 slot_for_load_save_ = slot;
194 if(num_files_found < 2)
197 for(
size_t i = 1; i < num_files_found; ++i)
199 FileInfo key = table[i];
201 while(j > 0 && CaseInsensitiveCmp(table[j - 1].name, key.name) > 0)
203 table[j] = table[j - 1];
213 size_t num_files_found;
220 int slot_for_load_save_;
223 static inline int CaseInsensitiveCmp(
const char *a,
const char *b)
226 unsigned char ca, cb;
229 ca =
static_cast<unsigned char>(*a);
230 cb =
static_cast<unsigned char>(*b);
231 ca =
static_cast<unsigned char>(std::tolower(ca));
232 cb =
static_cast<unsigned char>(std::tolower(cb));
234 return (ca < cb) ? -1 : 1;
240 return (*a ==
'\0') ? -1 : 1;
Definition FileTable.h:17
size_t GetFileSize(size_t idx) const
Definition FileTable.h:141
void SetSavePending(int slot)
Definition FileTable.h:176
bool WriteLog(const char *log_file_name)
Definition FileTable.h:101
bool Fill(const char *path, const char *endswith=nullptr)
Definition FileTable.h:43
void Clear()
Definition FileTable.h:23
void SetLoadPending(int slot)
Definition FileTable.h:163
bool IsSavePending() const
Definition FileTable.h:169
void ClearSavePending()
Definition FileTable.h:171
static constexpr const size_t kMaxFileSlots
Definition FileTable.h:20
const char * GetFileName(size_t idx) const
Definition FileTable.h:144
bool IsLoadPending() const
Definition FileTable.h:156
int GetSlotForSaveLoad() const
Definition FileTable.h:182
bool IsFileInSlot(size_t idx) const
Definition FileTable.h:138
static constexpr const size_t kMaxCustomFileNameLen
Definition FileTable.h:19
size_t GetNumFiles() const
Definition FileTable.h:147
void ClearLoadPending()
Definition FileTable.h:158
#define _MAX_LFN
Definition ffconf.h:117
Hardware defines and helpers for daisy field platform.
Definition index.h:2