Add root flag to CardReader (#15275)
This commit is contained in:
parent
eb1a368277
commit
98233b1de0
|
@ -975,8 +975,7 @@ namespace ExtUI {
|
||||||
|
|
||||||
bool FileList::isAtRootDir() {
|
bool FileList::isAtRootDir() {
|
||||||
#if ENABLED(SDSUPPORT)
|
#if ENABLED(SDSUPPORT)
|
||||||
card.getWorkDirName();
|
card.flag.workDirIsRoot;
|
||||||
return card.filename[0] == '/';
|
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -127,21 +127,14 @@ void menu_media() {
|
||||||
|
|
||||||
#if HAS_GRAPHICAL_LCD
|
#if HAS_GRAPHICAL_LCD
|
||||||
static uint16_t fileCnt;
|
static uint16_t fileCnt;
|
||||||
static bool at_root;
|
if (ui.first_page) fileCnt = card.get_num_Files();
|
||||||
if (ui.first_page) {
|
|
||||||
fileCnt = card.get_num_Files();
|
|
||||||
card.getWorkDirName();
|
|
||||||
at_root = card.filename[0] == '/';
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
const uint16_t fileCnt = card.get_num_Files();
|
const uint16_t fileCnt = card.get_num_Files();
|
||||||
card.getWorkDirName();
|
|
||||||
const bool at_root = card.filename[0] == '/';
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
START_MENU();
|
START_MENU();
|
||||||
MENU_BACK(MSG_MAIN);
|
MENU_BACK(MSG_MAIN);
|
||||||
if (at_root) {
|
if (card.flag.workDirIsRoot) {
|
||||||
#if !PIN_EXISTS(SD_DETECT)
|
#if !PIN_EXISTS(SD_DETECT)
|
||||||
MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
|
MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -629,7 +629,7 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=nullptr*/)
|
||||||
lsDive(nullptr, workDir, match);
|
lsDive(nullptr, workDir, match);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t CardReader::getnrfilenames() {
|
uint16_t CardReader::countFilesInWorkDir() {
|
||||||
lsAction = LS_Count;
|
lsAction = LS_Count;
|
||||||
nrFiles = 0;
|
nrFiles = 0;
|
||||||
workDir.rewind();
|
workDir.rewind();
|
||||||
|
@ -707,6 +707,7 @@ void CardReader::chdir(const char * relpath) {
|
||||||
|
|
||||||
if (newDir.open(parent, relpath, O_READ)) {
|
if (newDir.open(parent, relpath, O_READ)) {
|
||||||
workDir = newDir;
|
workDir = newDir;
|
||||||
|
flag.workDirIsRoot = false;
|
||||||
if (workDirDepth < MAX_DIR_DEPTH)
|
if (workDirDepth < MAX_DIR_DEPTH)
|
||||||
workDirParents[workDirDepth++] = workDir;
|
workDirParents[workDirDepth++] = workDir;
|
||||||
#if ENABLED(SDCARD_SORT_ALPHA)
|
#if ENABLED(SDCARD_SORT_ALPHA)
|
||||||
|
@ -726,14 +727,13 @@ int8_t CardReader::updir() {
|
||||||
presort();
|
presort();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (!workDirDepth) flag.workDirIsRoot = true;
|
||||||
return workDirDepth;
|
return workDirDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardReader::setroot() {
|
void CardReader::setroot() {
|
||||||
/*if (!workDir.openRoot(&volume)) {
|
|
||||||
SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
|
|
||||||
}*/
|
|
||||||
workDir = root;
|
workDir = root;
|
||||||
|
flag.workDirIsRoot = true;
|
||||||
#if ENABLED(SDCARD_SORT_ALPHA)
|
#if ENABLED(SDCARD_SORT_ALPHA)
|
||||||
presort();
|
presort();
|
||||||
#endif
|
#endif
|
||||||
|
@ -801,7 +801,7 @@ void CardReader::setroot() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If there are files, sort up to the limit
|
// If there are files, sort up to the limit
|
||||||
uint16_t fileCnt = getnrfilenames();
|
uint16_t fileCnt = countFilesInWorkDir();
|
||||||
if (fileCnt > 0) {
|
if (fileCnt > 0) {
|
||||||
|
|
||||||
// Never sort more than the max allowed
|
// Never sort more than the max allowed
|
||||||
|
@ -981,7 +981,7 @@ uint16_t CardReader::get_num_Files() {
|
||||||
#if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
|
#if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
|
||||||
nrFiles // no need to access the SD card for filenames
|
nrFiles // no need to access the SD card for filenames
|
||||||
#else
|
#else
|
||||||
getnrfilenames()
|
countFilesInWorkDir()
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ typedef struct {
|
||||||
sdprinting:1,
|
sdprinting:1,
|
||||||
mounted:1,
|
mounted:1,
|
||||||
filenameIsDir:1,
|
filenameIsDir:1,
|
||||||
|
workDirIsRoot:1,
|
||||||
abort_sd_printing:1
|
abort_sd_printing:1
|
||||||
#if ENABLED(BINARY_FILE_TRANSFER)
|
#if ENABLED(BINARY_FILE_TRANSFER)
|
||||||
, binary_mode:1
|
, binary_mode:1
|
||||||
|
@ -79,7 +80,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void getfilename(uint16_t nr, const char* const match=nullptr);
|
static void getfilename(uint16_t nr, const char* const match=nullptr);
|
||||||
static uint16_t getnrfilenames();
|
static uint16_t countFilesInWorkDir();
|
||||||
|
|
||||||
static void getAbsFilename(char *t);
|
static void getAbsFilename(char *t);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue