diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp index 6a4c01d083..5c2e177d7d 100644 --- a/common/settings/json_settings.cpp +++ b/common/settings/json_settings.cpp @@ -269,6 +269,9 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory ) /* allow_exceptions = */ true, /* ignore_comments = */ true ); + // Save whatever we loaded, before doing any migration etc + m_internals->m_original = *static_cast( m_internals.get() ); + // If parse succeeds, check if schema migration is required int filever = -1; @@ -438,10 +441,14 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce ) LOCALE_IO dummy; bool success = true; + nlohmann::json toSave = m_internals->m_original; + + toSave.update( m_internals->begin(), m_internals->end(), /* merge_objects = */ true ); + try { std::stringstream buffer; - buffer << std::setw( 2 ) << *m_internals << std::endl; + buffer << std::setw( 2 ) << toSave << std::endl; wxFFileOutputStream fileStream( path.GetFullPath(), "wb" ); diff --git a/include/settings/json_settings_internals.h b/include/settings/json_settings_internals.h index d34f46d14c..f7b0d2feb2 100644 --- a/include/settings/json_settings_internals.h +++ b/include/settings/json_settings_internals.h @@ -73,6 +73,10 @@ public: nlohmann::json::json_pointer root( "" ); this->nlohmann::json::operator[]( root ) = aOther.nlohmann::json::operator[]( root ); } + +private: + + nlohmann::json m_original; }; #endif // KICAD_JSON_SETTINGS_INTERNALS_H