From c088d1d2f9414940c4850b35468f0cbdb02de6d4 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sun, 7 Aug 2022 17:52:07 +1000 Subject: [PATCH] chore: Use `isFileAvailable` instead of `f_open` --- radio/src/gui/colorlcd/theme_manager.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/radio/src/gui/colorlcd/theme_manager.cpp b/radio/src/gui/colorlcd/theme_manager.cpp index 89cbbb14b..0f1a2cff2 100644 --- a/radio/src/gui/colorlcd/theme_manager.cpp +++ b/radio/src/gui/colorlcd/theme_manager.cpp @@ -299,24 +299,17 @@ void ThemeFile::applyBackground() auto pos = backgroundImageFileName.rfind('/'); if (pos != std::string::npos) { auto rootDir = backgroundImageFileName.substr(0, pos + 1); - rootDir = rootDir + "background_" + std::to_string(LCD_W) + "x" + std::to_string(LCD_H) + ".png"; + rootDir = rootDir + "background_" + std::to_string(LCD_W) + "x" + + std::to_string(LCD_H) + ".png"; - FIL file; - FRESULT result = f_open(&file, rootDir.c_str(), FA_OPEN_EXISTING); - if (result == FR_OK) { + if (isFileAvailable(rootDir.c_str())) { instance->setBackgroundImageFileName((char *)rootDir.c_str()); - f_close(&file); } else { // TODO: This needs to be made user configurable, not // require the file be deleted to remove global background - char fileName[FF_MAX_LFN + 1]; - fileName[FF_MAX_LFN] = '\0'; - strncpy(fileName, THEMES_PATH, FF_MAX_LFN); - strcat(fileName, "/EdgeTX/background.png"); - result = f_open(&file, fileName, FA_OPEN_EXISTING); - if (result == FR_OK) { - instance->setBackgroundImageFileName(fileName); - f_close(&file); + std::string fileName = THEMES_PATH PATH_SEPARATOR "EdgeTX/background.png"; + if (isFileAvailable(fileName.c_str())) { + instance->setBackgroundImageFileName(fileName.c_str()); } else { instance->setBackgroundImageFileName(""); }