Don't autosave future formats of project settings

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19910

(cherry picked from commit 7d689e0c616c8af4b056f20ce3c95c37624e3df7)
This commit is contained in:
Jon Evans 2025-02-10 18:31:18 -05:00
parent 21ae2b833e
commit 5426bfcdcd
10 changed files with 21 additions and 12 deletions

View File

@ -680,6 +680,10 @@ bool PROJECT_FILE::SaveAs( const wxString& aDirectory, const wxString& aFile )
updatePathByPtr( "schematic.ngspice.workbook_filename" ); updatePathByPtr( "schematic.ngspice.workbook_filename" );
updatePathByPtr( "pcbnew.page_layout_descr_file" ); 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 // While performing Save As, we have already checked that we can write to the directory
// so don't carry the previous flag // so don't carry the previous flag
SetReadOnly( false ); SetReadOnly( false );

View File

@ -77,6 +77,7 @@ JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation,
m_deleteLegacyAfterMigration( true ), m_deleteLegacyAfterMigration( true ),
m_resetParamsIfMissing( true ), m_resetParamsIfMissing( true ),
m_schemaVersion( aSchemaVersion ), m_schemaVersion( aSchemaVersion ),
m_isFutureFormat( false ),
m_manager( nullptr ) m_manager( nullptr )
{ {
m_internals = std::make_unique<JSON_SETTINGS_INTERNALS>(); m_internals = std::make_unique<JSON_SETTINGS_INTERNALS>();
@ -326,6 +327,7 @@ bool JSON_SETTINGS::LoadFromFile( const wxString& aDirectory )
GetFullFilename(), GetFullFilename(),
filever, filever,
m_schemaVersion ); m_schemaVersion );
m_isFutureFormat = true;
} }
} }
else else

View File

@ -1202,7 +1202,7 @@ bool SETTINGS_MANAGER::unloadProjectFile( PROJECT* aProject, bool aSave )
PROJECT_FILE* file = m_project_files[name]; PROJECT_FILE* file = m_project_files[name];
if( file->WasMigrated() ) if( !file->ShouldAutoSave() )
aSave = false; aSave = false;
auto it = std::find_if( m_settings.begin(), m_settings.end(), auto it = std::find_if( m_settings.begin(), m_settings.end(),
@ -1215,7 +1215,7 @@ bool SETTINGS_MANAGER::unloadProjectFile( PROJECT* aProject, bool aSave )
{ {
wxString projectPath = GetPathForSettingsFile( it->get() ); wxString projectPath = GetPathForSettingsFile( it->get() );
bool saveLocalSettings = aSave && !aProject->GetLocalSettings().WasMigrated(); bool saveLocalSettings = aSave && aProject->GetLocalSettings().ShouldAutoSave();
FlushAndRelease( &aProject->GetLocalSettings(), saveLocalSettings ); FlushAndRelease( &aProject->GetLocalSettings(), saveLocalSettings );

View File

@ -1098,7 +1098,7 @@ void SCH_EDIT_FRAME::doCloseWindow()
} }
// Make sure local settings are persisted // Make sure local settings are persisted
if( !Prj().GetLocalSettings().WasMigrated() ) if( Prj().GetLocalSettings().ShouldAutoSave() )
SaveProjectLocalSettings(); SaveProjectLocalSettings();
// Shutdown all running tools // Shutdown all running tools

View File

@ -106,9 +106,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: protected:
wxString getFileExt() const override; wxString getFileExt() const override;

View File

@ -73,9 +73,9 @@ public:
void ClearFileState(); 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: protected:
wxString getFileExt() const override wxString getFileExt() const override

View File

@ -339,6 +339,9 @@ protected:
/// Version of this settings schema. /// Version of this settings schema.
int m_schemaVersion; 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) /// A pointer to the settings manager managing this file (may be null)
SETTINGS_MANAGER* m_manager; SETTINGS_MANAGER* m_manager;

View File

@ -682,7 +682,7 @@ void KICAD_MANAGER_FRAME::SaveOpenJobSetsToLocalSettings( bool aIsExplicitUserSa
{ {
PROJECT_LOCAL_SETTINGS& cfg = Prj().GetLocalSettings(); PROJECT_LOCAL_SETTINGS& cfg = Prj().GetLocalSettings();
if( !aIsExplicitUserSave && cfg.WasMigrated() ) if( !aIsExplicitUserSave && !cfg.ShouldAutoSave() )
return; return;
cfg.m_OpenJobSets.clear(); cfg.m_OpenJobSets.clear();
@ -712,8 +712,8 @@ bool KICAD_MANAGER_FRAME::CloseProject( bool aSave )
if( !Kiway().PlayersClose( false ) ) if( !Kiway().PlayersClose( false ) )
return false; return false;
bool shouldSaveProject = !Prj().GetLocalSettings().WasMigrated() bool shouldSaveProject = Prj().GetLocalSettings().ShouldAutoSave()
&& !Prj().GetProjectFile().WasMigrated(); && Prj().GetProjectFile().ShouldAutoSave();
// Save the project file for the currently loaded project. // Save the project file for the currently loaded project.
if( m_active_project ) if( m_active_project )

View File

@ -853,7 +853,7 @@ int KICAD_MANAGER_CONTROL::ShowPlayer( const TOOL_EVENT& aEvent )
// Save window state to disk now. Don't wait around for a crash. // Save window state to disk now. Don't wait around for a crash.
if( Pgm().GetCommonSettings()->m_Session.remember_open_files if( Pgm().GetCommonSettings()->m_Session.remember_open_files
&& !player->GetCurrentFileName().IsEmpty() && !player->GetCurrentFileName().IsEmpty()
&& !Prj().GetLocalSettings().WasMigrated() ) && Prj().GetLocalSettings().ShouldAutoSave() )
{ {
wxFileName rfn( player->GetCurrentFileName() ); wxFileName rfn( player->GetCurrentFileName() );
rfn.MakeRelativeTo( Prj().GetProjectPath() ); rfn.MakeRelativeTo( Prj().GetProjectPath() );

View File

@ -1271,7 +1271,7 @@ void PCB_EDIT_FRAME::doCloseWindow()
} }
// Make sure local settings are persisted // Make sure local settings are persisted
if( !Prj().GetLocalSettings().WasMigrated() ) if( Prj().GetLocalSettings().ShouldAutoSave() )
{ {
m_netInspectorPanel->SaveSettings(); m_netInspectorPanel->SaveSettings();
SaveProjectLocalSettings(); SaveProjectLocalSettings();