Revert c2c950b and 41c1600 and put changes into 36c8aee to recreate the 1.4.x filane behaviour. This should fix #453 and #455. It's untested atm and can include bugs.

This commit is contained in:
Knutwurst
2023-04-23 22:11:42 +02:00
parent 9f93a2cc5d
commit 4d6715761d

View File

@@ -1170,13 +1170,14 @@
card.selectFileByIndex(count - 1); card.selectFileByIndex(count - 1);
// The longname may not be filed, so we use the built-in fallback here. // The longname may not be filed, so we use the built-in fallback here.
char* fileName = card.longest_filename(); char* fileName = card.longest_filename();
int fileNameLen = strlen(fileName); int fileNameLen = strlen(fileName);
bool fileNameWasCut = false;
// Cut off too long filenames. They don't fit on the screen anyway. // Cut off too long filenames.
// They don't fit on the screen anyway.
#if ENABLED(KNUTWURST_DGUS2_TFT) #if ENABLED(KNUTWURST_DGUS2_TFT)
bool fileNameWasCut = false; if (fileNameLen >= MAX_PRINTABLE_FILENAME_LEN) {
if (fileNameLen > MAX_PRINTABLE_FILENAME_LEN) {
fileNameWasCut = true; fileNameWasCut = true;
fileNameLen = MAX_PRINTABLE_FILENAME_LEN; fileNameLen = MAX_PRINTABLE_FILENAME_LEN;
} }
@@ -1184,35 +1185,31 @@
char outputString[fileNameLen]; char outputString[fileNameLen];
// Bugfix for non-printable special characters which are now replaced by underscores. // Bugfix for non-printable special characters
for (unsigned char i = 0; i < fileNameLen; i++) { // which are now replaced by underscores.
if (isPrintable(fileName[i])) for (unsigned char i = 0; i <= fileNameLen; i++) {
if (i >= fileNameLen) {
outputString[i] = ' ';
}
else {
outputString[i] = fileName[i]; outputString[i] = fileName[i];
else if (!isPrintable(outputString[i]))
outputString[i] = '_'; outputString[i] = '_';
}
} }
#if ENABLED(KNUTWURST_DGUS2_TFT) // I know, it's ugly, but it's faster than a string lib
// Append extension, if filename was truncated. I know, it's ugly, but it's faster than a string lib. if (fileNameWasCut) {
if (fileNameWasCut) { outputString[fileNameLen - 7] = '~';
outputString[fileNameLen - 7] = '~'; outputString[fileNameLen - 6] = '.';
outputString[fileNameLen - 6] = '.'; outputString[fileNameLen - 5] = 'g';
outputString[fileNameLen - 5] = 'g'; outputString[fileNameLen - 4] = 'c';
outputString[fileNameLen - 4] = 'c'; outputString[fileNameLen - 3] = 'o';
outputString[fileNameLen - 3] = 'o'; outputString[fileNameLen - 2] = 'd';
outputString[fileNameLen - 2] = 'd'; outputString[fileNameLen - 1] = 'e';
outputString[fileNameLen - 1] = 'e'; }
} else {
// Make sure to fill the output buffer with blanks. outputString[fileNameLen] = '\0';
for (unsigned char i = fileNameLen; i < MAX_PRINTABLE_FILENAME_LEN; i++) {
outputString[i] = ' ';
}
}
outputString[MAX_PRINTABLE_FILENAME_LEN] = '\0';
#else
// Just terminate the string.
outputString[fileNameLen] = '\0';
#endif
if (card.flag.filenameIsDir) { if (card.flag.filenameIsDir) {
#if ENABLED(KNUTWURST_DGUS2_TFT) #if ENABLED(KNUTWURST_DGUS2_TFT)
@@ -1231,8 +1228,7 @@
SERIAL_ECHO(count); SERIAL_ECHO(count);
SERIAL_ECHOPGM(": /"); SERIAL_ECHOPGM(": /");
SERIAL_ECHOLN(outputString); SERIAL_ECHOLN(outputString);
} } else {
else {
SENDLINE(card.filename); SENDLINE(card.filename);
SENDLINE(outputString); SENDLINE(outputString);
SERIAL_ECHO(count); SERIAL_ECHO(count);