diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 962b7398..d9f68169 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -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; } } diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index 84267287..16bc4b25 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -39,7 +39,7 @@ public: void ls(bool printLFN); - void chdir(const char * relpath); + bool chdir(const char * relpath); void updir(); void setroot(); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3202a7d8..0983c440 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -8490,13 +8490,16 @@ 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); - strcpy(dir_names[depth], filename); - MYSERIAL.println(dir_names[depth]); - card.chdir(filename); - lcd_encoder = 0; - menu_data_reset(); //Forces reloading of cached variables. + if (success) + { + strcpy(dir_names[card.getWorkDirDepth()], filename); + MYSERIAL.println(filename); + } + + lcd_encoder = 0; + menu_data_reset(); //Forces reloading of cached variables. } /** LCD API **/