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);
|
bool hasLabels = getCurrentFirmware()->getCapability(HasModelLabels);
|
||||||
|
|
||||||
// B&W radios do not use the models.yml file and scan the MODELS folder for modelxx.yml files
|
// fetch "MODELS/modelXX.yml"
|
||||||
// models have been deleted or reordered in Companion so delete all old modelxx.yml and just in case models.yml files
|
std::list<std::string> filelist;
|
||||||
// from radio MODELS folder before writing new modelxx.yml files
|
if (!getFileList(filelist)) {
|
||||||
if (!hasLabels) {
|
setError(tr("Cannot list files"));
|
||||||
// fetch "MODELS/modelXX.yml"
|
return false;
|
||||||
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)");
|
// Delete all old modelxx.yml from radio MODELS folder before writing new modelxx.yml files
|
||||||
for(const auto& f : filelist) {
|
const std::regex yml_regex("MODELS/(model([0-9s]+)\\.yml)");
|
||||||
std::smatch match;
|
for(const auto& f : filelist) {
|
||||||
if (std::regex_match(f, match, yml_regex)) {
|
std::smatch match;
|
||||||
if (match.size() == 3) {
|
if (std::regex_match(f, match, yml_regex)) {
|
||||||
if (!deleteFile(QString(f.c_str()))) {
|
if (match.size() == 3) {
|
||||||
return false;
|
if (!deleteFile(QString(f.c_str()))) {
|
||||||
}
|
setError(tr("Error deleting files"));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user