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

(cherry picked from commit 20036f8105)
This commit is contained in:
Jeff Young 2019-07-11 22:59:14 +01:00
parent d1ed4665de
commit 6ba2c44e88
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
{
std::unique_ptr<MODULE> m( FootprintLoad( aNickname, aFootprintName ) );
return m.get() != nullptr;
const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName,
row->GetProperties() );
}
catch( ... )
{

View File

@ -420,6 +420,13 @@ public:
const wxString& aFootprintName,
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
* will write @a aModule to an existing library located at @a aLibraryPath.

View File

@ -2012,6 +2012,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,
const PROPERTIES* aProperties )
{

View File

@ -125,6 +125,9 @@ public:
const wxString& aFootprintName,
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,
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,
const PROPERTIES* aProperties )
{