|
@@ -74,9 +74,12 @@ char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
|
74
|
74
|
/**
|
75
|
75
|
* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
|
76
|
76
|
* LS_Count - Add +1 to nrFiles for every file within the parent
|
77
|
|
- * LS_GetFilename - Get the filename of the file indexed by nrFiles
|
|
77
|
+ * LS_GetFilename - Get the filename of the file indexed by nrFile_index
|
78
|
78
|
* LS_SerialPrint - Print the full path and size of each file to serial output
|
79
|
79
|
*/
|
|
80
|
+
|
|
81
|
+uint16_t nrFile_index;
|
|
82
|
+
|
80
|
83
|
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
|
81
|
84
|
dir_t p;
|
82
|
85
|
uint8_t cnt = 0;
|
|
@@ -130,7 +133,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
130
|
133
|
|
131
|
134
|
if (!filenameIsDir && (p.name[8] != 'G' || p.name[9] == '~')) continue;
|
132
|
135
|
|
133
|
|
- switch (lsAction) {
|
|
136
|
+ switch (lsAction) { // 1 based file count
|
134
|
137
|
case LS_Count:
|
135
|
138
|
nrFiles++;
|
136
|
139
|
break;
|
|
@@ -148,7 +151,7 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
|
148
|
151
|
if (match != NULL) {
|
149
|
152
|
if (strcasecmp(match, filename) == 0) return;
|
150
|
153
|
}
|
151
|
|
- else if (cnt == nrFiles) return;
|
|
154
|
+ else if (cnt == nrFile_index) return; // 0 based index
|
152
|
155
|
cnt++;
|
153
|
156
|
break;
|
154
|
157
|
}
|
|
@@ -587,7 +590,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
|
587
|
590
|
#endif // SDSORT_CACHE_NAMES
|
588
|
591
|
curDir = &workDir;
|
589
|
592
|
lsAction = LS_GetFilename;
|
590
|
|
- nrFiles = nr;
|
|
593
|
+ nrFile_index = nr;
|
591
|
594
|
curDir->rewind();
|
592
|
595
|
lsDive("", *curDir, match);
|
593
|
596
|
}
|
|
@@ -688,7 +691,7 @@ void CardReader::updir() {
|
688
|
691
|
sortnames = new char*[fileCnt];
|
689
|
692
|
#endif
|
690
|
693
|
#elif ENABLED(SDSORT_USES_STACK)
|
691
|
|
- char sortnames[fileCnt][LONG_FILENAME_LENGTH];
|
|
694
|
+ char sortnames[fileCnt][SORTED_LONGNAME_MAXLEN];
|
692
|
695
|
#endif
|
693
|
696
|
|
694
|
697
|
// Folder sorting needs 1 bit per entry for flags.
|
|
@@ -727,7 +730,12 @@ void CardReader::updir() {
|
727
|
730
|
#endif
|
728
|
731
|
#else
|
729
|
732
|
// Copy filenames into the static array
|
730
|
|
- strcpy(sortnames[i], LONGEST_FILENAME);
|
|
733
|
+ #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
|
|
734
|
+ strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
735
|
+ sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
|
|
736
|
+ #else
|
|
737
|
+ strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
738
|
+ #endif
|
731
|
739
|
#if ENABLED(SDSORT_CACHE_NAMES)
|
732
|
740
|
strcpy(sortshort[i], filename);
|
733
|
741
|
#endif
|
|
@@ -818,12 +826,21 @@ void CardReader::updir() {
|
818
|
826
|
#if ENABLED(SDSORT_DYNAMIC_RAM)
|
819
|
827
|
sortnames = new char*[1];
|
820
|
828
|
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
|
821
|
|
- sortshort = new char*[1];
|
822
|
|
- sortshort[0] = strdup(filename); // malloc
|
|
829
|
+ #if ENABLED(SDSORT_CACHE_NAMES)
|
|
830
|
+ sortshort = new char*[1];
|
|
831
|
+ sortshort[0] = strdup(filename); // malloc
|
|
832
|
+ #endif
|
823
|
833
|
isDir = new uint8_t[1];
|
824
|
834
|
#else
|
825
|
|
- strcpy(sortnames[0], LONGEST_FILENAME);
|
826
|
|
- strcpy(sortshort[0], filename);
|
|
835
|
+ #if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
|
|
836
|
+ strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
837
|
+ sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
|
|
838
|
+ #else
|
|
839
|
+ strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
|
|
840
|
+ #endif
|
|
841
|
+ #if ENABLED(SDSORT_CACHE_NAMES)
|
|
842
|
+ strcpy(sortshort[0], filename);
|
|
843
|
+ #endif
|
827
|
844
|
#endif
|
828
|
845
|
isDir[0] = filenameIsDir ? 0x01 : 0x00;
|
829
|
846
|
#endif
|
|
@@ -852,6 +869,16 @@ void CardReader::updir() {
|
852
|
869
|
|
853
|
870
|
#endif // SDCARD_SORT_ALPHA
|
854
|
871
|
|
|
872
|
+uint16_t CardReader::get_num_Files() {
|
|
873
|
+ return
|
|
874
|
+ #if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
|
|
875
|
+ nrFiles // no need to access the SD card for filenames
|
|
876
|
+ #else
|
|
877
|
+ getnrfilenames()
|
|
878
|
+ #endif
|
|
879
|
+ ;
|
|
880
|
+}
|
|
881
|
+
|
855
|
882
|
void CardReader::printingHasFinished() {
|
856
|
883
|
stepper.synchronize();
|
857
|
884
|
file.close();
|