From aaabf8ab78293a7fea655c2a97bcd18abb04c4e1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 22 Nov 2017 13:20:26 +0100 Subject: [PATCH] Library Editor: fixed a crash when creating a new library with existing file --- eeschema/lib_manager.cpp | 9 +++++++++ eeschema/libeditframe.cpp | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp index 2ce013ba4c..32c60d996d 100644 --- a/eeschema/lib_manager.cpp +++ b/eeschema/lib_manager.cpp @@ -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 ); diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index 7eed1c41f7..1b0b2d9078 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -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; }