Explorar o código

Fix WorkDirDepth limit (for good this time)

Alex Voinea %!s(int64=3) %!d(string=hai) anos
pai
achega
84d043d41b
Modificáronse 3 ficheiros con 14 adicións e 9 borrados
  1. 4 2
      Firmware/cardreader.cpp
  2. 1 1
      Firmware/cardreader.h
  3. 9 6
      Firmware/ultralcd.cpp

+ 4 - 2
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;
   }
 }
 

+ 1 - 1
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();
 

+ 9 - 6
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 **/