diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 7c5b88dc8..878757294 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -65,7 +65,9 @@ bool loadModelsListFromYaml(std::vector& categories, for (const auto& model : models) { std::string filename; model["filename"] >> filename; - modelFiles.push_back({ filename, categories.size()-1 }); + std::string name; + model["name"] >> name; + modelFiles.push_back({filename, name, (int)categories.size() - 1}); } } } @@ -124,14 +126,15 @@ bool writeModelsListToYaml(const std::vector& categories, for (const auto& modelFile: modelFiles) { YAML::Node cat_attrs; - cat_attrs["filename"] = modelFile.first; + cat_attrs["filename"] = modelFile.filename; + cat_attrs["name"] = modelFile.name; - if (modelFile.second >= (int)categories.size()) { + if (modelFile.category >= (int)categories.size()) { return false; } - const std::string cat_name = categories[modelFile.second].name; - node[modelFile.second][cat_name].push_back(cat_attrs); + const std::string cat_name = categories[modelFile.category].name; + node[modelFile.category][cat_name].push_back(cat_attrs); } writeYamlToByteArray(node, data); diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index e82771562..60b69119d 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -29,8 +29,13 @@ constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 }; -typedef std::pair EtxModelfileCategoryPair; -typedef std::list EtxModelfiles; +struct EtxModelMetadata { + std::string filename; + std::string name; + int category; +}; + +typedef std::list EtxModelfiles; bool loadModelsListFromYaml(std::vector& categories, EtxModelfiles& modelFiles, diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 3f89b431f..58e7c7ba0 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -258,10 +258,10 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) int modelIdx = 0; for (const auto& mc : modelFiles) { - qDebug() << "Filename: " << mc.first.c_str() << " / Category: " << mc.second; + qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category; QByteArray modelBuffer; - QString filename = "MODELS/" + QString::fromStdString(mc.first); + QString filename = "MODELS/" + QString::fromStdString(mc.filename); if (!loadFile(modelBuffer, filename)) { setError(tr("Can't extract ") + filename); return false; @@ -277,9 +277,9 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) return false; } - model.category = mc.second; + model.category = mc.category; model.modelIndex = modelIdx; - strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1); + strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1); model.used = true; modelIdx++; @@ -317,7 +317,8 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) QString modelFilename; if (hasCategories) { modelFilename = QString("MODELS/%1").arg(model.filename); - modelFiles.push_back({ std::string(model.filename), model.category }); + modelFiles.push_back({std::string(model.filename), + std::string(model.name), model.category}); } else { modelFilename = QString("MODELS/model%1.yml") .arg(model.modelIndex, 2, 10, QLatin1Char('0'));