|
|
@ -676,16 +676,30 @@ void CardReader::updir() {
|
|
|
|
// If you use folders to organize, 20 may be enough
|
|
|
|
// If you use folders to organize, 20 may be enough
|
|
|
|
if (fileCnt > SDSORT_LIMIT) fileCnt = SDSORT_LIMIT;
|
|
|
|
if (fileCnt > SDSORT_LIMIT) fileCnt = SDSORT_LIMIT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sort order is always needed. May be static or dynamic.
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
sort_order = new uint8_t[fileCnt];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Use RAM to store the entire directory during pre-sort.
|
|
|
|
// Use RAM to store the entire directory during pre-sort.
|
|
|
|
// SDSORT_LIMIT should be set to prevent over-allocation.
|
|
|
|
// SDSORT_LIMIT should be set to prevent over-allocation.
|
|
|
|
#if ENABLED(SDSORT_USES_RAM)
|
|
|
|
#if ENABLED(SDSORT_USES_RAM)
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_USES_STACK)
|
|
|
|
// If using dynamic ram for names, allocate on the heap.
|
|
|
|
#if DISABLED(SDSORT_CACHE_NAMES)
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
sortshort = new char*[fileCnt];
|
|
|
|
|
|
|
|
sortnames = new char*[fileCnt];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif ENABLED(SDSORT_USES_STACK)
|
|
|
|
char sortnames[fileCnt][LONG_FILENAME_LENGTH];
|
|
|
|
char sortnames[fileCnt][LONG_FILENAME_LENGTH];
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Folder sorting needs 1 bit per entry for flags.
|
|
|
|
// Folder sorting needs 1 bit per entry for flags.
|
|
|
|
#if HAS_FOLDER_SORTING
|
|
|
|
#if HAS_FOLDER_SORTING
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
isDir = new uint8_t[(fileCnt + 7) >> 3];
|
|
|
|
|
|
|
|
#elif ENABLED(SDSORT_USES_STACK)
|
|
|
|
uint8_t isDir[(fileCnt + 7) >> 3];
|
|
|
|
uint8_t isDir[(fileCnt + 7) >> 3];
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -707,10 +721,21 @@ void CardReader::updir() {
|
|
|
|
// If using RAM then read all filenames now.
|
|
|
|
// If using RAM then read all filenames now.
|
|
|
|
#if ENABLED(SDSORT_USES_RAM)
|
|
|
|
#if ENABLED(SDSORT_USES_RAM)
|
|
|
|
getfilename(i);
|
|
|
|
getfilename(i);
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
// Use dynamic method to copy long filename
|
|
|
|
|
|
|
|
sortnames[i] = strdup(LONGEST_FILENAME);
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
|
|
|
|
// When caching also store the short name, since
|
|
|
|
|
|
|
|
// we're replacing the getfilename() behavior.
|
|
|
|
|
|
|
|
sortshort[i] = strdup(filename);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// Copy filenames into the static array
|
|
|
|
strcpy(sortnames[i], LONGEST_FILENAME);
|
|
|
|
strcpy(sortnames[i], LONGEST_FILENAME);
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
strcpy(sortshort[i], filename);
|
|
|
|
strcpy(sortshort[i], filename);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// char out[30];
|
|
|
|
// char out[30];
|
|
|
|
// sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
|
|
|
|
// sprintf_P(out, PSTR("---- %i %s %s"), i, filenameIsDir ? "D" : " ", sortnames[i]);
|
|
|
|
// SERIAL_ECHOLN(out);
|
|
|
|
// SERIAL_ECHOLN(out);
|
|
|
@ -780,13 +805,30 @@ void CardReader::updir() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!didSwap) break;
|
|
|
|
if (!didSwap) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Using RAM but not keeping names around
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_USES_RAM) && DISABLED(SDSORT_CACHE_NAMES)
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
for (uint16_t i = 0; i < fileCnt; ++i) free(sortnames[i]);
|
|
|
|
|
|
|
|
#if HAS_FOLDER_SORTING
|
|
|
|
|
|
|
|
free(isDir);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
sort_order[0] = 0;
|
|
|
|
sort_order[0] = 0;
|
|
|
|
#if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
#if ENABLED(SDSORT_USES_RAM) && ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
getfilename(0);
|
|
|
|
getfilename(0);
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
sortnames = new char*[1];
|
|
|
|
|
|
|
|
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
|
|
|
|
|
|
|
|
sortshort = new char*[1];
|
|
|
|
|
|
|
|
sortshort[0] = strdup(filename); // malloc
|
|
|
|
|
|
|
|
isDir = new uint8_t[1];
|
|
|
|
|
|
|
|
#else
|
|
|
|
strcpy(sortnames[0], LONGEST_FILENAME);
|
|
|
|
strcpy(sortnames[0], LONGEST_FILENAME);
|
|
|
|
strcpy(sortshort[0], filename);
|
|
|
|
strcpy(sortshort[0], filename);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
|
|
|
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -796,8 +838,21 @@ void CardReader::updir() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CardReader::flush_presort() {
|
|
|
|
void CardReader::flush_presort() {
|
|
|
|
|
|
|
|
if (sort_count > 0) {
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
|
|
|
|
delete sort_order;
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < sort_count; ++i) {
|
|
|
|
|
|
|
|
free(sortshort[i]); // strdup
|
|
|
|
|
|
|
|
free(sortnames[i]); // strdup
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delete sortshort;
|
|
|
|
|
|
|
|
delete sortnames;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
sort_count = 0;
|
|
|
|
sort_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SDCARD_SORT_ALPHA
|
|
|
|
#endif // SDCARD_SORT_ALPHA
|
|
|
|
|
|
|
|
|
|
|
|