diff --git a/plugins/3d/oce/loadmodel.cpp b/plugins/3d/oce/loadmodel.cpp index 335da6e47a..a9d13a792c 100644 --- a/plugins/3d/oce/loadmodel.cpp +++ b/plugins/3d/oce/loadmodel.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -473,6 +474,7 @@ bool readSTEPZ( Handle(TDocStd_Document)& m_doc, const char* aFileName ) return false; { + bool success = false; wxFFileOutputStream ofile( outFile.GetFullPath() ); if( !ofile.IsOk() ) @@ -486,17 +488,33 @@ bool readSTEPZ( Handle(TDocStd_Document)& m_doc, const char* aFileName ) try { expanded = gzip::decompress( buffer, size ); + success = true; } catch(...) + {} + + if( expanded.empty() ) { - delete[] buffer; - return false; + ifile.Reset(); + ifile.SeekI( 0 ); + wxZipInputStream izipfile( ifile ); + std::unique_ptr zip_file( izipfile.GetNextEntry() ); + + if( zip_file && !zip_file->IsDir() && izipfile.CanRead() ) + { + izipfile.Read( ofile ); + success = true; + } + } + else + { + ofile.Write( expanded.data(), expanded.size() ); } delete[] buffer; - - ofile.Write( expanded.data(), expanded.size() ); ofile.Close(); + + return success; } bool retval = readSTEP( m_doc, outFile.GetFullPath().mb_str() ); diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp index f61a9eafa6..e60d40e5b5 100644 --- a/utils/kicad2step/pcb/oce_utils.cpp +++ b/utils/kicad2step/pcb/oce_utils.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -1020,14 +1021,11 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ } { + bool success = false; wxFFileOutputStream ofile( outFile.GetFullPath() ); if( !ofile.IsOk() ) - { - ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n", - outFile.GetFullPath() ) ); return false; - } char *buffer = new char[size]; @@ -1037,17 +1035,33 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ try { expanded = gzip::decompress( buffer, size ); + success = true; } catch(...) + {} + + if( expanded.empty() ) { - delete[] buffer; - return false; + ifile.Reset(); + ifile.SeekI( 0 ); + wxZipInputStream izipfile( ifile ); + std::unique_ptr zip_file( izipfile.GetNextEntry() ); + + if( zip_file && !zip_file->IsDir() && izipfile.CanRead() ) + { + izipfile.Read( ofile ); + success = true; + } + } + else + { + ofile.Write( expanded.data(), expanded.size() ); } delete[] buffer; - - ofile.Write( expanded.data(), expanded.size() ); ofile.Close(); + + return success; } return getModelLabel( outFile.GetFullPath().ToStdString(), aScale, aLabel );