diff --git a/common/io/easyedapro/easyedapro_import_utils.cpp b/common/io/easyedapro/easyedapro_import_utils.cpp index 14f211af63..ca82e319fb 100644 --- a/common/io/easyedapro/easyedapro_import_utils.cpp +++ b/common/io/easyedapro/easyedapro_import_utils.cpp @@ -140,7 +140,8 @@ EASYEDAPRO::ProjectToSelectorDialog( const nlohmann::json& aProject, bool aPcbOn } -nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName ) +nlohmann::json EASYEDAPRO::FindJsonFile( const wxString& aZipFileName, + const std::set& aFileNames ) { std::shared_ptr entry; wxFFileInputStream in( aZipFileName ); @@ -152,7 +153,7 @@ nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName try { - if( name == wxS( "project.json" ) || name == wxS( "device.json" ) ) + if( aFileNames.find( name ) != aFileNames.end() ) { wxMemoryOutputStream memos; memos << zip; @@ -175,6 +176,20 @@ nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName } } + return nlohmann::json{}; +} + + +nlohmann::json EASYEDAPRO::ReadProjectOrDeviceFile( const wxString& aZipFileName ) +{ + static const std::set c_files = { wxS( "project.json" ), wxS( "device.json" ), + wxS( "footprint.json" ), wxS( "symbol.json" ) }; + + nlohmann::json j = FindJsonFile( aZipFileName, c_files ); + + if( !j.is_null() ) + return j; + THROW_IO_ERROR( wxString::Format( _( "'%s' does not appear to be a valid EasyEDA (JLCEDA) Pro " "project or library file. Cannot find project.json or device.json." ), diff --git a/common/io/easyedapro/easyedapro_import_utils.h b/common/io/easyedapro/easyedapro_import_utils.h index d4b6477a8c..6117d01ff0 100644 --- a/common/io/easyedapro/easyedapro_import_utils.h +++ b/common/io/easyedapro/easyedapro_import_utils.h @@ -25,6 +25,7 @@ #ifndef EASYEDAPRO_IMPORT_UTILS_H_ #define EASYEDAPRO_IMPORT_UTILS_H_ +#include #include #include #include @@ -46,6 +47,8 @@ std::vector ProjectToSelectorDialog( const nlohmann::json& bool aPcbOnly = false, bool aSchOnly = false ); +nlohmann::json FindJsonFile( const wxString& aZipFileName, const std::set& aFileNames ); + nlohmann::json ReadProjectOrDeviceFile( const wxString& aZipFileName ); void IterateZipFiles( diff --git a/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp b/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp index 3f0e446c09..aa1f6485fd 100644 --- a/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp +++ b/eeschema/sch_io/easyedapro/sch_io_easyedapro.cpp @@ -143,8 +143,14 @@ static LIB_SYMBOL* loadSymbol( nlohmann::json project, const wxString& aLibraryP || libFname.GetExt() == wxS( "zip" ) ) { std::map prjSymbols = project.at( "symbols" ); - std::map prjFootprints = project.at( "footprints" ); - std::map prjDevices = project.at( "devices" ); + std::map prjFootprints; + std::map prjDevices; + + if( project.contains( "footprints" ) ) + prjFootprints = project.at( "footprints" ); + + if( project.contains( "devices" ) ) + prjDevices = project.at( "devices" ); auto prjSymIt = std::find_if( prjSymbols.begin(), prjSymbols.end(), [&]( const auto& pair ) diff --git a/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp b/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp index 7dd822552f..56e9432404 100644 --- a/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp +++ b/pcbnew/pcb_io/easyedapro/pcb_io_easyedapro_parser.cpp @@ -897,7 +897,7 @@ FOOTPRINT* PCB_IO_EASYEDAPRO_PARSER::ParseFootprint( const nlohmann::json& } } - if( aProject.is_object() ) + if( aProject.is_object() && aProject.contains( "devices" ) ) { std::map devicesMap = aProject.at( "devices" ); std::map compAttrs;