diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index e98c3e5239..18c0dedfb1 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -589,6 +589,10 @@ bool PROJECT_FILE::SaveToFile( const wxString& aDirectory, bool aForce ) Set( "meta.filename", m_project->GetProjectName() + "." + FILEEXT::ProjectFileExtension ); + // If we're actually going ahead and doing the save, the flag that keeps code from doing the save + // should be cleared at this point + m_wasMigrated = false; + return JSON_SETTINGS::SaveToFile( aDirectory, aForce ); } @@ -631,6 +635,10 @@ bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile ) updatePathByPtr( "schematic.ngspice.workbook_filename" ); updatePathByPtr( "pcbnew.page_layout_descr_file" ); + // If we're actually going ahead and doing the save, the flag that keeps code from doing the save + // should be cleared at this point + m_wasMigrated = false; + // While performing Save As, we have already checked that we can write to the directory // so don't carry the previous flag SetReadOnly( false ); diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp index da76f21d6e..87f132695c 100644 --- a/common/settings/json_settings.cpp +++ b/common/settings/json_settings.cpp @@ -79,6 +79,7 @@ JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation, m_deleteLegacyAfterMigration( true ), m_resetParamsIfMissing( true ), m_schemaVersion( aSchemaVersion ), + m_isFutureFormat( false ), m_manager( nullptr ) { m_internals = std::make_unique<JSON_SETTINGS_INTERNALS>(); @@ -325,6 +326,7 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory ) wxLogTrace( traceSettings, wxT( "%s: warning: file version %d is newer than latest (%d)" ), GetFullFilename(), filever, m_schemaVersion ); + m_isFutureFormat = true; } } else diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index febe9ebf9f..062e1936b7 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -1185,7 +1185,7 @@ bool SETTINGS_MANAGER::unloadProjectFile( PROJECT* aProject, bool aSave ) PROJECT_FILE* file = m_project_files[name]; - if( file->WasMigrated() ) + if( !file->ShouldAutoSave() ) aSave = false; auto it = std::find_if( m_settings.begin(), m_settings.end(), @@ -1198,7 +1198,7 @@ bool SETTINGS_MANAGER::unloadProjectFile( PROJECT* aProject, bool aSave ) { wxString projectPath = GetPathForSettingsFile( it->get() ); - bool saveLocalSettings = aSave && !aProject->GetLocalSettings().WasMigrated(); + bool saveLocalSettings = aSave && aProject->GetLocalSettings().ShouldAutoSave(); FlushAndRelease( &aProject->GetLocalSettings(), saveLocalSettings ); diff --git a/include/project/project_file.h b/include/project/project_file.h index 0516d52341..76c75fa510 100644 --- a/include/project/project_file.h +++ b/include/project/project_file.h @@ -104,9 +104,9 @@ public: } /** - * @return true if the local settings needed to be migrated, and shouldn't be auto-saved + * @return true if it should be safe to auto-save this file without user action */ - bool WasMigrated() const { return m_wasMigrated; } + bool ShouldAutoSave() const { return !m_wasMigrated && !m_isFutureFormat; } protected: wxString getFileExt() const override; diff --git a/include/project/project_local_settings.h b/include/project/project_local_settings.h index 03e6194ed5..691ca0856a 100644 --- a/include/project/project_local_settings.h +++ b/include/project/project_local_settings.h @@ -72,9 +72,9 @@ public: void ClearFileState(); /** - * @return true if the local settings needed to be migrated, and shouldn't be auto-saved + * @return true if it should be safe to auto-save this file without user action */ - bool WasMigrated() const { return m_wasMigrated; } + bool ShouldAutoSave() const { return !m_wasMigrated && !m_isFutureFormat; } protected: wxString getFileExt() const override diff --git a/include/settings/json_settings.h b/include/settings/json_settings.h index fe6d0e9ded..52fd09d238 100644 --- a/include/settings/json_settings.h +++ b/include/settings/json_settings.h @@ -332,6 +332,9 @@ protected: /// Version of this settings schema. int m_schemaVersion; + /// Set to true if this settings is loaded from a file with a newer schema version than is known + bool m_isFutureFormat; + /// A pointer to the settings manager managing this file (may be null) SETTINGS_MANAGER* m_manager; diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index d00eee0bd3..e4d445163c 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -602,8 +602,8 @@ bool KICAD_MANAGER_FRAME::CloseProject( bool aSave ) if( !Kiway().PlayersClose( false ) ) return false; - bool shouldSaveProject = !Prj().GetLocalSettings().WasMigrated() - && !Prj().GetProjectFile().WasMigrated(); + bool shouldSaveProject = Prj().GetLocalSettings().ShouldAutoSave() + && Prj().GetProjectFile().ShouldAutoSave(); // Save the project file for the currently loaded project. if( m_active_project ) diff --git a/kicad/tools/kicad_manager_control.cpp b/kicad/tools/kicad_manager_control.cpp index 31d3f35e87..3432d0aa79 100644 --- a/kicad/tools/kicad_manager_control.cpp +++ b/kicad/tools/kicad_manager_control.cpp @@ -809,7 +809,7 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent ) // Save window state to disk now. Don't wait around for a crash. if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !player->GetCurrentFileName().IsEmpty() - && !Prj().GetLocalSettings().WasMigrated() ) + && Prj().GetLocalSettings().ShouldAutoSave() ) { wxFileName rfn( player->GetCurrentFileName() ); rfn.MakeRelativeTo( Prj().GetProjectPath() ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 265d7bb49d..d54f3e7293 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -1168,7 +1168,7 @@ void PCB_EDIT_FRAME::doCloseWindow() } // Make sure local settings are persisted - if( !Prj().GetLocalSettings().WasMigrated() ) + if( Prj().GetLocalSettings().ShouldAutoSave() ) SaveProjectLocalSettings(); else wxLogTrace( traceAutoSave, wxT( "Skipping auto-save of migrated local settings" ) );