Use CheckFileHeader in CADSTAR_SCH_ARCHIVE_PLUGIN::CanReadLibrary

This commit is contained in:
Alex Shvartzkop 2023-11-09 01:23:22 +03:00
parent 09f1df6c94
commit 5ccdb75091
1 changed files with 9 additions and 18 deletions

View File

@ -26,6 +26,7 @@
#include <sch_plugins/cadstar/cadstar_sch_archive_loader.h> #include <sch_plugins/cadstar/cadstar_sch_archive_loader.h>
#include <sch_plugins/cadstar/cadstar_sch_archive_plugin.h> #include <sch_plugins/cadstar/cadstar_sch_archive_plugin.h>
#include <plugins/cadstar/cadstar_parts_lib_parser.h>
#include <lib_symbol.h> #include <lib_symbol.h>
#include <progress_reporter.h> #include <progress_reporter.h>
@ -53,24 +54,14 @@ bool CADSTAR_SCH_ARCHIVE_PLUGIN::CanReadLibrary( const wxString& aFileName ) con
if( !SCH_PLUGIN::CanReadLibrary( aFileName ) ) if( !SCH_PLUGIN::CanReadLibrary( aFileName ) )
return false; return false;
wxFFileInputStream input( aFileName ); try
{
if( !input.IsOk() || input.Eof() ) CADSTAR_PARTS_LIB_PARSER p;
return false; return p.CheckFileHeader( aFileName.fn_str() );
}
// Find first non-empty line catch( const std::runtime_error& )
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;
return false; return false;
} }