fix(color): Bitmap name truncation if exactly 14 characters long (#4232)

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
philmoz
2023-10-31 11:40:49 +10:00
committed by GitHub
co-authored by Peter Feerick
parent ba30278456
commit f5593c44e8
7 changed files with 21 additions and 22 deletions
+5 -5
View File
@@ -239,14 +239,14 @@ void copySelection(char * dst, const char * src, uint8_t size)
void onModelSetupBitmapMenu(const char * result)
{
if (result == STR_UPDATE_LIST) {
if (!sdListFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(g_model.header.bitmap), nullptr)) {
if (!sdListFiles(BITMAPS_PATH, BITMAPS_EXT, LEN_BITMAP_NAME, nullptr)) {
POPUP_WARNING(STR_NO_BITMAPS_ON_SD);
}
}
else if (result != STR_EXIT) {
// The user choosed a bmp file in the list
copySelection(g_model.header.bitmap, result, sizeof(g_model.header.bitmap));
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap));
copySelection(g_model.header.bitmap, result, LEN_BITMAP_NAME);
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, LEN_BITMAP_NAME);
storageDirty(EE_MODEL);
}
}
@@ -641,12 +641,12 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_BITMAP:
lcdDrawTextAlignedLeft(y, STR_BITMAP);
if (ZEXIST(g_model.header.bitmap))
lcdDrawSizedText(MODEL_SETUP_2ND_COLUMN, y, g_model.header.bitmap, sizeof(g_model.header.bitmap), attr);
lcdDrawSizedText(MODEL_SETUP_2ND_COLUMN, y, g_model.header.bitmap, LEN_BITMAP_NAME, attr);
else
lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, STR_VCSWFUNC, 0, attr);
if (attr && event==EVT_KEY_BREAK(KEY_ENTER) && READ_ONLY_UNLOCKED()) {
s_editMode = 0;
if (sdListFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(g_model.header.bitmap), g_model.header.bitmap, LIST_NONE_SD_FILE)) {
if (sdListFiles(BITMAPS_PATH, BITMAPS_EXT, LEN_BITMAP_NAME, g_model.header.bitmap, LIST_NONE_SD_FILE)) {
POPUP_MENU_START(onModelSetupBitmapMenu);
}
else {
+5 -8
View File
@@ -66,19 +66,16 @@ struct ModelNameEdit : public ModelTextEdit {
static std::string getModelBitmap()
{
return std::string(g_model.header.bitmap, sizeof(g_model.header.bitmap));
return std::string(g_model.header.bitmap, LEN_BITMAP_NAME);
}
static void setModelBitmap(std::string newValue)
{
strncpy(g_model.header.bitmap, newValue.c_str(),
sizeof(g_model.header.bitmap));
g_model.header.bitmap[sizeof(g_model.header.bitmap)-1] = '\0';
strncpy(g_model.header.bitmap, newValue.c_str(), LEN_BITMAP_NAME);
auto model = modelslist.getCurrentModel();
if (model) {
strncpy(model->modelBitmap, newValue.c_str(),
sizeof(ModelCell::modelBitmap));
model->modelBitmap[sizeof(ModelCell::modelBitmap)-1] = '\0';
strncpy(model->modelBitmap, newValue.c_str(), LEN_BITMAP_NAME);
model->modelBitmap[LEN_BITMAP_NAME] = '\0';
}
SET_DIRTY();
}
@@ -86,7 +83,7 @@ static void setModelBitmap(std::string newValue)
struct ModelBitmapEdit : public FileChoice {
ModelBitmapEdit(Window *parent, const rect_t &rect) :
FileChoice(parent, rect, BITMAPS_PATH, BITMAPS_EXT,
sizeof(g_model.header.bitmap), getModelBitmap, setModelBitmap)
LEN_BITMAP_NAME, getModelBitmap, setModelBitmap)
{
}
};
+5 -3
View File
@@ -363,12 +363,14 @@ void RadioSdManagerPage::fileAction(const char* path, const char* name,
MultiFirmwareUpdate(fullpath, EXTERNAL_MODULE, MULTI_TYPE_ELRS);
});
} else if (!strcasecmp(BITMAPS_PATH, path) &&
isExtensionMatching(ext, BITMAPS_EXT)) {
isExtensionMatching(ext, BITMAPS_EXT) &&
strlen(name) <= LEN_BITMAP_NAME) {
menu->addLine(STR_ASSIGN_BITMAP, [=]() {
memcpy(g_model.header.bitmap, name, sizeof(g_model.header.bitmap));
memcpy(g_model.header.bitmap, name, LEN_BITMAP_NAME);
storageDirty(EE_MODEL);
});
} else if (!strcasecmp(ext, TEXT_EXT) || !strcasecmp(ext, LOGS_EXT) || !strcasecmp(ext, SCRIPT_EXT)) {
} else if (!strcasecmp(ext, TEXT_EXT) || !strcasecmp(ext, LOGS_EXT) ||
!strcasecmp(ext, SCRIPT_EXT)) {
menu->addLine(STR_VIEW_TEXT, [=]() {
FIL file;
if (FR_OK == f_open(&file, fullpath, FA_OPEN_EXISTING | FA_READ)) {
+1 -1
View File
@@ -97,7 +97,7 @@ class ModelBitmapWidget: public Widget
uint32_t getHash()
{
return hash(g_model.header.bitmap, sizeof(g_model.header.bitmap));
return hash(g_model.header.bitmap, LEN_BITMAP_NAME);
}
void loadBitmap()
@@ -170,8 +170,8 @@ void onSdManagerMenu(const char * result)
}
#if LCD_DEPTH > 1
else if (result == STR_ASSIGN_BITMAP) {
strAppendFilename(g_model.header.bitmap, line, sizeof(g_model.header.bitmap));
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap));
strAppendFilename(g_model.header.bitmap, line, LEN_BITMAP_NAME);
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, LEN_BITMAP_NAME);
storageDirty(EE_MODEL);
}
#endif
@@ -363,7 +363,7 @@ void menuRadioSdManager(event_t _event)
}
#if LCD_DEPTH > 1
else if (isExtensionMatching(ext, BITMAPS_EXT)) {
if (!READ_ONLY() && (ext-line) <= (int)sizeof(g_model.header.bitmap)) {
if (!READ_ONLY() && (ext-line) <= LEN_BITMAP_NAME) {
POPUP_MENU_ADD_ITEM(STR_ASSIGN_BITMAP);
}
}
+1 -1
View File
@@ -112,7 +112,7 @@ static int luaModelSetInfo(lua_State *L)
#if LCD_DEPTH > 1
else if (!strcmp(key, "bitmap")) {
const char * name = luaL_checkstring(L, -1);
strncpy(g_model.header.bitmap, name, sizeof(g_model.header.bitmap));
strncpy(g_model.header.bitmap, name, LEN_BITMAP_NAME);
}
#endif
}
+1 -1
View File
@@ -1350,7 +1350,7 @@ void ModelsList::updateCurrentModelCell()
if (currentModel) {
#if LEN_BITMAP_NAME > 0
strncpy(currentModel->modelBitmap, g_model.header.bitmap, LEN_BITMAP_NAME);
currentModel->modelBitmap[LEN_BITMAP_NAME - 1] = '\0';
currentModel->modelBitmap[LEN_BITMAP_NAME] = '\0';
#endif
strncpy(currentModel->modelFilename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
currentModel->modelFilename[LEN_MODEL_FILENAME] = '\0';