From 60ef3a545d9420dc771dfd48a051d6d553b56d12 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 17 Jan 2023 14:05:33 +1100 Subject: [PATCH] fix(cpn): Delete old models from radio before saving new models (#3020) * Delete model files from radio before saving them from Companion. * Update comments. Show error if file delete fails. --- companion/src/storage/labeled.cpp | 33 ++++++++++++++----------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/companion/src/storage/labeled.cpp b/companion/src/storage/labeled.cpp index 4175ef297..5744c6eb6 100644 --- a/companion/src/storage/labeled.cpp +++ b/companion/src/storage/labeled.cpp @@ -312,25 +312,22 @@ bool LabelsStorageFormat::writeYaml(const RadioData & radioData) bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels); - // B&W radios do not use the models.yml file and scan the MODELS folder for modelxx.yml files - // models have been deleted or reordered in Companion so delete all old modelxx.yml and just in case models.yml files - // from radio MODELS folder before writing new modelxx.yml files - if (!hasLabels) { - // fetch "MODELS/modelXX.yml" - std::list filelist; - if (!getFileList(filelist)) { - setError(tr("Cannot list files")); - return false; - } + // fetch "MODELS/modelXX.yml" + std::list filelist; + if (!getFileList(filelist)) { + setError(tr("Cannot list files")); + return false; + } - const std::regex yml_regex("MODELS/(model([0-9s]+)\\.yml)"); - for(const auto& f : filelist) { - std::smatch match; - if (std::regex_match(f, match, yml_regex)) { - if (match.size() == 3) { - if (!deleteFile(QString(f.c_str()))) { - return false; - } + // Delete all old modelxx.yml from radio MODELS folder before writing new modelxx.yml files + const std::regex yml_regex("MODELS/(model([0-9s]+)\\.yml)"); + for(const auto& f : filelist) { + std::smatch match; + if (std::regex_match(f, match, yml_regex)) { + if (match.size() == 3) { + if (!deleteFile(QString(f.c_str()))) { + setError(tr("Error deleting files")); + return false; } } }