diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp index 9073db71ef..ddf3389d82 100644 --- a/common/settings/json_settings.cpp +++ b/common/settings/json_settings.cpp @@ -73,6 +73,7 @@ JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation, m_createIfMissing( aCreateIfMissing ), m_createIfDefault( aCreateIfDefault ), m_writeFile( aWriteFile ), + m_modified( false ), m_deleteLegacyAfterMigration( true ), m_resetParamsIfMissing( true ), m_schemaVersion( aSchemaVersion ), @@ -351,6 +352,8 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory ) wxLogTrace( traceSettings, wxT( "Loaded <%s> with schema %d" ), GetFullFilename(), m_schemaVersion ); + m_modified = false; + // If we migrated, clean up the legacy file (with no extension) if( m_writeFile && ( legacy_migrated || migrated ) ) { @@ -371,15 +374,13 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory ) bool JSON_SETTINGS::Store() { - bool modified = false; - for( PARAM_BASE* param : m_params ) { - modified |= !param->MatchesFile( *this ); + m_modified |= !param->MatchesFile( *this ); param->Store( this ); } - return modified; + return m_modified; } @@ -502,6 +503,9 @@ bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce ) success = false; } + if( success ) + m_modified = false; + return success; } diff --git a/include/settings/json_settings.h b/include/settings/json_settings.h index a16fff9010..5afacf298f 100644 --- a/include/settings/json_settings.h +++ b/include/settings/json_settings.h @@ -109,7 +109,7 @@ public: /** * Stores the current parameters into the JSON document represented by this object * Note: this doesn't do any writing to disk; that's handled by SETTINGS_MANAGER - * @return true if any part of the JSON document was updated + * @return true if any part of the JSON document has been updated since the last save to disk */ virtual bool Store(); @@ -327,6 +327,9 @@ protected: /// Whether or not the backing store file should be written bool m_writeFile; + /// True if the JSON data store has been written to since the last file write + bool m_modified; + /// Whether or not to delete legacy file after migration bool m_deleteLegacyAfterMigration;