diff --git a/include/ABRecompressor.h b/include/ABRecompressor.h index 16d3942..819b959 100644 --- a/include/ABRecompressor.h +++ b/include/ABRecompressor.h @@ -10,10 +10,14 @@ extern "C" { #define ABRECOMPRESSOR_H #ifdef _WIN32 - #ifdef ABRECOMPRESSOR_EXPORTS - #define ABRECOMPRESSOR_API __declspec(dllexport) + #ifdef ABRECOMPRESSOR_STATIC + #define ABRECOMPRESSOR_API #else - #define ABRECOMPRESSOR_API __declspec(dllimport) + #ifdef ABRECOMPRESSOR_EXPORTS + #define ABRECOMPRESSOR_API __declspec(dllexport) + #else + #define ABRECOMPRESSOR_API __declspec(dllimport) + #endif #endif #else #define ABRECOMPRESSOR_API diff --git a/src/BlocksAndDirectoryInfo.cpp b/src/BlocksAndDirectoryInfo.cpp index f5250c5..5b39d3d 100644 --- a/src/BlocksAndDirectoryInfo.cpp +++ b/src/BlocksAndDirectoryInfo.cpp @@ -45,11 +45,7 @@ BlocksAndDirectoryInfo::BlocksAndDirectoryInfo(Reader* reader, Header* header, b } ByteArr* BlocksAndDirectoryInfo::ToBytes(){ - uint64_t size = 16 + 4 + 4 + 10 * BlocksInfoCount; - for (uint i = 0; i < DirectoryInfoCount; i++){ - size += DirectoryInfos[i].GetSize(); - } - ByteArr* result = new ByteArr(size); + ByteArr* result = new ByteArr(GetRawSize()); memcpy(result->GetData(), UncompressedDataHash->GetData(), 16); Writer writer = Writer(result, 16); writer.WriteUInt32(BlocksInfoCount); @@ -95,4 +91,12 @@ uint64_t BlocksAndDirectoryInfo::DataSize(){ return size1; } throw std::runtime_error("Data size mismatch, for blocks is " + std::to_string(size1) + " while for cab is " + std::to_string(size2)); +} + +uint64_t BlocksAndDirectoryInfo::GetRawSize(){ + uint64_t size = 16 + 4 + 4 + 10 * BlocksInfoCount; + for (uint i = 0; i < DirectoryInfoCount; i++){ + size += DirectoryInfos[i].GetSize(); + } + return size; } \ No newline at end of file diff --git a/src/BlocksAndDirectoryInfo.h b/src/BlocksAndDirectoryInfo.h index 04d4070..bdf8449 100644 --- a/src/BlocksAndDirectoryInfo.h +++ b/src/BlocksAndDirectoryInfo.h @@ -27,6 +27,7 @@ class BlocksAndDirectoryInfo{ ByteArr* ToBytes(); ByteArr* ToBytes(CompressionType compressionType); uint64_t DataSize(); + uint64_t GetRawSize(); }; #endif // ABRECOMPRESSOR_BLOCKSANDDIRECTORYINFO_H \ No newline at end of file diff --git a/src/BundleFile.cpp b/src/BundleFile.cpp index ac7f49f..d9f356f 100644 --- a/src/BundleFile.cpp +++ b/src/BundleFile.cpp @@ -115,6 +115,18 @@ char BundleFile::GetCompressionType(){ } ByteArr* BundleFile::ToBytes(CompressionType compressionType){ + if (compressionType == CompressionType::Lzma){ + uint64_t totalSize = data->GetSize(); + mDataInfo->BlocksInfoCount = (totalSize / UINT32_MAX) + ((totalSize % UINT32_MAX) ? 1 : 0); + for (int i = 0; i < mDataInfo->BlocksInfoCount; i++){ + if (i == mDataInfo->BlocksInfoCount - 1){ + mDataInfo->BlocksInfos[i].uncompressedSize = totalSize % UINT32_MAX; + }else{ + mDataInfo->BlocksInfos[i].uncompressedSize = UINT32_MAX; + } + } + } + for (int i = 0; i < mDataInfo->BlocksInfoCount; i++){ mDataInfo->BlocksInfos[i].flags = (StorageBlockFlags)(mDataInfo->BlocksInfos[i].flags | compressionType); } @@ -126,6 +138,7 @@ ByteArr* BundleFile::ToBytes(CompressionType compressionType){ p += mDataInfo->BlocksInfos[i].uncompressedSize; } ByteArr* bDataInfo = mDataInfo->ToBytes(CompressionType::Lz4HC); + mHeader->mUncompressedBlocksInfoSize = mDataInfo->GetRawSize(); mHeader->mCompressedBlocksInfoSize = bDataInfo->GetSize(); uint64_t size = mHeader->GetSize(); if (HeaderAligned){ diff --git a/src/Compression.cpp b/src/Compression.cpp index f47c2b4..7549ddf 100644 --- a/src/Compression.cpp +++ b/src/Compression.cpp @@ -80,6 +80,7 @@ ByteArr* Compress(CompressionType compressionType, byte* tocompressData, uint to lzma_ret ret; lzma_options_lzma opt; lzma_lzma_preset(&opt, LZMA_PRESET_EXTREME); + opt.dict_size = 0x200000; ret = lzma_alone_encoder(&strm, &opt); if (ret != LZMA_OK) { throw std::runtime_error("lzma_stream_buffer_decode error: " + std::to_string(ret));