From 25f34a14a162becf08a68a71af7db9634f9c02bf Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 5 Jan 2023 18:08:49 -0800 Subject: [PATCH] Check file starting signature when opening Opening .brd files might be legacy or eagle (probably others as well). We check for the starting "PCBNEW" in KiCad files to differentiate Fixes https://gitlab.com/kicad/code/kicad/issues/10201 --- pcbnew/files.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 87c2807943..627f920b65 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -65,6 +65,8 @@ #include #include +#include +#include #if wxCHECK_VERSION( 3, 1, 7 ) #include "widgets/filedlg_hook_save_project.h" @@ -493,8 +495,20 @@ IO_MGR::PCB_FILE_T plugin_type( const wxString& aFileName, int aCtl ) if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 ) { + wxFileInputStream input( aFileName ); + bool is_legacy = true; + + if(input.IsOk() && !input.Eof() ) + { + wxTextInputStream text( input ); + wxString line = text.ReadLine(); + + if( !line.StartsWith( wxT( "PCBNEW" ) ) ) + is_legacy = false; + } + // both legacy and eagle share a common file extension. - pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY; + pluginType = ( aCtl & KICTL_EAGLE_BRD ) || !is_legacy ? IO_MGR::EAGLE : IO_MGR::LEGACY; } else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 ) {