6#define MAX_FILE_LEN 256
19template <
class SDT,
class FileT>
23 void begin(
const char *startDir,
const char *extension,
27 this->
ext = extension;
32 LOGI(
"Index file size: %d", idx_file_size);
36 if (setupIndex && (keyNew != keyOld || idx_file_size == 0)) {
38 LOGW(
"Creating index file");
40 LOGI(
"Indexing completed");
47 void ls(
Print &p,
const char *startDir,
const char *extension,
50 this->
ext = extension;
61 LOGE(
"idx %d is negative", idx);
82 if (idxfile.available() == 0) {
83 LOGE(
"Index file is empty");
89 while (idxfile.available() > 0 && !found) {
90 result = idxfile.readStringUntil(
'\n');
93 char *c_str = (
char *)
result.c_str();
95 int lastPos =
result.length() - 1;
96 if (c_str[lastPos] == 13) {
100 LOGD(
"%d -> %s", count, c_str);
111 return found ?
result.c_str() :
nullptr;
116 if (filename ==
nullptr) {
117 LOGE(
"filename is null");
122 if (idxfile.available() == 0) {
123 LOGE(
"Index file is empty");
129 String searchName(filename);
131 while (idxfile.available() > 0) {
132 result = idxfile.readStringUntil(
'\n');
135 char *c_str = (
char *)
result.c_str();
137 int lastPos =
result.length() - 1;
138 if (lastPos >= 0 && c_str[lastPos] == 13) {
142 LOGD(
"Comparing %d: '%s' with '%s'", count, c_str, filename);
145 String currentFile(c_str);
146 if (currentFile == searchName ||
147 currentFile.endsWith(
"/" + searchName) ||
148 currentFile.endsWith(searchName)) {
149 LOGD(
"Found '%s' at index %d", filename, count);
163 LOGD(
"File '%s' not found in index", filename);
172 while (idxfile.available() > 0) {
173 result = idxfile.readStringUntil(
'\n');
175 char *c_str = (
char *)
result.c_str();
193 const char *
ext =
nullptr;
204 LOGD(
"listDir: %s", dirname);
205 FileT root =
open(dirname);
207 LOGE(
"Open failed: %s", dirname);
212 LOGD(
"Is not directory: %s", dirname);
216 if (
StrView(dirname).startsWith(
".")) {
217 LOGD(
"Invalid file: %s", dirname);
227 LOGD(
"name: %s", name.c_str());
229 listDir(idxfile, name.c_str());
233 LOGD(
"Adding file to index: %s", fn);
236 LOGD(
"Ignoring %s", fn);
259 if (!
result.openNext(&dir, O_READ)) {
260 LOGD(
"No next file");
264 return dir.openNextFile();
269 LOGD(
"pushPath: %s", name);
270 LOGD(
"pushPath: %s", name);
271 String nameStr(name);
279 LOGD(
"popPath: %s", str.c_str());
285 const char *file_name =
fileName(file);
286 if (file.isDirectory()) {
287 LOGD(
"-> isValidAudioFile: '%s': %d", file_name,
false);
290 StrView strFileTName(file_name);
293 LOGD(
"-> isValidAudioFile: '%s': %d", file_name,
result);
299 String key1 = idxdef.readString();
305 idxdef.write((
const uint8_t *)keyNew.c_str(), keyNew.length());
311 size_t result = idxfile.size();
339 return file.name() + pos;
345#if defined(USE_SDFAT) || ESP_IDF_VERSION_MAJOR >= 4
379 LOGE(
"FileT open error: %s", name);
383 return p_sd->open(name,
"r");
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define MAX_FILE_LEN
Definition SDDirect.h:6
#define FILE_WRITE
Definition VFSFile.h:18