Add FootprintExists() which can be more careful about FS differences.

(And in particular, MSW's case-insensitive FS.)

Fixes: lp:1835999
* https://bugs.launchpad.net/kicad/+bug/1835999
This commit is contained in:
Jeff Young 2019-07-11 22:59:14 +01:00
parent 34894acb89
commit 20036f8105
5 changed files with 39 additions and 2 deletions

View File

@ -341,8 +341,11 @@ bool FP_LIB_TABLE::FootprintExists( const wxString& aNickname, const wxString& a
{ {
try try
{ {
std::unique_ptr<MODULE> m( FootprintLoad( aNickname, aFootprintName ) ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
return m.get() != nullptr; wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName,
row->GetProperties() );
} }
catch( ... ) catch( ... )
{ {

View File

@ -420,6 +420,13 @@ public:
const wxString& aFootprintName, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ); const PROPERTIES* aProperties = NULL );
/**
* Function FootprintExists
* check for the existence of a footprint.
*/
virtual bool FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL );
/** /**
* Function FootprintSave * Function FootprintSave
* will write @a aModule to an existing library located at @a aLibraryPath. * will write @a aModule to an existing library located at @a aLibraryPath.

View File

@ -2103,6 +2103,22 @@ const MODULE* PCB_IO::GetEnumeratedFootprint( const wxString& aLibraryPath,
} }
bool PCB_IO::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties )
{
// Note: checking the cache sounds like a good idea, but won't catch files which differ
// only in case.
//
// Since this goes out to the native filesystem, we get platform differences (ie: MSW's
// case-insensitive filesystem) handled "for free".
wxFileName footprintFile( aLibraryPath, aFootprintName );
footprintFile.SetExt( KiCadFootprintFileExtension );
return footprintFile.Exists();
}
MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties ) const PROPERTIES* aProperties )
{ {

View File

@ -127,6 +127,9 @@ public:
const wxString& aFootprintName, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
bool FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override;
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;

View File

@ -81,6 +81,14 @@ const MODULE* PLUGIN::GetEnumeratedFootprint( const wxString& aLibraryPath,
} }
bool PLUGIN::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties )
{
// default implementation
return FootprintLoad( aLibraryPath, aFootprintName, aProperties ) != nullptr;
}
MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties ) const PROPERTIES* aProperties )
{ {