Migrate lib tables to KICAD7 on open

If KiCad does not detect an environmental variable set for the old
library table variables AND the library table being opened references
the unset env var, we will dynamically update the env var to the new
value

Fixes https://gitlab.com/kicad/code/kicad/issues/13464
This commit is contained in:
Seth Hillbrand 2023-01-22 15:36:54 -08:00
parent efe12f2da5
commit 70a57505de
2 changed files with 36 additions and 0 deletions

View File

@ -326,6 +326,31 @@ bool LIB_TABLE::InsertRow( LIB_TABLE_ROW* aRow, bool doReplace )
}
bool LIB_TABLE::migrate()
{
bool table_updated = false;
for( LIB_TABLE_ROW& row : m_rows )
{
bool row_updated = false;
wxString uri = row.GetFullURI( true );
// If the uri still has a variable in it, that means that the user does not have
// these vars defined. We update the old vars to the KICAD7 versions on load
row_updated |= ( uri.Replace( wxS( "${KICAD5_" ), wxS( "${KICAD7_" ), false ) > 0 );
row_updated |= ( uri.Replace( wxS( "${KICAD6_" ), wxS( "${KICAD7_" ), false ) > 0 );
if( row_updated )
{
row.SetFullURI( uri );
table_updated = true;
}
}
return table_updated;
}
void LIB_TABLE::Load( const wxString& aFileName )
{
// It's OK if footprint library tables are missing.
@ -335,6 +360,9 @@ void LIB_TABLE::Load( const wxString& aFileName )
LIB_TABLE_LEXER lexer( &reader );
Parse( &lexer );
if( migrate() && wxFileName::IsFileWritable( aFileName ) )
Save( aFileName );
}
}

View File

@ -521,6 +521,14 @@ protected:
*/
LIB_TABLE_ROW* findRow( const wxString& aNickname, bool aCheckIfEnabled = false ) const;
/**
* Updates the env vars from older version of KiCad, provided they do not currently
* resolve to anything
*
* @return True if the tables were modified
*/
bool migrate();
void reindex()
{
std::lock_guard<std::mutex> lock( m_nickIndexMutex );