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
This commit is contained in:
Seth Hillbrand 2023-01-05 18:08:49 -08:00
parent 570fa246ae
commit 25f34a14a1
1 changed files with 15 additions and 1 deletions

View File

@ -65,6 +65,8 @@
#include <wx/wupdlock.h> #include <wx/wupdlock.h>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#if wxCHECK_VERSION( 3, 1, 7 ) #if wxCHECK_VERSION( 3, 1, 7 )
#include "widgets/filedlg_hook_save_project.h" #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 ) 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. // 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 ) else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
{ {