From 06582b4cf9a2877c41bd0457a83016b8ac690979 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 15 May 2012 08:58:55 -0500 Subject: [PATCH] try to delete a footprint library before exporting or creating, quietly --- include/richio.h | 2 +- pcbnew/librairi.cpp | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/richio.h b/include/richio.h index 83e328d8d3..206433ad00 100644 --- a/include/richio.h +++ b/include/richio.h @@ -140,7 +140,7 @@ struct PARSE_ERROR : public IO_ERROR // wxString errorText is still public from IO_ERROR int lineNumber; ///< at which line number, 1 based index. - int byteIndex; ///< at which character position within the line, 1 based index + int byteIndex; ///< at which byte offset within the line, 1 based index /// problem line of input [say, from a LINE_READER]. /// this is brought up in original byte format rather than wxString form, incase diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index 037f21afa5..38e4f04358 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -25,15 +25,6 @@ #include // temporarily, for LoadMODULE() -/* - * Module library header format: - * Array LIBRARY HEADER-datetime - * $INDEX - * List of modules names (1 name per line) - * $EndIndex - * List of descriptions of Modules - * $EndLIBRARY - */ #define BACKUP_EXT wxT( "bak" ) #define FILETMP_EXT wxT( "$$$" ) #define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" ) @@ -191,7 +182,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib ) config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() ); } - wxString libName = fn.GetFullPath(); + wxString libPath = fn.GetFullPath(); try { @@ -200,8 +191,20 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib ) // Use IO_MGR::LEGACY for now, until the IO_MGR::KICAD plugin is ready. PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) ); - pi->FootprintLibCreate( libName ); - pi->FootprintSave( libName, aModule ); + try + { + // try to delete the library whether it exists or not, quietly. + pi->FootprintLibDelete( libPath ); + } + catch( IO_ERROR ioe ) + { + // Ignore this, it will often happen and is not an error because + // the library may not exist. If library was in a read only directory, + // it will still exist as we get to the FootprintLibCreate() below. + } + + pi->FootprintLibCreate( libPath ); + pi->FootprintSave( libPath, aModule ); } catch( IO_ERROR ioe ) { @@ -209,7 +212,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib ) return; } - msg.Printf( _( "Module exported in file <%s>" ), libName.GetData() ); + msg.Printf( _( "Module exported in file <%s>" ), libPath.GetData() ); DisplayInfoMessage( this, msg ); }