Fix WorkDirDepth limit (for good this time)

This commit is contained in:
Alex Voinea 2021-02-04 17:52:42 +02:00
parent 90c0f33bc5
commit 84d043d41b
3 changed files with 14 additions and 9 deletions

View File

@ -666,7 +666,7 @@ uint16_t CardReader::getnrfilenames()
return nrFiles;
}
void CardReader::chdir(const char * relpath)
bool CardReader::chdir(const char * relpath)
{
SdFile newfile;
SdFile *parent=&root;
@ -674,11 +674,12 @@ void CardReader::chdir(const char * relpath)
if(workDir.isOpen())
parent=&workDir;
if(!newfile.open(*parent,relpath, O_READ))
if(!newfile.open(*parent,relpath, O_READ) || ((workDirDepth + 1) >= MAX_DIR_DEPTH))
{
SERIAL_ECHO_START;
SERIAL_ECHORPGM(_n("Cannot enter subdir: "));////MSG_SD_CANT_ENTER_SUBDIR
SERIAL_ECHOLN(relpath);
return 0;
}
else
{
@ -691,6 +692,7 @@ void CardReader::chdir(const char * relpath)
#ifdef SDCARD_SORT_ALPHA
presort();
#endif
return 1;
}
}

View File

@ -39,7 +39,7 @@ public:
void ls(bool printLFN);
void chdir(const char * relpath);
bool chdir(const char * relpath);
void updir();
void setroot();

View File

@ -8490,11 +8490,14 @@ static void menu_action_sdfile(const char* filename)
void menu_action_sddirectory(const char* filename)
{
uint8_t depth = (uint8_t)card.getWorkDirDepth();
bool success = card.chdir(filename);
if (success)
{
strcpy(dir_names[card.getWorkDirDepth()], filename);
MYSERIAL.println(filename);
}
strcpy(dir_names[depth], filename);
MYSERIAL.println(dir_names[depth]);
card.chdir(filename);
lcd_encoder = 0;
menu_data_reset(); //Forces reloading of cached variables.
}