From 5465984239138e8a551be9050f4ccd1572d4698b Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Mon, 27 Mar 2023 15:01:08 +1100 Subject: [PATCH] fix(cpn): Load models into slot based on filename for B&W radios (#3373) * Fix(cpn) - load models into slot based on filename for non-label radios * Check model filename index within bounds and if not skip file * Check if slot is free before loading file if not skip --- companion/src/storage/labeled.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/companion/src/storage/labeled.cpp b/companion/src/storage/labeled.cpp index 5744c6eb6..85a1559c3 100644 --- a/companion/src/storage/labeled.cpp +++ b/companion/src/storage/labeled.cpp @@ -241,7 +241,7 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData) if (match.size() == 3) { std::ssub_match modelFile = match[1]; std::ssub_match modelIdx = match[2]; - modelFiles.push_back({ modelFile.str(), "", std::stoi(modelIdx.str()) }); + modelFiles.push_back({ modelFile.str(), "", std::stoi(modelIdx.str()) }); } } } @@ -249,10 +249,26 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData) int modelIdx = 0; bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels); - radioData.models.resize(modelFiles.size()); + if (hasLabels) + radioData.models.resize(modelFiles.size()); + for (const auto& mc : modelFiles) { qDebug() << "Filename: " << mc.filename.c_str(); + if (!hasLabels) { + if (mc.modelIdx >= 0 && mc.modelIdx < (int)radioData.models.size()) { + modelIdx = mc.modelIdx; + if (!radioData.models[modelIdx].isEmpty()) { + qDebug() << QString("Warning: file %1 skipped as slot %2 already used").arg(mc.filename.c_str()).arg(mc.modelIdx + 1); + continue; + } + } + else { + qDebug() << QString("Warning: file %1 skipped as slot %2 not available").arg(mc.filename.c_str()).arg(mc.modelIdx + 1); + continue; + } + } + QByteArray modelBuffer; QString filename = "MODELS/" + QString::fromStdString(mc.filename); if (!loadFile(modelBuffer, filename)) { @@ -280,7 +296,7 @@ bool LabelsStorageFormat::loadYaml(RadioData & radioData) if (hasLabels && !strncmp(radioData.generalSettings.currModelFilename, model.filename, sizeof(model.filename))) { - radioData.generalSettings.currModelIndex = modelIdx; + radioData.generalSettings.currModelIndex = modelIdx; } model.used = true;