Add checks to prevent files being saved before being fully read.

This commit is contained in:
AdenKoperczak 2025-01-29 11:04:17 -05:00
parent f3c846f0b1
commit bc79ed11a3
5 changed files with 31 additions and 1 deletions

View file

@ -60,6 +60,8 @@ public:
void WriteMarkerSettings();
std::shared_ptr<MarkerRecord> GetMarkerByName(const std::string& name);
bool markerFileRead_ {false};
void InitalizeIds();
types::MarkerId NewId();
types::MarkerId lastId_ {0};
@ -209,11 +211,16 @@ void MarkerManager::Impl::ReadMarkerSettings()
}
}
markerFileRead_ = true;
Q_EMIT self_->MarkersUpdated();
}
void MarkerManager::Impl::WriteMarkerSettings()
{
if (!markerFileRead_)
{
return;
}
logger_->info("Saving location marker settings");
const std::shared_lock lock(markerRecordLock_);

View file

@ -70,6 +70,8 @@ public:
boost::unordered_flat_map<std::string, std::shared_ptr<PlacefileRecord>>
placefileRecordMap_ {};
std::shared_mutex placefileRecordLock_ {};
bool placefileSettingsRead_ {false};
};
class PlacefileManager::Impl::PlacefileRecord
@ -413,10 +415,15 @@ void PlacefileManager::Impl::ReadPlacefileSettings()
}
}
}
placefileSettingsRead_ = true;
}
void PlacefileManager::Impl::WritePlacefileSettings()
{
if (!placefileSettingsRead_)
{
return;
}
logger_->info("Saving placefile settings");
std::shared_lock lock {placefileRecordLock_};

View file

@ -67,9 +67,10 @@ void SettingsManager::Initialize()
}
p->settingsPath_ = appDataPath + "/settings.json";
p->initialized_ = true;
ReadSettings(p->settingsPath_);
p->initialized_ = true;
p->ValidateSettings();
}

View file

@ -96,6 +96,8 @@ public:
manager::PlacefileManager::Instance()};
types::LayerVector layers_ {};
bool fileRead_ {false};
};
LayerModel::LayerModel(QObject* parent) :
@ -201,6 +203,8 @@ void LayerModel::Impl::ReadLayerSettings()
// Assign read layers
layers_.swap(newLayers);
}
fileRead_ = true;
}
void LayerModel::Impl::ValidateLayerSettings(types::LayerVector& layers)
@ -314,6 +318,10 @@ void LayerModel::Impl::ValidateLayerSettings(types::LayerVector& layers)
void LayerModel::Impl::WriteLayerSettings()
{
if (!fileRead_)
{
return;
}
logger_->info("Saving layer settings");
auto layerJson = boost::json::value_from(layers_);

View file

@ -68,6 +68,8 @@ public:
scwx::common::Coordinate previousPosition_;
QIcon starIcon_ {":/res/icons/font-awesome-6/star-solid.svg"};
bool presetsRead_ {false};
};
RadarSiteModel::RadarSiteModel(QObject* parent) :
@ -146,10 +148,15 @@ void RadarSiteModelImpl::ReadPresets()
}
}
}
presetsRead_ = true;
}
void RadarSiteModelImpl::WritePresets()
{
if (!presetsRead_)
{
return;
}
logger_->info("Saving presets");
auto presetsJson = boost::json::value_from(presets_);