From 86d0ac674501bb75711268f6e3a8517566073143 Mon Sep 17 00:00:00 2001 From: Kelly Byrd Date: Fri, 3 Feb 2017 11:55:18 -0800 Subject: [PATCH] Fixes #4368: Don't duplicate categories in OTX's models.txt (#4370) --- companion/src/storage/categorized.cpp | 49 +++++++++++++++------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 07068f903..c9bfc310c 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -114,20 +114,19 @@ bool CategorizedStorageFormat::load(RadioData & radioData) bool CategorizedStorageFormat::write(const RadioData & radioData) { - // models.txt - QByteArray modelsList; - int currentCategoryIndex = -1; + QByteArray modelsList; // models.txt + QByteArray radioSettingsData; // radio.bin + size_t numModels = radioData.models.size(); + size_t numCategories = radioData.categories.size(); + std::vector> sortedModels(numCategories); - // radio.bin - QByteArray radioSettingsData; writeRadioSettingsToByteArray(radioData.generalSettings, radioSettingsData); if (!writeFile(radioSettingsData, "RADIO/radio.bin")) { return false; } - // all models - for (unsigned int i=0; igetCapability(HasModelCategories)) { - int categoryIndex = model.category; - if (currentCategoryIndex != categoryIndex) { - modelsList.append(QString().sprintf("[%s]\n", radioData.categories[model.category].name)); - currentCategoryIndex = categoryIndex; + + // For firmware that doesn't support categories, we can just construct + // models.txt as we iterate thru the models vector. For firmware that does + // support categories, we have a bit of work to do in order to sort the + // models first by category index, so we use the sortedModels data + // structure to do that. + if (!getCurrentFirmware()->getCapability(HasModelCategories)) { + // Use format with model number and file name. This is needed because + // radios without category support can have unused model slots + modelsList.append(QString("%1 %2\n").arg(m).arg(model.filename)); + } else { + sortedModels[model.category].push_back(QString("%1\n").arg(model.filename)); + } + } + + if (getCurrentFirmware()->getCapability(HasModelCategories)) { + for (size_t c=0; c