IFC: support reading from IFCZip archives that don't use the same name for the embedded IFC file as the ZIP itself.
parent
b392322454
commit
31311bdb3b
|
@ -192,29 +192,44 @@ 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 )
|
|
||||||
{
|
|
||||||
// get file size, etc.
|
|
||||||
unz_file_info fileInfo;
|
|
||||||
unzGetCurrentFileInfo( zip , &fileInfo, 0, 0, 0, 0, 0, 0 );
|
|
||||||
|
|
||||||
uint8_t* buff = new uint8_t[fileInfo.uncompressed_size];
|
if(UNZ_OK == unzGoToFirstFile(zip)) {
|
||||||
|
do {
|
||||||
|
//
|
||||||
|
|
||||||
LogInfo("Decompressing IFCZIP file");
|
// get file size, etc.
|
||||||
|
unz_file_info fileInfo;
|
||||||
|
char filename[256];
|
||||||
|
unzGetCurrentFileInfo( zip , &fileInfo, filename, sizeof(filename), 0, 0, 0, 0 );
|
||||||
|
|
||||||
unzOpenCurrentFile( zip );
|
if (GetExtension(filename) != "ifc") {
|
||||||
const int ret = unzReadCurrentFile( zip, buff, fileInfo.uncompressed_size);
|
continue;
|
||||||
size_t filesize = fileInfo.uncompressed_size;
|
}
|
||||||
if ( ret < 0 || size_t(ret) != filesize )
|
|
||||||
{
|
uint8_t* buff = new uint8_t[fileInfo.uncompressed_size];
|
||||||
delete[] buff;
|
|
||||||
ThrowException("Failed to decompress IFC ZIP file");
|
LogInfo("Decompressing IFCZIP file");
|
||||||
}
|
|
||||||
unzCloseCurrentFile( zip );
|
unzOpenCurrentFile( zip );
|
||||||
stream.reset(new MemoryIOStream(buff,fileInfo.uncompressed_size,true));
|
const int ret = unzReadCurrentFile( zip, buff, fileInfo.uncompressed_size);
|
||||||
|
size_t filesize = fileInfo.uncompressed_size;
|
||||||
|
if ( ret < 0 || size_t(ret) != filesize )
|
||||||
|
{
|
||||||
|
delete[] buff;
|
||||||
|
ThrowException("Failed to decompress IFC ZIP file");
|
||||||
|
}
|
||||||
|
unzCloseCurrentFile( zip );
|
||||||
|
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);
|
||||||
|
|
Loading…
Reference in New Issue