-----------------------------------------------------------------------------------
| 684 | |
| 685 | // ----------------------------------------------------------------------------------- |
| 686 | void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { |
| 687 | IOStream *stream = pIOHandler->Open(pFile, "rb"); |
| 688 | if (nullptr == stream) { |
| 689 | throw DeadlyImportError("ASSBIN: Could not open ", pFile); |
| 690 | } |
| 691 | |
| 692 | // signature |
| 693 | stream->Seek(44, aiOrigin_CUR); |
| 694 | |
| 695 | unsigned int versionMajor = Read<unsigned int>(stream); |
| 696 | unsigned int versionMinor = Read<unsigned int>(stream); |
| 697 | if (versionMinor != ASSBIN_VERSION_MINOR || versionMajor != ASSBIN_VERSION_MAJOR) { |
| 698 | pIOHandler->Close(stream); |
| 699 | throw DeadlyImportError("Invalid version, data format not compatible!"); |
| 700 | } |
| 701 | |
| 702 | /*unsigned int versionRevision =*/Read<unsigned int>(stream); |
| 703 | /*unsigned int compileFlags =*/Read<unsigned int>(stream); |
| 704 | |
| 705 | shortened = Read<uint16_t>(stream) > 0; |
| 706 | compressed = Read<uint16_t>(stream) > 0; |
| 707 | |
| 708 | if (shortened) { |
| 709 | pIOHandler->Close(stream); |
| 710 | throw DeadlyImportError("Shortened binaries are not supported!"); |
| 711 | } |
| 712 | |
| 713 | stream->Seek(256, aiOrigin_CUR); // original filename |
| 714 | stream->Seek(128, aiOrigin_CUR); // options |
| 715 | stream->Seek(64, aiOrigin_CUR); // padding |
| 716 | |
| 717 | if (compressed) { |
| 718 | uLongf uncompressedSize = Read<uint32_t>(stream); |
| 719 | uLongf compressedSize = static_cast<uLongf>(stream->FileSize() - stream->Tell()); |
| 720 | |
| 721 | unsigned char *compressedData = new unsigned char[compressedSize]; |
| 722 | size_t len = stream->Read(compressedData, 1, compressedSize); |
| 723 | ai_assert(len == compressedSize); |
| 724 | |
| 725 | unsigned char *uncompressedData = new unsigned char[uncompressedSize]; |
| 726 | |
| 727 | int res = uncompress(uncompressedData, &uncompressedSize, compressedData, (uLong)len); |
| 728 | if (res != Z_OK) { |
| 729 | delete[] uncompressedData; |
| 730 | delete[] compressedData; |
| 731 | pIOHandler->Close(stream); |
| 732 | throw DeadlyImportError("Zlib decompression failed."); |
| 733 | } |
| 734 | |
| 735 | MemoryIOStream io(uncompressedData, uncompressedSize); |
| 736 | |
| 737 | ReadBinaryScene(&io, pScene); |
| 738 | |
| 739 | delete[] uncompressedData; |
| 740 | delete[] compressedData; |
| 741 | } else { |
| 742 | ReadBinaryScene(stream, pScene); |
| 743 | } |
nothing calls this directly
no test coverage detected