Fix model names on model select page with not yet converted models

Resolves #248
This commit is contained in:
Raphael Coeffic
2021-06-19 14:49:05 +02:00
parent cf5bb8d501
commit 82f60cdc81
3 changed files with 25 additions and 8 deletions
+19 -4
View File
@@ -108,15 +108,30 @@ class ModelButton : public Button
if (strncmp(modelCell->modelFilename, g_eeGeneral.currModelFilename,
LEN_MODEL_FILENAME) == 0) {
memcpy(&partialModel.header, &g_model.header, sizeof(partialModel));
version = EEPROM_VER;
} else {
error =
readModel(modelCell->modelFilename, (uint8_t *)&partialModel.header,
sizeof(partialModel), &version);
if (!error) {
if (modelCell->modelName[0] == '\0' &&
partialModel.header.name[0] != '\0') {
modelCell->setModelName(partialModel.header.name);
}
if (!error) {
if (modelCell->modelName[0] == '\0' &&
partialModel.header.name[0] != '\0') {
if (version == 219) {
size_t len = sizeof(partialModel.header.name);
char* str = partialModel.header.name;
for (int i=0; i < len; i++) {
str[i] = zchar2char(str[i]);
}
// Trim string
while(len > 0 && str[len-1]) {
if (str[len - 1] != ' ' && str[len - 1] != '\0') break;
str[--len] = '\0';
}
}
modelCell->setModelName(partialModel.header.name);
}
}
@@ -59,6 +59,9 @@ void convertRadioData(int version)
RAISE_ALERT(STR_STORAGE_WARNING, STR_SDCARD_CONVERSION_REQUIRE, NULL,
AU_NONE);
// Load models list before converting
modelslist.load();
unsigned converted = 0;
auto to_convert = modelslist.getModelsCount() + 1;
@@ -76,9 +79,6 @@ void convertRadioData(int version)
RTOS_WAIT_MS(200);
#endif
// Load models list before converting
modelslist.load();
const char* error = nullptr;
for (auto category_ptr : modelslist.getCategories()) {
for (auto model_ptr : *category_ptr) {
+3 -1
View File
@@ -48,7 +48,9 @@ ModelCell::~ModelCell()
void ModelCell::setModelName(char * name)
{
strncpy(modelName, name, LEN_MODEL_NAME);
if (modelName[0] == 0) {
modelName[LEN_MODEL_NAME] = '\0';
if (modelName[0] == '\0') {
char * tmp;
strncpy(modelName, modelFilename, LEN_MODEL_NAME);
tmp = (char *) memchr(modelName, '.', LEN_MODEL_NAME);