summaryrefslogtreecommitdiffstats
path: root/src/libs/7zip/win
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-04-06 13:33:38 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-04-13 11:32:09 +0300
commit96ade47c182bf37a2efca2aa62922e54e5ff1660 (patch)
tree93ceee6c6f8984f563f3dfe83e56f98b66b40f3a /src/libs/7zip/win
parent2d5f0ffaf1278516bbd74e3b60f9849f4c51cffa (diff)
Move LZMA SDK to 3rdparty subdirectory
Also add attribution document. Task-number: QTIFW-2336 Change-Id: I91546bc6c3ace244e4b546b945f40b7d204f7463 Reviewed-by: Katja Marttila <katja.marttila@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/libs/7zip/win')
-rw-r--r--src/libs/7zip/win/C/7zCrc.c85
-rw-r--r--src/libs/7zip/win/C/7zCrc.h25
-rw-r--r--src/libs/7zip/win/C/7zCrcOpt.c66
-rw-r--r--src/libs/7zip/win/C/7zStream.c171
-rw-r--r--src/libs/7zip/win/C/7zTypes.h256
-rw-r--r--src/libs/7zip/win/C/7zVersion.h10
-rw-r--r--src/libs/7zip/win/C/Alloc.c127
-rw-r--r--src/libs/7zip/win/C/Alloc.h38
-rw-r--r--src/libs/7zip/win/C/Bra.c135
-rw-r--r--src/libs/7zip/win/C/Bra.h64
-rw-r--r--src/libs/7zip/win/C/Bra86.c82
-rw-r--r--src/libs/7zip/win/C/BraIA64.c69
-rw-r--r--src/libs/7zip/win/C/C.pri48
-rw-r--r--src/libs/7zip/win/C/Compiler.h28
-rw-r--r--src/libs/7zip/win/C/CpuArch.c190
-rw-r--r--src/libs/7zip/win/C/CpuArch.h157
-rw-r--r--src/libs/7zip/win/C/Delta.c64
-rw-r--r--src/libs/7zip/win/C/Delta.h19
-rw-r--r--src/libs/7zip/win/C/LzFind.c763
-rw-r--r--src/libs/7zip/win/C/LzFind.h111
-rw-r--r--src/libs/7zip/win/C/LzFindMt.c794
-rw-r--r--src/libs/7zip/win/C/LzFindMt.h101
-rw-r--r--src/libs/7zip/win/C/LzHash.h54
-rw-r--r--src/libs/7zip/win/C/Lzma2Dec.c352
-rw-r--r--src/libs/7zip/win/C/Lzma2Dec.h80
-rw-r--r--src/libs/7zip/win/C/Lzma2Enc.c493
-rw-r--r--src/libs/7zip/win/C/Lzma2Enc.h62
-rw-r--r--src/libs/7zip/win/C/LzmaDec.c1025
-rw-r--r--src/libs/7zip/win/C/LzmaDec.h227
-rw-r--r--src/libs/7zip/win/C/LzmaEnc.c2278
-rw-r--r--src/libs/7zip/win/C/LzmaEnc.h78
-rw-r--r--src/libs/7zip/win/C/MtCoder.c329
-rw-r--r--src/libs/7zip/win/C/MtCoder.h98
-rw-r--r--src/libs/7zip/win/C/Precomp.h10
-rw-r--r--src/libs/7zip/win/C/RotateDefs.h26
-rw-r--r--src/libs/7zip/win/C/Sha256.c206
-rw-r--r--src/libs/7zip/win/C/Sha256.h26
-rw-r--r--src/libs/7zip/win/C/Threads.c93
-rw-r--r--src/libs/7zip/win/C/Threads.h67
-rw-r--r--src/libs/7zip/win/C/Xz.c90
-rw-r--r--src/libs/7zip/win/C/Xz.h275
-rw-r--r--src/libs/7zip/win/C/XzCrc64.c90
-rw-r--r--src/libs/7zip/win/C/XzCrc64.h26
-rw-r--r--src/libs/7zip/win/C/XzCrc64Opt.c69
-rw-r--r--src/libs/7zip/win/C/XzDec.c909
-rw-r--r--src/libs/7zip/win/C/XzEnc.c522
-rw-r--r--src/libs/7zip/win/C/XzEnc.h39
-rw-r--r--src/libs/7zip/win/C/XzIn.c307
-rw-r--r--src/libs/7zip/win/CPP/7zip/7zip.pri6
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7z.pri30
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zCompressionMode.h49
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.cpp343
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.h65
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.cpp464
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.h57
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zExtract.cpp262
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.cpp123
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.h58
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.cpp149
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.h58
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.cpp753
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.h179
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandlerOut.cpp875
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.cpp19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.h101
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.cpp1679
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.h412
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zItem.h186
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zOut.cpp901
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zOut.h319
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zProperties.cpp170
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zProperties.h22
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zRegister.cpp25
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zSpecStream.cpp22
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zSpecStream.h35
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zUpdate.cpp1363
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/7zUpdate.h120
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/7z/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Archive.pri6
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2.cpp119
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2.h179
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2MT.cpp218
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2MT.h83
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/Common.pri19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/DummyOutStream.cpp17
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/DummyOutStream.h25
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/HandlerOut.cpp141
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/HandlerOut.h65
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/InStreamWithCRC.cpp46
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/InStreamWithCRC.h67
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/ItemNameUtils.cpp88
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/ItemNameUtils.h27
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/MultiStream.cpp191
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/MultiStream.h89
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp18
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithCRC.h37
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/ParseProperties.h6
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/IArchive.h476
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/LzmaHandler.cpp604
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/SplitHandler.cpp369
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/XzHandler.cpp991
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/CWrappers.cpp230
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/CWrappers.h114
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/Common.pri40
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/CreateCoder.cpp391
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/CreateCoder.h127
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/FilePathAutoRename.cpp55
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/FilePathAutoRename.h10
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/FileStreams.cpp435
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/FileStreams.h148
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/FilterCoder.cpp265
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/FilterCoder.h142
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/InBuffer.cpp135
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/InBuffer.h90
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/InOutTempBuffer.cpp119
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/InOutTempBuffer.h46
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/LimitedStreams.cpp349
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/LimitedStreams.h251
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/LockedStream.cpp23
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/LockedStream.h38
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/MethodId.h10
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/MethodProps.cpp441
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/MethodProps.h185
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/OutBuffer.cpp111
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/OutBuffer.h63
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/ProgressUtils.cpp42
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/ProgressUtils.h34
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/PropId.cpp99
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/RegisterArc.h73
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/RegisterCodec.h66
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StreamBinder.cpp126
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StreamBinder.h34
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StreamObjects.cpp250
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StreamObjects.h140
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StreamUtils.cpp56
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/StreamUtils.h13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/UniqBlocks.cpp56
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/UniqBlocks.h30
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/VirtThread.cpp48
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/VirtThread.h24
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Bcj2Coder.cpp366
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Bcj2Coder.h82
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Bcj2Register.cpp19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BcjCoder.cpp15
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BcjCoder.h19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BcjRegister.cpp19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BranchCoder.cpp19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BranchCoder.h44
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BranchMisc.cpp21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BranchMisc.h14
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BranchRegister.cpp30
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ByteSwap.cpp73
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Compress.pri30
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/CopyCoder.cpp74
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/CopyCoder.h35
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/CopyRegister.cpp14
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeltaFilter.cpp125
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzma2Decoder.cpp189
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzma2Decoder.h73
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzma2Encoder.cpp94
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzma2Encoder.h36
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzma2Register.cpp20
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzmaDecoder.cpp266
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzmaDecoder.h88
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzmaEncoder.cpp161
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzmaEncoder.h38
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzmaRegister.cpp20
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/RangeCoder.h201
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/RangeCoderBit.h114
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Guid.txt192
-rw-r--r--src/libs/7zip/win/CPP/7zip/ICoder.h211
-rw-r--r--src/libs/7zip/win/CPP/7zip/IDecl.h15
-rw-r--r--src/libs/7zip/win/CPP/7zip/IPassword.h23
-rw-r--r--src/libs/7zip/win/CPP/7zip/IProgress.h33
-rw-r--r--src/libs/7zip/win/CPP/7zip/IStream.h127
-rw-r--r--src/libs/7zip/win/CPP/7zip/PropID.h124
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ArchiveCommandLine.cpp1257
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ArchiveCommandLine.h122
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp1191
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ArchiveExtractCallback.h299
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp125
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ArchiveOpenCallback.h111
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Common.pri44
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/DefaultName.cpp35
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/DefaultName.h11
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/DirItem.h126
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/EnumDirItems.cpp757
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/EnumDirItems.h27
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Extract.cpp473
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Extract.h94
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ExtractMode.h33
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ExtractingFilePath.cpp190
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ExtractingFilePath.h21
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/HashCalc.cpp361
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/HashCalc.h107
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/IFileExtractCallback.h72
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/LoadCodecs.cpp900
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/LoadCodecs.h303
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/OpenArchive.cpp3211
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/OpenArchive.h346
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/PropIDUtils.cpp553
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/PropIDUtils.h17
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Property.h14
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/SetProperties.cpp80
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/SetProperties.h10
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/SortUtils.cpp23
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/SortUtils.h10
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/TempFiles.cpp21
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/TempFiles.h16
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Update.cpp1477
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Update.h188
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdateAction.cpp64
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdateAction.h66
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdateCallback.cpp574
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdateCallback.h122
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdatePair.cpp233
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdatePair.h27
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdateProduce.cpp73
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/UpdateProduce.h55
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Console/Console.pri4
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Console/PercentPrinter.cpp102
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Console/PercentPrinter.h30
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Console/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/Common/ComTry.h17
-rw-r--r--src/libs/7zip/win/CPP/Common/CommandLineParser.cpp198
-rw-r--r--src/libs/7zip/win/CPP/Common/CommandLineParser.h63
-rw-r--r--src/libs/7zip/win/CPP/Common/Common.h13
-rw-r--r--src/libs/7zip/win/CPP/Common/Common.pri35
-rw-r--r--src/libs/7zip/win/CPP/Common/Defs.h20
-rw-r--r--src/libs/7zip/win/CPP/Common/IntToString.cpp146
-rw-r--r--src/libs/7zip/win/CPP/Common/IntToString.h24
-rw-r--r--src/libs/7zip/win/CPP/Common/ListFileUtils.cpp117
-rw-r--r--src/libs/7zip/win/CPP/Common/ListFileUtils.h14
-rw-r--r--src/libs/7zip/win/CPP/Common/MyBuffer.h237
-rw-r--r--src/libs/7zip/win/CPP/Common/MyCom.h242
-rw-r--r--src/libs/7zip/win/CPP/Common/MyException.h14
-rw-r--r--src/libs/7zip/win/CPP/Common/MyGuidDef.h54
-rw-r--r--src/libs/7zip/win/CPP/Common/MyInitGuid.h45
-rw-r--r--src/libs/7zip/win/CPP/Common/MyString.cpp1215
-rw-r--r--src/libs/7zip/win/CPP/Common/MyString.h525
-rw-r--r--src/libs/7zip/win/CPP/Common/MyTypes.h30
-rw-r--r--src/libs/7zip/win/CPP/Common/MyUnknown.h13
-rw-r--r--src/libs/7zip/win/CPP/Common/MyVector.h615
-rw-r--r--src/libs/7zip/win/CPP/Common/MyWindows.cpp145
-rw-r--r--src/libs/7zip/win/CPP/Common/MyWindows.h216
-rw-r--r--src/libs/7zip/win/CPP/Common/NewHandler.cpp162
-rw-r--r--src/libs/7zip/win/CPP/Common/NewHandler.h68
-rw-r--r--src/libs/7zip/win/CPP/Common/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/Common/StdOutStream.cpp106
-rw-r--r--src/libs/7zip/win/CPP/Common/StdOutStream.h62
-rw-r--r--src/libs/7zip/win/CPP/Common/StringConvert.cpp165
-rw-r--r--src/libs/7zip/win/CPP/Common/StringConvert.h77
-rw-r--r--src/libs/7zip/win/CPP/Common/StringToInt.cpp144
-rw-r--r--src/libs/7zip/win/CPP/Common/StringToInt.h21
-rw-r--r--src/libs/7zip/win/CPP/Common/UTFConvert.cpp176
-rw-r--r--src/libs/7zip/win/CPP/Common/UTFConvert.h12
-rw-r--r--src/libs/7zip/win/CPP/Common/Wildcard.cpp615
-rw-r--r--src/libs/7zip/win/CPP/Common/Wildcard.h157
-rw-r--r--src/libs/7zip/win/CPP/Windows/DLL.cpp110
-rw-r--r--src/libs/7zip/win/CPP/Windows/DLL.h52
-rw-r--r--src/libs/7zip/win/CPP/Windows/Defs.h17
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileDir.cpp583
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileDir.h97
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileFind.cpp579
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileFind.h158
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileIO.cpp432
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileIO.h201
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileLink.cpp426
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileMapping.h66
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileName.cpp687
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileName.h74
-rw-r--r--src/libs/7zip/win/CPP/Windows/Handle.h37
-rw-r--r--src/libs/7zip/win/CPP/Windows/PropVariant.cpp300
-rw-r--r--src/libs/7zip/win/CPP/Windows/PropVariant.h107
-rw-r--r--src/libs/7zip/win/CPP/Windows/PropVariantConv.cpp99
-rw-r--r--src/libs/7zip/win/CPP/Windows/PropVariantConv.h30
-rw-r--r--src/libs/7zip/win/CPP/Windows/SecurityUtils.cpp179
-rw-r--r--src/libs/7zip/win/CPP/Windows/SecurityUtils.h167
-rw-r--r--src/libs/7zip/win/CPP/Windows/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/Windows/Synchronization.cpp10
-rw-r--r--src/libs/7zip/win/CPP/Windows/Synchronization.h164
-rw-r--r--src/libs/7zip/win/CPP/Windows/System.cpp72
-rw-r--r--src/libs/7zip/win/CPP/Windows/System.h16
-rw-r--r--src/libs/7zip/win/CPP/Windows/Thread.h38
-rw-r--r--src/libs/7zip/win/CPP/Windows/TimeUtils.cpp203
-rw-r--r--src/libs/7zip/win/CPP/Windows/TimeUtils.h23
-rw-r--r--src/libs/7zip/win/CPP/Windows/Windows.pri29
-rw-r--r--src/libs/7zip/win/win.pri11
293 files changed, 0 insertions, 56670 deletions
diff --git a/src/libs/7zip/win/C/7zCrc.c b/src/libs/7zip/win/C/7zCrc.c
deleted file mode 100644
index 5f32380dd..000000000
--- a/src/libs/7zip/win/C/7zCrc.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* 7zCrc.c -- CRC32 init
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "7zCrc.h"
-#include "CpuArch.h"
-
-#define kCrcPoly 0xEDB88320
-
-#ifdef MY_CPU_X86_OR_AMD64
- #define CRC_NUM_TABLES 8
- UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
-#elif defined(MY_CPU_LE)
- #define CRC_NUM_TABLES 4
-#else
- #define CRC_NUM_TABLES 5
- #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))
- UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
-#endif
-
-#ifndef MY_CPU_BE
- UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
-#endif
-
-typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);
-
-CRC_FUNC g_CrcUpdate;
-UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
-
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
-{
- return g_CrcUpdate(v, data, size, g_CrcTable);
-}
-
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
-{
- return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;
-}
-
-void MY_FAST_CALL CrcGenerateTable()
-{
- UInt32 i;
- for (i = 0; i < 256; i++)
- {
- UInt32 r = i;
- unsigned j;
- for (j = 0; j < 8; j++)
- r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
- g_CrcTable[i] = r;
- }
- for (; i < 256 * CRC_NUM_TABLES; i++)
- {
- UInt32 r = g_CrcTable[i - 256];
- g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
- }
-
- #ifdef MY_CPU_LE
-
- g_CrcUpdate = CrcUpdateT4;
-
- #if CRC_NUM_TABLES == 8
- if (!CPU_Is_InOrder())
- g_CrcUpdate = CrcUpdateT8;
- #endif
-
- #else
- {
- #ifndef MY_CPU_BE
- UInt32 k = 1;
- if (*(const Byte *)&k == 1)
- g_CrcUpdate = CrcUpdateT4;
- else
- #endif
- {
- for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
- {
- UInt32 x = g_CrcTable[i - 256];
- g_CrcTable[i] = CRC_UINT32_SWAP(x);
- }
- g_CrcUpdate = CrcUpdateT1_BeT4;
- }
- }
- #endif
-}
diff --git a/src/libs/7zip/win/C/7zCrc.h b/src/libs/7zip/win/C/7zCrc.h
deleted file mode 100644
index 8fd579587..000000000
--- a/src/libs/7zip/win/C/7zCrc.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 7zCrc.h -- CRC32 calculation
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_CRC_H
-#define __7Z_CRC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-extern UInt32 g_CrcTable[];
-
-/* Call CrcGenerateTable one time before other CRC functions */
-void MY_FAST_CALL CrcGenerateTable(void);
-
-#define CRC_INIT_VAL 0xFFFFFFFF
-#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
-#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
-
-UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
-UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/7zCrcOpt.c b/src/libs/7zip/win/C/7zCrcOpt.c
deleted file mode 100644
index ce132b5d4..000000000
--- a/src/libs/7zip/win/C/7zCrcOpt.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* 7zCrcOpt.c -- CRC32 calculation
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-
-#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
-
-#ifndef MY_CPU_BE
-
-UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- for (; size >= 4; size -= 4, p += 4)
- {
- v ^= *(const UInt32 *)p;
- v =
- table[0x300 + (v & 0xFF)] ^
- table[0x200 + ((v >> 8) & 0xFF)] ^
- table[0x100 + ((v >> 16) & 0xFF)] ^
- table[0x000 + ((v >> 24))];
- }
- for (; size > 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- return v;
-}
-
-UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table)
-{
- return CrcUpdateT4(v, data, size, table);
-}
-
-#endif
-
-
-#ifndef MY_CPU_LE
-
-#define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))
-
-UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- v = CRC_UINT32_SWAP(v);
- table += 0x100;
- for (; size >= 4; size -= 4, p += 4)
- {
- v ^= *(const UInt32 *)p;
- v =
- table[0x000 + (v & 0xFF)] ^
- table[0x100 + ((v >> 8) & 0xFF)] ^
- table[0x200 + ((v >> 16) & 0xFF)] ^
- table[0x300 + ((v >> 24))];
- }
- table -= 0x100;
- v = CRC_UINT32_SWAP(v);
- for (; size > 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- return v;
-}
-
-#endif
diff --git a/src/libs/7zip/win/C/7zStream.c b/src/libs/7zip/win/C/7zStream.c
deleted file mode 100644
index 88f9c42b1..000000000
--- a/src/libs/7zip/win/C/7zStream.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/* 7zStream.c -- 7z Stream functions
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include <string.h>
-
-#include "7zTypes.h"
-
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
-{
- while (size != 0)
- {
- size_t processed = size;
- RINOK(stream->Read(stream, buf, &processed));
- if (processed == 0)
- return errorType;
- buf = (void *)((Byte *)buf + processed);
- size -= processed;
- }
- return SZ_OK;
-}
-
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
-{
- return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
-}
-
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
-{
- size_t processed = 1;
- RINOK(stream->Read(stream, buf, &processed));
- return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
-}
-
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
-{
- Int64 t = offset;
- return stream->Seek(stream, &t, SZ_SEEK_SET);
-}
-
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
-{
- const void *lookBuf;
- if (*size == 0)
- return SZ_OK;
- RINOK(stream->Look(stream, &lookBuf, size));
- memcpy(buf, lookBuf, *size);
- return stream->Skip(stream, *size);
-}
-
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
-{
- while (size != 0)
- {
- size_t processed = size;
- RINOK(stream->Read(stream, buf, &processed));
- if (processed == 0)
- return errorType;
- buf = (void *)((Byte *)buf + processed);
- size -= processed;
- }
- return SZ_OK;
-}
-
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
-{
- return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
-}
-
-static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)
-{
- SRes res = SZ_OK;
- CLookToRead *p = (CLookToRead *)pp;
- size_t size2 = p->size - p->pos;
- if (size2 == 0 && *size > 0)
- {
- p->pos = 0;
- size2 = LookToRead_BUF_SIZE;
- res = p->realStream->Read(p->realStream, p->buf, &size2);
- p->size = size2;
- }
- if (size2 < *size)
- *size = size2;
- *buf = p->buf + p->pos;
- return res;
-}
-
-static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)
-{
- SRes res = SZ_OK;
- CLookToRead *p = (CLookToRead *)pp;
- size_t size2 = p->size - p->pos;
- if (size2 == 0 && *size > 0)
- {
- p->pos = 0;
- if (*size > LookToRead_BUF_SIZE)
- *size = LookToRead_BUF_SIZE;
- res = p->realStream->Read(p->realStream, p->buf, size);
- size2 = p->size = *size;
- }
- if (size2 < *size)
- *size = size2;
- *buf = p->buf + p->pos;
- return res;
-}
-
-static SRes LookToRead_Skip(void *pp, size_t offset)
-{
- CLookToRead *p = (CLookToRead *)pp;
- p->pos += offset;
- return SZ_OK;
-}
-
-static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
-{
- CLookToRead *p = (CLookToRead *)pp;
- size_t rem = p->size - p->pos;
- if (rem == 0)
- return p->realStream->Read(p->realStream, buf, size);
- if (rem > *size)
- rem = *size;
- memcpy(buf, p->buf + p->pos, rem);
- p->pos += rem;
- *size = rem;
- return SZ_OK;
-}
-
-static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
-{
- CLookToRead *p = (CLookToRead *)pp;
- p->pos = p->size = 0;
- return p->realStream->Seek(p->realStream, pos, origin);
-}
-
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
-{
- p->s.Look = lookahead ?
- LookToRead_Look_Lookahead :
- LookToRead_Look_Exact;
- p->s.Skip = LookToRead_Skip;
- p->s.Read = LookToRead_Read;
- p->s.Seek = LookToRead_Seek;
-}
-
-void LookToRead_Init(CLookToRead *p)
-{
- p->pos = p->size = 0;
-}
-
-static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
-{
- CSecToLook *p = (CSecToLook *)pp;
- return LookInStream_LookRead(p->realStream, buf, size);
-}
-
-void SecToLook_CreateVTable(CSecToLook *p)
-{
- p->s.Read = SecToLook_Read;
-}
-
-static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
-{
- CSecToRead *p = (CSecToRead *)pp;
- return p->realStream->Read(p->realStream, buf, size);
-}
-
-void SecToRead_CreateVTable(CSecToRead *p)
-{
- p->s.Read = SecToRead_Read;
-}
diff --git a/src/libs/7zip/win/C/7zTypes.h b/src/libs/7zip/win/C/7zTypes.h
deleted file mode 100644
index 778413ef4..000000000
--- a/src/libs/7zip/win/C/7zTypes.h
+++ /dev/null
@@ -1,256 +0,0 @@
-/* 7zTypes.h -- Basic types
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_TYPES_H
-#define __7Z_TYPES_H
-
-#ifdef _WIN32
-/* #include <windows.h> */
-#endif
-
-#include <stddef.h>
-
-#ifndef EXTERN_C_BEGIN
-#ifdef __cplusplus
-#define EXTERN_C_BEGIN extern "C" {
-#define EXTERN_C_END }
-#else
-#define EXTERN_C_BEGIN
-#define EXTERN_C_END
-#endif
-#endif
-
-EXTERN_C_BEGIN
-
-#define SZ_OK 0
-
-#define SZ_ERROR_DATA 1
-#define SZ_ERROR_MEM 2
-#define SZ_ERROR_CRC 3
-#define SZ_ERROR_UNSUPPORTED 4
-#define SZ_ERROR_PARAM 5
-#define SZ_ERROR_INPUT_EOF 6
-#define SZ_ERROR_OUTPUT_EOF 7
-#define SZ_ERROR_READ 8
-#define SZ_ERROR_WRITE 9
-#define SZ_ERROR_PROGRESS 10
-#define SZ_ERROR_FAIL 11
-#define SZ_ERROR_THREAD 12
-
-#define SZ_ERROR_ARCHIVE 16
-#define SZ_ERROR_NO_ARCHIVE 17
-
-typedef int SRes;
-
-#ifdef _WIN32
-/* typedef DWORD WRes; */
-typedef unsigned WRes;
-#else
-typedef int WRes;
-#endif
-
-#ifndef RINOK
-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
-#endif
-
-typedef unsigned char Byte;
-typedef short Int16;
-typedef unsigned short UInt16;
-
-#ifdef _LZMA_UINT32_IS_ULONG
-typedef long Int32;
-typedef unsigned long UInt32;
-#else
-typedef int Int32;
-typedef unsigned int UInt32;
-#endif
-
-#ifdef _SZ_NO_INT_64
-
-/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
- NOTES: Some code will work incorrectly in that case! */
-
-typedef long Int64;
-typedef unsigned long UInt64;
-
-#else
-
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-typedef __int64 Int64;
-typedef unsigned __int64 UInt64;
-#define UINT64_CONST(n) n
-#else
-typedef long long int Int64;
-typedef unsigned long long int UInt64;
-#define UINT64_CONST(n) n ## ULL
-#endif
-
-#endif
-
-#ifdef _LZMA_NO_SYSTEM_SIZE_T
-typedef UInt32 SizeT;
-#else
-typedef size_t SizeT;
-#endif
-
-typedef int Bool;
-#define True 1
-#define False 0
-
-
-#ifdef _WIN32
-#define MY_STD_CALL __stdcall
-#else
-#define MY_STD_CALL
-#endif
-
-#ifdef _MSC_VER
-
-#if _MSC_VER >= 1300
-#define MY_NO_INLINE __declspec(noinline)
-#else
-#define MY_NO_INLINE
-#endif
-
-#define MY_CDECL __cdecl
-#define MY_FAST_CALL __fastcall
-
-#else
-
-#define MY_NO_INLINE
-#define MY_CDECL
-#define MY_FAST_CALL
-
-#endif
-
-
-/* The following interfaces use first parameter as pointer to structure */
-
-typedef struct
-{
- Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
-} IByteIn;
-
-typedef struct
-{
- void (*Write)(void *p, Byte b);
-} IByteOut;
-
-typedef struct
-{
- SRes (*Read)(void *p, void *buf, size_t *size);
- /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
- (output(*size) < input(*size)) is allowed */
-} ISeqInStream;
-
-/* it can return SZ_ERROR_INPUT_EOF */
-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
-SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
-
-typedef struct
-{
- size_t (*Write)(void *p, const void *buf, size_t size);
- /* Returns: result - the number of actually written bytes.
- (result < size) means error */
-} ISeqOutStream;
-
-typedef enum
-{
- SZ_SEEK_SET = 0,
- SZ_SEEK_CUR = 1,
- SZ_SEEK_END = 2
-} ESzSeek;
-
-typedef struct
-{
- SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
- SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
-} ISeekInStream;
-
-typedef struct
-{
- SRes (*Look)(void *p, const void **buf, size_t *size);
- /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
- (output(*size) > input(*size)) is not allowed
- (output(*size) < input(*size)) is allowed */
- SRes (*Skip)(void *p, size_t offset);
- /* offset must be <= output(*size) of Look */
-
- SRes (*Read)(void *p, void *buf, size_t *size);
- /* reads directly (without buffer). It's same as ISeqInStream::Read */
- SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
-} ILookInStream;
-
-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
-SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
-
-/* reads via ILookInStream::Read */
-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
-
-#define LookToRead_BUF_SIZE (1 << 14)
-
-typedef struct
-{
- ILookInStream s;
- ISeekInStream *realStream;
- size_t pos;
- size_t size;
- Byte buf[LookToRead_BUF_SIZE];
-} CLookToRead;
-
-void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
-void LookToRead_Init(CLookToRead *p);
-
-typedef struct
-{
- ISeqInStream s;
- ILookInStream *realStream;
-} CSecToLook;
-
-void SecToLook_CreateVTable(CSecToLook *p);
-
-typedef struct
-{
- ISeqInStream s;
- ILookInStream *realStream;
-} CSecToRead;
-
-void SecToRead_CreateVTable(CSecToRead *p);
-
-typedef struct
-{
- SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
- /* Returns: result. (result != SZ_OK) means break.
- Value (UInt64)(Int64)-1 for size means unknown value. */
-} ICompressProgress;
-
-typedef struct
-{
- void *(*Alloc)(void *p, size_t size);
- void (*Free)(void *p, void *address); /* address can be 0 */
-} ISzAlloc;
-
-#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
-#define IAlloc_Free(p, a) (p)->Free((p), a)
-
-#ifdef _WIN32
-
-#define CHAR_PATH_SEPARATOR '\\'
-#define WCHAR_PATH_SEPARATOR L'\\'
-#define STRING_PATH_SEPARATOR "\\"
-#define WSTRING_PATH_SEPARATOR L"\\"
-
-#else
-
-#define CHAR_PATH_SEPARATOR '/'
-#define WCHAR_PATH_SEPARATOR L'/'
-#define STRING_PATH_SEPARATOR "/"
-#define WSTRING_PATH_SEPARATOR L"/"
-
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/7zVersion.h b/src/libs/7zip/win/C/7zVersion.h
deleted file mode 100644
index 475918352..000000000
--- a/src/libs/7zip/win/C/7zVersion.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#define MY_VER_MAJOR 9
-#define MY_VER_MINOR 38
-#define MY_VER_BUILD 00
-#define MY_VERSION "9.38 beta"
-// #define MY_7ZIP_VERSION "9.38"
-#define MY_DATE "2015-01-03"
-#undef MY_COPYRIGHT
-#undef MY_VERSION_COPYRIGHT_DATE
-#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
-#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
diff --git a/src/libs/7zip/win/C/Alloc.c b/src/libs/7zip/win/C/Alloc.c
deleted file mode 100644
index 1f3f6c661..000000000
--- a/src/libs/7zip/win/C/Alloc.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* Alloc.c -- Memory allocation functions
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-#include <stdlib.h>
-
-#include "Alloc.h"
-
-/* #define _SZ_ALLOC_DEBUG */
-
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
-#ifdef _SZ_ALLOC_DEBUG
-#include <stdio.h>
-int g_allocCount = 0;
-int g_allocCountMid = 0;
-int g_allocCountBig = 0;
-#endif
-
-void *MyAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- {
- void *p = malloc(size);
- fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
- return p;
- }
- #else
- return malloc(size);
- #endif
-}
-
-void MyFree(void *address)
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
- #endif
- free(address);
-}
-
-#ifdef _WIN32
-
-void *MidAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
- #endif
- return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void MidFree(void *address)
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
- #endif
- if (address == 0)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#ifndef MEM_LARGE_PAGES
-#undef _7ZIP_LARGE_PAGES
-#endif
-
-#ifdef _7ZIP_LARGE_PAGES
-SIZE_T g_LargePageSize = 0;
-typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
-#endif
-
-void SetLargePageSize()
-{
- #ifdef _7ZIP_LARGE_PAGES
- SIZE_T size = 0;
- GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
- GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
- if (largePageMinimum == 0)
- return;
- size = largePageMinimum();
- if (size == 0 || (size & (size - 1)) != 0)
- return;
- g_LargePageSize = size;
- #endif
-}
-
-
-void *BigAlloc(size_t size)
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
- #endif
-
- #ifdef _7ZIP_LARGE_PAGES
- if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
- {
- void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
- MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
- if (res != 0)
- return res;
- }
- #endif
- return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void BigFree(void *address)
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
- #endif
-
- if (address == 0)
- return;
- VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#endif
diff --git a/src/libs/7zip/win/C/Alloc.h b/src/libs/7zip/win/C/Alloc.h
deleted file mode 100644
index b8e414367..000000000
--- a/src/libs/7zip/win/C/Alloc.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Alloc.h -- Memory allocation functions
-2009-02-07 : Igor Pavlov : Public domain */
-
-#ifndef __COMMON_ALLOC_H
-#define __COMMON_ALLOC_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void *MyAlloc(size_t size);
-void MyFree(void *address);
-
-#ifdef _WIN32
-
-void SetLargePageSize();
-
-void *MidAlloc(size_t size);
-void MidFree(void *address);
-void *BigAlloc(size_t size);
-void BigFree(void *address);
-
-#else
-
-#define MidAlloc(size) MyAlloc(size)
-#define MidFree(address) MyFree(address)
-#define BigAlloc(size) MyAlloc(size)
-#define BigFree(address) MyFree(address)
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/libs/7zip/win/C/Bra.c b/src/libs/7zip/win/C/Bra.c
deleted file mode 100644
index 33f7a391c..000000000
--- a/src/libs/7zip/win/C/Bra.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/* Bra.c -- Converters for RISC code
-2010-04-16 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Bra.h"
-
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 4)
- return 0;
- size -= 4;
- ip += 8;
- for (i = 0; i <= size; i += 4)
- {
- if (data[i + 3] == 0xEB)
- {
- UInt32 dest;
- UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
- src <<= 2;
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
- dest >>= 2;
- data[i + 2] = (Byte)(dest >> 16);
- data[i + 1] = (Byte)(dest >> 8);
- data[i + 0] = (Byte)dest;
- }
- }
- return i;
-}
-
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 4)
- return 0;
- size -= 4;
- ip += 4;
- for (i = 0; i <= size; i += 2)
- {
- if ((data[i + 1] & 0xF8) == 0xF0 &&
- (data[i + 3] & 0xF8) == 0xF8)
- {
- UInt32 dest;
- UInt32 src =
- (((UInt32)data[i + 1] & 0x7) << 19) |
- ((UInt32)data[i + 0] << 11) |
- (((UInt32)data[i + 3] & 0x7) << 8) |
- (data[i + 2]);
-
- src <<= 1;
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
- dest >>= 1;
-
- data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
- data[i + 0] = (Byte)(dest >> 11);
- data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
- data[i + 2] = (Byte)dest;
- i += 2;
- }
- }
- return i;
-}
-
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 4)
- return 0;
- size -= 4;
- for (i = 0; i <= size; i += 4)
- {
- if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
- {
- UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
- ((UInt32)data[i + 1] << 16) |
- ((UInt32)data[i + 2] << 8) |
- ((UInt32)data[i + 3] & (~3));
-
- UInt32 dest;
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
- data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
- data[i + 1] = (Byte)(dest >> 16);
- data[i + 2] = (Byte)(dest >> 8);
- data[i + 3] &= 0x3;
- data[i + 3] |= dest;
- }
- }
- return i;
-}
-
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- UInt32 i;
- if (size < 4)
- return 0;
- size -= 4;
- for (i = 0; i <= size; i += 4)
- {
- if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||
- (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))
- {
- UInt32 src =
- ((UInt32)data[i + 0] << 24) |
- ((UInt32)data[i + 1] << 16) |
- ((UInt32)data[i + 2] << 8) |
- ((UInt32)data[i + 3]);
- UInt32 dest;
-
- src <<= 2;
- if (encoding)
- dest = ip + i + src;
- else
- dest = src - (ip + i);
- dest >>= 2;
-
- dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
-
- data[i + 0] = (Byte)(dest >> 24);
- data[i + 1] = (Byte)(dest >> 16);
- data[i + 2] = (Byte)(dest >> 8);
- data[i + 3] = (Byte)dest;
- }
- }
- return i;
-}
diff --git a/src/libs/7zip/win/C/Bra.h b/src/libs/7zip/win/C/Bra.h
deleted file mode 100644
index 184c291a7..000000000
--- a/src/libs/7zip/win/C/Bra.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Bra.h -- Branch converters for executables
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __BRA_H
-#define __BRA_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/*
-These functions convert relative addresses to absolute addresses
-in CALL instructions to increase the compression ratio.
-
- In:
- data - data buffer
- size - size of data
- ip - current virtual Instruction Pinter (IP) value
- state - state variable for x86 converter
- encoding - 0 (for decoding), 1 (for encoding)
-
- Out:
- state - state variable for x86 converter
-
- Returns:
- The number of processed bytes. If you call these functions with multiple calls,
- you must start next call with first byte after block of processed bytes.
-
- Type Endian Alignment LookAhead
-
- x86 little 1 4
- ARMT little 2 2
- ARM little 4 0
- PPC big 4 0
- SPARC big 4 0
- IA64 little 16 0
-
- size must be >= Alignment + LookAhead, if it's not last block.
- If (size < Alignment + LookAhead), converter returns 0.
-
- Example:
-
- UInt32 ip = 0;
- for ()
- {
- ; size must be >= Alignment + LookAhead, if it's not last block
- SizeT processed = Convert(data, size, ip, 1);
- data += processed;
- size -= processed;
- ip += processed;
- }
-*/
-
-#define x86_Convert_Init(state) { state = 0; }
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
-SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Bra86.c b/src/libs/7zip/win/C/Bra86.c
deleted file mode 100644
index 6db15e7ec..000000000
--- a/src/libs/7zip/win/C/Bra86.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* Bra86.c -- Converter for x86 code (BCJ)
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Bra.h"
-
-#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
-
-SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
-{
- SizeT pos = 0;
- UInt32 mask = *state & 7;
- if (size < 5)
- return 0;
- size -= 4;
- ip += 5;
-
- for (;;)
- {
- Byte *p = data + pos;
- const Byte *limit = data + size;
- for (; p < limit; p++)
- if ((*p & 0xFE) == 0xE8)
- break;
-
- {
- SizeT d = (SizeT)(p - data - pos);
- pos = (SizeT)(p - data);
- if (p >= limit)
- {
- *state = (d > 2 ? 0 : mask >> (unsigned)d);
- return pos;
- }
- if (d > 2)
- mask = 0;
- else
- {
- mask >>= (unsigned)d;
- if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1])))
- {
- mask = (mask >> 1) | 4;
- pos++;
- continue;
- }
- }
- }
-
- if (Test86MSByte(p[4]))
- {
- UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
- UInt32 cur = ip + (UInt32)pos;
- pos += 5;
- if (encoding)
- v += cur;
- else
- v -= cur;
- if (mask != 0)
- {
- unsigned sh = (mask & 6) << 2;
- if (Test86MSByte((Byte)(v >> sh)))
- {
- v ^= (((UInt32)0x100 << sh) - 1);
- if (encoding)
- v += cur;
- else
- v -= cur;
- }
- mask = 0;
- }
- p[1] = (Byte)v;
- p[2] = (Byte)(v >> 8);
- p[3] = (Byte)(v >> 16);
- p[4] = (Byte)(0 - ((v >> 24) & 1));
- }
- else
- {
- mask = (mask >> 1) | 4;
- pos++;
- }
- }
-}
diff --git a/src/libs/7zip/win/C/BraIA64.c b/src/libs/7zip/win/C/BraIA64.c
deleted file mode 100644
index aa1a44e1e..000000000
--- a/src/libs/7zip/win/C/BraIA64.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* BraIA64.c -- Converter for IA-64 code
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Bra.h"
-
-static const Byte kBranchTable[32] =
-{
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 4, 4, 6, 6, 0, 0, 7, 7,
- 4, 4, 0, 0, 4, 4, 0, 0
-};
-
-SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
-{
- SizeT i;
- if (size < 16)
- return 0;
- size -= 16;
- for (i = 0; i <= size; i += 16)
- {
- UInt32 instrTemplate = data[i] & 0x1F;
- UInt32 mask = kBranchTable[instrTemplate];
- UInt32 bitPos = 5;
- int slot;
- for (slot = 0; slot < 3; slot++, bitPos += 41)
- {
- UInt32 bytePos, bitRes;
- UInt64 instruction, instNorm;
- int j;
- if (((mask >> slot) & 1) == 0)
- continue;
- bytePos = (bitPos >> 3);
- bitRes = bitPos & 0x7;
- instruction = 0;
- for (j = 0; j < 6; j++)
- instruction += (UInt64)data[i + j + bytePos] << (8 * j);
-
- instNorm = instruction >> bitRes;
- if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
- {
- UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
- UInt32 dest;
- src |= ((UInt32)(instNorm >> 36) & 1) << 20;
-
- src <<= 4;
-
- if (encoding)
- dest = ip + (UInt32)i + src;
- else
- dest = src - (ip + (UInt32)i);
-
- dest >>= 4;
-
- instNorm &= ~((UInt64)(0x8FFFFF) << 13);
- instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
- instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
-
- instruction &= (1 << bitRes) - 1;
- instruction |= (instNorm << bitRes);
- for (j = 0; j < 6; j++)
- data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
- }
- }
- }
- return i;
-}
diff --git a/src/libs/7zip/win/C/C.pri b/src/libs/7zip/win/C/C.pri
deleted file mode 100644
index 23d688642..000000000
--- a/src/libs/7zip/win/C/C.pri
+++ /dev/null
@@ -1,48 +0,0 @@
-HEADERS += $$7ZIP_BASE/C/7zCrc.h \
- $$7ZIP_BASE/C/7zTypes.h \
- $$7ZIP_BASE/C/7zVersion.h \
- $$7ZIP_BASE/C/Alloc.h \
- $$7ZIP_BASE/C/Bra.h \
- $$7ZIP_BASE/C/Compiler.h \
- $$7ZIP_BASE/C/CpuArch.h \
- $$7ZIP_BASE/C/Delta.h \
- $$7ZIP_BASE/C/LzFind.h \
- $$7ZIP_BASE/C/LzFindMt.h \
- $$7ZIP_BASE/C/LzHash.h \
- $$7ZIP_BASE/C/Lzma2Dec.h \
- $$7ZIP_BASE/C/Lzma2Enc.h \
- $$7ZIP_BASE/C/LzmaDec.h \
- $$7ZIP_BASE/C/LzmaEnc.h \
- $$7ZIP_BASE/C/MtCoder.h \
- $$7ZIP_BASE/C/Precomp.h \
- $$7ZIP_BASE/C/RotateDefs.h \
- $$7ZIP_BASE/C/Sha256.h \
- $$7ZIP_BASE/C/Threads.h \
- $$7ZIP_BASE/C/Xz.h \
- $$7ZIP_BASE/C/XzCrc64.h \
- $$7ZIP_BASE/C/XzEnc.h
-
-SOURCES += $$7ZIP_BASE/C/7zCrc.c \
- $$7ZIP_BASE/C/7zCrcOpt.c \
- $$7ZIP_BASE/C/7zStream.c \
- $$7ZIP_BASE/C/Alloc.c \
- $$7ZIP_BASE/C/Bra.c \
- $$7ZIP_BASE/C/Bra86.c \
- $$7ZIP_BASE/C/BraIA64.c \
- $$7ZIP_BASE/C/CpuArch.c \
- $$7ZIP_BASE/C/Delta.c \
- $$7ZIP_BASE/C/LzFind.c \
- $$7ZIP_BASE/C/LzFindMt.c \
- $$7ZIP_BASE/C/Lzma2Dec.c \
- $$7ZIP_BASE/C/Lzma2Enc.c \
- $$7ZIP_BASE/C/LzmaDec.c \
- $$7ZIP_BASE/C/LzmaEnc.c \
- $$7ZIP_BASE/C/MtCoder.c \
- $$7ZIP_BASE/C/Sha256.c \
- $$7ZIP_BASE/C/Threads.c \
- $$7ZIP_BASE/C/Xz.c \
- $$7ZIP_BASE/C/XzCrc64.c \
- $$7ZIP_BASE/C/XzCrc64Opt.c \
- $$7ZIP_BASE/C/XzDec.c \
- $$7ZIP_BASE/C/XzEnc.c \
- $$7ZIP_BASE/C/XzIn.c
diff --git a/src/libs/7zip/win/C/Compiler.h b/src/libs/7zip/win/C/Compiler.h
deleted file mode 100644
index 6e964897e..000000000
--- a/src/libs/7zip/win/C/Compiler.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Compiler.h -- Compiler ypes
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_COMPILER_H
-#define __7Z_COMPILER_H
-
-#ifdef _MSC_VER
-
- #ifdef UNDER_CE
- #define RPC_NO_WINDOWS_H
- /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */
- #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
- #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int
- #endif
-
- #if _MSC_VER >= 1300
- #pragma warning(disable : 4996) // This function or variable may be unsafe
- #else
- #pragma warning(disable : 4511) // copy constructor could not be generated
- #pragma warning(disable : 4512) // assignment operator could not be generated
- #pragma warning(disable : 4702) // unreachable code
- #pragma warning(disable : 4710) // not inlined
- #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
- #endif
-
-#endif
-
-#endif
diff --git a/src/libs/7zip/win/C/CpuArch.c b/src/libs/7zip/win/C/CpuArch.c
deleted file mode 100644
index 4feb028a2..000000000
--- a/src/libs/7zip/win/C/CpuArch.c
+++ /dev/null
@@ -1,190 +0,0 @@
-/* CpuArch.c -- CPU specific code
-2012-05-29: Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-
-#ifdef MY_CPU_X86_OR_AMD64
-
-#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__)
-#define USE_ASM
-#endif
-
-#if !defined(USE_ASM) && _MSC_VER >= 1500
-#include <intrin.h>
-#endif
-
-#if defined(USE_ASM) && !defined(MY_CPU_AMD64)
-static UInt32 CheckFlag(UInt32 flag)
-{
- #ifdef _MSC_VER
- __asm pushfd;
- __asm pop EAX;
- __asm mov EDX, EAX;
- __asm xor EAX, flag;
- __asm push EAX;
- __asm popfd;
- __asm pushfd;
- __asm pop EAX;
- __asm xor EAX, EDX;
- __asm push EDX;
- __asm popfd;
- __asm and flag, EAX;
- #else
- __asm__ __volatile__ (
- "pushf\n\t"
- "pop %%EAX\n\t"
- "movl %%EAX,%%EDX\n\t"
- "xorl %0,%%EAX\n\t"
- "push %%EAX\n\t"
- "popf\n\t"
- "pushf\n\t"
- "pop %%EAX\n\t"
- "xorl %%EDX,%%EAX\n\t"
- "push %%EDX\n\t"
- "popf\n\t"
- "andl %%EAX, %0\n\t":
- "=c" (flag) : "c" (flag));
- #endif
- return flag;
-}
-#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
-#else
-#define CHECK_CPUID_IS_SUPPORTED
-#endif
-
-static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
-{
- #ifdef USE_ASM
-
- #ifdef _MSC_VER
-
- UInt32 a2, b2, c2, d2;
- __asm xor EBX, EBX;
- __asm xor ECX, ECX;
- __asm xor EDX, EDX;
- __asm mov EAX, function;
- __asm cpuid;
- __asm mov a2, EAX;
- __asm mov b2, EBX;
- __asm mov c2, ECX;
- __asm mov d2, EDX;
-
- *a = a2;
- *b = b2;
- *c = c2;
- *d = d2;
-
- #else
-
- __asm__ __volatile__ (
- #if defined(MY_CPU_X86) && defined(__PIC__)
- "mov %%ebx, %%edi;"
- "cpuid;"
- "xchgl %%ebx, %%edi;"
- : "=a" (*a) ,
- "=D" (*b) ,
- #else
- "cpuid"
- : "=a" (*a) ,
- "=b" (*b) ,
- #endif
- "=c" (*c) ,
- "=d" (*d)
- : "0" (function)) ;
-
- #endif
-
- #else
-
- int CPUInfo[4];
- __cpuid(CPUInfo, function);
- *a = CPUInfo[0];
- *b = CPUInfo[1];
- *c = CPUInfo[2];
- *d = CPUInfo[3];
-
- #endif
-}
-
-Bool x86cpuid_CheckAndRead(Cx86cpuid *p)
-{
- CHECK_CPUID_IS_SUPPORTED
- MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
- MyCPUID(1, &p->ver, &p->b, &p->c, &p->d);
- return True;
-}
-
-static UInt32 kVendors[][3] =
-{
- { 0x756E6547, 0x49656E69, 0x6C65746E},
- { 0x68747541, 0x69746E65, 0x444D4163},
- { 0x746E6543, 0x48727561, 0x736C7561}
-};
-
-int x86cpuid_GetFirm(const Cx86cpuid *p)
-{
- unsigned i;
- for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
- {
- const UInt32 *v = kVendors[i];
- if (v[0] == p->vendor[0] &&
- v[1] == p->vendor[1] &&
- v[2] == p->vendor[2])
- return (int)i;
- }
- return -1;
-}
-
-Bool CPU_Is_InOrder()
-{
- Cx86cpuid p;
- int firm;
- UInt32 family, model;
- if (!x86cpuid_CheckAndRead(&p))
- return True;
- family = x86cpuid_GetFamily(&p);
- model = x86cpuid_GetModel(&p);
- firm = x86cpuid_GetFirm(&p);
- switch (firm)
- {
- case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && (
- /* Atom CPU */
- model == 0x100C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */
- || model == 0x2006 /* 45 nm, Z6xx */
- || model == 0x2007 /* 32 nm, Z2460 */
- || model == 0x3005 /* 32 nm, Z2760 */
- || model == 0x3006 /* 32 nm, N2xxx, D2xxx */
- )));
- case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA)));
- case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF));
- }
- return True;
-}
-
-#if !defined(MY_CPU_AMD64) && defined(_WIN32)
-#include <windows.h>
-static Bool CPU_Sys_Is_SSE_Supported()
-{
- OSVERSIONINFO vi;
- vi.dwOSVersionInfoSize = sizeof(vi);
- if (!GetVersionEx(&vi))
- return False;
- return (vi.dwMajorVersion >= 5);
-}
-#define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False;
-#else
-#define CHECK_SYS_SSE_SUPPORT
-#endif
-
-Bool CPU_Is_Aes_Supported()
-{
- Cx86cpuid p;
- CHECK_SYS_SSE_SUPPORT
- if (!x86cpuid_CheckAndRead(&p))
- return False;
- return (p.c >> 25) & 1;
-}
-
-#endif
diff --git a/src/libs/7zip/win/C/CpuArch.h b/src/libs/7zip/win/C/CpuArch.h
deleted file mode 100644
index 4fee00937..000000000
--- a/src/libs/7zip/win/C/CpuArch.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/* CpuArch.h -- CPU specific code
-2013-11-12: Igor Pavlov : Public domain */
-
-#ifndef __CPU_ARCH_H
-#define __CPU_ARCH_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/*
-MY_CPU_LE means that CPU is LITTLE ENDIAN.
-If MY_CPU_LE is not defined, we don't know about that property of platform (it can be LITTLE ENDIAN).
-
-MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
-If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
-*/
-
-#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
-#define MY_CPU_AMD64
-#endif
-
-#if defined(MY_CPU_AMD64) || defined(_M_IA64)
-#define MY_CPU_64BIT
-#endif
-
-#if defined(_M_IX86) || defined(__i386__)
-#define MY_CPU_X86
-#endif
-
-#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
-#define MY_CPU_X86_OR_AMD64
-#endif
-
-#if defined(MY_CPU_X86) || defined(_M_ARM)
-#define MY_CPU_32BIT
-#endif
-
-#if defined(_WIN32) && defined(_M_ARM)
-#define MY_CPU_ARM_LE
-#endif
-
-#if defined(_WIN32) && defined(_M_IA64)
-#define MY_CPU_IA64_LE
-#endif
-
-#if defined(MY_CPU_X86_OR_AMD64)
-#define MY_CPU_LE_UNALIGN
-#endif
-
-#if defined(MY_CPU_X86_OR_AMD64) || defined(MY_CPU_ARM_LE) || defined(MY_CPU_IA64_LE) || defined(__ARMEL__) || defined(__MIPSEL__) || defined(__LITTLE_ENDIAN__)
-#define MY_CPU_LE
-#endif
-
-#if defined(__BIG_ENDIAN__) || defined(__m68k__) || defined(__ARMEB__) || defined(__MIPSEB__)
-#define MY_CPU_BE
-#endif
-
-#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
-Stop_Compiling_Bad_Endian
-#endif
-
-#ifdef MY_CPU_LE_UNALIGN
-
-#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
-#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
-#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
-#define SetUi16(p, d) *(UInt16 *)(p) = (d);
-#define SetUi32(p, d) *(UInt32 *)(p) = (d);
-#define SetUi64(p, d) *(UInt64 *)(p) = (d);
-
-#else
-
-#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
-
-#define GetUi32(p) ( \
- ((const Byte *)(p))[0] | \
- ((UInt32)((const Byte *)(p))[1] << 8) | \
- ((UInt32)((const Byte *)(p))[2] << 16) | \
- ((UInt32)((const Byte *)(p))[3] << 24))
-
-#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
-
-#define SetUi16(p, d) { UInt32 _x_ = (d); \
- ((Byte *)(p))[0] = (Byte)_x_; \
- ((Byte *)(p))[1] = (Byte)(_x_ >> 8); }
-
-#define SetUi32(p, d) { UInt32 _x_ = (d); \
- ((Byte *)(p))[0] = (Byte)_x_; \
- ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
- ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
- ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
-
-#define SetUi64(p, d) { UInt64 _x64_ = (d); \
- SetUi32(p, (UInt32)_x64_); \
- SetUi32(((Byte *)(p)) + 4, (UInt32)(_x64_ >> 32)); }
-
-#endif
-
-#if defined(MY_CPU_LE_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
-
-#include <stdlib.h>
-
-#pragma intrinsic(_byteswap_ulong)
-#pragma intrinsic(_byteswap_uint64)
-#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
-#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
-
-#else
-
-#define GetBe32(p) ( \
- ((UInt32)((const Byte *)(p))[0] << 24) | \
- ((UInt32)((const Byte *)(p))[1] << 16) | \
- ((UInt32)((const Byte *)(p))[2] << 8) | \
- ((const Byte *)(p))[3] )
-
-#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
-
-#endif
-
-#define GetBe16(p) ((UInt16)(((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1]))
-
-
-#ifdef MY_CPU_X86_OR_AMD64
-
-typedef struct
-{
- UInt32 maxFunc;
- UInt32 vendor[3];
- UInt32 ver;
- UInt32 b;
- UInt32 c;
- UInt32 d;
-} Cx86cpuid;
-
-enum
-{
- CPU_FIRM_INTEL,
- CPU_FIRM_AMD,
- CPU_FIRM_VIA
-};
-
-Bool x86cpuid_CheckAndRead(Cx86cpuid *p);
-int x86cpuid_GetFirm(const Cx86cpuid *p);
-
-#define x86cpuid_GetFamily(p) (((p)->ver >> 8) & 0xFF00F)
-#define x86cpuid_GetModel(p) (((p)->ver >> 4) & 0xF00F)
-#define x86cpuid_GetStepping(p) ((p)->ver & 0xF)
-
-Bool CPU_Is_InOrder();
-Bool CPU_Is_Aes_Supported();
-
-#endif
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Delta.c b/src/libs/7zip/win/C/Delta.c
deleted file mode 100644
index e3edd21ed..000000000
--- a/src/libs/7zip/win/C/Delta.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Delta.c -- Delta converter
-2009-05-26 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "Delta.h"
-
-void Delta_Init(Byte *state)
-{
- unsigned i;
- for (i = 0; i < DELTA_STATE_SIZE; i++)
- state[i] = 0;
-}
-
-static void MyMemCpy(Byte *dest, const Byte *src, unsigned size)
-{
- unsigned i;
- for (i = 0; i < size; i++)
- dest[i] = src[i];
-}
-
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
-{
- Byte buf[DELTA_STATE_SIZE];
- unsigned j = 0;
- MyMemCpy(buf, state, delta);
- {
- SizeT i;
- for (i = 0; i < size;)
- {
- for (j = 0; j < delta && i < size; i++, j++)
- {
- Byte b = data[i];
- data[i] = (Byte)(b - buf[j]);
- buf[j] = b;
- }
- }
- }
- if (j == delta)
- j = 0;
- MyMemCpy(state, buf + j, delta - j);
- MyMemCpy(state + delta - j, buf, j);
-}
-
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size)
-{
- Byte buf[DELTA_STATE_SIZE];
- unsigned j = 0;
- MyMemCpy(buf, state, delta);
- {
- SizeT i;
- for (i = 0; i < size;)
- {
- for (j = 0; j < delta && i < size; i++, j++)
- {
- buf[j] = data[i] = (Byte)(buf[j] + data[i]);
- }
- }
- }
- if (j == delta)
- j = 0;
- MyMemCpy(state, buf + j, delta - j);
- MyMemCpy(state + delta - j, buf, j);
-}
diff --git a/src/libs/7zip/win/C/Delta.h b/src/libs/7zip/win/C/Delta.h
deleted file mode 100644
index 2fa54ad67..000000000
--- a/src/libs/7zip/win/C/Delta.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Delta.h -- Delta converter
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __DELTA_H
-#define __DELTA_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define DELTA_STATE_SIZE 256
-
-void Delta_Init(Byte *state);
-void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size);
-void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/LzFind.c b/src/libs/7zip/win/C/LzFind.c
deleted file mode 100644
index 9a4d25b80..000000000
--- a/src/libs/7zip/win/C/LzFind.c
+++ /dev/null
@@ -1,763 +0,0 @@
-/* LzFind.c -- Match finder for LZ algorithms
-2009-04-22 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include <string.h>
-
-#include "LzFind.h"
-#include "LzHash.h"
-
-#define kEmptyHashValue 0
-#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
-#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
-#define kNormalizeMask (~(kNormalizeStepMin - 1))
-#define kMaxHistorySize ((UInt32)3 << 30)
-
-#define kStartMaxLen 3
-
-static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
-{
- if (!p->directInput)
- {
- alloc->Free(alloc, p->bufferBase);
- p->bufferBase = 0;
- }
-}
-
-/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
-
-static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
-{
- UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
- if (p->directInput)
- {
- p->blockSize = blockSize;
- return 1;
- }
- if (p->bufferBase == 0 || p->blockSize != blockSize)
- {
- LzInWindow_Free(p, alloc);
- p->blockSize = blockSize;
- p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
- }
- return (p->bufferBase != 0);
-}
-
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
-Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
-
-UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
-
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
-{
- p->posLimit -= subValue;
- p->pos -= subValue;
- p->streamPos -= subValue;
-}
-
-static void MatchFinder_ReadBlock(CMatchFinder *p)
-{
- if (p->streamEndWasReached || p->result != SZ_OK)
- return;
- if (p->directInput)
- {
- UInt32 curSize = 0xFFFFFFFF - p->streamPos;
- if (curSize > p->directInputRem)
- curSize = (UInt32)p->directInputRem;
- p->directInputRem -= curSize;
- p->streamPos += curSize;
- if (p->directInputRem == 0)
- p->streamEndWasReached = 1;
- return;
- }
- for (;;)
- {
- Byte *dest = p->buffer + (p->streamPos - p->pos);
- size_t size = (p->bufferBase + p->blockSize - dest);
- if (size == 0)
- return;
- p->result = p->stream->Read(p->stream, dest, &size);
- if (p->result != SZ_OK)
- return;
- if (size == 0)
- {
- p->streamEndWasReached = 1;
- return;
- }
- p->streamPos += (UInt32)size;
- if (p->streamPos - p->pos > p->keepSizeAfter)
- return;
- }
-}
-
-void MatchFinder_MoveBlock(CMatchFinder *p)
-{
- memmove(p->bufferBase,
- p->buffer - p->keepSizeBefore,
- (size_t)(p->streamPos - p->pos + p->keepSizeBefore));
- p->buffer = p->bufferBase + p->keepSizeBefore;
-}
-
-int MatchFinder_NeedMove(CMatchFinder *p)
-{
- if (p->directInput)
- return 0;
- /* if (p->streamEndWasReached) return 0; */
- return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
-}
-
-void MatchFinder_ReadIfRequired(CMatchFinder *p)
-{
- if (p->streamEndWasReached)
- return;
- if (p->keepSizeAfter >= p->streamPos - p->pos)
- MatchFinder_ReadBlock(p);
-}
-
-static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
-{
- if (MatchFinder_NeedMove(p))
- MatchFinder_MoveBlock(p);
- MatchFinder_ReadBlock(p);
-}
-
-static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
-{
- p->cutValue = 32;
- p->btMode = 1;
- p->numHashBytes = 4;
- p->bigHash = 0;
-}
-
-#define kCrcPoly 0xEDB88320
-
-void MatchFinder_Construct(CMatchFinder *p)
-{
- UInt32 i;
- p->bufferBase = 0;
- p->directInput = 0;
- p->hash = 0;
- MatchFinder_SetDefaultSettings(p);
-
- for (i = 0; i < 256; i++)
- {
- UInt32 r = i;
- int j;
- for (j = 0; j < 8; j++)
- r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
- p->crc[i] = r;
- }
-}
-
-static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->hash);
- p->hash = 0;
-}
-
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
-{
- MatchFinder_FreeThisClassMemory(p, alloc);
- LzInWindow_Free(p, alloc);
-}
-
-static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
-{
- size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
- if (sizeInBytes / sizeof(CLzRef) != num)
- return 0;
- return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
-}
-
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAlloc *alloc)
-{
- UInt32 sizeReserv;
- if (historySize > kMaxHistorySize)
- {
- MatchFinder_Free(p, alloc);
- return 0;
- }
- sizeReserv = historySize >> 1;
- if (historySize > ((UInt32)2 << 30))
- sizeReserv = historySize >> 2;
- sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
-
- p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
- p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
- /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
- if (LzInWindow_Create(p, sizeReserv, alloc))
- {
- UInt32 newCyclicBufferSize = historySize + 1;
- UInt32 hs;
- p->matchMaxLen = matchMaxLen;
- {
- p->fixedHashSize = 0;
- if (p->numHashBytes == 2)
- hs = (1 << 16) - 1;
- else
- {
- hs = historySize - 1;
- hs |= (hs >> 1);
- hs |= (hs >> 2);
- hs |= (hs >> 4);
- hs |= (hs >> 8);
- hs >>= 1;
- hs |= 0xFFFF; /* don't change it! It's required for Deflate */
- if (hs > (1 << 24))
- {
- if (p->numHashBytes == 3)
- hs = (1 << 24) - 1;
- else
- hs >>= 1;
- }
- }
- p->hashMask = hs;
- hs++;
- if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
- if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
- if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
- hs += p->fixedHashSize;
- }
-
- {
- UInt32 prevSize = p->hashSizeSum + p->numSons;
- UInt32 newSize;
- p->historySize = historySize;
- p->hashSizeSum = hs;
- p->cyclicBufferSize = newCyclicBufferSize;
- p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
- newSize = p->hashSizeSum + p->numSons;
- if (p->hash != 0 && prevSize == newSize)
- return 1;
- MatchFinder_FreeThisClassMemory(p, alloc);
- p->hash = AllocRefs(newSize, alloc);
- if (p->hash != 0)
- {
- p->son = p->hash + p->hashSizeSum;
- return 1;
- }
- }
- }
- MatchFinder_Free(p, alloc);
- return 0;
-}
-
-static void MatchFinder_SetLimits(CMatchFinder *p)
-{
- UInt32 limit = kMaxValForNormalize - p->pos;
- UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
- if (limit2 < limit)
- limit = limit2;
- limit2 = p->streamPos - p->pos;
- if (limit2 <= p->keepSizeAfter)
- {
- if (limit2 > 0)
- limit2 = 1;
- }
- else
- limit2 -= p->keepSizeAfter;
- if (limit2 < limit)
- limit = limit2;
- {
- UInt32 lenLimit = p->streamPos - p->pos;
- if (lenLimit > p->matchMaxLen)
- lenLimit = p->matchMaxLen;
- p->lenLimit = lenLimit;
- }
- p->posLimit = p->pos + limit;
-}
-
-void MatchFinder_Init(CMatchFinder *p)
-{
- UInt32 i;
- for (i = 0; i < p->hashSizeSum; i++)
- p->hash[i] = kEmptyHashValue;
- p->cyclicBufferPos = 0;
- p->buffer = p->bufferBase;
- p->pos = p->streamPos = p->cyclicBufferSize;
- p->result = SZ_OK;
- p->streamEndWasReached = 0;
- MatchFinder_ReadBlock(p);
- MatchFinder_SetLimits(p);
-}
-
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
-{
- return (p->pos - p->historySize - 1) & kNormalizeMask;
-}
-
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
-{
- UInt32 i;
- for (i = 0; i < numItems; i++)
- {
- UInt32 value = items[i];
- if (value <= subValue)
- value = kEmptyHashValue;
- else
- value -= subValue;
- items[i] = value;
- }
-}
-
-static void MatchFinder_Normalize(CMatchFinder *p)
-{
- UInt32 subValue = MatchFinder_GetSubValue(p);
- MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
- MatchFinder_ReduceOffsets(p, subValue);
-}
-
-static void MatchFinder_CheckLimits(CMatchFinder *p)
-{
- if (p->pos == kMaxValForNormalize)
- MatchFinder_Normalize(p);
- if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
- MatchFinder_CheckAndMoveAndRead(p);
- if (p->cyclicBufferPos == p->cyclicBufferSize)
- p->cyclicBufferPos = 0;
- MatchFinder_SetLimits(p);
-}
-
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
-{
- son[_cyclicBufferPos] = curMatch;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- return distances;
- {
- const Byte *pb = cur - delta;
- curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
- if (pb[maxLen] == cur[maxLen] && *pb == *cur)
- {
- UInt32 len = 0;
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- *distances++ = maxLen = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- return distances;
- }
- }
- }
- }
-}
-
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
-{
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- return distances;
- }
- {
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- if (++len != lenLimit && pb[len] == cur[len])
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- *distances++ = maxLen = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return distances;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
-}
-
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
-{
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- return;
- }
- {
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- {
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- return;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
-}
-
-#define MOVE_POS \
- ++p->cyclicBufferPos; \
- p->buffer++; \
- if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
-
-#define MOVE_POS_RET MOVE_POS return offset;
-
-static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
-
-#define GET_MATCHES_HEADER2(minLen, ret_op) \
- UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
- lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
- cur = p->buffer;
-
-#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
-#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
-
-#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
-
-#define GET_MATCHES_FOOTER(offset, maxLen) \
- offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
- distances + offset, maxLen) - distances); MOVE_POS_RET;
-
-#define SKIP_FOOTER \
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
-
-static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 offset;
- GET_MATCHES_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 1)
-}
-
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 offset;
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- offset = 0;
- GET_MATCHES_FOOTER(offset, 2)
-}
-
-static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 hash2Value, delta2, maxLen, offset;
- GET_MATCHES_HEADER(3)
-
- HASH3_CALC;
-
- delta2 = p->pos - p->hash[hash2Value];
- curMatch = p->hash[kFix3HashSize + hashValue];
-
- p->hash[hash2Value] =
- p->hash[kFix3HashSize + hashValue] = p->pos;
-
-
- maxLen = 2;
- offset = 0;
- if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
- {
- for (; maxLen != lenLimit; maxLen++)
- if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
- break;
- distances[0] = maxLen;
- distances[1] = delta2 - 1;
- offset = 2;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-
-static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- delta2 = p->pos - p->hash[ hash2Value];
- delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
- curMatch = p->hash[kFix4HashSize + hashValue];
-
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] =
- p->hash[kFix4HashSize + hashValue] = p->pos;
-
- maxLen = 1;
- offset = 0;
- if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
- {
- distances[0] = maxLen = 2;
- distances[1] = delta2 - 1;
- offset = 2;
- }
- if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
- {
- maxLen = 3;
- distances[offset + 1] = delta3 - 1;
- offset += 2;
- delta2 = delta3;
- }
- if (offset != 0)
- {
- for (; maxLen != lenLimit; maxLen++)
- if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
- break;
- distances[offset - 2] = maxLen;
- if (maxLen == lenLimit)
- {
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
- }
- }
- if (maxLen < 3)
- maxLen = 3;
- GET_MATCHES_FOOTER(offset, maxLen)
-}
-
-static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
- GET_MATCHES_HEADER(4)
-
- HASH4_CALC;
-
- delta2 = p->pos - p->hash[ hash2Value];
- delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
- curMatch = p->hash[kFix4HashSize + hashValue];
-
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] =
- p->hash[kFix4HashSize + hashValue] = p->pos;
-
- maxLen = 1;
- offset = 0;
- if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
- {
- distances[0] = maxLen = 2;
- distances[1] = delta2 - 1;
- offset = 2;
- }
- if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
- {
- maxLen = 3;
- distances[offset + 1] = delta3 - 1;
- offset += 2;
- delta2 = delta3;
- }
- if (offset != 0)
- {
- for (; maxLen != lenLimit; maxLen++)
- if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
- break;
- distances[offset - 2] = maxLen;
- if (maxLen == lenLimit)
- {
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
- }
- }
- if (maxLen < 3)
- maxLen = 3;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances + offset, maxLen) - (distances));
- MOVE_POS_RET
-}
-
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
-{
- UInt32 offset;
- GET_MATCHES_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
- distances, 2) - (distances));
- MOVE_POS_RET
-}
-
-static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(2)
- HASH2_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 hash2Value;
- SKIP_HEADER(3)
- HASH3_CALC;
- curMatch = p->hash[kFix3HashSize + hashValue];
- p->hash[hash2Value] =
- p->hash[kFix3HashSize + hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 hash2Value, hash3Value;
- SKIP_HEADER(4)
- HASH4_CALC;
- curMatch = p->hash[kFix4HashSize + hashValue];
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] = p->pos;
- p->hash[kFix4HashSize + hashValue] = p->pos;
- SKIP_FOOTER
- }
- while (--num != 0);
-}
-
-static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- UInt32 hash2Value, hash3Value;
- SKIP_HEADER(4)
- HASH4_CALC;
- curMatch = p->hash[kFix4HashSize + hashValue];
- p->hash[ hash2Value] =
- p->hash[kFix3HashSize + hash3Value] =
- p->hash[kFix4HashSize + hashValue] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS
- }
- while (--num != 0);
-}
-
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
-{
- do
- {
- SKIP_HEADER(3)
- HASH_ZIP_CALC;
- curMatch = p->hash[hashValue];
- p->hash[hashValue] = p->pos;
- p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS
- }
- while (--num != 0);
-}
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
-{
- vTable->Init = (Mf_Init_Func)MatchFinder_Init;
- vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
- vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
- if (!p->btMode)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
- }
- else if (p->numHashBytes == 2)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
- }
- else if (p->numHashBytes == 3)
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
- }
- else
- {
- vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
- vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
- }
-}
diff --git a/src/libs/7zip/win/C/LzFind.h b/src/libs/7zip/win/C/LzFind.h
deleted file mode 100644
index 706143d25..000000000
--- a/src/libs/7zip/win/C/LzFind.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* LzFind.h -- Match finder for LZ algorithms
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_FIND_H
-#define __LZ_FIND_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-typedef UInt32 CLzRef;
-
-typedef struct _CMatchFinder
-{
- Byte *buffer;
- UInt32 pos;
- UInt32 posLimit;
- UInt32 streamPos;
- UInt32 lenLimit;
-
- UInt32 cyclicBufferPos;
- UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
-
- UInt32 matchMaxLen;
- CLzRef *hash;
- CLzRef *son;
- UInt32 hashMask;
- UInt32 cutValue;
-
- Byte *bufferBase;
- ISeqInStream *stream;
- int streamEndWasReached;
-
- UInt32 blockSize;
- UInt32 keepSizeBefore;
- UInt32 keepSizeAfter;
-
- UInt32 numHashBytes;
- int directInput;
- size_t directInputRem;
- int btMode;
- int bigHash;
- UInt32 historySize;
- UInt32 fixedHashSize;
- UInt32 hashSizeSum;
- UInt32 numSons;
- SRes result;
- UInt32 crc[256];
-} CMatchFinder;
-
-#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
-#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
-
-#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
-
-int MatchFinder_NeedMove(CMatchFinder *p);
-Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
-void MatchFinder_MoveBlock(CMatchFinder *p);
-void MatchFinder_ReadIfRequired(CMatchFinder *p);
-
-void MatchFinder_Construct(CMatchFinder *p);
-
-/* Conditions:
- historySize <= 3 GB
- keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
-*/
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
- UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
- ISzAlloc *alloc);
-void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
-void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
-void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
-
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *distances, UInt32 maxLen);
-
-/*
-Conditions:
- Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
- Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
-*/
-
-typedef void (*Mf_Init_Func)(void *object);
-typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
-typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
-typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
-typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
-typedef void (*Mf_Skip_Func)(void *object, UInt32);
-
-typedef struct _IMatchFinder
-{
- Mf_Init_Func Init;
- Mf_GetIndexByte_Func GetIndexByte;
- Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
- Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
- Mf_GetMatches_Func GetMatches;
- Mf_Skip_Func Skip;
-} IMatchFinder;
-
-void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
-
-void MatchFinder_Init(CMatchFinder *p);
-UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
-UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
-void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
-void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/LzFindMt.c b/src/libs/7zip/win/C/LzFindMt.c
deleted file mode 100644
index 8be0adaaf..000000000
--- a/src/libs/7zip/win/C/LzFindMt.c
+++ /dev/null
@@ -1,794 +0,0 @@
-/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
-2014-12-29 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "LzHash.h"
-
-#include "LzFindMt.h"
-
-void MtSync_Construct(CMtSync *p)
-{
- p->wasCreated = False;
- p->csWasInitialized = False;
- p->csWasEntered = False;
- Thread_Construct(&p->thread);
- Event_Construct(&p->canStart);
- Event_Construct(&p->wasStarted);
- Event_Construct(&p->wasStopped);
- Semaphore_Construct(&p->freeSemaphore);
- Semaphore_Construct(&p->filledSemaphore);
-}
-
-void MtSync_GetNextBlock(CMtSync *p)
-{
- if (p->needStart)
- {
- p->numProcessedBlocks = 1;
- p->needStart = False;
- p->stopWriting = False;
- p->exit = False;
- Event_Reset(&p->wasStarted);
- Event_Reset(&p->wasStopped);
-
- Event_Set(&p->canStart);
- Event_Wait(&p->wasStarted);
- }
- else
- {
- CriticalSection_Leave(&p->cs);
- p->csWasEntered = False;
- p->numProcessedBlocks++;
- Semaphore_Release1(&p->freeSemaphore);
- }
- Semaphore_Wait(&p->filledSemaphore);
- CriticalSection_Enter(&p->cs);
- p->csWasEntered = True;
-}
-
-/* MtSync_StopWriting must be called if Writing was started */
-
-void MtSync_StopWriting(CMtSync *p)
-{
- UInt32 myNumBlocks = p->numProcessedBlocks;
- if (!Thread_WasCreated(&p->thread) || p->needStart)
- return;
- p->stopWriting = True;
- if (p->csWasEntered)
- {
- CriticalSection_Leave(&p->cs);
- p->csWasEntered = False;
- }
- Semaphore_Release1(&p->freeSemaphore);
-
- Event_Wait(&p->wasStopped);
-
- while (myNumBlocks++ != p->numProcessedBlocks)
- {
- Semaphore_Wait(&p->filledSemaphore);
- Semaphore_Release1(&p->freeSemaphore);
- }
- p->needStart = True;
-}
-
-void MtSync_Destruct(CMtSync *p)
-{
- if (Thread_WasCreated(&p->thread))
- {
- MtSync_StopWriting(p);
- p->exit = True;
- if (p->needStart)
- Event_Set(&p->canStart);
- Thread_Wait(&p->thread);
- Thread_Close(&p->thread);
- }
- if (p->csWasInitialized)
- {
- CriticalSection_Delete(&p->cs);
- p->csWasInitialized = False;
- }
-
- Event_Close(&p->canStart);
- Event_Close(&p->wasStarted);
- Event_Close(&p->wasStopped);
- Semaphore_Close(&p->freeSemaphore);
- Semaphore_Close(&p->filledSemaphore);
-
- p->wasCreated = False;
-}
-
-#define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
-
-static SRes MtSync_Create2(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks)
-{
- if (p->wasCreated)
- return SZ_OK;
-
- RINOK_THREAD(CriticalSection_Init(&p->cs));
- p->csWasInitialized = True;
-
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
-
- RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
- RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
-
- p->needStart = True;
-
- RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
- p->wasCreated = True;
- return SZ_OK;
-}
-
-static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj, UInt32 numBlocks)
-{
- SRes res = MtSync_Create2(p, startAddress, obj, numBlocks);
- if (res != SZ_OK)
- MtSync_Destruct(p);
- return res;
-}
-
-void MtSync_Init(CMtSync *p) { p->needStart = True; }
-
-#define kMtMaxValForNormalize 0xFFFFFFFF
-
-#define DEF_GetHeads2(name, v, action) \
-static void GetHeads ## name(const Byte *p, UInt32 pos, \
-UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc) \
-{ action; for (; numHeads != 0; numHeads--) { \
-const UInt32 value = (v); p++; *heads++ = pos - hash[value]; hash[value] = pos++; } }
-
-#define DEF_GetHeads(name, v) DEF_GetHeads2(name, v, ;)
-
-DEF_GetHeads2(2, (p[0] | ((UInt32)p[1] << 8)), hashMask = hashMask; crc = crc; )
-DEF_GetHeads(3, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8)) & hashMask)
-DEF_GetHeads(4, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5)) & hashMask)
-DEF_GetHeads(4b, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ ((UInt32)p[3] << 16)) & hashMask)
-/* DEF_GetHeads(5, (crc[p[0]] ^ p[1] ^ ((UInt32)p[2] << 8) ^ (crc[p[3]] << 5) ^ (crc[p[4]] << 3)) & hashMask) */
-
-void HashThreadFunc(CMatchFinderMt *mt)
-{
- CMtSync *p = &mt->hashSync;
- for (;;)
- {
- UInt32 numProcessedBlocks = 0;
- Event_Wait(&p->canStart);
- Event_Set(&p->wasStarted);
- for (;;)
- {
- if (p->exit)
- return;
- if (p->stopWriting)
- {
- p->numProcessedBlocks = numProcessedBlocks;
- Event_Set(&p->wasStopped);
- break;
- }
-
- {
- CMatchFinder *mf = mt->MatchFinder;
- if (MatchFinder_NeedMove(mf))
- {
- CriticalSection_Enter(&mt->btSync.cs);
- CriticalSection_Enter(&mt->hashSync.cs);
- {
- const Byte *beforePtr = MatchFinder_GetPointerToCurrentPos(mf);
- const Byte *afterPtr;
- MatchFinder_MoveBlock(mf);
- afterPtr = MatchFinder_GetPointerToCurrentPos(mf);
- mt->pointerToCurPos -= beforePtr - afterPtr;
- mt->buffer -= beforePtr - afterPtr;
- }
- CriticalSection_Leave(&mt->btSync.cs);
- CriticalSection_Leave(&mt->hashSync.cs);
- continue;
- }
-
- Semaphore_Wait(&p->freeSemaphore);
-
- MatchFinder_ReadIfRequired(mf);
- if (mf->pos > (kMtMaxValForNormalize - kMtHashBlockSize))
- {
- UInt32 subValue = (mf->pos - mf->historySize - 1);
- MatchFinder_ReduceOffsets(mf, subValue);
- MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, mf->hashMask + 1);
- }
- {
- UInt32 *heads = mt->hashBuf + ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize;
- UInt32 num = mf->streamPos - mf->pos;
- heads[0] = 2;
- heads[1] = num;
- if (num >= mf->numHashBytes)
- {
- num = num - mf->numHashBytes + 1;
- if (num > kMtHashBlockSize - 2)
- num = kMtHashBlockSize - 2;
- mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);
- heads[0] += num;
- }
- mf->pos += num;
- mf->buffer += num;
- }
- }
-
- Semaphore_Release1(&p->filledSemaphore);
- }
- }
-}
-
-void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
-{
- MtSync_GetNextBlock(&p->hashSync);
- p->hashBufPosLimit = p->hashBufPos = ((p->hashSync.numProcessedBlocks - 1) & kMtHashNumBlocksMask) * kMtHashBlockSize;
- p->hashBufPosLimit += p->hashBuf[p->hashBufPos++];
- p->hashNumAvail = p->hashBuf[p->hashBufPos++];
-}
-
-#define kEmptyHashValue 0
-
-/* #define MFMT_GM_INLINE */
-
-#ifdef MFMT_GM_INLINE
-
-#define NO_INLINE MY_FAST_CALL
-
-Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
-{
- do
- {
- UInt32 *distances = _distances + 1;
- UInt32 curMatch = pos - *hash++;
-
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
- UInt32 cutValue = _cutValue;
- UInt32 maxLen = _maxLen;
- for (;;)
- {
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
- {
- *ptr0 = *ptr1 = kEmptyHashValue;
- break;
- }
- {
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
- const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
- if (pb[len] == cur[len])
- {
- if (++len != lenLimit && pb[len] == cur[len])
- while (++len != lenLimit)
- if (pb[len] != cur[len])
- break;
- if (maxLen < len)
- {
- *distances++ = maxLen = len;
- *distances++ = delta - 1;
- if (len == lenLimit)
- {
- *ptr1 = pair[0];
- *ptr0 = pair[1];
- break;
- }
- }
- }
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
- {
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
- }
- }
- }
- pos++;
- _cyclicBufferPos++;
- cur++;
- {
- UInt32 num = (UInt32)(distances - _distances);
- *_distances = num - 1;
- _distances += num;
- limit -= num;
- }
- }
- while (limit > 0 && --size != 0);
- *posRes = pos;
- return limit;
-}
-
-#endif
-
-void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
- UInt32 numProcessed = 0;
- UInt32 curPos = 2;
- UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
- distances[1] = p->hashNumAvail;
- while (curPos < limit)
- {
- if (p->hashBufPos == p->hashBufPosLimit)
- {
- MatchFinderMt_GetNextBlock_Hash(p);
- distances[1] = numProcessed + p->hashNumAvail;
- if (p->hashNumAvail >= p->numHashBytes)
- continue;
- for (; p->hashNumAvail != 0; p->hashNumAvail--)
- distances[curPos++] = 0;
- break;
- }
- {
- UInt32 size = p->hashBufPosLimit - p->hashBufPos;
- UInt32 lenLimit = p->matchMaxLen;
- UInt32 pos = p->pos;
- UInt32 cyclicBufferPos = p->cyclicBufferPos;
- if (lenLimit >= p->hashNumAvail)
- lenLimit = p->hashNumAvail;
- {
- UInt32 size2 = p->hashNumAvail - lenLimit + 1;
- if (size2 < size)
- size = size2;
- size2 = p->cyclicBufferSize - cyclicBufferPos;
- if (size2 < size)
- size = size2;
- }
- #ifndef MFMT_GM_INLINE
- while (curPos < limit && size-- != 0)
- {
- UInt32 *startDistances = distances + curPos;
- UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
- pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
- startDistances + 1, p->numHashBytes - 1) - startDistances);
- *startDistances = num - 1;
- curPos += num;
- cyclicBufferPos++;
- pos++;
- p->buffer++;
- }
- #else
- {
- UInt32 posRes;
- curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
- distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);
- p->hashBufPos += posRes - pos;
- cyclicBufferPos += posRes - pos;
- p->buffer += posRes - pos;
- pos = posRes;
- }
- #endif
-
- numProcessed += pos - p->pos;
- p->hashNumAvail -= pos - p->pos;
- p->pos = pos;
- if (cyclicBufferPos == p->cyclicBufferSize)
- cyclicBufferPos = 0;
- p->cyclicBufferPos = cyclicBufferPos;
- }
- }
- distances[0] = curPos;
-}
-
-void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
-{
- CMtSync *sync = &p->hashSync;
- if (!sync->needStart)
- {
- CriticalSection_Enter(&sync->cs);
- sync->csWasEntered = True;
- }
-
- BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);
-
- if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)
- {
- UInt32 subValue = p->pos - p->cyclicBufferSize;
- MatchFinder_Normalize3(subValue, p->son, p->cyclicBufferSize * 2);
- p->pos -= subValue;
- }
-
- if (!sync->needStart)
- {
- CriticalSection_Leave(&sync->cs);
- sync->csWasEntered = False;
- }
-}
-
-void BtThreadFunc(CMatchFinderMt *mt)
-{
- CMtSync *p = &mt->btSync;
- for (;;)
- {
- UInt32 blockIndex = 0;
- Event_Wait(&p->canStart);
- Event_Set(&p->wasStarted);
- for (;;)
- {
- if (p->exit)
- return;
- if (p->stopWriting)
- {
- p->numProcessedBlocks = blockIndex;
- MtSync_StopWriting(&mt->hashSync);
- Event_Set(&p->wasStopped);
- break;
- }
- Semaphore_Wait(&p->freeSemaphore);
- BtFillBlock(mt, blockIndex++);
- Semaphore_Release1(&p->filledSemaphore);
- }
- }
-}
-
-void MatchFinderMt_Construct(CMatchFinderMt *p)
-{
- p->hashBuf = 0;
- MtSync_Construct(&p->hashSync);
- MtSync_Construct(&p->btSync);
-}
-
-void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->hashBuf);
- p->hashBuf = 0;
-}
-
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
-{
- MtSync_Destruct(&p->hashSync);
- MtSync_Destruct(&p->btSync);
- MatchFinderMt_FreeMem(p, alloc);
-}
-
-#define kHashBufferSize (kMtHashBlockSize * kMtHashNumBlocks)
-#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
-
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p)
-{
- Byte allocaDummy[0x180];
- allocaDummy[0] = 0;
- allocaDummy[1] = allocaDummy[0];
- BtThreadFunc((CMatchFinderMt *)p);
- return 0;
-}
-
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
-{
- CMatchFinder *mf = p->MatchFinder;
- p->historySize = historySize;
- if (kMtBtBlockSize <= matchMaxLen * 4)
- return SZ_ERROR_PARAM;
- if (p->hashBuf == 0)
- {
- p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));
- if (p->hashBuf == 0)
- return SZ_ERROR_MEM;
- p->btBuf = p->hashBuf + kHashBufferSize;
- }
- keepAddBufferBefore += (kHashBufferSize + kBtBufferSize);
- keepAddBufferAfter += kMtHashBlockSize;
- if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
- return SZ_ERROR_MEM;
-
- RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p, kMtHashNumBlocks));
- RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p, kMtBtNumBlocks));
- return SZ_OK;
-}
-
-/* Call it after ReleaseStream / SetStream */
-void MatchFinderMt_Init(CMatchFinderMt *p)
-{
- CMatchFinder *mf = p->MatchFinder;
- p->btBufPos = p->btBufPosLimit = 0;
- p->hashBufPos = p->hashBufPosLimit = 0;
- MatchFinder_Init(mf);
- p->pointerToCurPos = MatchFinder_GetPointerToCurrentPos(mf);
- p->btNumAvailBytes = 0;
- p->lzPos = p->historySize + 1;
-
- p->hash = mf->hash;
- p->fixedHashSize = mf->fixedHashSize;
- p->crc = mf->crc;
-
- p->son = mf->son;
- p->matchMaxLen = mf->matchMaxLen;
- p->numHashBytes = mf->numHashBytes;
- p->pos = mf->pos;
- p->buffer = mf->buffer;
- p->cyclicBufferPos = mf->cyclicBufferPos;
- p->cyclicBufferSize = mf->cyclicBufferSize;
- p->cutValue = mf->cutValue;
-}
-
-/* ReleaseStream is required to finish multithreading */
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
-{
- MtSync_StopWriting(&p->btSync);
- /* p->MatchFinder->ReleaseStream(); */
-}
-
-void MatchFinderMt_Normalize(CMatchFinderMt *p)
-{
- MatchFinder_Normalize3(p->lzPos - p->historySize - 1, p->hash, p->fixedHashSize);
- p->lzPos = p->historySize + 1;
-}
-
-void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
-{
- UInt32 blockIndex;
- MtSync_GetNextBlock(&p->btSync);
- blockIndex = ((p->btSync.numProcessedBlocks - 1) & kMtBtNumBlocksMask);
- p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;
- p->btBufPosLimit += p->btBuf[p->btBufPos++];
- p->btNumAvailBytes = p->btBuf[p->btBufPos++];
- if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
- MatchFinderMt_Normalize(p);
-}
-
-const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
-{
- return p->pointerToCurPos;
-}
-
-#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
-
-UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
-{
- GET_NEXT_BLOCK_IF_REQUIRED;
- return p->btNumAvailBytes;
-}
-
-Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)
-{
- return p->pointerToCurPos[index];
-}
-
-UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
-{
- UInt32 hash2Value, curMatch2;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
- MT_HASH2_CALC
-
- curMatch2 = hash[hash2Value];
- hash[hash2Value] = lzPos;
-
- if (curMatch2 >= matchMinPos)
- if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
- *distances++ = 2;
- *distances++ = lzPos - curMatch2 - 1;
- }
- return distances;
-}
-
-UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, curMatch2, curMatch3;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
- MT_HASH3_CALC
-
- curMatch2 = hash[ hash2Value];
- curMatch3 = hash[kFix3HashSize + hash3Value];
-
- hash[ hash2Value] =
- hash[kFix3HashSize + hash3Value] =
- lzPos;
-
- if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
- distances[1] = lzPos - curMatch2 - 1;
- if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
- {
- distances[0] = 3;
- return distances + 2;
- }
- distances[0] = 2;
- distances += 2;
- }
- if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
- {
- *distances++ = 3;
- *distances++ = lzPos - curMatch3 - 1;
- }
- return distances;
-}
-
-/*
-UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
-{
- UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;
- UInt32 *hash = p->hash;
- const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
- MT_HASH4_CALC
-
- curMatch2 = hash[ hash2Value];
- curMatch3 = hash[kFix3HashSize + hash3Value];
- curMatch4 = hash[kFix4HashSize + hash4Value];
-
- hash[ hash2Value] =
- hash[kFix3HashSize + hash3Value] =
- hash[kFix4HashSize + hash4Value] =
- lzPos;
-
- if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
- distances[1] = lzPos - curMatch2 - 1;
- if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
- {
- distances[0] = (cur[(ptrdiff_t)curMatch2 - lzPos + 3] == cur[3]) ? 4 : 3;
- return distances + 2;
- }
- distances[0] = 2;
- distances += 2;
- }
- if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
- {
- distances[1] = lzPos - curMatch3 - 1;
- if (cur[(ptrdiff_t)curMatch3 - lzPos + 3] == cur[3])
- {
- distances[0] = 4;
- return distances + 2;
- }
- distances[0] = 3;
- distances += 2;
- }
-
- if (curMatch4 >= matchMinPos)
- if (
- cur[(ptrdiff_t)curMatch4 - lzPos] == cur[0] &&
- cur[(ptrdiff_t)curMatch4 - lzPos + 3] == cur[3]
- )
- {
- *distances++ = 4;
- *distances++ = lzPos - curMatch4 - 1;
- }
- return distances;
-}
-*/
-
-#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
-
-UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
- const UInt32 *btBuf = p->btBuf + p->btBufPos;
- UInt32 len = *btBuf++;
- p->btBufPos += 1 + len;
- p->btNumAvailBytes--;
- {
- UInt32 i;
- for (i = 0; i < len; i += 2)
- {
- *distances++ = *btBuf++;
- *distances++ = *btBuf++;
- }
- }
- INCREASE_LZ_POS
- return len;
-}
-
-UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
- const UInt32 *btBuf = p->btBuf + p->btBufPos;
- UInt32 len = *btBuf++;
- p->btBufPos += 1 + len;
-
- if (len == 0)
- {
- if (p->btNumAvailBytes-- >= 4)
- len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));
- }
- else
- {
- /* Condition: there are matches in btBuf with length < p->numHashBytes */
- UInt32 *distances2;
- p->btNumAvailBytes--;
- distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);
- do
- {
- *distances2++ = *btBuf++;
- *distances2++ = *btBuf++;
- }
- while ((len -= 2) != 0);
- len = (UInt32)(distances2 - (distances));
- }
- INCREASE_LZ_POS
- return len;
-}
-
-#define SKIP_HEADER2_MT do { GET_NEXT_BLOCK_IF_REQUIRED
-#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
-#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while (--num != 0);
-
-void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER2_MT { p->btNumAvailBytes--;
- SKIP_FOOTER_MT
-}
-
-void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER_MT(2)
- UInt32 hash2Value;
- MT_HASH2_CALC
- hash[hash2Value] = p->lzPos;
- SKIP_FOOTER_MT
-}
-
-void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER_MT(3)
- UInt32 hash2Value, hash3Value;
- MT_HASH3_CALC
- hash[kFix3HashSize + hash3Value] =
- hash[ hash2Value] =
- p->lzPos;
- SKIP_FOOTER_MT
-}
-
-/*
-void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
-{
- SKIP_HEADER_MT(4)
- UInt32 hash2Value, hash3Value, hash4Value;
- MT_HASH4_CALC
- hash[kFix4HashSize + hash4Value] =
- hash[kFix3HashSize + hash3Value] =
- hash[ hash2Value] =
- p->lzPos;
- SKIP_FOOTER_MT
-}
-*/
-
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
-{
- vTable->Init = (Mf_Init_Func)MatchFinderMt_Init;
- vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinderMt_GetIndexByte;
- vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes;
- vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos;
- vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches;
- switch(p->MatchFinder->numHashBytes)
- {
- case 2:
- p->GetHeadsFunc = GetHeads2;
- p->MixMatchesFunc = (Mf_Mix_Matches)0;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;
- vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;
- break;
- case 3:
- p->GetHeadsFunc = GetHeads3;
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip;
- break;
- default:
- /* case 4: */
- p->GetHeadsFunc = p->MatchFinder->bigHash ? GetHeads4b : GetHeads4;
- /* p->GetHeadsFunc = GetHeads4; */
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip;
- break;
- /*
- default:
- p->GetHeadsFunc = GetHeads5;
- p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4;
- vTable->Skip = (Mf_Skip_Func)MatchFinderMt4_Skip;
- break;
- */
- }
-}
diff --git a/src/libs/7zip/win/C/LzFindMt.h b/src/libs/7zip/win/C/LzFindMt.h
deleted file mode 100644
index 65cc12783..000000000
--- a/src/libs/7zip/win/C/LzFindMt.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_FIND_MT_H
-#define __LZ_FIND_MT_H
-
-#include "LzFind.h"
-#include "Threads.h"
-
-EXTERN_C_BEGIN
-
-#define kMtHashBlockSize (1 << 13)
-#define kMtHashNumBlocks (1 << 3)
-#define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
-
-#define kMtBtBlockSize (1 << 14)
-#define kMtBtNumBlocks (1 << 6)
-#define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
-
-typedef struct _CMtSync
-{
- Bool wasCreated;
- Bool needStart;
- Bool exit;
- Bool stopWriting;
-
- CThread thread;
- CAutoResetEvent canStart;
- CAutoResetEvent wasStarted;
- CAutoResetEvent wasStopped;
- CSemaphore freeSemaphore;
- CSemaphore filledSemaphore;
- Bool csWasInitialized;
- Bool csWasEntered;
- CCriticalSection cs;
- UInt32 numProcessedBlocks;
-} CMtSync;
-
-typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
-
-/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
-#define kMtCacheLineDummy 128
-
-typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
- UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
-
-typedef struct _CMatchFinderMt
-{
- /* LZ */
- const Byte *pointerToCurPos;
- UInt32 *btBuf;
- UInt32 btBufPos;
- UInt32 btBufPosLimit;
- UInt32 lzPos;
- UInt32 btNumAvailBytes;
-
- UInt32 *hash;
- UInt32 fixedHashSize;
- UInt32 historySize;
- const UInt32 *crc;
-
- Mf_Mix_Matches MixMatchesFunc;
-
- /* LZ + BT */
- CMtSync btSync;
- Byte btDummy[kMtCacheLineDummy];
-
- /* BT */
- UInt32 *hashBuf;
- UInt32 hashBufPos;
- UInt32 hashBufPosLimit;
- UInt32 hashNumAvail;
-
- CLzRef *son;
- UInt32 matchMaxLen;
- UInt32 numHashBytes;
- UInt32 pos;
- Byte *buffer;
- UInt32 cyclicBufferPos;
- UInt32 cyclicBufferSize; /* it must be historySize + 1 */
- UInt32 cutValue;
-
- /* BT + Hash */
- CMtSync hashSync;
- /* Byte hashDummy[kMtCacheLineDummy]; */
-
- /* Hash */
- Mf_GetHeads GetHeadsFunc;
- CMatchFinder *MatchFinder;
-} CMatchFinderMt;
-
-void MatchFinderMt_Construct(CMatchFinderMt *p);
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
-void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
-void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/LzHash.h b/src/libs/7zip/win/C/LzHash.h
deleted file mode 100644
index f3e89966c..000000000
--- a/src/libs/7zip/win/C/LzHash.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* LzHash.h -- HASH functions for LZ algorithms
-2009-02-07 : Igor Pavlov : Public domain */
-
-#ifndef __LZ_HASH_H
-#define __LZ_HASH_H
-
-#define kHash2Size (1 << 10)
-#define kHash3Size (1 << 16)
-#define kHash4Size (1 << 20)
-
-#define kFix3HashSize (kHash2Size)
-#define kFix4HashSize (kHash2Size + kHash3Size)
-#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
-
-#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
-
-#define HASH3_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
-
-#define HASH4_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
-
-#define HASH5_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
- hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
- hash4Value &= (kHash4Size - 1); }
-
-/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
-#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
-
-
-#define MT_HASH2_CALC \
- hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
-
-#define MT_HASH3_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
-
-#define MT_HASH4_CALC { \
- UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
- hash2Value = temp & (kHash2Size - 1); \
- hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
- hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
-
-#endif
diff --git a/src/libs/7zip/win/C/Lzma2Dec.c b/src/libs/7zip/win/C/Lzma2Dec.c
deleted file mode 100644
index e7dcc2725..000000000
--- a/src/libs/7zip/win/C/Lzma2Dec.c
+++ /dev/null
@@ -1,352 +0,0 @@
-/* Lzma2Dec.c -- LZMA2 Decoder
-2010-12-15 : Igor Pavlov : Public domain */
-
-/* #define SHOW_DEBUG_INFO */
-
-#include "Precomp.h"
-
-#ifdef SHOW_DEBUG_INFO
-#include <stdio.h>
-#endif
-
-#include <string.h>
-
-#include "Lzma2Dec.h"
-
-/*
-00000000 - EOS
-00000001 U U - Uncompressed Reset Dic
-00000010 U U - Uncompressed No Reset
-100uuuuu U U P P - LZMA no reset
-101uuuuu U U P P - LZMA reset state
-110uuuuu U U P P S - LZMA reset state + new prop
-111uuuuu U U P P S - LZMA reset state + new prop + reset dic
-
- u, U - Unpack Size
- P - Pack Size
- S - Props
-*/
-
-#define LZMA2_CONTROL_LZMA (1 << 7)
-#define LZMA2_CONTROL_COPY_NO_RESET 2
-#define LZMA2_CONTROL_COPY_RESET_DIC 1
-#define LZMA2_CONTROL_EOF 0
-
-#define LZMA2_IS_UNCOMPRESSED_STATE(p) (((p)->control & LZMA2_CONTROL_LZMA) == 0)
-
-#define LZMA2_GET_LZMA_MODE(p) (((p)->control >> 5) & 3)
-#define LZMA2_IS_THERE_PROP(mode) ((mode) >= 2)
-
-#define LZMA2_LCLP_MAX 4
-#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))
-
-#ifdef SHOW_DEBUG_INFO
-#define PRF(x) x
-#else
-#define PRF(x)
-#endif
-
-typedef enum
-{
- LZMA2_STATE_CONTROL,
- LZMA2_STATE_UNPACK0,
- LZMA2_STATE_UNPACK1,
- LZMA2_STATE_PACK0,
- LZMA2_STATE_PACK1,
- LZMA2_STATE_PROP,
- LZMA2_STATE_DATA,
- LZMA2_STATE_DATA_CONT,
- LZMA2_STATE_FINISHED,
- LZMA2_STATE_ERROR
-} ELzma2State;
-
-static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
-{
- UInt32 dicSize;
- if (prop > 40)
- return SZ_ERROR_UNSUPPORTED;
- dicSize = (prop == 40) ? 0xFFFFFFFF : LZMA2_DIC_SIZE_FROM_PROP(prop);
- props[0] = (Byte)LZMA2_LCLP_MAX;
- props[1] = (Byte)(dicSize);
- props[2] = (Byte)(dicSize >> 8);
- props[3] = (Byte)(dicSize >> 16);
- props[4] = (Byte)(dicSize >> 24);
- return SZ_OK;
-}
-
-SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
-{
- Byte props[LZMA_PROPS_SIZE];
- RINOK(Lzma2Dec_GetOldProps(prop, props));
- return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
-}
-
-SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc)
-{
- Byte props[LZMA_PROPS_SIZE];
- RINOK(Lzma2Dec_GetOldProps(prop, props));
- return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
-}
-
-void Lzma2Dec_Init(CLzma2Dec *p)
-{
- p->state = LZMA2_STATE_CONTROL;
- p->needInitDic = True;
- p->needInitState = True;
- p->needInitProp = True;
- LzmaDec_Init(&p->decoder);
-}
-
-static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
-{
- switch(p->state)
- {
- case LZMA2_STATE_CONTROL:
- p->control = b;
- PRF(printf("\n %4X ", p->decoder.dicPos));
- PRF(printf(" %2X", b));
- if (p->control == 0)
- return LZMA2_STATE_FINISHED;
- if (LZMA2_IS_UNCOMPRESSED_STATE(p))
- {
- if ((p->control & 0x7F) > 2)
- return LZMA2_STATE_ERROR;
- p->unpackSize = 0;
- }
- else
- p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
- return LZMA2_STATE_UNPACK0;
-
- case LZMA2_STATE_UNPACK0:
- p->unpackSize |= (UInt32)b << 8;
- return LZMA2_STATE_UNPACK1;
-
- case LZMA2_STATE_UNPACK1:
- p->unpackSize |= (UInt32)b;
- p->unpackSize++;
- PRF(printf(" %8d", p->unpackSize));
- return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
-
- case LZMA2_STATE_PACK0:
- p->packSize = (UInt32)b << 8;
- return LZMA2_STATE_PACK1;
-
- case LZMA2_STATE_PACK1:
- p->packSize |= (UInt32)b;
- p->packSize++;
- PRF(printf(" %8d", p->packSize));
- return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP:
- (p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
-
- case LZMA2_STATE_PROP:
- {
- int lc, lp;
- if (b >= (9 * 5 * 5))
- return LZMA2_STATE_ERROR;
- lc = b % 9;
- b /= 9;
- p->decoder.prop.pb = b / 5;
- lp = b % 5;
- if (lc + lp > LZMA2_LCLP_MAX)
- return LZMA2_STATE_ERROR;
- p->decoder.prop.lc = lc;
- p->decoder.prop.lp = lp;
- p->needInitProp = False;
- return LZMA2_STATE_DATA;
- }
- }
- return LZMA2_STATE_ERROR;
-}
-
-static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size)
-{
- memcpy(p->dic + p->dicPos, src, size);
- p->dicPos += size;
- if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= size)
- p->checkDicSize = p->prop.dicSize;
- p->processedPos += (UInt32)size;
-}
-
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);
-
-SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT inSize = *srcLen;
- *srcLen = 0;
- *status = LZMA_STATUS_NOT_SPECIFIED;
-
- while (p->state != LZMA2_STATE_FINISHED)
- {
- SizeT dicPos = p->decoder.dicPos;
- if (p->state == LZMA2_STATE_ERROR)
- return SZ_ERROR_DATA;
- if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_OK;
- }
- if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
- {
- if (*srcLen == inSize)
- {
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- (*srcLen)++;
- p->state = Lzma2Dec_UpdateState(p, *src++);
- continue;
- }
- {
- SizeT destSizeCur = dicLimit - dicPos;
- SizeT srcSizeCur = inSize - *srcLen;
- ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
-
- if (p->unpackSize <= destSizeCur)
- {
- destSizeCur = (SizeT)p->unpackSize;
- curFinishMode = LZMA_FINISH_END;
- }
-
- if (LZMA2_IS_UNCOMPRESSED_STATE(p))
- {
- if (*srcLen == inSize)
- {
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
-
- if (p->state == LZMA2_STATE_DATA)
- {
- Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
- if (initDic)
- p->needInitProp = p->needInitState = True;
- else if (p->needInitDic)
- return SZ_ERROR_DATA;
- p->needInitDic = False;
- LzmaDec_InitDicAndState(&p->decoder, initDic, False);
- }
-
- if (srcSizeCur > destSizeCur)
- srcSizeCur = destSizeCur;
-
- if (srcSizeCur == 0)
- return SZ_ERROR_DATA;
-
- LzmaDec_UpdateWithUncompressed(&p->decoder, src, srcSizeCur);
-
- src += srcSizeCur;
- *srcLen += srcSizeCur;
- p->unpackSize -= (UInt32)srcSizeCur;
- p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
- }
- else
- {
- SizeT outSizeProcessed;
- SRes res;
-
- if (p->state == LZMA2_STATE_DATA)
- {
- int mode = LZMA2_GET_LZMA_MODE(p);
- Bool initDic = (mode == 3);
- Bool initState = (mode > 0);
- if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
- return SZ_ERROR_DATA;
-
- LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
- p->needInitDic = False;
- p->needInitState = False;
- p->state = LZMA2_STATE_DATA_CONT;
- }
- if (srcSizeCur > p->packSize)
- srcSizeCur = (SizeT)p->packSize;
-
- res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
-
- src += srcSizeCur;
- *srcLen += srcSizeCur;
- p->packSize -= (UInt32)srcSizeCur;
-
- outSizeProcessed = p->decoder.dicPos - dicPos;
- p->unpackSize -= (UInt32)outSizeProcessed;
-
- RINOK(res);
- if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
- return res;
-
- if (srcSizeCur == 0 && outSizeProcessed == 0)
- {
- if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK ||
- p->unpackSize != 0 || p->packSize != 0)
- return SZ_ERROR_DATA;
- p->state = LZMA2_STATE_CONTROL;
- }
- if (*status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
- *status = LZMA_STATUS_NOT_FINISHED;
- }
- }
- }
- *status = LZMA_STATUS_FINISHED_WITH_MARK;
- return SZ_OK;
-}
-
-SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT outSize = *destLen, inSize = *srcLen;
- *srcLen = *destLen = 0;
- for (;;)
- {
- SizeT srcSizeCur = inSize, outSizeCur, dicPos;
- ELzmaFinishMode curFinishMode;
- SRes res;
- if (p->decoder.dicPos == p->decoder.dicBufSize)
- p->decoder.dicPos = 0;
- dicPos = p->decoder.dicPos;
- if (outSize > p->decoder.dicBufSize - dicPos)
- {
- outSizeCur = p->decoder.dicBufSize;
- curFinishMode = LZMA_FINISH_ANY;
- }
- else
- {
- outSizeCur = dicPos + outSize;
- curFinishMode = finishMode;
- }
-
- res = Lzma2Dec_DecodeToDic(p, outSizeCur, src, &srcSizeCur, curFinishMode, status);
- src += srcSizeCur;
- inSize -= srcSizeCur;
- *srcLen += srcSizeCur;
- outSizeCur = p->decoder.dicPos - dicPos;
- memcpy(dest, p->decoder.dic + dicPos, outSizeCur);
- dest += outSizeCur;
- outSize -= outSizeCur;
- *destLen += outSizeCur;
- if (res != 0)
- return res;
- if (outSizeCur == 0 || outSize == 0)
- return SZ_OK;
- }
-}
-
-SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
-{
- CLzma2Dec p;
- SRes res;
- SizeT outSize = *destLen, inSize = *srcLen;
- *destLen = *srcLen = 0;
- *status = LZMA_STATUS_NOT_SPECIFIED;
- Lzma2Dec_Construct(&p);
- RINOK(Lzma2Dec_AllocateProbs(&p, prop, alloc));
- p.decoder.dic = dest;
- p.decoder.dicBufSize = outSize;
- Lzma2Dec_Init(&p);
- *srcLen = inSize;
- res = Lzma2Dec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
- *destLen = p.decoder.dicPos;
- if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
- res = SZ_ERROR_INPUT_EOF;
- Lzma2Dec_FreeProbs(&p, alloc);
- return res;
-}
diff --git a/src/libs/7zip/win/C/Lzma2Dec.h b/src/libs/7zip/win/C/Lzma2Dec.h
deleted file mode 100644
index 367daf6b3..000000000
--- a/src/libs/7zip/win/C/Lzma2Dec.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Lzma2Dec.h -- LZMA2 Decoder
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA2_DEC_H
-#define __LZMA2_DEC_H
-
-#include "LzmaDec.h"
-
-EXTERN_C_BEGIN
-
-/* ---------- State Interface ---------- */
-
-typedef struct
-{
- CLzmaDec decoder;
- UInt32 packSize;
- UInt32 unpackSize;
- int state;
- Byte control;
- Bool needInitDic;
- Bool needInitState;
- Bool needInitProp;
-} CLzma2Dec;
-
-#define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder)
-#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc);
-#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc);
-
-SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);
-SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);
-void Lzma2Dec_Init(CLzma2Dec *p);
-
-
-/*
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen or dicLimit).
- LZMA_FINISH_ANY - use smallest number of input bytes
- LZMA_FINISH_END - read EndOfStream marker after decoding
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_NEEDS_MORE_INPUT
- SZ_ERROR_DATA - Data error
-*/
-
-SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- One Call Interface ---------- */
-
-/*
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - use smallest number of input bytes
- LZMA_FINISH_END - read EndOfStream marker after decoding
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
-*/
-
-SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Lzma2Enc.c b/src/libs/7zip/win/C/Lzma2Enc.c
deleted file mode 100644
index 5d67cc344..000000000
--- a/src/libs/7zip/win/C/Lzma2Enc.c
+++ /dev/null
@@ -1,493 +0,0 @@
-/* Lzma2Enc.c -- LZMA2 Encoder
-2012-06-19 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-/* #include <stdio.h> */
-#include <string.h>
-
-/* #define _7ZIP_ST */
-
-#include "Lzma2Enc.h"
-
-#ifndef _7ZIP_ST
-#include "MtCoder.h"
-#else
-#define NUM_MT_CODER_THREADS_MAX 1
-#endif
-
-#define LZMA2_CONTROL_LZMA (1 << 7)
-#define LZMA2_CONTROL_COPY_NO_RESET 2
-#define LZMA2_CONTROL_COPY_RESET_DIC 1
-#define LZMA2_CONTROL_EOF 0
-
-#define LZMA2_LCLP_MAX 4
-
-#define LZMA2_DIC_SIZE_FROM_PROP(p) (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11))
-
-#define LZMA2_PACK_SIZE_MAX (1 << 16)
-#define LZMA2_COPY_CHUNK_SIZE LZMA2_PACK_SIZE_MAX
-#define LZMA2_UNPACK_SIZE_MAX (1 << 21)
-#define LZMA2_KEEP_WINDOW_SIZE LZMA2_UNPACK_SIZE_MAX
-
-#define LZMA2_CHUNK_SIZE_COMPRESSED_MAX ((1 << 16) + 16)
-
-
-#define PRF(x) /* x */
-
-/* ---------- CLzma2EncInt ---------- */
-
-typedef struct
-{
- CLzmaEncHandle enc;
- UInt64 srcPos;
- Byte props;
- Bool needInitState;
- Bool needInitProp;
-} CLzma2EncInt;
-
-static SRes Lzma2EncInt_Init(CLzma2EncInt *p, const CLzma2EncProps *props)
-{
- Byte propsEncoded[LZMA_PROPS_SIZE];
- SizeT propsSize = LZMA_PROPS_SIZE;
- RINOK(LzmaEnc_SetProps(p->enc, &props->lzmaProps));
- RINOK(LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize));
- p->srcPos = 0;
- p->props = propsEncoded[0];
- p->needInitState = True;
- p->needInitProp = True;
- return SZ_OK;
-}
-
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize,
- ISzAlloc *alloc, ISzAlloc *allocBig);
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
- UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig);
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
- Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
-void LzmaEnc_Finish(CLzmaEncHandle pp);
-void LzmaEnc_SaveState(CLzmaEncHandle pp);
-void LzmaEnc_RestoreState(CLzmaEncHandle pp);
-
-
-static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
- size_t *packSizeRes, ISeqOutStream *outStream)
-{
- size_t packSizeLimit = *packSizeRes;
- size_t packSize = packSizeLimit;
- UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX;
- unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0);
- Bool useCopyBlock;
- SRes res;
-
- *packSizeRes = 0;
- if (packSize < lzHeaderSize)
- return SZ_ERROR_OUTPUT_EOF;
- packSize -= lzHeaderSize;
-
- LzmaEnc_SaveState(p->enc);
- res = LzmaEnc_CodeOneMemBlock(p->enc, p->needInitState,
- outBuf + lzHeaderSize, &packSize, LZMA2_PACK_SIZE_MAX, &unpackSize);
-
- PRF(printf("\npackSize = %7d unpackSize = %7d ", packSize, unpackSize));
-
- if (unpackSize == 0)
- return res;
-
- if (res == SZ_OK)
- useCopyBlock = (packSize + 2 >= unpackSize || packSize > (1 << 16));
- else
- {
- if (res != SZ_ERROR_OUTPUT_EOF)
- return res;
- res = SZ_OK;
- useCopyBlock = True;
- }
-
- if (useCopyBlock)
- {
- size_t destPos = 0;
- PRF(printf("################# COPY "));
- while (unpackSize > 0)
- {
- UInt32 u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;
- if (packSizeLimit - destPos < u + 3)
- return SZ_ERROR_OUTPUT_EOF;
- outBuf[destPos++] = (Byte)(p->srcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET);
- outBuf[destPos++] = (Byte)((u - 1) >> 8);
- outBuf[destPos++] = (Byte)(u - 1);
- memcpy(outBuf + destPos, LzmaEnc_GetCurBuf(p->enc) - unpackSize, u);
- unpackSize -= u;
- destPos += u;
- p->srcPos += u;
- if (outStream)
- {
- *packSizeRes += destPos;
- if (outStream->Write(outStream, outBuf, destPos) != destPos)
- return SZ_ERROR_WRITE;
- destPos = 0;
- }
- else
- *packSizeRes = destPos;
- /* needInitState = True; */
- }
- LzmaEnc_RestoreState(p->enc);
- return SZ_OK;
- }
- {
- size_t destPos = 0;
- UInt32 u = unpackSize - 1;
- UInt32 pm = (UInt32)(packSize - 1);
- unsigned mode = (p->srcPos == 0) ? 3 : (p->needInitState ? (p->needInitProp ? 2 : 1) : 0);
-
- PRF(printf(" "));
-
- outBuf[destPos++] = (Byte)(LZMA2_CONTROL_LZMA | (mode << 5) | ((u >> 16) & 0x1F));
- outBuf[destPos++] = (Byte)(u >> 8);
- outBuf[destPos++] = (Byte)u;
- outBuf[destPos++] = (Byte)(pm >> 8);
- outBuf[destPos++] = (Byte)pm;
-
- if (p->needInitProp)
- outBuf[destPos++] = p->props;
-
- p->needInitProp = False;
- p->needInitState = False;
- destPos += packSize;
- p->srcPos += unpackSize;
-
- if (outStream)
- if (outStream->Write(outStream, outBuf, destPos) != destPos)
- return SZ_ERROR_WRITE;
- *packSizeRes = destPos;
- return SZ_OK;
- }
-}
-
-/* ---------- Lzma2 Props ---------- */
-
-void Lzma2EncProps_Init(CLzma2EncProps *p)
-{
- LzmaEncProps_Init(&p->lzmaProps);
- p->numTotalThreads = -1;
- p->numBlockThreads = -1;
- p->blockSize = 0;
-}
-
-void Lzma2EncProps_Normalize(CLzma2EncProps *p)
-{
- int t1, t1n, t2, t3;
- {
- CLzmaEncProps lzmaProps = p->lzmaProps;
- LzmaEncProps_Normalize(&lzmaProps);
- t1n = lzmaProps.numThreads;
- }
-
- t1 = p->lzmaProps.numThreads;
- t2 = p->numBlockThreads;
- t3 = p->numTotalThreads;
-
- if (t2 > NUM_MT_CODER_THREADS_MAX)
- t2 = NUM_MT_CODER_THREADS_MAX;
-
- if (t3 <= 0)
- {
- if (t2 <= 0)
- t2 = 1;
- t3 = t1n * t2;
- }
- else if (t2 <= 0)
- {
- t2 = t3 / t1n;
- if (t2 == 0)
- {
- t1 = 1;
- t2 = t3;
- }
- if (t2 > NUM_MT_CODER_THREADS_MAX)
- t2 = NUM_MT_CODER_THREADS_MAX;
- }
- else if (t1 <= 0)
- {
- t1 = t3 / t2;
- if (t1 == 0)
- t1 = 1;
- }
- else
- t3 = t1n * t2;
-
- p->lzmaProps.numThreads = t1;
-
- LzmaEncProps_Normalize(&p->lzmaProps);
-
- if (p->blockSize == 0)
- {
- UInt32 dictSize = p->lzmaProps.dictSize;
- UInt64 blockSize = (UInt64)dictSize << 2;
- const UInt32 kMinSize = (UInt32)1 << 20;
- const UInt32 kMaxSize = (UInt32)1 << 28;
- if (blockSize < kMinSize) blockSize = kMinSize;
- if (blockSize > kMaxSize) blockSize = kMaxSize;
- if (blockSize < dictSize) blockSize = dictSize;
- p->blockSize = (size_t)blockSize;
- }
- if (t2 > 1)
- {
- UInt64 temp = p->lzmaProps.reduceSize + p->blockSize - 1;
- if (temp > p->lzmaProps.reduceSize)
- {
- UInt64 numBlocks = temp / p->blockSize;
- if (numBlocks < t2)
- {
- t2 = (UInt32)numBlocks;
- t3 = t1 * t2;
- }
- }
- }
- p->numBlockThreads = t2;
- p->numTotalThreads = t3;
-}
-
-static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
-{
- return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
-}
-
-/* ---------- Lzma2 ---------- */
-
-typedef struct
-{
- Byte propEncoded;
- CLzma2EncProps props;
-
- Byte *outBuf;
-
- ISzAlloc *alloc;
- ISzAlloc *allocBig;
-
- CLzma2EncInt coders[NUM_MT_CODER_THREADS_MAX];
-
- #ifndef _7ZIP_ST
- CMtCoder mtCoder;
- #endif
-
-} CLzma2Enc;
-
-
-/* ---------- Lzma2EncThread ---------- */
-
-static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
- ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)
-{
- UInt64 packTotal = 0;
- SRes res = SZ_OK;
-
- if (mainEncoder->outBuf == 0)
- {
- mainEncoder->outBuf = (Byte *)IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
- if (mainEncoder->outBuf == 0)
- return SZ_ERROR_MEM;
- }
- RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));
- RINOK(LzmaEnc_PrepareForLzma2(p->enc, inStream, LZMA2_KEEP_WINDOW_SIZE,
- mainEncoder->alloc, mainEncoder->allocBig));
- for (;;)
- {
- size_t packSize = LZMA2_CHUNK_SIZE_COMPRESSED_MAX;
- res = Lzma2EncInt_EncodeSubblock(p, mainEncoder->outBuf, &packSize, outStream);
- if (res != SZ_OK)
- break;
- packTotal += packSize;
- res = Progress(progress, p->srcPos, packTotal);
- if (res != SZ_OK)
- break;
- if (packSize == 0)
- break;
- }
- LzmaEnc_Finish(p->enc);
- if (res == SZ_OK)
- {
- Byte b = 0;
- if (outStream->Write(outStream, &b, 1) != 1)
- return SZ_ERROR_WRITE;
- }
- return res;
-}
-
-#ifndef _7ZIP_ST
-
-typedef struct
-{
- IMtCoderCallback funcTable;
- CLzma2Enc *lzma2Enc;
-} CMtCallbackImp;
-
-static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *destSize,
- const Byte *src, size_t srcSize, int finished)
-{
- CMtCallbackImp *imp = (CMtCallbackImp *)pp;
- CLzma2Enc *mainEncoder = imp->lzma2Enc;
- CLzma2EncInt *p = &mainEncoder->coders[index];
-
- SRes res = SZ_OK;
- {
- size_t destLim = *destSize;
- *destSize = 0;
-
- if (srcSize != 0)
- {
- RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));
-
- RINOK(LzmaEnc_MemPrepare(p->enc, src, srcSize, LZMA2_KEEP_WINDOW_SIZE,
- mainEncoder->alloc, mainEncoder->allocBig));
-
- while (p->srcPos < srcSize)
- {
- size_t packSize = destLim - *destSize;
- res = Lzma2EncInt_EncodeSubblock(p, dest + *destSize, &packSize, NULL);
- if (res != SZ_OK)
- break;
- *destSize += packSize;
-
- if (packSize == 0)
- {
- res = SZ_ERROR_FAIL;
- break;
- }
-
- if (MtProgress_Set(&mainEncoder->mtCoder.mtProgress, index, p->srcPos, *destSize) != SZ_OK)
- {
- res = SZ_ERROR_PROGRESS;
- break;
- }
- }
- LzmaEnc_Finish(p->enc);
- if (res != SZ_OK)
- return res;
- }
- if (finished)
- {
- if (*destSize == destLim)
- return SZ_ERROR_OUTPUT_EOF;
- dest[(*destSize)++] = 0;
- }
- }
- return res;
-}
-
-#endif
-
-/* ---------- Lzma2Enc ---------- */
-
-CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzma2Enc *p = (CLzma2Enc *)alloc->Alloc(alloc, sizeof(CLzma2Enc));
- if (p == 0)
- return NULL;
- Lzma2EncProps_Init(&p->props);
- Lzma2EncProps_Normalize(&p->props);
- p->outBuf = 0;
- p->alloc = alloc;
- p->allocBig = allocBig;
- {
- unsigned i;
- for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
- p->coders[i].enc = 0;
- }
- #ifndef _7ZIP_ST
- MtCoder_Construct(&p->mtCoder);
- #endif
-
- return p;
-}
-
-void Lzma2Enc_Destroy(CLzma2EncHandle pp)
-{
- CLzma2Enc *p = (CLzma2Enc *)pp;
- unsigned i;
- for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
- {
- CLzma2EncInt *t = &p->coders[i];
- if (t->enc)
- {
- LzmaEnc_Destroy(t->enc, p->alloc, p->allocBig);
- t->enc = 0;
- }
- }
-
- #ifndef _7ZIP_ST
- MtCoder_Destruct(&p->mtCoder);
- #endif
-
- IAlloc_Free(p->alloc, p->outBuf);
- IAlloc_Free(p->alloc, pp);
-}
-
-SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props)
-{
- CLzma2Enc *p = (CLzma2Enc *)pp;
- CLzmaEncProps lzmaProps = props->lzmaProps;
- LzmaEncProps_Normalize(&lzmaProps);
- if (lzmaProps.lc + lzmaProps.lp > LZMA2_LCLP_MAX)
- return SZ_ERROR_PARAM;
- p->props = *props;
- Lzma2EncProps_Normalize(&p->props);
- return SZ_OK;
-}
-
-Byte Lzma2Enc_WriteProperties(CLzma2EncHandle pp)
-{
- CLzma2Enc *p = (CLzma2Enc *)pp;
- unsigned i;
- UInt32 dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps);
- for (i = 0; i < 40; i++)
- if (dicSize <= LZMA2_DIC_SIZE_FROM_PROP(i))
- break;
- return (Byte)i;
-}
-
-SRes Lzma2Enc_Encode(CLzma2EncHandle pp,
- ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress)
-{
- CLzma2Enc *p = (CLzma2Enc *)pp;
- int i;
-
- for (i = 0; i < p->props.numBlockThreads; i++)
- {
- CLzma2EncInt *t = &p->coders[i];
- if (t->enc == NULL)
- {
- t->enc = LzmaEnc_Create(p->alloc);
- if (t->enc == NULL)
- return SZ_ERROR_MEM;
- }
- }
-
- #ifndef _7ZIP_ST
- if (p->props.numBlockThreads <= 1)
- #endif
- return Lzma2Enc_EncodeMt1(&p->coders[0], p, outStream, inStream, progress);
-
- #ifndef _7ZIP_ST
-
- {
- CMtCallbackImp mtCallback;
-
- mtCallback.funcTable.Code = MtCallbackImp_Code;
- mtCallback.lzma2Enc = p;
-
- p->mtCoder.progress = progress;
- p->mtCoder.inStream = inStream;
- p->mtCoder.outStream = outStream;
- p->mtCoder.alloc = p->alloc;
- p->mtCoder.mtCallback = &mtCallback.funcTable;
-
- p->mtCoder.blockSize = p->props.blockSize;
- p->mtCoder.destBlockSize = p->props.blockSize + (p->props.blockSize >> 10) + 16;
- p->mtCoder.numThreads = p->props.numBlockThreads;
-
- return MtCoder_Code(&p->mtCoder);
- }
- #endif
-}
diff --git a/src/libs/7zip/win/C/Lzma2Enc.h b/src/libs/7zip/win/C/Lzma2Enc.h
deleted file mode 100644
index f409f184c..000000000
--- a/src/libs/7zip/win/C/Lzma2Enc.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Lzma2Enc.h -- LZMA2 Encoder
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA2_ENC_H
-#define __LZMA2_ENC_H
-
-#include "LzmaEnc.h"
-
-EXTERN_C_BEGIN
-
-typedef struct
-{
- CLzmaEncProps lzmaProps;
- size_t blockSize;
- int numBlockThreads;
- int numTotalThreads;
-} CLzma2EncProps;
-
-void Lzma2EncProps_Init(CLzma2EncProps *p);
-void Lzma2EncProps_Normalize(CLzma2EncProps *p);
-
-/* ---------- CLzmaEnc2Handle Interface ---------- */
-
-/* Lzma2Enc_* functions can return the following exit codes:
-Returns:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater in props
- SZ_ERROR_WRITE - Write callback error
- SZ_ERROR_PROGRESS - some break from progress callback
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-typedef void * CLzma2EncHandle;
-
-CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig);
-void Lzma2Enc_Destroy(CLzma2EncHandle p);
-SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props);
-Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p);
-SRes Lzma2Enc_Encode(CLzma2EncHandle p,
- ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress);
-
-/* ---------- One Call Interface ---------- */
-
-/* Lzma2Encode
-Return code:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-/*
-SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-*/
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/LzmaDec.c b/src/libs/7zip/win/C/LzmaDec.c
deleted file mode 100644
index b1a2ad150..000000000
--- a/src/libs/7zip/win/C/LzmaDec.c
+++ /dev/null
@@ -1,1025 +0,0 @@
-/* LzmaDec.c -- LZMA Decoder
-2015-01-01 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "LzmaDec.h"
-
-#include <string.h>
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-
-#define RC_INIT_SIZE 5
-
-#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
-
-#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
-#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
-#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
-#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
- { UPDATE_0(p); i = (i + i); A0; } else \
- { UPDATE_1(p); i = (i + i) + 1; A1; }
-#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
-
-#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
-#define TREE_DECODE(probs, limit, i) \
- { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
-
-/* #define _LZMA_SIZE_OPT */
-
-#ifdef _LZMA_SIZE_OPT
-#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
-#else
-#define TREE_6_DECODE(probs, i) \
- { i = 1; \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- TREE_GET_BIT(probs, i); \
- i -= 0x40; }
-#endif
-
-#define NORMAL_LITER_DEC GET_BIT(prob + symbol, symbol)
-#define MATCHED_LITER_DEC \
- matchByte <<= 1; \
- bit = (matchByte & offs); \
- probLit = prob + offs + bit + symbol; \
- GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
-
-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
-
-#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
-#define UPDATE_0_CHECK range = bound;
-#define UPDATE_1_CHECK range -= bound; code -= bound;
-#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
- { UPDATE_0_CHECK; i = (i + i); A0; } else \
- { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
-#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
-#define TREE_DECODE_CHECK(probs, limit, i) \
- { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
-
-
-#define kNumPosBitsMax 4
-#define kNumPosStatesMax (1 << kNumPosBitsMax)
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define LenChoice 0
-#define LenChoice2 (LenChoice + 1)
-#define LenLow (LenChoice2 + 1)
-#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
-#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
-
-
-#define kNumStates 12
-#define kNumLitStates 7
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#define kNumPosSlotBits 6
-#define kNumLenToPosStates 4
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-
-#define kMatchMinLen 2
-#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
-
-#define IsMatch 0
-#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
-#define IsRepG0 (IsRep + kNumStates)
-#define IsRepG1 (IsRepG0 + kNumStates)
-#define IsRepG2 (IsRepG1 + kNumStates)
-#define IsRep0Long (IsRepG2 + kNumStates)
-#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
-#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
-#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
-#define LenCoder (Align + kAlignTableSize)
-#define RepLenCoder (LenCoder + kNumLenProbs)
-#define Literal (RepLenCoder + kNumLenProbs)
-
-#define LZMA_BASE_SIZE 1846
-#define LZMA_LIT_SIZE 768
-
-#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
-
-#if Literal != LZMA_BASE_SIZE
-StopCompilingDueBUG
-#endif
-
-#define LZMA_DIC_MIN (1 << 12)
-
-/* First LZMA-symbol is always decoded.
-And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
-Out:
- Result:
- SZ_OK - OK
- SZ_ERROR_DATA - Error
- p->remainLen:
- < kMatchSpecLenStart : normal remain
- = kMatchSpecLenStart : finished
- = kMatchSpecLenStart + 1 : Flush marker
- = kMatchSpecLenStart + 2 : State Init Marker
-*/
-
-static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
-{
- CLzmaProb *probs = p->probs;
-
- unsigned state = p->state;
- UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
- unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
- unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
- unsigned lc = p->prop.lc;
-
- Byte *dic = p->dic;
- SizeT dicBufSize = p->dicBufSize;
- SizeT dicPos = p->dicPos;
-
- UInt32 processedPos = p->processedPos;
- UInt32 checkDicSize = p->checkDicSize;
- unsigned len = 0;
-
- const Byte *buf = p->buf;
- UInt32 range = p->range;
- UInt32 code = p->code;
-
- do
- {
- CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = processedPos & pbMask;
-
- prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
- IF_BIT_0(prob)
- {
- unsigned symbol;
- UPDATE_0(prob);
- prob = probs + Literal;
- if (checkDicSize != 0 || processedPos != 0)
- prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
- (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
-
- if (state < kNumLitStates)
- {
- state -= (state < 4) ? state : 3;
- symbol = 1;
- #ifdef _LZMA_SIZE_OPT
- do { NORMAL_LITER_DEC } while (symbol < 0x100);
- #else
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- NORMAL_LITER_DEC
- #endif
- }
- else
- {
- unsigned matchByte = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
- unsigned offs = 0x100;
- state -= (state < 10) ? 3 : 6;
- symbol = 1;
- #ifdef _LZMA_SIZE_OPT
- do
- {
- unsigned bit;
- CLzmaProb *probLit;
- MATCHED_LITER_DEC
- }
- while (symbol < 0x100);
- #else
- {
- unsigned bit;
- CLzmaProb *probLit;
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- MATCHED_LITER_DEC
- }
- #endif
- }
- dic[dicPos++] = (Byte)symbol;
- processedPos++;
- continue;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRep + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- state += kNumStates;
- prob = probs + LenCoder;
- }
- else
- {
- UPDATE_1(prob);
- if (checkDicSize == 0 && processedPos == 0)
- return SZ_ERROR_DATA;
- prob = probs + IsRepG0 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
- dicPos++;
- processedPos++;
- state = state < kNumLitStates ? 9 : 11;
- continue;
- }
- UPDATE_1(prob);
- }
- else
- {
- UInt32 distance;
- UPDATE_1(prob);
- prob = probs + IsRepG1 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep1;
- }
- else
- {
- UPDATE_1(prob);
- prob = probs + IsRepG2 + state;
- IF_BIT_0(prob)
- {
- UPDATE_0(prob);
- distance = rep2;
- }
- else
- {
- UPDATE_1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = probs + RepLenCoder;
- }
- {
- unsigned limit, offset;
- CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- limit = (1 << kLenNumLowBits);
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenChoice2;
- IF_BIT_0(probLen)
- {
- UPDATE_0(probLen);
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- limit = (1 << kLenNumMidBits);
- }
- else
- {
- UPDATE_1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- limit = (1 << kLenNumHighBits);
- }
- }
- TREE_DECODE(probLen, limit, len);
- len += offset;
- }
-
- if (state >= kNumStates)
- {
- UInt32 distance;
- prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
- TREE_6_DECODE(prob, distance);
- if (distance >= kStartPosModelIndex)
- {
- unsigned posSlot = (unsigned)distance;
- int numDirectBits = (int)(((distance >> 1) - 1));
- distance = (2 | (distance & 1));
- if (posSlot < kEndPosModelIndex)
- {
- distance <<= numDirectBits;
- prob = probs + SpecPos + distance - posSlot - 1;
- {
- UInt32 mask = 1;
- unsigned i = 1;
- do
- {
- GET_BIT2(prob + i, i, ; , distance |= mask);
- mask <<= 1;
- }
- while (--numDirectBits != 0);
- }
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE
- range >>= 1;
-
- {
- UInt32 t;
- code -= range;
- t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
- distance = (distance << 1) + (t + 1);
- code += range & t;
- }
- /*
- distance <<= 1;
- if (code >= range)
- {
- code -= range;
- distance |= 1;
- }
- */
- }
- while (--numDirectBits != 0);
- prob = probs + Align;
- distance <<= kNumAlignBits;
- {
- unsigned i = 1;
- GET_BIT2(prob + i, i, ; , distance |= 1);
- GET_BIT2(prob + i, i, ; , distance |= 2);
- GET_BIT2(prob + i, i, ; , distance |= 4);
- GET_BIT2(prob + i, i, ; , distance |= 8);
- }
- if (distance == (UInt32)0xFFFFFFFF)
- {
- len += kMatchSpecLenStart;
- state -= kNumStates;
- break;
- }
- }
- }
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- rep0 = distance + 1;
- if (checkDicSize == 0)
- {
- if (distance >= processedPos)
- return SZ_ERROR_DATA;
- }
- else if (distance >= checkDicSize)
- return SZ_ERROR_DATA;
- state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
- }
-
- len += kMatchMinLen;
-
- if (limit == dicPos)
- return SZ_ERROR_DATA;
- {
- SizeT rem = limit - dicPos;
- unsigned curLen = ((rem < len) ? (unsigned)rem : len);
- SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
-
- processedPos += curLen;
-
- len -= curLen;
- if (pos + curLen <= dicBufSize)
- {
- Byte *dest = dic + dicPos;
- ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
- const Byte *lim = dest + curLen;
- dicPos += curLen;
- do
- *(dest) = (Byte)*(dest + src);
- while (++dest != lim);
- }
- else
- {
- do
- {
- dic[dicPos++] = dic[pos];
- if (++pos == dicBufSize)
- pos = 0;
- }
- while (--curLen != 0);
- }
- }
- }
- }
- while (dicPos < limit && buf < bufLimit);
- NORMALIZE;
- p->buf = buf;
- p->range = range;
- p->code = code;
- p->remainLen = len;
- p->dicPos = dicPos;
- p->processedPos = processedPos;
- p->reps[0] = rep0;
- p->reps[1] = rep1;
- p->reps[2] = rep2;
- p->reps[3] = rep3;
- p->state = state;
-
- return SZ_OK;
-}
-
-static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
-{
- if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
- {
- Byte *dic = p->dic;
- SizeT dicPos = p->dicPos;
- SizeT dicBufSize = p->dicBufSize;
- unsigned len = p->remainLen;
- UInt32 rep0 = p->reps[0];
- if (limit - dicPos < len)
- len = (unsigned)(limit - dicPos);
-
- if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
- p->checkDicSize = p->prop.dicSize;
-
- p->processedPos += len;
- p->remainLen -= len;
- while (len != 0)
- {
- len--;
- dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
- dicPos++;
- }
- p->dicPos = dicPos;
- }
-}
-
-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
-{
- do
- {
- SizeT limit2 = limit;
- if (p->checkDicSize == 0)
- {
- UInt32 rem = p->prop.dicSize - p->processedPos;
- if (limit - p->dicPos > rem)
- limit2 = p->dicPos + rem;
- }
- RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
- if (p->processedPos >= p->prop.dicSize)
- p->checkDicSize = p->prop.dicSize;
- LzmaDec_WriteRem(p, limit);
- }
- while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
-
- if (p->remainLen > kMatchSpecLenStart)
- {
- p->remainLen = kMatchSpecLenStart;
- }
- return 0;
-}
-
-typedef enum
-{
- DUMMY_ERROR, /* unexpected end of input stream */
- DUMMY_LIT,
- DUMMY_MATCH,
- DUMMY_REP
-} ELzmaDummy;
-
-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
-{
- UInt32 range = p->range;
- UInt32 code = p->code;
- const Byte *bufLimit = buf + inSize;
- CLzmaProb *probs = p->probs;
- unsigned state = p->state;
- ELzmaDummy res;
-
- {
- CLzmaProb *prob;
- UInt32 bound;
- unsigned ttt;
- unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
-
- prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK
-
- /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
-
- prob = probs + Literal;
- if (p->checkDicSize != 0 || p->processedPos != 0)
- prob += (LZMA_LIT_SIZE *
- ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
- (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
-
- if (state < kNumLitStates)
- {
- unsigned symbol = 1;
- do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
- }
- else
- {
- unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
- ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
- unsigned offs = 0x100;
- unsigned symbol = 1;
- do
- {
- unsigned bit;
- CLzmaProb *probLit;
- matchByte <<= 1;
- bit = (matchByte & offs);
- probLit = prob + offs + bit + symbol;
- GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
- }
- while (symbol < 0x100);
- }
- res = DUMMY_LIT;
- }
- else
- {
- unsigned len;
- UPDATE_1_CHECK;
-
- prob = probs + IsRep + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- state = 0;
- prob = probs + LenCoder;
- res = DUMMY_MATCH;
- }
- else
- {
- UPDATE_1_CHECK;
- res = DUMMY_REP;
- prob = probs + IsRepG0 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- NORMALIZE_CHECK;
- return DUMMY_REP;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG1 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- prob = probs + IsRepG2 + state;
- IF_BIT_0_CHECK(prob)
- {
- UPDATE_0_CHECK;
- }
- else
- {
- UPDATE_1_CHECK;
- }
- }
- }
- state = kNumStates;
- prob = probs + RepLenCoder;
- }
- {
- unsigned limit, offset;
- CLzmaProb *probLen = prob + LenChoice;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- limit = 1 << kLenNumLowBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenChoice2;
- IF_BIT_0_CHECK(probLen)
- {
- UPDATE_0_CHECK;
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- limit = 1 << kLenNumMidBits;
- }
- else
- {
- UPDATE_1_CHECK;
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- limit = 1 << kLenNumHighBits;
- }
- }
- TREE_DECODE_CHECK(probLen, limit, len);
- len += offset;
- }
-
- if (state < 4)
- {
- unsigned posSlot;
- prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
- {
- int numDirectBits = ((posSlot >> 1) - 1);
-
- /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
-
- if (posSlot < kEndPosModelIndex)
- {
- prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- NORMALIZE_CHECK
- range >>= 1;
- code -= range & (((code - range) >> 31) - 1);
- /* if (code >= range) code -= range; */
- }
- while (--numDirectBits != 0);
- prob = probs + Align;
- numDirectBits = kNumAlignBits;
- }
- {
- unsigned i = 1;
- do
- {
- GET_BIT_CHECK(prob + i, i);
- }
- while (--numDirectBits != 0);
- }
- }
- }
- }
- }
- NORMALIZE_CHECK;
- return res;
-}
-
-
-static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
-{
- p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
- p->range = 0xFFFFFFFF;
- p->needFlush = 0;
-}
-
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
-{
- p->needFlush = 1;
- p->remainLen = 0;
- p->tempBufSize = 0;
-
- if (initDic)
- {
- p->processedPos = 0;
- p->checkDicSize = 0;
- p->needInitState = 1;
- }
- if (initState)
- p->needInitState = 1;
-}
-
-void LzmaDec_Init(CLzmaDec *p)
-{
- p->dicPos = 0;
- LzmaDec_InitDicAndState(p, True, True);
-}
-
-static void LzmaDec_InitStateReal(CLzmaDec *p)
-{
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
- UInt32 i;
- CLzmaProb *probs = p->probs;
- for (i = 0; i < numProbs; i++)
- probs[i] = kBitModelTotal >> 1;
- p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
- p->state = 0;
- p->needInitState = 0;
-}
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
- ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT inSize = *srcLen;
- (*srcLen) = 0;
- LzmaDec_WriteRem(p, dicLimit);
-
- *status = LZMA_STATUS_NOT_SPECIFIED;
-
- while (p->remainLen != kMatchSpecLenStart)
- {
- int checkEndMarkNow;
-
- if (p->needFlush != 0)
- {
- for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
- p->tempBuf[p->tempBufSize++] = *src++;
- if (p->tempBufSize < RC_INIT_SIZE)
- {
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (p->tempBuf[0] != 0)
- return SZ_ERROR_DATA;
-
- LzmaDec_InitRc(p, p->tempBuf);
- p->tempBufSize = 0;
- }
-
- checkEndMarkNow = 0;
- if (p->dicPos >= dicLimit)
- {
- if (p->remainLen == 0 && p->code == 0)
- {
- *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
- return SZ_OK;
- }
- if (finishMode == LZMA_FINISH_ANY)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_OK;
- }
- if (p->remainLen != 0)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- checkEndMarkNow = 1;
- }
-
- if (p->needInitState)
- LzmaDec_InitStateReal(p);
-
- if (p->tempBufSize == 0)
- {
- SizeT processed;
- const Byte *bufLimit;
- if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- int dummyRes = LzmaDec_TryDummy(p, src, inSize);
- if (dummyRes == DUMMY_ERROR)
- {
- memcpy(p->tempBuf, src, inSize);
- p->tempBufSize = (unsigned)inSize;
- (*srcLen) += inSize;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- bufLimit = src;
- }
- else
- bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
- p->buf = src;
- if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
- return SZ_ERROR_DATA;
- processed = (SizeT)(p->buf - src);
- (*srcLen) += processed;
- src += processed;
- inSize -= processed;
- }
- else
- {
- unsigned rem = p->tempBufSize, lookAhead = 0;
- while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
- p->tempBuf[rem++] = src[lookAhead++];
- p->tempBufSize = rem;
- if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
- {
- int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
- if (dummyRes == DUMMY_ERROR)
- {
- (*srcLen) += lookAhead;
- *status = LZMA_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
- if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
- {
- *status = LZMA_STATUS_NOT_FINISHED;
- return SZ_ERROR_DATA;
- }
- }
- p->buf = p->tempBuf;
- if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
- return SZ_ERROR_DATA;
- lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
- (*srcLen) += lookAhead;
- src += lookAhead;
- inSize -= lookAhead;
- p->tempBufSize = 0;
- }
- }
- if (p->code == 0)
- *status = LZMA_STATUS_FINISHED_WITH_MARK;
- return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
-}
-
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
-{
- SizeT outSize = *destLen;
- SizeT inSize = *srcLen;
- *srcLen = *destLen = 0;
- for (;;)
- {
- SizeT inSizeCur = inSize, outSizeCur, dicPos;
- ELzmaFinishMode curFinishMode;
- SRes res;
- if (p->dicPos == p->dicBufSize)
- p->dicPos = 0;
- dicPos = p->dicPos;
- if (outSize > p->dicBufSize - dicPos)
- {
- outSizeCur = p->dicBufSize;
- curFinishMode = LZMA_FINISH_ANY;
- }
- else
- {
- outSizeCur = dicPos + outSize;
- curFinishMode = finishMode;
- }
-
- res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
- src += inSizeCur;
- inSize -= inSizeCur;
- *srcLen += inSizeCur;
- outSizeCur = p->dicPos - dicPos;
- memcpy(dest, p->dic + dicPos, outSizeCur);
- dest += outSizeCur;
- outSize -= outSizeCur;
- *destLen += outSizeCur;
- if (res != 0)
- return res;
- if (outSizeCur == 0 || outSize == 0)
- return SZ_OK;
- }
-}
-
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->probs);
- p->probs = 0;
-}
-
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->dic);
- p->dic = 0;
-}
-
-void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
-{
- LzmaDec_FreeProbs(p, alloc);
- LzmaDec_FreeDict(p, alloc);
-}
-
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
-{
- UInt32 dicSize;
- Byte d;
-
- if (size < LZMA_PROPS_SIZE)
- return SZ_ERROR_UNSUPPORTED;
- else
- dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
-
- if (dicSize < LZMA_DIC_MIN)
- dicSize = LZMA_DIC_MIN;
- p->dicSize = dicSize;
-
- d = data[0];
- if (d >= (9 * 5 * 5))
- return SZ_ERROR_UNSUPPORTED;
-
- p->lc = d % 9;
- d /= 9;
- p->pb = d / 5;
- p->lp = d % 5;
-
- return SZ_OK;
-}
-
-static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
-{
- UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
- if (p->probs == 0 || numProbs != p->numProbs)
- {
- LzmaDec_FreeProbs(p, alloc);
- p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
- p->numProbs = numProbs;
- if (p->probs == 0)
- return SZ_ERROR_MEM;
- }
- return SZ_OK;
-}
-
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
-{
- CLzmaProps propNew;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
- p->prop = propNew;
- return SZ_OK;
-}
-
-SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
-{
- CLzmaProps propNew;
- SizeT dicBufSize;
- RINOK(LzmaProps_Decode(&propNew, props, propsSize));
- RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
- dicBufSize = propNew.dicSize;
- if (p->dic == 0 || dicBufSize != p->dicBufSize)
- {
- LzmaDec_FreeDict(p, alloc);
- p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
- if (p->dic == 0)
- {
- LzmaDec_FreeProbs(p, alloc);
- return SZ_ERROR_MEM;
- }
- }
- p->dicBufSize = dicBufSize;
- p->prop = propNew;
- return SZ_OK;
-}
-
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAlloc *alloc)
-{
- CLzmaDec p;
- SRes res;
- SizeT outSize = *destLen, inSize = *srcLen;
- *destLen = *srcLen = 0;
- *status = LZMA_STATUS_NOT_SPECIFIED;
- if (inSize < RC_INIT_SIZE)
- return SZ_ERROR_INPUT_EOF;
- LzmaDec_Construct(&p);
- RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));
- p.dic = dest;
- p.dicBufSize = outSize;
- LzmaDec_Init(&p);
- *srcLen = inSize;
- res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
- *destLen = p.dicPos;
- if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
- res = SZ_ERROR_INPUT_EOF;
- LzmaDec_FreeProbs(&p, alloc);
- return res;
-}
diff --git a/src/libs/7zip/win/C/LzmaDec.h b/src/libs/7zip/win/C/LzmaDec.h
deleted file mode 100644
index 63efc351f..000000000
--- a/src/libs/7zip/win/C/LzmaDec.h
+++ /dev/null
@@ -1,227 +0,0 @@
-/* LzmaDec.h -- LZMA Decoder
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_DEC_H
-#define __LZMA_DEC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-/* #define _LZMA_PROB32 */
-/* _LZMA_PROB32 can increase the speed on some CPUs,
- but memory usage for CLzmaDec::probs will be doubled in that case */
-
-#ifdef _LZMA_PROB32
-#define CLzmaProb UInt32
-#else
-#define CLzmaProb UInt16
-#endif
-
-
-/* ---------- LZMA Properties ---------- */
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaProps
-{
- unsigned lc, lp, pb;
- UInt32 dicSize;
-} CLzmaProps;
-
-/* LzmaProps_Decode - decodes properties
-Returns:
- SZ_OK
- SZ_ERROR_UNSUPPORTED - Unsupported properties
-*/
-
-SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
-
-
-/* ---------- LZMA Decoder state ---------- */
-
-/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
- Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
-
-#define LZMA_REQUIRED_INPUT_MAX 20
-
-typedef struct
-{
- CLzmaProps prop;
- CLzmaProb *probs;
- Byte *dic;
- const Byte *buf;
- UInt32 range, code;
- SizeT dicPos;
- SizeT dicBufSize;
- UInt32 processedPos;
- UInt32 checkDicSize;
- unsigned state;
- UInt32 reps[4];
- unsigned remainLen;
- int needFlush;
- int needInitState;
- UInt32 numProbs;
- unsigned tempBufSize;
- Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
-} CLzmaDec;
-
-#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
-
-void LzmaDec_Init(CLzmaDec *p);
-
-/* There are two types of LZMA streams:
- 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
- 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
-
-typedef enum
-{
- LZMA_FINISH_ANY, /* finish at any point */
- LZMA_FINISH_END /* block must be finished at the end */
-} ELzmaFinishMode;
-
-/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
-
- You must use LZMA_FINISH_END, when you know that current output buffer
- covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
-
- If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
- and output value of destLen will be less than output buffer size limit.
- You can check status result also.
-
- You can use multiple checks to test data integrity after full decompression:
- 1) Check Result and "status" variable.
- 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
-
-typedef enum
-{
- LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
- LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
- LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
- LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
-} ELzmaStatus;
-
-/* ELzmaStatus is used only as output value for function call */
-
-
-/* ---------- Interfaces ---------- */
-
-/* There are 3 levels of interfaces:
- 1) Dictionary Interface
- 2) Buffer Interface
- 3) One Call Interface
- You can select any of these interfaces, but don't mix functions from different
- groups for same object. */
-
-
-/* There are two variants to allocate state for Dictionary Interface:
- 1) LzmaDec_Allocate / LzmaDec_Free
- 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
- You can use variant 2, if you set dictionary buffer manually.
- For Buffer Interface you must always use variant 1.
-
-LzmaDec_Allocate* can return:
- SZ_OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
-*/
-
-SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
-
-SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
-void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
-
-/* ---------- Dictionary Interface ---------- */
-
-/* You can use it, if you want to eliminate the overhead for data copying from
- dictionary to some other external buffer.
- You must work with CLzmaDec variables directly in this interface.
-
- STEPS:
- LzmaDec_Constr()
- LzmaDec_Allocate()
- for (each new stream)
- {
- LzmaDec_Init()
- while (it needs more decompression)
- {
- LzmaDec_DecodeToDic()
- use data from CLzmaDec::dic and update CLzmaDec::dicPos
- }
- }
- LzmaDec_Free()
-*/
-
-/* LzmaDec_DecodeToDic
-
- The decoding to internal dictionary buffer (CLzmaDec::dic).
- You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
-
-finishMode:
- It has meaning only if the decoding reaches output limit (dicLimit).
- LZMA_FINISH_ANY - Decode just dicLimit bytes.
- LZMA_FINISH_END - Stream must be finished after dicLimit.
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_NEEDS_MORE_INPUT
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
-*/
-
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- Buffer Interface ---------- */
-
-/* It's zlib-like interface.
- See LzmaDec_DecodeToDic description for information about STEPS and return results,
- but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
- to work with CLzmaDec variables manually.
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
-*/
-
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-
-
-/* ---------- One Call Interface ---------- */
-
-/* LzmaDecode
-
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- LZMA_FINISH_ANY - Decode just destLen bytes.
- LZMA_FINISH_END - Stream must be finished after (*destLen).
-
-Returns:
- SZ_OK
- status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
- LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
- SZ_ERROR_DATA - Data error
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_UNSUPPORTED - Unsupported properties
- SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
-*/
-
-SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
- ELzmaStatus *status, ISzAlloc *alloc);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/LzmaEnc.c b/src/libs/7zip/win/C/LzmaEnc.c
deleted file mode 100644
index bf3cc2ddb..000000000
--- a/src/libs/7zip/win/C/LzmaEnc.c
+++ /dev/null
@@ -1,2278 +0,0 @@
-/* LzmaEnc.c -- LZMA Encoder
-2014-12-29 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include <string.h>
-
-/* #define SHOW_STAT */
-/* #define SHOW_STAT2 */
-
-#if defined(SHOW_STAT) || defined(SHOW_STAT2)
-#include <stdio.h>
-#endif
-
-#include "LzmaEnc.h"
-
-#include "LzFind.h"
-#ifndef _7ZIP_ST
-#include "LzFindMt.h"
-#endif
-
-#ifdef SHOW_STAT
-static unsigned g_STAT_OFFSET = 0;
-#endif
-
-#define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1)
-
-#define kBlockSize (9 << 10)
-#define kUnpackBlockSize (1 << 18)
-#define kMatchArraySize (1 << 21)
-#define kMatchRecordMaxSize ((LZMA_MATCH_LEN_MAX * 2 + 3) * LZMA_MATCH_LEN_MAX)
-
-#define kNumMaxDirectBits (31)
-
-#define kNumTopBits 24
-#define kTopValue ((UInt32)1 << kNumTopBits)
-
-#define kNumBitModelTotalBits 11
-#define kBitModelTotal (1 << kNumBitModelTotalBits)
-#define kNumMoveBits 5
-#define kProbInitValue (kBitModelTotal >> 1)
-
-#define kNumMoveReducingBits 4
-#define kNumBitPriceShiftBits 4
-#define kBitPrice (1 << kNumBitPriceShiftBits)
-
-void LzmaEncProps_Init(CLzmaEncProps *p)
-{
- p->level = 5;
- p->dictSize = p->mc = 0;
- p->reduceSize = (UInt64)(Int64)-1;
- p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
- p->writeEndMark = 0;
-}
-
-void LzmaEncProps_Normalize(CLzmaEncProps *p)
-{
- int level = p->level;
- if (level < 0) level = 5;
- p->level = level;
- if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
- if (p->dictSize > p->reduceSize)
- {
- unsigned i;
- for (i = 11; i <= 30; i++)
- {
- if ((UInt32)p->reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; }
- if ((UInt32)p->reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; }
- }
- }
- if (p->lc < 0) p->lc = 3;
- if (p->lp < 0) p->lp = 0;
- if (p->pb < 0) p->pb = 2;
- if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
- if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
- if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
- if (p->numHashBytes < 0) p->numHashBytes = 4;
- if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
- if (p->numThreads < 0)
- p->numThreads =
- #ifndef _7ZIP_ST
- ((p->btMode && p->algo) ? 2 : 1);
- #else
- 1;
- #endif
-}
-
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
-{
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
- return props.dictSize;
-}
-
-/* #define LZMA_LOG_BSR */
-/* Define it for Intel's CPU */
-
-
-#ifdef LZMA_LOG_BSR
-
-#define kDicLogSizeMaxCompress 30
-
-#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
-
-UInt32 GetPosSlot1(UInt32 pos)
-{
- UInt32 res;
- BSR2_RET(pos, res);
- return res;
-}
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
-
-#else
-
-#define kNumLogBits (9 + (int)sizeof(size_t) / 2)
-#define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
-
-void LzmaEnc_FastPosInit(Byte *g_FastPos)
-{
- int c = 2, slotFast;
- g_FastPos[0] = 0;
- g_FastPos[1] = 1;
-
- for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)
- {
- UInt32 k = (1 << ((slotFast >> 1) - 1));
- UInt32 j;
- for (j = 0; j < k; j++, c++)
- g_FastPos[c] = (Byte)slotFast;
- }
-}
-
-#define BSR2_RET(pos, res) { UInt32 i = 6 + ((kNumLogBits - 1) & \
- (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \
- res = p->g_FastPos[pos >> i] + (i * 2); }
-/*
-#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \
- p->g_FastPos[pos >> 6] + 12 : \
- p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; }
-*/
-
-#define GetPosSlot1(pos) p->g_FastPos[pos]
-#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
-#define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); }
-
-#endif
-
-
-#define LZMA_NUM_REPS 4
-
-typedef unsigned CState;
-
-typedef struct
-{
- UInt32 price;
-
- CState state;
- int prev1IsChar;
- int prev2;
-
- UInt32 posPrev2;
- UInt32 backPrev2;
-
- UInt32 posPrev;
- UInt32 backPrev;
- UInt32 backs[LZMA_NUM_REPS];
-} COptimal;
-
-#define kNumOpts (1 << 12)
-
-#define kNumLenToPosStates 4
-#define kNumPosSlotBits 6
-#define kDicLogSizeMin 0
-#define kDicLogSizeMax 32
-#define kDistTableSizeMax (kDicLogSizeMax * 2)
-
-
-#define kNumAlignBits 4
-#define kAlignTableSize (1 << kNumAlignBits)
-#define kAlignMask (kAlignTableSize - 1)
-
-#define kStartPosModelIndex 4
-#define kEndPosModelIndex 14
-#define kNumPosModels (kEndPosModelIndex - kStartPosModelIndex)
-
-#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
-
-#ifdef _LZMA_PROB32
-#define CLzmaProb UInt32
-#else
-#define CLzmaProb UInt16
-#endif
-
-#define LZMA_PB_MAX 4
-#define LZMA_LC_MAX 8
-#define LZMA_LP_MAX 4
-
-#define LZMA_NUM_PB_STATES_MAX (1 << LZMA_PB_MAX)
-
-
-#define kLenNumLowBits 3
-#define kLenNumLowSymbols (1 << kLenNumLowBits)
-#define kLenNumMidBits 3
-#define kLenNumMidSymbols (1 << kLenNumMidBits)
-#define kLenNumHighBits 8
-#define kLenNumHighSymbols (1 << kLenNumHighBits)
-
-#define kLenNumSymbolsTotal (kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
-
-#define LZMA_MATCH_LEN_MIN 2
-#define LZMA_MATCH_LEN_MAX (LZMA_MATCH_LEN_MIN + kLenNumSymbolsTotal - 1)
-
-#define kNumStates 12
-
-typedef struct
-{
- CLzmaProb choice;
- CLzmaProb choice2;
- CLzmaProb low[LZMA_NUM_PB_STATES_MAX << kLenNumLowBits];
- CLzmaProb mid[LZMA_NUM_PB_STATES_MAX << kLenNumMidBits];
- CLzmaProb high[kLenNumHighSymbols];
-} CLenEnc;
-
-typedef struct
-{
- CLenEnc p;
- UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
- UInt32 tableSize;
- UInt32 counters[LZMA_NUM_PB_STATES_MAX];
-} CLenPriceEnc;
-
-typedef struct
-{
- UInt32 range;
- Byte cache;
- UInt64 low;
- UInt64 cacheSize;
- Byte *buf;
- Byte *bufLim;
- Byte *bufBase;
- ISeqOutStream *outStream;
- UInt64 processed;
- SRes res;
-} CRangeEnc;
-
-typedef struct
-{
- CLzmaProb *litProbs;
-
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
-
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
-
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
-
- UInt32 reps[LZMA_NUM_REPS];
- UInt32 state;
-} CSaveState;
-
-typedef struct
-{
- IMatchFinder matchFinder;
- void *matchFinderObj;
-
- #ifndef _7ZIP_ST
- Bool mtMode;
- CMatchFinderMt matchFinderMt;
- #endif
-
- CMatchFinder matchFinderBase;
-
- #ifndef _7ZIP_ST
- Byte pad[128];
- #endif
-
- UInt32 optimumEndIndex;
- UInt32 optimumCurrentIndex;
-
- UInt32 longestMatchLength;
- UInt32 numPairs;
- UInt32 numAvail;
- COptimal opt[kNumOpts];
-
- #ifndef LZMA_LOG_BSR
- Byte g_FastPos[1 << kNumLogBits];
- #endif
-
- UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
- UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
- UInt32 numFastBytes;
- UInt32 additionalOffset;
- UInt32 reps[LZMA_NUM_REPS];
- UInt32 state;
-
- UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
- UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances];
- UInt32 alignPrices[kAlignTableSize];
- UInt32 alignPriceCount;
-
- UInt32 distTableSize;
-
- unsigned lc, lp, pb;
- unsigned lpMask, pbMask;
-
- CLzmaProb *litProbs;
-
- CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX];
- CLzmaProb isRep[kNumStates];
- CLzmaProb isRepG0[kNumStates];
- CLzmaProb isRepG1[kNumStates];
- CLzmaProb isRepG2[kNumStates];
- CLzmaProb isRep0Long[kNumStates][LZMA_NUM_PB_STATES_MAX];
-
- CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
- CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
- CLzmaProb posAlignEncoder[1 << kNumAlignBits];
-
- CLenPriceEnc lenEnc;
- CLenPriceEnc repLenEnc;
-
- unsigned lclp;
-
- Bool fastMode;
-
- CRangeEnc rc;
-
- Bool writeEndMark;
- UInt64 nowPos64;
- UInt32 matchPriceCount;
- Bool finished;
- Bool multiThread;
-
- SRes result;
- UInt32 dictSize;
-
- int needInit;
-
- CSaveState saveState;
-} CLzmaEnc;
-
-void LzmaEnc_SaveState(CLzmaEncHandle pp)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CSaveState *dest = &p->saveState;
- int i;
- dest->lenEnc = p->lenEnc;
- dest->repLenEnc = p->repLenEnc;
- dest->state = p->state;
-
- for (i = 0; i < kNumStates; i++)
- {
- memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
- memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
- }
- for (i = 0; i < kNumLenToPosStates; i++)
- memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
- memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
- memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
- memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
- memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
- memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
- memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
- memcpy(dest->reps, p->reps, sizeof(p->reps));
- memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
-}
-
-void LzmaEnc_RestoreState(CLzmaEncHandle pp)
-{
- CLzmaEnc *dest = (CLzmaEnc *)pp;
- const CSaveState *p = &dest->saveState;
- int i;
- dest->lenEnc = p->lenEnc;
- dest->repLenEnc = p->repLenEnc;
- dest->state = p->state;
-
- for (i = 0; i < kNumStates; i++)
- {
- memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
- memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
- }
- for (i = 0; i < kNumLenToPosStates; i++)
- memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
- memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
- memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
- memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
- memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
- memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
- memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
- memcpy(dest->reps, p->reps, sizeof(p->reps));
- memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
-}
-
-SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- CLzmaEncProps props = *props2;
- LzmaEncProps_Normalize(&props);
-
- if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||
- props.dictSize > ((UInt32)1 << kDicLogSizeMaxCompress) || props.dictSize > ((UInt32)1 << 30))
- return SZ_ERROR_PARAM;
- p->dictSize = props.dictSize;
- {
- unsigned fb = props.fb;
- if (fb < 5)
- fb = 5;
- if (fb > LZMA_MATCH_LEN_MAX)
- fb = LZMA_MATCH_LEN_MAX;
- p->numFastBytes = fb;
- }
- p->lc = props.lc;
- p->lp = props.lp;
- p->pb = props.pb;
- p->fastMode = (props.algo == 0);
- p->matchFinderBase.btMode = props.btMode;
- {
- UInt32 numHashBytes = 4;
- if (props.btMode)
- {
- if (props.numHashBytes < 2)
- numHashBytes = 2;
- else if (props.numHashBytes < 4)
- numHashBytes = props.numHashBytes;
- }
- p->matchFinderBase.numHashBytes = numHashBytes;
- }
-
- p->matchFinderBase.cutValue = props.mc;
-
- p->writeEndMark = props.writeEndMark;
-
- #ifndef _7ZIP_ST
- /*
- if (newMultiThread != _multiThread)
- {
- ReleaseMatchFinder();
- _multiThread = newMultiThread;
- }
- */
- p->multiThread = (props.numThreads > 1);
- #endif
-
- return SZ_OK;
-}
-
-static const int kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
-static const int kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
-static const int kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
-static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
-
-#define IsCharState(s) ((s) < 7)
-
-#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
-
-#define kInfinityPrice (1 << 30)
-
-static void RangeEnc_Construct(CRangeEnc *p)
-{
- p->outStream = 0;
- p->bufBase = 0;
-}
-
-#define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize)
-
-#define RC_BUF_SIZE (1 << 16)
-static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc)
-{
- if (p->bufBase == 0)
- {
- p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE);
- if (p->bufBase == 0)
- return 0;
- p->bufLim = p->bufBase + RC_BUF_SIZE;
- }
- return 1;
-}
-
-static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->bufBase);
- p->bufBase = 0;
-}
-
-static void RangeEnc_Init(CRangeEnc *p)
-{
- /* Stream.Init(); */
- p->low = 0;
- p->range = 0xFFFFFFFF;
- p->cacheSize = 1;
- p->cache = 0;
-
- p->buf = p->bufBase;
-
- p->processed = 0;
- p->res = SZ_OK;
-}
-
-static void RangeEnc_FlushStream(CRangeEnc *p)
-{
- size_t num;
- if (p->res != SZ_OK)
- return;
- num = p->buf - p->bufBase;
- if (num != p->outStream->Write(p->outStream, p->bufBase, num))
- p->res = SZ_ERROR_WRITE;
- p->processed += num;
- p->buf = p->bufBase;
-}
-
-static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
-{
- if ((UInt32)p->low < (UInt32)0xFF000000 || (unsigned)(p->low >> 32) != 0)
- {
- Byte temp = p->cache;
- do
- {
- Byte *buf = p->buf;
- *buf++ = (Byte)(temp + (Byte)(p->low >> 32));
- p->buf = buf;
- if (buf == p->bufLim)
- RangeEnc_FlushStream(p);
- temp = 0xFF;
- }
- while (--p->cacheSize != 0);
- p->cache = (Byte)((UInt32)p->low >> 24);
- }
- p->cacheSize++;
- p->low = (UInt32)p->low << 8;
-}
-
-static void RangeEnc_FlushData(CRangeEnc *p)
-{
- int i;
- for (i = 0; i < 5; i++)
- RangeEnc_ShiftLow(p);
-}
-
-static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, unsigned numBits)
-{
- do
- {
- p->range >>= 1;
- p->low += p->range & (0 - ((value >> --numBits) & 1));
- if (p->range < kTopValue)
- {
- p->range <<= 8;
- RangeEnc_ShiftLow(p);
- }
- }
- while (numBits != 0);
-}
-
-static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
-{
- UInt32 ttt = *prob;
- UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt;
- if (symbol == 0)
- {
- p->range = newBound;
- ttt += (kBitModelTotal - ttt) >> kNumMoveBits;
- }
- else
- {
- p->low += newBound;
- p->range -= newBound;
- ttt -= ttt >> kNumMoveBits;
- }
- *prob = (CLzmaProb)ttt;
- if (p->range < kTopValue)
- {
- p->range <<= 8;
- RangeEnc_ShiftLow(p);
- }
-}
-
-static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
-{
- symbol |= 0x100;
- do
- {
- RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
- symbol <<= 1;
- }
- while (symbol < 0x10000);
-}
-
-static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
-{
- UInt32 offs = 0x100;
- symbol |= 0x100;
- do
- {
- matchByte <<= 1;
- RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
- }
- while (symbol < 0x10000);
-}
-
-void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
-{
- UInt32 i;
- for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
- {
- const int kCyclesBits = kNumBitPriceShiftBits;
- UInt32 w = i;
- UInt32 bitCount = 0;
- int j;
- for (j = 0; j < kCyclesBits; j++)
- {
- w = w * w;
- bitCount <<= 1;
- while (w >= ((UInt32)1 << 16))
- {
- w >>= 1;
- bitCount++;
- }
- }
- ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
- }
-}
-
-
-#define GET_PRICE(prob, symbol) \
- p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICEa(prob, symbol) \
- ProbPrices[((prob) ^ ((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-
-#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-#define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits]
-#define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- symbol |= 0x100;
- do
- {
- price += GET_PRICEa(probs[symbol >> 8], (symbol >> 7) & 1);
- symbol <<= 1;
- }
- while (symbol < 0x10000);
- return price;
-}
-
-static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- UInt32 offs = 0x100;
- symbol |= 0x100;
- do
- {
- matchByte <<= 1;
- price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
- }
- while (symbol < 0x10000);
- return price;
-}
-
-
-static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
-{
- UInt32 m = 1;
- int i;
- for (i = numBitLevels; i != 0;)
- {
- UInt32 bit;
- i--;
- bit = (symbol >> i) & 1;
- RangeEnc_EncodeBit(rc, probs + m, bit);
- m = (m << 1) | bit;
- }
-}
-
-static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
-{
- UInt32 m = 1;
- int i;
- for (i = 0; i < numBitLevels; i++)
- {
- UInt32 bit = symbol & 1;
- RangeEnc_EncodeBit(rc, probs + m, bit);
- m = (m << 1) | bit;
- symbol >>= 1;
- }
-}
-
-static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- symbol |= (1 << numBitLevels);
- while (symbol != 1)
- {
- price += GET_PRICEa(probs[symbol >> 1], symbol & 1);
- symbol >>= 1;
- }
- return price;
-}
-
-static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, UInt32 *ProbPrices)
-{
- UInt32 price = 0;
- UInt32 m = 1;
- int i;
- for (i = numBitLevels; i != 0; i--)
- {
- UInt32 bit = symbol & 1;
- symbol >>= 1;
- price += GET_PRICEa(probs[m], bit);
- m = (m << 1) | bit;
- }
- return price;
-}
-
-
-static void LenEnc_Init(CLenEnc *p)
-{
- unsigned i;
- p->choice = p->choice2 = kProbInitValue;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumLowBits); i++)
- p->low[i] = kProbInitValue;
- for (i = 0; i < (LZMA_NUM_PB_STATES_MAX << kLenNumMidBits); i++)
- p->mid[i] = kProbInitValue;
- for (i = 0; i < kLenNumHighSymbols; i++)
- p->high[i] = kProbInitValue;
-}
-
-static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState)
-{
- if (symbol < kLenNumLowSymbols)
- {
- RangeEnc_EncodeBit(rc, &p->choice, 0);
- RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol);
- }
- else
- {
- RangeEnc_EncodeBit(rc, &p->choice, 1);
- if (symbol < kLenNumLowSymbols + kLenNumMidSymbols)
- {
- RangeEnc_EncodeBit(rc, &p->choice2, 0);
- RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbols);
- }
- else
- {
- RangeEnc_EncodeBit(rc, &p->choice2, 1);
- RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols);
- }
- }
-}
-
-static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32 *ProbPrices)
-{
- UInt32 a0 = GET_PRICE_0a(p->choice);
- UInt32 a1 = GET_PRICE_1a(p->choice);
- UInt32 b0 = a1 + GET_PRICE_0a(p->choice2);
- UInt32 b1 = a1 + GET_PRICE_1a(p->choice2);
- UInt32 i = 0;
- for (i = 0; i < kLenNumLowSymbols; i++)
- {
- if (i >= numSymbols)
- return;
- prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPrices);
- }
- for (; i < kLenNumLowSymbols + kLenNumMidSymbols; i++)
- {
- if (i >= numSymbols)
- return;
- prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNumLowSymbols, ProbPrices);
- }
- for (; i < numSymbols; i++)
- prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices);
-}
-
-static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPrices)
-{
- LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices);
- p->counters[posState] = p->tableSize;
-}
-
-static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices)
-{
- UInt32 posState;
- for (posState = 0; posState < numPosStates; posState++)
- LenPriceEnc_UpdateTable(p, posState, ProbPrices);
-}
-
-static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, UInt32 *ProbPrices)
-{
- LenEnc_Encode(&p->p, rc, symbol, posState);
- if (updatePrice)
- if (--p->counters[posState] == 0)
- LenPriceEnc_UpdateTable(p, posState, ProbPrices);
-}
-
-
-
-
-static void MovePos(CLzmaEnc *p, UInt32 num)
-{
- #ifdef SHOW_STAT
- g_STAT_OFFSET += num;
- printf("\n MovePos %d", num);
- #endif
-
- if (num != 0)
- {
- p->additionalOffset += num;
- p->matchFinder.Skip(p->matchFinderObj, num);
- }
-}
-
-static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
-{
- UInt32 lenRes = 0, numPairs;
- p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
- numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
-
- #ifdef SHOW_STAT
- printf("\n i = %d numPairs = %d ", g_STAT_OFFSET, numPairs / 2);
- g_STAT_OFFSET++;
- {
- UInt32 i;
- for (i = 0; i < numPairs; i += 2)
- printf("%2d %6d | ", p->matches[i], p->matches[i + 1]);
- }
- #endif
-
- if (numPairs > 0)
- {
- lenRes = p->matches[numPairs - 2];
- if (lenRes == p->numFastBytes)
- {
- const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- UInt32 distance = p->matches[numPairs - 1] + 1;
- UInt32 numAvail = p->numAvail;
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
- {
- const Byte *pby2 = pby - distance;
- for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
- }
- }
- }
- p->additionalOffset++;
- *numDistancePairsRes = numPairs;
- return lenRes;
-}
-
-
-#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False;
-#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False;
-#define IsShortRep(p) ((p)->backPrev == 0)
-
-static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)
-{
- return
- GET_PRICE_0(p->isRepG0[state]) +
- GET_PRICE_0(p->isRep0Long[state][posState]);
-}
-
-static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState)
-{
- UInt32 price;
- if (repIndex == 0)
- {
- price = GET_PRICE_0(p->isRepG0[state]);
- price += GET_PRICE_1(p->isRep0Long[state][posState]);
- }
- else
- {
- price = GET_PRICE_1(p->isRepG0[state]);
- if (repIndex == 1)
- price += GET_PRICE_0(p->isRepG1[state]);
- else
- {
- price += GET_PRICE_1(p->isRepG1[state]);
- price += GET_PRICE(p->isRepG2[state], repIndex - 2);
- }
- }
- return price;
-}
-
-static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState)
-{
- return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] +
- GetPureRepPrice(p, repIndex, state, posState);
-}
-
-static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
-{
- UInt32 posMem = p->opt[cur].posPrev;
- UInt32 backMem = p->opt[cur].backPrev;
- p->optimumEndIndex = cur;
- do
- {
- if (p->opt[cur].prev1IsChar)
- {
- MakeAsChar(&p->opt[posMem])
- p->opt[posMem].posPrev = posMem - 1;
- if (p->opt[cur].prev2)
- {
- p->opt[posMem - 1].prev1IsChar = False;
- p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2;
- p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2;
- }
- }
- {
- UInt32 posPrev = posMem;
- UInt32 backCur = backMem;
-
- backMem = p->opt[posPrev].backPrev;
- posMem = p->opt[posPrev].posPrev;
-
- p->opt[posPrev].backPrev = backCur;
- p->opt[posPrev].posPrev = cur;
- cur = posPrev;
- }
- }
- while (cur != 0);
- *backRes = p->opt[0].backPrev;
- p->optimumCurrentIndex = p->opt[0].posPrev;
- return p->optimumCurrentIndex;
-}
-
-#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
-
-static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
-{
- UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;
- UInt32 matchPrice, repMatchPrice, normalMatchPrice;
- UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];
- UInt32 *matches;
- const Byte *data;
- Byte curByte, matchByte;
- if (p->optimumEndIndex != p->optimumCurrentIndex)
- {
- const COptimal *opt = &p->opt[p->optimumCurrentIndex];
- UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex;
- *backRes = opt->backPrev;
- p->optimumCurrentIndex = opt->posPrev;
- return lenRes;
- }
- p->optimumCurrentIndex = p->optimumEndIndex = 0;
-
- if (p->additionalOffset == 0)
- mainLen = ReadMatchDistances(p, &numPairs);
- else
- {
- mainLen = p->longestMatchLength;
- numPairs = p->numPairs;
- }
-
- numAvail = p->numAvail;
- if (numAvail < 2)
- {
- *backRes = (UInt32)(-1);
- return 1;
- }
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- repMaxIndex = 0;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 lenTest;
- const Byte *data2;
- reps[i] = p->reps[i];
- data2 = data - (reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- {
- repLens[i] = 0;
- continue;
- }
- for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
- repLens[i] = lenTest;
- if (lenTest > repLens[repMaxIndex])
- repMaxIndex = i;
- }
- if (repLens[repMaxIndex] >= p->numFastBytes)
- {
- UInt32 lenRes;
- *backRes = repMaxIndex;
- lenRes = repLens[repMaxIndex];
- MovePos(p, lenRes - 1);
- return lenRes;
- }
-
- matches = p->matches;
- if (mainLen >= p->numFastBytes)
- {
- *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
- MovePos(p, mainLen - 1);
- return mainLen;
- }
- curByte = *data;
- matchByte = *(data - (reps[0] + 1));
-
- if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)
- {
- *backRes = (UInt32)-1;
- return 1;
- }
-
- p->opt[0].state = (CState)p->state;
-
- posState = (position & p->pbMask);
-
- {
- const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
- (!IsCharState(p->state) ?
- LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, curByte, p->ProbPrices));
- }
-
- MakeAsChar(&p->opt[1]);
-
- matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
- repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
-
- if (matchByte == curByte)
- {
- UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);
- if (shortRepPrice < p->opt[1].price)
- {
- p->opt[1].price = shortRepPrice;
- MakeAsShortRep(&p->opt[1]);
- }
- }
- lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);
-
- if (lenEnd < 2)
- {
- *backRes = p->opt[1].backPrev;
- return 1;
- }
-
- p->opt[1].posPrev = 0;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- p->opt[0].backs[i] = reps[i];
-
- len = lenEnd;
- do
- p->opt[len--].price = kInfinityPrice;
- while (len >= 2);
-
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 repLen = repLens[i];
- UInt32 price;
- if (repLen < 2)
- continue;
- price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState);
- do
- {
- UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];
- COptimal *opt = &p->opt[repLen];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = 0;
- opt->backPrev = i;
- opt->prev1IsChar = False;
- }
- }
- while (--repLen >= 2);
- }
-
- normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
-
- len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
- if (len <= mainLen)
- {
- UInt32 offs = 0;
- while (len > matches[offs])
- offs += 2;
- for (; ; len++)
- {
- COptimal *opt;
- UInt32 distance = matches[offs + 1];
-
- UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];
- UInt32 lenToPosState = GetLenToPosState(len);
- if (distance < kNumFullDistances)
- curAndLenPrice += p->distancesPrices[lenToPosState][distance];
- else
- {
- UInt32 slot;
- GetPosSlot2(distance, slot);
- curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];
- }
- opt = &p->opt[len];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = 0;
- opt->backPrev = distance + LZMA_NUM_REPS;
- opt->prev1IsChar = False;
- }
- if (len == matches[offs])
- {
- offs += 2;
- if (offs == numPairs)
- break;
- }
- }
- }
-
- cur = 0;
-
- #ifdef SHOW_STAT2
- if (position >= 0)
- {
- unsigned i;
- printf("\n pos = %4X", position);
- for (i = cur; i <= lenEnd; i++)
- printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price);
- }
- #endif
-
- for (;;)
- {
- UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
- UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
- Bool nextIsChar;
- Byte curByte, matchByte;
- const Byte *data;
- COptimal *curOpt;
- COptimal *nextOpt;
-
- cur++;
- if (cur == lenEnd)
- return Backward(p, backRes, cur);
-
- newLen = ReadMatchDistances(p, &numPairs);
- if (newLen >= p->numFastBytes)
- {
- p->numPairs = numPairs;
- p->longestMatchLength = newLen;
- return Backward(p, backRes, cur);
- }
- position++;
- curOpt = &p->opt[cur];
- posPrev = curOpt->posPrev;
- if (curOpt->prev1IsChar)
- {
- posPrev--;
- if (curOpt->prev2)
- {
- state = p->opt[curOpt->posPrev2].state;
- if (curOpt->backPrev2 < LZMA_NUM_REPS)
- state = kRepNextStates[state];
- else
- state = kMatchNextStates[state];
- }
- else
- state = p->opt[posPrev].state;
- state = kLiteralNextStates[state];
- }
- else
- state = p->opt[posPrev].state;
- if (posPrev == cur - 1)
- {
- if (IsShortRep(curOpt))
- state = kShortRepNextStates[state];
- else
- state = kLiteralNextStates[state];
- }
- else
- {
- UInt32 pos;
- const COptimal *prevOpt;
- if (curOpt->prev1IsChar && curOpt->prev2)
- {
- posPrev = curOpt->posPrev2;
- pos = curOpt->backPrev2;
- state = kRepNextStates[state];
- }
- else
- {
- pos = curOpt->backPrev;
- if (pos < LZMA_NUM_REPS)
- state = kRepNextStates[state];
- else
- state = kMatchNextStates[state];
- }
- prevOpt = &p->opt[posPrev];
- if (pos < LZMA_NUM_REPS)
- {
- UInt32 i;
- reps[0] = prevOpt->backs[pos];
- for (i = 1; i <= pos; i++)
- reps[i] = prevOpt->backs[i - 1];
- for (; i < LZMA_NUM_REPS; i++)
- reps[i] = prevOpt->backs[i];
- }
- else
- {
- UInt32 i;
- reps[0] = (pos - LZMA_NUM_REPS);
- for (i = 1; i < LZMA_NUM_REPS; i++)
- reps[i] = prevOpt->backs[i - 1];
- }
- }
- curOpt->state = (CState)state;
-
- curOpt->backs[0] = reps[0];
- curOpt->backs[1] = reps[1];
- curOpt->backs[2] = reps[2];
- curOpt->backs[3] = reps[3];
-
- curPrice = curOpt->price;
- nextIsChar = False;
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- curByte = *data;
- matchByte = *(data - (reps[0] + 1));
-
- posState = (position & p->pbMask);
-
- curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
- {
- const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- curAnd1Price +=
- (!IsCharState(state) ?
- LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, curByte, p->ProbPrices));
- }
-
- nextOpt = &p->opt[cur + 1];
-
- if (curAnd1Price < nextOpt->price)
- {
- nextOpt->price = curAnd1Price;
- nextOpt->posPrev = cur;
- MakeAsChar(nextOpt);
- nextIsChar = True;
- }
-
- matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
- repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
-
- if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
- {
- UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
- if (shortRepPrice <= nextOpt->price)
- {
- nextOpt->price = shortRepPrice;
- nextOpt->posPrev = cur;
- MakeAsShortRep(nextOpt);
- nextIsChar = True;
- }
- }
- numAvailFull = p->numAvail;
- {
- UInt32 temp = kNumOpts - 1 - cur;
- if (temp < numAvailFull)
- numAvailFull = temp;
- }
-
- if (numAvailFull < 2)
- continue;
- numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
-
- if (!nextIsChar && matchByte != curByte) /* speed optimization */
- {
- /* try Literal + rep0 */
- UInt32 temp;
- UInt32 lenTest2;
- const Byte *data2 = data - (reps[0] + 1);
- UInt32 limit = p->numFastBytes + 1;
- if (limit > numAvailFull)
- limit = numAvailFull;
-
- for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
- lenTest2 = temp - 1;
- if (lenTest2 >= 2)
- {
- UInt32 state2 = kLiteralNextStates[state];
- UInt32 posStateNext = (position + 1) & p->pbMask;
- UInt32 nextRepMatchPrice = curAnd1Price +
- GET_PRICE_1(p->isMatch[state2][posStateNext]) +
- GET_PRICE_1(p->isRep[state2]);
- /* for (; lenTest2 >= 2; lenTest2--) */
- {
- UInt32 curAndLenPrice;
- COptimal *opt;
- UInt32 offset = cur + 1 + lenTest2;
- while (lenEnd < offset)
- p->opt[++lenEnd].price = kInfinityPrice;
- curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
- opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur + 1;
- opt->backPrev = 0;
- opt->prev1IsChar = True;
- opt->prev2 = False;
- }
- }
- }
- }
-
- startLen = 2; /* speed optimization */
- {
- UInt32 repIndex;
- for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++)
- {
- UInt32 lenTest;
- UInt32 lenTestTemp;
- UInt32 price;
- const Byte *data2 = data - (reps[repIndex] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
- while (lenEnd < cur + lenTest)
- p->opt[++lenEnd].price = kInfinityPrice;
- lenTestTemp = lenTest;
- price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState);
- do
- {
- UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];
- COptimal *opt = &p->opt[cur + lenTest];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur;
- opt->backPrev = repIndex;
- opt->prev1IsChar = False;
- }
- }
- while (--lenTest >= 2);
- lenTest = lenTestTemp;
-
- if (repIndex == 0)
- startLen = lenTest + 1;
-
- /* if (_maxMode) */
- {
- UInt32 lenTest2 = lenTest + 1;
- UInt32 limit = lenTest2 + p->numFastBytes;
- UInt32 nextRepMatchPrice;
- if (limit > numAvailFull)
- limit = numAvailFull;
- for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
- lenTest2 -= lenTest + 1;
- if (lenTest2 >= 2)
- {
- UInt32 state2 = kRepNextStates[state];
- UInt32 posStateNext = (position + lenTest) & p->pbMask;
- UInt32 curAndLenCharPrice =
- price + p->repLenEnc.prices[posState][lenTest - 2] +
- GET_PRICE_0(p->isMatch[state2][posStateNext]) +
- LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
- data[lenTest], data2[lenTest], p->ProbPrices);
- state2 = kLiteralNextStates[state2];
- posStateNext = (position + lenTest + 1) & p->pbMask;
- nextRepMatchPrice = curAndLenCharPrice +
- GET_PRICE_1(p->isMatch[state2][posStateNext]) +
- GET_PRICE_1(p->isRep[state2]);
-
- /* for (; lenTest2 >= 2; lenTest2--) */
- {
- UInt32 curAndLenPrice;
- COptimal *opt;
- UInt32 offset = cur + lenTest + 1 + lenTest2;
- while (lenEnd < offset)
- p->opt[++lenEnd].price = kInfinityPrice;
- curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
- opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur + lenTest + 1;
- opt->backPrev = 0;
- opt->prev1IsChar = True;
- opt->prev2 = True;
- opt->posPrev2 = cur;
- opt->backPrev2 = repIndex;
- }
- }
- }
- }
- }
- }
- /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */
- if (newLen > numAvail)
- {
- newLen = numAvail;
- for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);
- matches[numPairs] = newLen;
- numPairs += 2;
- }
- if (newLen >= startLen)
- {
- UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
- UInt32 offs, curBack, posSlot;
- UInt32 lenTest;
- while (lenEnd < cur + newLen)
- p->opt[++lenEnd].price = kInfinityPrice;
-
- offs = 0;
- while (startLen > matches[offs])
- offs += 2;
- curBack = matches[offs + 1];
- GetPosSlot2(curBack, posSlot);
- for (lenTest = /*2*/ startLen; ; lenTest++)
- {
- UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN];
- UInt32 lenToPosState = GetLenToPosState(lenTest);
- COptimal *opt;
- if (curBack < kNumFullDistances)
- curAndLenPrice += p->distancesPrices[lenToPosState][curBack];
- else
- curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
-
- opt = &p->opt[cur + lenTest];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur;
- opt->backPrev = curBack + LZMA_NUM_REPS;
- opt->prev1IsChar = False;
- }
-
- if (/*_maxMode && */lenTest == matches[offs])
- {
- /* Try Match + Literal + Rep0 */
- const Byte *data2 = data - (curBack + 1);
- UInt32 lenTest2 = lenTest + 1;
- UInt32 limit = lenTest2 + p->numFastBytes;
- UInt32 nextRepMatchPrice;
- if (limit > numAvailFull)
- limit = numAvailFull;
- for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
- lenTest2 -= lenTest + 1;
- if (lenTest2 >= 2)
- {
- UInt32 state2 = kMatchNextStates[state];
- UInt32 posStateNext = (position + lenTest) & p->pbMask;
- UInt32 curAndLenCharPrice = curAndLenPrice +
- GET_PRICE_0(p->isMatch[state2][posStateNext]) +
- LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
- data[lenTest], data2[lenTest], p->ProbPrices);
- state2 = kLiteralNextStates[state2];
- posStateNext = (posStateNext + 1) & p->pbMask;
- nextRepMatchPrice = curAndLenCharPrice +
- GET_PRICE_1(p->isMatch[state2][posStateNext]) +
- GET_PRICE_1(p->isRep[state2]);
-
- /* for (; lenTest2 >= 2; lenTest2--) */
- {
- UInt32 offset = cur + lenTest + 1 + lenTest2;
- UInt32 curAndLenPrice;
- COptimal *opt;
- while (lenEnd < offset)
- p->opt[++lenEnd].price = kInfinityPrice;
- curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
- opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
- {
- opt->price = curAndLenPrice;
- opt->posPrev = cur + lenTest + 1;
- opt->backPrev = 0;
- opt->prev1IsChar = True;
- opt->prev2 = True;
- opt->posPrev2 = cur;
- opt->backPrev2 = curBack + LZMA_NUM_REPS;
- }
- }
- }
- offs += 2;
- if (offs == numPairs)
- break;
- curBack = matches[offs + 1];
- if (curBack >= kNumFullDistances)
- GetPosSlot2(curBack, posSlot);
- }
- }
- }
- }
-}
-
-#define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist))
-
-static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
-{
- UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;
- const Byte *data;
- const UInt32 *matches;
-
- if (p->additionalOffset == 0)
- mainLen = ReadMatchDistances(p, &numPairs);
- else
- {
- mainLen = p->longestMatchLength;
- numPairs = p->numPairs;
- }
-
- numAvail = p->numAvail;
- *backRes = (UInt32)-1;
- if (numAvail < 2)
- return 1;
- if (numAvail > LZMA_MATCH_LEN_MAX)
- numAvail = LZMA_MATCH_LEN_MAX;
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
-
- repLen = repIndex = 0;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 len;
- const Byte *data2 = data - (p->reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- for (len = 2; len < numAvail && data[len] == data2[len]; len++);
- if (len >= p->numFastBytes)
- {
- *backRes = i;
- MovePos(p, len - 1);
- return len;
- }
- if (len > repLen)
- {
- repIndex = i;
- repLen = len;
- }
- }
-
- matches = p->matches;
- if (mainLen >= p->numFastBytes)
- {
- *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
- MovePos(p, mainLen - 1);
- return mainLen;
- }
-
- mainDist = 0; /* for GCC */
- if (mainLen >= 2)
- {
- mainDist = matches[numPairs - 1];
- while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)
- {
- if (!ChangePair(matches[numPairs - 3], mainDist))
- break;
- numPairs -= 2;
- mainLen = matches[numPairs - 2];
- mainDist = matches[numPairs - 1];
- }
- if (mainLen == 2 && mainDist >= 0x80)
- mainLen = 1;
- }
-
- if (repLen >= 2 && (
- (repLen + 1 >= mainLen) ||
- (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||
- (repLen + 3 >= mainLen && mainDist >= (1 << 15))))
- {
- *backRes = repIndex;
- MovePos(p, repLen - 1);
- return repLen;
- }
-
- if (mainLen < 2 || numAvail <= 2)
- return 1;
-
- p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);
- if (p->longestMatchLength >= 2)
- {
- UInt32 newDistance = matches[p->numPairs - 1];
- if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||
- (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||
- (p->longestMatchLength > mainLen + 1) ||
- (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))
- return 1;
- }
-
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 len, limit;
- const Byte *data2 = data - (p->reps[i] + 1);
- if (data[0] != data2[0] || data[1] != data2[1])
- continue;
- limit = mainLen - 1;
- for (len = 2; len < limit && data[len] == data2[len]; len++);
- if (len >= limit)
- return 1;
- }
- *backRes = mainDist + LZMA_NUM_REPS;
- MovePos(p, mainLen - 2);
- return mainLen;
-}
-
-static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)
-{
- UInt32 len;
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
- p->state = kMatchNextStates[p->state];
- len = LZMA_MATCH_LEN_MIN;
- LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1);
- RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits);
- RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask);
-}
-
-static SRes CheckErrors(CLzmaEnc *p)
-{
- if (p->result != SZ_OK)
- return p->result;
- if (p->rc.res != SZ_OK)
- p->result = SZ_ERROR_WRITE;
- if (p->matchFinderBase.result != SZ_OK)
- p->result = SZ_ERROR_READ;
- if (p->result != SZ_OK)
- p->finished = True;
- return p->result;
-}
-
-static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
-{
- /* ReleaseMFStream(); */
- p->finished = True;
- if (p->writeEndMark)
- WriteEndMarker(p, nowPos & p->pbMask);
- RangeEnc_FlushData(&p->rc);
- RangeEnc_FlushStream(&p->rc);
- return CheckErrors(p);
-}
-
-static void FillAlignPrices(CLzmaEnc *p)
-{
- UInt32 i;
- for (i = 0; i < kAlignTableSize; i++)
- p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices);
- p->alignPriceCount = 0;
-}
-
-static void FillDistancesPrices(CLzmaEnc *p)
-{
- UInt32 tempPrices[kNumFullDistances];
- UInt32 i, lenToPosState;
- for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
- {
- UInt32 posSlot = GetPosSlot1(i);
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices);
- }
-
- for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
- {
- UInt32 posSlot;
- const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];
- UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];
- for (posSlot = 0; posSlot < p->distTableSize; posSlot++)
- posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);
- for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++)
- posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
-
- {
- UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
- UInt32 i;
- for (i = 0; i < kStartPosModelIndex; i++)
- distancesPrices[i] = posSlotPrices[i];
- for (; i < kNumFullDistances; i++)
- distancesPrices[i] = posSlotPrices[GetPosSlot1(i)] + tempPrices[i];
- }
- }
- p->matchPriceCount = 0;
-}
-
-void LzmaEnc_Construct(CLzmaEnc *p)
-{
- RangeEnc_Construct(&p->rc);
- MatchFinder_Construct(&p->matchFinderBase);
- #ifndef _7ZIP_ST
- MatchFinderMt_Construct(&p->matchFinderMt);
- p->matchFinderMt.MatchFinder = &p->matchFinderBase;
- #endif
-
- {
- CLzmaEncProps props;
- LzmaEncProps_Init(&props);
- LzmaEnc_SetProps(p, &props);
- }
-
- #ifndef LZMA_LOG_BSR
- LzmaEnc_FastPosInit(p->g_FastPos);
- #endif
-
- LzmaEnc_InitPriceTables(p->ProbPrices);
- p->litProbs = 0;
- p->saveState.litProbs = 0;
-}
-
-CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
-{
- void *p;
- p = alloc->Alloc(alloc, sizeof(CLzmaEnc));
- if (p != 0)
- LzmaEnc_Construct((CLzmaEnc *)p);
- return p;
-}
-
-void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->litProbs);
- alloc->Free(alloc, p->saveState.litProbs);
- p->litProbs = 0;
- p->saveState.litProbs = 0;
-}
-
-void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- #ifndef _7ZIP_ST
- MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
- #endif
- MatchFinder_Free(&p->matchFinderBase, allocBig);
- LzmaEnc_FreeLits(p, alloc);
- RangeEnc_Free(&p->rc, alloc);
-}
-
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig);
- alloc->Free(alloc, p);
-}
-
-static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize)
-{
- UInt32 nowPos32, startPos32;
- if (p->needInit)
- {
- p->matchFinder.Init(p->matchFinderObj);
- p->needInit = 0;
- }
-
- if (p->finished)
- return p->result;
- RINOK(CheckErrors(p));
-
- nowPos32 = (UInt32)p->nowPos64;
- startPos32 = nowPos32;
-
- if (p->nowPos64 == 0)
- {
- UInt32 numPairs;
- Byte curByte;
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- return Flush(p, nowPos32);
- ReadMatchDistances(p, &numPairs);
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
- p->state = kLiteralNextStates[p->state];
- curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);
- LitEnc_Encode(&p->rc, p->litProbs, curByte);
- p->additionalOffset--;
- nowPos32++;
- }
-
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0)
- for (;;)
- {
- UInt32 pos, len, posState;
-
- if (p->fastMode)
- len = GetOptimumFast(p, &pos);
- else
- len = GetOptimum(p, nowPos32, &pos);
-
- #ifdef SHOW_STAT2
- printf("\n pos = %4X, len = %d pos = %d", nowPos32, len, pos);
- #endif
-
- posState = nowPos32 & p->pbMask;
- if (len == 1 && pos == (UInt32)-1)
- {
- Byte curByte;
- CLzmaProb *probs;
- const Byte *data;
-
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0);
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
- curByte = *data;
- probs = LIT_PROBS(nowPos32, *(data - 1));
- if (IsCharState(p->state))
- LitEnc_Encode(&p->rc, probs, curByte);
- else
- LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1));
- p->state = kLiteralNextStates[p->state];
- }
- else
- {
- RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1);
- if (pos < LZMA_NUM_REPS)
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1);
- if (pos == 0)
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0);
- RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1));
- }
- else
- {
- UInt32 distance = p->reps[pos];
- RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1);
- if (pos == 1)
- RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0);
- else
- {
- RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1);
- RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2);
- if (pos == 3)
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- }
- p->reps[1] = p->reps[0];
- p->reps[0] = distance;
- }
- if (len == 1)
- p->state = kShortRepNextStates[p->state];
- else
- {
- LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- p->state = kRepNextStates[p->state];
- }
- }
- else
- {
- UInt32 posSlot;
- RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
- p->state = kMatchNextStates[p->state];
- LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
- pos -= LZMA_NUM_REPS;
- GetPosSlot(pos, posSlot);
- RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
-
- if (posSlot >= kStartPosModelIndex)
- {
- UInt32 footerBits = ((posSlot >> 1) - 1);
- UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- UInt32 posReduced = pos - base;
-
- if (posSlot < kEndPosModelIndex)
- RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced);
- else
- {
- RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits);
- RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask);
- p->alignPriceCount++;
- }
- }
- p->reps[3] = p->reps[2];
- p->reps[2] = p->reps[1];
- p->reps[1] = p->reps[0];
- p->reps[0] = pos;
- p->matchPriceCount++;
- }
- }
- p->additionalOffset -= len;
- nowPos32 += len;
- if (p->additionalOffset == 0)
- {
- UInt32 processed;
- if (!p->fastMode)
- {
- if (p->matchPriceCount >= (1 << 7))
- FillDistancesPrices(p);
- if (p->alignPriceCount >= kAlignTableSize)
- FillAlignPrices(p);
- }
- if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
- break;
- processed = nowPos32 - startPos32;
- if (useLimits)
- {
- if (processed + kNumOpts + 300 >= maxUnpackSize ||
- RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize)
- break;
- }
- else if (processed >= (1 << 15))
- {
- p->nowPos64 += nowPos32 - startPos32;
- return CheckErrors(p);
- }
- }
- }
- p->nowPos64 += nowPos32 - startPos32;
- return Flush(p, nowPos32);
-}
-
-#define kBigHashDicLimit ((UInt32)1 << 24)
-
-static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- UInt32 beforeSize = kNumOpts;
- if (!RangeEnc_Alloc(&p->rc, alloc))
- return SZ_ERROR_MEM;
- #ifndef _7ZIP_ST
- p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0));
- #endif
-
- {
- unsigned lclp = p->lc + p->lp;
- if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp)
- {
- LzmaEnc_FreeLits(p, alloc);
- p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
- p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb));
- if (p->litProbs == 0 || p->saveState.litProbs == 0)
- {
- LzmaEnc_FreeLits(p, alloc);
- return SZ_ERROR_MEM;
- }
- p->lclp = lclp;
- }
- }
-
- p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit);
-
- if (beforeSize + p->dictSize < keepWindowSize)
- beforeSize = keepWindowSize - p->dictSize;
-
- #ifndef _7ZIP_ST
- if (p->mtMode)
- {
- RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig));
- p->matchFinderObj = &p->matchFinderMt;
- MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder);
- }
- else
- #endif
- {
- if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_LEN_MAX, allocBig))
- return SZ_ERROR_MEM;
- p->matchFinderObj = &p->matchFinderBase;
- MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder);
- }
- return SZ_OK;
-}
-
-void LzmaEnc_Init(CLzmaEnc *p)
-{
- UInt32 i;
- p->state = 0;
- for (i = 0 ; i < LZMA_NUM_REPS; i++)
- p->reps[i] = 0;
-
- RangeEnc_Init(&p->rc);
-
-
- for (i = 0; i < kNumStates; i++)
- {
- UInt32 j;
- for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++)
- {
- p->isMatch[i][j] = kProbInitValue;
- p->isRep0Long[i][j] = kProbInitValue;
- }
- p->isRep[i] = kProbInitValue;
- p->isRepG0[i] = kProbInitValue;
- p->isRepG1[i] = kProbInitValue;
- p->isRepG2[i] = kProbInitValue;
- }
-
- {
- UInt32 num = 0x300 << (p->lp + p->lc);
- for (i = 0; i < num; i++)
- p->litProbs[i] = kProbInitValue;
- }
-
- {
- for (i = 0; i < kNumLenToPosStates; i++)
- {
- CLzmaProb *probs = p->posSlotEncoder[i];
- UInt32 j;
- for (j = 0; j < (1 << kNumPosSlotBits); j++)
- probs[j] = kProbInitValue;
- }
- }
- {
- for (i = 0; i < kNumFullDistances - kEndPosModelIndex; i++)
- p->posEncoders[i] = kProbInitValue;
- }
-
- LenEnc_Init(&p->lenEnc.p);
- LenEnc_Init(&p->repLenEnc.p);
-
- for (i = 0; i < (1 << kNumAlignBits); i++)
- p->posAlignEncoder[i] = kProbInitValue;
-
- p->optimumEndIndex = 0;
- p->optimumCurrentIndex = 0;
- p->additionalOffset = 0;
-
- p->pbMask = (1 << p->pb) - 1;
- p->lpMask = (1 << p->lp) - 1;
-}
-
-void LzmaEnc_InitPrices(CLzmaEnc *p)
-{
- if (!p->fastMode)
- {
- FillDistancesPrices(p);
- FillAlignPrices(p);
- }
-
- p->lenEnc.tableSize =
- p->repLenEnc.tableSize =
- p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
- LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
- LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
-}
-
-static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- UInt32 i;
- for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++)
- if (p->dictSize <= ((UInt32)1 << i))
- break;
- p->distTableSize = i * 2;
-
- p->finished = False;
- p->result = SZ_OK;
- RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig));
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- p->nowPos64 = 0;
- return SZ_OK;
-}
-
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
- ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- p->matchFinderBase.stream = inStream;
- p->needInit = 1;
- p->rc.outStream = outStream;
- return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
-}
-
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
- ISeqInStream *inStream, UInt32 keepWindowSize,
- ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- p->matchFinderBase.stream = inStream;
- p->needInit = 1;
- return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
-}
-
-static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
-{
- p->matchFinderBase.directInput = 1;
- p->matchFinderBase.bufferBase = (Byte *)src;
- p->matchFinderBase.directInputRem = srcLen;
-}
-
-SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
- UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- LzmaEnc_SetInputBuf(p, src, srcLen);
- p->needInit = 1;
-
- return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
-}
-
-void LzmaEnc_Finish(CLzmaEncHandle pp)
-{
- #ifndef _7ZIP_ST
- CLzmaEnc *p = (CLzmaEnc *)pp;
- if (p->mtMode)
- MatchFinderMt_ReleaseStream(&p->matchFinderMt);
- #else
- pp = pp;
- #endif
-}
-
-typedef struct
-{
- ISeqOutStream funcTable;
- Byte *data;
- SizeT rem;
- Bool overflow;
-} CSeqOutStreamBuf;
-
-static size_t MyWrite(void *pp, const void *data, size_t size)
-{
- CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp;
- if (p->rem < size)
- {
- size = p->rem;
- p->overflow = True;
- }
- memcpy(p->data, data, size);
- p->rem -= size;
- p->data += size;
- return size;
-}
-
-
-UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
-}
-
-const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
-{
- const CLzmaEnc *p = (CLzmaEnc *)pp;
- return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
-}
-
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
- Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- UInt64 nowPos64;
- SRes res;
- CSeqOutStreamBuf outStream;
-
- outStream.funcTable.Write = MyWrite;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = False;
-
- p->writeEndMark = False;
- p->finished = False;
- p->result = SZ_OK;
-
- if (reInit)
- LzmaEnc_Init(p);
- LzmaEnc_InitPrices(p);
- nowPos64 = p->nowPos64;
- RangeEnc_Init(&p->rc);
- p->rc.outStream = &outStream.funcTable;
-
- res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
-
- *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
- *destLen -= outStream.rem;
- if (outStream.overflow)
- return SZ_ERROR_OUTPUT_EOF;
-
- return res;
-}
-
-static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
-{
- SRes res = SZ_OK;
-
- #ifndef _7ZIP_ST
- Byte allocaDummy[0x300];
- allocaDummy[0] = 0;
- allocaDummy[1] = allocaDummy[0];
- #endif
-
- for (;;)
- {
- res = LzmaEnc_CodeOneBlock(p, False, 0, 0);
- if (res != SZ_OK || p->finished != 0)
- break;
- if (progress != 0)
- {
- res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc));
- if (res != SZ_OK)
- {
- res = SZ_ERROR_PROGRESS;
- break;
- }
- }
- }
- LzmaEnc_Finish(p);
- return res;
-}
-
-SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
- ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
- return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
-}
-
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
-{
- CLzmaEnc *p = (CLzmaEnc *)pp;
- int i;
- UInt32 dictSize = p->dictSize;
- if (*size < LZMA_PROPS_SIZE)
- return SZ_ERROR_PARAM;
- *size = LZMA_PROPS_SIZE;
- props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc);
-
- for (i = 11; i <= 30; i++)
- {
- if (dictSize <= ((UInt32)2 << i))
- {
- dictSize = (2 << i);
- break;
- }
- if (dictSize <= ((UInt32)3 << i))
- {
- dictSize = (3 << i);
- break;
- }
- }
-
- for (i = 0; i < 4; i++)
- props[1 + i] = (Byte)(dictSize >> (8 * i));
- return SZ_OK;
-}
-
-SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- SRes res;
- CLzmaEnc *p = (CLzmaEnc *)pp;
-
- CSeqOutStreamBuf outStream;
-
- LzmaEnc_SetInputBuf(p, src, srcLen);
-
- outStream.funcTable.Write = MyWrite;
- outStream.data = dest;
- outStream.rem = *destLen;
- outStream.overflow = False;
-
- p->writeEndMark = writeEndMark;
-
- p->rc.outStream = &outStream.funcTable;
- res = LzmaEnc_MemPrepare(pp, src, srcLen, 0, alloc, allocBig);
- if (res == SZ_OK)
- res = LzmaEnc_Encode2(p, progress);
-
- *destLen -= outStream.rem;
- if (outStream.overflow)
- return SZ_ERROR_OUTPUT_EOF;
- return res;
-}
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
-{
- CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
- SRes res;
- if (p == 0)
- return SZ_ERROR_MEM;
-
- res = LzmaEnc_SetProps(p, props);
- if (res == SZ_OK)
- {
- res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
- if (res == SZ_OK)
- res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
- writeEndMark, progress, alloc, allocBig);
- }
-
- LzmaEnc_Destroy(p, alloc, allocBig);
- return res;
-}
diff --git a/src/libs/7zip/win/C/LzmaEnc.h b/src/libs/7zip/win/C/LzmaEnc.h
deleted file mode 100644
index cffe220bb..000000000
--- a/src/libs/7zip/win/C/LzmaEnc.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* LzmaEnc.h -- LZMA Encoder
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __LZMA_ENC_H
-#define __LZMA_ENC_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define LZMA_PROPS_SIZE 5
-
-typedef struct _CLzmaEncProps
-{
- int level; /* 0 <= level <= 9 */
- UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
- (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
- default = (1 << 24) */
- UInt64 reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF.
- Encoder uses this value to reduce dictionary size */
- int lc; /* 0 <= lc <= 8, default = 3 */
- int lp; /* 0 <= lp <= 4, default = 0 */
- int pb; /* 0 <= pb <= 4, default = 2 */
- int algo; /* 0 - fast, 1 - normal, default = 1 */
- int fb; /* 5 <= fb <= 273, default = 32 */
- int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
- int numHashBytes; /* 2, 3 or 4, default = 4 */
- UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
- unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
- int numThreads; /* 1 or 2, default = 2 */
-} CLzmaEncProps;
-
-void LzmaEncProps_Init(CLzmaEncProps *p);
-void LzmaEncProps_Normalize(CLzmaEncProps *p);
-UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
-
-
-/* ---------- CLzmaEncHandle Interface ---------- */
-
-/* LzmaEnc_* functions can return the following exit codes:
-Returns:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater in props
- SZ_ERROR_WRITE - Write callback error.
- SZ_ERROR_PROGRESS - some break from progress callback
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-typedef void * CLzmaEncHandle;
-
-CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
-void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
-SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
-SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
-SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-
-/* ---------- One Call Interface ---------- */
-
-/* LzmaEncode
-Return code:
- SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_PARAM - Incorrect paramater
- SZ_ERROR_OUTPUT_EOF - output buffer overflow
- SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
-*/
-
-SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
- ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/MtCoder.c b/src/libs/7zip/win/C/MtCoder.c
deleted file mode 100644
index 3d4dd2d14..000000000
--- a/src/libs/7zip/win/C/MtCoder.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/* MtCoder.c -- Multi-thread Coder
-2010-09-24 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include <stdio.h>
-
-#include "MtCoder.h"
-
-void LoopThread_Construct(CLoopThread *p)
-{
- Thread_Construct(&p->thread);
- Event_Construct(&p->startEvent);
- Event_Construct(&p->finishedEvent);
-}
-
-void LoopThread_Close(CLoopThread *p)
-{
- Thread_Close(&p->thread);
- Event_Close(&p->startEvent);
- Event_Close(&p->finishedEvent);
-}
-
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE LoopThreadFunc(void *pp)
-{
- CLoopThread *p = (CLoopThread *)pp;
- for (;;)
- {
- if (Event_Wait(&p->startEvent) != 0)
- return SZ_ERROR_THREAD;
- if (p->stop)
- return 0;
- p->res = p->func(p->param);
- if (Event_Set(&p->finishedEvent) != 0)
- return SZ_ERROR_THREAD;
- }
-}
-
-WRes LoopThread_Create(CLoopThread *p)
-{
- p->stop = 0;
- RINOK(AutoResetEvent_CreateNotSignaled(&p->startEvent));
- RINOK(AutoResetEvent_CreateNotSignaled(&p->finishedEvent));
- return Thread_Create(&p->thread, LoopThreadFunc, p);
-}
-
-WRes LoopThread_StopAndWait(CLoopThread *p)
-{
- p->stop = 1;
- if (Event_Set(&p->startEvent) != 0)
- return SZ_ERROR_THREAD;
- return Thread_Wait(&p->thread);
-}
-
-WRes LoopThread_StartSubThread(CLoopThread *p) { return Event_Set(&p->startEvent); }
-WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEvent); }
-
-static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
-{
- return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
-}
-
-static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress)
-{
- unsigned i;
- for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
- p->inSizes[i] = p->outSizes[i] = 0;
- p->totalInSize = p->totalOutSize = 0;
- p->progress = progress;
- p->res = SZ_OK;
-}
-
-static void MtProgress_Reinit(CMtProgress *p, unsigned index)
-{
- p->inSizes[index] = 0;
- p->outSizes[index] = 0;
-}
-
-#define UPDATE_PROGRESS(size, prev, total) \
- if (size != (UInt64)(Int64)-1) { total += size - prev; prev = size; }
-
-SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize)
-{
- SRes res;
- CriticalSection_Enter(&p->cs);
- UPDATE_PROGRESS(inSize, p->inSizes[index], p->totalInSize)
- UPDATE_PROGRESS(outSize, p->outSizes[index], p->totalOutSize)
- if (p->res == SZ_OK)
- p->res = Progress(p->progress, p->totalInSize, p->totalOutSize);
- res = p->res;
- CriticalSection_Leave(&p->cs);
- return res;
-}
-
-static void MtProgress_SetError(CMtProgress *p, SRes res)
-{
- CriticalSection_Enter(&p->cs);
- if (p->res == SZ_OK)
- p->res = res;
- CriticalSection_Leave(&p->cs);
-}
-
-static void MtCoder_SetError(CMtCoder* p, SRes res)
-{
- CriticalSection_Enter(&p->cs);
- if (p->res == SZ_OK)
- p->res = res;
- CriticalSection_Leave(&p->cs);
-}
-
-/* ---------- MtThread ---------- */
-
-void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder)
-{
- p->mtCoder = mtCoder;
- p->outBuf = 0;
- p->inBuf = 0;
- Event_Construct(&p->canRead);
- Event_Construct(&p->canWrite);
- LoopThread_Construct(&p->thread);
-}
-
-#define RINOK_THREAD(x) { if((x) != 0) return SZ_ERROR_THREAD; }
-
-static void CMtThread_CloseEvents(CMtThread *p)
-{
- Event_Close(&p->canRead);
- Event_Close(&p->canWrite);
-}
-
-static void CMtThread_Destruct(CMtThread *p)
-{
- CMtThread_CloseEvents(p);
-
- if (Thread_WasCreated(&p->thread.thread))
- {
- LoopThread_StopAndWait(&p->thread);
- LoopThread_Close(&p->thread);
- }
-
- if (p->mtCoder->alloc)
- IAlloc_Free(p->mtCoder->alloc, p->outBuf);
- p->outBuf = 0;
-
- if (p->mtCoder->alloc)
- IAlloc_Free(p->mtCoder->alloc, p->inBuf);
- p->inBuf = 0;
-}
-
-#define MY_BUF_ALLOC(buf, size, newSize) \
- if (buf == 0 || size != newSize) \
- { IAlloc_Free(p->mtCoder->alloc, buf); \
- size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \
- if (buf == 0) return SZ_ERROR_MEM; }
-
-static SRes CMtThread_Prepare(CMtThread *p)
-{
- MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize)
- MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize)
-
- p->stopReading = False;
- p->stopWriting = False;
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead));
- RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite));
-
- return SZ_OK;
-}
-
-static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)
-{
- size_t size = *processedSize;
- *processedSize = 0;
- while (size != 0)
- {
- size_t curSize = size;
- SRes res = stream->Read(stream, data, &curSize);
- *processedSize += curSize;
- data += curSize;
- size -= curSize;
- RINOK(res);
- if (curSize == 0)
- return SZ_OK;
- }
- return SZ_OK;
-}
-
-#define GET_NEXT_THREAD(p) &p->mtCoder->threads[p->index == p->mtCoder->numThreads - 1 ? 0 : p->index + 1]
-
-static SRes MtThread_Process(CMtThread *p, Bool *stop)
-{
- CMtThread *next;
- *stop = True;
- if (Event_Wait(&p->canRead) != 0)
- return SZ_ERROR_THREAD;
-
- next = GET_NEXT_THREAD(p);
-
- if (p->stopReading)
- {
- next->stopReading = True;
- return Event_Set(&next->canRead) == 0 ? SZ_OK : SZ_ERROR_THREAD;
- }
-
- {
- size_t size = p->mtCoder->blockSize;
- size_t destSize = p->outBufSize;
-
- RINOK(FullRead(p->mtCoder->inStream, p->inBuf, &size));
- next->stopReading = *stop = (size != p->mtCoder->blockSize);
- if (Event_Set(&next->canRead) != 0)
- return SZ_ERROR_THREAD;
-
- RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index,
- p->outBuf, &destSize, p->inBuf, size, *stop));
-
- MtProgress_Reinit(&p->mtCoder->mtProgress, p->index);
-
- if (Event_Wait(&p->canWrite) != 0)
- return SZ_ERROR_THREAD;
- if (p->stopWriting)
- return SZ_ERROR_FAIL;
- if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize)
- return SZ_ERROR_WRITE;
- return Event_Set(&next->canWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD;
- }
-}
-
-static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE ThreadFunc(void *pp)
-{
- CMtThread *p = (CMtThread *)pp;
- for (;;)
- {
- Bool stop;
- CMtThread *next = GET_NEXT_THREAD(p);
- SRes res = MtThread_Process(p, &stop);
- if (res != SZ_OK)
- {
- MtCoder_SetError(p->mtCoder, res);
- MtProgress_SetError(&p->mtCoder->mtProgress, res);
- next->stopReading = True;
- next->stopWriting = True;
- Event_Set(&next->canRead);
- Event_Set(&next->canWrite);
- return res;
- }
- if (stop)
- return 0;
- }
-}
-
-void MtCoder_Construct(CMtCoder* p)
-{
- unsigned i;
- p->alloc = 0;
- for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
- {
- CMtThread *t = &p->threads[i];
- t->index = i;
- CMtThread_Construct(t, p);
- }
- CriticalSection_Init(&p->cs);
- CriticalSection_Init(&p->mtProgress.cs);
-}
-
-void MtCoder_Destruct(CMtCoder* p)
-{
- unsigned i;
- for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++)
- CMtThread_Destruct(&p->threads[i]);
- CriticalSection_Delete(&p->cs);
- CriticalSection_Delete(&p->mtProgress.cs);
-}
-
-SRes MtCoder_Code(CMtCoder *p)
-{
- unsigned i, numThreads = p->numThreads;
- SRes res = SZ_OK;
- p->res = SZ_OK;
-
- MtProgress_Init(&p->mtProgress, p->progress);
-
- for (i = 0; i < numThreads; i++)
- {
- RINOK(CMtThread_Prepare(&p->threads[i]));
- }
-
- for (i = 0; i < numThreads; i++)
- {
- CMtThread *t = &p->threads[i];
- CLoopThread *lt = &t->thread;
-
- if (!Thread_WasCreated(&lt->thread))
- {
- lt->func = ThreadFunc;
- lt->param = t;
-
- if (LoopThread_Create(lt) != SZ_OK)
- {
- res = SZ_ERROR_THREAD;
- break;
- }
- }
- }
-
- if (res == SZ_OK)
- {
- unsigned j;
- for (i = 0; i < numThreads; i++)
- {
- CMtThread *t = &p->threads[i];
- if (LoopThread_StartSubThread(&t->thread) != SZ_OK)
- {
- res = SZ_ERROR_THREAD;
- p->threads[0].stopReading = True;
- break;
- }
- }
-
- Event_Set(&p->threads[0].canWrite);
- Event_Set(&p->threads[0].canRead);
-
- for (j = 0; j < i; j++)
- LoopThread_WaitSubThread(&p->threads[j].thread);
- }
-
- for (i = 0; i < numThreads; i++)
- CMtThread_CloseEvents(&p->threads[i]);
- return (res == SZ_OK) ? p->res : res;
-}
diff --git a/src/libs/7zip/win/C/MtCoder.h b/src/libs/7zip/win/C/MtCoder.h
deleted file mode 100644
index e2cbdc3ab..000000000
--- a/src/libs/7zip/win/C/MtCoder.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* MtCoder.h -- Multi-thread Coder
-2009-11-19 : Igor Pavlov : Public domain */
-
-#ifndef __MT_CODER_H
-#define __MT_CODER_H
-
-#include "Threads.h"
-
-EXTERN_C_BEGIN
-
-typedef struct
-{
- CThread thread;
- CAutoResetEvent startEvent;
- CAutoResetEvent finishedEvent;
- int stop;
-
- THREAD_FUNC_TYPE func;
- LPVOID param;
- THREAD_FUNC_RET_TYPE res;
-} CLoopThread;
-
-void LoopThread_Construct(CLoopThread *p);
-void LoopThread_Close(CLoopThread *p);
-WRes LoopThread_Create(CLoopThread *p);
-WRes LoopThread_StopAndWait(CLoopThread *p);
-WRes LoopThread_StartSubThread(CLoopThread *p);
-WRes LoopThread_WaitSubThread(CLoopThread *p);
-
-#ifndef _7ZIP_ST
-#define NUM_MT_CODER_THREADS_MAX 32
-#else
-#define NUM_MT_CODER_THREADS_MAX 1
-#endif
-
-typedef struct
-{
- UInt64 totalInSize;
- UInt64 totalOutSize;
- ICompressProgress *progress;
- SRes res;
- CCriticalSection cs;
- UInt64 inSizes[NUM_MT_CODER_THREADS_MAX];
- UInt64 outSizes[NUM_MT_CODER_THREADS_MAX];
-} CMtProgress;
-
-SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize);
-
-struct _CMtCoder;
-
-typedef struct
-{
- struct _CMtCoder *mtCoder;
- Byte *outBuf;
- size_t outBufSize;
- Byte *inBuf;
- size_t inBufSize;
- unsigned index;
- CLoopThread thread;
-
- Bool stopReading;
- Bool stopWriting;
- CAutoResetEvent canRead;
- CAutoResetEvent canWrite;
-} CMtThread;
-
-typedef struct
-{
- SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize,
- const Byte *src, size_t srcSize, int finished);
-} IMtCoderCallback;
-
-typedef struct _CMtCoder
-{
- size_t blockSize;
- size_t destBlockSize;
- unsigned numThreads;
-
- ISeqInStream *inStream;
- ISeqOutStream *outStream;
- ICompressProgress *progress;
- ISzAlloc *alloc;
-
- IMtCoderCallback *mtCallback;
- CCriticalSection cs;
- SRes res;
-
- CMtProgress mtProgress;
- CMtThread threads[NUM_MT_CODER_THREADS_MAX];
-} CMtCoder;
-
-void MtCoder_Construct(CMtCoder* p);
-void MtCoder_Destruct(CMtCoder* p);
-SRes MtCoder_Code(CMtCoder *p);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Precomp.h b/src/libs/7zip/win/C/Precomp.h
deleted file mode 100644
index e8ff8b40e..000000000
--- a/src/libs/7zip/win/C/Precomp.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* Precomp.h -- StdAfx
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_PRECOMP_H
-#define __7Z_PRECOMP_H
-
-#include "Compiler.h"
-/* #include "7zTypes.h" */
-
-#endif
diff --git a/src/libs/7zip/win/C/RotateDefs.h b/src/libs/7zip/win/C/RotateDefs.h
deleted file mode 100644
index 1b83e5ea1..000000000
--- a/src/libs/7zip/win/C/RotateDefs.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* RotateDefs.h -- Rotate functions
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __ROTATE_DEFS_H
-#define __ROTATE_DEFS_H
-
-#ifdef _MSC_VER
-
-#include <stdlib.h>
-
-// #if (_MSC_VER >= 1200)
-#pragma intrinsic(_rotl)
-#pragma intrinsic(_rotr)
-// #endif
-
-#define rotlFixed(x, n) _rotl((x), (n))
-#define rotrFixed(x, n) _rotr((x), (n))
-
-#else
-
-#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
-#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
-
-#endif
-
-#endif
diff --git a/src/libs/7zip/win/C/Sha256.c b/src/libs/7zip/win/C/Sha256.c
deleted file mode 100644
index 10df0874f..000000000
--- a/src/libs/7zip/win/C/Sha256.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/* Crypto/Sha256.c -- SHA-256 Hash
-2010-06-11 : Igor Pavlov : Public domain
-This code is based on public domain code from Wei Dai's Crypto++ library. */
-
-#include "Precomp.h"
-
-#include "RotateDefs.h"
-#include "Sha256.h"
-
-/* define it for speed optimization */
-/* #define _SHA256_UNROLL */
-/* #define _SHA256_UNROLL2 */
-
-void Sha256_Init(CSha256 *p)
-{
- p->state[0] = 0x6a09e667;
- p->state[1] = 0xbb67ae85;
- p->state[2] = 0x3c6ef372;
- p->state[3] = 0xa54ff53a;
- p->state[4] = 0x510e527f;
- p->state[5] = 0x9b05688c;
- p->state[6] = 0x1f83d9ab;
- p->state[7] = 0x5be0cd19;
- p->count = 0;
-}
-
-#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22))
-#define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25))
-#define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3))
-#define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10))
-
-#define blk0(i) (W[i] = data[i])
-#define blk2(i) (W[i&15] += s1(W[(i-2)&15]) + W[(i-7)&15] + s0(W[(i-15)&15]))
-
-#define Ch(x,y,z) (z^(x&(y^z)))
-#define Maj(x,y,z) ((x&y)|(z&(x|y)))
-
-#define a(i) T[(0-(i))&7]
-#define b(i) T[(1-(i))&7]
-#define c(i) T[(2-(i))&7]
-#define d(i) T[(3-(i))&7]
-#define e(i) T[(4-(i))&7]
-#define f(i) T[(5-(i))&7]
-#define g(i) T[(6-(i))&7]
-#define h(i) T[(7-(i))&7]
-
-
-#ifdef _SHA256_UNROLL2
-
-#define R(a,b,c,d,e,f,g,h, i) h += S1(e) + Ch(e,f,g) + K[i+j] + (j?blk2(i):blk0(i));\
- d += h; h += S0(a) + Maj(a, b, c)
-
-#define RX_8(i) \
- R(a,b,c,d,e,f,g,h, i); \
- R(h,a,b,c,d,e,f,g, i+1); \
- R(g,h,a,b,c,d,e,f, i+2); \
- R(f,g,h,a,b,c,d,e, i+3); \
- R(e,f,g,h,a,b,c,d, i+4); \
- R(d,e,f,g,h,a,b,c, i+5); \
- R(c,d,e,f,g,h,a,b, i+6); \
- R(b,c,d,e,f,g,h,a, i+7)
-
-#else
-
-#define R(i) h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j?blk2(i):blk0(i));\
- d(i) += h(i); h(i) += S0(a(i)) + Maj(a(i), b(i), c(i))
-
-#ifdef _SHA256_UNROLL
-
-#define RX_8(i) R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7);
-
-#endif
-
-#endif
-
-static const UInt32 K[64] = {
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
- 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
- 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
- 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
- 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
-};
-
-static void Sha256_Transform(UInt32 *state, const UInt32 *data)
-{
- UInt32 W[16];
- unsigned j;
- #ifdef _SHA256_UNROLL2
- UInt32 a,b,c,d,e,f,g,h;
- a = state[0];
- b = state[1];
- c = state[2];
- d = state[3];
- e = state[4];
- f = state[5];
- g = state[6];
- h = state[7];
- #else
- UInt32 T[8];
- for (j = 0; j < 8; j++)
- T[j] = state[j];
- #endif
-
- for (j = 0; j < 64; j += 16)
- {
- #if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2)
- RX_8(0); RX_8(8);
- #else
- unsigned i;
- for (i = 0; i < 16; i++) { R(i); }
- #endif
- }
-
- #ifdef _SHA256_UNROLL2
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
- state[4] += e;
- state[5] += f;
- state[6] += g;
- state[7] += h;
- #else
- for (j = 0; j < 8; j++)
- state[j] += T[j];
- #endif
-
- /* Wipe variables */
- /* memset(W, 0, sizeof(W)); */
- /* memset(T, 0, sizeof(T)); */
-}
-
-#undef S0
-#undef S1
-#undef s0
-#undef s1
-
-static void Sha256_WriteByteBlock(CSha256 *p)
-{
- UInt32 data32[16];
- unsigned i;
- for (i = 0; i < 16; i++)
- data32[i] =
- ((UInt32)(p->buffer[i * 4 ]) << 24) +
- ((UInt32)(p->buffer[i * 4 + 1]) << 16) +
- ((UInt32)(p->buffer[i * 4 + 2]) << 8) +
- ((UInt32)(p->buffer[i * 4 + 3]));
- Sha256_Transform(p->state, data32);
-}
-
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size)
-{
- UInt32 curBufferPos = (UInt32)p->count & 0x3F;
- while (size > 0)
- {
- p->buffer[curBufferPos++] = *data++;
- p->count++;
- size--;
- if (curBufferPos == 64)
- {
- curBufferPos = 0;
- Sha256_WriteByteBlock(p);
- }
- }
-}
-
-void Sha256_Final(CSha256 *p, Byte *digest)
-{
- UInt64 lenInBits = (p->count << 3);
- UInt32 curBufferPos = (UInt32)p->count & 0x3F;
- unsigned i;
- p->buffer[curBufferPos++] = 0x80;
- while (curBufferPos != (64 - 8))
- {
- curBufferPos &= 0x3F;
- if (curBufferPos == 0)
- Sha256_WriteByteBlock(p);
- p->buffer[curBufferPos++] = 0;
- }
- for (i = 0; i < 8; i++)
- {
- p->buffer[curBufferPos++] = (Byte)(lenInBits >> 56);
- lenInBits <<= 8;
- }
- Sha256_WriteByteBlock(p);
-
- for (i = 0; i < 8; i++)
- {
- *digest++ = (Byte)(p->state[i] >> 24);
- *digest++ = (Byte)(p->state[i] >> 16);
- *digest++ = (Byte)(p->state[i] >> 8);
- *digest++ = (Byte)(p->state[i]);
- }
- Sha256_Init(p);
-}
diff --git a/src/libs/7zip/win/C/Sha256.h b/src/libs/7zip/win/C/Sha256.h
deleted file mode 100644
index 3f455dbc0..000000000
--- a/src/libs/7zip/win/C/Sha256.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Sha256.h -- SHA-256 Hash
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __CRYPTO_SHA256_H
-#define __CRYPTO_SHA256_H
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-#define SHA256_DIGEST_SIZE 32
-
-typedef struct
-{
- UInt32 state[8];
- UInt64 count;
- Byte buffer[64];
-} CSha256;
-
-void Sha256_Init(CSha256 *p);
-void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
-void Sha256_Final(CSha256 *p, Byte *digest);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Threads.c b/src/libs/7zip/win/C/Threads.c
deleted file mode 100644
index 5c67a1e26..000000000
--- a/src/libs/7zip/win/C/Threads.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Threads.c -- multithreading library
-2013-11-12 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#ifndef _WIN32_WCE
-#include <process.h>
-#endif
-
-#include "Threads.h"
-
-static WRes GetError()
-{
- DWORD res = GetLastError();
- return (res) ? (WRes)(res) : 1;
-}
-
-WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); }
-WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); }
-
-WRes HandlePtr_Close(HANDLE *p)
-{
- if (*p != NULL)
- if (!CloseHandle(*p))
- return GetError();
- *p = NULL;
- return 0;
-}
-
-WRes Handle_WaitObject(HANDLE h) { return (WRes)WaitForSingleObject(h, INFINITE); }
-
-WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param)
-{
- /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
-
- #ifdef UNDER_CE
-
- DWORD threadId;
- *p = CreateThread(0, 0, func, param, 0, &threadId);
-
- #else
-
- unsigned threadId;
- *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId);
-
- #endif
-
- /* maybe we must use errno here, but probably GetLastError() is also OK. */
- return HandleToWRes(*p);
-}
-
-WRes Event_Create(CEvent *p, BOOL manualReset, int signaled)
-{
- *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL);
- return HandleToWRes(*p);
-}
-
-WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(*p)); }
-WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(*p)); }
-
-WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled) { return Event_Create(p, TRUE, signaled); }
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Create(p, FALSE, signaled); }
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); }
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); }
-
-
-WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount)
-{
- *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL);
- return HandleToWRes(*p);
-}
-
-static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
- { return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); }
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num)
- { return Semaphore_Release(p, (LONG)num, NULL); }
-WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); }
-
-WRes CriticalSection_Init(CCriticalSection *p)
-{
- /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */
- #ifdef _MSC_VER
- __try
- #endif
- {
- InitializeCriticalSection(p);
- /* InitializeCriticalSectionAndSpinCount(p, 0); */
- }
- #ifdef _MSC_VER
- __except (EXCEPTION_EXECUTE_HANDLER) { return 1; }
- #endif
- return 0;
-}
diff --git a/src/libs/7zip/win/C/Threads.h b/src/libs/7zip/win/C/Threads.h
deleted file mode 100644
index 9b3e1c556..000000000
--- a/src/libs/7zip/win/C/Threads.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Threads.h -- multithreading library
-2013-11-12 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_THREADS_H
-#define __7Z_THREADS_H
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-WRes HandlePtr_Close(HANDLE *h);
-WRes Handle_WaitObject(HANDLE h);
-
-typedef HANDLE CThread;
-#define Thread_Construct(p) *(p) = NULL
-#define Thread_WasCreated(p) (*(p) != NULL)
-#define Thread_Close(p) HandlePtr_Close(p)
-#define Thread_Wait(p) Handle_WaitObject(*(p))
-
-typedef
-#ifdef UNDER_CE
- DWORD
-#else
- unsigned
-#endif
- THREAD_FUNC_RET_TYPE;
-
-#define THREAD_FUNC_CALL_TYPE MY_STD_CALL
-#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
-typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *);
-WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param);
-
-typedef HANDLE CEvent;
-typedef CEvent CAutoResetEvent;
-typedef CEvent CManualResetEvent;
-#define Event_Construct(p) *(p) = NULL
-#define Event_IsCreated(p) (*(p) != NULL)
-#define Event_Close(p) HandlePtr_Close(p)
-#define Event_Wait(p) Handle_WaitObject(*(p))
-WRes Event_Set(CEvent *p);
-WRes Event_Reset(CEvent *p);
-WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled);
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p);
-WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled);
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p);
-
-typedef HANDLE CSemaphore;
-#define Semaphore_Construct(p) (*p) = NULL
-#define Semaphore_Close(p) HandlePtr_Close(p)
-#define Semaphore_Wait(p) Handle_WaitObject(*(p))
-WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount);
-WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
-WRes Semaphore_Release1(CSemaphore *p);
-
-typedef CRITICAL_SECTION CCriticalSection;
-WRes CriticalSection_Init(CCriticalSection *p);
-#define CriticalSection_Delete(p) DeleteCriticalSection(p)
-#define CriticalSection_Enter(p) EnterCriticalSection(p)
-#define CriticalSection_Leave(p) LeaveCriticalSection(p)
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Xz.c b/src/libs/7zip/win/C/Xz.c
deleted file mode 100644
index fbc732a8a..000000000
--- a/src/libs/7zip/win/C/Xz.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* Xz.c - Xz
-2009-04-15 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "7zCrc.h"
-#include "CpuArch.h"
-#include "Xz.h"
-#include "XzCrc64.h"
-
-Byte XZ_SIG[XZ_SIG_SIZE] = { 0xFD, '7', 'z', 'X', 'Z', 0 };
-Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE] = { 'Y', 'Z' };
-
-unsigned Xz_WriteVarInt(Byte *buf, UInt64 v)
-{
- unsigned i = 0;
- do
- {
- buf[i++] = (Byte)((v & 0x7F) | 0x80);
- v >>= 7;
- }
- while (v != 0);
- buf[i - 1] &= 0x7F;
- return i;
-}
-
-void Xz_Construct(CXzStream *p)
-{
- p->numBlocks = p->numBlocksAllocated = 0;
- p->blocks = 0;
- p->flags = 0;
-}
-
-void Xz_Free(CXzStream *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->blocks);
- p->numBlocks = p->numBlocksAllocated = 0;
- p->blocks = 0;
-}
-
-unsigned XzFlags_GetCheckSize(CXzStreamFlags f)
-{
- int t = XzFlags_GetCheckType(f);
- return (t == 0) ? 0 : (4 << ((t - 1) / 3));
-}
-
-void XzCheck_Init(CXzCheck *p, int mode)
-{
- p->mode = mode;
- switch (mode)
- {
- case XZ_CHECK_CRC32: p->crc = CRC_INIT_VAL; break;
- case XZ_CHECK_CRC64: p->crc64 = CRC64_INIT_VAL; break;
- case XZ_CHECK_SHA256: Sha256_Init(&p->sha); break;
- }
-}
-
-void XzCheck_Update(CXzCheck *p, const void *data, size_t size)
-{
- switch (p->mode)
- {
- case XZ_CHECK_CRC32: p->crc = CrcUpdate(p->crc, data, size); break;
- case XZ_CHECK_CRC64: p->crc64 = Crc64Update(p->crc64, data, size); break;
- case XZ_CHECK_SHA256: Sha256_Update(&p->sha, (const Byte *)data, size); break;
- }
-}
-
-int XzCheck_Final(CXzCheck *p, Byte *digest)
-{
- switch (p->mode)
- {
- case XZ_CHECK_CRC32:
- SetUi32(digest, CRC_GET_DIGEST(p->crc));
- break;
- case XZ_CHECK_CRC64:
- {
- int i;
- UInt64 v = CRC64_GET_DIGEST(p->crc64);
- for (i = 0; i < 8; i++, v >>= 8)
- digest[i] = (Byte)(v & 0xFF);
- break;
- }
- case XZ_CHECK_SHA256:
- Sha256_Final(&p->sha, digest);
- break;
- default:
- return 0;
- }
- return 1;
-}
diff --git a/src/libs/7zip/win/C/Xz.h b/src/libs/7zip/win/C/Xz.h
deleted file mode 100644
index 9268d5bc6..000000000
--- a/src/libs/7zip/win/C/Xz.h
+++ /dev/null
@@ -1,275 +0,0 @@
-/* Xz.h - Xz interface
-2014-12-30 : Igor Pavlov : Public domain */
-
-#ifndef __XZ_H
-#define __XZ_H
-
-#include "Sha256.h"
-
-EXTERN_C_BEGIN
-
-#define XZ_ID_Subblock 1
-#define XZ_ID_Delta 3
-#define XZ_ID_X86 4
-#define XZ_ID_PPC 5
-#define XZ_ID_IA64 6
-#define XZ_ID_ARM 7
-#define XZ_ID_ARMT 8
-#define XZ_ID_SPARC 9
-#define XZ_ID_LZMA2 0x21
-
-unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value);
-unsigned Xz_WriteVarInt(Byte *buf, UInt64 v);
-
-/* ---------- xz block ---------- */
-
-#define XZ_BLOCK_HEADER_SIZE_MAX 1024
-
-#define XZ_NUM_FILTERS_MAX 4
-#define XZ_BF_NUM_FILTERS_MASK 3
-#define XZ_BF_PACK_SIZE (1 << 6)
-#define XZ_BF_UNPACK_SIZE (1 << 7)
-
-#define XZ_FILTER_PROPS_SIZE_MAX 20
-
-typedef struct
-{
- UInt64 id;
- UInt32 propsSize;
- Byte props[XZ_FILTER_PROPS_SIZE_MAX];
-} CXzFilter;
-
-typedef struct
-{
- UInt64 packSize;
- UInt64 unpackSize;
- Byte flags;
- CXzFilter filters[XZ_NUM_FILTERS_MAX];
-} CXzBlock;
-
-#define XzBlock_GetNumFilters(p) (((p)->flags & XZ_BF_NUM_FILTERS_MASK) + 1)
-#define XzBlock_HasPackSize(p) (((p)->flags & XZ_BF_PACK_SIZE) != 0)
-#define XzBlock_HasUnpackSize(p) (((p)->flags & XZ_BF_UNPACK_SIZE) != 0)
-
-SRes XzBlock_Parse(CXzBlock *p, const Byte *header);
-SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes);
-
-/* ---------- xz stream ---------- */
-
-#define XZ_SIG_SIZE 6
-#define XZ_FOOTER_SIG_SIZE 2
-
-extern Byte XZ_SIG[XZ_SIG_SIZE];
-extern Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE];
-
-#define XZ_STREAM_FLAGS_SIZE 2
-#define XZ_STREAM_CRC_SIZE 4
-
-#define XZ_STREAM_HEADER_SIZE (XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE)
-#define XZ_STREAM_FOOTER_SIZE (XZ_FOOTER_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE + 4)
-
-#define XZ_CHECK_MASK 0xF
-#define XZ_CHECK_NO 0
-#define XZ_CHECK_CRC32 1
-#define XZ_CHECK_CRC64 4
-#define XZ_CHECK_SHA256 10
-
-typedef struct
-{
- int mode;
- UInt32 crc;
- UInt64 crc64;
- CSha256 sha;
-} CXzCheck;
-
-void XzCheck_Init(CXzCheck *p, int mode);
-void XzCheck_Update(CXzCheck *p, const void *data, size_t size);
-int XzCheck_Final(CXzCheck *p, Byte *digest);
-
-typedef UInt16 CXzStreamFlags;
-
-#define XzFlags_IsSupported(f) ((f) <= XZ_CHECK_MASK)
-#define XzFlags_GetCheckType(f) ((f) & XZ_CHECK_MASK)
-#define XzFlags_HasDataCrc32(f) (Xz_GetCheckType(f) == XZ_CHECK_CRC32)
-unsigned XzFlags_GetCheckSize(CXzStreamFlags f);
-
-SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf);
-SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream);
-
-typedef struct
-{
- UInt64 unpackSize;
- UInt64 totalSize;
-} CXzBlockSizes;
-
-typedef struct
-{
- CXzStreamFlags flags;
- size_t numBlocks;
- size_t numBlocksAllocated;
- CXzBlockSizes *blocks;
- UInt64 startOffset;
-} CXzStream;
-
-void Xz_Construct(CXzStream *p);
-void Xz_Free(CXzStream *p, ISzAlloc *alloc);
-
-#define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1)
-
-UInt64 Xz_GetUnpackSize(const CXzStream *p);
-UInt64 Xz_GetPackSize(const CXzStream *p);
-
-typedef struct
-{
- size_t num;
- size_t numAllocated;
- CXzStream *streams;
-} CXzs;
-
-void Xzs_Construct(CXzs *p);
-void Xzs_Free(CXzs *p, ISzAlloc *alloc);
-SRes Xzs_ReadBackward(CXzs *p, ILookInStream *inStream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc);
-
-UInt64 Xzs_GetNumBlocks(const CXzs *p);
-UInt64 Xzs_GetUnpackSize(const CXzs *p);
-
-typedef enum
-{
- CODER_STATUS_NOT_SPECIFIED, /* use main error code instead */
- CODER_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
- CODER_STATUS_NOT_FINISHED, /* stream was not finished */
- CODER_STATUS_NEEDS_MORE_INPUT /* you must provide more input bytes */
-} ECoderStatus;
-
-typedef enum
-{
- CODER_FINISH_ANY, /* finish at any point */
- CODER_FINISH_END /* block must be finished at the end */
-} ECoderFinishMode;
-
-typedef struct _IStateCoder
-{
- void *p;
- void (*Free)(void *p, ISzAlloc *alloc);
- SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc);
- void (*Init)(void *p);
- SRes (*Code)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished);
-} IStateCoder;
-
-#define MIXCODER_NUM_FILTERS_MAX 4
-
-typedef struct
-{
- ISzAlloc *alloc;
- Byte *buf;
- int numCoders;
- int finished[MIXCODER_NUM_FILTERS_MAX - 1];
- size_t pos[MIXCODER_NUM_FILTERS_MAX - 1];
- size_t size[MIXCODER_NUM_FILTERS_MAX - 1];
- UInt64 ids[MIXCODER_NUM_FILTERS_MAX];
- IStateCoder coders[MIXCODER_NUM_FILTERS_MAX];
-} CMixCoder;
-
-void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc);
-void MixCoder_Free(CMixCoder *p);
-void MixCoder_Init(CMixCoder *p);
-SRes MixCoder_SetFromMethod(CMixCoder *p, int coderIndex, UInt64 methodId);
-SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, int srcWasFinished,
- ECoderFinishMode finishMode, ECoderStatus *status);
-
-typedef enum
-{
- XZ_STATE_STREAM_HEADER,
- XZ_STATE_STREAM_INDEX,
- XZ_STATE_STREAM_INDEX_CRC,
- XZ_STATE_STREAM_FOOTER,
- XZ_STATE_STREAM_PADDING,
- XZ_STATE_BLOCK_HEADER,
- XZ_STATE_BLOCK,
- XZ_STATE_BLOCK_FOOTER
-} EXzState;
-
-typedef struct
-{
- EXzState state;
- UInt32 pos;
- unsigned alignPos;
- unsigned indexPreSize;
-
- CXzStreamFlags streamFlags;
-
- UInt32 blockHeaderSize;
- UInt64 packSize;
- UInt64 unpackSize;
-
- UInt64 numBlocks;
- UInt64 indexSize;
- UInt64 indexPos;
- UInt64 padSize;
-
- UInt64 numStartedStreams;
- UInt64 numFinishedStreams;
- UInt64 numTotalBlocks;
-
- UInt32 crc;
- CMixCoder decoder;
- CXzBlock block;
- CXzCheck check;
- CSha256 sha;
- Byte shaDigest[SHA256_DIGEST_SIZE];
- Byte buf[XZ_BLOCK_HEADER_SIZE_MAX];
-} CXzUnpacker;
-
-void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc);
-void XzUnpacker_Init(CXzUnpacker *p);
-void XzUnpacker_Free(CXzUnpacker *p);
-
-/*
-finishMode:
- It has meaning only if the decoding reaches output limit (*destLen).
- CODER_FINISH_ANY - use smallest number of input bytes
- CODER_FINISH_END - read EndOfStream marker after decoding
-
-Returns:
- SZ_OK
- status:
- CODER_STATUS_NOT_FINISHED,
- CODER_STATUS_NEEDS_MORE_INPUT - maybe there are more xz streams,
- call XzUnpacker_IsStreamWasFinished to check that current stream was finished
- SZ_ERROR_MEM - Memory allocation error
- SZ_ERROR_DATA - Data error
- SZ_ERROR_UNSUPPORTED - Unsupported method or method properties
- SZ_ERROR_CRC - CRC error
- // SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
-
- SZ_ERROR_NO_ARCHIVE - the error with xz Stream Header with one of the following reasons:
- - xz Stream Signature failure
- - CRC32 of xz Stream Header is failed
- - The size of Stream padding is not multiple of four bytes.
- It's possible to get that error, if xz stream was finished and the stream
- contains some another data. In that case you can call XzUnpacker_GetExtraSize()
- function to get real size of xz stream.
-*/
-
-
-SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ECoderFinishMode finishMode,
- ECoderStatus *status);
-
-Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p);
-
-/*
-Call XzUnpacker_GetExtraSize after XzUnpacker_Code function to detect real size of
-xz stream in two cases:
-XzUnpacker_Code() returns:
- res == SZ_OK && status == CODER_STATUS_NEEDS_MORE_INPUT
- res == SZ_ERROR_NO_ARCHIVE
-*/
-
-UInt64 XzUnpacker_GetExtraSize(CXzUnpacker *p);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/XzCrc64.c b/src/libs/7zip/win/C/XzCrc64.c
deleted file mode 100644
index 2c04c0af4..000000000
--- a/src/libs/7zip/win/C/XzCrc64.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* XzCrc64.c -- CRC64 calculation
-2011-06-28 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "XzCrc64.h"
-#include "CpuArch.h"
-
-#define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)
-
-#ifdef MY_CPU_LE
- #define CRC_NUM_TABLES 4
-#else
- #define CRC_NUM_TABLES 5
- #define CRC_UINT64_SWAP(v) \
- ((v >> 56) | \
- ((v >> 40) & ((UInt64)0xFF << 8)) | \
- ((v >> 24) & ((UInt64)0xFF << 16)) | \
- ((v >> 8) & ((UInt64)0xFF << 24)) | \
- ((v << 8) & ((UInt64)0xFF << 32)) | \
- ((v << 24) & ((UInt64)0xFF << 40)) | \
- ((v << 40) & ((UInt64)0xFF << 48)) | \
- (v << 56))
- UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
-#endif
-
-#ifndef MY_CPU_BE
- UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table);
-#endif
-
-typedef UInt64 (MY_FAST_CALL *CRC_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table);
-
-static CRC_FUNC g_Crc64Update;
-UInt64 g_Crc64Table[256 * CRC_NUM_TABLES];
-
-UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size)
-{
- return g_Crc64Update(v, data, size, g_Crc64Table);
-}
-
-UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size)
-{
- return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL;
-}
-
-void MY_FAST_CALL Crc64GenerateTable()
-{
- UInt32 i;
- for (i = 0; i < 256; i++)
- {
- UInt64 r = i;
- unsigned j;
- for (j = 0; j < 8; j++)
- r = (r >> 1) ^ (kCrc64Poly & ~((r & 1) - 1));
- g_Crc64Table[i] = r;
- }
- for (; i < 256 * CRC_NUM_TABLES; i++)
- {
- UInt64 r = g_Crc64Table[i - 256];
- g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8);
- }
-
- #ifdef MY_CPU_LE
-
- g_Crc64Update = XzCrc64UpdateT4;
-
-
-
-
-
-
- #else
- {
- #ifndef MY_CPU_BE
- UInt32 k = 1;
- if (*(const Byte *)&k == 1)
- g_Crc64Update = XzCrc64UpdateT4;
- else
- #endif
- {
- for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
- {
- UInt64 x = g_Crc64Table[i - 256];
- g_Crc64Table[i] = CRC_UINT64_SWAP(x);
- }
- g_Crc64Update = XzCrc64UpdateT1_BeT4;
- }
- }
- #endif
-}
diff --git a/src/libs/7zip/win/C/XzCrc64.h b/src/libs/7zip/win/C/XzCrc64.h
deleted file mode 100644
index 08dbc330c..000000000
--- a/src/libs/7zip/win/C/XzCrc64.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* XzCrc64.h -- CRC64 calculation
-2013-01-18 : Igor Pavlov : Public domain */
-
-#ifndef __XZ_CRC64_H
-#define __XZ_CRC64_H
-
-#include <stddef.h>
-
-#include "7zTypes.h"
-
-EXTERN_C_BEGIN
-
-extern UInt64 g_Crc64Table[];
-
-void MY_FAST_CALL Crc64GenerateTable(void);
-
-#define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF)
-#define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL)
-#define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
-
-UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size);
-UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/XzCrc64Opt.c b/src/libs/7zip/win/C/XzCrc64Opt.c
deleted file mode 100644
index dccae1c19..000000000
--- a/src/libs/7zip/win/C/XzCrc64Opt.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* XzCrc64Opt.c -- CRC64 calculation
-2011-06-28 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include "CpuArch.h"
-
-#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
-
-#ifndef MY_CPU_BE
-
-UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- for (; size >= 4; size -= 4, p += 4)
- {
- UInt32 d = (UInt32)v ^ *(const UInt32 *)p;
- v = (v >> 32) ^
- table[0x300 + ((d ) & 0xFF)] ^
- table[0x200 + ((d >> 8) & 0xFF)] ^
- table[0x100 + ((d >> 16) & 0xFF)] ^
- table[0x000 + ((d >> 24))];
- }
- for (; size > 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- return v;
-}
-
-#endif
-
-
-#ifndef MY_CPU_LE
-
-#define CRC_UINT64_SWAP(v) \
- ((v >> 56) | \
- ((v >> 40) & ((UInt64)0xFF << 8)) | \
- ((v >> 24) & ((UInt64)0xFF << 16)) | \
- ((v >> 8) & ((UInt64)0xFF << 24)) | \
- ((v << 8) & ((UInt64)0xFF << 32)) | \
- ((v << 24) & ((UInt64)0xFF << 40)) | \
- ((v << 40) & ((UInt64)0xFF << 48)) | \
- (v << 56))
-
-UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- v = CRC_UINT64_SWAP(v);
- table += 0x100;
- for (; size >= 4; size -= 4, p += 4)
- {
- UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p;
- v = (v << 32) ^
- table[0x000 + ((d ) & 0xFF)] ^
- table[0x100 + ((d >> 8) & 0xFF)] ^
- table[0x200 + ((d >> 16) & 0xFF)] ^
- table[0x300 + ((d >> 24))];
- }
- table -= 0x100;
- v = CRC_UINT64_SWAP(v);
- for (; size > 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- return v;
-}
-
-#endif
diff --git a/src/libs/7zip/win/C/XzDec.c b/src/libs/7zip/win/C/XzDec.c
deleted file mode 100644
index 6eef587d3..000000000
--- a/src/libs/7zip/win/C/XzDec.c
+++ /dev/null
@@ -1,909 +0,0 @@
-/* XzDec.c -- Xz Decode
-2014-12-30 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-/* #define XZ_DUMP */
-
-#ifdef XZ_DUMP
-#include <stdio.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "7zCrc.h"
-#include "Alloc.h"
-#include "Bra.h"
-#include "CpuArch.h"
-#include "Delta.h"
-#include "Lzma2Dec.h"
-
-#ifdef USE_SUBBLOCK
-#include "Bcj3Dec.c"
-#include "SbDec.c"
-#endif
-
-#include "Xz.h"
-
-#define XZ_CHECK_SIZE_MAX 64
-
-#define CODER_BUF_SIZE (1 << 17)
-
-unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value)
-{
- int i, limit;
- *value = 0;
- limit = (maxSize > 9) ? 9 : (int)maxSize;
-
- for (i = 0; i < limit;)
- {
- Byte b = p[i];
- *value |= (UInt64)(b & 0x7F) << (7 * i++);
- if ((b & 0x80) == 0)
- return (b == 0 && i != 1) ? 0 : i;
- }
- return 0;
-}
-
-/* ---------- BraState ---------- */
-
-#define BRA_BUF_SIZE (1 << 14)
-
-typedef struct
-{
- size_t bufPos;
- size_t bufConv;
- size_t bufTotal;
-
- UInt32 methodId;
- int encodeMode;
- UInt32 delta;
- UInt32 ip;
- UInt32 x86State;
- Byte deltaState[DELTA_STATE_SIZE];
-
- Byte buf[BRA_BUF_SIZE];
-} CBraState;
-
-void BraState_Free(void *pp, ISzAlloc *alloc)
-{
- alloc->Free(alloc, pp);
-}
-
-SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
-{
- CBraState *p = ((CBraState *)pp);
- alloc = alloc;
- p->ip = 0;
- if (p->methodId == XZ_ID_Delta)
- {
- if (propSize != 1)
- return SZ_ERROR_UNSUPPORTED;
- p->delta = (unsigned)props[0] + 1;
- }
- else
- {
- if (propSize == 4)
- {
- UInt32 v = GetUi32(props);
- switch(p->methodId)
- {
- case XZ_ID_PPC:
- case XZ_ID_ARM:
- case XZ_ID_SPARC:
- if ((v & 3) != 0)
- return SZ_ERROR_UNSUPPORTED;
- break;
- case XZ_ID_ARMT:
- if ((v & 1) != 0)
- return SZ_ERROR_UNSUPPORTED;
- break;
- case XZ_ID_IA64:
- if ((v & 0xF) != 0)
- return SZ_ERROR_UNSUPPORTED;
- break;
- }
- p->ip = v;
- }
- else if (propSize != 0)
- return SZ_ERROR_UNSUPPORTED;
- }
- return SZ_OK;
-}
-
-void BraState_Init(void *pp)
-{
- CBraState *p = ((CBraState *)pp);
- p->bufPos = p->bufConv = p->bufTotal = 0;
- x86_Convert_Init(p->x86State);
- if (p->methodId == XZ_ID_Delta)
- Delta_Init(p->deltaState);
-}
-
-#define CASE_BRA_CONV(isa) case XZ_ID_ ## isa: p->bufConv = isa ## _Convert(p->buf, p->bufTotal, p->ip, p->encodeMode); break;
-
-static SRes BraState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
-{
- CBraState *p = ((CBraState *)pp);
- SizeT destLenOrig = *destLen;
- SizeT srcLenOrig = *srcLen;
- *destLen = 0;
- *srcLen = 0;
- finishMode = finishMode;
- *wasFinished = 0;
- while (destLenOrig > 0)
- {
- if (p->bufPos != p->bufConv)
- {
- size_t curSize = p->bufConv - p->bufPos;
- if (curSize > destLenOrig)
- curSize = destLenOrig;
- memcpy(dest, p->buf + p->bufPos, curSize);
- p->bufPos += curSize;
- *destLen += curSize;
- dest += curSize;
- destLenOrig -= curSize;
- continue;
- }
- p->bufTotal -= p->bufPos;
- memmove(p->buf, p->buf + p->bufPos, p->bufTotal);
- p->bufPos = 0;
- p->bufConv = 0;
- {
- size_t curSize = BRA_BUF_SIZE - p->bufTotal;
- if (curSize > srcLenOrig)
- curSize = srcLenOrig;
- memcpy(p->buf + p->bufTotal, src, curSize);
- *srcLen += curSize;
- src += curSize;
- srcLenOrig -= curSize;
- p->bufTotal += curSize;
- }
- if (p->bufTotal == 0)
- break;
- switch(p->methodId)
- {
- case XZ_ID_Delta:
- if (p->encodeMode)
- Delta_Encode(p->deltaState, p->delta, p->buf, p->bufTotal);
- else
- Delta_Decode(p->deltaState, p->delta, p->buf, p->bufTotal);
- p->bufConv = p->bufTotal;
- break;
- case XZ_ID_X86:
- p->bufConv = x86_Convert(p->buf, p->bufTotal, p->ip, &p->x86State, p->encodeMode);
- break;
- CASE_BRA_CONV(PPC)
- CASE_BRA_CONV(IA64)
- CASE_BRA_CONV(ARM)
- CASE_BRA_CONV(ARMT)
- CASE_BRA_CONV(SPARC)
- default:
- return SZ_ERROR_UNSUPPORTED;
- }
- p->ip += (UInt32)p->bufConv;
-
- if (p->bufConv == 0)
- {
- if (!srcWasFinished)
- break;
- p->bufConv = p->bufTotal;
- }
- }
- if (p->bufTotal == p->bufPos && srcLenOrig == 0 && srcWasFinished)
- *wasFinished = 1;
- return SZ_OK;
-}
-
-SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc)
-{
- CBraState *decoder;
- if (id != XZ_ID_Delta &&
- id != XZ_ID_X86 &&
- id != XZ_ID_PPC &&
- id != XZ_ID_IA64 &&
- id != XZ_ID_ARM &&
- id != XZ_ID_ARMT &&
- id != XZ_ID_SPARC)
- return SZ_ERROR_UNSUPPORTED;
- p->p = 0;
- decoder = (CBraState *)alloc->Alloc(alloc, sizeof(CBraState));
- if (decoder == 0)
- return SZ_ERROR_MEM;
- decoder->methodId = (UInt32)id;
- decoder->encodeMode = encodeMode;
- p->p = decoder;
- p->Free = BraState_Free;
- p->SetProps = BraState_SetProps;
- p->Init = BraState_Init;
- p->Code = BraState_Code;
- return SZ_OK;
-}
-
-/* ---------- SbState ---------- */
-
-#ifdef USE_SUBBLOCK
-
-static void SbState_Free(void *pp, ISzAlloc *alloc)
-{
- CSbDec *p = (CSbDec *)pp;
- SbDec_Free(p);
- alloc->Free(alloc, pp);
-}
-
-static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
-{
- pp = pp;
- props = props;
- alloc = alloc;
- return (propSize == 0) ? SZ_OK : SZ_ERROR_UNSUPPORTED;
-}
-
-static void SbState_Init(void *pp)
-{
- SbDec_Init((CSbDec *)pp);
-}
-
-static SRes SbState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
-{
- CSbDec *p = (CSbDec *)pp;
- SRes res;
- srcWasFinished = srcWasFinished;
- p->dest = dest;
- p->destLen = *destLen;
- p->src = src;
- p->srcLen = *srcLen;
- p->finish = finishMode; /* change it */
- res = SbDec_Decode((CSbDec *)pp);
- *destLen -= p->destLen;
- *srcLen -= p->srcLen;
- *wasFinished = (*destLen == 0 && *srcLen == 0); /* change it */
- return res;
-}
-
-SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
-{
- CSbDec *decoder;
- p->p = 0;
- decoder = alloc->Alloc(alloc, sizeof(CSbDec));
- if (decoder == 0)
- return SZ_ERROR_MEM;
- p->p = decoder;
- p->Free = SbState_Free;
- p->SetProps = SbState_SetProps;
- p->Init = SbState_Init;
- p->Code = SbState_Code;
- SbDec_Construct(decoder);
- SbDec_SetAlloc(decoder, alloc);
- return SZ_OK;
-}
-#endif
-
-/* ---------- Lzma2State ---------- */
-
-static void Lzma2State_Free(void *pp, ISzAlloc *alloc)
-{
- Lzma2Dec_Free((CLzma2Dec *)pp, alloc);
- alloc->Free(alloc, pp);
-}
-
-static SRes Lzma2State_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *alloc)
-{
- if (propSize != 1)
- return SZ_ERROR_UNSUPPORTED;
- return Lzma2Dec_Allocate((CLzma2Dec *)pp, props[0], alloc);
-}
-
-static void Lzma2State_Init(void *pp)
-{
- Lzma2Dec_Init((CLzma2Dec *)pp);
-}
-
-static SRes Lzma2State_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
-{
- ELzmaStatus status;
- /* ELzmaFinishMode fm = (finishMode == LZMA_FINISH_ANY) ? LZMA_FINISH_ANY : LZMA_FINISH_END; */
- SRes res = Lzma2Dec_DecodeToBuf((CLzma2Dec *)pp, dest, destLen, src, srcLen, (ELzmaFinishMode)finishMode, &status);
- srcWasFinished = srcWasFinished;
- *wasFinished = (status == LZMA_STATUS_FINISHED_WITH_MARK);
- return res;
-}
-
-static SRes Lzma2State_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
-{
- CLzma2Dec *decoder = (CLzma2Dec *)alloc->Alloc(alloc, sizeof(CLzma2Dec));
- p->p = decoder;
- if (decoder == 0)
- return SZ_ERROR_MEM;
- p->Free = Lzma2State_Free;
- p->SetProps = Lzma2State_SetProps;
- p->Init = Lzma2State_Init;
- p->Code = Lzma2State_Code;
- Lzma2Dec_Construct(decoder);
- return SZ_OK;
-}
-
-
-void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc)
-{
- int i;
- p->alloc = alloc;
- p->buf = 0;
- p->numCoders = 0;
- for (i = 0; i < MIXCODER_NUM_FILTERS_MAX; i++)
- p->coders[i].p = NULL;
-}
-
-void MixCoder_Free(CMixCoder *p)
-{
- int i;
- for (i = 0; i < p->numCoders; i++)
- {
- IStateCoder *sc = &p->coders[i];
- if (p->alloc && sc->p)
- sc->Free(sc->p, p->alloc);
- }
- p->numCoders = 0;
- if (p->buf)
- {
- p->alloc->Free(p->alloc, p->buf);
- p->buf = 0; /* 9.31: the BUG was fixed */
- }
-}
-
-void MixCoder_Init(CMixCoder *p)
-{
- int i;
- for (i = 0; i < p->numCoders - 1; i++)
- {
- p->size[i] = 0;
- p->pos[i] = 0;
- p->finished[i] = 0;
- }
- for (i = 0; i < p->numCoders; i++)
- {
- IStateCoder *coder = &p->coders[i];
- coder->Init(coder->p);
- }
-}
-
-SRes MixCoder_SetFromMethod(CMixCoder *p, int coderIndex, UInt64 methodId)
-{
- IStateCoder *sc = &p->coders[coderIndex];
- p->ids[coderIndex] = methodId;
- switch(methodId)
- {
- case XZ_ID_LZMA2: return Lzma2State_SetFromMethod(sc, p->alloc);
- #ifdef USE_SUBBLOCK
- case XZ_ID_Subblock: return SbState_SetFromMethod(sc, p->alloc);
- #endif
- }
- if (coderIndex == 0)
- return SZ_ERROR_UNSUPPORTED;
- return BraState_SetFromMethod(sc, methodId, 0, p->alloc);
-}
-
-SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, int srcWasFinished,
- ECoderFinishMode finishMode, ECoderStatus *status)
-{
- SizeT destLenOrig = *destLen;
- SizeT srcLenOrig = *srcLen;
- Bool allFinished = True;
- *destLen = 0;
- *srcLen = 0;
- *status = CODER_STATUS_NOT_FINISHED;
-
- if (p->buf == 0)
- {
- p->buf = (Byte *)p->alloc->Alloc(p->alloc, CODER_BUF_SIZE * (MIXCODER_NUM_FILTERS_MAX - 1));
- if (p->buf == 0)
- return SZ_ERROR_MEM;
- }
-
- if (p->numCoders != 1)
- finishMode = CODER_FINISH_ANY;
-
- for (;;)
- {
- Bool processed = False;
- int i;
- /*
- if (p->numCoders == 1 && *destLen == destLenOrig && finishMode == LZMA_FINISH_ANY)
- break;
- */
-
- for (i = 0; i < p->numCoders; i++)
- {
- SRes res;
- IStateCoder *coder = &p->coders[i];
- Byte *destCur;
- SizeT destLenCur, srcLenCur;
- const Byte *srcCur;
- int srcFinishedCur;
- int encodingWasFinished;
-
- if (i == 0)
- {
- srcCur = src;
- srcLenCur = srcLenOrig - *srcLen;
- srcFinishedCur = srcWasFinished;
- }
- else
- {
- srcCur = p->buf + (CODER_BUF_SIZE * (i - 1)) + p->pos[i - 1];
- srcLenCur = p->size[i - 1] - p->pos[i - 1];
- srcFinishedCur = p->finished[i - 1];
- }
-
- if (i == p->numCoders - 1)
- {
- destCur = dest;
- destLenCur = destLenOrig - *destLen;
- }
- else
- {
- if (p->pos[i] != p->size[i])
- continue;
- destCur = p->buf + (CODER_BUF_SIZE * i);
- destLenCur = CODER_BUF_SIZE;
- }
-
- res = coder->Code(coder->p, destCur, &destLenCur, srcCur, &srcLenCur, srcFinishedCur, finishMode, &encodingWasFinished);
-
- if (!encodingWasFinished)
- allFinished = False;
-
- if (i == 0)
- {
- *srcLen += srcLenCur;
- src += srcLenCur;
- }
- else
- {
- p->pos[i - 1] += srcLenCur;
- }
-
- if (i == p->numCoders - 1)
- {
- *destLen += destLenCur;
- dest += destLenCur;
- }
- else
- {
- p->size[i] = destLenCur;
- p->pos[i] = 0;
- p->finished[i] = encodingWasFinished;
- }
-
- if (res != SZ_OK)
- return res;
-
- if (destLenCur != 0 || srcLenCur != 0)
- processed = True;
- }
- if (!processed)
- break;
- }
- if (allFinished)
- *status = CODER_STATUS_FINISHED_WITH_MARK;
- return SZ_OK;
-}
-
-SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf)
-{
- *p = (CXzStreamFlags)GetBe16(buf + XZ_SIG_SIZE);
- if (CrcCalc(buf + XZ_SIG_SIZE, XZ_STREAM_FLAGS_SIZE) !=
- GetUi32(buf + XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE))
- return SZ_ERROR_NO_ARCHIVE;
- return XzFlags_IsSupported(*p) ? SZ_OK : SZ_ERROR_UNSUPPORTED;
-}
-
-static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf)
-{
- return
- indexSize == (((UInt64)GetUi32(buf + 4) + 1) << 2) &&
- (GetUi32(buf) == CrcCalc(buf + 4, 6) &&
- flags == GetBe16(buf + 8) &&
- memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) == 0);
-}
-
-#define READ_VARINT_AND_CHECK(buf, pos, size, res) \
- { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
- if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }
-
-
-SRes XzBlock_Parse(CXzBlock *p, const Byte *header)
-{
- unsigned pos;
- int numFilters, i;
- UInt32 headerSize = (UInt32)header[0] << 2;
-
- if (CrcCalc(header, headerSize) != GetUi32(header + headerSize))
- return SZ_ERROR_ARCHIVE;
-
- pos = 1;
- if (pos == headerSize)
- return SZ_ERROR_ARCHIVE;
- p->flags = header[pos++];
-
- if (XzBlock_HasPackSize(p))
- {
- READ_VARINT_AND_CHECK(header, pos, headerSize, &p->packSize);
- if (p->packSize == 0 || p->packSize + headerSize >= (UInt64)1 << 63)
- return SZ_ERROR_ARCHIVE;
- }
-
- if (XzBlock_HasUnpackSize(p))
- READ_VARINT_AND_CHECK(header, pos, headerSize, &p->unpackSize);
-
- numFilters = XzBlock_GetNumFilters(p);
- for (i = 0; i < numFilters; i++)
- {
- CXzFilter *filter = p->filters + i;
- UInt64 size;
- READ_VARINT_AND_CHECK(header, pos, headerSize, &filter->id);
- READ_VARINT_AND_CHECK(header, pos, headerSize, &size);
- if (size > headerSize - pos || size > XZ_FILTER_PROPS_SIZE_MAX)
- return SZ_ERROR_ARCHIVE;
- filter->propsSize = (UInt32)size;
- memcpy(filter->props, header + pos, (size_t)size);
- pos += (unsigned)size;
-
- #ifdef XZ_DUMP
- printf("\nf[%d] = %2X: ", i, filter->id);
- {
- int i;
- for (i = 0; i < size; i++)
- printf(" %2X", filter->props[i]);
- }
- #endif
- }
-
- while (pos < headerSize)
- if (header[pos++] != 0)
- return SZ_ERROR_ARCHIVE;
- return SZ_OK;
-}
-
-SRes XzDec_Init(CMixCoder *p, const CXzBlock *block)
-{
- int i;
- Bool needReInit = True;
- int numFilters = XzBlock_GetNumFilters(block);
- if (numFilters == p->numCoders)
- {
- for (i = 0; i < numFilters; i++)
- if (p->ids[i] != block->filters[numFilters - 1 - i].id)
- break;
- needReInit = (i != numFilters);
- }
- if (needReInit)
- {
- MixCoder_Free(p);
- p->numCoders = numFilters;
- for (i = 0; i < numFilters; i++)
- {
- const CXzFilter *f = &block->filters[numFilters - 1 - i];
- RINOK(MixCoder_SetFromMethod(p, i, f->id));
- }
- }
- for (i = 0; i < numFilters; i++)
- {
- const CXzFilter *f = &block->filters[numFilters - 1 - i];
- IStateCoder *sc = &p->coders[i];
- RINOK(sc->SetProps(sc->p, f->props, f->propsSize, p->alloc));
- }
- MixCoder_Init(p);
- return SZ_OK;
-}
-
-void XzUnpacker_Init(CXzUnpacker *p)
-{
- p->state = XZ_STATE_STREAM_HEADER;
- p->pos = 0;
- p->numStartedStreams = 0;
- p->numFinishedStreams = 0;
- p->numTotalBlocks = 0;
- p->padSize = 0;
-}
-
-void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc)
-{
- MixCoder_Construct(&p->decoder, alloc);
- XzUnpacker_Init(p);
-}
-
-void XzUnpacker_Free(CXzUnpacker *p)
-{
- MixCoder_Free(&p->decoder);
-}
-
-SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
- const Byte *src, SizeT *srcLen, ECoderFinishMode finishMode, ECoderStatus *status)
-{
- SizeT destLenOrig = *destLen;
- SizeT srcLenOrig = *srcLen;
- *destLen = 0;
- *srcLen = 0;
- *status = CODER_STATUS_NOT_SPECIFIED;
- for (;;)
- {
- SizeT srcRem = srcLenOrig - *srcLen;
-
- if (p->state == XZ_STATE_BLOCK)
- {
- SizeT destLen2 = destLenOrig - *destLen;
- SizeT srcLen2 = srcLenOrig - *srcLen;
- SRes res;
- if (srcLen2 == 0 && destLen2 == 0)
- {
- *status = CODER_STATUS_NOT_FINISHED;
- return SZ_OK;
- }
-
- res = MixCoder_Code(&p->decoder, dest, &destLen2, src, &srcLen2, False, finishMode, status);
- XzCheck_Update(&p->check, dest, destLen2);
-
- (*srcLen) += srcLen2;
- src += srcLen2;
- p->packSize += srcLen2;
-
- (*destLen) += destLen2;
- dest += destLen2;
- p->unpackSize += destLen2;
-
- RINOK(res);
-
- if (*status == CODER_STATUS_FINISHED_WITH_MARK)
- {
- Byte temp[32];
- unsigned num = Xz_WriteVarInt(temp, p->packSize + p->blockHeaderSize + XzFlags_GetCheckSize(p->streamFlags));
- num += Xz_WriteVarInt(temp + num, p->unpackSize);
- Sha256_Update(&p->sha, temp, num);
- p->indexSize += num;
- p->numBlocks++;
-
- p->state = XZ_STATE_BLOCK_FOOTER;
- p->pos = 0;
- p->alignPos = 0;
- }
- else if (srcLen2 == 0 && destLen2 == 0)
- return SZ_OK;
-
- continue;
- }
-
- if (srcRem == 0)
- {
- *status = CODER_STATUS_NEEDS_MORE_INPUT;
- return SZ_OK;
- }
-
- switch (p->state)
- {
- case XZ_STATE_STREAM_HEADER:
- {
- if (p->pos < XZ_STREAM_HEADER_SIZE)
- {
- if (p->pos < XZ_SIG_SIZE && *src != XZ_SIG[p->pos])
- return SZ_ERROR_NO_ARCHIVE;
- p->buf[p->pos++] = *src++;
- (*srcLen)++;
- }
- else
- {
- RINOK(Xz_ParseHeader(&p->streamFlags, p->buf));
- p->numStartedStreams++;
- p->state = XZ_STATE_BLOCK_HEADER;
- Sha256_Init(&p->sha);
- p->indexSize = 0;
- p->numBlocks = 0;
- p->pos = 0;
- }
- break;
- }
-
- case XZ_STATE_BLOCK_HEADER:
- {
- if (p->pos == 0)
- {
- p->buf[p->pos++] = *src++;
- (*srcLen)++;
- if (p->buf[0] == 0)
- {
- p->indexPreSize = 1 + Xz_WriteVarInt(p->buf + 1, p->numBlocks);
- p->indexPos = p->indexPreSize;
- p->indexSize += p->indexPreSize;
- Sha256_Final(&p->sha, p->shaDigest);
- Sha256_Init(&p->sha);
- p->crc = CrcUpdate(CRC_INIT_VAL, p->buf, p->indexPreSize);
- p->state = XZ_STATE_STREAM_INDEX;
- }
- p->blockHeaderSize = ((UInt32)p->buf[0] << 2) + 4;
- }
- else if (p->pos != p->blockHeaderSize)
- {
- UInt32 cur = p->blockHeaderSize - p->pos;
- if (cur > srcRem)
- cur = (UInt32)srcRem;
- memcpy(p->buf + p->pos, src, cur);
- p->pos += cur;
- (*srcLen) += cur;
- src += cur;
- }
- else
- {
- RINOK(XzBlock_Parse(&p->block, p->buf));
- p->numTotalBlocks++;
- p->state = XZ_STATE_BLOCK;
- p->packSize = 0;
- p->unpackSize = 0;
- XzCheck_Init(&p->check, XzFlags_GetCheckType(p->streamFlags));
- RINOK(XzDec_Init(&p->decoder, &p->block));
- }
- break;
- }
-
- case XZ_STATE_BLOCK_FOOTER:
- {
- if (((p->packSize + p->alignPos) & 3) != 0)
- {
- (*srcLen)++;
- p->alignPos++;
- if (*src++ != 0)
- return SZ_ERROR_CRC;
- }
- else
- {
- UInt32 checkSize = XzFlags_GetCheckSize(p->streamFlags);
- UInt32 cur = checkSize - p->pos;
- if (cur != 0)
- {
- if (cur > srcRem)
- cur = (UInt32)srcRem;
- memcpy(p->buf + p->pos, src, cur);
- p->pos += cur;
- (*srcLen) += cur;
- src += cur;
- }
- else
- {
- Byte digest[XZ_CHECK_SIZE_MAX];
- p->state = XZ_STATE_BLOCK_HEADER;
- p->pos = 0;
- if (XzCheck_Final(&p->check, digest) && memcmp(digest, p->buf, checkSize) != 0)
- return SZ_ERROR_CRC;
- }
- }
- break;
- }
-
- case XZ_STATE_STREAM_INDEX:
- {
- if (p->pos < p->indexPreSize)
- {
- (*srcLen)++;
- if (*src++ != p->buf[p->pos++])
- return SZ_ERROR_CRC;
- }
- else
- {
- if (p->indexPos < p->indexSize)
- {
- UInt64 cur = p->indexSize - p->indexPos;
- if (srcRem > cur)
- srcRem = (SizeT)cur;
- p->crc = CrcUpdate(p->crc, src, srcRem);
- Sha256_Update(&p->sha, src, srcRem);
- (*srcLen) += srcRem;
- src += srcRem;
- p->indexPos += srcRem;
- }
- else if ((p->indexPos & 3) != 0)
- {
- Byte b = *src++;
- p->crc = CRC_UPDATE_BYTE(p->crc, b);
- (*srcLen)++;
- p->indexPos++;
- p->indexSize++;
- if (b != 0)
- return SZ_ERROR_CRC;
- }
- else
- {
- Byte digest[SHA256_DIGEST_SIZE];
- p->state = XZ_STATE_STREAM_INDEX_CRC;
- p->indexSize += 4;
- p->pos = 0;
- Sha256_Final(&p->sha, digest);
- if (memcmp(digest, p->shaDigest, SHA256_DIGEST_SIZE) != 0)
- return SZ_ERROR_CRC;
- }
- }
- break;
- }
-
- case XZ_STATE_STREAM_INDEX_CRC:
- {
- if (p->pos < 4)
- {
- (*srcLen)++;
- p->buf[p->pos++] = *src++;
- }
- else
- {
- p->state = XZ_STATE_STREAM_FOOTER;
- p->pos = 0;
- if (CRC_GET_DIGEST(p->crc) != GetUi32(p->buf))
- return SZ_ERROR_CRC;
- }
- break;
- }
-
- case XZ_STATE_STREAM_FOOTER:
- {
- UInt32 cur = XZ_STREAM_FOOTER_SIZE - p->pos;
- if (cur > srcRem)
- cur = (UInt32)srcRem;
- memcpy(p->buf + p->pos, src, cur);
- p->pos += cur;
- (*srcLen) += cur;
- src += cur;
- if (p->pos == XZ_STREAM_FOOTER_SIZE)
- {
- p->state = XZ_STATE_STREAM_PADDING;
- p->numFinishedStreams++;
- p->padSize = 0;
- if (!Xz_CheckFooter(p->streamFlags, p->indexSize, p->buf))
- return SZ_ERROR_CRC;
- }
- break;
- }
-
- case XZ_STATE_STREAM_PADDING:
- {
- if (*src != 0)
- {
- if (((UInt32)p->padSize & 3) != 0)
- return SZ_ERROR_NO_ARCHIVE;
- p->pos = 0;
- p->state = XZ_STATE_STREAM_HEADER;
- }
- else
- {
- (*srcLen)++;
- src++;
- p->padSize++;
- }
- break;
- }
-
- case XZ_STATE_BLOCK: break; /* to disable GCC warning */
- }
- }
- /*
- if (p->state == XZ_STATE_FINISHED)
- *status = CODER_STATUS_FINISHED_WITH_MARK;
- return SZ_OK;
- */
-}
-
-Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p)
-{
- return (p->state == XZ_STATE_STREAM_PADDING) && (((UInt32)p->padSize & 3) == 0);
-}
-
-UInt64 XzUnpacker_GetExtraSize(CXzUnpacker *p)
-{
- UInt64 num = 0;
- if (p->state == XZ_STATE_STREAM_PADDING)
- num += p->padSize;
- else if (p->state == XZ_STATE_STREAM_HEADER)
- num += p->padSize + p->pos;
- return num;
-}
diff --git a/src/libs/7zip/win/C/XzEnc.c b/src/libs/7zip/win/C/XzEnc.c
deleted file mode 100644
index 56680fcd8..000000000
--- a/src/libs/7zip/win/C/XzEnc.c
+++ /dev/null
@@ -1,522 +0,0 @@
-/* XzEnc.c -- Xz Encode
-2014-12-30 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "7zCrc.h"
-#include "Alloc.h"
-#include "Bra.h"
-#include "CpuArch.h"
-#ifdef USE_SUBBLOCK
-#include "Bcj3Enc.c"
-#include "SbFind.c"
-#include "SbEnc.c"
-#endif
-
-#include "XzEnc.h"
-
-static void *SzBigAlloc(void *p, size_t size) { p = p; return BigAlloc(size); }
-static void SzBigFree(void *p, void *address) { p = p; BigFree(address); }
-static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
-
-static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
-static void SzFree(void *p, void *address) { p = p; MyFree(address); }
-static ISzAlloc g_Alloc = { SzAlloc, SzFree };
-
-#define XzBlock_ClearFlags(p) (p)->flags = 0;
-#define XzBlock_SetNumFilters(p, n) (p)->flags |= ((n) - 1);
-#define XzBlock_SetHasPackSize(p) (p)->flags |= XZ_BF_PACK_SIZE;
-#define XzBlock_SetHasUnpackSize(p) (p)->flags |= XZ_BF_UNPACK_SIZE;
-
-static SRes WriteBytes(ISeqOutStream *s, const void *buf, UInt32 size)
-{
- return (s->Write(s, buf, size) == size) ? SZ_OK : SZ_ERROR_WRITE;
-}
-
-static SRes WriteBytesAndCrc(ISeqOutStream *s, const void *buf, UInt32 size, UInt32 *crc)
-{
- *crc = CrcUpdate(*crc, buf, size);
- return WriteBytes(s, buf, size);
-}
-
-SRes Xz_WriteHeader(CXzStreamFlags f, ISeqOutStream *s)
-{
- UInt32 crc;
- Byte header[XZ_STREAM_HEADER_SIZE];
- memcpy(header, XZ_SIG, XZ_SIG_SIZE);
- header[XZ_SIG_SIZE] = (Byte)(f >> 8);
- header[XZ_SIG_SIZE + 1] = (Byte)(f & 0xFF);
- crc = CrcCalc(header + XZ_SIG_SIZE, XZ_STREAM_FLAGS_SIZE);
- SetUi32(header + XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE, crc);
- return WriteBytes(s, header, XZ_STREAM_HEADER_SIZE);
-}
-
-SRes XzBlock_WriteHeader(const CXzBlock *p, ISeqOutStream *s)
-{
- Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
-
- unsigned pos = 1;
- int numFilters, i;
- header[pos++] = p->flags;
-
- if (XzBlock_HasPackSize(p)) pos += Xz_WriteVarInt(header + pos, p->packSize);
- if (XzBlock_HasUnpackSize(p)) pos += Xz_WriteVarInt(header + pos, p->unpackSize);
- numFilters = XzBlock_GetNumFilters(p);
- for (i = 0; i < numFilters; i++)
- {
- const CXzFilter *f = &p->filters[i];
- pos += Xz_WriteVarInt(header + pos, f->id);
- pos += Xz_WriteVarInt(header + pos, f->propsSize);
- memcpy(header + pos, f->props, f->propsSize);
- pos += f->propsSize;
- }
- while((pos & 3) != 0)
- header[pos++] = 0;
- header[0] = (Byte)(pos >> 2);
- SetUi32(header + pos, CrcCalc(header, pos));
- return WriteBytes(s, header, pos + 4);
-}
-
-SRes Xz_WriteFooter(CXzStream *p, ISeqOutStream *s)
-{
- Byte buf[32];
- UInt64 globalPos;
- {
- UInt32 crc = CRC_INIT_VAL;
- unsigned pos = 1 + Xz_WriteVarInt(buf + 1, p->numBlocks);
- size_t i;
-
- globalPos = pos;
- buf[0] = 0;
- RINOK(WriteBytesAndCrc(s, buf, pos, &crc));
- for (i = 0; i < p->numBlocks; i++)
- {
- const CXzBlockSizes *block = &p->blocks[i];
- pos = Xz_WriteVarInt(buf, block->totalSize);
- pos += Xz_WriteVarInt(buf + pos, block->unpackSize);
- globalPos += pos;
- RINOK(WriteBytesAndCrc(s, buf, pos, &crc));
- }
- pos = ((unsigned)globalPos & 3);
- if (pos != 0)
- {
- buf[0] = buf[1] = buf[2] = 0;
- RINOK(WriteBytesAndCrc(s, buf, 4 - pos, &crc));
- globalPos += 4 - pos;
- }
- {
- SetUi32(buf, CRC_GET_DIGEST(crc));
- RINOK(WriteBytes(s, buf, 4));
- globalPos += 4;
- }
- }
-
- {
- UInt32 indexSize = (UInt32)((globalPos >> 2) - 1);
- SetUi32(buf + 4, indexSize);
- buf[8] = (Byte)(p->flags >> 8);
- buf[9] = (Byte)(p->flags & 0xFF);
- SetUi32(buf, CrcCalc(buf + 4, 6));
- memcpy(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE);
- return WriteBytes(s, buf, 12);
- }
-}
-
-SRes Xz_AddIndexRecord(CXzStream *p, UInt64 unpackSize, UInt64 totalSize, ISzAlloc *alloc)
-{
- if (p->blocks == 0 || p->numBlocksAllocated == p->numBlocks)
- {
- size_t num = (p->numBlocks + 1) * 2;
- size_t newSize = sizeof(CXzBlockSizes) * num;
- CXzBlockSizes *blocks;
- if (newSize / sizeof(CXzBlockSizes) != num)
- return SZ_ERROR_MEM;
- blocks = (CXzBlockSizes *)alloc->Alloc(alloc, newSize);
- if (blocks == 0)
- return SZ_ERROR_MEM;
- if (p->numBlocks != 0)
- {
- memcpy(blocks, p->blocks, p->numBlocks * sizeof(CXzBlockSizes));
- Xz_Free(p, alloc);
- }
- p->blocks = blocks;
- p->numBlocksAllocated = num;
- }
- {
- CXzBlockSizes *block = &p->blocks[p->numBlocks++];
- block->totalSize = totalSize;
- block->unpackSize = unpackSize;
- }
- return SZ_OK;
-}
-
-/* ---------- CSeqCheckInStream ---------- */
-
-typedef struct
-{
- ISeqInStream p;
- ISeqInStream *realStream;
- UInt64 processed;
- CXzCheck check;
-} CSeqCheckInStream;
-
-void SeqCheckInStream_Init(CSeqCheckInStream *p, int mode)
-{
- p->processed = 0;
- XzCheck_Init(&p->check, mode);
-}
-
-void SeqCheckInStream_GetDigest(CSeqCheckInStream *p, Byte *digest)
-{
- XzCheck_Final(&p->check, digest);
-}
-
-static SRes SeqCheckInStream_Read(void *pp, void *data, size_t *size)
-{
- CSeqCheckInStream *p = (CSeqCheckInStream *)pp;
- SRes res = p->realStream->Read(p->realStream, data, size);
- XzCheck_Update(&p->check, data, *size);
- p->processed += *size;
- return res;
-}
-
-/* ---------- CSeqSizeOutStream ---------- */
-
-typedef struct
-{
- ISeqOutStream p;
- ISeqOutStream *realStream;
- UInt64 processed;
-} CSeqSizeOutStream;
-
-static size_t MyWrite(void *pp, const void *data, size_t size)
-{
- CSeqSizeOutStream *p = (CSeqSizeOutStream *)pp;
- size = p->realStream->Write(p->realStream, data, size);
- p->processed += size;
- return size;
-}
-
-/* ---------- CSeqInFilter ---------- */
-
-#define FILTER_BUF_SIZE (1 << 20)
-
-typedef struct
-{
- ISeqInStream p;
- ISeqInStream *realStream;
- IStateCoder StateCoder;
- Byte *buf;
- size_t curPos;
- size_t endPos;
- int srcWasFinished;
-} CSeqInFilter;
-
-static SRes SeqInFilter_Read(void *pp, void *data, size_t *size)
-{
- CSeqInFilter *p = (CSeqInFilter *)pp;
- size_t sizeOriginal = *size;
- if (sizeOriginal == 0)
- return SZ_OK;
- *size = 0;
- for (;;)
- {
- if (!p->srcWasFinished && p->curPos == p->endPos)
- {
- p->curPos = 0;
- p->endPos = FILTER_BUF_SIZE;
- RINOK(p->realStream->Read(p->realStream, p->buf, &p->endPos));
- if (p->endPos == 0)
- p->srcWasFinished = 1;
- }
- {
- SizeT srcLen = p->endPos - p->curPos;
- int wasFinished;
- SRes res;
- *size = sizeOriginal;
- res = p->StateCoder.Code(p->StateCoder.p, data, size, p->buf + p->curPos, &srcLen,
- p->srcWasFinished, CODER_FINISH_ANY, &wasFinished);
- p->curPos += srcLen;
- if (*size != 0 || srcLen == 0 || res != 0)
- return res;
- }
- }
-}
-
-static void SeqInFilter_Construct(CSeqInFilter *p)
-{
- p->buf = NULL;
- p->p.Read = SeqInFilter_Read;
-}
-
-static void SeqInFilter_Free(CSeqInFilter *p)
-{
- if (p->buf)
- {
- g_Alloc.Free(&g_Alloc, p->buf);
- p->buf = NULL;
- }
-}
-
-SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc);
-
-static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props)
-{
- if (!p->buf)
- {
- p->buf = g_Alloc.Alloc(&g_Alloc, FILTER_BUF_SIZE);
- if (!p->buf)
- return SZ_ERROR_MEM;
- }
- p->curPos = p->endPos = 0;
- p->srcWasFinished = 0;
- RINOK(BraState_SetFromMethod(&p->StateCoder, props->id, 1, &g_Alloc));
- RINOK(p->StateCoder.SetProps(p->StateCoder.p, props->props, props->propsSize, &g_Alloc));
- p->StateCoder.Init(p->StateCoder.p);
- return SZ_OK;
-}
-
-/* ---------- CSbEncInStream ---------- */
-
-#ifdef USE_SUBBLOCK
-
-typedef struct
-{
- ISeqInStream p;
- ISeqInStream *inStream;
- CSbEnc enc;
-} CSbEncInStream;
-
-static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)
-{
- CSbEncInStream *p = (CSbEncInStream *)pp;
- size_t sizeOriginal = *size;
- if (sizeOriginal == 0)
- return S_OK;
- for (;;)
- {
- if (p->enc.needRead && !p->enc.readWasFinished)
- {
- size_t processed = p->enc.needReadSizeMax;
- RINOK(p->inStream->Read(p->inStream, p->enc.buf + p->enc.readPos, &processed));
- p->enc.readPos += processed;
- if (processed == 0)
- {
- p->enc.readWasFinished = True;
- p->enc.isFinalFinished = True;
- }
- p->enc.needRead = False;
- }
- *size = sizeOriginal;
- RINOK(SbEnc_Read(&p->enc, data, size));
- if (*size != 0 || !p->enc.needRead)
- return S_OK;
- }
-}
-
-void SbEncInStream_Construct(CSbEncInStream *p, ISzAlloc *alloc)
-{
- SbEnc_Construct(&p->enc, alloc);
- p->p.Read = SbEncInStream_Read;
-}
-
-SRes SbEncInStream_Init(CSbEncInStream *p)
-{
- return SbEnc_Init(&p->enc);
-}
-
-void SbEncInStream_Free(CSbEncInStream *p)
-{
- SbEnc_Free(&p->enc);
-}
-
-#endif
-
-
-typedef struct
-{
- CLzma2EncHandle lzma2;
- #ifdef USE_SUBBLOCK
- CSbEncInStream sb;
- #endif
- CSeqInFilter filter;
- ISzAlloc *alloc;
- ISzAlloc *bigAlloc;
-} CLzma2WithFilters;
-
-
-static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAlloc *alloc, ISzAlloc *bigAlloc)
-{
- p->alloc = alloc;
- p->bigAlloc = bigAlloc;
- p->lzma2 = NULL;
- #ifdef USE_SUBBLOCK
- SbEncInStream_Construct(&p->sb, alloc);
- #endif
- SeqInFilter_Construct(&p->filter);
-}
-
-static SRes Lzma2WithFilters_Create(CLzma2WithFilters *p)
-{
- p->lzma2 = Lzma2Enc_Create(p->alloc, p->bigAlloc);
- if (p->lzma2 == 0)
- return SZ_ERROR_MEM;
- return SZ_OK;
-}
-
-static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
-{
- SeqInFilter_Free(&p->filter);
- #ifdef USE_SUBBLOCK
- SbEncInStream_Free(&p->sb);
- #endif
- if (p->lzma2)
- {
- Lzma2Enc_Destroy(p->lzma2);
- p->lzma2 = NULL;
- }
-}
-
-void XzProps_Init(CXzProps *p)
-{
- p->lzma2Props = 0;
- p->filterProps = 0;
- p->checkId = XZ_CHECK_CRC32;
-}
-
-void XzFilterProps_Init(CXzFilterProps *p)
-{
- p->id = 0;
- p->delta = 0;
- p->ip= 0;
- p->ipDefined = False;
-}
-
-static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
- ISeqOutStream *outStream, ISeqInStream *inStream,
- const CXzProps *props, ICompressProgress *progress)
-{
- xz->flags = (Byte)props->checkId;
-
- RINOK(Lzma2Enc_SetProps(lzmaf->lzma2, props->lzma2Props));
- RINOK(Xz_WriteHeader(xz->flags, outStream));
-
- {
- CSeqCheckInStream checkInStream;
- CSeqSizeOutStream seqSizeOutStream;
- CXzBlock block;
- int filterIndex = 0;
- CXzFilter *filter = NULL;
- const CXzFilterProps *fp = props->filterProps;
-
- XzBlock_ClearFlags(&block);
- XzBlock_SetNumFilters(&block, 1 + (fp ? 1 : 0));
-
- if (fp)
- {
- filter = &block.filters[filterIndex++];
- filter->id = fp->id;
- filter->propsSize = 0;
- if (fp->id == XZ_ID_Delta)
- {
- filter->props[0] = (Byte)(fp->delta - 1);
- filter->propsSize = 1;
- }
- else if (fp->ipDefined)
- {
- SetUi32(filter->props, fp->ip);
- filter->propsSize = 4;
- }
- }
-
- {
- CXzFilter *f = &block.filters[filterIndex++];
- f->id = XZ_ID_LZMA2;
- f->propsSize = 1;
- f->props[0] = Lzma2Enc_WriteProperties(lzmaf->lzma2);
- }
-
- seqSizeOutStream.p.Write = MyWrite;
- seqSizeOutStream.realStream = outStream;
- seqSizeOutStream.processed = 0;
-
- RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.p));
-
- checkInStream.p.Read = SeqCheckInStream_Read;
- checkInStream.realStream = inStream;
- SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags));
-
- if (fp)
- {
- #ifdef USE_SUBBLOCK
- if (fp->id == XZ_ID_Subblock)
- {
- lzmaf->sb.inStream = &checkInStream.p;
- RINOK(SbEncInStream_Init(&lzmaf->sb));
- }
- else
- #endif
- {
- lzmaf->filter.realStream = &checkInStream.p;
- RINOK(SeqInFilter_Init(&lzmaf->filter, filter));
- }
- }
-
- {
- UInt64 packPos = seqSizeOutStream.processed;
- SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.p,
- fp ?
- #ifdef USE_SUBBLOCK
- (fp->id == XZ_ID_Subblock) ? &lzmaf->sb.p:
- #endif
- &lzmaf->filter.p:
- &checkInStream.p,
- progress);
- RINOK(res);
- block.unpackSize = checkInStream.processed;
- block.packSize = seqSizeOutStream.processed - packPos;
- }
-
- {
- unsigned padSize = 0;
- Byte buf[128];
- while((((unsigned)block.packSize + padSize) & 3) != 0)
- buf[padSize++] = 0;
- SeqCheckInStream_GetDigest(&checkInStream, buf + padSize);
- RINOK(WriteBytes(&seqSizeOutStream.p, buf, padSize + XzFlags_GetCheckSize(xz->flags)));
- RINOK(Xz_AddIndexRecord(xz, block.unpackSize, seqSizeOutStream.processed - padSize, &g_Alloc));
- }
- }
- return Xz_WriteFooter(xz, outStream);
-}
-
-SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
- const CXzProps *props, ICompressProgress *progress)
-{
- SRes res;
- CXzStream xz;
- CLzma2WithFilters lzmaf;
- Xz_Construct(&xz);
- Lzma2WithFilters_Construct(&lzmaf, &g_Alloc, &g_BigAlloc);
- res = Lzma2WithFilters_Create(&lzmaf);
- if (res == SZ_OK)
- res = Xz_Compress(&xz, &lzmaf, outStream, inStream, props, progress);
- Lzma2WithFilters_Free(&lzmaf);
- Xz_Free(&xz, &g_Alloc);
- return res;
-}
-
-SRes Xz_EncodeEmpty(ISeqOutStream *outStream)
-{
- SRes res;
- CXzStream xz;
- Xz_Construct(&xz);
- res = Xz_WriteHeader(xz.flags, outStream);
- if (res == SZ_OK)
- res = Xz_WriteFooter(&xz, outStream);
- Xz_Free(&xz, &g_Alloc);
- return res;
-}
diff --git a/src/libs/7zip/win/C/XzEnc.h b/src/libs/7zip/win/C/XzEnc.h
deleted file mode 100644
index c3c19eca0..000000000
--- a/src/libs/7zip/win/C/XzEnc.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* XzEnc.h -- Xz Encode
-2011-02-07 : Igor Pavlov : Public domain */
-
-#ifndef __XZ_ENC_H
-#define __XZ_ENC_H
-
-#include "Lzma2Enc.h"
-
-#include "Xz.h"
-
-EXTERN_C_BEGIN
-
-typedef struct
-{
- UInt32 id;
- UInt32 delta;
- UInt32 ip;
- int ipDefined;
-} CXzFilterProps;
-
-void XzFilterProps_Init(CXzFilterProps *p);
-
-typedef struct
-{
- const CLzma2EncProps *lzma2Props;
- const CXzFilterProps *filterProps;
- unsigned checkId;
-} CXzProps;
-
-void XzProps_Init(CXzProps *p);
-
-SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
- const CXzProps *props, ICompressProgress *progress);
-
-SRes Xz_EncodeEmpty(ISeqOutStream *outStream);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/XzIn.c b/src/libs/7zip/win/C/XzIn.c
deleted file mode 100644
index ed9eac31a..000000000
--- a/src/libs/7zip/win/C/XzIn.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/* XzIn.c - Xz input
-2014-12-30 : Igor Pavlov : Public domain */
-
-#include "Precomp.h"
-
-#include <string.h>
-
-#include "7zCrc.h"
-#include "CpuArch.h"
-#include "Xz.h"
-
-SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream)
-{
- Byte sig[XZ_STREAM_HEADER_SIZE];
- RINOK(SeqInStream_Read2(inStream, sig, XZ_STREAM_HEADER_SIZE, SZ_ERROR_NO_ARCHIVE));
- if (memcmp(sig, XZ_SIG, XZ_SIG_SIZE) != 0)
- return SZ_ERROR_NO_ARCHIVE;
- return Xz_ParseHeader(p, sig);
-}
-
-#define READ_VARINT_AND_CHECK(buf, pos, size, res) \
- { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
- if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }
-
-SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes)
-{
- Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
- unsigned headerSize;
- *headerSizeRes = 0;
- RINOK(SeqInStream_ReadByte(inStream, &header[0]));
- headerSize = ((unsigned)header[0] << 2) + 4;
- if (headerSize == 0)
- {
- *headerSizeRes = 1;
- *isIndex = True;
- return SZ_OK;
- }
-
- *isIndex = False;
- *headerSizeRes = headerSize;
- RINOK(SeqInStream_Read(inStream, header + 1, headerSize - 1));
- return XzBlock_Parse(p, header);
-}
-
-#define ADD_SIZE_CHECH(size, val) \
- { UInt64 newSize = size + (val); if (newSize < size) return XZ_SIZE_OVERFLOW; size = newSize; }
-
-UInt64 Xz_GetUnpackSize(const CXzStream *p)
-{
- UInt64 size = 0;
- size_t i;
- for (i = 0; i < p->numBlocks; i++)
- ADD_SIZE_CHECH(size, p->blocks[i].unpackSize);
- return size;
-}
-
-UInt64 Xz_GetPackSize(const CXzStream *p)
-{
- UInt64 size = 0;
- size_t i;
- for (i = 0; i < p->numBlocks; i++)
- ADD_SIZE_CHECH(size, (p->blocks[i].totalSize + 3) & ~(UInt64)3);
- return size;
-}
-
-/*
-SRes XzBlock_ReadFooter(CXzBlock *p, CXzStreamFlags f, ISeqInStream *inStream)
-{
- return SeqInStream_Read(inStream, p->check, XzFlags_GetCheckSize(f));
-}
-*/
-
-static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc *alloc)
-{
- size_t i, numBlocks, pos = 1;
- UInt32 crc;
-
- if (size < 5 || buf[0] != 0)
- return SZ_ERROR_ARCHIVE;
-
- size -= 4;
- crc = CrcCalc(buf, size);
- if (crc != GetUi32(buf + size))
- return SZ_ERROR_ARCHIVE;
-
- {
- UInt64 numBlocks64;
- READ_VARINT_AND_CHECK(buf, pos, size, &numBlocks64);
- numBlocks = (size_t)numBlocks64;
- if (numBlocks != numBlocks64 || numBlocks * 2 > size)
- return SZ_ERROR_ARCHIVE;
- }
-
- Xz_Free(p, alloc);
- if (numBlocks != 0)
- {
- p->numBlocks = numBlocks;
- p->numBlocksAllocated = numBlocks;
- p->blocks = alloc->Alloc(alloc, sizeof(CXzBlockSizes) * numBlocks);
- if (p->blocks == 0)
- return SZ_ERROR_MEM;
- for (i = 0; i < numBlocks; i++)
- {
- CXzBlockSizes *block = &p->blocks[i];
- READ_VARINT_AND_CHECK(buf, pos, size, &block->totalSize);
- READ_VARINT_AND_CHECK(buf, pos, size, &block->unpackSize);
- if (block->totalSize == 0)
- return SZ_ERROR_ARCHIVE;
- }
- }
- while ((pos & 3) != 0)
- if (buf[pos++] != 0)
- return SZ_ERROR_ARCHIVE;
- return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE;
-}
-
-static SRes Xz_ReadIndex(CXzStream *p, ILookInStream *stream, UInt64 indexSize, ISzAlloc *alloc)
-{
- SRes res;
- size_t size;
- Byte *buf;
- if (indexSize > ((UInt32)1 << 31))
- return SZ_ERROR_UNSUPPORTED;
- size = (size_t)indexSize;
- if (size != indexSize)
- return SZ_ERROR_UNSUPPORTED;
- buf = alloc->Alloc(alloc, size);
- if (buf == 0)
- return SZ_ERROR_MEM;
- res = LookInStream_Read2(stream, buf, size, SZ_ERROR_UNSUPPORTED);
- if (res == SZ_OK)
- res = Xz_ReadIndex2(p, buf, size, alloc);
- alloc->Free(alloc, buf);
- return res;
-}
-
-static SRes SeekFromCur(ILookInStream *inStream, Int64 *res)
-{
- return inStream->Seek(inStream, res, SZ_SEEK_CUR);
-}
-
-static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOffset, ISzAlloc *alloc)
-{
- UInt64 indexSize;
- Byte buf[XZ_STREAM_FOOTER_SIZE];
-
- if ((*startOffset & 3) != 0 || *startOffset < XZ_STREAM_FOOTER_SIZE)
- return SZ_ERROR_NO_ARCHIVE;
- *startOffset = -XZ_STREAM_FOOTER_SIZE;
- RINOK(SeekFromCur(stream, startOffset));
-
- RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
-
- if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
- {
- UInt32 total = 0;
- *startOffset += XZ_STREAM_FOOTER_SIZE;
- for (;;)
- {
- size_t i;
- #define TEMP_BUF_SIZE (1 << 10)
- Byte tempBuf[TEMP_BUF_SIZE];
- if (*startOffset < XZ_STREAM_FOOTER_SIZE || total > (1 << 16))
- return SZ_ERROR_NO_ARCHIVE;
- i = (*startOffset > TEMP_BUF_SIZE) ? TEMP_BUF_SIZE : (size_t)*startOffset;
- total += (UInt32)i;
- *startOffset = -(Int64)i;
- RINOK(SeekFromCur(stream, startOffset));
- RINOK(LookInStream_Read2(stream, tempBuf, i, SZ_ERROR_NO_ARCHIVE));
- for (; i != 0; i--)
- if (tempBuf[i - 1] != 0)
- break;
- if (i != 0)
- {
- if ((i & 3) != 0)
- return SZ_ERROR_NO_ARCHIVE;
- *startOffset += i;
- break;
- }
- }
- if (*startOffset < XZ_STREAM_FOOTER_SIZE)
- return SZ_ERROR_NO_ARCHIVE;
- *startOffset -= XZ_STREAM_FOOTER_SIZE;
- RINOK(stream->Seek(stream, startOffset, SZ_SEEK_SET));
- RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
- if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
- return SZ_ERROR_NO_ARCHIVE;
- }
-
- p->flags = (CXzStreamFlags)GetBe16(buf + 8);
-
- if (!XzFlags_IsSupported(p->flags))
- return SZ_ERROR_UNSUPPORTED;
-
- if (GetUi32(buf) != CrcCalc(buf + 4, 6))
- return SZ_ERROR_ARCHIVE;
-
- indexSize = ((UInt64)GetUi32(buf + 4) + 1) << 2;
-
- *startOffset = -(Int64)(indexSize + XZ_STREAM_FOOTER_SIZE);
- RINOK(SeekFromCur(stream, startOffset));
-
- RINOK(Xz_ReadIndex(p, stream, indexSize, alloc));
-
- {
- UInt64 totalSize = Xz_GetPackSize(p);
- UInt64 sum = XZ_STREAM_HEADER_SIZE + totalSize + indexSize;
- if (totalSize == XZ_SIZE_OVERFLOW ||
- sum >= ((UInt64)1 << 63) ||
- totalSize >= ((UInt64)1 << 63))
- return SZ_ERROR_ARCHIVE;
- *startOffset = -(Int64)sum;
- RINOK(SeekFromCur(stream, startOffset));
- }
- {
- CXzStreamFlags headerFlags;
- CSecToRead secToRead;
- SecToRead_CreateVTable(&secToRead);
- secToRead.realStream = stream;
-
- RINOK(Xz_ReadHeader(&headerFlags, &secToRead.s));
- return (p->flags == headerFlags) ? SZ_OK : SZ_ERROR_ARCHIVE;
- }
-}
-
-
-/* ---------- Xz Streams ---------- */
-
-void Xzs_Construct(CXzs *p)
-{
- p->num = p->numAllocated = 0;
- p->streams = 0;
-}
-
-void Xzs_Free(CXzs *p, ISzAlloc *alloc)
-{
- size_t i;
- for (i = 0; i < p->num; i++)
- Xz_Free(&p->streams[i], alloc);
- alloc->Free(alloc, p->streams);
- p->num = p->numAllocated = 0;
- p->streams = 0;
-}
-
-UInt64 Xzs_GetNumBlocks(const CXzs *p)
-{
- UInt64 num = 0;
- size_t i;
- for (i = 0; i < p->num; i++)
- num += p->streams[i].numBlocks;
- return num;
-}
-
-UInt64 Xzs_GetUnpackSize(const CXzs *p)
-{
- UInt64 size = 0;
- size_t i;
- for (i = 0; i < p->num; i++)
- ADD_SIZE_CHECH(size, Xz_GetUnpackSize(&p->streams[i]));
- return size;
-}
-
-/*
-UInt64 Xzs_GetPackSize(const CXzs *p)
-{
- UInt64 size = 0;
- size_t i;
- for (i = 0; i < p->num; i++)
- ADD_SIZE_CHECH(size, Xz_GetTotalSize(&p->streams[i]));
- return size;
-}
-*/
-
-SRes Xzs_ReadBackward(CXzs *p, ILookInStream *stream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc)
-{
- Int64 endOffset = 0;
- RINOK(stream->Seek(stream, &endOffset, SZ_SEEK_END));
- *startOffset = endOffset;
- for (;;)
- {
- CXzStream st;
- SRes res;
- Xz_Construct(&st);
- res = Xz_ReadBackward(&st, stream, startOffset, alloc);
- st.startOffset = *startOffset;
- RINOK(res);
- if (p->num == p->numAllocated)
- {
- size_t newNum = p->num + p->num / 4 + 1;
- Byte *data = (Byte *)alloc->Alloc(alloc, newNum * sizeof(CXzStream));
- if (data == 0)
- return SZ_ERROR_MEM;
- p->numAllocated = newNum;
- if (p->num != 0)
- memcpy(data, p->streams, p->num * sizeof(CXzStream));
- alloc->Free(alloc, p->streams);
- p->streams = (CXzStream *)data;
- }
- p->streams[p->num++] = st;
- if (*startOffset == 0)
- break;
- RINOK(stream->Seek(stream, startOffset, SZ_SEEK_SET));
- if (progress && progress->Progress(progress, endOffset - *startOffset, (UInt64)(Int64)-1) != SZ_OK)
- return SZ_ERROR_PROGRESS;
- }
- return SZ_OK;
-}
diff --git a/src/libs/7zip/win/CPP/7zip/7zip.pri b/src/libs/7zip/win/CPP/7zip/7zip.pri
deleted file mode 100644
index a2b70a1f2..000000000
--- a/src/libs/7zip/win/CPP/7zip/7zip.pri
+++ /dev/null
@@ -1,6 +0,0 @@
-HEADERS += $$7ZIP_BASE/CPP/7zip/ICoder.h \
- $$7ZIP_BASE/CPP/7zip/IDecl.h \
- $$7ZIP_BASE/CPP/7zip/IPassword.h \
- $$7ZIP_BASE/CPP/7zip/IProgress.h \
- $$7ZIP_BASE/CPP/7zip/IStream.h \
- $$7ZIP_BASE/CPP/7zip/PropID.h
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7z.pri b/src/libs/7zip/win/CPP/7zip/Archive/7z/7z.pri
deleted file mode 100644
index 7763cf705..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7z.pri
+++ /dev/null
@@ -1,30 +0,0 @@
-HEADERS += $$7ZIP_BASE/CPP/7zip/Archive/7z/7zCompressionMode.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zDecode.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zEncode.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zFolderInStream.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zFolderOutStream.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zHandler.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zHeader.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zIn.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zItem.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zOut.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zProperties.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zSpecStream.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zUpdate.h \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/StdAfx.h
-
-SOURCES += $$7ZIP_BASE/CPP/7zip/Archive/7z/7zDecode.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zEncode.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zExtract.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zFolderInStream.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zFolderOutStream.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zHandler.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zHandlerOut.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zHeader.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zIn.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zOut.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zProperties.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zRegister.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zSpecStream.cpp \
- $$7ZIP_BASE/CPP/7zip/Archive/7z/7zUpdate.cpp
-
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zCompressionMode.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zCompressionMode.h
deleted file mode 100644
index 5cde97c38..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zCompressionMode.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// 7zCompressionMode.h
-
-#ifndef __7Z_COMPRESSION_MODE_H
-#define __7Z_COMPRESSION_MODE_H
-
-#include "../../Common/MethodId.h"
-#include "../../Common/MethodProps.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CMethodFull: public CProps
-{
- CMethodId Id;
- UInt32 NumInStreams;
- UInt32 NumOutStreams;
-
- bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
-};
-
-struct CBind
-{
- UInt32 InCoder;
- UInt32 InStream;
- UInt32 OutCoder;
- UInt32 OutStream;
-};
-
-struct CCompressionMethodMode
-{
- CObjectVector<CMethodFull> Methods;
- CRecordVector<CBind> Binds;
- #ifndef _7ZIP_ST
- UInt32 NumThreads;
- #endif
- bool PasswordIsDefined;
- UString Password;
-
- bool IsEmpty() const { return (Methods.IsEmpty() && !PasswordIsDefined); }
- CCompressionMethodMode(): PasswordIsDefined(false)
- #ifndef _7ZIP_ST
- , NumThreads(1)
- #endif
- {}
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.cpp
deleted file mode 100644
index 973966bd3..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.cpp
+++ /dev/null
@@ -1,343 +0,0 @@
-// 7zDecode.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/LockedStream.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamObjects.h"
-
-#include "7zDecode.h"
-
-namespace NArchive {
-namespace N7z {
-
-static void ConvertFolderItemInfoToBindInfo(const CFolder &folder,
- CBindInfoEx &bindInfo)
-{
- bindInfo.Clear();
- bindInfo.BindPairs.ClearAndSetSize(folder.BindPairs.Size());
- unsigned i;
- for (i = 0; i < folder.BindPairs.Size(); i++)
- {
- NCoderMixer::CBindPair &bindPair = bindInfo.BindPairs[i];
- bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex;
- bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex;
- }
-
- bindInfo.Coders.ClearAndSetSize(folder.Coders.Size());
- bindInfo.CoderMethodIDs.ClearAndSetSize(folder.Coders.Size());
-
- UInt32 outStreamIndex = 0;
- for (i = 0; i < folder.Coders.Size(); i++)
- {
- NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];
- const CCoderInfo &coderInfo = folder.Coders[i];
- coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams;
- coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams;
- bindInfo.CoderMethodIDs[i] = coderInfo.MethodID;
- for (UInt32 j = 0; j < coderStreamsInfo.NumOutStreams; j++, outStreamIndex++)
- if (folder.FindBindPairForOutStream(outStreamIndex) < 0)
- bindInfo.OutStreams.Add(outStreamIndex);
- }
- bindInfo.InStreams.ClearAndSetSize(folder.PackStreams.Size());
- for (i = 0; i < folder.PackStreams.Size(); i++)
- bindInfo.InStreams[i] = (UInt32)folder.PackStreams[i];
-}
-
-static bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1,
- const NCoderMixer::CCoderStreamsInfo &a2)
-{
- return (a1.NumInStreams == a2.NumInStreams) &&
- (a1.NumOutStreams == a2.NumOutStreams);
-}
-
-static bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2)
-{
- return (a1.InIndex == a2.InIndex) &&
- (a1.OutIndex == a2.OutIndex);
-}
-
-static bool AreBindInfoExEqual(const CBindInfoEx &a1, const CBindInfoEx &a2)
-{
- if (a1.Coders.Size() != a2.Coders.Size())
- return false;
- unsigned i;
- for (i = 0; i < a1.Coders.Size(); i++)
- if (!AreCodersEqual(a1.Coders[i], a2.Coders[i]))
- return false;
- if (a1.BindPairs.Size() != a2.BindPairs.Size())
- return false;
- for (i = 0; i < a1.BindPairs.Size(); i++)
- if (!AreBindPairsEqual(a1.BindPairs[i], a2.BindPairs[i]))
- return false;
- for (i = 0; i < a1.CoderMethodIDs.Size(); i++)
- if (a1.CoderMethodIDs[i] != a2.CoderMethodIDs[i])
- return false;
- if (a1.InStreams.Size() != a2.InStreams.Size())
- return false;
- if (a1.OutStreams.Size() != a2.OutStreams.Size())
- return false;
- return true;
-}
-
-CDecoder::CDecoder(bool multiThread)
-{
- #ifndef _ST_MODE
- multiThread = true;
- #endif
- _multiThread = multiThread;
- _bindInfoExPrevIsDefined = false;
-}
-
-HRESULT CDecoder::Decode(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream,
- UInt64 startPos,
- const CFolders &folders, int folderIndex,
- ISequentialOutStream *outStream,
- ICompressProgressInfo *compressProgress
- _7Z_DECODER_CRYPRO_VARS_DECL
- #if !defined(_7ZIP_ST) && !defined(_SFX)
- , bool mtMode, UInt32 numThreads
- #endif
- )
-{
- const UInt64 *packPositions = &folders.PackPositions[folders.FoStartPackStreamIndex[folderIndex]];
- CFolder folderInfo;
- folders.ParseFolderInfo(folderIndex, folderInfo);
-
- if (!folderInfo.CheckStructure(folders.GetNumFolderUnpackSizes(folderIndex)))
- return E_NOTIMPL;
-
- /*
- We don't need to init isEncrypted and passwordIsDefined
- We must upgrade them only
- #ifndef _NO_CRYPTO
- isEncrypted = false;
- passwordIsDefined = false;
- #endif
- */
-
- CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;
-
- CLockedInStream lockedInStream;
- lockedInStream.Init(inStream);
-
- for (unsigned j = 0; j < folderInfo.PackStreams.Size(); j++)
- {
- CLockedSequentialInStreamImp *lockedStreamImpSpec = new CLockedSequentialInStreamImp;
- CMyComPtr<ISequentialInStream> lockedStreamImp = lockedStreamImpSpec;
- lockedStreamImpSpec->Init(&lockedInStream, startPos + packPositions[j]);
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream = streamSpec;
- streamSpec->SetStream(lockedStreamImp);
- streamSpec->Init(packPositions[j + 1] - packPositions[j]);
- inStreams.Add(inStream);
- }
-
- unsigned numCoders = folderInfo.Coders.Size();
-
- CBindInfoEx bindInfo;
- ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo);
- bool createNewCoders;
- if (!_bindInfoExPrevIsDefined)
- createNewCoders = true;
- else
- createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev);
- if (createNewCoders)
- {
- unsigned i;
- _decoders.Clear();
- // _decoders2.Clear();
-
- _mixerCoder.Release();
-
- if (_multiThread)
- {
- _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT;
- _mixerCoder = _mixerCoderMTSpec;
- _mixerCoderCommon = _mixerCoderMTSpec;
- }
- else
- {
- #ifdef _ST_MODE
- _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST;
- _mixerCoder = _mixerCoderSTSpec;
- _mixerCoderCommon = _mixerCoderSTSpec;
- #endif
- }
- RINOK(_mixerCoderCommon->SetBindInfo(bindInfo));
-
- for (i = 0; i < numCoders; i++)
- {
- const CCoderInfo &coderInfo = folderInfo.Coders[i];
-
-
- CMyComPtr<ICompressCoder> decoder;
- CMyComPtr<ICompressCoder2> decoder2;
- RINOK(CreateCoder(
- EXTERNAL_CODECS_LOC_VARS
- coderInfo.MethodID, decoder, decoder2, false));
- CMyComPtr<IUnknown> decoderUnknown;
- if (coderInfo.IsSimpleCoder())
- {
- if (decoder == 0)
- return E_NOTIMPL;
-
- decoderUnknown = (IUnknown *)decoder;
-
- if (_multiThread)
- _mixerCoderMTSpec->AddCoder(decoder);
- #ifdef _ST_MODE
- else
- _mixerCoderSTSpec->AddCoder(decoder, false);
- #endif
- }
- else
- {
- if (decoder2 == 0)
- return E_NOTIMPL;
- decoderUnknown = (IUnknown *)decoder2;
- if (_multiThread)
- _mixerCoderMTSpec->AddCoder2(decoder2);
- #ifdef _ST_MODE
- else
- _mixerCoderSTSpec->AddCoder2(decoder2, false);
- #endif
- }
- _decoders.Add(decoderUnknown);
- #ifdef EXTERNAL_CODECS
- CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
- decoderUnknown.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
- if (setCompressCodecsInfo)
- {
- RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(__externalCodecs->GetCodecs));
- }
- #endif
- }
- _bindInfoExPrev = bindInfo;
- _bindInfoExPrevIsDefined = true;
- }
- unsigned i;
- _mixerCoderCommon->ReInit();
-
- UInt32 packStreamIndex = 0;
- UInt32 unpackStreamIndexStart = folders.FoToCoderUnpackSizes[folderIndex];
- UInt32 unpackStreamIndex = unpackStreamIndexStart;
- UInt32 coderIndex = 0;
- // UInt32 coder2Index = 0;
-
- for (i = 0; i < numCoders; i++)
- {
- const CCoderInfo &coderInfo = folderInfo.Coders[i];
- CMyComPtr<IUnknown> &decoder = _decoders[coderIndex];
-
- {
- CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
- decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
- if (setDecoderProperties)
- {
- const CByteBuffer &props = coderInfo.Props;
- size_t size = props.Size();
- if (size > 0xFFFFFFFF)
- return E_NOTIMPL;
- // if (size > 0)
- {
- RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)props, (UInt32)size));
- }
- }
- }
-
- #if !defined(_7ZIP_ST) && !defined(_SFX)
- if (mtMode)
- {
- CMyComPtr<ICompressSetCoderMt> setCoderMt;
- decoder.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
- if (setCoderMt)
- {
- RINOK(setCoderMt->SetNumberOfThreads(numThreads));
- }
- }
- #endif
-
- #ifndef _NO_CRYPTO
- {
- CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
- decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);
- if (cryptoSetPassword)
- {
- isEncrypted = true;
- if (!getTextPassword)
- return E_NOTIMPL;
- CMyComBSTR passwordBSTR;
- RINOK(getTextPassword->CryptoGetTextPassword(&passwordBSTR));
- passwordIsDefined = true;
- size_t len = 0;
- if (passwordBSTR)
- len = MyStringLen((BSTR)passwordBSTR);
- CByteBuffer buffer(len * 2);
- for (size_t i = 0; i < len; i++)
- {
- wchar_t c = passwordBSTR[i];
- ((Byte *)buffer)[i * 2] = (Byte)c;
- ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
- }
- RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, (UInt32)buffer.Size()));
- }
- }
- #endif
-
- coderIndex++;
-
- UInt32 numInStreams = (UInt32)coderInfo.NumInStreams;
- UInt32 numOutStreams = (UInt32)coderInfo.NumOutStreams;
- CObjArray<UInt64> packSizes(numInStreams);
- CObjArray<const UInt64 *> packSizesPointers(numInStreams);
- CObjArray<const UInt64 *> unpackSizesPointers(numOutStreams);
- UInt32 j;
-
- for (j = 0; j < numOutStreams; j++, unpackStreamIndex++)
- unpackSizesPointers[j] = &folders.CoderUnpackSizes[unpackStreamIndex];
-
- for (j = 0; j < numInStreams; j++, packStreamIndex++)
- {
- int bindPairIndex = folderInfo.FindBindPairForInStream(packStreamIndex);
- if (bindPairIndex >= 0)
- packSizesPointers[j] = &folders.CoderUnpackSizes[unpackStreamIndexStart + (UInt32)folderInfo.BindPairs[bindPairIndex].OutIndex];
- else
- {
- int index = folderInfo.FindPackStreamArrayIndex(packStreamIndex);
- if (index < 0)
- return S_FALSE; // check it
- packSizes[j] = packPositions[index + 1] - packPositions[index];
- packSizesPointers[j] = &packSizes[j];
- }
- }
-
- _mixerCoderCommon->SetCoderInfo(i, packSizesPointers, unpackSizesPointers);
- }
- UInt32 mainCoder, temp;
- bindInfo.FindOutStream(bindInfo.OutStreams[0], mainCoder, temp);
-
- if (_multiThread)
- _mixerCoderMTSpec->SetProgressCoderIndex(mainCoder);
- /*
- else
- _mixerCoderSTSpec->SetProgressCoderIndex(mainCoder);;
- */
-
- if (numCoders == 0)
- return 0;
- unsigned num = inStreams.Size();
- CObjArray<ISequentialInStream *> inStreamPointers(num);
- for (i = 0; i < num; i++)
- inStreamPointers[i] = inStreams[i];
- ISequentialOutStream *outStreamPointer = outStream;
- return _mixerCoder->Code(
- inStreamPointers, NULL, num,
- &outStreamPointer, NULL, 1,
- compressProgress);
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.h
deleted file mode 100644
index 54e9d2b52..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zDecode.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// 7zDecode.h
-
-#ifndef __7Z_DECODE_H
-#define __7Z_DECODE_H
-
-#include "../../IStream.h"
-#include "../../IPassword.h"
-
-#include "../Common/CoderMixer2.h"
-#include "../Common/CoderMixer2MT.h"
-#ifdef _ST_MODE
-#include "../Common/CoderMixer2ST.h"
-#endif
-
-#include "../../Common/CreateCoder.h"
-
-#include "7zIn.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CBindInfoEx: public NCoderMixer::CBindInfo
-{
- CRecordVector<CMethodId> CoderMethodIDs;
- void Clear()
- {
- CBindInfo::Clear();
- CoderMethodIDs.Clear();
- }
-};
-
-class CDecoder
-{
- bool _bindInfoExPrevIsDefined;
- CBindInfoEx _bindInfoExPrev;
-
- bool _multiThread;
- #ifdef _ST_MODE
- NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec;
- #endif
- NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec;
- NCoderMixer::CCoderMixer2 *_mixerCoderCommon;
-
- CMyComPtr<ICompressCoder2> _mixerCoder;
- CObjectVector<CMyComPtr<IUnknown> > _decoders;
- // CObjectVector<CMyComPtr<ICompressCoder2> > _decoders2;
-public:
- CDecoder(bool multiThread);
- HRESULT Decode(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream,
- UInt64 startPos,
- const CFolders &folders, int folderIndex,
- ISequentialOutStream *outStream,
- ICompressProgressInfo *compressProgress
- _7Z_DECODER_CRYPRO_VARS_DECL
- #if !defined(_7ZIP_ST) && !defined(_SFX)
- , bool mtMode, UInt32 numThreads
- #endif
- );
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.cpp
deleted file mode 100644
index 5f1436fc7..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.cpp
+++ /dev/null
@@ -1,464 +0,0 @@
-// 7zEncode.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/CreateCoder.h"
-#include "../../Common/FilterCoder.h"
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/InOutTempBuffer.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamObjects.h"
-
-#include "7zEncode.h"
-#include "7zSpecStream.h"
-
-static const UInt64 k_Delta = 0x03;
-static const UInt64 k_BCJ = 0x03030103;
-static const UInt64 k_BCJ2 = 0x0303011B;
-
-namespace NArchive {
-namespace N7z {
-
-static void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo,
- const CRecordVector<CMethodId> decompressionMethods,
- CFolder &folder)
-{
- // bindInfo.CoderMethodIDs.Clear();
- // folder.OutStreams.Clear();
- folder.BindPairs.SetSize(bindInfo.BindPairs.Size());
- unsigned i;
- for (i = 0; i < bindInfo.BindPairs.Size(); i++)
- {
- CBindPair &bp = folder.BindPairs[i];
- const NCoderMixer::CBindPair &mixerBp = bindInfo.BindPairs[i];
- bp.InIndex = mixerBp.InIndex;
- bp.OutIndex = mixerBp.OutIndex;
- }
- folder.Coders.SetSize(bindInfo.Coders.Size());
- for (i = 0; i < bindInfo.Coders.Size(); i++)
- {
- CCoderInfo &coderInfo = folder.Coders[i];
- const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i];
- coderInfo.NumInStreams = coderStreamsInfo.NumInStreams;
- coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams;
- coderInfo.MethodID = decompressionMethods[i];
- // coderInfo.Props can be nonFree;
- }
- folder.PackStreams.SetSize(bindInfo.InStreams.Size());
- for (i = 0; i < bindInfo.InStreams.Size(); i++)
- folder.PackStreams[i] = bindInfo.InStreams[i];
-}
-
-static HRESULT SetCoderProps2(const CProps &props, const UInt64 *dataSizeReduce, IUnknown *coder)
-{
- CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
- coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
- if (setCoderProperties)
- return props.SetCoderProps(setCoderProperties, dataSizeReduce);
- return props.AreThereNonOptionalProps() ? E_INVALIDARG : S_OK;
-}
-
-HRESULT CEncoder::CreateMixerCoder(
- DECL_EXTERNAL_CODECS_LOC_VARS
- const UInt64 *inSizeForReduce)
-{
- _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT;
- _mixerCoder = _mixerCoderSpec;
- RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo));
- FOR_VECTOR (i, _options.Methods)
- {
- const CMethodFull &methodFull = _options.Methods[i];
- CCoderInfo &encodingInfo = _codersInfo.AddNew();
- encodingInfo.MethodID = methodFull.Id;
- CMyComPtr<ICompressCoder> encoder;
- CMyComPtr<ICompressCoder2> encoder2;
-
-
- RINOK(CreateCoder(
- EXTERNAL_CODECS_LOC_VARS
- methodFull.Id, encoder, encoder2, true));
-
- if (!encoder && !encoder2)
- return E_FAIL;
-
- CMyComPtr<IUnknown> encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2;
-
- #ifndef _7ZIP_ST
- {
- CMyComPtr<ICompressSetCoderMt> setCoderMt;
- encoderCommon.QueryInterface(IID_ICompressSetCoderMt, &setCoderMt);
- if (setCoderMt)
- {
- RINOK(setCoderMt->SetNumberOfThreads(_options.NumThreads));
- }
- }
- #endif
-
- RINOK(SetCoderProps2(methodFull, inSizeForReduce, encoderCommon));
-
- /*
- CMyComPtr<ICryptoResetSalt> resetSalt;
- encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt);
- if (resetSalt)
- {
- resetSalt->ResetSalt();
- }
- */
-
- #ifdef EXTERNAL_CODECS
- CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
- encoderCommon.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
- if (setCompressCodecsInfo)
- {
- RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(__externalCodecs->GetCodecs));
- }
- #endif
-
- CMyComPtr<ICryptoSetPassword> cryptoSetPassword;
- encoderCommon.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword);
-
- if (cryptoSetPassword)
- {
- const UInt32 sizeInBytes = _options.Password.Len() * 2;
- CByteBuffer buffer(sizeInBytes);
- for (unsigned i = 0; i < _options.Password.Len(); i++)
- {
- wchar_t c = _options.Password[i];
- ((Byte *)buffer)[i * 2] = (Byte)c;
- ((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
- }
- RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, sizeInBytes));
- }
-
- if (encoder)
- _mixerCoderSpec->AddCoder(encoder);
- else
- _mixerCoderSpec->AddCoder2(encoder2);
- }
- return S_OK;
-}
-
-HRESULT CEncoder::Encode(
- DECL_EXTERNAL_CODECS_LOC_VARS
- ISequentialInStream *inStream,
- const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,
- CFolder &folderItem,
- CRecordVector<UInt64> &coderUnpackSizes,
- UInt64 &unpackSize,
- ISequentialOutStream *outStream,
- CRecordVector<UInt64> &packSizes,
- ICompressProgressInfo *compressProgress)
-{
- RINOK(EncoderConstr());
-
- if (!_mixerCoderSpec)
- {
- RINOK(CreateMixerCoder(EXTERNAL_CODECS_LOC_VARS inSizeForReduce));
- }
- _mixerCoderSpec->ReInit();
- // _mixerCoderSpec->SetCoderInfo(0, NULL, NULL, progress);
-
- CObjectVector<CInOutTempBuffer> inOutTempBuffers;
- CObjectVector<CSequentialOutTempBufferImp *> tempBufferSpecs;
- CObjectVector<CMyComPtr<ISequentialOutStream> > tempBuffers;
- unsigned numMethods = _bindInfo.Coders.Size();
- unsigned i;
- for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
- {
- CInOutTempBuffer &iotb = inOutTempBuffers.AddNew();
- iotb.Create();
- iotb.InitWriting();
- }
- for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
- {
- CSequentialOutTempBufferImp *tempBufferSpec = new CSequentialOutTempBufferImp;
- CMyComPtr<ISequentialOutStream> tempBuffer = tempBufferSpec;
- tempBufferSpec->Init(&inOutTempBuffers[i - 1]);
- tempBuffers.Add(tempBuffer);
- tempBufferSpecs.Add(tempBufferSpec);
- }
-
- for (i = 0; i < numMethods; i++)
- _mixerCoderSpec->SetCoderInfo(i, NULL, NULL);
-
- if (_bindInfo.InStreams.IsEmpty())
- return E_FAIL;
- UInt32 mainCoderIndex, mainStreamIndex;
- _bindInfo.FindInStream(_bindInfo.InStreams[0], mainCoderIndex, mainStreamIndex);
-
- if (inStreamSize)
- {
- CRecordVector<const UInt64 *> sizePointers;
- for (UInt32 i = 0; i < _bindInfo.Coders[mainCoderIndex].NumInStreams; i++)
- if (i == mainStreamIndex)
- sizePointers.Add(inStreamSize);
- else
- sizePointers.Add(NULL);
- _mixerCoderSpec->SetCoderInfo(mainCoderIndex, &sizePointers.Front(), NULL);
- }
-
-
- // UInt64 outStreamStartPos;
- // RINOK(stream->Seek(0, STREAM_SEEK_CUR, &outStreamStartPos));
-
- CSequentialInStreamSizeCount2 *inStreamSizeCountSpec = new CSequentialInStreamSizeCount2;
- CMyComPtr<ISequentialInStream> inStreamSizeCount = inStreamSizeCountSpec;
- CSequentialOutStreamSizeCount *outStreamSizeCountSpec = NULL;
- CMyComPtr<ISequentialOutStream> outStreamSizeCount;
-
- inStreamSizeCountSpec->Init(inStream);
-
- CRecordVector<ISequentialInStream *> inStreamPointers;
- CRecordVector<ISequentialOutStream *> outStreamPointers;
- inStreamPointers.Add(inStreamSizeCount);
-
- if (_bindInfo.OutStreams.Size() != 0)
- {
- outStreamSizeCountSpec = new CSequentialOutStreamSizeCount;
- outStreamSizeCount = outStreamSizeCountSpec;
- outStreamSizeCountSpec->SetStream(outStream);
- outStreamSizeCountSpec->Init();
- outStreamPointers.Add(outStreamSizeCount);
- }
-
- for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
- outStreamPointers.Add(tempBuffers[i - 1]);
-
- for (i = 0; i < _codersInfo.Size(); i++)
- {
- CCoderInfo &encodingInfo = _codersInfo[i];
-
- CMyComPtr<ICryptoResetInitVector> resetInitVector;
- _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector);
- if (resetInitVector)
- {
- resetInitVector->ResetInitVector();
- }
-
- CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
- _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties);
- if (writeCoderProperties)
- {
- CDynBufSeqOutStream *outStreamSpec = new CDynBufSeqOutStream;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
- outStreamSpec->Init();
- writeCoderProperties->WriteCoderProperties(outStream);
- outStreamSpec->CopyToBuffer(encodingInfo.Props);
- }
- }
-
- UInt32 progressIndex = mainCoderIndex;
-
- for (i = 0; i + 1 < _codersInfo.Size(); i++)
- {
- UInt64 m = _codersInfo[i].MethodID;
- if (m == k_Delta || m == k_BCJ || m == k_BCJ2)
- progressIndex = i + 1;
- }
-
- _mixerCoderSpec->SetProgressCoderIndex(progressIndex);
-
- RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1,
- &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress));
-
- ConvertBindInfoToFolderItemInfo(_decompressBindInfo, _decompressionMethods, folderItem);
-
- if (_bindInfo.OutStreams.Size() != 0)
- packSizes.Add(outStreamSizeCountSpec->GetSize());
-
- for (i = 1; i < _bindInfo.OutStreams.Size(); i++)
- {
- CInOutTempBuffer &inOutTempBuffer = inOutTempBuffers[i - 1];
- RINOK(inOutTempBuffer.WriteToStream(outStream));
- packSizes.Add(inOutTempBuffer.GetDataSize());
- }
-
- unpackSize = 0;
- for (i = 0; i < (int)_bindReverseConverter->NumSrcInStreams; i++)
- {
- int binder = _bindInfo.FindBinderForInStream(
- _bindReverseConverter->DestOutToSrcInMap[i]);
- UInt64 streamSize;
- if (binder < 0)
- {
- streamSize = inStreamSizeCountSpec->GetSize();
- unpackSize = streamSize;
- }
- else
- streamSize = _mixerCoderSpec->GetWriteProcessedSize(binder);
- coderUnpackSizes.Add(streamSize);
- }
- for (i = 0; i < numMethods; i++)
- folderItem.Coders[numMethods - 1 - i].Props = _codersInfo[i].Props;
- return S_OK;
-}
-
-
-CEncoder::CEncoder(const CCompressionMethodMode &options):
- _bindReverseConverter(0),
- _constructed(false)
-{
- if (options.IsEmpty())
- throw 1;
-
- _options = options;
- _mixerCoderSpec = NULL;
-}
-
-HRESULT CEncoder::EncoderConstr()
-{
- if (_constructed)
- return S_OK;
- if (_options.Methods.IsEmpty())
- {
- // it has only password method;
- if (!_options.PasswordIsDefined)
- throw 1;
- if (!_options.Binds.IsEmpty())
- throw 1;
- NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
- CMethodFull method;
-
- method.NumInStreams = 1;
- method.NumOutStreams = 1;
- coderStreamsInfo.NumInStreams = 1;
- coderStreamsInfo.NumOutStreams = 1;
- method.Id = k_AES;
-
- _options.Methods.Add(method);
- _bindInfo.Coders.Add(coderStreamsInfo);
-
- _bindInfo.InStreams.Add(0);
- _bindInfo.OutStreams.Add(0);
- }
- else
- {
-
- UInt32 numInStreams = 0, numOutStreams = 0;
- unsigned i;
- for (i = 0; i < _options.Methods.Size(); i++)
- {
- const CMethodFull &methodFull = _options.Methods[i];
- NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
- coderStreamsInfo.NumInStreams = methodFull.NumOutStreams;
- coderStreamsInfo.NumOutStreams = methodFull.NumInStreams;
- if (_options.Binds.IsEmpty())
- {
- if (i < _options.Methods.Size() - 1)
- {
- NCoderMixer::CBindPair bindPair;
- bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams;
- bindPair.OutIndex = numOutStreams;
- _bindInfo.BindPairs.Add(bindPair);
- }
- else if (coderStreamsInfo.NumOutStreams != 0)
- _bindInfo.OutStreams.Insert(0, numOutStreams);
- for (UInt32 j = 1; j < coderStreamsInfo.NumOutStreams; j++)
- _bindInfo.OutStreams.Add(numOutStreams + j);
- }
-
- numInStreams += coderStreamsInfo.NumInStreams;
- numOutStreams += coderStreamsInfo.NumOutStreams;
-
- _bindInfo.Coders.Add(coderStreamsInfo);
- }
-
- if (!_options.Binds.IsEmpty())
- {
- for (i = 0; i < _options.Binds.Size(); i++)
- {
- NCoderMixer::CBindPair bindPair;
- const CBind &bind = _options.Binds[i];
- bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream;
- bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream;
- _bindInfo.BindPairs.Add(bindPair);
- }
- for (i = 0; i < (int)numOutStreams; i++)
- if (_bindInfo.FindBinderForOutStream(i) == -1)
- _bindInfo.OutStreams.Add(i);
- }
-
- for (i = 0; i < (int)numInStreams; i++)
- if (_bindInfo.FindBinderForInStream(i) == -1)
- _bindInfo.InStreams.Add(i);
-
- if (_bindInfo.InStreams.IsEmpty())
- throw 1; // this is error
-
- // Make main stream first in list
- int inIndex = _bindInfo.InStreams[0];
- for (;;)
- {
- UInt32 coderIndex, coderStreamIndex;
- _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex);
- UInt32 outIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);
- int binder = _bindInfo.FindBinderForOutStream(outIndex);
- if (binder >= 0)
- {
- inIndex = _bindInfo.BindPairs[binder].InIndex;
- continue;
- }
- for (i = 0; i < _bindInfo.OutStreams.Size(); i++)
- if (_bindInfo.OutStreams[i] == outIndex)
- {
- _bindInfo.OutStreams.Delete(i);
- _bindInfo.OutStreams.Insert(0, outIndex);
- break;
- }
- break;
- }
-
- if (_options.PasswordIsDefined)
- {
- unsigned numCryptoStreams = _bindInfo.OutStreams.Size();
-
- for (i = 0; i < numCryptoStreams; i++)
- {
- NCoderMixer::CBindPair bindPair;
- bindPair.InIndex = numInStreams + i;
- bindPair.OutIndex = _bindInfo.OutStreams[i];
- _bindInfo.BindPairs.Add(bindPair);
- }
- _bindInfo.OutStreams.Clear();
-
- /*
- if (numCryptoStreams == 0)
- numCryptoStreams = 1;
- */
-
- for (i = 0; i < numCryptoStreams; i++)
- {
- NCoderMixer::CCoderStreamsInfo coderStreamsInfo;
- CMethodFull method;
- method.NumInStreams = 1;
- method.NumOutStreams = 1;
- coderStreamsInfo.NumInStreams = method.NumOutStreams;
- coderStreamsInfo.NumOutStreams = method.NumInStreams;
- method.Id = k_AES;
-
- _options.Methods.Add(method);
- _bindInfo.Coders.Add(coderStreamsInfo);
- _bindInfo.OutStreams.Add(numOutStreams + i);
- }
- }
-
- }
-
- for (int i = _options.Methods.Size() - 1; i >= 0; i--)
- {
- const CMethodFull &methodFull = _options.Methods[i];
- _decompressionMethods.Add(methodFull.Id);
- }
-
- _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo);
- _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo);
- _constructed = true;
- return S_OK;
-}
-
-CEncoder::~CEncoder()
-{
- delete _bindReverseConverter;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.h
deleted file mode 100644
index 8e20bdb5f..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zEncode.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// 7zEncode.h
-
-#ifndef __7Z_ENCODE_H
-#define __7Z_ENCODE_H
-
-// #include "../../Common/StreamObjects.h"
-
-#include "7zCompressionMode.h"
-
-#include "../Common/CoderMixer2.h"
-#include "../Common/CoderMixer2MT.h"
-#ifdef _ST_MODE
-#include "../Common/CoderMixer2ST.h"
-#endif
-#include "7zItem.h"
-
-#include "../../Common/CreateCoder.h"
-
-namespace NArchive {
-namespace N7z {
-
-class CEncoder
-{
- NCoderMixer::CCoderMixer2MT *_mixerCoderSpec;
- CMyComPtr<ICompressCoder2> _mixerCoder;
-
- CObjectVector<CCoderInfo> _codersInfo;
-
- CCompressionMethodMode _options;
- NCoderMixer::CBindInfo _bindInfo;
- NCoderMixer::CBindInfo _decompressBindInfo;
- NCoderMixer::CBindReverseConverter *_bindReverseConverter;
- CRecordVector<CMethodId> _decompressionMethods;
-
- HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS
- const UInt64 *inSizeForReduce);
-
- bool _constructed;
-public:
- CEncoder(const CCompressionMethodMode &options);
- ~CEncoder();
- HRESULT EncoderConstr();
- HRESULT Encode(
- DECL_EXTERNAL_CODECS_LOC_VARS
- ISequentialInStream *inStream,
- const UInt64 *inStreamSize, const UInt64 *inSizeForReduce,
- CFolder &folderItem,
- CRecordVector<UInt64> &coderUnpackSizes,
- UInt64 &unpackSize,
- ISequentialOutStream *outStream,
- CRecordVector<UInt64> &packSizes,
- ICompressProgressInfo *compressProgress);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zExtract.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zExtract.cpp
deleted file mode 100644
index bb350455c..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zExtract.cpp
+++ /dev/null
@@ -1,262 +0,0 @@
-// 7zExtract.cpp
-
-#include "StdAfx.h"
-
-#include "../../../Common/ComTry.h"
-
-#include "../../Common/ProgressUtils.h"
-
-#include "7zDecode.h"
-// #include "7z1Decode.h"
-#include "7zFolderOutStream.h"
-#include "7zHandler.h"
-
-namespace NArchive {
-namespace N7z {
-
-struct CExtractFolderInfo
-{
- #ifdef _7Z_VOL
- int VolumeIndex;
- #endif
- CNum FileIndex;
- CNum FolderIndex;
- CBoolVector ExtractStatuses;
- UInt64 UnpackSize;
- CExtractFolderInfo(
- #ifdef _7Z_VOL
- int volumeIndex,
- #endif
- CNum fileIndex, CNum folderIndex):
- #ifdef _7Z_VOL
- VolumeIndex(volumeIndex),
- #endif
- FileIndex(fileIndex),
- FolderIndex(folderIndex),
- UnpackSize(0)
- {
- if (fileIndex != kNumNoIndex)
- {
- ExtractStatuses.ClearAndSetSize(1);
- ExtractStatuses[0] = true;
- }
- };
-};
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallbackSpec)
-{
- COM_TRY_BEGIN
- bool testMode = (testModeSpec != 0);
- CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
- UInt64 importantTotalUnpacked = 0;
-
- bool allFilesMode = (numItems == (UInt32)(Int32)-1);
- if (allFilesMode)
- numItems =
- #ifdef _7Z_VOL
- _refs.Size();
- #else
- _db.Files.Size();
- #endif
-
- if (numItems == 0)
- return S_OK;
-
- /*
- if (_volumes.Size() != 1)
- return E_FAIL;
- const CVolume &volume = _volumes.Front();
- const CDbEx &_db = volume.Database;
- IInStream *_inStream = volume.Stream;
- */
-
- CObjectVector<CExtractFolderInfo> extractFolderInfoVector;
- for (UInt32 ii = 0; ii < numItems; ii++)
- {
- // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];
- UInt32 ref2Index = allFilesMode ? ii : indices[ii];
- // const CRef2 &ref2 = _refs[ref2Index];
-
- // for (UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)
- {
- #ifdef _7Z_VOL
- // const CRef &ref = ref2.Refs[ri];
- const CRef &ref = _refs[ref2Index];
-
- int volumeIndex = ref.VolumeIndex;
- const CVolume &volume = _volumes[volumeIndex];
- const CDbEx &db = volume.Database;
- UInt32 fileIndex = ref.ItemIndex;
- #else
- const CDbEx &db = _db;
- UInt32 fileIndex = ref2Index;
- #endif
-
- CNum folderIndex = db.FileIndexToFolderIndexMap[fileIndex];
- if (folderIndex == kNumNoIndex)
- {
- extractFolderInfoVector.Add(CExtractFolderInfo(
- #ifdef _7Z_VOL
- volumeIndex,
- #endif
- fileIndex, kNumNoIndex));
- continue;
- }
- if (extractFolderInfoVector.IsEmpty() ||
- folderIndex != extractFolderInfoVector.Back().FolderIndex
- #ifdef _7Z_VOL
- || volumeIndex != extractFolderInfoVector.Back().VolumeIndex
- #endif
- )
- {
- extractFolderInfoVector.Add(CExtractFolderInfo(
- #ifdef _7Z_VOL
- volumeIndex,
- #endif
- kNumNoIndex, folderIndex));
- UInt64 unpackSize = db.GetFolderUnpackSize(folderIndex);
- importantTotalUnpacked += unpackSize;
- extractFolderInfoVector.Back().UnpackSize = unpackSize;
- }
-
- CExtractFolderInfo &efi = extractFolderInfoVector.Back();
-
- // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];
- CNum startIndex = db.FolderStartFileIndex[folderIndex];
- for (CNum index = efi.ExtractStatuses.Size();
- index <= fileIndex - startIndex; index++)
- {
- // UInt64 unpackSize = _db.Files[startIndex + index].UnpackSize;
- // Count partial_folder_size
- // efi.UnpackSize += unpackSize;
- // importantTotalUnpacked += unpackSize;
- efi.ExtractStatuses.Add(index == fileIndex - startIndex);
- }
- }
- }
-
- RINOK(extractCallback->SetTotal(importantTotalUnpacked));
-
- CDecoder decoder(
- #ifdef _ST_MODE
- false
- #else
- true
- #endif
- );
- // CDecoder1 decoder;
-
- UInt64 totalPacked = 0;
- UInt64 totalUnpacked = 0;
- UInt64 curPacked, curUnpacked;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- for (unsigned i = 0;; i++, totalUnpacked += curUnpacked, totalPacked += curPacked)
- {
- lps->OutSize = totalUnpacked;
- lps->InSize = totalPacked;
- RINOK(lps->SetCur());
-
- if (i >= extractFolderInfoVector.Size())
- break;
-
- const CExtractFolderInfo &efi = extractFolderInfoVector[i];
- curUnpacked = efi.UnpackSize;
- curPacked = 0;
-
- CFolderOutStream *folderOutStream = new CFolderOutStream;
- CMyComPtr<ISequentialOutStream> outStream(folderOutStream);
-
- #ifdef _7Z_VOL
- const CVolume &volume = _volumes[efi.VolumeIndex];
- const CDbEx &db = volume.Database;
- #else
- const CDbEx &db = _db;
- #endif
-
- CNum startIndex;
- if (efi.FileIndex != kNumNoIndex)
- startIndex = efi.FileIndex;
- else
- startIndex = db.FolderStartFileIndex[efi.FolderIndex];
-
- HRESULT result = folderOutStream->Init(&db,
- #ifdef _7Z_VOL
- volume.StartRef2Index,
- #else
- 0,
- #endif
- startIndex,
- &efi.ExtractStatuses, extractCallback, testMode, _crcSize != 0);
-
- RINOK(result);
-
- if (efi.FileIndex != kNumNoIndex)
- continue;
-
- CNum folderIndex = efi.FolderIndex;
- curPacked = _db.GetFolderFullPackSize(folderIndex);
-
- #ifndef _NO_CRYPTO
- CMyComPtr<ICryptoGetTextPassword> getTextPassword;
- if (extractCallback)
- extractCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
- #endif
-
- try
- {
- #ifndef _NO_CRYPTO
- bool isEncrypted = false;
- bool passwordIsDefined = false;
- #endif
-
- HRESULT result = decoder.Decode(
- EXTERNAL_CODECS_VARS
- #ifdef _7Z_VOL
- volume.Stream,
- #else
- _inStream,
- #endif
- db.ArcInfo.DataStartPosition,
- db, folderIndex,
- outStream,
- progress
- _7Z_DECODER_CRYPRO_VARS
- #if !defined(_7ZIP_ST) && !defined(_SFX)
- , true, _numThreads
- #endif
- );
-
- if (result == S_FALSE)
- {
- RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kDataError));
- continue;
- }
- if (result == E_NOTIMPL)
- {
- RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kUnsupportedMethod));
- continue;
- }
- if (result != S_OK)
- return result;
- if (folderOutStream->WasWritingFinished() != S_OK)
- {
- RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kDataError));
- continue;
- }
- }
- catch(...)
- {
- RINOK(folderOutStream->FlushCorrupted(NExtract::NOperationResult::kDataError));
- continue;
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.cpp
deleted file mode 100644
index 3f420a513..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-// 7zFolderInStream.cpp
-
-#include "StdAfx.h"
-
-#include "7zFolderInStream.h"
-
-namespace NArchive {
-namespace N7z {
-
-CFolderInStream::CFolderInStream()
-{
- _inStreamWithHashSpec = new CSequentialInStreamWithCRC;
- _inStreamWithHash = _inStreamWithHashSpec;
-}
-
-void CFolderInStream::Init(IArchiveUpdateCallback *updateCallback,
- const UInt32 *fileIndices, UInt32 numFiles)
-{
- _updateCallback = updateCallback;
- _numFiles = numFiles;
- _fileIndex = 0;
- _fileIndices = fileIndices;
- Processed.Clear();
- CRCs.Clear();
- Sizes.Clear();
- _fileIsOpen = false;
- _currentSizeIsDefined = false;
-}
-
-HRESULT CFolderInStream::OpenStream()
-{
- _filePos = 0;
- while (_fileIndex < _numFiles)
- {
- CMyComPtr<ISequentialInStream> stream;
- HRESULT result = _updateCallback->GetStream(_fileIndices[_fileIndex], &stream);
- if (result != S_OK && result != S_FALSE)
- return result;
- _fileIndex++;
- _inStreamWithHashSpec->SetStream(stream);
- _inStreamWithHashSpec->Init();
- if (stream)
- {
- _fileIsOpen = true;
- CMyComPtr<IStreamGetSize> streamGetSize;
- stream.QueryInterface(IID_IStreamGetSize, &streamGetSize);
- if (streamGetSize)
- {
- RINOK(streamGetSize->GetSize(&_currentSize));
- _currentSizeIsDefined = true;
- }
- return S_OK;
- }
- RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
- Sizes.Add(0);
- Processed.Add(result == S_OK);
- AddDigest();
- }
- return S_OK;
-}
-
-void CFolderInStream::AddDigest()
-{
- CRCs.Add(_inStreamWithHashSpec->GetCRC());
-}
-
-HRESULT CFolderInStream::CloseStream()
-{
- RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
- _inStreamWithHashSpec->ReleaseStream();
- _fileIsOpen = false;
- _currentSizeIsDefined = false;
- Processed.Add(true);
- Sizes.Add(_filePos);
- AddDigest();
- return S_OK;
-}
-
-STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- if (processedSize != 0)
- *processedSize = 0;
- while (size > 0)
- {
- if (_fileIsOpen)
- {
- UInt32 processed2;
- RINOK(_inStreamWithHash->Read(data, size, &processed2));
- if (processed2 == 0)
- {
- RINOK(CloseStream());
- continue;
- }
- if (processedSize != 0)
- *processedSize = processed2;
- _filePos += processed2;
- break;
- }
- if (_fileIndex >= _numFiles)
- break;
- RINOK(OpenStream());
- }
- return S_OK;
-}
-
-STDMETHODIMP CFolderInStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)
-{
- *value = 0;
- unsigned index2 = (unsigned)subStream;
- if (subStream > Sizes.Size())
- return E_FAIL;
- if (index2 < Sizes.Size())
- {
- *value = Sizes[index2];
- return S_OK;
- }
- if (!_currentSizeIsDefined)
- return S_FALSE;
- *value = _currentSize;
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.h
deleted file mode 100644
index 4ed4b2dd2..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderInStream.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// 7zFolderInStream.h
-
-#ifndef __7Z_FOLDER_IN_STREAM_H
-#define __7Z_FOLDER_IN_STREAM_H
-
-#include "../../ICoder.h"
-#include "../IArchive.h"
-#include "../Common/InStreamWithCRC.h"
-
-#include "7zItem.h"
-
-namespace NArchive {
-namespace N7z {
-
-class CFolderInStream:
- public ISequentialInStream,
- public ICompressGetSubStreamSize,
- public CMyUnknownImp
-{
- CSequentialInStreamWithCRC *_inStreamWithHashSpec;
- CMyComPtr<ISequentialInStream> _inStreamWithHash;
- CMyComPtr<IArchiveUpdateCallback> _updateCallback;
-
- bool _currentSizeIsDefined;
- bool _fileIsOpen;
- UInt64 _currentSize;
- UInt64 _filePos;
- const UInt32 *_fileIndices;
- UInt32 _numFiles;
- UInt32 _fileIndex;
-
- HRESULT OpenStream();
- HRESULT CloseStream();
- void AddDigest();
-
-public:
- CRecordVector<bool> Processed;
- CRecordVector<UInt32> CRCs;
- CRecordVector<UInt64> Sizes;
-
- MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
-
- CFolderInStream();
- void Init(IArchiveUpdateCallback *updateCallback, const UInt32 *fileIndices, UInt32 numFiles);
- UInt64 GetFullSize() const
- {
- UInt64 size = 0;
- FOR_VECTOR (i, Sizes)
- size += Sizes[i];
- return size;
- }
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.cpp
deleted file mode 100644
index 847f65bf2..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-// 7zFolderOutStream.cpp
-
-#include "StdAfx.h"
-
-#include "7zFolderOutStream.h"
-
-namespace NArchive {
-namespace N7z {
-
-CFolderOutStream::CFolderOutStream()
-{
- _crcStreamSpec = new COutStreamWithCRC;
- _crcStream = _crcStreamSpec;
-}
-
-HRESULT CFolderOutStream::Init(
- const CDbEx *db,
- UInt32 ref2Offset, UInt32 startIndex,
- const CBoolVector *extractStatuses,
- IArchiveExtractCallback *extractCallback,
- bool testMode, bool checkCrc)
-{
- _db = db;
- _ref2Offset = ref2Offset;
- _startIndex = startIndex;
-
- _extractStatuses = extractStatuses;
- _extractCallback = extractCallback;
- _testMode = testMode;
- _checkCrc = checkCrc;
-
- _currentIndex = 0;
- _fileIsOpen = false;
- return ProcessEmptyFiles();
-}
-
-HRESULT CFolderOutStream::OpenFile()
-{
- Int32 askMode = ((*_extractStatuses)[_currentIndex]) ? (_testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract) :
- NExtract::NAskMode::kSkip;
- CMyComPtr<ISequentialOutStream> realOutStream;
- UInt32 index = _startIndex + _currentIndex;
- RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode));
- _crcStreamSpec->SetStream(realOutStream);
- _crcStreamSpec->Init(_checkCrc);
- _fileIsOpen = true;
- const CFileItem &fi = _db->Files[index];
- _rem = fi.Size;
- if (askMode == NExtract::NAskMode::kExtract && !realOutStream &&
- !_db->IsItemAnti(index) && !fi.IsDir)
- askMode = NExtract::NAskMode::kSkip;
- return _extractCallback->PrepareOperation(askMode);
-}
-
-HRESULT CFolderOutStream::CloseFileAndSetResult(Int32 res)
-{
- _crcStreamSpec->ReleaseStream();
- _fileIsOpen = false;
- _currentIndex++;
- return _extractCallback->SetOperationResult(res);
-}
-
-HRESULT CFolderOutStream::CloseFileAndSetResult()
-{
- const CFileItem &fi = _db->Files[_startIndex + _currentIndex];
- return CloseFileAndSetResult(
- (fi.IsDir || !fi.CrcDefined || !_checkCrc || fi.Crc == _crcStreamSpec->GetCRC()) ?
- NExtract::NOperationResult::kOK :
- NExtract::NOperationResult::kCRCError);
-}
-
-HRESULT CFolderOutStream::ProcessEmptyFiles()
-{
- while (_currentIndex < _extractStatuses->Size() && _db->Files[_startIndex + _currentIndex].Size == 0)
- {
- RINOK(OpenFile());
- RINOK(CloseFileAndSetResult());
- }
- return S_OK;
-}
-
-STDMETHODIMP CFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- if (processedSize != NULL)
- *processedSize = 0;
- while (size != 0)
- {
- if (_fileIsOpen)
- {
- UInt32 cur = size < _rem ? size : (UInt32)_rem;
- RINOK(_crcStream->Write(data, cur, &cur));
- if (cur == 0)
- break;
- data = (const Byte *)data + cur;
- size -= cur;
- _rem -= cur;
- if (processedSize != NULL)
- *processedSize += cur;
- if (_rem == 0)
- {
- RINOK(CloseFileAndSetResult());
- RINOK(ProcessEmptyFiles());
- continue;
- }
- }
- else
- {
- RINOK(ProcessEmptyFiles());
- if (_currentIndex == _extractStatuses->Size())
- {
- // we support partial extracting
- if (processedSize != NULL)
- *processedSize += size;
- break;
- }
- RINOK(OpenFile());
- }
- }
- return S_OK;
-}
-
-STDMETHODIMP CFolderOutStream::GetSubStreamSize(UInt64 subStream, UInt64 *value)
-{
- *value = 0;
- if ((int)subStream >= _extractStatuses->Size())
- return S_FALSE;
- *value = _db->Files[_startIndex + (int)subStream].Size;
- return S_OK;
-}
-
-HRESULT CFolderOutStream::FlushCorrupted(Int32 resultEOperationResult)
-{
- while (_currentIndex < _extractStatuses->Size())
- {
- if (_fileIsOpen)
- {
- RINOK(CloseFileAndSetResult(resultEOperationResult));
- }
- else
- {
- RINOK(OpenFile());
- }
- }
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.h
deleted file mode 100644
index cc2d77343..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zFolderOutStream.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// 7zFolderOutStream.h
-
-#ifndef __7Z_FOLDER_OUT_STREAM_H
-#define __7Z_FOLDER_OUT_STREAM_H
-
-#include "../../IStream.h"
-#include "../IArchive.h"
-#include "../Common/OutStreamWithCRC.h"
-
-#include "7zIn.h"
-
-namespace NArchive {
-namespace N7z {
-
-class CFolderOutStream:
- public ISequentialOutStream,
- public ICompressGetSubStreamSize,
- public CMyUnknownImp
-{
- COutStreamWithCRC *_crcStreamSpec;
- CMyComPtr<ISequentialOutStream> _crcStream;
- const CDbEx *_db;
- const CBoolVector *_extractStatuses;
- CMyComPtr<IArchiveExtractCallback> _extractCallback;
- UInt32 _ref2Offset;
- UInt32 _startIndex;
- unsigned _currentIndex;
- bool _testMode;
- bool _checkCrc;
- bool _fileIsOpen;
- UInt64 _rem;
-
- HRESULT OpenFile();
- HRESULT CloseFileAndSetResult(Int32 res);
- HRESULT CloseFileAndSetResult();
- HRESULT ProcessEmptyFiles();
-public:
- MY_UNKNOWN_IMP1(ICompressGetSubStreamSize)
-
- CFolderOutStream();
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value);
-
- HRESULT Init(
- const CDbEx *db,
- UInt32 ref2Offset, UInt32 startIndex,
- const CBoolVector *extractStatuses,
- IArchiveExtractCallback *extractCallback,
- bool testMode, bool checkCrc);
- HRESULT FlushCorrupted(Int32 resultEOperationResult);
- HRESULT WasWritingFinished() const
- { return (_currentIndex == _extractStatuses->Size()) ? S_OK: E_FAIL; }
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.cpp
deleted file mode 100644
index ed65dc20c..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.cpp
+++ /dev/null
@@ -1,753 +0,0 @@
-// 7zHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../C/CpuArch.h"
-
-#include "../../../Common/ComTry.h"
-#include "../../../Common/IntToString.h"
-
-#ifndef __7Z_SET_PROPERTIES
-#include "../../../Windows/System.h"
-#endif
-
-#include "../Common/ItemNameUtils.h"
-
-#include "7zHandler.h"
-#include "7zProperties.h"
-
-#ifdef __7Z_SET_PROPERTIES
-#ifdef EXTRACT_ONLY
-#include "../Common/ParseProperties.h"
-#endif
-#endif
-
-using namespace NWindows;
-using namespace NCOM;
-
-namespace NArchive {
-namespace N7z {
-
-CHandler::CHandler()
-{
- #ifndef _NO_CRYPTO
- _isEncrypted = false;
- _passwordIsDefined = false;
- #endif
-
- #ifdef EXTRACT_ONLY
- _crcSize = 4;
- #ifdef __7Z_SET_PROPERTIES
- _numThreads = NSystem::GetNumberOfProcessors();
- #endif
- #endif
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _db.Files.Size();
- return S_OK;
-}
-
-#ifdef _SFX
-
-IMP_IInArchive_ArcProps_NO_Table
-
-STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProps)
-{
- *numProps = 0;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */,
- BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */)
-{
- return E_NOTIMPL;
-}
-
-#else
-
-static const Byte kArcProps[] =
-{
- kpidHeadersSize,
- kpidMethod,
- kpidSolid,
- kpidNumBlocks
- // , kpidIsTree
-};
-
-IMP_IInArchive_ArcProps
-
-static inline char GetHex(unsigned value)
-{
- return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));
-}
-
-static unsigned ConvertMethodIdToString_Back(char *s, UInt64 id)
-{
- int len = 0;
- do
- {
- s[--len] = GetHex((unsigned)id & 0xF); id >>= 4;
- s[--len] = GetHex((unsigned)id & 0xF); id >>= 4;
- }
- while (id != 0);
- return (unsigned)-len;
-}
-
-static void ConvertMethodIdToString(AString &res, UInt64 id)
-{
- const unsigned kLen = 32;
- char s[kLen];
- unsigned len = kLen - 1;
- s[len] = 0;
- res += s + len - ConvertMethodIdToString_Back(s + len, id);
-}
-
-static unsigned GetStringForSizeValue(char *s, UInt32 val)
-{
- unsigned i;
- for (i = 0; i <= 31; i++)
- if (((UInt32)1 << i) == val)
- {
- if (i < 10)
- {
- s[0] = (char)('0' + i);
- s[1] = 0;
- return 1;
- }
- if (i < 20) { s[0] = '1'; s[1] = (char)('0' + i - 10); }
- else if (i < 30) { s[0] = '2'; s[1] = (char)('0' + i - 20); }
- else { s[0] = '3'; s[1] = (char)('0' + i - 30); }
- s[2] = 0;
- return 2;
- }
- char c = 'b';
- if ((val & ((1 << 20) - 1)) == 0) { val >>= 20; c = 'm'; }
- else if ((val & ((1 << 10) - 1)) == 0) { val >>= 10; c = 'k'; }
- ::ConvertUInt32ToString(val, s);
- unsigned pos = MyStringLen(s);
- s[pos++] = c;
- s[pos] = 0;
- return pos;
-}
-
-/*
-static inline void AddHexToString(UString &res, Byte value)
-{
- res += GetHex((Byte)(value >> 4));
- res += GetHex((Byte)(value & 0xF));
-}
-*/
-
-static char *AddProp32(char *s, const char *name, UInt32 v)
-{
- *s++ = ':';
- s = MyStpCpy(s, name);
- ::ConvertUInt32ToString(v, s);
- return s + MyStringLen(s);
-}
-
-void CHandler::AddMethodName(AString &s, UInt64 id)
-{
- UString methodName;
- FindMethod(EXTERNAL_CODECS_VARS id, methodName);
- if (methodName.IsEmpty())
- {
- for (unsigned i = 0; i < methodName.Len(); i++)
- if (methodName[i] >= 0x80)
- {
- methodName.Empty();
- break;
- }
- }
- if (methodName.IsEmpty())
- ConvertMethodIdToString(s, id);
- else
- for (unsigned i = 0; i < methodName.Len(); i++)
- s += (char)methodName[i];
-}
-
-#endif
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- #ifndef _SFX
- COM_TRY_BEGIN
- #endif
- NCOM::CPropVariant prop;
- switch (propID)
- {
- #ifndef _SFX
- case kpidMethod:
- {
- AString s;
- const CParsedMethods &pm = _db.ParsedMethods;
- FOR_VECTOR (i, pm.IDs)
- {
- UInt64 id = pm.IDs[i];
- if (!s.IsEmpty())
- s += ' ';
- char temp[16];
- if (id == k_LZMA2)
- {
- s += "LZMA2:";
- if ((pm.Lzma2Prop & 1) == 0)
- ConvertUInt32ToString((pm.Lzma2Prop >> 1) + 12, temp);
- else
- GetStringForSizeValue(temp, 3 << ((pm.Lzma2Prop >> 1) + 11));
- s += temp;
- }
- else if (id == k_LZMA)
- {
- s += "LZMA:";
- GetStringForSizeValue(temp, pm.LzmaDic);
- s += temp;
- }
- else
- AddMethodName(s, id);
- }
- prop = s;
- break;
- }
- case kpidSolid: prop = _db.IsSolid(); break;
- case kpidNumBlocks: prop = (UInt32)_db.NumFolders; break;
- case kpidHeadersSize: prop = _db.HeadersSize; break;
- case kpidPhySize: prop = _db.PhySize; break;
- case kpidOffset: if (_db.ArcInfo.StartPosition != 0) prop = _db.ArcInfo.StartPosition; break;
- /*
- case kpidIsTree: if (_db.IsTree) prop = true; break;
- case kpidIsAltStream: if (_db.ThereAreAltStreams) prop = true; break;
- case kpidIsAux: if (_db.IsTree) prop = true; break;
- */
- // case kpidError: if (_db.ThereIsHeaderError) prop = "Header error"; break;
- #endif
-
- case kpidWarningFlags:
- {
- UInt32 v = 0;
- if (_db.StartHeaderWasRecovered) v |= kpv_ErrorFlags_HeadersError;
- if (_db.UnsupportedFeatureWarning) v |= kpv_ErrorFlags_UnsupportedFeature;
- if (v != 0)
- prop = v;
- break;
- }
-
- case kpidErrorFlags:
- {
- UInt32 v = 0;
- if (!_db.IsArc) v |= kpv_ErrorFlags_IsNotArc;
- if (_db.ThereIsHeaderError) v |= kpv_ErrorFlags_HeadersError;
- if (_db.UnexpectedEnd) v |= kpv_ErrorFlags_UnexpectedEnd;
- // if (_db.UnsupportedVersion) v |= kpv_ErrorFlags_Unsupported;
- if (_db.UnsupportedFeatureError) v |= kpv_ErrorFlags_UnsupportedFeature;
- prop = v;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- #ifndef _SFX
- COM_TRY_END
- #endif
-}
-
-static void SetFileTimeProp_From_UInt64Def(PROPVARIANT *prop, const CUInt64DefVector &v, int index)
-{
- UInt64 value;
- if (v.GetItem(index, value))
- PropVarEm_Set_FileTime64(prop, value);
-}
-
-bool CHandler::IsFolderEncrypted(CNum folderIndex) const
-{
- if (folderIndex == kNumNoIndex)
- return false;
- size_t startPos = _db.FoCodersDataOffset[folderIndex];
- const Byte *p = _db.CodersData + startPos;
- size_t size = _db.FoCodersDataOffset[folderIndex + 1] - startPos;
- CInByte2 inByte;
- inByte.Init(p, size);
-
- CNum numCoders = inByte.ReadNum();
- for (; numCoders != 0; numCoders--)
- {
- Byte mainByte = inByte.ReadByte();
- unsigned idSize = (mainByte & 0xF);
- const Byte *longID = inByte.GetPtr();
- UInt64 id64 = 0;
- for (unsigned j = 0; j < idSize; j++)
- id64 = ((id64 << 8) | longID[j]);
- inByte.SkipDataNoCheck(idSize);
- if (id64 == k_AES)
- return true;
- if ((mainByte & 0x20) != 0)
- inByte.SkipDataNoCheck(inByte.ReadNum());
- }
- return false;
-}
-
-STDMETHODIMP CHandler::GetNumRawProps(UInt32 *numProps)
-{
- *numProps = 0;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetRawPropInfo(UInt32 /* index */, BSTR *name, PROPID *propID)
-{
- *name = NULL;
- *propID = kpidNtSecure;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetParent(UInt32 /* index */, UInt32 *parent, UInt32 *parentType)
-{
- /*
- const CFileItem &file = _db.Files[index];
- *parentType = (file.IsAltStream ? NParentType::kAltStream : NParentType::kDir);
- *parent = (UInt32)(Int32)file.Parent;
- */
- *parentType = NParentType::kDir;
- *parent = (UInt32)(Int32)-1;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetRawProp(UInt32 index, PROPID propID, const void **data, UInt32 *dataSize, UInt32 *propType)
-{
- *data = NULL;
- *dataSize = 0;
- *propType = 0;
-
- if (/* _db.IsTree && propID == kpidName ||
- !_db.IsTree && */ propID == kpidPath)
- {
- if (_db.NameOffsets && _db.NamesBuf)
- {
- size_t offset = _db.NameOffsets[index];
- size_t size = (_db.NameOffsets[index + 1] - offset) * 2;
- if (size < ((UInt32)1 << 31))
- {
- *data = (const void *)(_db.NamesBuf + offset * 2);
- *dataSize = (UInt32)size;
- *propType = NPropDataType::kUtf16z;
- }
- }
- return S_OK;
- }
- /*
- if (propID == kpidNtSecure)
- {
- if (index < (UInt32)_db.SecureIDs.Size())
- {
- int id = _db.SecureIDs[index];
- size_t offs = _db.SecureOffsets[id];
- size_t size = _db.SecureOffsets[id + 1] - offs;
- if (size >= 0)
- {
- *data = _db.SecureBuf + offs;
- *dataSize = (UInt32)size;
- *propType = NPropDataType::kRaw;
- }
- }
- }
- */
- return S_OK;
-}
-
-#ifndef _SFX
-
-HRESULT CHandler::SetMethodToProp(CNum folderIndex, PROPVARIANT *prop) const
-{
- PropVariant_Clear(prop);
- if (folderIndex == kNumNoIndex)
- return S_OK;
- // for (int ttt = 0; ttt < 1; ttt++) {
- const unsigned kTempSize = 256;
- char temp[kTempSize];
- unsigned pos = kTempSize;
- temp[--pos] = 0;
-
- size_t startPos = _db.FoCodersDataOffset[folderIndex];
- const Byte *p = _db.CodersData + startPos;
- size_t size = _db.FoCodersDataOffset[folderIndex + 1] - startPos;
- CInByte2 inByte;
- inByte.Init(p, size);
-
- // numCoders == 0 ???
- CNum numCoders = inByte.ReadNum();
- bool needSpace = false;
- for (; numCoders != 0; numCoders--, needSpace = true)
- {
- if (pos < 32) // max size of property
- break;
- Byte mainByte = inByte.ReadByte();
- unsigned idSize = (mainByte & 0xF);
- const Byte *longID = inByte.GetPtr();
- UInt64 id64 = 0;
- for (unsigned j = 0; j < idSize; j++)
- id64 = ((id64 << 8) | longID[j]);
- inByte.SkipDataNoCheck(idSize);
-
- if ((mainByte & 0x10) != 0)
- {
- inByte.ReadNum(); // NumInStreams
- inByte.ReadNum(); // NumOutStreams
- }
-
- CNum propsSize = 0;
- const Byte *props = NULL;
- if ((mainByte & 0x20) != 0)
- {
- propsSize = inByte.ReadNum();
- props = inByte.GetPtr();
- inByte.SkipDataNoCheck(propsSize);
- }
-
- const char *name = NULL;
- char s[32];
- s[0] = 0;
-
- if (id64 <= (UInt32)0xFFFFFFFF)
- {
- UInt32 id = (UInt32)id64;
- if (id == k_LZMA)
- {
- name = "LZMA";
- if (propsSize == 5)
- {
- UInt32 dicSize = GetUi32((const Byte *)props + 1);
- char *dest = s + GetStringForSizeValue(s, dicSize);
- UInt32 d = props[0];
- if (d != 0x5D)
- {
- UInt32 lc = d % 9;
- d /= 9;
- UInt32 pb = d / 5;
- UInt32 lp = d % 5;
- if (lc != 3) dest = AddProp32(dest, "lc", lc);
- if (lp != 0) dest = AddProp32(dest, "lp", lp);
- if (pb != 2) dest = AddProp32(dest, "pb", pb);
- }
- }
- }
- else if (id == k_LZMA2)
- {
- name = "LZMA2";
- if (propsSize == 1)
- {
- Byte p = props[0];
- if ((p & 1) == 0)
- ConvertUInt32ToString((UInt32)((p >> 1) + 12), s);
- else
- GetStringForSizeValue(s, 3 << ((p >> 1) + 11));
- }
- }
- else if (id == k_PPMD)
- {
- name = "PPMD";
- if (propsSize == 5)
- {
- Byte order = *props;
- char *dest = s;
- *dest++ = 'o';
- ConvertUInt32ToString(order, dest);
- dest += MyStringLen(dest);
- dest = MyStpCpy(dest, ":mem");
- GetStringForSizeValue(dest, GetUi32(props + 1));
- }
- }
- else if (id == k_Delta)
- {
- name = "Delta";
- if (propsSize == 1)
- ConvertUInt32ToString((UInt32)props[0] + 1, s);
- }
- else if (id == k_BCJ2) name = "BCJ2";
- else if (id == k_BCJ) name = "BCJ";
- else if (id == k_AES)
- {
- name = "7zAES";
- if (propsSize >= 1)
- {
- Byte firstByte = props[0];
- UInt32 numCyclesPower = firstByte & 0x3F;
- ConvertUInt32ToString(numCyclesPower, s);
- }
- }
- }
-
- if (name)
- {
- unsigned nameLen = MyStringLen(name);
- unsigned propsLen = MyStringLen(s);
- unsigned totalLen = nameLen + propsLen;
- if (propsLen != 0)
- totalLen++;
- if (needSpace)
- totalLen++;
- if (totalLen + 5 >= pos)
- break;
- pos -= totalLen;
- MyStringCopy(temp + pos, name);
- if (propsLen != 0)
- {
- char *dest = temp + pos + nameLen;
- *dest++ = ':';
- MyStringCopy(dest, s);
- }
- if (needSpace)
- temp[pos + totalLen - 1] = ' ';
- }
- else
- {
- UString methodName;
- FindMethod(EXTERNAL_CODECS_VARS id64, methodName);
- if (methodName.IsEmpty())
- {
- for (unsigned j = 0; j < methodName.Len(); j++)
- if (methodName[j] >= 0x80)
- {
- methodName.Empty();
- break;
- }
- }
- if (needSpace)
- temp[--pos] = ' ';
- if (methodName.IsEmpty())
- pos -= ConvertMethodIdToString_Back(temp + pos, id64);
- else
- {
- unsigned len = methodName.Len();
- if (len + 5 > pos)
- break;
- pos -= len;
- for (unsigned i = 0; i < len; i++)
- temp[pos + i] = (char)methodName[i];
- }
- }
- }
- if (numCoders != 0 && pos >= 4)
- {
- temp[--pos] = ' ';
- temp[--pos] = '.';
- temp[--pos] = '.';
- temp[--pos] = '.';
- }
- return PropVarEm_Set_Str(prop, temp + pos);
- // }
-}
-
-#endif
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- PropVariant_Clear(value);
- // COM_TRY_BEGIN
- // NCOM::CPropVariant prop;
-
- /*
- const CRef2 &ref2 = _refs[index];
- if (ref2.Refs.IsEmpty())
- return E_FAIL;
- const CRef &ref = ref2.Refs.Front();
- */
-
- const CFileItem &item = _db.Files[index];
- UInt32 index2 = index;
-
- switch(propID)
- {
- case kpidIsDir: PropVarEm_Set_Bool(value, item.IsDir); break;
- case kpidSize:
- {
- PropVarEm_Set_UInt64(value, item.Size);
- // prop = ref2.Size;
- break;
- }
- case kpidPackSize:
- {
- // prop = ref2.PackSize;
- {
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- {
- if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2)
- PropVarEm_Set_UInt64(value, _db.GetFolderFullPackSize(folderIndex));
- /*
- else
- PropVarEm_Set_UInt64(value, 0);
- */
- }
- else
- PropVarEm_Set_UInt64(value, 0);
- }
- break;
- }
- // case kpidIsAux: prop = _db.IsItemAux(index2); break;
- case kpidPosition: { UInt64 v; if (_db.StartPos.GetItem(index2, v)) PropVarEm_Set_UInt64(value, v); break; }
- case kpidCTime: SetFileTimeProp_From_UInt64Def(value, _db.CTime, index2); break;
- case kpidATime: SetFileTimeProp_From_UInt64Def(value, _db.ATime, index2); break;
- case kpidMTime: SetFileTimeProp_From_UInt64Def(value, _db.MTime, index2); break;
- case kpidAttrib: if (item.AttribDefined) PropVarEm_Set_UInt32(value, item.Attrib); break;
- case kpidCRC: if (item.CrcDefined) PropVarEm_Set_UInt32(value, item.Crc); break;
- case kpidEncrypted: PropVarEm_Set_Bool(value, IsFolderEncrypted(_db.FileIndexToFolderIndexMap[index2])); break;
- case kpidIsAnti: PropVarEm_Set_Bool(value, _db.IsItemAnti(index2)); break;
- /*
- case kpidIsAltStream: prop = item.IsAltStream; break;
- case kpidNtSecure:
- {
- int id = _db.SecureIDs[index];
- size_t offs = _db.SecureOffsets[id];
- size_t size = _db.SecureOffsets[id + 1] - offs;
- if (size >= 0)
- {
- prop.SetBlob(_db.SecureBuf + offs, (ULONG)size);
- }
- break;
- }
- */
-
- case kpidPath: return _db.GetPath_Prop(index, value);
- #ifndef _SFX
- case kpidMethod: return SetMethodToProp(_db.FileIndexToFolderIndexMap[index2], value);
- case kpidBlock:
- {
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- PropVarEm_Set_UInt32(value, (UInt32)folderIndex);
- }
- break;
- case kpidPackedSize0:
- case kpidPackedSize1:
- case kpidPackedSize2:
- case kpidPackedSize3:
- case kpidPackedSize4:
- {
- /*
- CNum folderIndex = _db.FileIndexToFolderIndexMap[index2];
- if (folderIndex != kNumNoIndex)
- {
- const CFolder &folderInfo = _db.Folders[folderIndex];
- if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 &&
- folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0))
- {
- prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0);
- }
- else
- prop = (UInt64)0;
- }
- else
- prop = (UInt64)0;
- */
- }
- break;
- #endif
- }
- // prop.Detach(value);
- return S_OK;
- // COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *openArchiveCallback)
-{
- COM_TRY_BEGIN
- Close();
- #ifndef _SFX
- _fileInfoPopIDs.Clear();
- #endif
-
- try
- {
- CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback;
-
- #ifndef _NO_CRYPTO
- CMyComPtr<ICryptoGetTextPassword> getTextPassword;
- if (openArchiveCallback)
- openArchiveCallbackTemp.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
- #endif
-
- CInArchive archive;
- _db.IsArc = false;
- RINOK(archive.Open(stream, maxCheckStartPosition));
- _db.IsArc = true;
-
- HRESULT result = archive.ReadDatabase(
- EXTERNAL_CODECS_VARS
- _db
- #ifndef _NO_CRYPTO
- , getTextPassword, _isEncrypted, _passwordIsDefined
- #endif
- );
- RINOK(result);
-
- _inStream = stream;
- }
- catch(...)
- {
- Close();
- // return E_INVALIDARG;
- // we must return out_of_memory here
- return S_FALSE;
- }
- // _inStream = stream;
- #ifndef _SFX
- FillPopIDs();
- #endif
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- COM_TRY_BEGIN
- _inStream.Release();
- _db.Clear();
- #ifndef _NO_CRYPTO
- _isEncrypted = false;
- _passwordIsDefined = false;
- #endif
- return S_OK;
- COM_TRY_END
-}
-
-#ifdef __7Z_SET_PROPERTIES
-#ifdef EXTRACT_ONLY
-
-STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, UInt32 numProps)
-{
- COM_TRY_BEGIN
- const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
- _numThreads = numProcessors;
-
- for (UInt32 i = 0; i < numProps; i++)
- {
- UString name = names[i];
- name.MakeLower_Ascii();
- if (name.IsEmpty())
- return E_INVALIDARG;
- const PROPVARIANT &value = values[i];
- UInt32 number;
- int index = ParseStringToUInt32(name, number);
- if (index == 0)
- {
- if (name.IsPrefixedBy(L"mt"))
- {
- RINOK(ParseMtProp(name.Ptr(2), value, numProcessors, _numThreads));
- continue;
- }
- else
- return E_INVALIDARG;
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-#endif
-#endif
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.h
deleted file mode 100644
index 677a3e10a..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandler.h
+++ /dev/null
@@ -1,179 +0,0 @@
-// 7z/Handler.h
-
-#ifndef __7Z_HANDLER_H
-#define __7Z_HANDLER_H
-
-#include "../../ICoder.h"
-#include "../IArchive.h"
-
-#include "../../Common/CreateCoder.h"
-
-#ifndef EXTRACT_ONLY
-#include "../Common/HandlerOut.h"
-#endif
-
-#include "7zCompressionMode.h"
-#include "7zIn.h"
-
-namespace NArchive {
-namespace N7z {
-
-const UInt32 k_Copy = 0x0;
-const UInt32 k_Delta = 3;
-const UInt32 k_LZMA2 = 0x21;
-const UInt32 k_LZMA = 0x030101;
-const UInt32 k_PPMD = 0x030401;
-const UInt32 k_BCJ = 0x03030103;
-const UInt32 k_BCJ2 = 0x0303011B;
-const UInt32 k_Deflate = 0x040108;
-const UInt32 k_BZip2 = 0x040202;
-
-#ifndef __7Z_SET_PROPERTIES
-
-#ifdef EXTRACT_ONLY
-#if !defined(_7ZIP_ST) && !defined(_SFX)
-#define __7Z_SET_PROPERTIES
-#endif
-#else
-#define __7Z_SET_PROPERTIES
-#endif
-
-#endif
-
-
-#ifndef EXTRACT_ONLY
-
-class COutHandler: public CMultiMethodProps
-{
- HRESULT SetSolidFromString(const UString &s);
- HRESULT SetSolidFromPROPVARIANT(const PROPVARIANT &value);
-public:
- bool _removeSfxBlock;
-
- UInt64 _numSolidFiles;
- UInt64 _numSolidBytes;
- bool _numSolidBytesDefined;
- bool _solidExtension;
-
- bool _compressHeaders;
- bool _encryptHeadersSpecified;
- bool _encryptHeaders;
- // bool _useParents; 9.26
-
- CBoolPair Write_CTime;
- CBoolPair Write_ATime;
- CBoolPair Write_MTime;
-
- bool _volumeMode;
-
- void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); }
- void InitSolidSize() { _numSolidBytes = (UInt64)(Int64)(-1); }
- void InitSolid()
- {
- InitSolidFiles();
- InitSolidSize();
- _solidExtension = false;
- _numSolidBytesDefined = false;
- }
-
- void InitProps();
-
- COutHandler() { InitProps(); }
-
- HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value);
-};
-
-#endif
-
-class CHandler:
- public IInArchive,
- public IArchiveGetRawProps,
- #ifdef __7Z_SET_PROPERTIES
- public ISetProperties,
- #endif
- #ifndef EXTRACT_ONLY
- public IOutArchive,
- #endif
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
- #ifndef EXTRACT_ONLY
- , public COutHandler
- #endif
-{
-public:
- MY_QUERYINTERFACE_BEGIN2(IInArchive)
- MY_QUERYINTERFACE_ENTRY(IArchiveGetRawProps)
- #ifdef __7Z_SET_PROPERTIES
- MY_QUERYINTERFACE_ENTRY(ISetProperties)
- #endif
- #ifndef EXTRACT_ONLY
- MY_QUERYINTERFACE_ENTRY(IOutArchive)
- #endif
- QUERY_ENTRY_ISetCompressCodecsInfo
- MY_QUERYINTERFACE_END
- MY_ADDREF_RELEASE
-
- INTERFACE_IInArchive(;)
- INTERFACE_IArchiveGetRawProps(;)
-
- #ifdef __7Z_SET_PROPERTIES
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, UInt32 numProps);
- #endif
-
- #ifndef EXTRACT_ONLY
- INTERFACE_IOutArchive(;)
- #endif
-
- DECL_ISetCompressCodecsInfo
-
- CHandler();
-
-private:
- CMyComPtr<IInStream> _inStream;
- NArchive::N7z::CDbEx _db;
- #ifndef _NO_CRYPTO
- bool _isEncrypted;
- bool _passwordIsDefined;
- #endif
-
- #ifdef EXTRACT_ONLY
-
- #ifdef __7Z_SET_PROPERTIES
- UInt32 _numThreads;
- #endif
-
- UInt32 _crcSize;
-
- #else
-
- CRecordVector<CBind> _binds;
-
- HRESULT PropsMethod_To_FullMethod(CMethodFull &dest, const COneMethodInfo &m);
- HRESULT SetHeaderMethod(CCompressionMethodMode &headerMethod);
- void AddDefaultMethod();
- HRESULT SetMainMethod(CCompressionMethodMode &method,
- CObjectVector<COneMethodInfo> &methodsInfo
- #ifndef _7ZIP_ST
- , UInt32 numThreads
- #endif
- );
-
-
- #endif
-
- bool IsFolderEncrypted(CNum folderIndex) const;
- #ifndef _SFX
-
- CRecordVector<UInt64> _fileInfoPopIDs;
- void FillPopIDs();
- void AddMethodName(AString &s, UInt64 id);
- HRESULT SetMethodToProp(CNum folderIndex, PROPVARIANT *prop) const;
-
- #endif
-
- DECL_EXTERNAL_CODECS_VARS
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandlerOut.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandlerOut.cpp
deleted file mode 100644
index 7de5b8140..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHandlerOut.cpp
+++ /dev/null
@@ -1,875 +0,0 @@
-// 7zHandlerOut.cpp
-
-#include "StdAfx.h"
-
-#include "../../../Common/ComTry.h"
-#include "../../../Common/StringToInt.h"
-#include "../../../Common/Wildcard.h"
-
-#include "../Common/ItemNameUtils.h"
-#include "../Common/ParseProperties.h"
-
-#include "7zHandler.h"
-#include "7zOut.h"
-#include "7zUpdate.h"
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace N7z {
-
-static const wchar_t *k_LZMA_Name = L"LZMA";
-static const wchar_t *kDefaultMethodName = L"LZMA2";
-static const wchar_t *k_Copy_Name = L"Copy";
-
-static const wchar_t *k_MatchFinder_ForHeaders = L"BT2";
-static const UInt32 k_NumFastBytes_ForHeaders = 273;
-static const UInt32 k_Level_ForHeaders = 5;
-static const UInt32 k_Dictionary_ForHeaders =
- #ifdef UNDER_CE
- 1 << 18;
- #else
- 1 << 20;
- #endif
-
-STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)
-{
- *type = NFileTimeType::kWindows;
- return S_OK;
-}
-
-HRESULT CHandler::PropsMethod_To_FullMethod(CMethodFull &dest, const COneMethodInfo &m)
-{
- if (!FindMethod(
- EXTERNAL_CODECS_VARS
- m.MethodName, dest.Id, dest.NumInStreams, dest.NumOutStreams))
- return E_INVALIDARG;
- (CProps &)dest = (CProps &)m;
- return S_OK;
-}
-
-HRESULT CHandler::SetHeaderMethod(CCompressionMethodMode &headerMethod)
-{
- if (!_compressHeaders)
- return S_OK;
- COneMethodInfo m;
- m.MethodName = k_LZMA_Name;
- m.AddPropString(NCoderPropID::kMatchFinder, k_MatchFinder_ForHeaders);
- m.AddProp32(NCoderPropID::kLevel, k_Level_ForHeaders);
- m.AddProp32(NCoderPropID::kNumFastBytes, k_NumFastBytes_ForHeaders);
- m.AddProp32(NCoderPropID::kDictionarySize, k_Dictionary_ForHeaders);
- m.AddNumThreadsProp(1);
-
- CMethodFull methodFull;
- RINOK(PropsMethod_To_FullMethod(methodFull, m));
- headerMethod.Methods.Add(methodFull);
- return S_OK;
-}
-
-void CHandler::AddDefaultMethod()
-{
- FOR_VECTOR (i, _methods)
- {
- UString &methodName = _methods[i].MethodName;
- if (methodName.IsEmpty())
- methodName = kDefaultMethodName;
- }
- if (_methods.IsEmpty())
- {
- COneMethodInfo m;
- m.MethodName = (GetLevel() == 0 ? k_Copy_Name : kDefaultMethodName);
- _methods.Add(m);
- }
-}
-
-HRESULT CHandler::SetMainMethod(
- CCompressionMethodMode &methodMode,
- CObjectVector<COneMethodInfo> &methods
- #ifndef _7ZIP_ST
- , UInt32 numThreads
- #endif
- )
-{
- AddDefaultMethod();
-
- const UInt64 kSolidBytes_Min = (1 << 24);
- const UInt64 kSolidBytes_Max = ((UInt64)1 << 32) - 1;
-
- bool needSolid = false;
- FOR_VECTOR (i, methods)
- {
- COneMethodInfo &oneMethodInfo = methods[i];
- SetGlobalLevelAndThreads(oneMethodInfo
- #ifndef _7ZIP_ST
- , numThreads
- #endif
- );
-
- CMethodFull methodFull;
- RINOK(PropsMethod_To_FullMethod(methodFull, oneMethodInfo));
- methodMode.Methods.Add(methodFull);
-
- if (methodFull.Id != k_Copy)
- needSolid = true;
-
- if (_numSolidBytesDefined)
- continue;
-
- UInt32 dicSize;
- switch (methodFull.Id)
- {
- case k_LZMA:
- case k_LZMA2: dicSize = oneMethodInfo.Get_Lzma_DicSize(); break;
- case k_PPMD: dicSize = oneMethodInfo.Get_Ppmd_MemSize(); break;
- case k_Deflate: dicSize = (UInt32)1 << 15; break;
- case k_BZip2: dicSize = oneMethodInfo.Get_BZip2_BlockSize(); break;
- default: continue;
- }
- _numSolidBytes = (UInt64)dicSize << 7;
- if (_numSolidBytes < kSolidBytes_Min) _numSolidBytes = kSolidBytes_Min;
- if (_numSolidBytes > kSolidBytes_Max) _numSolidBytes = kSolidBytes_Max;
- _numSolidBytesDefined = true;
- }
-
- if (!_numSolidBytesDefined)
- if (needSolid)
- _numSolidBytes = kSolidBytes_Max;
- else
- _numSolidBytes = 0;
- _numSolidBytesDefined = true;
- return S_OK;
-}
-
-static HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, PROPID propID, UInt64 &ft, bool &ftDefined)
-{
- // ft = 0;
- // ftDefined = false;
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(index, propID, &prop));
- if (prop.vt == VT_FILETIME)
- {
- ft = prop.filetime.dwLowDateTime | ((UInt64)prop.filetime.dwHighDateTime << 32);
- ftDefined = true;
- }
- else if (prop.vt != VT_EMPTY)
- return E_INVALIDARG;
- else
- {
- ft = 0;
- ftDefined = false;
- }
- return S_OK;
-}
-
-/*
-
-#ifdef _WIN32
-static const wchar_t kDirDelimiter1 = L'\\';
-#endif
-static const wchar_t kDirDelimiter2 = L'/';
-
-static inline bool IsCharDirLimiter(wchar_t c)
-{
- return (
- #ifdef _WIN32
- c == kDirDelimiter1 ||
- #endif
- c == kDirDelimiter2);
-}
-
-static int FillSortIndex(CObjectVector<CTreeFolder> &treeFolders, int cur, int curSortIndex)
-{
- CTreeFolder &tf = treeFolders[cur];
- tf.SortIndex = curSortIndex++;
- for (int i = 0; i < tf.SubFolders.Size(); i++)
- curSortIndex = FillSortIndex(treeFolders, tf.SubFolders[i], curSortIndex);
- tf.SortIndexEnd = curSortIndex;
- return curSortIndex;
-}
-
-static int FindSubFolder(const CObjectVector<CTreeFolder> &treeFolders, int cur, const UString &name, int &insertPos)
-{
- const CIntVector &subFolders = treeFolders[cur].SubFolders;
- int left = 0, right = subFolders.Size();
- insertPos = -1;
- for (;;)
- {
- if (left == right)
- {
- insertPos = left;
- return -1;
- }
- int mid = (left + right) / 2;
- int midFolder = subFolders[mid];
- int compare = CompareFileNames(name, treeFolders[midFolder].Name);
- if (compare == 0)
- return midFolder;
- if (compare < 0)
- right = mid;
- else
- left = mid + 1;
- }
-}
-
-static int AddFolder(CObjectVector<CTreeFolder> &treeFolders, int cur, const UString &name)
-{
- int insertPos;
- int folderIndex = FindSubFolder(treeFolders, cur, name, insertPos);
- if (folderIndex < 0)
- {
- folderIndex = treeFolders.Size();
- CTreeFolder &newFolder = treeFolders.AddNew();
- newFolder.Parent = cur;
- newFolder.Name = name;
- treeFolders[cur].SubFolders.Insert(insertPos, folderIndex);
- }
- // else if (treeFolders[folderIndex].IsAltStreamFolder != isAltStreamFolder) throw 1123234234;
- return folderIndex;
-}
-*/
-
-STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
- IArchiveUpdateCallback *updateCallback)
-{
- COM_TRY_BEGIN
-
- const CDbEx *db = 0;
- #ifdef _7Z_VOL
- if (_volumes.Size() > 1)
- return E_FAIL;
- const CVolume *volume = 0;
- if (_volumes.Size() == 1)
- {
- volume = &_volumes.Front();
- db = &volume->Database;
- }
- #else
- if (_inStream != 0)
- db = &_db;
- #endif
-
- /*
- CMyComPtr<IArchiveGetRawProps> getRawProps;
- updateCallback->QueryInterface(IID_IArchiveGetRawProps, (void **)&getRawProps);
-
- CUniqBlocks secureBlocks;
- secureBlocks.AddUniq(NULL, 0);
-
- CObjectVector<CTreeFolder> treeFolders;
- {
- CTreeFolder folder;
- folder.Parent = -1;
- treeFolders.Add(folder);
- }
- */
-
- CObjectVector<CUpdateItem> updateItems;
-
- bool need_CTime = (Write_CTime.Def && Write_CTime.Val);
- bool need_ATime = (Write_ATime.Def && Write_ATime.Val);
- bool need_MTime = (Write_MTime.Def && Write_MTime.Val || !Write_MTime.Def);
- if (db)
- {
- if (!Write_CTime.Def) need_CTime = !db->CTime.Defs.IsEmpty();
- if (!Write_ATime.Def) need_ATime = !db->ATime.Defs.IsEmpty();
- if (!Write_MTime.Def) need_MTime = !db->MTime.Defs.IsEmpty();
- }
-
- UString s;
-
- for (UInt32 i = 0; i < numItems; i++)
- {
- Int32 newData, newProps;
- UInt32 indexInArchive;
- if (!updateCallback)
- return E_FAIL;
- RINOK(updateCallback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArchive));
- CUpdateItem ui;
- ui.NewProps = IntToBool(newProps);
- ui.NewData = IntToBool(newData);
- ui.IndexInArchive = indexInArchive;
- ui.IndexInClient = i;
- ui.IsAnti = false;
- ui.Size = 0;
-
- UString name;
- // bool isAltStream = false;
- if (ui.IndexInArchive != -1)
- {
- if (db == 0 || (unsigned)ui.IndexInArchive >= db->Files.Size())
- return E_INVALIDARG;
- const CFileItem &fi = db->Files[ui.IndexInArchive];
- if (!ui.NewProps)
- {
- _db.GetPath(ui.IndexInArchive, name);
- }
- ui.IsDir = fi.IsDir;
- ui.Size = fi.Size;
- // isAltStream = fi.IsAltStream;
- ui.IsAnti = db->IsItemAnti(ui.IndexInArchive);
-
- if (!ui.NewProps)
- {
- ui.CTimeDefined = db->CTime.GetItem(ui.IndexInArchive, ui.CTime);
- ui.ATimeDefined = db->ATime.GetItem(ui.IndexInArchive, ui.ATime);
- ui.MTimeDefined = db->MTime.GetItem(ui.IndexInArchive, ui.MTime);
- }
- }
-
- if (ui.NewProps)
- {
- bool folderStatusIsDefined;
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(i, kpidAttrib, &prop));
- if (prop.vt == VT_EMPTY)
- ui.AttribDefined = false;
- else if (prop.vt != VT_UI4)
- return E_INVALIDARG;
- else
- {
- ui.Attrib = prop.ulVal;
- ui.AttribDefined = true;
- }
- }
-
- // we need MTime to sort files.
- if (need_CTime) RINOK(GetTime(updateCallback, i, kpidCTime, ui.CTime, ui.CTimeDefined));
- if (need_ATime) RINOK(GetTime(updateCallback, i, kpidATime, ui.ATime, ui.ATimeDefined));
- if (need_MTime) RINOK(GetTime(updateCallback, i, kpidMTime, ui.MTime, ui.MTimeDefined));
-
- /*
- if (getRawProps)
- {
- const void *data;
- UInt32 dataSize;
- UInt32 propType;
-
- getRawProps->GetRawProp(i, kpidNtSecure, &data, &dataSize, &propType);
- if (dataSize != 0 && propType != NPropDataType::kRaw)
- return E_FAIL;
- ui.SecureIndex = secureBlocks.AddUniq((const Byte *)data, dataSize);
- }
- */
-
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(i, kpidPath, &prop));
- if (prop.vt == VT_EMPTY)
- {
- }
- else if (prop.vt != VT_BSTR)
- return E_INVALIDARG;
- else
- {
- name = NItemName::MakeLegalName(prop.bstrVal);
- }
- }
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(i, kpidIsDir, &prop));
- if (prop.vt == VT_EMPTY)
- folderStatusIsDefined = false;
- else if (prop.vt != VT_BOOL)
- return E_INVALIDARG;
- else
- {
- ui.IsDir = (prop.boolVal != VARIANT_FALSE);
- folderStatusIsDefined = true;
- }
- }
-
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(i, kpidIsAnti, &prop));
- if (prop.vt == VT_EMPTY)
- ui.IsAnti = false;
- else if (prop.vt != VT_BOOL)
- return E_INVALIDARG;
- else
- ui.IsAnti = (prop.boolVal != VARIANT_FALSE);
- }
-
- /*
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(i, kpidIsAltStream, &prop));
- if (prop.vt == VT_EMPTY)
- isAltStream = false;
- else if (prop.vt != VT_BOOL)
- return E_INVALIDARG;
- else
- isAltStream = (prop.boolVal != VARIANT_FALSE);
- }
- */
-
- if (ui.IsAnti)
- {
- ui.AttribDefined = false;
-
- ui.CTimeDefined = false;
- ui.ATimeDefined = false;
- ui.MTimeDefined = false;
-
- ui.Size = 0;
- }
-
- if (!folderStatusIsDefined && ui.AttribDefined)
- ui.SetDirStatusFromAttrib();
- }
- else
- {
- /*
- if (_db.SecureIDs.IsEmpty())
- ui.SecureIndex = secureBlocks.AddUniq(NULL, 0);
- else
- {
- int id = _db.SecureIDs[ui.IndexInArchive];
- size_t offs = _db.SecureOffsets[id];
- size_t size = _db.SecureOffsets[id + 1] - offs;
- ui.SecureIndex = secureBlocks.AddUniq(_db.SecureBuf + offs, size);
- }
- */
- }
-
- /*
- {
- int folderIndex = 0;
- if (_useParents)
- {
- int j;
- s.Empty();
- for (j = 0; j < name.Len(); j++)
- {
- wchar_t c = name[j];
- if (IsCharDirLimiter(c))
- {
- folderIndex = AddFolder(treeFolders, folderIndex, s);
- s.Empty();
- continue;
- }
- s += c;
- }
- if (isAltStream)
- {
- int colonPos = s.Find(':');
- if (colonPos < 0)
- {
- // isAltStream = false;
- return E_INVALIDARG;
- }
- UString mainName = s.Left(colonPos);
- int newFolderIndex = AddFolder(treeFolders, folderIndex, mainName);
- if (treeFolders[newFolderIndex].UpdateItemIndex < 0)
- {
- for (int j = updateItems.Size() - 1; j >= 0; j--)
- {
- CUpdateItem &ui2 = updateItems[j];
- if (ui2.ParentFolderIndex == folderIndex
- && ui2.Name == mainName)
- {
- ui2.TreeFolderIndex = newFolderIndex;
- treeFolders[newFolderIndex].UpdateItemIndex = j;
- }
- }
- }
- folderIndex = newFolderIndex;
- s.Delete(0, colonPos + 1);
- }
- ui.Name = s;
- }
- else
- ui.Name = name;
- ui.IsAltStream = isAltStream;
- ui.ParentFolderIndex = folderIndex;
- ui.TreeFolderIndex = -1;
- if (ui.IsDir && !s.IsEmpty())
- {
- ui.TreeFolderIndex = AddFolder(treeFolders, folderIndex, s);
- treeFolders[ui.TreeFolderIndex].UpdateItemIndex = updateItems.Size();
- }
- }
- */
- ui.Name = name;
-
- if (ui.NewData)
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(i, kpidSize, &prop));
- if (prop.vt != VT_UI8)
- return E_INVALIDARG;
- ui.Size = (UInt64)prop.uhVal.QuadPart;
- if (ui.Size != 0 && ui.IsAnti)
- return E_INVALIDARG;
- }
- updateItems.Add(ui);
- }
-
- /*
- FillSortIndex(treeFolders, 0, 0);
- for (i = 0; i < (UInt32)updateItems.Size(); i++)
- {
- CUpdateItem &ui = updateItems[i];
- ui.ParentSortIndex = treeFolders[ui.ParentFolderIndex].SortIndex;
- ui.ParentSortIndexEnd = treeFolders[ui.ParentFolderIndex].SortIndexEnd;
- }
- */
-
- CCompressionMethodMode methodMode, headerMethod;
-
- HRESULT res = SetMainMethod(methodMode, _methods
- #ifndef _7ZIP_ST
- , _numThreads
- #endif
- );
- RINOK(res);
- methodMode.Binds = _binds;
-
- RINOK(SetHeaderMethod(headerMethod));
- #ifndef _7ZIP_ST
- methodMode.NumThreads = _numThreads;
- headerMethod.NumThreads = 1;
- #endif
-
- CMyComPtr<ICryptoGetTextPassword2> getPassword2;
- updateCallback->QueryInterface(IID_ICryptoGetTextPassword2, (void **)&getPassword2);
-
- methodMode.PasswordIsDefined = false;
- methodMode.Password.Empty();
- if (getPassword2)
- {
- CMyComBSTR password;
- Int32 passwordIsDefined;
- RINOK(getPassword2->CryptoGetTextPassword2(&passwordIsDefined, &password));
- methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);
- if (methodMode.PasswordIsDefined && (BSTR)password)
- methodMode.Password = password;
- }
-
- bool compressMainHeader = _compressHeaders; // check it
-
- bool encryptHeaders = false;
-
- if (methodMode.PasswordIsDefined)
- {
- if (_encryptHeadersSpecified)
- encryptHeaders = _encryptHeaders;
- #ifndef _NO_CRYPTO
- else
- encryptHeaders = _passwordIsDefined;
- #endif
- compressMainHeader = true;
- if (encryptHeaders)
- {
- headerMethod.PasswordIsDefined = methodMode.PasswordIsDefined;
- headerMethod.Password = methodMode.Password;
- }
- }
-
- if (numItems < 2)
- compressMainHeader = false;
-
- CUpdateOptions options;
- options.Method = &methodMode;
- options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;
- int level = GetLevel();
- options.UseFilters = level != 0 && _autoFilter;
- options.MaxFilter = level >= 8;
-
- options.HeaderOptions.CompressMainHeader = compressMainHeader;
- /*
- options.HeaderOptions.WriteCTime = Write_CTime;
- options.HeaderOptions.WriteATime = Write_ATime;
- options.HeaderOptions.WriteMTime = Write_MTime;
- */
-
- options.NumSolidFiles = _numSolidFiles;
- options.NumSolidBytes = _numSolidBytes;
- options.SolidExtension = _solidExtension;
- options.RemoveSfxBlock = _removeSfxBlock;
- options.VolumeMode = _volumeMode;
-
- COutArchive archive;
- CArchiveDatabaseOut newDatabase;
-
- CMyComPtr<ICryptoGetTextPassword> getPassword;
- updateCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getPassword);
-
- /*
- if (secureBlocks.Sorted.Size() > 1)
- {
- secureBlocks.GetReverseMap();
- for (int i = 0; i < updateItems.Size(); i++)
- {
- int &secureIndex = updateItems[i].SecureIndex;
- secureIndex = secureBlocks.BufIndexToSortedIndex[secureIndex];
- }
- }
- */
-
- res = Update(
- EXTERNAL_CODECS_VARS
- #ifdef _7Z_VOL
- volume ? volume->Stream: 0,
- volume ? db : 0,
- #else
- _inStream,
- db,
- #endif
- updateItems,
- // treeFolders,
- // secureBlocks,
- archive, newDatabase, outStream, updateCallback, options
- #ifndef _NO_CRYPTO
- , getPassword
- #endif
- );
-
- RINOK(res);
-
- updateItems.ClearAndFree();
-
- return archive.WriteDatabase(EXTERNAL_CODECS_VARS
- newDatabase, options.HeaderMethod, options.HeaderOptions);
-
- COM_TRY_END
-}
-
-static HRESULT GetBindInfoPart(UString &srcString, UInt32 &coder, UInt32 &stream)
-{
- stream = 0;
- int index = ParseStringToUInt32(srcString, coder);
- if (index == 0)
- return E_INVALIDARG;
- srcString.Delete(0, index);
- if (srcString[0] == 's')
- {
- srcString.Delete(0);
- int index = ParseStringToUInt32(srcString, stream);
- if (index == 0)
- return E_INVALIDARG;
- srcString.Delete(0, index);
- }
- return S_OK;
-}
-
-void COutHandler::InitProps()
-{
- CMultiMethodProps::Init();
-
- _removeSfxBlock = false;
- _compressHeaders = true;
- _encryptHeadersSpecified = false;
- _encryptHeaders = false;
- // _useParents = false;
-
- Write_CTime.Init();
- Write_ATime.Init();
- Write_MTime.Init();
-
- _volumeMode = false;
- InitSolid();
-}
-
-HRESULT COutHandler::SetSolidFromString(const UString &s)
-{
- UString s2 = s;
- s2.MakeLower_Ascii();
- for (unsigned i = 0; i < s2.Len();)
- {
- const wchar_t *start = ((const wchar_t *)s2) + i;
- const wchar_t *end;
- UInt64 v = ConvertStringToUInt64(start, &end);
- if (start == end)
- {
- if (s2[i++] != 'e')
- return E_INVALIDARG;
- _solidExtension = true;
- continue;
- }
- i += (int)(end - start);
- if (i == s2.Len())
- return E_INVALIDARG;
- wchar_t c = s2[i++];
- if (c == 'f')
- {
- if (v < 1)
- v = 1;
- _numSolidFiles = v;
- }
- else
- {
- unsigned numBits;
- switch (c)
- {
- case 'b': numBits = 0; break;
- case 'k': numBits = 10; break;
- case 'm': numBits = 20; break;
- case 'g': numBits = 30; break;
- case 't': numBits = 40; break;
- default: return E_INVALIDARG;
- }
- _numSolidBytes = (v << numBits);
- _numSolidBytesDefined = true;
- }
- }
- return S_OK;
-}
-
-HRESULT COutHandler::SetSolidFromPROPVARIANT(const PROPVARIANT &value)
-{
- bool isSolid;
- switch (value.vt)
- {
- case VT_EMPTY: isSolid = true; break;
- case VT_BOOL: isSolid = (value.boolVal != VARIANT_FALSE); break;
- case VT_BSTR:
- if (StringToBool(value.bstrVal, isSolid))
- break;
- return SetSolidFromString(value.bstrVal);
- default: return E_INVALIDARG;
- }
- if (isSolid)
- InitSolid();
- else
- _numSolidFiles = 1;
- return S_OK;
-}
-
-static HRESULT PROPVARIANT_to_BoolPair(const PROPVARIANT &prop, CBoolPair &dest)
-{
- RINOK(PROPVARIANT_to_bool(prop, dest.Val));
- dest.Def = true;
- return S_OK;
-}
-
-HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value)
-{
- UString name = nameSpec;
- name.MakeLower_Ascii();
- if (name.IsEmpty())
- return E_INVALIDARG;
-
- if (name[0] == L's')
- {
- name.Delete(0);
- if (name.IsEmpty())
- return SetSolidFromPROPVARIANT(value);
- if (value.vt != VT_EMPTY)
- return E_INVALIDARG;
- return SetSolidFromString(name);
- }
-
- UInt32 number;
- int index = ParseStringToUInt32(name, number);
- UString realName = name.Ptr(index);
- if (index == 0)
- {
- if (name.IsEqualTo("rsfx")) return PROPVARIANT_to_bool(value, _removeSfxBlock);
- if (name.IsEqualTo("hc")) return PROPVARIANT_to_bool(value, _compressHeaders);
- // if (name.IsEqualToNoCase(L"HS")) return PROPVARIANT_to_bool(value, _useParents);
-
- if (name.IsEqualTo("hcf"))
- {
- bool compressHeadersFull = true;
- RINOK(PROPVARIANT_to_bool(value, compressHeadersFull));
- return compressHeadersFull ? S_OK: E_INVALIDARG;
- }
-
- if (name.IsEqualTo("he"))
- {
- RINOK(PROPVARIANT_to_bool(value, _encryptHeaders));
- _encryptHeadersSpecified = true;
- return S_OK;
- }
-
- if (name.IsEqualTo("tc")) return PROPVARIANT_to_BoolPair(value, Write_CTime);
- if (name.IsEqualTo("ta")) return PROPVARIANT_to_BoolPair(value, Write_ATime);
- if (name.IsEqualTo("tm")) return PROPVARIANT_to_BoolPair(value, Write_MTime);
-
- if (name.IsEqualTo("v")) return PROPVARIANT_to_bool(value, _volumeMode);
- }
- return CMultiMethodProps::SetProperty(name, value);
-}
-
-STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, UInt32 numProps)
-{
- COM_TRY_BEGIN
- _binds.Clear();
- InitProps();
-
- for (UInt32 i = 0; i < numProps; i++)
- {
- UString name = names[i];
- name.MakeLower_Ascii();
- if (name.IsEmpty())
- return E_INVALIDARG;
-
- const PROPVARIANT &value = values[i];
-
- if (name[0] == 'b')
- {
- if (value.vt != VT_EMPTY)
- return E_INVALIDARG;
- name.Delete(0);
- CBind bind;
- RINOK(GetBindInfoPart(name, bind.OutCoder, bind.OutStream));
- if (name[0] != ':')
- return E_INVALIDARG;
- name.Delete(0);
- RINOK(GetBindInfoPart(name, bind.InCoder, bind.InStream));
- if (!name.IsEmpty())
- return E_INVALIDARG;
- _binds.Add(bind);
- continue;
- }
-
- RINOK(SetProperty(name, value));
- }
-
- unsigned numEmptyMethods = GetNumEmptyMethods();
- if (numEmptyMethods > 0)
- {
- unsigned k;
- for (k = 0; k < _binds.Size(); k++)
- {
- const CBind &bind = _binds[k];
- if (bind.InCoder < (UInt32)numEmptyMethods ||
- bind.OutCoder < (UInt32)numEmptyMethods)
- return E_INVALIDARG;
- }
- for (k = 0; k < _binds.Size(); k++)
- {
- CBind &bind = _binds[k];
- bind.InCoder -= (UInt32)numEmptyMethods;
- bind.OutCoder -= (UInt32)numEmptyMethods;
- }
- _methods.DeleteFrontal(numEmptyMethods);
- }
-
- AddDefaultMethod();
-
- if (!_filterMethod.MethodName.IsEmpty())
- {
- FOR_VECTOR (k, _binds)
- {
- CBind &bind = _binds[k];
- bind.InCoder++;
- bind.OutCoder++;
- }
- _methods.Insert(0, _filterMethod);
- }
-
- FOR_VECTOR (k, _binds)
- {
- const CBind &bind = _binds[k];
- if (bind.InCoder >= (UInt32)_methods.Size() ||
- bind.OutCoder >= (UInt32)_methods.Size())
- return E_INVALIDARG;
- }
-
- return S_OK;
- COM_TRY_END
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.cpp
deleted file mode 100644
index acff2fdd8..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// 7zHeader.cpp
-
-#include "StdAfx.h"
-
-#include "7zHeader.h"
-
-namespace NArchive {
-namespace N7z {
-
-Byte kSignature[kSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
-#ifdef _7Z_VOL
-Byte kFinishSignature[kSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C + 1};
-#endif
-
-// We can change signature. So file doesn't contain correct signature.
-// struct SignatureInitializer { SignatureInitializer() { kSignature[0]--; } };
-// static SignatureInitializer g_SignatureInitializer;
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.h
deleted file mode 100644
index 61dad655d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zHeader.h
+++ /dev/null
@@ -1,101 +0,0 @@
-// 7z/7zHeader.h
-
-#ifndef __7Z_HEADER_H
-#define __7Z_HEADER_H
-
-#include "../../../Common/MyTypes.h"
-
-namespace NArchive {
-namespace N7z {
-
-const unsigned kSignatureSize = 6;
-extern Byte kSignature[kSignatureSize];
-
-// #define _7Z_VOL
-// 7z-MultiVolume is not finished yet.
-// It can work already, but I still do not like some
-// things of that new multivolume format.
-// So please keep it commented.
-
-#ifdef _7Z_VOL
-extern Byte kFinishSignature[kSignatureSize];
-#endif
-
-struct CArchiveVersion
-{
- Byte Major;
- Byte Minor;
-};
-
-const Byte kMajorVersion = 0;
-
-struct CStartHeader
-{
- UInt64 NextHeaderOffset;
- UInt64 NextHeaderSize;
- UInt32 NextHeaderCRC;
-};
-
-const UInt32 kStartHeaderSize = 20;
-
-#ifdef _7Z_VOL
-struct CFinishHeader: public CStartHeader
-{
- UInt64 ArchiveStartOffset; // data offset from end if that struct
- UInt64 AdditionalStartBlockSize; // start signature & start header size
-};
-
-const UInt32 kFinishHeaderSize = kStartHeaderSize + 16;
-#endif
-
-namespace NID
-{
- enum EEnum
- {
- kEnd,
-
- kHeader,
-
- kArchiveProperties,
-
- kAdditionalStreamsInfo,
- kMainStreamsInfo,
- kFilesInfo,
-
- kPackInfo,
- kUnpackInfo,
- kSubStreamsInfo,
-
- kSize,
- kCRC,
-
- kFolder,
-
- kCodersUnpackSize,
- kNumUnpackStream,
-
- kEmptyStream,
- kEmptyFile,
- kAnti,
-
- kName,
- kCTime,
- kATime,
- kMTime,
- kWinAttrib,
- kComment,
-
- kEncodedHeader,
-
- kStartPos,
- kDummy
-
- // kNtSecure,
- // kParent,
- // kIsAux
- };
-}
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.cpp
deleted file mode 100644
index 28ec5e083..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.cpp
+++ /dev/null
@@ -1,1679 +0,0 @@
-// 7zIn.cpp
-
-#include "StdAfx.h"
-
-#ifdef _WIN32
-#include <wchar.h>
-#else
-#include <ctype.h>
-#endif
-
-#include "../../../../C/7zCrc.h"
-#include "../../../../C/CpuArch.h"
-
-#include "../../Common/StreamObjects.h"
-#include "../../Common/StreamUtils.h"
-
-#include "7zDecode.h"
-#include "7zIn.h"
-
-#define Get16(p) GetUi16(p)
-#define Get32(p) GetUi32(p)
-#define Get64(p) GetUi64(p)
-
-// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader
-#ifndef _SFX
-#define FORMAT_7Z_RECOVERY
-#endif
-
-using namespace NWindows;
-using namespace NCOM;
-
-namespace NArchive {
-namespace N7z {
-
-static const UInt32 k_LZMA2 = 0x21;
-static const UInt32 k_LZMA = 0x030101;
-
-static void BoolVector_Fill_False(CBoolVector &v, unsigned size)
-{
- v.ClearAndSetSize(size);
- bool *p = &v[0];
- for (unsigned i = 0; i < size; i++)
- p[i] = false;
-}
-
-static bool BoolVector_GetAndSet(CBoolVector &v, UInt32 index)
-{
- if (index >= (UInt32)v.Size())
- return true;
- bool res = v[index];
- v[index] = true;
- return res;
-}
-
-bool CFolder::CheckStructure(unsigned numUnpackSizes) const
-{
- const unsigned kNumCodersMax = sizeof(UInt32) * 8; // don't change it
- const unsigned kMaskSize = sizeof(UInt32) * 8; // it must be >= kNumCodersMax
- const unsigned kNumBindsMax = 32;
-
- if (Coders.Size() > kNumCodersMax || BindPairs.Size() > kNumBindsMax)
- return false;
-
- {
- CBoolVector v;
- BoolVector_Fill_False(v, BindPairs.Size() + PackStreams.Size());
-
- unsigned i;
- for (i = 0; i < BindPairs.Size(); i++)
- if (BoolVector_GetAndSet(v, BindPairs[i].InIndex))
- return false;
- for (i = 0; i < PackStreams.Size(); i++)
- if (BoolVector_GetAndSet(v, PackStreams[i]))
- return false;
-
- BoolVector_Fill_False(v, numUnpackSizes);
- for (i = 0; i < BindPairs.Size(); i++)
- if (BoolVector_GetAndSet(v, BindPairs[i].OutIndex))
- return false;
- }
-
- UInt32 mask[kMaskSize];
- unsigned i;
- for (i = 0; i < kMaskSize; i++)
- mask[i] = 0;
-
- {
- CUIntVector inStreamToCoder, outStreamToCoder;
- for (i = 0; i < Coders.Size(); i++)
- {
- CNum j;
- const CCoderInfo &coder = Coders[i];
- for (j = 0; j < coder.NumInStreams; j++)
- inStreamToCoder.Add(i);
- for (j = 0; j < coder.NumOutStreams; j++)
- outStreamToCoder.Add(i);
- }
-
- for (i = 0; i < BindPairs.Size(); i++)
- {
- const CBindPair &bp = BindPairs[i];
- mask[inStreamToCoder[bp.InIndex]] |= (1 << outStreamToCoder[bp.OutIndex]);
- }
- }
-
- for (i = 0; i < kMaskSize; i++)
- for (unsigned j = 0; j < kMaskSize; j++)
- if (((1 << j) & mask[i]) != 0)
- mask[i] |= mask[j];
-
- for (i = 0; i < kMaskSize; i++)
- if (((1 << i) & mask[i]) != 0)
- return false;
-
- return true;
-}
-
-class CInArchiveException {};
-class CUnsupportedFeatureException: public CInArchiveException {};
-
-static void ThrowException() { throw CInArchiveException(); }
-static inline void ThrowEndOfData() { ThrowException(); }
-static inline void ThrowUnsupported() { throw CUnsupportedFeatureException(); }
-static inline void ThrowIncorrect() { ThrowException(); }
-
-class CStreamSwitch
-{
- CInArchive *_archive;
- bool _needRemove;
- bool _needUpdatePos;
-public:
- CStreamSwitch(): _needRemove(false), _needUpdatePos(false) {}
- ~CStreamSwitch() { Remove(); }
- void Remove();
- void Set(CInArchive *archive, const Byte *data, size_t size, bool needUpdatePos);
- void Set(CInArchive *archive, const CByteBuffer &byteBuffer);
- void Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector);
-};
-
-void CStreamSwitch::Remove()
-{
- if (_needRemove)
- {
- if (_archive->_inByteBack->GetRem() != 0)
- _archive->ThereIsHeaderError = true;
- _archive->DeleteByteStream(_needUpdatePos);
- _needRemove = false;
- }
-}
-
-void CStreamSwitch::Set(CInArchive *archive, const Byte *data, size_t size, bool needUpdatePos)
-{
- Remove();
- _archive = archive;
- _archive->AddByteStream(data, size);
- _needRemove = true;
- _needUpdatePos = needUpdatePos;
-}
-
-void CStreamSwitch::Set(CInArchive *archive, const CByteBuffer &byteBuffer)
-{
- Set(archive, byteBuffer, byteBuffer.Size(), false);
-}
-
-void CStreamSwitch::Set(CInArchive *archive, const CObjectVector<CByteBuffer> *dataVector)
-{
- Remove();
- Byte external = archive->ReadByte();
- if (external != 0)
- {
- CNum dataIndex = archive->ReadNum();
- if (dataIndex >= dataVector->Size())
- ThrowIncorrect();
- Set(archive, (*dataVector)[dataIndex]);
- }
-}
-
-void CInArchive::AddByteStream(const Byte *buf, size_t size)
-{
- if (_numInByteBufs == kNumBufLevelsMax)
- ThrowIncorrect();
- _inByteBack = &_inByteVector[_numInByteBufs++];
- _inByteBack->Init(buf, size);
-}
-
-
-Byte CInByte2::ReadByte()
-{
- if (_pos >= _size)
- ThrowEndOfData();
- return _buffer[_pos++];
-}
-
-void CInByte2::ReadBytes(Byte *data, size_t size)
-{
- if (size > _size - _pos)
- ThrowEndOfData();
- memcpy(data, _buffer + _pos, size);
- _pos += size;
-}
-
-void CInByte2::SkipData(UInt64 size)
-{
- if (size > _size - _pos)
- ThrowEndOfData();
- _pos += (size_t)size;
-}
-
-void CInByte2::SkipData()
-{
- SkipData(ReadNumber());
-}
-
-static UInt64 ReadNumberSpec(const Byte *p, size_t size, size_t &processed)
-{
- if (size == 0)
- {
- processed = 0;
- return 0;
- }
- Byte firstByte = *p++;
- size--;
- if ((firstByte & 0x80) == 0)
- {
- processed = 1;
- return firstByte;
- }
- Byte mask = 0x40;
- if (size == 0)
- {
- processed = 0;
- return 0;
- }
- UInt64 value = (UInt64)*p;
- p++;
- size--;
- for (unsigned i = 1; i < 8; i++)
- {
- if ((firstByte & mask) == 0)
- {
- UInt64 highPart = firstByte & (mask - 1);
- value += (highPart << (i * 8));
- processed = i + 1;
- return value;
- }
- if (size == 0)
- {
- processed = 0;
- return 0;
- }
- value |= ((UInt64)*p << (i * 8));
- p++;
- size--;
- mask >>= 1;
- }
- processed = 9;
- return value;
-}
-
-UInt64 CInByte2::ReadNumber()
-{
- size_t processed;
- UInt64 res = ReadNumberSpec(_buffer + _pos, _size - _pos, processed);
- if (processed == 0)
- ThrowEndOfData();
- _pos += processed;
- return res;
-}
-
-CNum CInByte2::ReadNum()
-{
- /*
- if (_pos < _size)
- {
- Byte val = _buffer[_pos];
- if ((unsigned)val < 0x80)
- {
- _pos++;
- return (unsigned)val;
- }
- }
- */
- UInt64 value = ReadNumber();
- if (value > kNumMax)
- ThrowUnsupported();
- return (CNum)value;
-}
-
-UInt32 CInByte2::ReadUInt32()
-{
- if (_pos + 4 > _size)
- ThrowEndOfData();
- UInt32 res = Get32(_buffer + _pos);
- _pos += 4;
- return res;
-}
-
-UInt64 CInByte2::ReadUInt64()
-{
- if (_pos + 8 > _size)
- ThrowEndOfData();
- UInt64 res = Get64(_buffer + _pos);
- _pos += 8;
- return res;
-}
-
-#define CHECK_SIGNATURE if (p[0] != '7' || p[1] != 'z' || p[2] != 0xBC || p[3] != 0xAF || p[4] != 0x27 || p[5] != 0x1C) return false;
-
-static inline bool TestSignature(const Byte *p)
-{
- CHECK_SIGNATURE
- return CrcCalc(p + 12, 20) == Get32(p + 8);
-}
-
-#ifdef FORMAT_7Z_RECOVERY
-static inline bool TestSignature2(const Byte *p)
-{
- CHECK_SIGNATURE;
- if (CrcCalc(p + 12, 20) == Get32(p + 8))
- return true;
- for (unsigned i = 8; i < kHeaderSize; i++)
- if (p[i] != 0)
- return false;
- return (p[6] != 0 || p[7] != 0);
-}
-#else
-#define TestSignature2(p) TestSignature(p)
-#endif
-
-HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
-{
- RINOK(ReadStream_FALSE(stream, _header, kHeaderSize));
-
- if (TestSignature2(_header))
- return S_OK;
- if (searchHeaderSizeLimit && *searchHeaderSizeLimit == 0)
- return S_FALSE;
-
- const UInt32 kBufSize = 1 << 15;
- CByteArr buf(kBufSize);
- memcpy(buf, _header, kHeaderSize);
- UInt64 offset = 0;
-
- for (;;)
- {
- UInt32 readSize = kBufSize - kHeaderSize;
- {
- UInt64 rem = *searchHeaderSizeLimit - offset;
- if (readSize > rem)
- readSize = (UInt32)rem;
- if (readSize == 0)
- return S_FALSE;
- }
- UInt32 processed = 0;
- RINOK(stream->Read(buf + kHeaderSize, readSize, &processed));
- if (processed == 0)
- return S_FALSE;
- for (UInt32 pos = 0;;)
- {
- const Byte *p = buf + pos + 1;
- const Byte *lim = buf + processed;
- for (; p <= lim; p += 4)
- {
- if (p[0] == '7') break;
- if (p[1] == '7') { p += 1; break; }
- if (p[2] == '7') { p += 2; break; }
- if (p[3] == '7') { p += 3; break; }
- };
- if (p > lim)
- break;
- pos = (UInt32)(p - buf);
- if (TestSignature(p))
- {
- memcpy(_header, p, kHeaderSize);
- _arhiveBeginStreamPosition += offset + pos;
- return stream->Seek(_arhiveBeginStreamPosition + kHeaderSize, STREAM_SEEK_SET, NULL);
- }
- }
- offset += processed;
- memmove(buf, buf + processed, kHeaderSize);
- }
-}
-
-// S_FALSE means that file is not archive
-HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
-{
- HeadersSize = 0;
- Close();
- RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_arhiveBeginStreamPosition))
- RINOK(stream->Seek(0, STREAM_SEEK_END, &_fileEndPosition))
- RINOK(stream->Seek(_arhiveBeginStreamPosition, STREAM_SEEK_SET, NULL))
- RINOK(FindAndReadSignature(stream, searchHeaderSizeLimit));
- _stream = stream;
- return S_OK;
-}
-
-void CInArchive::Close()
-{
- _numInByteBufs = 0;
- _stream.Release();
- ThereIsHeaderError = false;
-}
-
-void CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)
-{
- for (;;)
- {
- if (ReadID() == NID::kEnd)
- break;
- SkipData();
- }
-}
-
-// CFolder &folder can be non empty. So we must set all fields
-
-void CInByte2::ParseFolder(CFolder &folder)
-{
- CNum numCoders = ReadNum();
-
- folder.Coders.SetSize(numCoders);
-
- CNum numInStreams = 0;
- CNum numOutStreams = 0;
- CNum i;
- for (i = 0; i < numCoders; i++)
- {
- CCoderInfo &coder = folder.Coders[i];
- {
- Byte mainByte = ReadByte();
- if ((mainByte & 0xC0) != 0)
- ThrowUnsupported();
- unsigned idSize = (mainByte & 0xF);
- if (idSize > 8 || idSize > GetRem())
- ThrowUnsupported();
- const Byte *longID = GetPtr();
- UInt64 id = 0;
- for (unsigned j = 0; j < idSize; j++)
- id = ((id << 8) | longID[j]);
- SkipDataNoCheck(idSize);
- coder.MethodID = id;
-
- if ((mainByte & 0x10) != 0)
- {
- coder.NumInStreams = ReadNum();
- coder.NumOutStreams = ReadNum();
- }
- else
- {
- coder.NumInStreams = 1;
- coder.NumOutStreams = 1;
- }
- if ((mainByte & 0x20) != 0)
- {
- CNum propsSize = ReadNum();
- coder.Props.Alloc((size_t)propsSize);
- ReadBytes((Byte *)coder.Props, (size_t)propsSize);
- }
- else
- coder.Props.Free();
- }
- numInStreams += coder.NumInStreams;
- numOutStreams += coder.NumOutStreams;
- }
-
- CNum numBindPairs = numOutStreams - 1;
- folder.BindPairs.SetSize(numBindPairs);
- for (i = 0; i < numBindPairs; i++)
- {
- CBindPair &bp = folder.BindPairs[i];
- bp.InIndex = ReadNum();
- bp.OutIndex = ReadNum();
- }
-
- if (numInStreams < numBindPairs)
- ThrowUnsupported();
- CNum numPackStreams = numInStreams - numBindPairs;
- folder.PackStreams.SetSize(numPackStreams);
- if (numPackStreams == 1)
- {
- for (i = 0; i < numInStreams; i++)
- if (folder.FindBindPairForInStream(i) < 0)
- {
- folder.PackStreams[0] = i;
- break;
- }
- if (i == numInStreams)
- ThrowUnsupported();
- }
- else
- for (i = 0; i < numPackStreams; i++)
- folder.PackStreams[i] = ReadNum();
-}
-
-void CFolders::ParseFolderInfo(unsigned folderIndex, CFolder &folder) const
-{
- size_t startPos = FoCodersDataOffset[folderIndex];
- CInByte2 inByte;
- inByte.Init(CodersData + startPos, FoCodersDataOffset[folderIndex + 1] - startPos);
- inByte.ParseFolder(folder);
- if (inByte.GetRem() != 0)
- throw 20120424;
-}
-
-
-void CDatabase::GetPath(unsigned index, UString &path) const
-{
- path.Empty();
- if (!NameOffsets || !NamesBuf)
- return;
-
- size_t offset = NameOffsets[index];
- size_t size = NameOffsets[index + 1] - offset - 1;
-
- if (size >= (1 << 20))
- return;
-
- wchar_t *s = path.GetBuffer((unsigned)size);
-
- const Byte *p = ((const Byte *)NamesBuf + offset * 2);
-
- #if defined(_WIN32) && defined(MY_CPU_LE)
-
- wmemcpy(s, (const wchar_t *)p, size);
-
- #else
-
- for (size_t i = 0; i < size; i++)
- {
- *s = Get16(p);
- p += 2;
- s++;
- }
-
- #endif
-
- path.ReleaseBuffer((unsigned)size);
-}
-
-HRESULT CDatabase::GetPath_Prop(unsigned index, PROPVARIANT *path) const throw()
-{
- PropVariant_Clear(path);
- if (!NameOffsets || !NamesBuf)
- return S_OK;
-
- size_t offset = NameOffsets[index];
- size_t size = NameOffsets[index + 1] - offset;
-
- if (size >= (1 << 14))
- return S_OK;
-
- RINOK(PropVarEm_Alloc_Bstr(path, (unsigned)size - 1));
- wchar_t *s = path->bstrVal;
-
- const Byte *p = ((const Byte *)NamesBuf + offset * 2);
-
- for (size_t i = 0; i < size; i++)
- {
- wchar_t c = Get16(p);
- p += 2;
- #if WCHAR_PATH_SEPARATOR != L'/'
- if (c == L'/')
- c = WCHAR_PATH_SEPARATOR;
- #endif
- *s++ = c;
- }
-
- return S_OK;
-
- /*
- unsigned cur = index;
- unsigned size = 0;
-
- for (int i = 0;; i++)
- {
- size_t len = NameOffsets[cur + 1] - NameOffsets[cur];
- size += (unsigned)len;
- if (i > 256 || len > (1 << 14) || size > (1 << 14))
- return PropVarEm_Set_Str(path, "[TOO-LONG]");
- cur = Files[cur].Parent;
- if (cur < 0)
- break;
- }
- size--;
-
- RINOK(PropVarEm_Alloc_Bstr(path, size));
- wchar_t *s = path->bstrVal;
- s += size;
- *s = 0;
- cur = index;
-
- for (;;)
- {
- unsigned len = (unsigned)(NameOffsets[cur + 1] - NameOffsets[cur] - 1);
- const Byte *p = (const Byte *)NamesBuf + (NameOffsets[cur + 1] * 2) - 2;
- do
- {
- p -= 2;
- --s;
- wchar_t c = Get16(p);
- if (c == '/')
- c = WCHAR_PATH_SEPARATOR;
- *s = c;
- }
- while (--len);
- const CFileItem &file = Files[cur];
- cur = file.Parent;
- if (cur < 0)
- return S_OK;
- *(--s) = (file.IsAltStream ? ':' : WCHAR_PATH_SEPARATOR);
- }
- */
-}
-
-void CInArchive::WaitId(UInt64 id)
-{
- for (;;)
- {
- UInt64 type = ReadID();
- if (type == id)
- return;
- if (type == NID::kEnd)
- ThrowIncorrect();
- SkipData();
- }
-}
-
-void CInArchive::ReadHashDigests(unsigned numItems, CUInt32DefVector &crcs)
-{
- ReadBoolVector2(numItems, crcs.Defs);
- crcs.Vals.ClearAndSetSize(numItems);
- UInt32 *p = &crcs.Vals[0];
- const bool *defs = &crcs.Defs[0];
- for (unsigned i = 0; i < numItems; i++)
- {
- UInt32 crc = 0;
- if (defs[i])
- crc = ReadUInt32();
- p[i] = crc;
- }
-}
-
-void CInArchive::ReadPackInfo(CFolders &f)
-{
- CNum numPackStreams = ReadNum();
-
- WaitId(NID::kSize);
- f.PackPositions.Alloc(numPackStreams + 1);
- f.NumPackStreams = numPackStreams;
- UInt64 sum = 0;
- for (CNum i = 0; i < numPackStreams; i++)
- {
- f.PackPositions[i] = sum;
- UInt64 packSize = ReadNumber();
- sum += packSize;
- if (sum < packSize)
- ThrowIncorrect();
- }
- f.PackPositions[numPackStreams] = sum;
-
- UInt64 type;
- for (;;)
- {
- type = ReadID();
- if (type == NID::kEnd)
- return;
- if (type == NID::kCRC)
- {
- CUInt32DefVector PackCRCs;
- ReadHashDigests(numPackStreams, PackCRCs);
- continue;
- }
- SkipData();
- }
-}
-
-void CInArchive::ReadUnpackInfo(
- const CObjectVector<CByteBuffer> *dataVector,
- CFolders &folders)
-{
- WaitId(NID::kFolder);
- CNum numFolders = ReadNum();
-
- CNum numCodersOutStreams = 0;
- {
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, dataVector);
- const Byte *startBufPtr = _inByteBack->GetPtr();
- folders.NumFolders = numFolders;
-
- folders.FoStartPackStreamIndex.Alloc(numFolders + 1);
- folders.FoToMainUnpackSizeIndex.Alloc(numFolders);
- folders.FoCodersDataOffset.Alloc(numFolders + 1);
- folders.FoToCoderUnpackSizes.Alloc(numFolders + 1);
-
- CRecordVector<bool> InStreamUsed;
- CRecordVector<bool> OutStreamUsed;
-
- CNum packStreamIndex = 0;
- CNum fo;
- CInByte2 *inByte = _inByteBack;
- for (fo = 0; fo < numFolders; fo++)
- {
- UInt32 numOutStreams = 0;
- UInt32 indexOfMainStream = 0;
- UInt32 numPackStreams = 0;
- folders.FoCodersDataOffset[fo] = _inByteBack->GetPtr() - startBufPtr;
-
- numOutStreams = 0;
- CNum numInStreams = 0;
- CNum numCoders = inByte->ReadNum();
- for (CNum ci = 0; ci < numCoders; ci++)
- {
- Byte mainByte = inByte->ReadByte();
- if ((mainByte & 0xC0) != 0)
- ThrowUnsupported();
- unsigned idSize = (mainByte & 0xF);
- if (idSize > 8)
- ThrowUnsupported();
- if (idSize > inByte->GetRem())
- ThrowEndOfData();
- const Byte *longID = inByte->GetPtr();
- UInt64 id = 0;
- for (unsigned j = 0; j < idSize; j++)
- id = ((id << 8) | longID[j]);
- inByte->SkipDataNoCheck(idSize);
- if (folders.ParsedMethods.IDs.Size() < 128)
- folders.ParsedMethods.IDs.AddToUniqueSorted(id);
- CNum coderInStreams = 1;
- CNum coderOutStreams = 1;
- if ((mainByte & 0x10) != 0)
- {
- coderInStreams = inByte->ReadNum();
- coderOutStreams = inByte->ReadNum();
- }
- numInStreams += coderInStreams;
- if (numInStreams < coderInStreams)
- ThrowUnsupported();
- numOutStreams += coderOutStreams;
- if (numOutStreams < coderOutStreams)
- ThrowUnsupported();
- if ((mainByte & 0x20) != 0)
- {
- CNum propsSize = inByte->ReadNum();
- if (propsSize > inByte->GetRem())
- ThrowEndOfData();
- if (id == k_LZMA2 && propsSize == 1)
- {
- Byte v = *_inByteBack->GetPtr();
- if (folders.ParsedMethods.Lzma2Prop < v)
- folders.ParsedMethods.Lzma2Prop = v;
- }
- else if (id == k_LZMA && propsSize == 5)
- {
- UInt32 dicSize = GetUi32(_inByteBack->GetPtr() + 1);
- if (folders.ParsedMethods.LzmaDic < dicSize)
- folders.ParsedMethods.LzmaDic = dicSize;
- }
- inByte->SkipDataNoCheck((size_t)propsSize);
- }
- }
-
- if (numOutStreams == 1 && numInStreams == 1)
- {
- indexOfMainStream = 0;
- numPackStreams = 1;
- }
- else
- {
- UInt32 i;
- if (numOutStreams == 0)
- ThrowUnsupported();
- CNum numBindPairs = numOutStreams - 1;
- if (numInStreams < numBindPairs)
- ThrowUnsupported();
- if (numInStreams >= 256 || numOutStreams >= 256)
- ThrowUnsupported();
-
- InStreamUsed.ClearAndSetSize(numInStreams);
- for (i = 0; i < numInStreams; i++)
- InStreamUsed[i] = false;
-
- OutStreamUsed.ClearAndSetSize(numOutStreams);
- for (i = 0; i < numOutStreams; i++)
- OutStreamUsed[i] = false;
-
- for (i = 0; i < numBindPairs; i++)
- {
- CNum index = ReadNum();
- if (index >= numInStreams || InStreamUsed[index])
- ThrowUnsupported();
- InStreamUsed[index] = true;
- index = ReadNum();
- if (index >= numOutStreams || OutStreamUsed[index])
- ThrowUnsupported();
- OutStreamUsed[index] = true;
- }
-
- numPackStreams = numInStreams - numBindPairs;
-
- if (numPackStreams != 1)
- for (i = 0; i < numPackStreams; i++)
- inByte->ReadNum(); // PackStreams
-
- for (i = 0; i < numOutStreams; i++)
- if (!OutStreamUsed[i])
- {
- indexOfMainStream = i;
- break;
- }
- if (i == numOutStreams)
- ThrowUnsupported();
- }
- folders.FoToCoderUnpackSizes[fo] = numCodersOutStreams;
- numCodersOutStreams += numOutStreams;
- folders.FoStartPackStreamIndex[fo] = packStreamIndex;
- packStreamIndex += numPackStreams;
- folders.FoToMainUnpackSizeIndex[fo] = (Byte)indexOfMainStream;
- }
- size_t dataSize = _inByteBack->GetPtr() - startBufPtr;
- folders.FoToCoderUnpackSizes[fo] = numCodersOutStreams;
- folders.FoStartPackStreamIndex[fo] = packStreamIndex;
- folders.FoCodersDataOffset[fo] = _inByteBack->GetPtr() - startBufPtr;
- folders.CodersData.CopyFrom(startBufPtr, dataSize);
- }
-
- WaitId(NID::kCodersUnpackSize);
- folders.CoderUnpackSizes.Alloc(numCodersOutStreams);
- for (CNum i = 0; i < numCodersOutStreams; i++)
- folders.CoderUnpackSizes[i] = ReadNumber();
-
- for (;;)
- {
- UInt64 type = ReadID();
- if (type == NID::kEnd)
- return;
- if (type == NID::kCRC)
- {
- ReadHashDigests(numFolders, folders.FolderCRCs);
- continue;
- }
- SkipData();
- }
-}
-
-void CInArchive::ReadSubStreamsInfo(
- CFolders &folders,
- CRecordVector<UInt64> &unpackSizes,
- CUInt32DefVector &digests)
-{
- folders.NumUnpackStreamsVector.Alloc(folders.NumFolders);
- CNum i;
- for (i = 0; i < folders.NumFolders; i++)
- folders.NumUnpackStreamsVector[i] = 1;
-
- UInt64 type;
-
- for (;;)
- {
- type = ReadID();
- if (type == NID::kNumUnpackStream)
- {
- for (i = 0; i < folders.NumFolders; i++)
- folders.NumUnpackStreamsVector[i] = ReadNum();
- continue;
- }
- if (type == NID::kCRC || type == NID::kSize || type == NID::kEnd)
- break;
- SkipData();
- }
-
- if (type == NID::kSize)
- {
- for (i = 0; i < folders.NumFolders; i++)
- {
- // v3.13 incorrectly worked with empty folders
- // v4.07: we check that folder is empty
- CNum numSubstreams = folders.NumUnpackStreamsVector[i];
- if (numSubstreams == 0)
- continue;
- UInt64 sum = 0;
- for (CNum j = 1; j < numSubstreams; j++)
- {
- UInt64 size = ReadNumber();
- unpackSizes.Add(size);
- sum += size;
- if (sum < size)
- ThrowIncorrect();
- }
- UInt64 folderUnpackSize = folders.GetFolderUnpackSize(i);
- if (folderUnpackSize < sum)
- ThrowIncorrect();
- unpackSizes.Add(folderUnpackSize - sum);
- }
- type = ReadID();
- }
- else
- {
- for (i = 0; i < folders.NumFolders; i++)
- {
- /* v9.26 - v9.29 incorrectly worked:
- if (folders.NumUnpackStreamsVector[i] == 0), it threw error */
- CNum val = folders.NumUnpackStreamsVector[i];
- if (val > 1)
- ThrowIncorrect();
- if (val == 1)
- unpackSizes.Add(folders.GetFolderUnpackSize(i));
- }
- }
-
- unsigned numDigests = 0;
- for (i = 0; i < folders.NumFolders; i++)
- {
- CNum numSubstreams = folders.NumUnpackStreamsVector[i];
- if (numSubstreams != 1 || !folders.FolderCRCs.ValidAndDefined(i))
- numDigests += numSubstreams;
- }
-
- for (;;)
- {
- if (type == NID::kEnd)
- break;
- if (type == NID::kCRC)
- {
- // CUInt32DefVector digests2;
- // ReadHashDigests(numDigests, digests2);
- CBoolVector digests2;
- ReadBoolVector2(numDigests, digests2);
-
- digests.ClearAndSetSize(unpackSizes.Size());
-
- unsigned k = 0;
- unsigned k2 = 0;
-
- for (i = 0; i < folders.NumFolders; i++)
- {
- CNum numSubstreams = folders.NumUnpackStreamsVector[i];
- if (numSubstreams == 1 && folders.FolderCRCs.ValidAndDefined(i))
- {
- digests.Defs[k] = true;
- digests.Vals[k] = folders.FolderCRCs.Vals[i];
- k++;
- }
- else for (CNum j = 0; j < numSubstreams; j++)
- {
- bool defined = digests2[k2++];
- digests.Defs[k] = defined;
- UInt32 crc = 0;
- if (defined)
- crc = ReadUInt32();
- digests.Vals[k] = crc;
- k++;
- }
- }
- // if (k != unpackSizes.Size()) throw 1234567;
- }
- else
- SkipData();
-
- type = ReadID();
- }
-
- if (digests.Defs.Size() != unpackSizes.Size())
- {
- digests.ClearAndSetSize(unpackSizes.Size());
- unsigned k = 0;
- for (i = 0; i < folders.NumFolders; i++)
- {
- CNum numSubstreams = folders.NumUnpackStreamsVector[i];
- if (numSubstreams == 1 && folders.FolderCRCs.ValidAndDefined(i))
- {
- digests.Defs[k] = true;
- digests.Vals[k] = folders.FolderCRCs.Vals[i];
- k++;
- }
- else for (CNum j = 0; j < numSubstreams; j++)
- {
- digests.Defs[k] = false;
- digests.Vals[k] = 0;
- k++;
- }
- }
- }
-}
-
-void CInArchive::ReadStreamsInfo(
- const CObjectVector<CByteBuffer> *dataVector,
- UInt64 &dataOffset,
- CFolders &folders,
- CRecordVector<UInt64> &unpackSizes,
- CUInt32DefVector &digests)
-{
- UInt64 type = ReadID();
-
- if (type == NID::kPackInfo)
- {
- dataOffset = ReadNumber();
- ReadPackInfo(folders);
- type = ReadID();
- }
-
- if (type == NID::kUnpackInfo)
- {
- ReadUnpackInfo(dataVector, folders);
- type = ReadID();
- }
-
- if (folders.NumFolders != 0 && !folders.PackPositions)
- {
- // if there are folders, we need PackPositions also
- folders.PackPositions.Alloc(1);
- folders.PackPositions[0] = 0;
- }
-
- if (type == NID::kSubStreamsInfo)
- {
- ReadSubStreamsInfo(folders, unpackSizes, digests);
- type = ReadID();
- }
- else
- {
- folders.NumUnpackStreamsVector.Alloc(folders.NumFolders);
- /* If digests.Defs.Size() == 0, it means that there are no crcs.
- So we don't need to fill digests with values. */
- // digests.Vals.ClearAndSetSize(folders.NumFolders);
- // BoolVector_Fill_False(digests.Defs, folders.NumFolders);
- for (CNum i = 0; i < folders.NumFolders; i++)
- {
- folders.NumUnpackStreamsVector[i] = 1;
- unpackSizes.Add(folders.GetFolderUnpackSize(i));
- // digests.Vals[i] = 0;
- }
- }
-
- if (type != NID::kEnd)
- ThrowIncorrect();
-}
-
-void CInArchive::ReadBoolVector(unsigned numItems, CBoolVector &v)
-{
- v.ClearAndSetSize(numItems);
- Byte b = 0;
- Byte mask = 0;
- bool *p = &v[0];
- for (unsigned i = 0; i < numItems; i++)
- {
- if (mask == 0)
- {
- b = ReadByte();
- mask = 0x80;
- }
- p[i] = ((b & mask) != 0);
- mask >>= 1;
- }
-}
-
-void CInArchive::ReadBoolVector2(unsigned numItems, CBoolVector &v)
-{
- Byte allAreDefined = ReadByte();
- if (allAreDefined == 0)
- {
- ReadBoolVector(numItems, v);
- return;
- }
- v.ClearAndSetSize(numItems);
- bool *p = &v[0];
- for (unsigned i = 0; i < numItems; i++)
- p[i] = true;
-}
-
-void CInArchive::ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
- CUInt64DefVector &v, unsigned numItems)
-{
- ReadBoolVector2(numItems, v.Defs);
-
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
-
- v.Vals.ClearAndSetSize(numItems);
- UInt64 *p = &v.Vals[0];
- const bool *defs = &v.Defs[0];
-
- for (unsigned i = 0; i < numItems; i++)
- {
- UInt64 t = 0;
- if (defs[i])
- t = ReadUInt64();
- p[i] = t;
- }
-}
-
-HRESULT CInArchive::ReadAndDecodePackedStreams(
- DECL_EXTERNAL_CODECS_LOC_VARS
- UInt64 baseOffset,
- UInt64 &dataOffset, CObjectVector<CByteBuffer> &dataVector
- _7Z_DECODER_CRYPRO_VARS_DECL
- )
-{
- CFolders folders;
- CRecordVector<UInt64> unpackSizes;
- CUInt32DefVector digests;
-
- ReadStreamsInfo(NULL,
- dataOffset,
- folders,
- unpackSizes,
- digests);
-
- CDecoder decoder(
- #ifdef _ST_MODE
- false
- #else
- true
- #endif
- );
-
- for (CNum i = 0; i < folders.NumFolders; i++)
- {
- CByteBuffer &data = dataVector.AddNew();
- UInt64 unpackSize64 = folders.GetFolderUnpackSize(i);
- size_t unpackSize = (size_t)unpackSize64;
- if (unpackSize != unpackSize64)
- ThrowUnsupported();
- data.Alloc(unpackSize);
-
- CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream;
- CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
- outStreamSpec->Init(data, unpackSize);
-
- HRESULT result = decoder.Decode(
- EXTERNAL_CODECS_LOC_VARS
- _stream, baseOffset + dataOffset,
- folders, i,
- outStream, NULL
- _7Z_DECODER_CRYPRO_VARS
- #if !defined(_7ZIP_ST) && !defined(_SFX)
- , false, 1
- #endif
- );
- RINOK(result);
-
- if (folders.FolderCRCs.ValidAndDefined(i))
- if (CrcCalc(data, unpackSize) != folders.FolderCRCs.Vals[i])
- ThrowIncorrect();
- }
- HeadersSize += folders.PackPositions[folders.NumPackStreams];
- return S_OK;
-}
-
-HRESULT CInArchive::ReadHeader(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CDbEx &db
- _7Z_DECODER_CRYPRO_VARS_DECL
- )
-{
- UInt64 type = ReadID();
-
- if (type == NID::kArchiveProperties)
- {
- ReadArchiveProperties(db.ArcInfo);
- type = ReadID();
- }
-
- CObjectVector<CByteBuffer> dataVector;
-
- if (type == NID::kAdditionalStreamsInfo)
- {
- HRESULT result = ReadAndDecodePackedStreams(
- EXTERNAL_CODECS_LOC_VARS
- db.ArcInfo.StartPositionAfterHeader,
- db.ArcInfo.DataStartPosition2,
- dataVector
- _7Z_DECODER_CRYPRO_VARS
- );
- RINOK(result);
- db.ArcInfo.DataStartPosition2 += db.ArcInfo.StartPositionAfterHeader;
- type = ReadID();
- }
-
- CRecordVector<UInt64> unpackSizes;
- CUInt32DefVector digests;
-
- if (type == NID::kMainStreamsInfo)
- {
- ReadStreamsInfo(&dataVector,
- db.ArcInfo.DataStartPosition,
- (CFolders &)db,
- unpackSizes,
- digests);
- db.ArcInfo.DataStartPosition += db.ArcInfo.StartPositionAfterHeader;
- type = ReadID();
- }
-
- db.Files.Clear();
-
- if (type == NID::kFilesInfo)
- {
-
- CNum numFiles = ReadNum();
- db.Files.ClearAndSetSize(numFiles);
- CNum i;
- /*
- db.Files.Reserve(numFiles);
- CNum i;
- for (i = 0; i < numFiles; i++)
- db.Files.Add(CFileItem());
- */
-
- db.ArcInfo.FileInfoPopIDs.Add(NID::kSize);
- // if (!db.PackSizes.IsEmpty())
- db.ArcInfo.FileInfoPopIDs.Add(NID::kPackInfo);
- if (numFiles > 0 && !digests.Defs.IsEmpty())
- db.ArcInfo.FileInfoPopIDs.Add(NID::kCRC);
-
- CBoolVector emptyStreamVector;
- BoolVector_Fill_False(emptyStreamVector, (unsigned)numFiles);
- CBoolVector emptyFileVector;
- CBoolVector antiFileVector;
- CNum numEmptyStreams = 0;
-
- for (;;)
- {
- UInt64 type = ReadID();
- if (type == NID::kEnd)
- break;
- UInt64 size = ReadNumber();
- if (size > _inByteBack->GetRem())
- ThrowIncorrect();
- CStreamSwitch switchProp;
- switchProp.Set(this, _inByteBack->GetPtr(), (size_t)size, true);
- bool addPropIdToList = true;
- bool isKnownType = true;
- if (type > ((UInt32)1 << 30))
- isKnownType = false;
- else switch((UInt32)type)
- {
- case NID::kName:
- {
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
- size_t rem = _inByteBack->GetRem();
- db.NamesBuf.Alloc(rem);
- ReadBytes(db.NamesBuf, rem);
- db.NameOffsets.Alloc(db.Files.Size() + 1);
- size_t pos = 0;
- unsigned i;
- for (i = 0; i < db.Files.Size(); i++)
- {
- size_t curRem = (rem - pos) / 2;
- const UInt16 *buf = (const UInt16 *)(db.NamesBuf + pos);
- size_t j;
- for (j = 0; j < curRem && buf[j] != 0; j++);
- if (j == curRem)
- ThrowEndOfData();
- db.NameOffsets[i] = pos / 2;
- pos += j * 2 + 2;
- }
- db.NameOffsets[i] = pos / 2;
- if (pos != rem)
- ThereIsHeaderError = true;
- break;
- }
- case NID::kWinAttrib:
- {
- CBoolVector boolVector;
- ReadBoolVector2(db.Files.Size(), boolVector);
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
- for (i = 0; i < numFiles; i++)
- {
- CFileItem &file = db.Files[i];
- file.AttribDefined = boolVector[i];
- if (file.AttribDefined)
- file.Attrib = ReadUInt32();
- }
- break;
- }
- /*
- case NID::kIsAux:
- {
- ReadBoolVector(db.Files.Size(), db.IsAux);
- break;
- }
- case NID::kParent:
- {
- db.IsTree = true;
- // CBoolVector boolVector;
- // ReadBoolVector2(db.Files.Size(), boolVector);
- // CStreamSwitch streamSwitch;
- // streamSwitch.Set(this, &dataVector);
- CBoolVector boolVector;
- ReadBoolVector2(db.Files.Size(), boolVector);
-
- db.ThereAreAltStreams = false;
- for (i = 0; i < numFiles; i++)
- {
- CFileItem &file = db.Files[i];
- // file.Parent = -1;
- // if (boolVector[i])
- file.Parent = (int)ReadUInt32();
- file.IsAltStream = !boolVector[i];
- if (file.IsAltStream)
- db.ThereAreAltStreams = true;
- }
- break;
- }
- */
- case NID::kEmptyStream:
- {
- ReadBoolVector(numFiles, emptyStreamVector);
- numEmptyStreams = 0;
- for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
- if (emptyStreamVector[i])
- numEmptyStreams++;
-
- BoolVector_Fill_False(emptyFileVector, numEmptyStreams);
- BoolVector_Fill_False(antiFileVector, numEmptyStreams);
-
- break;
- }
- case NID::kEmptyFile: ReadBoolVector(numEmptyStreams, emptyFileVector); break;
- case NID::kAnti: ReadBoolVector(numEmptyStreams, antiFileVector); break;
- case NID::kStartPos: ReadUInt64DefVector(dataVector, db.StartPos, (unsigned)numFiles); break;
- case NID::kCTime: ReadUInt64DefVector(dataVector, db.CTime, (unsigned)numFiles); break;
- case NID::kATime: ReadUInt64DefVector(dataVector, db.ATime, (unsigned)numFiles); break;
- case NID::kMTime: ReadUInt64DefVector(dataVector, db.MTime, (unsigned)numFiles); break;
- case NID::kDummy:
- {
- for (UInt64 j = 0; j < size; j++)
- if (ReadByte() != 0)
- ThereIsHeaderError = true;
- addPropIdToList = false;
- break;
- }
- /*
- case NID::kNtSecure:
- {
- try
- {
- {
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, &dataVector);
- UInt32 numDescriptors = ReadUInt32();
- size_t offset = 0;
- db.SecureOffsets.Clear();
- for (i = 0; i < numDescriptors; i++)
- {
- UInt32 size = ReadUInt32();
- db.SecureOffsets.Add(offset);
- offset += size;
- }
- // ThrowIncorrect();;
- db.SecureOffsets.Add(offset);
- db.SecureBuf.SetCapacity(offset);
- for (i = 0; i < numDescriptors; i++)
- {
- offset = db.SecureOffsets[i];
- ReadBytes(db.SecureBuf + offset, db.SecureOffsets[i + 1] - offset);
- }
- db.SecureIDs.Clear();
- for (unsigned i = 0; i < db.Files.Size(); i++)
- {
- db.SecureIDs.Add(ReadNum());
- // db.SecureIDs.Add(ReadUInt32());
- }
- // ReadUInt32();
- if (_inByteBack->GetRem() != 0)
- ThrowIncorrect();;
- }
- }
- catch(CInArchiveException &)
- {
- ThereIsHeaderError = true;
- addPropIdToList = isKnownType = false;
- db.ClearSecure();
- }
- break;
- }
- */
- default:
- addPropIdToList = isKnownType = false;
- }
- if (isKnownType)
- {
- if (addPropIdToList)
- db.ArcInfo.FileInfoPopIDs.Add(type);
- }
- else
- {
- db.UnsupportedFeatureWarning = true;
- _inByteBack->SkipRem();
- }
- // SkipData worked incorrectly in some versions before v4.59 (7zVer <= 00.02)
- if (_inByteBack->GetRem() != 0)
- ThrowIncorrect();
- }
-
- type = ReadID(); // Read (NID::kEnd) end of headers
-
- CNum emptyFileIndex = 0;
- CNum sizeIndex = 0;
-
- CNum numAntiItems = 0;
- for (i = 0; i < numEmptyStreams; i++)
- if (antiFileVector[i])
- numAntiItems++;
-
- for (i = 0; i < numFiles; i++)
- {
- CFileItem &file = db.Files[i];
- bool isAnti;
- file.HasStream = !emptyStreamVector[i];
- file.Crc = 0;
- if (file.HasStream)
- {
- file.IsDir = false;
- isAnti = false;
- file.Size = unpackSizes[sizeIndex];
- file.CrcDefined = digests.ValidAndDefined(sizeIndex);
- if (file.CrcDefined)
- file.Crc = digests.Vals[sizeIndex];
- sizeIndex++;
- }
- else
- {
- file.IsDir = !emptyFileVector[emptyFileIndex];
- isAnti = antiFileVector[emptyFileIndex];
- emptyFileIndex++;
- file.Size = 0;
- file.CrcDefined = false;
- }
- if (numAntiItems != 0)
- db.IsAnti.Add(isAnti);
- }
- }
- db.FillLinks();
- /*
- if (type != NID::kEnd)
- ThrowIncorrect();
- if (_inByteBack->GetRem() != 0)
- ThrowIncorrect();
- */
- return S_OK;
-}
-
-void CDbEx::FillLinks()
-{
- FolderStartFileIndex.ClearAndSetSize(NumFolders);
-
- FileIndexToFolderIndexMap.ClearAndSetSize(Files.Size());
-
- CNum folderIndex = 0;
- CNum indexInFolder = 0;
- unsigned i;
- for (i = 0; i < Files.Size(); i++)
- {
- bool emptyStream = !Files[i].HasStream;
- if (indexInFolder == 0)
- {
- if (emptyStream)
- {
- FileIndexToFolderIndexMap[i] = kNumNoIndex;
- continue;
- }
- // v3.13 incorrectly worked with empty folders
- // v4.07: we skip empty folders
- for (;;)
- {
- if (folderIndex >= NumFolders)
- ThrowIncorrect();
- FolderStartFileIndex[folderIndex] = i;
- if (NumUnpackStreamsVector[folderIndex] != 0)
- break;
- folderIndex++;
- }
- }
- FileIndexToFolderIndexMap[i] = folderIndex;
- if (emptyStream)
- continue;
- if (++indexInFolder >= NumUnpackStreamsVector[folderIndex])
- {
- folderIndex++;
- indexInFolder = 0;
- }
- }
-
- if (indexInFolder != 0)
- folderIndex++;
- /*
- if (indexInFolder != 0)
- ThrowIncorrect();
- */
- for (;;)
- {
- if (folderIndex >= NumFolders)
- return;
- FolderStartFileIndex[folderIndex] = i;
- /*
- if (NumUnpackStreamsVector[folderIndex] != 0)
- ThrowIncorrect();;
- */
- folderIndex++;
- }
-}
-
-HRESULT CInArchive::ReadDatabase2(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CDbEx &db
- _7Z_DECODER_CRYPRO_VARS_DECL
- )
-{
- db.Clear();
- db.ArcInfo.StartPosition = _arhiveBeginStreamPosition;
-
- db.ArcInfo.Version.Major = _header[6];
- db.ArcInfo.Version.Minor = _header[7];
-
- if (db.ArcInfo.Version.Major != kMajorVersion)
- {
- // db.UnsupportedVersion = true;
- return S_FALSE;
- }
-
- UInt64 nextHeaderOffset = Get64(_header + 12);
- UInt64 nextHeaderSize = Get64(_header + 20);
- UInt32 nextHeaderCRC = Get32(_header + 28);
-
- #ifdef FORMAT_7Z_RECOVERY
- UInt32 crcFromArc = Get32(_header + 8);
- if (crcFromArc == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)
- {
- UInt64 cur, fileSize;
- RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));
- const unsigned kCheckSize = 512;
- Byte buf[kCheckSize];
- RINOK(_stream->Seek(0, STREAM_SEEK_END, &fileSize));
- UInt64 rem = fileSize - cur;
- unsigned checkSize = kCheckSize;
- if (rem < kCheckSize)
- checkSize = (unsigned)(rem);
- if (checkSize < 3)
- return S_FALSE;
- RINOK(_stream->Seek(fileSize - checkSize, STREAM_SEEK_SET, NULL));
- RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));
-
- if (buf[checkSize - 1] != 0)
- return S_FALSE;
-
- unsigned i;
- for (i = checkSize - 2;; i--)
- {
- if (buf[i] == NID::kEncodedHeader && buf[i + 1] == NID::kPackInfo ||
- buf[i] == NID::kHeader && buf[i + 1] == NID::kMainStreamsInfo)
- break;
- if (i == 0)
- return S_FALSE;
- }
- nextHeaderSize = checkSize - i;
- nextHeaderOffset = rem - nextHeaderSize;
- nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);
- RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));
- db.StartHeaderWasRecovered = true;
- }
- else
- #endif
- {
- // Crc was tested already at signature check
- // if (CrcCalc(_header + 12, 20) != crcFromArchive) ThrowIncorrect();
- }
-
- db.ArcInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;
- db.PhySize = kHeaderSize;
-
- db.IsArc = false;
- if ((Int64)nextHeaderOffset < 0 ||
- nextHeaderSize > ((UInt64)1 << 62))
- return S_FALSE;
- if (nextHeaderSize == 0)
- {
- if (nextHeaderOffset != 0)
- return S_FALSE;
- db.IsArc = true;
- return S_OK;
- }
-
- if (!db.StartHeaderWasRecovered)
- db.IsArc = true;
-
- HeadersSize += kHeaderSize + nextHeaderSize;
- db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;
- if (_fileEndPosition - db.ArcInfo.StartPositionAfterHeader < nextHeaderOffset + nextHeaderSize)
- {
- db.UnexpectedEnd = true;
- return S_FALSE;
- }
- RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));
-
- size_t nextHeaderSize_t = (size_t)nextHeaderSize;
- if (nextHeaderSize_t != nextHeaderSize)
- return E_OUTOFMEMORY;
- CByteBuffer buffer2(nextHeaderSize_t);
-
- RINOK(ReadStream_FALSE(_stream, buffer2, nextHeaderSize_t));
-
- if (CrcCalc(buffer2, nextHeaderSize_t) != nextHeaderCRC)
- ThrowIncorrect();
-
- if (!db.StartHeaderWasRecovered)
- db.PhySizeWasConfirmed = true;
-
- CStreamSwitch streamSwitch;
- streamSwitch.Set(this, buffer2);
-
- CObjectVector<CByteBuffer> dataVector;
-
- UInt64 type = ReadID();
- if (type != NID::kHeader)
- {
- if (type != NID::kEncodedHeader)
- ThrowIncorrect();
- HRESULT result = ReadAndDecodePackedStreams(
- EXTERNAL_CODECS_LOC_VARS
- db.ArcInfo.StartPositionAfterHeader,
- db.ArcInfo.DataStartPosition2,
- dataVector
- _7Z_DECODER_CRYPRO_VARS
- );
- RINOK(result);
- if (dataVector.Size() == 0)
- return S_OK;
- if (dataVector.Size() > 1)
- ThrowIncorrect();
- streamSwitch.Remove();
- streamSwitch.Set(this, dataVector.Front());
- if (ReadID() != NID::kHeader)
- ThrowIncorrect();
- }
-
- db.IsArc = true;
-
- db.HeadersSize = HeadersSize;
-
- return ReadHeader(
- EXTERNAL_CODECS_LOC_VARS
- db
- _7Z_DECODER_CRYPRO_VARS
- );
-}
-
-HRESULT CInArchive::ReadDatabase(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CDbEx &db
- _7Z_DECODER_CRYPRO_VARS_DECL
- )
-{
- try
- {
- HRESULT res = ReadDatabase2(
- EXTERNAL_CODECS_LOC_VARS db
- _7Z_DECODER_CRYPRO_VARS
- );
- if (ThereIsHeaderError)
- db.ThereIsHeaderError = true;
- if (res == E_NOTIMPL)
- ThrowUnsupported();
- return res;
- }
- catch(CUnsupportedFeatureException &)
- {
- db.UnsupportedFeatureError = true;
- return S_FALSE;
- }
- catch(CInArchiveException &)
- {
- db.ThereIsHeaderError = true;
- return S_FALSE;
- }
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.h
deleted file mode 100644
index 98f61c81e..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zIn.h
+++ /dev/null
@@ -1,412 +0,0 @@
-// 7zIn.h
-
-#ifndef __7Z_IN_H
-#define __7Z_IN_H
-
-#include "../../../Common/MyCom.h"
-
-#include "../../../Windows/PropVariant.h"
-
-#include "../../IPassword.h"
-#include "../../IStream.h"
-
-#include "../../Common/CreateCoder.h"
-#include "../../Common/InBuffer.h"
-
-#include "7zItem.h"
-
-namespace NArchive {
-namespace N7z {
-
-/*
- We don't need to init isEncrypted and passwordIsDefined
- We must upgrade them only */
-
-#ifdef _NO_CRYPTO
-#define _7Z_DECODER_CRYPRO_VARS_DECL
-#define _7Z_DECODER_CRYPRO_VARS
-#else
-#define _7Z_DECODER_CRYPRO_VARS_DECL , ICryptoGetTextPassword *getTextPassword, bool &isEncrypted, bool &passwordIsDefined
-#define _7Z_DECODER_CRYPRO_VARS , getTextPassword, isEncrypted, passwordIsDefined
-#endif
-
-struct CParsedMethods
-{
- Byte Lzma2Prop;
- UInt32 LzmaDic;
- CRecordVector<UInt64> IDs;
-
- CParsedMethods(): Lzma2Prop(0), LzmaDic(0) {}
-};
-
-struct CFolders
-{
- CNum NumPackStreams;
- CNum NumFolders;
-
- CObjArray<UInt64> PackPositions; // NumPackStreams + 1
- // CUInt32DefVector PackCRCs; // we don't use PackCRCs now
-
- CUInt32DefVector FolderCRCs; // NumFolders
- CObjArray<CNum> NumUnpackStreamsVector; // NumFolders
-
- CObjArray<UInt64> CoderUnpackSizes; // including unpack sizes of bind coders
- CObjArray<CNum> FoToCoderUnpackSizes; // NumFolders + 1
- CObjArray<CNum> FoStartPackStreamIndex; // NumFolders + 1
- CObjArray<Byte> FoToMainUnpackSizeIndex; // NumFolders
-
- CObjArray<size_t> FoCodersDataOffset; // NumFolders + 1
- CByteBuffer CodersData;
-
- CParsedMethods ParsedMethods;
-
- void ParseFolderInfo(unsigned folderIndex, CFolder &folder) const;
-
- unsigned GetNumFolderUnpackSizes(unsigned folderIndex) const
- {
- return FoToCoderUnpackSizes[folderIndex + 1] - FoToCoderUnpackSizes[folderIndex];
- }
-
- UInt64 GetFolderUnpackSize(unsigned folderIndex) const
- {
- return CoderUnpackSizes[FoToCoderUnpackSizes[folderIndex] + FoToMainUnpackSizeIndex[folderIndex]];
- }
-
- UInt64 GetStreamPackSize(unsigned index) const
- {
- return PackPositions[index + 1] - PackPositions[index];
- }
-
- void Clear()
- {
- NumPackStreams = 0;
- PackPositions.Free();
- // PackCRCs.Clear();
-
- NumFolders = 0;
- FolderCRCs.Clear();
- NumUnpackStreamsVector.Free();
- CoderUnpackSizes.Free();
- FoToCoderUnpackSizes.Free();
- FoStartPackStreamIndex.Free();
- FoToMainUnpackSizeIndex.Free();
- FoCodersDataOffset.Free();
- CodersData.Free();
- }
-};
-
-struct CDatabase: public CFolders
-{
- CRecordVector<CFileItem> Files;
-
- CUInt64DefVector CTime;
- CUInt64DefVector ATime;
- CUInt64DefVector MTime;
- CUInt64DefVector StartPos;
- CRecordVector<bool> IsAnti;
- /*
- CRecordVector<bool> IsAux;
- CByteBuffer SecureBuf;
- CRecordVector<UInt32> SecureIDs;
- */
-
- CByteBuffer NamesBuf;
- CObjArray<size_t> NameOffsets; // numFiles + 1, offsets of utf-16 symbols
-
- /*
- void ClearSecure()
- {
- SecureBuf.Free();
- SecureIDs.Clear();
- }
- */
-
- void Clear()
- {
- CFolders::Clear();
- // ClearSecure();
-
- NamesBuf.Free();
- NameOffsets.Free();
-
- Files.Clear();
- CTime.Clear();
- ATime.Clear();
- MTime.Clear();
- StartPos.Clear();
- IsAnti.Clear();
- // IsAux.Clear();
- }
-
- bool IsSolid() const
- {
- for (CNum i = 0; i < NumFolders; i++)
- if (NumUnpackStreamsVector[i] > 1)
- return true;
- return false;
- }
- bool IsItemAnti(unsigned index) const { return (index < IsAnti.Size() && IsAnti[index]); }
- // bool IsItemAux(unsigned index) const { return (index < IsAux.Size() && IsAux[index]); }
-
- const void * GetName(unsigned index) const
- {
- if (!NameOffsets || !NamesBuf)
- return NULL;
- return (const void *)((const Byte *)NamesBuf + NameOffsets[index] * 2);
- };
-
- void GetPath(unsigned index, UString &path) const;
- HRESULT GetPath_Prop(unsigned index, PROPVARIANT *path) const throw();
-};
-
-struct CInArchiveInfo
-{
- CArchiveVersion Version;
- UInt64 StartPosition;
- UInt64 StartPositionAfterHeader;
- UInt64 DataStartPosition;
- UInt64 DataStartPosition2;
- CRecordVector<UInt64> FileInfoPopIDs;
-
- void Clear()
- {
- StartPosition = 0;
- StartPositionAfterHeader = 0;
- DataStartPosition = 0;
- DataStartPosition2 = 0;
- FileInfoPopIDs.Clear();
- }
-};
-
-struct CDbEx: public CDatabase
-{
- CInArchiveInfo ArcInfo;
- CRecordVector<CNum> FolderStartFileIndex;
- CRecordVector<CNum> FileIndexToFolderIndexMap;
-
- UInt64 HeadersSize;
- UInt64 PhySize;
-
- /*
- CRecordVector<size_t> SecureOffsets;
- bool IsTree;
- bool ThereAreAltStreams;
- */
-
- bool IsArc;
- bool PhySizeWasConfirmed;
-
- bool ThereIsHeaderError;
- bool UnexpectedEnd;
- // bool UnsupportedVersion;
-
- bool StartHeaderWasRecovered;
- bool UnsupportedFeatureWarning;
- bool UnsupportedFeatureError;
-
- /*
- void ClearSecureEx()
- {
- ClearSecure();
- SecureOffsets.Clear();
- }
- */
-
- void Clear()
- {
- IsArc = false;
- PhySizeWasConfirmed = false;
-
- ThereIsHeaderError = false;
- UnexpectedEnd = false;
- // UnsupportedVersion = false;
-
- StartHeaderWasRecovered = false;
- UnsupportedFeatureError = false;
- UnsupportedFeatureWarning = false;
-
- /*
- IsTree = false;
- ThereAreAltStreams = false;
- */
-
- CDatabase::Clear();
-
- // SecureOffsets.Clear();
- ArcInfo.Clear();
- FolderStartFileIndex.Clear();
- FileIndexToFolderIndexMap.Clear();
-
- HeadersSize = 0;
- PhySize = 0;
- }
-
- void FillLinks();
-
- UInt64 GetFolderStreamPos(unsigned folderIndex, unsigned indexInFolder) const
- {
- return ArcInfo.DataStartPosition +
- PackPositions[FoStartPackStreamIndex[folderIndex] + indexInFolder];
- }
-
- UInt64 GetFolderFullPackSize(unsigned folderIndex) const
- {
- return
- PackPositions[FoStartPackStreamIndex[folderIndex + 1]] -
- PackPositions[FoStartPackStreamIndex[folderIndex]];
- }
-
- UInt64 GetFolderPackStreamSize(unsigned folderIndex, unsigned streamIndex) const
- {
- unsigned i = FoStartPackStreamIndex[folderIndex] + streamIndex;
- return PackPositions[i + 1] - PackPositions[i];
- }
-
- UInt64 GetFilePackSize(CNum fileIndex) const
- {
- CNum folderIndex = FileIndexToFolderIndexMap[fileIndex];
- if (folderIndex != kNumNoIndex)
- if (FolderStartFileIndex[folderIndex] == fileIndex)
- return GetFolderFullPackSize(folderIndex);
- return 0;
- }
-};
-
-const unsigned kNumBufLevelsMax = 4;
-
-struct CInByte2
-{
- const Byte *_buffer;
-public:
- size_t _size;
- size_t _pos;
-
- size_t GetRem() const { return _size - _pos; }
- const Byte *GetPtr() const { return _buffer + _pos; }
- void Init(const Byte *buffer, size_t size)
- {
- _buffer = buffer;
- _size = size;
- _pos = 0;
- }
- Byte ReadByte();
- void ReadBytes(Byte *data, size_t size);
- void SkipDataNoCheck(UInt64 size) { _pos += (size_t)size; }
- void SkipData(UInt64 size);
-
- void SkipData();
- void SkipRem() { _pos = _size; }
- UInt64 ReadNumber();
- CNum ReadNum();
- UInt32 ReadUInt32();
- UInt64 ReadUInt64();
-
- void ParseFolder(CFolder &folder);
-};
-
-class CStreamSwitch;
-
-const UInt32 kHeaderSize = 32;
-
-class CInArchive
-{
- friend class CStreamSwitch;
-
- CMyComPtr<IInStream> _stream;
-
- unsigned _numInByteBufs;
- CInByte2 _inByteVector[kNumBufLevelsMax];
-
- CInByte2 *_inByteBack;
- bool ThereIsHeaderError;
-
- UInt64 _arhiveBeginStreamPosition;
- UInt64 _fileEndPosition;
-
- Byte _header[kHeaderSize];
-
- UInt64 HeadersSize;
-
- void AddByteStream(const Byte *buffer, size_t size);
-
- void DeleteByteStream(bool needUpdatePos)
- {
- _numInByteBufs--;
- if (_numInByteBufs > 0)
- {
- _inByteBack = &_inByteVector[_numInByteBufs - 1];
- if (needUpdatePos)
- _inByteBack->_pos += _inByteVector[_numInByteBufs]._pos;
- }
- }
-
-private:
- HRESULT FindAndReadSignature(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
-
- void ReadBytes(Byte *data, size_t size) { _inByteBack->ReadBytes(data, size); }
- Byte ReadByte() { return _inByteBack->ReadByte(); }
- UInt64 ReadNumber() { return _inByteBack->ReadNumber(); }
- CNum ReadNum() { return _inByteBack->ReadNum(); }
- UInt64 ReadID() { return _inByteBack->ReadNumber(); }
- UInt32 ReadUInt32() { return _inByteBack->ReadUInt32(); }
- UInt64 ReadUInt64() { return _inByteBack->ReadUInt64(); }
- void SkipData(UInt64 size) { _inByteBack->SkipData(size); }
- void SkipData() { _inByteBack->SkipData(); }
- void WaitId(UInt64 id);
-
- void ReadArchiveProperties(CInArchiveInfo &archiveInfo);
- void ReadHashDigests(unsigned numItems, CUInt32DefVector &crcs);
-
- void ReadPackInfo(CFolders &f);
-
- void ReadUnpackInfo(
- const CObjectVector<CByteBuffer> *dataVector,
- CFolders &folders);
-
- void ReadSubStreamsInfo(
- CFolders &folders,
- CRecordVector<UInt64> &unpackSizes,
- CUInt32DefVector &digests);
-
- void ReadStreamsInfo(
- const CObjectVector<CByteBuffer> *dataVector,
- UInt64 &dataOffset,
- CFolders &folders,
- CRecordVector<UInt64> &unpackSizes,
- CUInt32DefVector &digests);
-
- void ReadBoolVector(unsigned numItems, CBoolVector &v);
- void ReadBoolVector2(unsigned numItems, CBoolVector &v);
- void ReadUInt64DefVector(const CObjectVector<CByteBuffer> &dataVector,
- CUInt64DefVector &v, unsigned numItems);
- HRESULT ReadAndDecodePackedStreams(
- DECL_EXTERNAL_CODECS_LOC_VARS
- UInt64 baseOffset, UInt64 &dataOffset,
- CObjectVector<CByteBuffer> &dataVector
- _7Z_DECODER_CRYPRO_VARS_DECL
- );
- HRESULT ReadHeader(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CDbEx &db
- _7Z_DECODER_CRYPRO_VARS_DECL
- );
- HRESULT ReadDatabase2(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CDbEx &db
- _7Z_DECODER_CRYPRO_VARS_DECL
- );
-public:
- CInArchive(): _numInByteBufs(0) { }
- HRESULT Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit); // S_FALSE means is not archive
- void Close();
-
- HRESULT ReadDatabase(
- DECL_EXTERNAL_CODECS_LOC_VARS
- CDbEx &db
- _7Z_DECODER_CRYPRO_VARS_DECL
- );
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zItem.h b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zItem.h
deleted file mode 100644
index c112f83fd..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zItem.h
+++ /dev/null
@@ -1,186 +0,0 @@
-// 7zItem.h
-
-#ifndef __7Z_ITEM_H
-#define __7Z_ITEM_H
-
-#include "../../../Common/MyBuffer.h"
-#include "../../../Common/MyString.h"
-
-#include "../../Common/MethodId.h"
-
-#include "7zHeader.h"
-
-namespace NArchive {
-namespace N7z {
-
-const UInt64 k_AES = 0x06F10701;
-
-typedef UInt32 CNum;
-const CNum kNumMax = 0x7FFFFFFF;
-const CNum kNumNoIndex = 0xFFFFFFFF;
-
-struct CCoderInfo
-{
- CMethodId MethodID;
- CByteBuffer Props;
- CNum NumInStreams;
- CNum NumOutStreams;
-
- bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
-};
-
-struct CBindPair
-{
- CNum InIndex;
- CNum OutIndex;
-};
-
-struct CFolder
-{
- CObjArray2<CCoderInfo> Coders;
- CObjArray2<CBindPair> BindPairs;
- CObjArray2<CNum> PackStreams;
-
- CNum GetNumOutStreams() const
- {
- CNum result = 0;
- FOR_VECTOR(i, Coders)
- result += Coders[i].NumOutStreams;
- return result;
- }
-
- int FindBindPairForInStream(CNum inStreamIndex) const
- {
- FOR_VECTOR(i, BindPairs)
- if (BindPairs[i].InIndex == inStreamIndex)
- return i;
- return -1;
- }
- int FindBindPairForOutStream(CNum outStreamIndex) const
- {
- FOR_VECTOR(i, BindPairs)
- if (BindPairs[i].OutIndex == outStreamIndex)
- return i;
- return -1;
- }
- int FindPackStreamArrayIndex(CNum inStreamIndex) const
- {
- FOR_VECTOR(i, PackStreams)
- if (PackStreams[i] == inStreamIndex)
- return i;
- return -1;
- }
-
- int GetIndexOfMainOutStream() const
- {
- for (int i = (int)GetNumOutStreams() - 1; i >= 0; i--)
- if (FindBindPairForOutStream(i) < 0)
- return i;
- throw 1;
- }
-
- bool IsEncrypted() const
- {
- for (int i = Coders.Size() - 1; i >= 0; i--)
- if (Coders[i].MethodID == k_AES)
- return true;
- return false;
- }
-
- bool CheckStructure(unsigned numUnpackSizes) const;
-};
-
-struct CUInt32DefVector
-{
- CBoolVector Defs;
- CRecordVector<UInt32> Vals;
-
- void ClearAndSetSize(unsigned newSize)
- {
- Defs.ClearAndSetSize(newSize);
- Vals.ClearAndSetSize(newSize);
- }
-
- void Clear()
- {
- Defs.Clear();
- Vals.Clear();
- }
-
- void ReserveDown()
- {
- Defs.ReserveDown();
- Vals.ReserveDown();
- }
-
- bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; }
-};
-
-struct CUInt64DefVector
-{
- CBoolVector Defs;
- CRecordVector<UInt64> Vals;
-
- void Clear()
- {
- Defs.Clear();
- Vals.Clear();
- }
-
- void ReserveDown()
- {
- Defs.ReserveDown();
- Vals.ReserveDown();
- }
-
- bool GetItem(unsigned index, UInt64 &value) const
- {
- if (index < Defs.Size() && Defs[index])
- {
- value = Vals[index];
- return true;
- }
- value = 0;
- return false;
- }
-
- void SetItem(unsigned index, bool defined, UInt64 value);
-
- bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
-};
-
-struct CFileItem
-{
- UInt64 Size;
- UInt32 Attrib;
- UInt32 Crc;
- /*
- int Parent;
- bool IsAltStream;
- */
- bool HasStream; // Test it !!! it means that there is
- // stream in some folder. It can be empty stream
- bool IsDir;
- bool CrcDefined;
- bool AttribDefined;
-
- CFileItem():
- /*
- Parent(-1),
- IsAltStream(false),
- */
- HasStream(true),
- IsDir(false),
- CrcDefined(false),
- AttribDefined(false)
- {}
- void SetAttrib(UInt32 attrib)
- {
- AttribDefined = true;
- Attrib = attrib;
- }
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zOut.cpp b/src/libs/7zip/win/CPP/7zip/Archive/7z/7zOut.cpp
deleted file mode 100644
index e20858ea7..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/7z/7zOut.cpp
+++ /dev/null
@@ -1,901 +0,0 @@
-// 7zOut.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../C/7zCrc.h"
-
-#include "../../Common/StreamObjects.h"
-
-#include "7zOut.h"
-
-namespace NArchive {
-namespace N7z {
-
-HRESULT COutArchive::WriteSignature()
-{
- Byte buf[8];
- memcpy(buf, kSignature, kSignatureSize);
- buf[kSignatureSize] = kMajorVersion;
- buf[kSignatureSize + 1] = 4;
- return WriteDirect(buf, 8);
-}
-
-#ifdef _7Z_VOL
-HRESULT COutArchive::WriteFinishSignature()
-{
- RINOK(WriteDirect(kFinishSignature, kSignatureSize));
- CArchiveVersion av;
- av.Major = kMajorVersion;
- av.Minor = 2;
- RINOK(WriteDirectByte(av.Major));
- return WriteDirectByte(av.Minor);
-}
-#endif
-
-static void SetUInt32(Byte *p, UInt32 d)
-{
- for (int i = 0; i < 4; i++, d >>= 8)
- p[i] = (Byte)d;
-}
-
-static void SetUInt64(Byte *p, UInt64 d)
-{
- for (int i = 0; i < 8; i++, d >>= 8)
- p[i] = (Byte)d;
-}
-
-HRESULT COutArchive::WriteStartHeader(const CStartHeader &h)
-{
- Byte buf[24];
- SetUInt64(buf + 4, h.NextHeaderOffset);
- SetUInt64(buf + 12, h.NextHeaderSize);
- SetUInt32(buf + 20, h.NextHeaderCRC);
- SetUInt32(buf, CrcCalc(buf + 4, 20));
- return WriteDirect(buf, 24);
-}
-
-#ifdef _7Z_VOL
-HRESULT COutArchive::WriteFinishHeader(const CFinishHeader &h)
-{
- CCRC crc;
- crc.UpdateUInt64(h.NextHeaderOffset);
- crc.UpdateUInt64(h.NextHeaderSize);
- crc.UpdateUInt32(h.NextHeaderCRC);
- crc.UpdateUInt64(h.ArchiveStartOffset);
- crc.UpdateUInt64(h.AdditionalStartBlockSize);
- RINOK(WriteDirectUInt32(crc.GetDigest()));
- RINOK(WriteDirectUInt64(h.NextHeaderOffset));
- RINOK(WriteDirectUInt64(h.NextHeaderSize));
- RINOK(WriteDirectUInt32(h.NextHeaderCRC));
- RINOK(WriteDirectUInt64(h.ArchiveStartOffset));
- return WriteDirectUInt64(h.AdditionalStartBlockSize);
-}
-#endif
-
-HRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker)
-{
- Close();
- #ifdef _7Z_VOL
- // endMarker = false;
- _endMarker = endMarker;
- #endif
- SeqStream = stream;
- if (!endMarker)
- {
- SeqStream.QueryInterface(IID_IOutStream, &Stream);
- if (!Stream)
- {
- return E_NOTIMPL;
- // endMarker = true;
- }
- }
- #ifdef _7Z_VOL
- if (endMarker)
- {
- /*
- CStartHeader sh;
- sh.NextHeaderOffset = (UInt32)(Int32)-1;
- sh.NextHeaderSize = (UInt32)(Int32)-1;
- sh.NextHeaderCRC = 0;
- WriteStartHeader(sh);
- */
- }
- else
- #endif
- {
- if (!Stream)
- return E_FAIL;
- RINOK(WriteSignature());
- RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos));
- }
- return S_OK;
-}
-
-void COutArchive::Close()
-{
- SeqStream.Release();
- Stream.Release();
-}
-
-HRESULT COutArchive::SkipPrefixArchiveHeader()
-{
- #ifdef _7Z_VOL
- if (_endMarker)
- return S_OK;
- #endif
- Byte buf[24];
- memset(buf, 0, 24);
- return WriteDirect(buf, 24);
-}
-
-UInt64 COutArchive::GetPos() const
-{
- if (_countMode)
- return _countSize;
- if (_writeToStream)
- return _outByte.GetProcessedSize();
- return _outByte2.GetPos();
-}
-
-void COutArchive::WriteBytes(const void *data, size_t size)
-{
- if (_countMode)
- _countSize += size;
- else if (_writeToStream)
- {
- _outByte.WriteBytes(data, size);
- _crc = CrcUpdate(_crc, data, size);
- }
- else
- _outByte2.WriteBytes(data, size);
-}
-
-void COutArchive::WriteByte(Byte b)
-{
- if (_countMode)
- _countSize++;
- else if (_writeToStream)
- {
- _outByte.WriteByte(b);
- _crc = CRC_UPDATE_BYTE(_crc, b);
- }
- else
- _outByte2.WriteByte(b);
-}
-
-void COutArchive::WriteUInt32(UInt32 value)
-{
- for (int i = 0; i < 4; i++)
- {
- WriteByte((Byte)value);
- value >>= 8;
- }
-}
-
-void COutArchive::WriteUInt64(UInt64 value)
-{
- for (int i = 0; i < 8; i++)
- {
- WriteByte((Byte)value);
- value >>= 8;
- }
-}
-
-void COutArchive::WriteNumber(UInt64 value)
-{
- Byte firstByte = 0;
- Byte mask = 0x80;
- int i;
- for (i = 0; i < 8; i++)
- {
- if (value < ((UInt64(1) << ( 7 * (i + 1)))))
- {
- firstByte |= Byte(value >> (8 * i));
- break;
- }
- firstByte |= mask;
- mask >>= 1;
- }
- WriteByte(firstByte);
- for (;i > 0; i--)
- {
- WriteByte((Byte)value);
- value >>= 8;
- }
-}
-
-static UInt32 GetBigNumberSize(UInt64 value)
-{
- int i;
- for (i = 1; i < 9; i++)
- if (value < (((UInt64)1 << (i * 7))))
- break;
- return i;
-}
-
-#ifdef _7Z_VOL
-UInt32 COutArchive::GetVolHeadersSize(UInt64 dataSize, int nameLength, bool props)
-{
- UInt32 result = GetBigNumberSize(dataSize) * 2 + 41;
- if (nameLength != 0)
- {
- nameLength = (nameLength + 1) * 2;
- result += nameLength + GetBigNumberSize(nameLength) + 2;
- }
- if (props)<