Merge pull request #399 from stklcode/fix/cleanup-filename
simplify file name sanitization
This commit is contained in:
@@ -1190,15 +1190,14 @@
|
|||||||
else {
|
else {
|
||||||
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;
|
bool fileNameWasCut = false;
|
||||||
|
|
||||||
// Cut off too long filenames.
|
// Cut off too long filenames. They don't fit on the screen anyway.
|
||||||
// They don't fit on the screen anyway.
|
|
||||||
#if ENABLED(KNUTWURST_DGUS2_TFT)
|
#if ENABLED(KNUTWURST_DGUS2_TFT)
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -1206,20 +1205,18 @@
|
|||||||
|
|
||||||
char outputString[fileNameLen];
|
char outputString[fileNameLen];
|
||||||
|
|
||||||
// Bugfix for non-printable special characters
|
// Bugfix for non-printable special characters which are now replaced by underscores.
|
||||||
// which are now replaced by underscores.
|
for (unsigned char i = 0; i < fileNameLen; i++) {
|
||||||
for (unsigned char i = 0; i <= fileNameLen; i++) {
|
if (isPrintable(fileName[i]))
|
||||||
if (i >= fileNameLen) {
|
|
||||||
outputString[i] = ' ';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
outputString[i] = fileName[i];
|
outputString[i] = fileName[i];
|
||||||
if (!isPrintable(outputString[i]))
|
else
|
||||||
outputString[i] = '_';
|
outputString[i] = '_';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// I know, it's ugly, but it's faster than a string lib
|
// Terminate the string.
|
||||||
|
outputString[fileNameLen] = '\0';
|
||||||
|
|
||||||
|
// 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] = '.';
|
||||||
@@ -1230,8 +1227,6 @@
|
|||||||
outputString[fileNameLen - 1] = 'e';
|
outputString[fileNameLen - 1] = 'e';
|
||||||
}
|
}
|
||||||
|
|
||||||
outputString[fileNameLen] = '\0';
|
|
||||||
|
|
||||||
if (card.flag.filenameIsDir) {
|
if (card.flag.filenameIsDir) {
|
||||||
#if ENABLED(KNUTWURST_DGUS2_TFT)
|
#if ENABLED(KNUTWURST_DGUS2_TFT)
|
||||||
HARDWARE_SERIAL_PROTOCOLPGM("/");
|
HARDWARE_SERIAL_PROTOCOLPGM("/");
|
||||||
|
Reference in New Issue
Block a user