Add card.longest_filename, more lcd_strlen updates

This commit is contained in:
Scott Lahteine
2018-07-17 17:33:01 -05:00
parent 036f25e159
commit 7e648f3721
6 changed files with 39 additions and 44 deletions

View File

@@ -35,8 +35,6 @@
#include "power_loss_recovery.h"
#endif
#define LONGEST_FILENAME (longFilename[0] ? longFilename : filename)
CardReader::CardReader() {
#if ENABLED(SDCARD_SORT_ALPHA)
sort_count = 0;
@@ -731,7 +729,7 @@ void CardReader::setroot() {
getfilename(i);
#if ENABLED(SDSORT_DYNAMIC_RAM)
// Use dynamic method to copy long filename
sortnames[i] = strdup(LONGEST_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.
@@ -740,10 +738,10 @@ void CardReader::setroot() {
#else
// Copy filenames into the static array
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
sortnames[i][SORTED_LONGNAME_MAXLEN - 1] = '\0';
#else
strncpy(sortnames[i], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
strncpy(sortnames[i], longest_filename(), SORTED_LONGNAME_MAXLEN);
#endif
#if ENABLED(SDSORT_CACHE_NAMES)
strcpy(sortshort[i], filename);
@@ -791,12 +789,12 @@ void CardReader::setroot() {
// throughout the loop. Slow if there are many.
#if DISABLED(SDSORT_USES_RAM)
getfilename(o1);
strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it)
strcpy(name1, longest_filename()); // save (or getfilename below will trounce it)
#if HAS_FOLDER_SORTING
bool dir1 = filenameIsDir;
#endif
getfilename(o2);
char *name2 = LONGEST_FILENAME; // use the string in-place
char *name2 = longest_filename(); // use the string in-place
#endif // !SDSORT_USES_RAM
// Sort the current pair according to settings.
@@ -834,7 +832,7 @@ void CardReader::setroot() {
getfilename(0);
#if ENABLED(SDSORT_DYNAMIC_RAM)
sortnames = new char*[1];
sortnames[0] = strdup(LONGEST_FILENAME); // malloc
sortnames[0] = strdup(longest_filename()); // malloc
#if ENABLED(SDSORT_CACHE_NAMES)
sortshort = new char*[1];
sortshort[0] = strdup(filename); // malloc
@@ -842,10 +840,10 @@ void CardReader::setroot() {
isDir = new uint8_t[1];
#else
#if SORTED_LONGNAME_MAXLEN != LONG_FILENAME_LENGTH
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
sortnames[0][SORTED_LONGNAME_MAXLEN - 1] = '\0';
#else
strncpy(sortnames[0], LONGEST_FILENAME, SORTED_LONGNAME_MAXLEN);
strncpy(sortnames[0], longest_filename(), SORTED_LONGNAME_MAXLEN);
#endif
#if ENABLED(SDSORT_CACHE_NAMES)
strcpy(sortshort[0], filename);