fix(cpn): preserve current calibration when writing models and settings to radio (#6722)

This commit is contained in:
Neil Horne
2025-10-29 11:23:45 +10:00
committed by GitHub
parent dbab5745b6
commit edaba32e2b
10 changed files with 143 additions and 62 deletions
+70 -33
View File
@@ -62,57 +62,94 @@ void unregisterStorageFactories()
bool Storage::load(RadioData & radioData)
{
QFile file(filename);
if (!file.exists()) {
setError(tr("Unable to find file %1!").arg(filename));
if (!fileExists())
return false;
}
bool ret = false;
foreach (StorageFactory * factory, registeredStorageFactories) {
if (factory->probe(filename)) {
StorageFormat * format = factory->instance(filename);
if (format->load(radioData)) {
board = format->getBoard();
setWarning(format->warning());
ret = true;
delete format;
break;
}
else {
setError(format->error());
}
delete format;
StorageFormat *format = getStorageFormat();
if (format) {
if (format->load(radioData)) {
board = format->getBoard();
setWarning(format->warning());
ret = true;
} else {
setError(format->error());
}
delete format;
}
return ret;
}
bool Storage::write(const RadioData & radioData)
bool Storage::write(RadioData & radioData)
{
bool ret = false;
foreach (StorageFactory * factory, registeredStorageFactories) {
if (factory->probe(filename)) {
StorageFormat * format = factory->instance(filename);
ret = format->write(radioData);
delete format;
break;
}
StorageFormat *format = getStorageFormat();
if (format) {
ret = format->write(radioData);
delete format;
}
return ret;
}
bool Storage::writeModel(const RadioData & radioData, const int modelIndex)
{
bool ret = false;
foreach (StorageFactory * factory, registeredStorageFactories) {
if (factory->probe(filename)) {
StorageFormat * format = factory->instance(filename);
ret = format->writeModel(radioData, modelIndex);
delete format;
break;
}
StorageFormat *format = getStorageFormat();
if (format) {
ret = format->writeModel(radioData, modelIndex);
delete format;
}
return ret;
}
bool Storage::fileExists()
{
QFile file(filename);
if (!file.exists()) {
setError(tr("Unable to find file %1!").arg(filename));
return false;
}
return true;
}
StorageFormat * Storage::getStorageFormat()
{
foreach (StorageFactory * factory, registeredStorageFactories) {
if (factory->probe(filename))
return factory->instance(filename);
}
return nullptr;
}
bool Storage::load(GeneralSettings & generalSettings)
{
if (!fileExists())
return false;
bool ret = false;
StorageFormat *format = getStorageFormat();
if (format) {
if (format->load(generalSettings)) {
board = format->getBoard();
setWarning(format->warning());
ret = true;
}
else
setError(format->error());
delete format;
}
return ret;
}