"M20 L" support. Print long filenames

This commit is contained in:
Voinea Dragos 2021-01-22 11:13:44 +02:00
parent b71f1be37a
commit ced3d9fa77
3 changed files with 22 additions and 9 deletions

View File

@ -5677,7 +5677,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
*/ */
case 20: case 20:
SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST
card.ls(); card.ls(code_seen('L'));
SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST
break; break;

View File

@ -62,9 +62,10 @@ char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
/** /**
+* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction: +* Dive into a folder and recurse depth-first to perform a pre-set operation lsAction:
+* LS_Count - Add +1 to nrFiles for every file within the parent +* LS_Count - Add +1 to nrFiles for every file within the parent
+* LS_GetFilename - Get the filename of the file indexed by nrFiles +* LS_GetFilename - Get the filename of the file indexed by nrFiles
+* LS_SerialPrint - Print the full path and size of each file to serial output +* LS_SerialPrint - Print the full path and size of each file to serial output
+* LS_SerialPrint_LFN - Print the full path, long filename and size of each file to serial output
+*/ +*/
void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) { void CardReader::lsDive(const char *prepend, SdFile parent, const char * const match/*=NULL*/) {
@ -90,9 +91,13 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
// Serial.print(path); // Serial.print(path);
// Get a new directory object using the full path // Get a new directory object using the full path
// and dive recursively into it. // and dive recursively into it.
if (lsAction == LS_SerialPrint_LFN)
printf_P(PSTR("DIR_ENTER: %s \"%s\"\n"), path, longFilename[0] ? longFilename : lfilename);
SdFile dir; SdFile dir;
if (!dir.open(parent, lfilename, O_READ)) { if (!dir.open(parent, lfilename, O_READ)) {
if (lsAction == LS_SerialPrint) { if (lsAction == LS_SerialPrint || lsAction == LS_SerialPrint_LFN) {
//SERIAL_ECHO_START(); //SERIAL_ECHO_START();
//SERIAL_ECHOPGM(_i("Cannot open subdir"));////MSG_SD_CANT_OPEN_SUBDIR //SERIAL_ECHOPGM(_i("Cannot open subdir"));////MSG_SD_CANT_OPEN_SUBDIR
//SERIAL_ECHOLN(lfilename); //SERIAL_ECHOLN(lfilename);
@ -100,6 +105,9 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
} }
lsDive(path, dir); lsDive(path, dir);
// close() is done automatically by destructor of SdFile // close() is done automatically by destructor of SdFile
if (lsAction == LS_SerialPrint_LFN)
puts_P(PSTR("DIR_EXIT"));
} }
else { else {
uint8_t pn0 = p.name[0]; uint8_t pn0 = p.name[0];
@ -114,11 +122,16 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
nrFiles++; nrFiles++;
break; break;
case LS_SerialPrint_LFN:
case LS_SerialPrint: case LS_SerialPrint:
createFilename(filename, p); createFilename(filename, p);
SERIAL_PROTOCOL(prepend); SERIAL_PROTOCOL(prepend);
SERIAL_PROTOCOL(filename); SERIAL_PROTOCOL(filename);
MYSERIAL.write(' '); MYSERIAL.write(' ');
if (lsAction == LS_SerialPrint_LFN)
printf_P(PSTR("\"%s\" "), LONGEST_FILENAME);
SERIAL_PROTOCOLLN(p.fileSize); SERIAL_PROTOCOLLN(p.fileSize);
break; break;
@ -160,9 +173,9 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
} // while readDir } // while readDir
} }
void CardReader::ls() void CardReader::ls(bool printLFN)
{ {
lsAction=LS_SerialPrint; lsAction = printLFN ? LS_SerialPrint_LFN : LS_SerialPrint;
//if(lsAction==LS_Count) //if(lsAction==LS_Count)
//nrFiles=0; //nrFiles=0;

View File

@ -6,7 +6,7 @@
#define MAX_DIR_DEPTH 10 #define MAX_DIR_DEPTH 10
#include "SdFile.h" #include "SdFile.h"
enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename}; enum LsAction {LS_SerialPrint,LS_SerialPrint_LFN,LS_Count,LS_GetFilename};
class CardReader class CardReader
{ {
public: public:
@ -38,7 +38,7 @@ public:
uint16_t getWorkDirDepth(); uint16_t getWorkDirDepth();
void ls(); void ls(bool printLFN);
void chdir(const char * relpath); void chdir(const char * relpath);
void updir(); void updir();
void setroot(); void setroot();