chore: Use isFileAvailable instead of f_open
This commit is contained in:
committed by
Peter Feerick
parent
15a19e1fef
commit
c088d1d2f9
@@ -299,24 +299,17 @@ void ThemeFile::applyBackground()
|
|||||||
auto pos = backgroundImageFileName.rfind('/');
|
auto pos = backgroundImageFileName.rfind('/');
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
auto rootDir = backgroundImageFileName.substr(0, pos + 1);
|
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;
|
if (isFileAvailable(rootDir.c_str())) {
|
||||||
FRESULT result = f_open(&file, rootDir.c_str(), FA_OPEN_EXISTING);
|
|
||||||
if (result == FR_OK) {
|
|
||||||
instance->setBackgroundImageFileName((char *)rootDir.c_str());
|
instance->setBackgroundImageFileName((char *)rootDir.c_str());
|
||||||
f_close(&file);
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: This needs to be made user configurable, not
|
// TODO: This needs to be made user configurable, not
|
||||||
// require the file be deleted to remove global background
|
// require the file be deleted to remove global background
|
||||||
char fileName[FF_MAX_LFN + 1];
|
std::string fileName = THEMES_PATH PATH_SEPARATOR "EdgeTX/background.png";
|
||||||
fileName[FF_MAX_LFN] = '\0';
|
if (isFileAvailable(fileName.c_str())) {
|
||||||
strncpy(fileName, THEMES_PATH, FF_MAX_LFN);
|
instance->setBackgroundImageFileName(fileName.c_str());
|
||||||
strcat(fileName, "/EdgeTX/background.png");
|
|
||||||
result = f_open(&file, fileName, FA_OPEN_EXISTING);
|
|
||||||
if (result == FR_OK) {
|
|
||||||
instance->setBackgroundImageFileName(fileName);
|
|
||||||
f_close(&file);
|
|
||||||
} else {
|
} else {
|
||||||
instance->setBackgroundImageFileName("");
|
instance->setBackgroundImageFileName("");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user