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.
This commit is contained in:
@@ -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<std::string> filelist;
|
||||
if (!getFileList(filelist)) {
|
||||
setError(tr("Cannot list files"));
|
||||
return false;
|
||||
}
|
||||
// fetch "MODELS/modelXX.yml"
|
||||
std::list<std::string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user