|
|
@ -74,9 +74,12 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
|
|
|
|
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
|
|
|
|
* LS_Count - Add +1 to nrFiles for every file within the parent
|
|
|
|
* LS_Count - Add +1 to nrFiles for every file within the parent
|
|
|
|
* LS_GetFilename - Get the filename of the file indexed by nrFiles
|
|
|
|
* LS_GetFilename - Get the filename of the file indexed by nrFile_index
|
|
|
|
* LS_SerialPrint - Print the full path and size of each file to serial output
|
|
|
|
* LS_SerialPrint - Print the full path and size of each file to serial output
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t nrFile_index;
|
|
|
|
|
|
|
|
|
|
|
|
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
|
|
|
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
|
|
|
dir_t p;
|
|
|
|
dir_t p;
|
|
|
|
uint8_t cnt = 0;
|
|
|
|
uint8_t cnt = 0;
|
|
|
@ -130,7 +133,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
|
|
|
|
|
|
|
|
|
|
|
if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
|
|
|
|
if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
|
|
|
|
|
|
|
|
|
|
|
|
switch (lsAction) {
|
|
|
|
switch (lsAction) { // 1 based file count
|
|
|
|
case LS_Count:
|
|
|
|
case LS_Count:
|
|
|
|
nrFiles++;
|
|
|
|
nrFiles++;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -148,7 +151,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
|
|
|
if (match != NULL) {
|
|
|
|
if (match != NULL) {
|
|
|
|
if (strcasecmp(match, filename) == 0) return;
|
|
|
|
if (strcasecmp(match, filename) == 0) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cnt == nrFiles) return;
|
|
|
|
else if (cnt == nrFile_index) return; // 0 based index
|
|
|
|
cnt++;
|
|
|
|
cnt++;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -587,7 +590,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
|
|
|
|
#endif // SDSORT_CACHE_NAMES
|
|
|
|
#endif // SDSORT_CACHE_NAMES
|
|
|
|
curDir = &workDir;
|
|
|
|
curDir = &workDir;
|
|
|
|
lsAction = LS_GetFilename;
|
|
|
|
lsAction = LS_GetFilename;
|
|
|
|
nrFiles = nr;
|
|
|
|
nrFile_index = nr;
|
|
|
|
curDir->rewind();
|
|
|
|
curDir->rewind();
|
|
|
|
lsDive("", *curDir, match);
|
|
|
|
lsDive("", *curDir, match);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -688,7 +691,7 @@ void CardReader::updir() {
|
|
|
|
sortnames = new char*[fileCnt];
|
|
|
|
sortnames = new char*[fileCnt];
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#elif ENABLED(SDSORT_USES_STACK)
|
|
|
|
#elif ENABLED(SDSORT_USES_STACK)
|
|
|
|
char sortnames[fileCnt][LONG_FILENAME_LENGTH];
|
|
|
|
char sortnames[fileCnt][SORTED_LONGNAME_MAXLEN];
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Folder sorting needs 1 bit per entry for flags.
|
|
|
|
// Folder sorting needs 1 bit per entry for flags.
|
|
|
@ -727,7 +730,12 @@ void CardReader::updir() {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
// Copy filenames into the static array
|
|
|
|
// Copy filenames into the static array
|
|
|
|
strcpy(sortnames[i], LONGEST_FILENAME);
|
|
|
|
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
|
|
|
|
|
|
|
|
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
|
|
|
|
|
|
sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
strcpy(sortshort[i], filename);
|
|
|
|
strcpy(sortshort[i], filename);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -818,12 +826,21 @@ void CardReader::updir() {
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
|
|
|
sortnames = new char*[1];
|
|
|
|
sortnames = new char*[1];
|
|
|
|
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
|
|
|
|
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
|
|
|
|
sortshort = new char*[1];
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
sortshort[0] = strdup(filename); // malloc
|
|
|
|
sortshort = new char*[1];
|
|
|
|
|
|
|
|
sortshort[0] = strdup(filename); // malloc
|
|
|
|
|
|
|
|
#endif
|
|
|
|
isDir = new uint8_t[1];
|
|
|
|
isDir = new uint8_t[1];
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
strcpy(sortnames[0], LONGEST_FILENAME);
|
|
|
|
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
|
|
|
|
strcpy(sortshort[0], filename);
|
|
|
|
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
|
|
|
|
|
|
sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
|
|
|
|
|
|
|
strcpy(sortshort[0], filename);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
|
|
|
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -852,6 +869,16 @@ void CardReader::updir() {
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SDCARD_SORT_ALPHA
|
|
|
|
#endif // SDCARD_SORT_ALPHA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t CardReader::get_num_Files() {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
#if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
|
|
|
|
|
|
|
|
nrFiles // no need to access the SD card for filenames
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
getnrfilenames()
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CardReader::printingHasFinished() {
|
|
|
|
void CardReader::printingHasFinished() {
|
|
|
|
stepper.synchronize();
|
|
|
|
stepper.synchronize();
|
|
|
|
file.close();
|
|
|
|
file.close();
|
|
|
|