IFC: support reading from IFCZip archives that don't use the same name for the embedded IFC file as the ZIP itself.

pull/60/head
Alexander Gessler 2013-06-25 00:22:47 +02:00
parent b392322454
commit 31311bdb3b
1 changed files with 33 additions and 18 deletions

View File

@ -192,11 +192,19 @@ void IFCImporter::InternReadFile( const std::string& pFile,
} }
// search file (same name as the IFCZIP except for the file extension) and place file pointer there // search file (same name as the IFCZIP except for the file extension) and place file pointer there
if ( unzLocateFile( zip, fileName.c_str(), 0 ) == UNZ_OK )
{ if(UNZ_OK == unzGoToFirstFile(zip)) {
do {
//
// get file size, etc. // get file size, etc.
unz_file_info fileInfo; unz_file_info fileInfo;
unzGetCurrentFileInfo( zip , &fileInfo, 0, 0, 0, 0, 0, 0 ); char filename[256];
unzGetCurrentFileInfo( zip , &fileInfo, filename, sizeof(filename), 0, 0, 0, 0 );
if (GetExtension(filename) != "ifc") {
continue;
}
uint8_t* buff = new uint8_t[fileInfo.uncompressed_size]; uint8_t* buff = new uint8_t[fileInfo.uncompressed_size];
@ -212,9 +220,16 @@ void IFCImporter::InternReadFile( const std::string& pFile,
} }
unzCloseCurrentFile( zip ); unzCloseCurrentFile( zip );
stream.reset(new MemoryIOStream(buff,fileInfo.uncompressed_size,true)); stream.reset(new MemoryIOStream(buff,fileInfo.uncompressed_size,true));
break;
if (unzGoToNextFile(zip) == UNZ_END_OF_LIST_OF_FILE) {
ThrowException("Found no IFC file member in IFCZIP file (1)");
}
} while(true);
} }
else { else {
ThrowException("Found no IFC file member in IFCZIP file"); ThrowException("Found no IFC file member in IFCZIP file (2)");
} }
unzClose(zip); unzClose(zip);