7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 10:31:40 +00:00

SCH_IO_MGR::GuessPluginTypeFromLibPath(): fix issue for new .kicad_sym files

GuessPluginTypeFromLibPath() was previously testing the type, but also the
existence of the lib file of *.kicad_sym filename, but when creating a new lib,
its existence obviously must not be tested
This commit is contained in:
jean-pierre charras 2025-03-06 09:52:26 +01:00
parent af3aba3c46
commit e54c73b516
2 changed files with 18 additions and 3 deletions

View File

@ -154,8 +154,22 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a
if( !pi )
continue;
if( pi->CanReadLibrary( aLibPath ) )
return fileType;
// For SCH_IO_MGR::SCH_KICAD and KICTL_CREATE option is set, use SCH_IO::CanReadLibrary()
// here instead of SCH_IO_KICAD_SEXPR::CanReadLibrary because aLibPath perhaps
// does notexist, and we need to use the version that does not test the existence
// of the file, just know if aLibPath file type can be handled.
if( fileType == SCH_IO_MGR::SCH_KICAD && ( aCtl & KICTL_CREATE ) )
{
if( pi->SCH_IO::CanReadLibrary( aLibPath ) ) // Test only the file ext
return fileType;
}
else
{
// Other lib types must be tested using the specific CanReadLibrary() and
// in some cases need to read the file
if( pi->CanReadLibrary( aLibPath ) )
return fileType;
}
}
return SCH_IO_MGR::SCH_FILE_UNKNOWN;

View File

@ -764,7 +764,8 @@ bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate
// try to use path normalized to an environmental variable or project path
wxString relPath = NormalizePath( aFilePath, &Pgm().GetLocalEnvVariables(), &m_frame.Prj() );
SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aFilePath );
SCH_IO_MGR::SCH_FILE_T schFileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( aFilePath,
aCreate ? KICTL_CREATE : 0 );
if( schFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
schFileType = SCH_IO_MGR::SCH_LEGACY;