diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index a40016419f..60cdc1a989 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -222,16 +222,8 @@ void FP_CACHE::Load() do { - FILE* fp = wxFopen( fpFileName, wxT( "r" ) ); - - if( !fp ) - { - THROW_IO_ERROR( wxString::Format( _( "cannot open footprint library file '%s'" ), - fpFileName.GetData() ) ); - } - // reader now owns fp, will close on exception or return - FILE_LINE_READER reader( fp, fpFileName ); + FILE_LINE_READER reader( fpFileName ); m_owner->m_parser->SetLineReader( &reader ); @@ -1551,15 +1543,7 @@ PCB_IO::~PCB_IO() BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties ) { - wxFFile file( aFileName, wxT("r") ); - - if( !file.IsOpened() ) - { - wxString msg = wxString::Format( _( "Unable to read file \"%s\"" ), GetChars( aFileName ) ); - THROW_IO_ERROR( msg ); - } - - FILE_LINE_READER reader( file.fp(), aFileName, false /* wxFFile owns fp */ ); + FILE_LINE_READER reader( aFileName ); m_parser->SetLineReader( &reader ); m_parser->SetBoard( aAppendToMe ); diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 258579bd87..ca1407b456 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -238,15 +238,7 @@ BOARD* LEGACY_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPE // delete on exception, iff I own m_board, according to aAppendToMe auto_ptr deleter( aAppendToMe ? NULL : m_board ); - FILE* fp = wxFopen( aFileName, wxT( "r" ) ); - if( !fp ) - { - m_error.Printf( _( "Unable to open file '%s'" ), aFileName.GetData() ); - THROW_IO_ERROR( m_error ); - } - - // reader now owns fp, will close on exception or return - FILE_LINE_READER reader( fp, aFileName ); + FILE_LINE_READER reader( aFileName ); m_reader = &reader; // member function accessibility @@ -3920,15 +3912,7 @@ wxDateTime FPL_CACHE::GetLibModificationTime() void FPL_CACHE::Load() { - FILE* fp = wxFopen( m_lib_name, wxT( "r" ) ); - if( !fp ) - { - THROW_IO_ERROR( wxString::Format( - _( "Unable to open legacy library file '%s'" ), m_lib_name.GetData() ) ); - } - - // reader now owns fp, will close on exception or return - FILE_LINE_READER reader( fp, m_lib_name ); + FILE_LINE_READER reader( m_lib_name ); ReadAndVerifyHeader( &reader ); SkipIndex( &reader ); diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp index b7d598b9f2..398297f1b4 100644 --- a/pcbnew/specctra.cpp +++ b/pcbnew/specctra.cpp @@ -230,14 +230,9 @@ void SPECCTRA_DB::readTIME( time_t* time_stamp ) throw( IO_ERROR ) void SPECCTRA_DB::LoadPCB( const wxString& filename ) throw( IO_ERROR ) { - FILE* fp = wxFopen( filename, wxT("r") ); + FILE_LINE_READER reader( filename ); - if( !fp ) - { - ThrowIOError( _("Unable to open file \"%s\""), GetChars(filename) ); - } - - PushReader( new FILE_LINE_READER( fp, filename ) ); + PushReader( &reader ); if( NextTok() != T_LEFT ) Expecting( T_LEFT ); @@ -248,21 +243,15 @@ void SPECCTRA_DB::LoadPCB( const wxString& filename ) throw( IO_ERROR ) SetPCB( new PCB() ); doPCB( pcb ); - - delete PopReader(); // close fp + PopReader(); } void SPECCTRA_DB::LoadSESSION( const wxString& filename ) throw( IO_ERROR ) { - FILE* fp = wxFopen( filename, wxT("r") ); + FILE_LINE_READER reader( filename ); - if( !fp ) - { - ThrowIOError( _("Unable to open file \"%s\""), GetChars(filename) ); - } - - PushReader( new FILE_LINE_READER( fp, filename ) ); + PushReader( &reader ); if( NextTok() != T_LEFT ) Expecting( T_LEFT ); @@ -274,7 +263,7 @@ void SPECCTRA_DB::LoadSESSION( const wxString& filename ) throw( IO_ERROR ) doSESSION( session ); - delete PopReader(); // close fp + PopReader(); }