2
0
Эх сурвалжийг харах

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

Alexander Gessler 12 жил өмнө
parent
commit
31311bdb3b
1 өөрчлөгдсөн 36 нэмэгдсэн , 21 устгасан
  1. 36 21
      code/IFCLoader.cpp

+ 36 - 21
code/IFCLoader.cpp

@@ -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
-		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];
-
-			LogInfo("Decompressing IFCZIP file");
-
-			unzOpenCurrentFile( zip  );
-			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));
+		
+		if(UNZ_OK == unzGoToFirstFile(zip)) {
+			do {
+				//
+
+				// get file size, etc.
+				unz_file_info fileInfo;
+				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];
+
+				LogInfo("Decompressing IFCZIP file");
+
+				unzOpenCurrentFile( zip  );
+				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 {
-			ThrowException("Found no IFC file member in IFCZIP file");
+			ThrowException("Found no IFC file member in IFCZIP file (2)");
 		}
 
 		unzClose(zip);