Don't rely on exception processing for normal flow.

Also make sure when we do update the json in the parent to use the
form that will create the object if it doesn't already exist.
This commit is contained in:
Jeff Young 2021-06-14 23:15:08 +01:00
parent fb46cd8bc5
commit 38312f0aca
1 changed files with 20 additions and 20 deletions

View File

@ -115,37 +115,37 @@ bool NESTED_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
if( !m_parent )
return false;
try
{
bool modified = Store();
try
{
nlohmann::json patch = nlohmann::json::diff( *m_internals,
m_parent->m_internals->Get<nlohmann::json>( m_path ) );
auto jsonObjectInParent = m_parent->GetJson( m_path );
modified |= !patch.empty();
}
catch( ... )
{
if( !jsonObjectInParent )
modified = true;
else if( !nlohmann::json::diff( *m_internals, jsonObjectInParent.value() ).empty() )
modified = true;
}
if( !modified && !aForce )
return false;
try
if( modified || aForce )
{
m_parent->m_internals->At( m_path ).update( *m_internals );
( *m_parent->m_internals )[m_path].update( *m_internals );
wxLogTrace( traceSettings, "Stored NESTED_SETTINGS %s with schema %d",
GetFilename(), m_schemaVersion );
GetFilename(),
m_schemaVersion );
}
return modified;
}
catch( ... )
{
wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not store to %s at %s",
m_filename, m_parent->GetFilename(), m_path );
}
m_filename,
m_parent->GetFilename(),
m_path );
return modified;
return false;
}
}