Skip to content

Commit

Permalink
fix(ui): Ignore hidden file when iterating SD card contents (#2925)
Browse files Browse the repository at this point in the history
* Ignore hidden file when iterating SD card contents.

* Fix compile error.
  • Loading branch information
philmoz authored and pfeerick committed Dec 23, 2022
1 parent 3e5e601 commit 60641b6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/file_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ static int scan_files(std::list<std::string>& files,
break; // Break on error or end of dir
// if (strlen((const char*)fno.fname) > SD_SCREEN_FILE_LENGTH)
// continue;
if (fno.fname[0] == '.' && fno.fname[1] != '.')
continue; // Ignore hidden files under UNIX, but not ..
if (fno.fattrib & (AM_HID|AM_SYS)) continue; /* Ignore hidden and system files */
if (fno.fname[0] == '.' && fno.fname[1] != '.') continue; // Ignore hidden files under UNIX, but not ..

if (fno.fattrib & AM_DIR) {
directories.push_back((char*)fno.fname);
Expand Down
33 changes: 14 additions & 19 deletions radio/src/gui/colorlcd/model_templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,22 @@ SelectTemplate::SelectTemplate(TemplatePage* tp)

if (res == FR_OK) {
// read all entries
bool firstTime = true;
for (;;) {
res = sdReadDir(&dir, &fno, firstTime);
firstTime = false;
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0)
break; // Break on error or end of dir
if (strlen((const char*)fno.fname) > SD_SCREEN_FILE_LENGTH)
continue;
if (fno.fname[0] == '.')
continue;
if (!(fno.fattrib & AM_DIR)) {
const char *ext = getFileExtension(fno.fname);
if(ext && !strcasecmp(ext, YAML_EXT)) {
int len = ext - fno.fname;
if (len < FF_MAX_LFN) {
char name[FF_MAX_LFN] = { 0 };
strncpy(name, fno.fname, len);
files.push_back(name);
}
if (fno.fattrib & (AM_DIR|AM_HID|AM_SYS)) continue; /* Ignore folders, hidden and system files */
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */

const char *ext = getFileExtension(fno.fname);
if(ext && !strcasecmp(ext, YAML_EXT)) {
int len = ext - fno.fname;
if (len < FF_MAX_LFN) {
char name[FF_MAX_LFN] = { 0 };
strncpy(name, fno.fname, len);
files.push_back(name);
}
}
}
Expand Down Expand Up @@ -203,16 +200,14 @@ SelectTemplateFolder::SelectTemplateFolder(std::function<void(void)> update)

if (res == FR_OK) {
// read all entries
bool firstTime = true;
for (;;) {
res = sdReadDir(&dir, &fno, firstTime);
firstTime = false;
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0)
break; // Break on error or end of dir
if (strlen((const char*)fno.fname) > SD_SCREEN_FILE_LENGTH)
continue;
if (fno.fname[0] == '.')
continue;
if (fno.fattrib & (AM_HID|AM_SYS)) continue; /* Ignore hidden and system files */
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
if (fno.fattrib & AM_DIR)
directories.push_back((char*)fno.fname);
}
Expand Down
5 changes: 2 additions & 3 deletions radio/src/gui/colorlcd/radio_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ static void scanLuaTools(std::list<ToolEntry>& scripts)
TCHAR path[FF_MAX_LFN+1] = SCRIPTS_TOOLS_PATH "/";
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) continue; /* Skip subfolders */
if (fno.fattrib & AM_HID) continue; /* Skip hidden files */
if (fno.fattrib & AM_SYS) continue; /* Skip system files */
if (fno.fattrib & (AM_DIR|AM_HID|AM_SYS)) continue; // skip subfolders, hidden files and system files
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */

strcat(path, fno.fname);
if (isRadioScriptTool(fno.fname)) {
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/common/stdlcd/radio_sdmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ void menuRadioSdManager(event_t _event)
res = sdReadDir(&dir, &fno, firstTime);
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (strlen(fno.fname) > SD_SCREEN_FILE_LENGTH) continue;
if (fno.fattrib & AM_HID) continue; /* Ignore Windows hidden files */
if (fno.fattrib & (AM_HID|AM_SYS)) continue; /* Ignore hidden and system files */
if (fno.fname[0] == '.' && fno.fname[1] != '.') continue; /* Ignore UNIX hidden files, but not .. */

reusableBuffer.sdManager.count++;
Expand Down
5 changes: 2 additions & 3 deletions radio/src/gui/common/stdlcd/radio_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ void menuRadioTools(event_t event)

res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) continue; /* Skip subfolders */
if (fno.fattrib & AM_HID) continue; /* Skip hidden files */
if (fno.fattrib & AM_SYS) continue; /* Skip system files */
if (fno.fattrib & (AM_DIR|AM_HID|AM_SYS)) continue; // skip subfolders, hidden files and system files
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */

strcat(path, fno.fname);
if (isRadioScriptTool(fno.fname)) {
Expand Down
5 changes: 2 additions & 3 deletions radio/src/sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) continue; /* Skip subfolders */
if (fno.fattrib & AM_HID) continue; /* Skip hidden files */
if (fno.fattrib & AM_SYS) continue; /* Skip system files */
if (fno.fattrib & (AM_DIR|AM_HID|AM_SYS)) continue; // skip subfolders, hidden files and system files
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */

fnExt = getFileExtension(fno.fname, 0, 0, &fnLen, &extLen);
fnLen -= extLen;
Expand Down

0 comments on commit 60641b6

Please sign in to comment.