Library Editor: fixed a crash when creating a new library with existing file

This commit is contained in:
Maciej Suminski 2017-11-22 13:20:26 +01:00
parent 8b0041bf9a
commit aaabf8ab78
2 changed files with 24 additions and 4 deletions

View File

@ -541,7 +541,16 @@ bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate )
libTable->InsertRow( libRow );
if( aCreate )
{
// CreateSymbolLib() fails if the file exists
if( wxFileName::Exists( aFilePath ) )
{
if( !wxRemoveFile( aFilePath ) )
return false;
}
libTable->CreateSymbolLib( libName );
}
getAdapter()->AddLibrary( libName );

View File

@ -1510,6 +1510,7 @@ bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
{
wxFileName fileName = getLibraryFileName( !aCreateNew );
wxString libName = fileName.GetName();
bool res = false;
if( libName.IsEmpty() )
return false;
@ -1521,12 +1522,22 @@ bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
return false;
}
m_libMgr->AddLibrary( fileName.GetFullPath() );
if( aCreateNew )
Prj().SchSymbolLibTable()->CreateSymbolLib( libName );
{
res = m_libMgr->CreateLibrary( fileName.GetFullPath() );
return true;
if( !res )
DisplayError( this, _( "Could not create the library file. Check write permission." ) );
}
else
{
res = m_libMgr->AddLibrary( fileName.GetFullPath() );
if( !res )
DisplayError( this, _( "Could not open the library file." ) );
}
return res;
}