From 5ccdb750915c319e96a8ab4a2f48b70cfe94e5df Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Thu, 9 Nov 2023 01:23:22 +0300 Subject: [PATCH] Use CheckFileHeader in CADSTAR_SCH_ARCHIVE_PLUGIN::CanReadLibrary --- .../cadstar/cadstar_sch_archive_plugin.cpp | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp index 95d152dc63..1a2ed20b39 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -53,24 +54,14 @@ bool CADSTAR_SCH_ARCHIVE_PLUGIN::CanReadLibrary( const wxString& aFileName ) con if( !SCH_PLUGIN::CanReadLibrary( aFileName ) ) return false; - wxFFileInputStream input( aFileName ); - - if( !input.IsOk() || input.Eof() ) - return false; - - // Find first non-empty line - wxTextInputStream text( input ); - wxString line = text.ReadLine(); - - while( !input.Eof() && line.IsEmpty() ) - line = text.ReadLine().Trim( false /*trim from left*/ ); - - // CADSTAR libs start with - // # FORMAT 32 - // or - // .PartName :2 ;Part 0 Description - if( line.StartsWith( wxS( "#" ) ) || line.StartsWith( wxS( "." ) ) ) - return true; + try + { + CADSTAR_PARTS_LIB_PARSER p; + return p.CheckFileHeader( aFileName.fn_str() ); + } + catch( const std::runtime_error& ) + { + } return false; }