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

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