altium: verify that file contains "Compound File Binary Format" magic bytes, as we do not support the ASCII format
This commit is contained in:
parent
85240d590b
commit
c2a91caacf
|
@ -679,6 +679,7 @@ public:
|
|||
protected:
|
||||
static bool fileStartsWithPrefix( const wxString& aFilePath, const wxString& aPrefix,
|
||||
bool aIgnoreWhitespace );
|
||||
static bool fileStartsWithBinaryHeader( const wxString& aFilePath, const std::vector<uint8_t>& aHeader );
|
||||
};
|
||||
|
||||
#endif // IO_MGR_H_
|
||||
|
|
|
@ -318,3 +318,22 @@ bool PLUGIN::fileStartsWithPrefix( const wxString& aFilePath, const wxString& aP
|
|||
return false;
|
||||
}
|
||||
|
||||
bool PLUGIN::fileStartsWithBinaryHeader( const wxString& aFilePath, const std::vector<uint8_t>& aHeader )
|
||||
{
|
||||
wxFileInputStream input( aFilePath );
|
||||
|
||||
if( input.IsOk() && !input.Eof() )
|
||||
{
|
||||
if (input.GetLength() < aHeader.size())
|
||||
return false;
|
||||
|
||||
std::vector<uint8_t> parsedHeader(aHeader.size());
|
||||
if (!input.ReadAll(parsedHeader.data(), parsedHeader.size()))
|
||||
return false;
|
||||
|
||||
return parsedHeader == aHeader;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <wx/string.h>
|
||||
|
||||
#include <altium_circuit_maker_plugin.h>
|
||||
#include <altium_designer_plugin.h>
|
||||
#include <altium_pcb.h>
|
||||
#include "plugins/altium/altium_parser.h"
|
||||
|
||||
|
@ -62,6 +63,15 @@ PLUGIN_FILE_DESC ALTIUM_CIRCUIT_MAKER_PLUGIN::GetBoardFileDesc() const
|
|||
}
|
||||
|
||||
|
||||
bool ALTIUM_CIRCUIT_MAKER_PLUGIN::CanReadBoard( const wxString& aFileName ) const
|
||||
{
|
||||
if( !PLUGIN::CanReadBoard( aFileName ) )
|
||||
return false;
|
||||
|
||||
return ALTIUM_DESIGNER_PLUGIN::checkFileHeader( aFileName );
|
||||
}
|
||||
|
||||
|
||||
BOARD* ALTIUM_CIRCUIT_MAKER_PLUGIN::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties,
|
||||
PROJECT* aProject,
|
||||
|
|
|
@ -35,6 +35,8 @@ public:
|
|||
|
||||
PLUGIN_FILE_DESC GetBoardFileDesc() const override;
|
||||
|
||||
bool CanReadBoard( const wxString& aFileName ) const override;
|
||||
|
||||
BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties, PROJECT* aProject = nullptr,
|
||||
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <wx/string.h>
|
||||
|
||||
#include <altium_circuit_studio_plugin.h>
|
||||
#include <altium_designer_plugin.h>
|
||||
#include <altium_pcb.h>
|
||||
#include "plugins/altium/altium_parser.h"
|
||||
|
||||
|
@ -62,6 +63,15 @@ PLUGIN_FILE_DESC ALTIUM_CIRCUIT_STUDIO_PLUGIN::GetBoardFileDesc() const
|
|||
}
|
||||
|
||||
|
||||
bool ALTIUM_CIRCUIT_STUDIO_PLUGIN::CanReadBoard( const wxString& aFileName ) const
|
||||
{
|
||||
if( !PLUGIN::CanReadBoard( aFileName ) )
|
||||
return false;
|
||||
|
||||
return ALTIUM_DESIGNER_PLUGIN::checkFileHeader( aFileName );
|
||||
}
|
||||
|
||||
|
||||
BOARD* ALTIUM_CIRCUIT_STUDIO_PLUGIN::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties,
|
||||
PROJECT* aProject,
|
||||
|
|
|
@ -35,6 +35,8 @@ public:
|
|||
|
||||
PLUGIN_FILE_DESC GetBoardFileDesc() const override;
|
||||
|
||||
bool CanReadBoard( const wxString& aFileName ) const override;
|
||||
|
||||
BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
|
||||
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
||||
|
|
|
@ -50,6 +50,31 @@ ALTIUM_DESIGNER_PLUGIN::~ALTIUM_DESIGNER_PLUGIN()
|
|||
}
|
||||
|
||||
|
||||
bool ALTIUM_DESIGNER_PLUGIN::checkFileHeader( const wxString& aFileName )
|
||||
{
|
||||
// Compound File Binary Format header
|
||||
return fileStartsWithBinaryHeader( aFileName, { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1} );
|
||||
}
|
||||
|
||||
|
||||
bool ALTIUM_DESIGNER_PLUGIN::CanReadBoard( const wxString& aFileName ) const
|
||||
{
|
||||
if( !PLUGIN::CanReadBoard( aFileName ) )
|
||||
return false;
|
||||
|
||||
return checkFileHeader( aFileName );
|
||||
}
|
||||
|
||||
|
||||
bool ALTIUM_DESIGNER_PLUGIN::CanReadFootprintLib( const wxString& aFileName ) const
|
||||
{
|
||||
if( !PLUGIN::CanReadFootprintLib( aFileName ) )
|
||||
return false;
|
||||
|
||||
return checkFileHeader( aFileName );
|
||||
}
|
||||
|
||||
|
||||
BOARD* ALTIUM_DESIGNER_PLUGIN::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
|
||||
PROGRESS_REPORTER* aProgressReporter )
|
||||
|
|
|
@ -45,6 +45,9 @@ public:
|
|||
return PLUGIN_FILE_DESC( _HKI( "Altium PCB footprint library files" ), { "PcbLib" } );
|
||||
}
|
||||
|
||||
bool CanReadBoard( const wxString& aFileName ) const override;
|
||||
bool CanReadFootprintLib( const wxString& aFileName ) const override;
|
||||
|
||||
BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties, PROJECT* aProject = nullptr,
|
||||
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
||||
|
@ -67,6 +70,8 @@ public:
|
|||
ALTIUM_DESIGNER_PLUGIN();
|
||||
~ALTIUM_DESIGNER_PLUGIN();
|
||||
|
||||
static bool checkFileHeader( const wxString& aFileName );
|
||||
|
||||
private:
|
||||
const STRING_UTF8_MAP* m_props;
|
||||
BOARD* m_board;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <wx/string.h>
|
||||
|
||||
#include <solidworks_pcb_plugin.h>
|
||||
#include <altium_designer_plugin.h>
|
||||
#include <altium_pcb.h>
|
||||
#include "plugins/altium/altium_parser.h"
|
||||
|
||||
|
@ -52,6 +53,15 @@ PLUGIN_FILE_DESC SOLIDWORKS_PCB_PLUGIN::GetBoardFileDesc() const
|
|||
}
|
||||
|
||||
|
||||
bool SOLIDWORKS_PCB_PLUGIN::CanReadBoard( const wxString& aFileName ) const
|
||||
{
|
||||
if( !PLUGIN::CanReadBoard( aFileName ) )
|
||||
return false;
|
||||
|
||||
return ALTIUM_DESIGNER_PLUGIN::checkFileHeader( aFileName );
|
||||
}
|
||||
|
||||
|
||||
BOARD* SOLIDWORKS_PCB_PLUGIN::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
|
||||
PROGRESS_REPORTER* aProgressReporter )
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
|
||||
PLUGIN_FILE_DESC GetBoardFileDesc() const override;
|
||||
|
||||
bool CanReadBoard( const wxString& aFileName ) const override;
|
||||
|
||||
BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties, PROJECT* aProject = nullptr,
|
||||
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
A fake Board file for testing
|
|
@ -0,0 +1 @@
|
|||
A fake Board file for testing
|
|
@ -0,0 +1 @@
|
|||
A fake Board file for testing
|
|
@ -0,0 +1 @@
|
|||
A fake Board file for testing
|
|
@ -63,6 +63,27 @@ static const std::vector<BOARD_PLUGIN_CASE> BoardPluginCases = {
|
|||
"plugins/fakeboard.cpa",
|
||||
IO_MGR::FILE_TYPE_NONE
|
||||
},
|
||||
{
|
||||
"Fake Board file (Altium Circuit Studio file ext)",
|
||||
"plugins/fakeboard.CSPcbDoc",
|
||||
IO_MGR::FILE_TYPE_NONE
|
||||
},
|
||||
{
|
||||
"Fake Board file (Altium Circuit Maker file ext)",
|
||||
"plugins/fakeboard.CMPcbDoc",
|
||||
IO_MGR::FILE_TYPE_NONE
|
||||
},
|
||||
{
|
||||
"Fake Board file (Altium Designer file ext)",
|
||||
"plugins/fakeboard.PcbDoc",
|
||||
IO_MGR::FILE_TYPE_NONE
|
||||
},
|
||||
|
||||
{
|
||||
"Fake Board file (Solid Works PCB file ext)",
|
||||
"plugins/fakeboard.SWPcbDoc",
|
||||
IO_MGR::FILE_TYPE_NONE
|
||||
},
|
||||
|
||||
//
|
||||
// REAL Boards:
|
||||
|
@ -92,8 +113,13 @@ static const std::vector<BOARD_PLUGIN_CASE> BoardPluginCases = {
|
|||
"Basic CADSTAR board file",
|
||||
"plugins/cadstar/route_offset/minimal_route_offset_curved_track.cpa",
|
||||
IO_MGR::CADSTAR_PCB_ARCHIVE
|
||||
},
|
||||
{
|
||||
"Basic Altium Designer board file",
|
||||
"plugins/altium/eDP_adapter_dvt1_source/eDP_adapter_dvt1.PcbDoc",
|
||||
IO_MGR::ALTIUM_DESIGNER
|
||||
}
|
||||
// Todo: Add Altium (+derivatives) and Fabmaster tests
|
||||
// Todo: Add Altium derivatives and Fabmaster tests
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue