summaryrefslogtreecommitdiffstats
path: root/src/libs/7zip/win
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2013-05-02 15:28:22 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2013-05-08 13:01:55 +0200
commitd89674f944c419c9473da688993ee69671f2c295 (patch)
tree8422461a5b45d97b6d32dfa8e060e69d600210c9 /src/libs/7zip/win
parent5ed380ebcf8ef1157f651cbdef8393ccac897ee2 (diff)
Reset to only use the basic LZMA SDK (Windows).
Change-Id: I8088cc4775f6c5397991f00512354836d614ea4e Reviewed-by: Kai Koehne <kai.koehne@digia.com> Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'src/libs/7zip/win')
-rw-r--r--src/libs/7zip/win/7zC.txt (renamed from src/libs/7zip/win/DOC/7zC.txt)0
-rw-r--r--src/libs/7zip/win/7zFormat.txt (renamed from src/libs/7zip/win/DOC/7zFormat.txt)84
-rw-r--r--src/libs/7zip/win/C/Aes.c282
-rw-r--r--src/libs/7zip/win/C/Aes.h38
-rw-r--r--src/libs/7zip/win/C/AesOpt.c182
-rw-r--r--src/libs/7zip/win/C/BwtSort.c516
-rw-r--r--src/libs/7zip/win/C/BwtSort.h30
-rw-r--r--src/libs/7zip/win/C/HuffEnc.c146
-rw-r--r--src/libs/7zip/win/C/HuffEnc.h27
-rw-r--r--src/libs/7zip/win/C/Ppmd.h81
-rw-r--r--src/libs/7zip/win/C/Ppmd7.c708
-rw-r--r--src/libs/7zip/win/C/Ppmd7.h140
-rw-r--r--src/libs/7zip/win/C/Ppmd7Dec.c187
-rw-r--r--src/libs/7zip/win/C/Ppmd7Enc.c185
-rw-r--r--src/libs/7zip/win/C/Ppmd8.c1120
-rw-r--r--src/libs/7zip/win/C/Ppmd8.h133
-rw-r--r--src/libs/7zip/win/C/Ppmd8Dec.c155
-rw-r--r--src/libs/7zip/win/C/Ppmd8Enc.c161
-rw-r--r--src/libs/7zip/win/C/Sort.c93
-rw-r--r--src/libs/7zip/win/C/Sort.h20
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/ApmHandler.cpp356
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Archive.def6
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Archive2.def9
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/ArjHandler.cpp798
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Bz2Handler.cpp423
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.cpp189
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.h44
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.cpp929
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.h28
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.cpp15
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.h44
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.cpp272
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.h161
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabItem.h63
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/CabRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Cab/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.cpp721
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.h29
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.cpp24
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.h28
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.cpp937
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.h244
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Chm/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.cpp239
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.h28
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.cpp389
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.h119
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Com/ComRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.cpp19
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.h32
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.cpp239
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.h88
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.cpp99
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.h69
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.cpp62
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.h12
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp18
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.h36
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/CpioHandler.cpp624
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/CramfsHandler.cpp644
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/DebHandler.cpp413
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.cpp118
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.h35
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/DllExports.cpp47
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/DmgHandler.cpp918
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/ElfHandler.cpp534
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/FatHandler.cpp996
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/FlvHandler.cpp544
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/GzHandler.cpp698
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.cpp243
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.h26
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.cpp480
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.h154
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.cpp326
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.h30
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.cpp21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.h61
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.cpp453
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.h315
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoItem.h141
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Iso/StdAfx.h9
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/LzhHandler.cpp775
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/MachoHandler.cpp500
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/MbrHandler.cpp507
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/MslzHandler.cpp257
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/MubHandler.cpp266
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.cpp130
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.h47
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.cpp510
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.h43
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisIn.cpp1461
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisIn.h181
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Nsis/StdAfx.h9
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/NtfsHandler.cpp1764
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/PeHandler.cpp1752
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/PpmdHandler.cpp456
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarHandler.cpp869
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarHandler.h66
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarHeader.cpp21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarHeader.h205
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarIn.cpp478
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarIn.h123
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarItem.cpp55
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarItem.h79
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp78
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/RarVolumeInStream.h49
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/StdAfx.cpp3
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Rar/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/RpmHandler.cpp292
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/SquashfsHandler.cpp2155
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/SwfHandler.cpp706
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/StdAfx.h9
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarHandler.cpp386
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarHandler.h61
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarHandlerOut.cpp122
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarHeader.cpp25
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarHeader.h108
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarIn.cpp207
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarIn.h17
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarItem.h72
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarOut.cpp187
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarOut.h28
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarRegister.cpp18
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarUpdate.cpp139
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Tar/TarUpdate.h34
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Udf/StdAfx.h9
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Udf/UdfHandler.cpp451
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Udf/UdfHandler.h37
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Udf/UdfIn.cpp876
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Udf/UdfIn.h375
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Udf/UdfRegister.cpp13
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/VhdHandler.cpp734
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/WimHandler.cpp660
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/WimHandler.h77
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/WimHandlerOut.cpp639
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/WimIn.cpp855
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/WimIn.h297
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Wim/WimRegister.cpp18
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/XarHandler.cpp588
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/ZHandler.cpp161
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipAddCommon.cpp379
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipAddCommon.h56
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipCompressionMode.h42
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipHandler.cpp822
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipHandler.h101
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp531
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipHeader.cpp36
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipHeader.h284
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipIn.cpp893
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipIn.h125
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipItem.cpp172
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipItem.h281
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipItemEx.h34
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipOut.cpp289
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipOut.h56
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipRegister.cpp18
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipUpdate.cpp1068
-rw-r--r--src/libs/7zip/win/CPP/7zip/Archive/Zip/ZipUpdate.h58
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/InMemStream.cpp222
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/InMemStream.h284
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/MemBlocks.cpp183
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/MemBlocks.h71
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/OutMemStream.cpp142
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/OutMemStream.h96
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/ProgressMt.cpp53
-rw-r--r--src/libs/7zip/win/CPP/7zip/Common/ProgressMt.h46
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ArjDecoder1.cpp309
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ArjDecoder1.h98
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ArjDecoder2.cpp90
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ArjDecoder2.h59
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Const.h54
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Crc.cpp26
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Crc.h31
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Decoder.cpp943
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Decoder.h205
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Encoder.cpp895
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Encoder.h245
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BZip2Register.cpp20
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BitlDecoder.cpp24
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BitlDecoder.h141
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BitlEncoder.h57
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BitmDecoder.h66
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/BitmEncoder.h50
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Deflate64Register.cpp20
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeflateConst.h134
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeflateDecoder.cpp353
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeflateDecoder.h157
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeflateEncoder.cpp986
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeflateEncoder.h211
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DeflateRegister.cpp21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DllExports.cpp45
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/DllExports2.cpp28
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/HuffmanDecoder.h89
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ImplodeDecoder.cpp219
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ImplodeDecoder.h57
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp89
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ImplodeHuffmanDecoder.h34
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzOutWindow.cpp14
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzOutWindow.h66
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzhDecoder.cpp220
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzhDecoder.h106
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzx.h61
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzx86Converter.cpp90
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Lzx86Converter.h46
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzxDecoder.cpp387
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/LzxDecoder.h159
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Mtf8.h193
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdDecoder.cpp167
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdDecoder.h78
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdEncoder.cpp119
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdEncoder.h48
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdRegister.cpp21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdZip.cpp223
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/PpmdZip.h72
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/QuantumDecoder.cpp175
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/QuantumDecoder.h264
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar1Decoder.cpp480
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar1Decoder.h88
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar2Decoder.cpp391
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar2Decoder.h174
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar3Decoder.cpp897
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar3Decoder.h267
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar3Vm.cpp1091
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/Rar3Vm.h179
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/RarCodecsRegister.cpp26
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ShrinkDecoder.cpp145
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ShrinkDecoder.h38
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ZDecoder.cpp159
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ZDecoder.h42
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ZlibDecoder.cpp89
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ZlibDecoder.h48
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ZlibEncoder.cpp61
-rw-r--r--src/libs/7zip/win/CPP/7zip/Compress/ZlibEncoder.h48
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/7zAes.cpp244
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/7zAes.h117
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/7zAesRegister.cpp18
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/HmacSha1.cpp109
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/HmacSha1.h39
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/MyAes.cpp48
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/MyAes.h38
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp83
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/Pbkdf2HmacSha1.h21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/RandGen.cpp107
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/RandGen.h21
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/Rar20Crypto.cpp133
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/Rar20Crypto.h50
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/RarAes.cpp134
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/RarAes.h47
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/Sha1.cpp229
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/Sha1.h68
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/StdAfx.h8
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/WzAes.cpp221
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/WzAes.h125
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/ZipCrypto.cpp88
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/ZipCrypto.h56
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/ZipStrong.cpp164
-rw-r--r--src/libs/7zip/win/CPP/7zip/Crypto/ZipStrong.h47
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/CompressCall.cpp246
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/CompressCall.h24
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/CompressCall2.cpp178
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/Update.h4
-rw-r--r--src/libs/7zip/win/CPP/7zip/UI/Common/ZipRegistry.cpp293
-rw-r--r--src/libs/7zip/win/CPP/Common/Lang.cpp130
-rw-r--r--src/libs/7zip/win/CPP/Common/Lang.h28
-rw-r--r--src/libs/7zip/win/CPP/Common/MyMap.cpp140
-rw-r--r--src/libs/7zip/win/CPP/Common/MyMap.h28
-rw-r--r--src/libs/7zip/win/CPP/Common/MyWindows.cpp109
-rw-r--r--src/libs/7zip/win/CPP/Common/MyXml.cpp209
-rw-r--r--src/libs/7zip/win/CPP/Common/MyXml.h40
-rw-r--r--src/libs/7zip/win/CPP/Common/Random.cpp26
-rw-r--r--src/libs/7zip/win/CPP/Common/Random.h16
-rw-r--r--src/libs/7zip/win/CPP/Common/TextConfig.cpp138
-rw-r--r--src/libs/7zip/win/CPP/Common/TextConfig.h22
-rw-r--r--src/libs/7zip/win/CPP/Windows/COM.cpp37
-rw-r--r--src/libs/7zip/win/CPP/Windows/COM.h69
-rw-r--r--src/libs/7zip/win/CPP/Windows/Clipboard.cpp135
-rw-r--r--src/libs/7zip/win/CPP/Windows/Clipboard.h28
-rw-r--r--src/libs/7zip/win/CPP/Windows/CommonDialog.cpp184
-rw-r--r--src/libs/7zip/win/CPP/Windows/CommonDialog.h19
-rw-r--r--src/libs/7zip/win/CPP/Windows/Console.cpp10
-rw-r--r--src/libs/7zip/win/CPP/Windows/Console.h52
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileSystem.cpp126
-rw-r--r--src/libs/7zip/win/CPP/Windows/FileSystem.h51
-rw-r--r--src/libs/7zip/win/CPP/Windows/Memory.cpp36
-rw-r--r--src/libs/7zip/win/CPP/Windows/Memory.h53
-rw-r--r--src/libs/7zip/win/CPP/Windows/Menu.cpp191
-rw-r--r--src/libs/7zip/win/CPP/Windows/Menu.h153
-rw-r--r--src/libs/7zip/win/CPP/Windows/NationalTime.cpp37
-rw-r--r--src/libs/7zip/win/CPP/Windows/NationalTime.h20
-rw-r--r--src/libs/7zip/win/CPP/Windows/Net.cpp380
-rw-r--r--src/libs/7zip/win/CPP/Windows/Net.h87
-rw-r--r--src/libs/7zip/win/CPP/Windows/Process.cpp81
-rw-r--r--src/libs/7zip/win/CPP/Windows/Process.h100
-rw-r--r--src/libs/7zip/win/CPP/Windows/ProcessMessages.cpp22
-rw-r--r--src/libs/7zip/win/CPP/Windows/ProcessMessages.h14
-rw-r--r--src/libs/7zip/win/CPP/Windows/PropVariantUtils.cpp78
-rw-r--r--src/libs/7zip/win/CPP/Windows/PropVariantUtils.h28
-rw-r--r--src/libs/7zip/win/CPP/Windows/ResourceString.cpp64
-rw-r--r--src/libs/7zip/win/CPP/Windows/ResourceString.h22
-rw-r--r--src/libs/7zip/win/CPP/Windows/Security.cpp179
-rw-r--r--src/libs/7zip/win/CPP/Windows/Security.h167
-rw-r--r--src/libs/7zip/win/CPP/Windows/Shell.cpp335
-rw-r--r--src/libs/7zip/win/CPP/Windows/Shell.h93
-rw-r--r--src/libs/7zip/win/CPP/Windows/Window.cpp169
-rw-r--r--src/libs/7zip/win/CPP/Windows/Window.h261
-rw-r--r--src/libs/7zip/win/DOC/License.txt52
-rw-r--r--src/libs/7zip/win/DOC/copying.txt504
-rw-r--r--src/libs/7zip/win/DOC/history.txt456
-rw-r--r--src/libs/7zip/win/DOC/readme.txt181
-rw-r--r--src/libs/7zip/win/DOC/unRarLicense.txt41
-rw-r--r--src/libs/7zip/win/Methods.txt (renamed from src/libs/7zip/win/DOC/Methods.txt)0
-rw-r--r--src/libs/7zip/win/history.txt271
-rw-r--r--src/libs/7zip/win/lzma.txt (renamed from src/libs/7zip/win/DOC/lzma.txt)0
-rw-r--r--src/libs/7zip/win/win.pri164
321 files changed, 348 insertions, 67336 deletions
diff --git a/src/libs/7zip/win/DOC/7zC.txt b/src/libs/7zip/win/7zC.txt
index 5d5d06d7b..5d5d06d7b 100644
--- a/src/libs/7zip/win/DOC/7zC.txt
+++ b/src/libs/7zip/win/7zC.txt
diff --git a/src/libs/7zip/win/DOC/7zFormat.txt b/src/libs/7zip/win/7zFormat.txt
index 55b52b1b9..e1cf7380d 100644
--- a/src/libs/7zip/win/DOC/7zFormat.txt
+++ b/src/libs/7zip/win/7zFormat.txt
@@ -1,5 +1,5 @@
-7z Format description (4.59)
-----------------------------
+7z Format description (2.30 Beta 25)
+-----------------------------------
This file contains description of 7z archive format.
7z archive can contain files compressed with any method.
@@ -126,43 +126,40 @@ UINT64 means real UINT64 encoded with the following scheme:
Property IDs
------------
-0x00 = kEnd
+0x00 = kEnd,
-0x01 = kHeader
+0x01 = kHeader,
-0x02 = kArchiveProperties
+0x02 = kArchiveProperties,
-0x03 = kAdditionalStreamsInfo
-0x04 = kMainStreamsInfo
-0x05 = kFilesInfo
+0x03 = kAdditionalStreamsInfo,
+0x04 = kMainStreamsInfo,
+0x05 = kFilesInfo,
-0x06 = kPackInfo
-0x07 = kUnPackInfo
-0x08 = kSubStreamsInfo
+0x06 = kPackInfo,
+0x07 = kUnPackInfo,
+0x08 = kSubStreamsInfo,
-0x09 = kSize
-0x0A = kCRC
+0x09 = kSize,
+0x0A = kCRC,
-0x0B = kFolder
+0x0B = kFolder,
-0x0C = kCodersUnPackSize
-0x0D = kNumUnPackStream
+0x0C = kCodersUnPackSize,
+0x0D = kNumUnPackStream,
-0x0E = kEmptyStream
-0x0F = kEmptyFile
-0x10 = kAnti
+0x0E = kEmptyStream,
+0x0F = kEmptyFile,
+0x10 = kAnti,
-0x11 = kName
-0x12 = kCTime
-0x13 = kATime
-0x14 = kMTime
-0x15 = kWinAttributes
-0x16 = kComment
+0x11 = kName,
+0x12 = kCreationTime,
+0x13 = kLastAccessTime,
+0x14 = kLastWriteTime,
+0x15 = kWinAttributes,
+0x16 = kComment,
-0x17 = kEncodedHeader
-
-0x18 = kStartPos
-0x19 = kDummy
+0x17 = kEncodedHeader,
7z format headers
@@ -241,19 +238,24 @@ Folder
{
BYTE
{
- 0:3 CodecIdSize
- 4: Is Complex Coder
- 5: There Are Attributes
- 6: Reserved
- 7: There are more alternative methods. (Not used anymore, must be 0).
+ 0:3 DecompressionMethod.IDSize
+ 4:
+ 0 - IsSimple
+ 1 - Is not simple
+ 5:
+ 0 - No Attributes
+ 1 - There Are Attributes
+ 7:
+ 0 - Last Method in Alternative_Method_List
+ 1 - There are more alternative methods
}
- BYTE CodecId[CodecIdSize]
- if (Is Complex Coder)
+ BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]
+ if (!IsSimple)
{
UINT64 NumInStreams;
UINT64 NumOutStreams;
}
- if (There Are Attributes)
+ if (DecompressionMethod[0] != 0)
{
UINT64 PropertiesSize
BYTE Properties[PropertiesSize]
@@ -385,9 +387,9 @@ FilesInfo
for(EmptyStreams)
BIT IsAntiFile
- case kCTime: (0x12)
- case kATime: (0x13)
- case kMTime: (0x14)
+ case kCreationTime: (0x12)
+ case kLastAccessTime: (0x13)
+ case kLastWriteTime: (0x14)
BYTE AllAreDefined
if (AllAreDefined == 0)
{
@@ -399,7 +401,7 @@ FilesInfo
UINT64 DataIndex
[]
for(Definded Items)
- UINT64 Time
+ UINT32 Time
[]
kNames: (0x11)
diff --git a/src/libs/7zip/win/C/Aes.c b/src/libs/7zip/win/C/Aes.c
deleted file mode 100644
index e7221cd2b..000000000
--- a/src/libs/7zip/win/C/Aes.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/* Aes.c -- AES encryption / decryption
-2009-11-23 : Igor Pavlov : Public domain */
-
-#include "Aes.h"
-#include "CpuArch.h"
-
-static UInt32 T[256 * 4];
-static Byte Sbox[256] = {
- 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
- 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
- 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
- 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
- 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
- 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
- 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
- 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
- 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
- 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
- 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
- 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
- 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
- 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
- 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
- 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16};
-
-void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);
-void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);
-void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);
-
-void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
-void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
-void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *ivAes, Byte *data, size_t numBlocks);
-
-AES_CODE_FUNC g_AesCbc_Encode;
-AES_CODE_FUNC g_AesCbc_Decode;
-AES_CODE_FUNC g_AesCtr_Code;
-
-static UInt32 D[256 * 4];
-static Byte InvS[256];
-
-static Byte Rcon[11] = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
-
-#define xtime(x) ((((x) << 1) ^ (((x) & 0x80) != 0 ? 0x1B : 0)) & 0xFF)
-
-#define Ui32(a0, a1, a2, a3) ((UInt32)(a0) | ((UInt32)(a1) << 8) | ((UInt32)(a2) << 16) | ((UInt32)(a3) << 24))
-
-#define gb0(x) ( (x) & 0xFF)
-#define gb1(x) (((x) >> ( 8)) & 0xFF)
-#define gb2(x) (((x) >> (16)) & 0xFF)
-#define gb3(x) (((x) >> (24)) & 0xFF)
-
-void AesGenTables(void)
-{
- unsigned i;
- for (i = 0; i < 256; i++)
- InvS[Sbox[i]] = (Byte)i;
- for (i = 0; i < 256; i++)
- {
- {
- UInt32 a1 = Sbox[i];
- UInt32 a2 = xtime(a1);
- UInt32 a3 = a2 ^ a1;
- T[ i] = Ui32(a2, a1, a1, a3);
- T[0x100 + i] = Ui32(a3, a2, a1, a1);
- T[0x200 + i] = Ui32(a1, a3, a2, a1);
- T[0x300 + i] = Ui32(a1, a1, a3, a2);
- }
- {
- UInt32 a1 = InvS[i];
- UInt32 a2 = xtime(a1);
- UInt32 a4 = xtime(a2);
- UInt32 a8 = xtime(a4);
- UInt32 a9 = a8 ^ a1;
- UInt32 aB = a8 ^ a2 ^ a1;
- UInt32 aD = a8 ^ a4 ^ a1;
- UInt32 aE = a8 ^ a4 ^ a2;
- D[ i] = Ui32(aE, a9, aD, aB);
- D[0x100 + i] = Ui32(aB, aE, a9, aD);
- D[0x200 + i] = Ui32(aD, aB, aE, a9);
- D[0x300 + i] = Ui32(a9, aD, aB, aE);
- }
- }
- g_AesCbc_Encode = AesCbc_Encode;
- g_AesCbc_Decode = AesCbc_Decode;
- g_AesCtr_Code = AesCtr_Code;
- #ifdef MY_CPU_X86_OR_AMD64
- if (CPU_Is_Aes_Supported())
- {
- g_AesCbc_Encode = AesCbc_Encode_Intel;
- g_AesCbc_Decode = AesCbc_Decode_Intel;
- g_AesCtr_Code = AesCtr_Code_Intel;
- }
- #endif
-}
-
-#define HT(i, x, s) (T + (x << 8))[gb ## x(s[(i + x) & 3])]
-#define HT4(m, i, s, p) m[i] = \
- HT(i, 0, s) ^ \
- HT(i, 1, s) ^ \
- HT(i, 2, s) ^ \
- HT(i, 3, s) ^ w[p + i]
-/* such order (2031) in HT16 is for VC6/K8 speed optimization) */
-#define HT16(m, s, p) \
- HT4(m, 2, s, p); \
- HT4(m, 0, s, p); \
- HT4(m, 3, s, p); \
- HT4(m, 1, s, p); \
-
-#define FT(i, x) Sbox[gb ## x(m[(i + x) & 3])]
-#define FT4(i) dest[i] = Ui32(FT(i, 0), FT(i, 1), FT(i, 2), FT(i, 3)) ^ w[i];
-
-#define HD(i, x, s) (D + (x << 8))[gb ## x(s[(i - x) & 3])]
-#define HD4(m, i, s, p) m[i] = \
- HD(i, 0, s) ^ \
- HD(i, 1, s) ^ \
- HD(i, 2, s) ^ \
- HD(i, 3, s) ^ w[p + i];
-/* such order (0231) in HD16 is for VC6/K8 speed optimization) */
-#define HD16(m, s, p) \
- HD4(m, 0, s, p); \
- HD4(m, 2, s, p); \
- HD4(m, 3, s, p); \
- HD4(m, 1, s, p); \
-
-#define FD(i, x) InvS[gb ## x(m[(i - x) & 3])]
-#define FD4(i) dest[i] = Ui32(FD(i, 0), FD(i, 1), FD(i, 2), FD(i, 3)) ^ w[i];
-
-void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *w, const Byte *key, unsigned keySize)
-{
- unsigned i, wSize;
- wSize = keySize + 28;
- keySize /= 4;
- w[0] = ((UInt32)keySize / 2) + 3;
- w += 4;
-
- for (i = 0; i < keySize; i++, key += 4)
- w[i] = GetUi32(key);
-
- for (; i < wSize; i++)
- {
- UInt32 t = w[i - 1];
- unsigned rem = i % keySize;
- if (rem == 0)
- t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);
- else if (keySize > 6 && rem == 4)
- t = Ui32(Sbox[gb0(t)], Sbox[gb1(t)], Sbox[gb2(t)], Sbox[gb3(t)]);
- w[i] = w[i - keySize] ^ t;
- }
-}
-
-void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *w, const Byte *key, unsigned keySize)
-{
- unsigned i, num;
- Aes_SetKey_Enc(w, key, keySize);
- num = keySize + 20;
- w += 8;
- for (i = 0; i < num; i++)
- {
- UInt32 r = w[i];
- w[i] =
- D[ Sbox[gb0(r)]] ^
- D[0x100 + Sbox[gb1(r)]] ^
- D[0x200 + Sbox[gb2(r)]] ^
- D[0x300 + Sbox[gb3(r)]];
- }
-}
-
-/* Aes_Encode and Aes_Decode functions work with little-endian words.
- src and dest are pointers to 4 UInt32 words.
- arc and dest can point to same block */
-
-static void Aes_Encode(const UInt32 *w, UInt32 *dest, const UInt32 *src)
-{
- UInt32 s[4];
- UInt32 m[4];
- UInt32 numRounds2 = w[0];
- w += 4;
- s[0] = src[0] ^ w[0];
- s[1] = src[1] ^ w[1];
- s[2] = src[2] ^ w[2];
- s[3] = src[3] ^ w[3];
- w += 4;
- for (;;)
- {
- HT16(m, s, 0);
- if (--numRounds2 == 0)
- break;
- HT16(s, m, 4);
- w += 8;
- }
- w += 4;
- FT4(0); FT4(1); FT4(2); FT4(3);
-}
-
-static void Aes_Decode(const UInt32 *w, UInt32 *dest, const UInt32 *src)
-{
- UInt32 s[4];
- UInt32 m[4];
- UInt32 numRounds2 = w[0];
- w += 4 + numRounds2 * 8;
- s[0] = src[0] ^ w[0];
- s[1] = src[1] ^ w[1];
- s[2] = src[2] ^ w[2];
- s[3] = src[3] ^ w[3];
- for (;;)
- {
- w -= 8;
- HD16(m, s, 4);
- if (--numRounds2 == 0)
- break;
- HD16(s, m, 0);
- }
- FD4(0); FD4(1); FD4(2); FD4(3);
-}
-
-void AesCbc_Init(UInt32 *p, const Byte *iv)
-{
- unsigned i;
- for (i = 0; i < 4; i++)
- p[i] = GetUi32(iv + i * 4);
-}
-
-void MY_FAST_CALL AesCbc_Encode(UInt32 *p, Byte *data, size_t numBlocks)
-{
- for (; numBlocks != 0; numBlocks--, data += AES_BLOCK_SIZE)
- {
- p[0] ^= GetUi32(data);
- p[1] ^= GetUi32(data + 4);
- p[2] ^= GetUi32(data + 8);
- p[3] ^= GetUi32(data + 12);
-
- Aes_Encode(p + 4, p, p);
-
- SetUi32(data, p[0]);
- SetUi32(data + 4, p[1]);
- SetUi32(data + 8, p[2]);
- SetUi32(data + 12, p[3]);
- }
-}
-
-void MY_FAST_CALL AesCbc_Decode(UInt32 *p, Byte *data, size_t numBlocks)
-{
- UInt32 in[4], out[4];
- for (; numBlocks != 0; numBlocks--, data += AES_BLOCK_SIZE)
- {
- in[0] = GetUi32(data);
- in[1] = GetUi32(data + 4);
- in[2] = GetUi32(data + 8);
- in[3] = GetUi32(data + 12);
-
- Aes_Decode(p + 4, out, in);
-
- SetUi32(data, p[0] ^ out[0]);
- SetUi32(data + 4, p[1] ^ out[1]);
- SetUi32(data + 8, p[2] ^ out[2]);
- SetUi32(data + 12, p[3] ^ out[3]);
-
- p[0] = in[0];
- p[1] = in[1];
- p[2] = in[2];
- p[3] = in[3];
- }
-}
-
-void MY_FAST_CALL AesCtr_Code(UInt32 *p, Byte *data, size_t numBlocks)
-{
- for (; numBlocks != 0; numBlocks--)
- {
- UInt32 temp[4];
- Byte buf[16];
- int i;
- if (++p[0] == 0)
- p[1]++;
- Aes_Encode(p + 4, temp, p);
- SetUi32(buf, temp[0]);
- SetUi32(buf + 4, temp[1]);
- SetUi32(buf + 8, temp[2]);
- SetUi32(buf + 12, temp[3]);
- for (i = 0; i < 16; i++)
- *data++ ^= buf[i];
- }
-}
diff --git a/src/libs/7zip/win/C/Aes.h b/src/libs/7zip/win/C/Aes.h
deleted file mode 100644
index c9b0677c8..000000000
--- a/src/libs/7zip/win/C/Aes.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Aes.h -- AES encryption / decryption
-2009-11-23 : Igor Pavlov : Public domain */
-
-#ifndef __AES_H
-#define __AES_H
-
-#include "Types.h"
-
-EXTERN_C_BEGIN
-
-#define AES_BLOCK_SIZE 16
-
-/* Call AesGenTables one time before other AES functions */
-void AesGenTables(void);
-
-/* UInt32 pointers must be 16-byte aligned */
-
-/* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */
-#define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4)
-
-/* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */
-/* keySize = 16 or 24 or 32 (bytes) */
-typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize);
-void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize);
-void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize);
-
-/* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */
-void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
-/* data - 16-byte aligned pointer to data */
-/* numBlocks - the number of 16-byte blocks in data array */
-typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);
-extern AES_CODE_FUNC g_AesCbc_Encode;
-extern AES_CODE_FUNC g_AesCbc_Decode;
-extern AES_CODE_FUNC g_AesCtr_Code;
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/AesOpt.c b/src/libs/7zip/win/C/AesOpt.c
deleted file mode 100644
index c0bd8bc15..000000000
--- a/src/libs/7zip/win/C/AesOpt.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/* AesOpt.c -- Intel's AES
-2009-11-23 : Igor Pavlov : Public domain */
-
-#include "CpuArch.h"
-
-#ifdef MY_CPU_X86_OR_AMD64
-#if _MSC_VER >= 1500
-//#define USE_INTEL_AES
-#endif
-#endif
-
-#ifdef USE_INTEL_AES
-
-#include <wmmintrin.h>
-
-void MY_FAST_CALL AesCbc_Encode_Intel(__m128i *p, __m128i *data, size_t numBlocks)
-{
- __m128i m = *p;
- for (; numBlocks != 0; numBlocks--, data++)
- {
- UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
- const __m128i *w = p + 3;
- m = _mm_xor_si128(m, *data);
- m = _mm_xor_si128(m, p[2]);
- do
- {
- m = _mm_aesenc_si128(m, w[0]);
- m = _mm_aesenc_si128(m, w[1]);
- w += 2;
- }
- while (--numRounds2 != 0);
- m = _mm_aesenc_si128(m, w[0]);
- m = _mm_aesenclast_si128(m, w[1]);
- *data = m;
- }
- *p = m;
-}
-
-#define NUM_WAYS 3
-
-#define AES_OP_W(op, n) { \
- const __m128i t = w[n]; \
- m0 = op(m0, t); \
- m1 = op(m1, t); \
- m2 = op(m2, t); \
- }
-
-#define AES_DEC(n) AES_OP_W(_mm_aesdec_si128, n)
-#define AES_DEC_LAST(n) AES_OP_W(_mm_aesdeclast_si128, n)
-#define AES_ENC(n) AES_OP_W(_mm_aesenc_si128, n)
-#define AES_ENC_LAST(n) AES_OP_W(_mm_aesenclast_si128, n)
-
-void MY_FAST_CALL AesCbc_Decode_Intel(__m128i *p, __m128i *data, size_t numBlocks)
-{
- __m128i iv = *p;
- for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS)
- {
- UInt32 numRounds2 = *(const UInt32 *)(p + 1);
- const __m128i *w = p + numRounds2 * 2;
- __m128i m0, m1, m2;
- {
- const __m128i t = w[2];
- m0 = _mm_xor_si128(t, data[0]);
- m1 = _mm_xor_si128(t, data[1]);
- m2 = _mm_xor_si128(t, data[2]);
- }
- numRounds2--;
- do
- {
- AES_DEC(1)
- AES_DEC(0)
- w -= 2;
- }
- while (--numRounds2 != 0);
- AES_DEC(1)
- AES_DEC_LAST(0)
-
- {
- __m128i t;
- t = _mm_xor_si128(m0, iv); iv = data[0]; data[0] = t;
- t = _mm_xor_si128(m1, iv); iv = data[1]; data[1] = t;
- t = _mm_xor_si128(m2, iv); iv = data[2]; data[2] = t;
- }
- }
- for (; numBlocks != 0; numBlocks--, data++)
- {
- UInt32 numRounds2 = *(const UInt32 *)(p + 1);
- const __m128i *w = p + numRounds2 * 2;
- __m128i m = _mm_xor_si128(w[2], *data);
- numRounds2--;
- do
- {
- m = _mm_aesdec_si128(m, w[1]);
- m = _mm_aesdec_si128(m, w[0]);
- w -= 2;
- }
- while (--numRounds2 != 0);
- m = _mm_aesdec_si128(m, w[1]);
- m = _mm_aesdeclast_si128(m, w[0]);
-
- m = _mm_xor_si128(m, iv);
- iv = *data;
- *data = m;
- }
- *p = iv;
-}
-
-void MY_FAST_CALL AesCtr_Code_Intel(__m128i *p, __m128i *data, size_t numBlocks)
-{
- __m128i ctr = *p;
- __m128i one;
- one.m128i_u64[0] = 1;
- one.m128i_u64[1] = 0;
- for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS)
- {
- UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
- const __m128i *w = p;
- __m128i m0, m1, m2;
- {
- const __m128i t = w[2];
- ctr = _mm_add_epi64(ctr, one); m0 = _mm_xor_si128(ctr, t);
- ctr = _mm_add_epi64(ctr, one); m1 = _mm_xor_si128(ctr, t);
- ctr = _mm_add_epi64(ctr, one); m2 = _mm_xor_si128(ctr, t);
- }
- w += 3;
- do
- {
- AES_ENC(0)
- AES_ENC(1)
- w += 2;
- }
- while (--numRounds2 != 0);
- AES_ENC(0)
- AES_ENC_LAST(1)
- data[0] = _mm_xor_si128(data[0], m0);
- data[1] = _mm_xor_si128(data[1], m1);
- data[2] = _mm_xor_si128(data[2], m2);
- }
- for (; numBlocks != 0; numBlocks--, data++)
- {
- UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1;
- const __m128i *w = p;
- __m128i m;
- ctr = _mm_add_epi64(ctr, one);
- m = _mm_xor_si128(ctr, p[2]);
- w += 3;
- do
- {
- m = _mm_aesenc_si128(m, w[0]);
- m = _mm_aesenc_si128(m, w[1]);
- w += 2;
- }
- while (--numRounds2 != 0);
- m = _mm_aesenc_si128(m, w[0]);
- m = _mm_aesenclast_si128(m, w[1]);
- *data = _mm_xor_si128(*data, m);
- }
- *p = ctr;
-}
-
-#else
-
-void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks);
-void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks);
-void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks);
-
-void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *p, Byte *data, size_t numBlocks)
-{
- AesCbc_Encode(p, data, numBlocks);
-}
-
-void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *p, Byte *data, size_t numBlocks)
-{
- AesCbc_Decode(p, data, numBlocks);
-}
-
-void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *p, Byte *data, size_t numBlocks)
-{
- AesCtr_Code(p, data, numBlocks);
-}
-
-#endif
diff --git a/src/libs/7zip/win/C/BwtSort.c b/src/libs/7zip/win/C/BwtSort.c
deleted file mode 100644
index 207305072..000000000
--- a/src/libs/7zip/win/C/BwtSort.c
+++ /dev/null
@@ -1,516 +0,0 @@
-/* BwtSort.c -- BWT block sorting
-2008-08-17
-Igor Pavlov
-Public domain */
-
-#include "BwtSort.h"
-#include "Sort.h"
-
-/* #define BLOCK_SORT_USE_HEAP_SORT */
-
-#define NO_INLINE MY_FAST_CALL
-
-/* Don't change it !!! */
-#define kNumHashBytes 2
-#define kNumHashValues (1 << (kNumHashBytes * 8))
-
-/* kNumRefBitsMax must be < (kNumHashBytes * 8) = 16 */
-#define kNumRefBitsMax 12
-
-#define BS_TEMP_SIZE kNumHashValues
-
-#ifdef BLOCK_SORT_EXTERNAL_FLAGS
-
-/* 32 Flags in UInt32 word */
-#define kNumFlagsBits 5
-#define kNumFlagsInWord (1 << kNumFlagsBits)
-#define kFlagsMask (kNumFlagsInWord - 1)
-#define kAllFlags 0xFFFFFFFF
-
-#else
-
-#define kNumBitsMax 20
-#define kIndexMask ((1 << kNumBitsMax) - 1)
-#define kNumExtraBits (32 - kNumBitsMax)
-#define kNumExtra0Bits (kNumExtraBits - 2)
-#define kNumExtra0Mask ((1 << kNumExtra0Bits) - 1)
-
-#define SetFinishedGroupSize(p, size) \
- { *(p) |= ((((size) - 1) & kNumExtra0Mask) << kNumBitsMax); \
- if ((size) > (1 << kNumExtra0Bits)) { \
- *(p) |= 0x40000000; *((p) + 1) |= ((((size) - 1)>> kNumExtra0Bits) << kNumBitsMax); } } \
-
-static void SetGroupSize(UInt32 *p, UInt32 size)
-{
- if (--size == 0)
- return;
- *p |= 0x80000000 | ((size & kNumExtra0Mask) << kNumBitsMax);
- if (size >= (1 << kNumExtra0Bits))
- {
- *p |= 0x40000000;
- p[1] |= ((size >> kNumExtra0Bits) << kNumBitsMax);
- }
-}
-
-#endif
-
-/*
-SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks
- "range" is not real range. It's only for optimization.
-returns: 1 - if there are groups, 0 - no more groups
-*/
-
-UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 groupOffset, UInt32 groupSize, int NumRefBits, UInt32 *Indices
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- , UInt32 left, UInt32 range
- #endif
- )
-{
- UInt32 *ind2 = Indices + groupOffset;
- UInt32 *Groups;
- if (groupSize <= 1)
- {
- /*
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetFinishedGroupSize(ind2, 1);
- #endif
- */
- return 0;
- }
- Groups = Indices + BlockSize + BS_TEMP_SIZE;
- if (groupSize <= ((UInt32)1 << NumRefBits)
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- && groupSize <= range
- #endif
- )
- {
- UInt32 *temp = Indices + BlockSize;
- UInt32 j;
- UInt32 mask, thereAreGroups, group, cg;
- {
- UInt32 gPrev;
- UInt32 gRes = 0;
- {
- UInt32 sp = ind2[0] + NumSortedBytes;
- if (sp >= BlockSize) sp -= BlockSize;
- gPrev = Groups[sp];
- temp[0] = (gPrev << NumRefBits);
- }
-
- for (j = 1; j < groupSize; j++)
- {
- UInt32 sp = ind2[j] + NumSortedBytes;
- UInt32 g;
- if (sp >= BlockSize) sp -= BlockSize;
- g = Groups[sp];
- temp[j] = (g << NumRefBits) | j;
- gRes |= (gPrev ^ g);
- }
- if (gRes == 0)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2, groupSize);
- #endif
- return 1;
- }
- }
-
- HeapSort(temp, groupSize);
- mask = ((1 << NumRefBits) - 1);
- thereAreGroups = 0;
-
- group = groupOffset;
- cg = (temp[0] >> NumRefBits);
- temp[0] = ind2[temp[0] & mask];
-
- {
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags = Groups + BlockSize;
- #else
- UInt32 prevGroupStart = 0;
- #endif
-
- for (j = 1; j < groupSize; j++)
- {
- UInt32 val = temp[j];
- UInt32 cgCur = (val >> NumRefBits);
-
- if (cgCur != cg)
- {
- cg = cgCur;
- group = groupOffset + j;
-
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 t = group - 1;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- }
- #else
- SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
- prevGroupStart = j;
- #endif
- }
- else
- thereAreGroups = 1;
- {
- UInt32 ind = ind2[val & mask];
- temp[j] = ind;
- Groups[ind] = group;
- }
- }
-
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(temp + prevGroupStart, j - prevGroupStart);
- #endif
- }
-
- for (j = 0; j < groupSize; j++)
- ind2[j] = temp[j];
- return thereAreGroups;
- }
-
- /* Check that all strings are in one group (cannot sort) */
- {
- UInt32 group, j;
- UInt32 sp = ind2[0] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- group = Groups[sp];
- for (j = 1; j < groupSize; j++)
- {
- sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- if (Groups[sp] != group)
- break;
- }
- if (j == groupSize)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2, groupSize);
- #endif
- return 1;
- }
- }
-
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- {
- /* ---------- Range Sort ---------- */
- UInt32 i;
- UInt32 mid;
- for (;;)
- {
- UInt32 j;
- if (range <= 1)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2, groupSize);
- #endif
- return 1;
- }
- mid = left + ((range + 1) >> 1);
- j = groupSize;
- i = 0;
- do
- {
- UInt32 sp = ind2[i] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- if (Groups[sp] >= mid)
- {
- for (j--; j > i; j--)
- {
- sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- if (Groups[sp] < mid)
- {
- UInt32 temp = ind2[i]; ind2[i] = ind2[j]; ind2[j] = temp;
- break;
- }
- }
- if (i >= j)
- break;
- }
- }
- while (++i < j);
- if (i == 0)
- {
- range = range - (mid - left);
- left = mid;
- }
- else if (i == groupSize)
- range = (mid - left);
- else
- break;
- }
-
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 t = (groupOffset + i - 1);
- UInt32 *Flags = Groups + BlockSize;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- }
- #endif
-
- {
- UInt32 j;
- for (j = i; j < groupSize; j++)
- Groups[ind2[j]] = groupOffset + i;
- }
-
- {
- UInt32 res = SortGroup(BlockSize, NumSortedBytes, groupOffset, i, NumRefBits, Indices, left, mid - left);
- return res | SortGroup(BlockSize, NumSortedBytes, groupOffset + i, groupSize - i, NumRefBits, Indices, mid, range - (mid - left));
- }
-
- }
-
- #else
-
- /* ---------- Heap Sort ---------- */
-
- {
- UInt32 j;
- for (j = 0; j < groupSize; j++)
- {
- UInt32 sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize;
- ind2[j] = sp;
- }
-
- HeapSortRef(ind2, Groups, groupSize);
-
- /* Write Flags */
- {
- UInt32 sp = ind2[0];
- UInt32 group = Groups[sp];
-
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags = Groups + BlockSize;
- #else
- UInt32 prevGroupStart = 0;
- #endif
-
- for (j = 1; j < groupSize; j++)
- {
- sp = ind2[j];
- if (Groups[sp] != group)
- {
- group = Groups[sp];
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 t = groupOffset + j - 1;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- }
- #else
- SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
- prevGroupStart = j;
- #endif
- }
- }
-
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart);
- #endif
- }
- {
- /* Write new Groups values and Check that there are groups */
- UInt32 thereAreGroups = 0;
- for (j = 0; j < groupSize; j++)
- {
- UInt32 group = groupOffset + j;
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax);
- if ((ind2[j] & 0x40000000) != 0)
- subGroupSize += ((ind2[j + 1] >> kNumBitsMax) << kNumExtra0Bits);
- subGroupSize++;
- for (;;)
- {
- UInt32 original = ind2[j];
- UInt32 sp = original & kIndexMask;
- if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
- ind2[j] = sp | (original & ~kIndexMask);
- Groups[sp] = group;
- if (--subGroupSize == 0)
- break;
- j++;
- thereAreGroups = 1;
- }
- #else
- UInt32 *Flags = Groups + BlockSize;
- for (;;)
- {
- UInt32 sp = ind2[j]; if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes;
- ind2[j] = sp;
- Groups[sp] = group;
- if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0)
- break;
- j++;
- thereAreGroups = 1;
- }
- #endif
- }
- return thereAreGroups;
- }
- }
- #endif
-}
-
-/* conditions: blockSize > 0 */
-UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
-{
- UInt32 *counters = Indices + blockSize;
- UInt32 i;
- UInt32 *Groups;
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 *Flags;
- #endif
-
- /* Radix-Sort for 2 bytes */
- for (i = 0; i < kNumHashValues; i++)
- counters[i] = 0;
- for (i = 0; i < blockSize - 1; i++)
- counters[((UInt32)data[i] << 8) | data[i + 1]]++;
- counters[((UInt32)data[i] << 8) | data[0]]++;
-
- Groups = counters + BS_TEMP_SIZE;
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- Flags = Groups + blockSize;
- {
- UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits;
- for (i = 0; i < numWords; i++)
- Flags[i] = kAllFlags;
- }
- #endif
-
- {
- UInt32 sum = 0;
- for (i = 0; i < kNumHashValues; i++)
- {
- UInt32 groupSize = counters[i];
- if (groupSize > 0)
- {
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 t = sum + groupSize - 1;
- Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask));
- #endif
- sum += groupSize;
- }
- counters[i] = sum - groupSize;
- }
-
- for (i = 0; i < blockSize - 1; i++)
- Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]];
- Groups[i] = counters[((UInt32)data[i] << 8) | data[0]];
-
- for (i = 0; i < blockSize - 1; i++)
- Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i;
- Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
-
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- {
- UInt32 prev = 0;
- for (i = 0; i < kNumHashValues; i++)
- {
- UInt32 prevGroupSize = counters[i] - prev;
- if (prevGroupSize == 0)
- continue;
- SetGroupSize(Indices + prev, prevGroupSize);
- prev = counters[i];
- }
- }
- #endif
- }
-
- {
- int NumRefBits;
- UInt32 NumSortedBytes;
- for (NumRefBits = 0; ((blockSize - 1) >> NumRefBits) != 0; NumRefBits++);
- NumRefBits = 32 - NumRefBits;
- if (NumRefBits > kNumRefBitsMax)
- NumRefBits = kNumRefBitsMax;
-
- for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1)
- {
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- UInt32 finishedGroupSize = 0;
- #endif
- UInt32 newLimit = 0;
- for (i = 0; i < blockSize;)
- {
- UInt32 groupSize;
- #ifdef BLOCK_SORT_EXTERNAL_FLAGS
-
- if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0)
- {
- i++;
- continue;
- }
- for (groupSize = 1;
- (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
- groupSize++);
-
- groupSize++;
-
- #else
-
- groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
- {
- Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
- if ((Indices[i] & 0x40000000) != 0)
- {
- groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
- Indices[i + 1] &= kIndexMask;
- }
- Indices[i] &= kIndexMask;
- groupSize++;
- if (finishedGroup || groupSize == 1)
- {
- Indices[i - finishedGroupSize] &= kIndexMask;
- if (finishedGroupSize > 1)
- Indices[i - finishedGroupSize + 1] &= kIndexMask;
- {
- UInt32 newGroupSize = groupSize + finishedGroupSize;
- SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize);
- finishedGroupSize = newGroupSize;
- }
- i += groupSize;
- continue;
- }
- finishedGroupSize = 0;
- }
-
- #endif
-
- if (NumSortedBytes >= blockSize)
- {
- UInt32 j;
- for (j = 0; j < groupSize; j++)
- {
- UInt32 t = (i + j);
- /* Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); */
- Groups[Indices[t]] = t;
- }
- }
- else
- if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices
- #ifndef BLOCK_SORT_USE_HEAP_SORT
- , 0, blockSize
- #endif
- ) != 0)
- newLimit = i + groupSize;
- i += groupSize;
- }
- if (newLimit == 0)
- break;
- }
- }
- #ifndef BLOCK_SORT_EXTERNAL_FLAGS
- for (i = 0; i < blockSize;)
- {
- UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
- if ((Indices[i] & 0x40000000) != 0)
- {
- groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits);
- Indices[i + 1] &= kIndexMask;
- }
- Indices[i] &= kIndexMask;
- groupSize++;
- i += groupSize;
- }
- #endif
- return Groups[0];
-}
-
diff --git a/src/libs/7zip/win/C/BwtSort.h b/src/libs/7zip/win/C/BwtSort.h
deleted file mode 100644
index ce5598f0f..000000000
--- a/src/libs/7zip/win/C/BwtSort.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* BwtSort.h -- BWT block sorting
-2009-02-07 : Igor Pavlov : Public domain */
-
-#ifndef __BWT_SORT_H
-#define __BWT_SORT_H
-
-#include "Types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M */
-/* #define BLOCK_SORT_EXTERNAL_FLAGS */
-
-#ifdef BLOCK_SORT_EXTERNAL_FLAGS
-#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5))
-#else
-#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0
-#endif
-
-#define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16))
-
-UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/libs/7zip/win/C/HuffEnc.c b/src/libs/7zip/win/C/HuffEnc.c
deleted file mode 100644
index 561c7e5da..000000000
--- a/src/libs/7zip/win/C/HuffEnc.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/* HuffEnc.c -- functions for Huffman encoding
-2009-09-02 : Igor Pavlov : Public domain */
-
-#include "HuffEnc.h"
-#include "Sort.h"
-
-#define kMaxLen 16
-#define NUM_BITS 10
-#define MASK ((1 << NUM_BITS) - 1)
-
-#define NUM_COUNTERS 64
-
-#define HUFFMAN_SPEED_OPT
-
-void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)
-{
- UInt32 num = 0;
- /* if (maxLen > 10) maxLen = 10; */
- {
- UInt32 i;
-
- #ifdef HUFFMAN_SPEED_OPT
-
- UInt32 counters[NUM_COUNTERS];
- for (i = 0; i < NUM_COUNTERS; i++)
- counters[i] = 0;
- for (i = 0; i < numSymbols; i++)
- {
- UInt32 freq = freqs[i];
- counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;
- }
-
- for (i = 1; i < NUM_COUNTERS; i++)
- {
- UInt32 temp = counters[i];
- counters[i] = num;
- num += temp;
- }
-
- for (i = 0; i < numSymbols; i++)
- {
- UInt32 freq = freqs[i];
- if (freq == 0)
- lens[i] = 0;
- else
- p[counters[((freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1)]++] = i | (freq << NUM_BITS);
- }
- counters[0] = 0;
- HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);
-
- #else
-
- for (i = 0; i < numSymbols; i++)
- {
- UInt32 freq = freqs[i];
- if (freq == 0)
- lens[i] = 0;
- else
- p[num++] = i | (freq << NUM_BITS);
- }
- HeapSort(p, num);
-
- #endif
- }
-
- if (num < 2)
- {
- unsigned minCode = 0;
- unsigned maxCode = 1;
- if (num == 1)
- {
- maxCode = (unsigned)p[0] & MASK;
- if (maxCode == 0)
- maxCode++;
- }
- p[minCode] = 0;
- p[maxCode] = 1;
- lens[minCode] = lens[maxCode] = 1;
- return;
- }
-
- {
- UInt32 b, e, i;
-
- i = b = e = 0;
- do
- {
- UInt32 n, m, freq;
- n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
- freq = (p[n] & ~MASK);
- p[n] = (p[n] & MASK) | (e << NUM_BITS);
- m = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
- freq += (p[m] & ~MASK);
- p[m] = (p[m] & MASK) | (e << NUM_BITS);
- p[e] = (p[e] & MASK) | freq;
- e++;
- }
- while (num - e > 1);
-
- {
- UInt32 lenCounters[kMaxLen + 1];
- for (i = 0; i <= kMaxLen; i++)
- lenCounters[i] = 0;
-
- p[--e] &= MASK;
- lenCounters[1] = 2;
- while (e > 0)
- {
- UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;
- p[e] = (p[e] & MASK) | (len << NUM_BITS);
- if (len >= maxLen)
- for (len = maxLen - 1; lenCounters[len] == 0; len--);
- lenCounters[len]--;
- lenCounters[len + 1] += 2;
- }
-
- {
- UInt32 len;
- i = 0;
- for (len = maxLen; len != 0; len--)
- {
- UInt32 num;
- for (num = lenCounters[len]; num != 0; num--)
- lens[p[i++] & MASK] = (Byte)len;
- }
- }
-
- {
- UInt32 nextCodes[kMaxLen + 1];
- {
- UInt32 code = 0;
- UInt32 len;
- for (len = 1; len <= kMaxLen; len++)
- nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;
- }
- /* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
-
- {
- UInt32 i;
- for (i = 0; i < numSymbols; i++)
- p[i] = nextCodes[lens[i]]++;
- }
- }
- }
- }
-}
diff --git a/src/libs/7zip/win/C/HuffEnc.h b/src/libs/7zip/win/C/HuffEnc.h
deleted file mode 100644
index 9cf4bfde8..000000000
--- a/src/libs/7zip/win/C/HuffEnc.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* HuffEnc.h -- Huffman encoding
-2009-02-07 : Igor Pavlov : Public domain */
-
-#ifndef __HUFF_ENC_H
-#define __HUFF_ENC_H
-
-#include "Types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
-Conditions:
- num <= 1024 = 2 ^ NUM_BITS
- Sum(freqs) < 4M = 2 ^ (32 - NUM_BITS)
- maxLen <= 16 = kMaxLen
- Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)
-*/
-
-void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/libs/7zip/win/C/Ppmd.h b/src/libs/7zip/win/C/Ppmd.h
deleted file mode 100644
index 72a1cc52f..000000000
--- a/src/libs/7zip/win/C/Ppmd.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Ppmd.h -- PPMD codec common code
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
-
-#ifndef __PPMD_H
-#define __PPMD_H
-
-#include "Types.h"
-#include "CpuArch.h"
-
-EXTERN_C_BEGIN
-
-#ifdef MY_CPU_32BIT
- #define PPMD_32BIT
-#endif
-
-#define PPMD_INT_BITS 7
-#define PPMD_PERIOD_BITS 7
-#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS))
-
-#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift))
-#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2)
-#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob))
-#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob))
-
-#define PPMD_N1 4
-#define PPMD_N2 4
-#define PPMD_N3 4
-#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4)
-#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4)
-
-/* SEE-contexts for PPM-contexts with masked symbols */
-typedef struct
-{
- UInt16 Summ; /* Freq */
- Byte Shift; /* Speed of Freq change; low Shift is for fast change */
- Byte Count; /* Count to next change of Shift */
-} CPpmd_See;
-
-#define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \
- { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); }
-
-typedef struct
-{
- Byte Symbol;
- Byte Freq;
- UInt16 SuccessorLow;
- UInt16 SuccessorHigh;
-} CPpmd_State;
-
-typedef
- #ifdef PPMD_32BIT
- CPpmd_State *
- #else
- UInt32
- #endif
- CPpmd_State_Ref;
-
-typedef
- #ifdef PPMD_32BIT
- void *
- #else
- UInt32
- #endif
- CPpmd_Void_Ref;
-
-typedef
- #ifdef PPMD_32BIT
- Byte *
- #else
- UInt32
- #endif
- CPpmd_Byte_Ref;
-
-#define PPMD_SetAllBitsIn256Bytes(p) \
- { unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \
- p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }}
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Ppmd7.c b/src/libs/7zip/win/C/Ppmd7.c
deleted file mode 100644
index 060d86d2e..000000000
--- a/src/libs/7zip/win/C/Ppmd7.c
+++ /dev/null
@@ -1,708 +0,0 @@
-/* Ppmd7.c -- PPMdH codec
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
-
-#include <memory.h>
-
-#include "Ppmd7.h"
-
-const Byte PPMD7_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
-static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
-
-#define MAX_FREQ 124
-#define UNIT_SIZE 12
-
-#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
-#define U2I(nu) (p->Units2Indx[(nu) - 1])
-#define I2U(indx) (p->Indx2Units[indx])
-
-#ifdef PPMD_32BIT
- #define REF(ptr) (ptr)
-#else
- #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
-#endif
-
-#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
-
-#define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref))
-#define STATS(ctx) Ppmd7_GetStats(p, ctx)
-#define ONE_STATE(ctx) Ppmd7Context_OneState(ctx)
-#define SUFFIX(ctx) CTX((ctx)->Suffix)
-
-typedef CPpmd7_Context * CTX_PTR;
-
-struct CPpmd7_Node_;
-
-typedef
- #ifdef PPMD_32BIT
- struct CPpmd7_Node_ *
- #else
- UInt32
- #endif
- CPpmd7_Node_Ref;
-
-typedef struct CPpmd7_Node_
-{
- UInt16 Stamp; /* must be at offset 0 as CPpmd7_Context::NumStats. Stamp=0 means free */
- UInt16 NU;
- CPpmd7_Node_Ref Next; /* must be at offset >= 4 */
- CPpmd7_Node_Ref Prev;
-} CPpmd7_Node;
-
-#ifdef PPMD_32BIT
- #define NODE(ptr) (ptr)
-#else
- #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs)))
-#endif
-
-void Ppmd7_Construct(CPpmd7 *p)
-{
- unsigned i, k, m;
-
- p->Base = 0;
-
- for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
- {
- unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
- do { p->Units2Indx[k++] = (Byte)i; } while(--step);
- p->Indx2Units[i] = (Byte)k;
- }
-
- p->NS2BSIndx[0] = (0 << 1);
- p->NS2BSIndx[1] = (1 << 1);
- memset(p->NS2BSIndx + 2, (2 << 1), 9);
- memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
-
- for (i = 0; i < 3; i++)
- p->NS2Indx[i] = (Byte)i;
- for (m = i, k = 1; i < 256; i++)
- {
- p->NS2Indx[i] = (Byte)m;
- if (--k == 0)
- k = (++m) - 2;
- }
-
- memset(p->HB2Flag, 0, 0x40);
- memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
-}
-
-void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->Base);
- p->Size = 0;
- p->Base = 0;
-}
-
-Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)
-{
- if (p->Base == 0 || p->Size != size)
- {
- Ppmd7_Free(p, alloc);
- p->AlignOffset =
- #ifdef PPMD_32BIT
- (4 - size) & 3;
- #else
- 4 - (size & 3);
- #endif
- if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size
- #ifndef PPMD_32BIT
- + UNIT_SIZE
- #endif
- )) == 0)
- return False;
- p->Size = size;
- }
- return True;
-}
-
-static void InsertNode(CPpmd7 *p, void *node, unsigned indx)
-{
- *((CPpmd_Void_Ref *)node) = p->FreeList[indx];
- p->FreeList[indx] = REF(node);
-}
-
-static void *RemoveNode(CPpmd7 *p, unsigned indx)
-{
- CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]);
- p->FreeList[indx] = *node;
- return node;
-}
-
-static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx)
-{
- unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
- ptr = (Byte *)ptr + U2B(I2U(newIndx));
- if (I2U(i = U2I(nu)) != nu)
- {
- unsigned k = I2U(--i);
- InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);
- }
- InsertNode(p, ptr, i);
-}
-
-static void GlueFreeBlocks(CPpmd7 *p)
-{
- #ifdef PPMD_32BIT
- CPpmd7_Node headItem;
- CPpmd7_Node_Ref head = &headItem;
- #else
- CPpmd7_Node_Ref head = p->AlignOffset + p->Size;
- #endif
-
- CPpmd7_Node_Ref n = head;
- unsigned i;
-
- p->GlueCount = 255;
-
- /* create doubly-linked list of free blocks */
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- {
- UInt16 nu = I2U(i);
- CPpmd7_Node_Ref next = (CPpmd7_Node_Ref)p->FreeList[i];
- p->FreeList[i] = 0;
- while (next != 0)
- {
- CPpmd7_Node *node = NODE(next);
- node->Next = n;
- n = NODE(n)->Prev = next;
- next = *(const CPpmd7_Node_Ref *)node;
- node->Stamp = 0;
- node->NU = (UInt16)nu;
- }
- }
- NODE(head)->Stamp = 1;
- NODE(head)->Next = n;
- NODE(n)->Prev = head;
- if (p->LoUnit != p->HiUnit)
- ((CPpmd7_Node *)p->LoUnit)->Stamp = 1;
-
- /* Glue free blocks */
- while (n != head)
- {
- CPpmd7_Node *node = NODE(n);
- UInt32 nu = (UInt32)node->NU;
- for (;;)
- {
- CPpmd7_Node *node2 = NODE(n) + nu;
- nu += node2->NU;
- if (node2->Stamp != 0 || nu >= 0x10000)
- break;
- NODE(node2->Prev)->Next = node2->Next;
- NODE(node2->Next)->Prev = node2->Prev;
- node->NU = (UInt16)nu;
- }
- n = node->Next;
- }
-
- /* Fill lists of free blocks */
- for (n = NODE(head)->Next; n != head;)
- {
- CPpmd7_Node *node = NODE(n);
- unsigned nu;
- CPpmd7_Node_Ref next = node->Next;
- for (nu = node->NU; nu > 128; nu -= 128, node += 128)
- InsertNode(p, node, PPMD_NUM_INDEXES - 1);
- if (I2U(i = U2I(nu)) != nu)
- {
- unsigned k = I2U(--i);
- InsertNode(p, node + k, nu - k - 1);
- }
- InsertNode(p, node, i);
- n = next;
- }
-}
-
-static void *AllocUnitsRare(CPpmd7 *p, unsigned indx)
-{
- unsigned i;
- void *retVal;
- if (p->GlueCount == 0)
- {
- GlueFreeBlocks(p);
- if (p->FreeList[indx] != 0)
- return RemoveNode(p, indx);
- }
- i = indx;
- do
- {
- if (++i == PPMD_NUM_INDEXES)
- {
- UInt32 numBytes = U2B(I2U(indx));
- p->GlueCount--;
- return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);
- }
- }
- while (p->FreeList[i] == 0);
- retVal = RemoveNode(p, i);
- SplitBlock(p, retVal, i, indx);
- return retVal;
-}
-
-static void *AllocUnits(CPpmd7 *p, unsigned indx)
-{
- UInt32 numBytes;
- if (p->FreeList[indx] != 0)
- return RemoveNode(p, indx);
- numBytes = U2B(I2U(indx));
- if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
- {
- void *retVal = p->LoUnit;
- p->LoUnit += numBytes;
- return retVal;
- }
- return AllocUnitsRare(p, indx);
-}
-
-#define MyMem12Cpy(dest, src, num) \
- { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
- do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
-
-static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
-{
- unsigned i0 = U2I(oldNU);
- unsigned i1 = U2I(newNU);
- if (i0 == i1)
- return oldPtr;
- if (p->FreeList[i1] != 0)
- {
- void *ptr = RemoveNode(p, i1);
- MyMem12Cpy(ptr, oldPtr, newNU);
- InsertNode(p, oldPtr, i0);
- return ptr;
- }
- SplitBlock(p, oldPtr, i0, i1);
- return oldPtr;
-}
-
-#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
-
-static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)
-{
- (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
- (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
-}
-
-static void RestartModel(CPpmd7 *p)
-{
- unsigned i, k, m;
-
- memset(p->FreeList, 0, sizeof(p->FreeList));
- p->Text = p->Base + p->AlignOffset;
- p->HiUnit = p->Text + p->Size;
- p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;
- p->GlueCount = 0;
-
- p->OrderFall = p->MaxOrder;
- p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;
- p->PrevSuccess = 0;
-
- p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */
- p->MinContext->Suffix = 0;
- p->MinContext->NumStats = 256;
- p->MinContext->SummFreq = 256 + 1;
- p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
- p->LoUnit += U2B(256 / 2);
- p->MinContext->Stats = REF(p->FoundState);
- for (i = 0; i < 256; i++)
- {
- CPpmd_State *s = &p->FoundState[i];
- s->Symbol = (Byte)i;
- s->Freq = 1;
- SetSuccessor(s, 0);
- }
-
- for (i = 0; i < 128; i++)
- for (k = 0; k < 8; k++)
- {
- UInt16 *dest = p->BinSumm[i] + k;
- UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2));
- for (m = 0; m < 64; m += 8)
- dest[m] = val;
- }
-
- for (i = 0; i < 25; i++)
- for (k = 0; k < 16; k++)
- {
- CPpmd_See *s = &p->See[i][k];
- s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4));
- s->Count = 4;
- }
-}
-
-void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)
-{
- p->MaxOrder = maxOrder;
- RestartModel(p);
- p->DummySee.Shift = PPMD_PERIOD_BITS;
- p->DummySee.Summ = 0; /* unused */
- p->DummySee.Count = 64; /* unused */
-}
-
-static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
-{
- CPpmd_State upState;
- CTX_PTR c = p->MinContext;
- CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
- CPpmd_State *ps[PPMD7_MAX_ORDER];
- unsigned numPs = 0;
-
- if (!skip)
- ps[numPs++] = p->FoundState;
-
- while (c->Suffix)
- {
- CPpmd_Void_Ref successor;
- CPpmd_State *s;
- c = SUFFIX(c);
- if (c->NumStats != 1)
- {
- for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);
- }
- else
- s = ONE_STATE(c);
- successor = SUCCESSOR(s);
- if (successor != upBranch)
- {
- c = CTX(successor);
- if (numPs == 0)
- return c;
- break;
- }
- ps[numPs++] = s;
- }
-
- upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch);
- SetSuccessor(&upState, upBranch + 1);
-
- if (c->NumStats == 1)
- upState.Freq = ONE_STATE(c)->Freq;
- else
- {
- UInt32 cf, s0;
- CPpmd_State *s;
- for (s = STATS(c); s->Symbol != upState.Symbol; s++);
- cf = s->Freq - 1;
- s0 = c->SummFreq - c->NumStats - cf;
- upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((2 * cf + 3 * s0 - 1) / (2 * s0))));
- }
-
- do
- {
- /* Create Child */
- CTX_PTR c1; /* = AllocContext(p); */
- if (p->HiUnit != p->LoUnit)
- c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);
- else if (p->FreeList[0] != 0)
- c1 = (CTX_PTR)RemoveNode(p, 0);
- else
- {
- c1 = (CTX_PTR)AllocUnitsRare(p, 0);
- if (!c1)
- return NULL;
- }
- c1->NumStats = 1;
- *ONE_STATE(c1) = upState;
- c1->Suffix = REF(c);
- SetSuccessor(ps[--numPs], REF(c1));
- c = c1;
- }
- while (numPs != 0);
-
- return c;
-}
-
-static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)
-{
- CPpmd_State tmp = *t1;
- *t1 = *t2;
- *t2 = tmp;
-}
-
-static void UpdateModel(CPpmd7 *p)
-{
- CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
- CTX_PTR c;
- unsigned s0, ns;
-
- if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
- {
- c = SUFFIX(p->MinContext);
-
- if (c->NumStats == 1)
- {
- CPpmd_State *s = ONE_STATE(c);
- if (s->Freq < 32)
- s->Freq++;
- }
- else
- {
- CPpmd_State *s = STATS(c);
- if (s->Symbol != p->FoundState->Symbol)
- {
- do { s++; } while (s->Symbol != p->FoundState->Symbol);
- if (s[0].Freq >= s[-1].Freq)
- {
- SwapStates(&s[0], &s[-1]);
- s--;
- }
- }
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq += 2;
- c->SummFreq += 2;
- }
- }
- }
-
- if (p->OrderFall == 0)
- {
- p->MinContext = p->MaxContext = CreateSuccessors(p, True);
- if (p->MinContext == 0)
- {
- RestartModel(p);
- return;
- }
- SetSuccessor(p->FoundState, REF(p->MinContext));
- return;
- }
-
- *p->Text++ = p->FoundState->Symbol;
- successor = REF(p->Text);
- if (p->Text >= p->UnitsStart)
- {
- RestartModel(p);
- return;
- }
-
- if (fSuccessor)
- {
- if (fSuccessor <= successor)
- {
- CTX_PTR cs = CreateSuccessors(p, False);
- if (cs == NULL)
- {
- RestartModel(p);
- return;
- }
- fSuccessor = REF(cs);
- }
- if (--p->OrderFall == 0)
- {
- successor = fSuccessor;
- p->Text -= (p->MaxContext != p->MinContext);
- }
- }
- else
- {
- SetSuccessor(p->FoundState, successor);
- fSuccessor = REF(p->MinContext);
- }
-
- s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1);
-
- for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c))
- {
- unsigned ns1;
- UInt32 cf, sf;
- if ((ns1 = c->NumStats) != 1)
- {
- if ((ns1 & 1) == 0)
- {
- /* Expand for one UNIT */
- unsigned oldNU = ns1 >> 1;
- unsigned i = U2I(oldNU);
- if (i != U2I(oldNU + 1))
- {
- void *ptr = AllocUnits(p, i + 1);
- void *oldPtr;
- if (!ptr)
- {
- RestartModel(p);
- return;
- }
- oldPtr = STATS(c);
- MyMem12Cpy(ptr, oldPtr, oldNU);
- InsertNode(p, oldPtr, i);
- c->Stats = STATS_REF(ptr);
- }
- }
- c->SummFreq = (UInt16)(c->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & (c->SummFreq <= 8 * ns1)));
- }
- else
- {
- CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
- if (!s)
- {
- RestartModel(p);
- return;
- }
- *s = *ONE_STATE(c);
- c->Stats = REF(s);
- if (s->Freq < MAX_FREQ / 4 - 1)
- s->Freq <<= 1;
- else
- s->Freq = MAX_FREQ - 4;
- c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 3));
- }
- cf = 2 * (UInt32)p->FoundState->Freq * (c->SummFreq + 6);
- sf = (UInt32)s0 + c->SummFreq;
- if (cf < 6 * sf)
- {
- cf = 1 + (cf > sf) + (cf >= 4 * sf);
- c->SummFreq += 3;
- }
- else
- {
- cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf);
- c->SummFreq = (UInt16)(c->SummFreq + cf);
- }
- {
- CPpmd_State *s = STATS(c) + ns1;
- SetSuccessor(s, successor);
- s->Symbol = p->FoundState->Symbol;
- s->Freq = (Byte)cf;
- c->NumStats = (UInt16)(ns1 + 1);
- }
- }
- p->MaxContext = p->MinContext = CTX(fSuccessor);
-}
-
-static void Rescale(CPpmd7 *p)
-{
- unsigned i, adder, sumFreq, escFreq;
- CPpmd_State *stats = STATS(p->MinContext);
- CPpmd_State *s = p->FoundState;
- {
- CPpmd_State tmp = *s;
- for (; s != stats; s--)
- s[0] = s[-1];
- *s = tmp;
- }
- escFreq = p->MinContext->SummFreq - s->Freq;
- s->Freq += 4;
- adder = (p->OrderFall != 0);
- s->Freq = (Byte)((s->Freq + adder) >> 1);
- sumFreq = s->Freq;
-
- i = p->MinContext->NumStats - 1;
- do
- {
- escFreq -= (++s)->Freq;
- s->Freq = (Byte)((s->Freq + adder) >> 1);
- sumFreq += s->Freq;
- if (s[0].Freq > s[-1].Freq)
- {
- CPpmd_State *s1 = s;
- CPpmd_State tmp = *s1;
- do
- s1[0] = s1[-1];
- while (--s1 != stats && tmp.Freq > s1[-1].Freq);
- *s1 = tmp;
- }
- }
- while (--i);
-
- if (s->Freq == 0)
- {
- unsigned numStats = p->MinContext->NumStats;
- unsigned n0, n1;
- do { i++; } while ((--s)->Freq == 0);
- escFreq += i;
- p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i);
- if (p->MinContext->NumStats == 1)
- {
- CPpmd_State tmp = *stats;
- do
- {
- tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1));
- escFreq >>= 1;
- }
- while (escFreq > 1);
- InsertNode(p, stats, U2I(((numStats + 1) >> 1)));
- *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;
- return;
- }
- n0 = (numStats + 1) >> 1;
- n1 = (p->MinContext->NumStats + 1) >> 1;
- if (n0 != n1)
- p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));
- }
- p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));
- p->FoundState = STATS(p->MinContext);
-}
-
-CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
-{
- CPpmd_See *see;
- unsigned nonMasked = p->MinContext->NumStats - numMasked;
- if (p->MinContext->NumStats != 256)
- {
- see = p->See[p->NS2Indx[nonMasked - 1]] +
- (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) +
- 2 * (p->MinContext->SummFreq < 11 * p->MinContext->NumStats) +
- 4 * (numMasked > nonMasked) +
- p->HiBitsFlag;
- {
- unsigned r = (see->Summ >> see->Shift);
- see->Summ = (UInt16)(see->Summ - r);
- *escFreq = r + (r == 0);
- }
- }
- else
- {
- see = &p->DummySee;
- *escFreq = 1;
- }
- return see;
-}
-
-static void NextContext(CPpmd7 *p)
-{
- CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
- if (p->OrderFall == 0 && (Byte *)c > p->Text)
- p->MinContext = p->MaxContext = c;
- else
- UpdateModel(p);
-}
-
-void Ppmd7_Update1(CPpmd7 *p)
-{
- CPpmd_State *s = p->FoundState;
- s->Freq += 4;
- p->MinContext->SummFreq += 4;
- if (s[0].Freq > s[-1].Freq)
- {
- SwapStates(&s[0], &s[-1]);
- p->FoundState = --s;
- if (s->Freq > MAX_FREQ)
- Rescale(p);
- }
- NextContext(p);
-}
-
-void Ppmd7_Update1_0(CPpmd7 *p)
-{
- p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq);
- p->RunLength += p->PrevSuccess;
- p->MinContext->SummFreq += 4;
- if ((p->FoundState->Freq += 4) > MAX_FREQ)
- Rescale(p);
- NextContext(p);
-}
-
-void Ppmd7_UpdateBin(CPpmd7 *p)
-{
- p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0));
- p->PrevSuccess = 1;
- p->RunLength++;
- NextContext(p);
-}
-
-void Ppmd7_Update2(CPpmd7 *p)
-{
- p->MinContext->SummFreq += 4;
- if ((p->FoundState->Freq += 4) > MAX_FREQ)
- Rescale(p);
- p->RunLength = p->InitRL;
- UpdateModel(p);
-}
diff --git a/src/libs/7zip/win/C/Ppmd7.h b/src/libs/7zip/win/C/Ppmd7.h
deleted file mode 100644
index 96521c31f..000000000
--- a/src/libs/7zip/win/C/Ppmd7.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/* Ppmd7.h -- PPMdH compression codec
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
-
-/* This code supports virtual RangeDecoder and includes the implementation
-of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H.
-If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */
-
-#ifndef __PPMD7_H
-#define __PPMD7_H
-
-#include "Ppmd.h"
-
-EXTERN_C_BEGIN
-
-#define PPMD7_MIN_ORDER 2
-#define PPMD7_MAX_ORDER 64
-
-#define PPMD7_MIN_MEM_SIZE (1 << 11)
-#define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3)
-
-struct CPpmd7_Context_;
-
-typedef
- #ifdef PPMD_32BIT
- struct CPpmd7_Context_ *
- #else
- UInt32
- #endif
- CPpmd7_Context_Ref;
-
-typedef struct CPpmd7_Context_
-{
- UInt16 NumStats;
- UInt16 SummFreq;
- CPpmd_State_Ref Stats;
- CPpmd7_Context_Ref Suffix;
-} CPpmd7_Context;
-
-#define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
-
-typedef struct
-{
- CPpmd7_Context *MinContext, *MaxContext;
- CPpmd_State *FoundState;
- unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag;
- Int32 RunLength, InitRL; /* must be 32-bit at least */
-
- UInt32 Size;
- UInt32 GlueCount;
- Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
- UInt32 AlignOffset;
-
- Byte Indx2Units[PPMD_NUM_INDEXES];
- Byte Units2Indx[128];
- CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
- Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256];
- CPpmd_See DummySee, See[25][16];
- UInt16 BinSumm[128][64];
-} CPpmd7;
-
-void Ppmd7_Construct(CPpmd7 *p);
-Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc);
-void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc);
-void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);
-#define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
-
-
-/* ---------- Internal Functions ---------- */
-
-extern const Byte PPMD7_kExpEscape[16];
-
-#ifdef PPMD_32BIT
- #define Ppmd7_GetPtr(p, ptr) (ptr)
- #define Ppmd7_GetContext(p, ptr) (ptr)
- #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats)
-#else
- #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
- #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))
- #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))
-#endif
-
-void Ppmd7_Update1(CPpmd7 *p);
-void Ppmd7_Update1_0(CPpmd7 *p);
-void Ppmd7_Update2(CPpmd7 *p);
-void Ppmd7_UpdateBin(CPpmd7 *p);
-
-#define Ppmd7_GetBinSumm(p) \
- &p->BinSumm[Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
- p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \
- (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \
- 2 * p->HB2Flag[Ppmd7Context_OneState(p->MinContext)->Symbol] + \
- ((p->RunLength >> 26) & 0x20)]
-
-CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale);
-
-
-/* ---------- Decode ---------- */
-
-typedef struct
-{
- UInt32 (*GetThreshold)(void *p, UInt32 total);
- void (*Decode)(void *p, UInt32 start, UInt32 size);
- UInt32 (*DecodeBit)(void *p, UInt32 size0);
-} IPpmd7_RangeDec;
-
-typedef struct
-{
- IPpmd7_RangeDec p;
- UInt32 Range;
- UInt32 Code;
- IByteIn *Stream;
-} CPpmd7z_RangeDec;
-
-void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p);
-Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p);
-#define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
-
-int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc);
-
-
-/* ---------- Encode ---------- */
-
-typedef struct
-{
- UInt64 Low;
- UInt32 Range;
- Byte Cache;
- UInt64 CacheSize;
- IByteOut *Stream;
-} CPpmd7z_RangeEnc;
-
-void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p);
-void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p);
-
-void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol);
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Ppmd7Dec.c b/src/libs/7zip/win/C/Ppmd7Dec.c
deleted file mode 100644
index 68438d5ce..000000000
--- a/src/libs/7zip/win/C/Ppmd7Dec.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* Ppmd7Dec.c -- PPMdH Decoder
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
-
-#include "Ppmd7.h"
-
-#define kTopValue (1 << 24)
-
-Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
-{
- unsigned i;
- p->Code = 0;
- p->Range = 0xFFFFFFFF;
- if (p->Stream->Read((void *)p->Stream) != 0)
- return False;
- for (i = 0; i < 4; i++)
- p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
- return (p->Code < 0xFFFFFFFF);
-}
-
-static UInt32 Range_GetThreshold(void *pp, UInt32 total)
-{
- CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
- return (p->Code) / (p->Range /= total);
-}
-
-static void Range_Normalize(CPpmd7z_RangeDec *p)
-{
- if (p->Range < kTopValue)
- {
- p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
- p->Range <<= 8;
- if (p->Range < kTopValue)
- {
- p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream);
- p->Range <<= 8;
- }
- }
-}
-
-static void Range_Decode(void *pp, UInt32 start, UInt32 size)
-{
- CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
- p->Code -= start * p->Range;
- p->Range *= size;
- Range_Normalize(p);
-}
-
-static UInt32 Range_DecodeBit(void *pp, UInt32 size0)
-{
- CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp;
- UInt32 newBound = (p->Range >> 14) * size0;
- UInt32 symbol;
- if (p->Code < newBound)
- {
- symbol = 0;
- p->Range = newBound;
- }
- else
- {
- symbol = 1;
- p->Code -= newBound;
- p->Range -= newBound;
- }
- Range_Normalize(p);
- return symbol;
-}
-
-void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)
-{
- p->p.GetThreshold = Range_GetThreshold;
- p->p.Decode = Range_Decode;
- p->p.DecodeBit = Range_DecodeBit;
-}
-
-
-#define MASK(sym) ((signed char *)charMask)[sym]
-
-int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
-{
- size_t charMask[256 / sizeof(size_t)];
- if (p->MinContext->NumStats != 1)
- {
- CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);
- unsigned i;
- UInt32 count, hiCnt;
- if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
- {
- Byte symbol;
- rc->Decode(rc, 0, s->Freq);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd7_Update1_0(p);
- return symbol;
- }
- p->PrevSuccess = 0;
- i = p->MinContext->NumStats - 1;
- do
- {
- if ((hiCnt += (++s)->Freq) > count)
- {
- Byte symbol;
- rc->Decode(rc, hiCnt - s->Freq, s->Freq);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd7_Update1(p);
- return symbol;
- }
- }
- while (--i);
- if (count >= p->MinContext->SummFreq)
- return -2;
- p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
- rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt);
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- i = p->MinContext->NumStats - 1;
- do { MASK((--s)->Symbol) = 0; } while (--i);
- }
- else
- {
- UInt16 *prob = Ppmd7_GetBinSumm(p);
- if (rc->DecodeBit(rc, *prob) == 0)
- {
- Byte symbol;
- *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
- symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol;
- Ppmd7_UpdateBin(p);
- return symbol;
- }
- *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
- p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0;
- p->PrevSuccess = 0;
- }
- for (;;)
- {
- CPpmd_State *ps[256], *s;
- UInt32 freqSum, count, hiCnt;
- CPpmd_See *see;
- unsigned i, num, numMasked = p->MinContext->NumStats;
- do
- {
- p->OrderFall++;
- if (!p->MinContext->Suffix)
- return -1;
- p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
- }
- while (p->MinContext->NumStats == numMasked);
- hiCnt = 0;
- s = Ppmd7_GetStats(p, p->MinContext);
- i = 0;
- num = p->MinContext->NumStats - numMasked;
- do
- {
- int k = (int)(MASK(s->Symbol));
- hiCnt += (s->Freq & k);
- ps[i] = s++;
- i -= k;
- }
- while (i != num);
-
- see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum);
- freqSum += hiCnt;
- count = rc->GetThreshold(rc, freqSum);
-
- if (count < hiCnt)
- {
- Byte symbol;
- CPpmd_State **pps = ps;
- for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
- s = *pps;
- rc->Decode(rc, hiCnt - s->Freq, s->Freq);
- Ppmd_See_Update(see);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd7_Update2(p);
- return symbol;
- }
- if (count >= freqSum)
- return -2;
- rc->Decode(rc, hiCnt, freqSum - hiCnt);
- see->Summ = (UInt16)(see->Summ + freqSum);
- do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
- }
-}
diff --git a/src/libs/7zip/win/C/Ppmd7Enc.c b/src/libs/7zip/win/C/Ppmd7Enc.c
deleted file mode 100644
index 8247757d0..000000000
--- a/src/libs/7zip/win/C/Ppmd7Enc.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/* Ppmd7Enc.c -- PPMdH Encoder
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
-
-#include "Ppmd7.h"
-
-#define kTopValue (1 << 24)
-
-void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p)
-{
- p->Low = 0;
- p->Range = 0xFFFFFFFF;
- p->Cache = 0;
- p->CacheSize = 1;
-}
-
-static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p)
-{
- if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0)
- {
- Byte temp = p->Cache;
- do
- {
- p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32)));
- temp = 0xFF;
- }
- while(--p->CacheSize != 0);
- p->Cache = (Byte)((UInt32)p->Low >> 24);
- }
- p->CacheSize++;
- p->Low = (UInt32)p->Low << 8;
-}
-
-static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total)
-{
- p->Low += start * (p->Range /= total);
- p->Range *= size;
- while (p->Range < kTopValue)
- {
- p->Range <<= 8;
- RangeEnc_ShiftLow(p);
- }
-}
-
-static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0)
-{
- p->Range = (p->Range >> 14) * size0;
- while (p->Range < kTopValue)
- {
- p->Range <<= 8;
- RangeEnc_ShiftLow(p);
- }
-}
-
-static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0)
-{
- UInt32 newBound = (p->Range >> 14) * size0;
- p->Low += newBound;
- p->Range -= newBound;
- while (p->Range < kTopValue)
- {
- p->Range <<= 8;
- RangeEnc_ShiftLow(p);
- }
-}
-
-void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p)
-{
- unsigned i;
- for (i = 0; i < 5; i++)
- RangeEnc_ShiftLow(p);
-}
-
-
-#define MASK(sym) ((signed char *)charMask)[sym]
-
-void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol)
-{
- size_t charMask[256 / sizeof(size_t)];
- if (p->MinContext->NumStats != 1)
- {
- CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext);
- UInt32 sum;
- unsigned i;
- if (s->Symbol == symbol)
- {
- RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq);
- p->FoundState = s;
- Ppmd7_Update1_0(p);
- return;
- }
- p->PrevSuccess = 0;
- sum = s->Freq;
- i = p->MinContext->NumStats - 1;
- do
- {
- if ((++s)->Symbol == symbol)
- {
- RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq);
- p->FoundState = s;
- Ppmd7_Update1(p);
- return;
- }
- sum += s->Freq;
- }
- while (--i);
-
- p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- i = p->MinContext->NumStats - 1;
- do { MASK((--s)->Symbol) = 0; } while (--i);
- RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);
- }
- else
- {
- UInt16 *prob = Ppmd7_GetBinSumm(p);
- CPpmd_State *s = Ppmd7Context_OneState(p->MinContext);
- if (s->Symbol == symbol)
- {
- RangeEnc_EncodeBit_0(rc, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
- p->FoundState = s;
- Ppmd7_UpdateBin(p);
- return;
- }
- else
- {
- RangeEnc_EncodeBit_1(rc, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
- p->InitEsc = PPMD7_kExpEscape[*prob >> 10];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- p->PrevSuccess = 0;
- }
- }
- for (;;)
- {
- UInt32 escFreq;
- CPpmd_See *see;
- CPpmd_State *s;
- UInt32 sum;
- unsigned i, numMasked = p->MinContext->NumStats;
- do
- {
- p->OrderFall++;
- if (!p->MinContext->Suffix)
- return; /* EndMarker (symbol = -1) */
- p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
- }
- while (p->MinContext->NumStats == numMasked);
-
- see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq);
- s = Ppmd7_GetStats(p, p->MinContext);
- sum = 0;
- i = p->MinContext->NumStats;
- do
- {
- int cur = s->Symbol;
- if (cur == symbol)
- {
- UInt32 low = sum;
- CPpmd_State *s1 = s;
- do
- {
- sum += (s->Freq & (int)(MASK(s->Symbol)));
- s++;
- }
- while (--i);
- RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq);
- Ppmd_See_Update(see);
- p->FoundState = s1;
- Ppmd7_Update2(p);
- return;
- }
- sum += (s->Freq & (int)(MASK(cur)));
- MASK(cur) = 0;
- s++;
- }
- while (--i);
-
- RangeEnc_Encode(rc, sum, escFreq, sum + escFreq);
- see->Summ = (UInt16)(see->Summ + sum + escFreq);
- }
-}
diff --git a/src/libs/7zip/win/C/Ppmd8.c b/src/libs/7zip/win/C/Ppmd8.c
deleted file mode 100644
index 9187a88ef..000000000
--- a/src/libs/7zip/win/C/Ppmd8.c
+++ /dev/null
@@ -1,1120 +0,0 @@
-/* Ppmd8.c -- PPMdI codec
-2010-03-24 : Igor Pavlov : Public domain
-This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
-
-#include <memory.h>
-
-#include "Ppmd8.h"
-
-const Byte PPMD8_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
-static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
-
-#define MAX_FREQ 124
-#define UNIT_SIZE 12
-
-#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
-#define U2I(nu) (p->Units2Indx[(nu) - 1])
-#define I2U(indx) (p->Indx2Units[indx])
-
-#ifdef PPMD_32BIT
- #define REF(ptr) (ptr)
-#else
- #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
-#endif
-
-#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
-
-#define CTX(ref) ((CPpmd8_Context *)Ppmd8_GetContext(p, ref))
-#define STATS(ctx) Ppmd8_GetStats(p, ctx)
-#define ONE_STATE(ctx) Ppmd8Context_OneState(ctx)
-#define SUFFIX(ctx) CTX((ctx)->Suffix)
-
-typedef CPpmd8_Context * CTX_PTR;
-
-struct CPpmd8_Node_;
-
-typedef
- #ifdef PPMD_32BIT
- struct CPpmd8_Node_ *
- #else
- UInt32
- #endif
- CPpmd8_Node_Ref;
-
-typedef struct CPpmd8_Node_
-{
- UInt32 Stamp;
- CPpmd8_Node_Ref Next;
- UInt32 NU;
-} CPpmd8_Node;
-
-#ifdef PPMD_32BIT
- #define NODE(ptr) (ptr)
-#else
- #define NODE(offs) ((CPpmd8_Node *)(p->Base + (offs)))
-#endif
-
-#define EMPTY_NODE 0xFFFFFFFF
-
-void Ppmd8_Construct(CPpmd8 *p)
-{
- unsigned i, k, m;
-
- p->Base = 0;
-
- for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
- {
- unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
- do { p->Units2Indx[k++] = (Byte)i; } while(--step);
- p->Indx2Units[i] = (Byte)k;
- }
-
- p->NS2BSIndx[0] = (0 << 1);
- p->NS2BSIndx[1] = (1 << 1);
- memset(p->NS2BSIndx + 2, (2 << 1), 9);
- memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
-
- for (i = 0; i < 5; i++)
- p->NS2Indx[i] = (Byte)i;
- for (m = i, k = 1; i < 260; i++)
- {
- p->NS2Indx[i] = (Byte)m;
- if (--k == 0)
- k = (++m) - 4;
- }
-}
-
-void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->Base);
- p->Size = 0;
- p->Base = 0;
-}
-
-Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc)
-{
- if (p->Base == 0 || p->Size != size)
- {
- Ppmd8_Free(p, alloc);
- p->AlignOffset =
- #ifdef PPMD_32BIT
- (4 - size) & 3;
- #else
- 4 - (size & 3);
- #endif
- if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size)) == 0)
- return False;
- p->Size = size;
- }
- return True;
-}
-
-static void InsertNode(CPpmd8 *p, void *node, unsigned indx)
-{
- ((CPpmd8_Node *)node)->Stamp = EMPTY_NODE;
- ((CPpmd8_Node *)node)->Next = (CPpmd8_Node_Ref)p->FreeList[indx];
- ((CPpmd8_Node *)node)->NU = I2U(indx);
- p->FreeList[indx] = REF(node);
- p->Stamps[indx]++;
-}
-
-static void *RemoveNode(CPpmd8 *p, unsigned indx)
-{
- CPpmd8_Node *node = NODE((CPpmd8_Node_Ref)p->FreeList[indx]);
- p->FreeList[indx] = node->Next;
- p->Stamps[indx]--;
- return node;
-}
-
-static void SplitBlock(CPpmd8 *p, void *ptr, unsigned oldIndx, unsigned newIndx)
-{
- unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
- ptr = (Byte *)ptr + U2B(I2U(newIndx));
- if (I2U(i = U2I(nu)) != nu)
- {
- unsigned k = I2U(--i);
- InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);
- }
- InsertNode(p, ptr, i);
-}
-
-static void GlueFreeBlocks(CPpmd8 *p)
-{
- CPpmd8_Node_Ref head = 0;
- CPpmd8_Node_Ref *prev = &head;
- unsigned i;
-
- p->GlueCount = 1 << 13;
- memset(p->Stamps, 0, sizeof(p->Stamps));
-
- /* Order-0 context is always at top UNIT, so we don't need guard NODE at the end.
- All blocks up to p->LoUnit can be free, so we need guard NODE at LoUnit. */
- if (p->LoUnit != p->HiUnit)
- ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
-
- /* Glue free blocks */
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- {
- CPpmd8_Node_Ref next = (CPpmd8_Node_Ref)p->FreeList[i];
- p->FreeList[i] = 0;
- while (next != 0)
- {
- CPpmd8_Node *node = NODE(next);
- if (node->NU != 0)
- {
- CPpmd8_Node *node2;
- *prev = next;
- prev = &(node->Next);
- while ((node2 = node + node->NU)->Stamp == EMPTY_NODE)
- {
- node->NU += node2->NU;
- node2->NU = 0;
- }
- }
- next = node->Next;
- }
- }
- *prev = 0;
-
- /* Fill lists of free blocks */
- while (head != 0)
- {
- CPpmd8_Node *node = NODE(head);
- unsigned nu;
- head = node->Next;
- nu = node->NU;
- if (nu == 0)
- continue;
- for (; nu > 128; nu -= 128, node += 128)
- InsertNode(p, node, PPMD_NUM_INDEXES - 1);
- if (I2U(i = U2I(nu)) != nu)
- {
- unsigned k = I2U(--i);
- InsertNode(p, node + k, nu - k - 1);
- }
- InsertNode(p, node, i);
- }
-}
-
-static void *AllocUnitsRare(CPpmd8 *p, unsigned indx)
-{
- unsigned i;
- void *retVal;
- if (p->GlueCount == 0)
- {
- GlueFreeBlocks(p);
- if (p->FreeList[indx] != 0)
- return RemoveNode(p, indx);
- }
- i = indx;
- do
- {
- if (++i == PPMD_NUM_INDEXES)
- {
- UInt32 numBytes = U2B(I2U(indx));
- p->GlueCount--;
- return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);
- }
- }
- while (p->FreeList[i] == 0);
- retVal = RemoveNode(p, i);
- SplitBlock(p, retVal, i, indx);
- return retVal;
-}
-
-static void *AllocUnits(CPpmd8 *p, unsigned indx)
-{
- UInt32 numBytes;
- if (p->FreeList[indx] != 0)
- return RemoveNode(p, indx);
- numBytes = U2B(I2U(indx));
- if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
- {
- void *retVal = p->LoUnit;
- p->LoUnit += numBytes;
- return retVal;
- }
- return AllocUnitsRare(p, indx);
-}
-
-#define MyMem12Cpy(dest, src, num) \
- { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
- do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
-
-static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
-{
- unsigned i0 = U2I(oldNU);
- unsigned i1 = U2I(newNU);
- if (i0 == i1)
- return oldPtr;
- if (p->FreeList[i1] != 0)
- {
- void *ptr = RemoveNode(p, i1);
- MyMem12Cpy(ptr, oldPtr, newNU);
- InsertNode(p, oldPtr, i0);
- return ptr;
- }
- SplitBlock(p, oldPtr, i0, i1);
- return oldPtr;
-}
-
-static void FreeUnits(CPpmd8 *p, void *ptr, unsigned nu)
-{
- InsertNode(p, ptr, U2I(nu));
-}
-
-static void SpecialFreeUnit(CPpmd8 *p, void *ptr)
-{
- if ((Byte *)ptr != p->UnitsStart)
- InsertNode(p, ptr, 0);
- else
- {
- #ifdef PPMD8_FREEZE_SUPPORT
- *(UInt32 *)ptr = EMPTY_NODE; /* it's used for (Flags == 0xFF) check in RemoveBinContexts */
- #endif
- p->UnitsStart += UNIT_SIZE;
- }
-}
-
-static void *MoveUnitsUp(CPpmd8 *p, void *oldPtr, unsigned nu)
-{
- unsigned indx = U2I(nu);
- void *ptr;
- if ((Byte *)oldPtr > p->UnitsStart + 16 * 1024 || REF(oldPtr) > p->FreeList[indx])
- return oldPtr;
- ptr = RemoveNode(p, indx);
- MyMem12Cpy(ptr, oldPtr, nu);
- if ((Byte*)oldPtr != p->UnitsStart)
- InsertNode(p, oldPtr, indx);
- else
- p->UnitsStart += U2B(I2U(indx));
- return ptr;
-}
-
-static void ExpandTextArea(CPpmd8 *p)
-{
- UInt32 count[PPMD_NUM_INDEXES];
- unsigned i;
- memset(count, 0, sizeof(count));
- if (p->LoUnit != p->HiUnit)
- ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
-
- {
- CPpmd8_Node *node = (CPpmd8_Node *)p->UnitsStart;
- for (; node->Stamp == EMPTY_NODE; node += node->NU)
- {
- node->Stamp = 0;
- count[U2I(node->NU)]++;
- }
- p->UnitsStart = (Byte *)node;
- }
-
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- {
- CPpmd8_Node_Ref *next = (CPpmd8_Node_Ref *)&p->FreeList[i];
- while (count[i] != 0)
- {
- CPpmd8_Node *node = NODE(*next);
- while (node->Stamp == 0)
- {
- *next = node->Next;
- node = NODE(*next);
- p->Stamps[i]--;
- if (--count[i] == 0)
- break;
- }
- next = &node->Next;
- }
- }
-}
-
-#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
-
-static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)
-{
- (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
- (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
-}
-
-#define RESET_TEXT(offs) { p->Text = p->Base + p->AlignOffset + (offs); }
-
-static void RestartModel(CPpmd8 *p)
-{
- unsigned i, k, m, r;
-
- memset(p->FreeList, 0, sizeof(p->FreeList));
- memset(p->Stamps, 0, sizeof(p->Stamps));
- RESET_TEXT(0);
- p->HiUnit = p->Text + p->Size;
- p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;
- p->GlueCount = 0;
-
- p->OrderFall = p->MaxOrder;
- p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;
- p->PrevSuccess = 0;
-
- p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */
- p->MinContext->Suffix = 0;
- p->MinContext->NumStats = 255;
- p->MinContext->Flags = 0;
- p->MinContext->SummFreq = 256 + 1;
- p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
- p->LoUnit += U2B(256 / 2);
- p->MinContext->Stats = REF(p->FoundState);
- for (i = 0; i < 256; i++)
- {
- CPpmd_State *s = &p->FoundState[i];
- s->Symbol = (Byte)i;
- s->Freq = 1;
- SetSuccessor(s, 0);
- }
-
- for (i = m = 0; m < 25; m++)
- {
- while (p->NS2Indx[i] == m)
- i++;
- for (k = 0; k < 8; k++)
- {
- UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 1));
- UInt16 *dest = p->BinSumm[m] + k;
- for (r = 0; r < 64; r += 8)
- dest[r] = val;
- }
- }
-
- for (i = m = 0; m < 24; m++)
- {
- while (p->NS2Indx[i + 3] == m + 3)
- i++;
- for (k = 0; k < 32; k++)
- {
- CPpmd_See *s = &p->See[m][k];
- s->Summ = (UInt16)((2 * i + 5) << (s->Shift = PPMD_PERIOD_BITS - 4));
- s->Count = 7;
- }
- }
-}
-
-void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod)
-{
- p->MaxOrder = maxOrder;
- p->RestoreMethod = restoreMethod;
- RestartModel(p);
- p->DummySee.Shift = PPMD_PERIOD_BITS;
- p->DummySee.Summ = 0; /* unused */
- p->DummySee.Count = 64; /* unused */
-}
-
-static void Refresh(CPpmd8 *p, CTX_PTR ctx, unsigned oldNU, unsigned scale)
-{
- unsigned i = ctx->NumStats, escFreq, sumFreq, flags;
- CPpmd_State *s = (CPpmd_State *)ShrinkUnits(p, STATS(ctx), oldNU, (i + 2) >> 1);
- ctx->Stats = REF(s);
- #ifdef PPMD8_FREEZE_SUPPORT
- /* fixed over Shkarin's code. Fixed code is not compatible with original code for some files in FREEZE mode. */
- scale |= (ctx->SummFreq >= ((UInt32)1 << 15));
- #endif
- flags = (ctx->Flags & (0x10 + 0x04 * scale)) + 0x08 * (s->Symbol >= 0x40);
- escFreq = ctx->SummFreq - s->Freq;
- sumFreq = (s->Freq = (Byte)((s->Freq + scale) >> scale));
- do
- {
- escFreq -= (++s)->Freq;
- sumFreq += (s->Freq = (Byte)((s->Freq + scale) >> scale));
- flags |= 0x08 * (s->Symbol >= 0x40);
- }
- while (--i);
- ctx->SummFreq = (UInt16)(sumFreq + ((escFreq + scale) >> scale));
- ctx->Flags = (Byte)flags;
-}
-
-static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)
-{
- CPpmd_State tmp = *t1;
- *t1 = *t2;
- *t2 = tmp;
-}
-
-static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order)
-{
- int i;
- unsigned tmp;
- CPpmd_State *s;
-
- if (!ctx->NumStats)
- {
- s = ONE_STATE(ctx);
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart)
- {
- if (order < p->MaxOrder)
- SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
- if (SUCCESSOR(s) || order <= 9) /* O_BOUND */
- return REF(ctx);
- }
- SpecialFreeUnit(p, ctx);
- return 0;
- }
-
- ctx->Stats = STATS_REF(MoveUnitsUp(p, STATS(ctx), tmp = ((unsigned)ctx->NumStats + 2) >> 1));
-
- for (s = STATS(ctx) + (i = ctx->NumStats); s >= STATS(ctx); s--)
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) < p->UnitsStart)
- {
- CPpmd_State *s2 = STATS(ctx) + (i--);
- SetSuccessor(s, 0);
- SwapStates(s, s2);
- }
- else if (order < p->MaxOrder)
- SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
-
- if (i != ctx->NumStats && order)
- {
- ctx->NumStats = (Byte)i;
- s = STATS(ctx);
- if (i < 0)
- {
- FreeUnits(p, s, tmp);
- SpecialFreeUnit(p, ctx);
- return 0;
- }
- if (i == 0)
- {
- ctx->Flags = (ctx->Flags & 0x10) + 0x08 * (s->Symbol >= 0x40);
- *ONE_STATE(ctx) = *s;
- FreeUnits(p, s, tmp);
- ONE_STATE(ctx)->Freq = (Byte)((unsigned)ONE_STATE(ctx)->Freq + 11) >> 3;
- }
- else
- Refresh(p, ctx, tmp, ctx->SummFreq > 16 * i);
- }
- return REF(ctx);
-}
-
-#ifdef PPMD8_FREEZE_SUPPORT
-static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order)
-{
- CPpmd_State *s;
- if (!ctx->NumStats)
- {
- s = ONE_STATE(ctx);
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart && order < p->MaxOrder)
- SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
- /* Suffix context can be removed already, since different (high-order)
- Successors may refer to same context. So we check Flags == 0xFF (Stamp == EMPTY_NODE) */
- if (!SUCCESSOR(s) && (!SUFFIX(ctx)->NumStats || SUFFIX(ctx)->Flags == 0xFF))
- {
- FreeUnits(p, ctx, 1);
- return 0;
- }
- else
- return REF(ctx);
- }
-
- for (s = STATS(ctx) + ctx->NumStats; s >= STATS(ctx); s--)
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart && order < p->MaxOrder)
- SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
-
- return REF(ctx);
-}
-#endif
-
-static UInt32 GetUsedMemory(const CPpmd8 *p)
-{
- UInt32 v = 0;
- unsigned i;
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- v += p->Stamps[i] * I2U(i);
- return p->Size - (UInt32)(p->HiUnit - p->LoUnit) - (UInt32)(p->UnitsStart - p->Text) - U2B(v);
-}
-
-#ifdef PPMD8_FREEZE_SUPPORT
- #define RESTORE_MODEL(c1, fSuccessor) RestoreModel(p, c1, fSuccessor)
-#else
- #define RESTORE_MODEL(c1, fSuccessor) RestoreModel(p, c1)
-#endif
-
-static void RestoreModel(CPpmd8 *p, CTX_PTR c1
- #ifdef PPMD8_FREEZE_SUPPORT
- , CTX_PTR fSuccessor
- #endif
- )
-{
- CTX_PTR c;
- CPpmd_State *s;
- RESET_TEXT(0);
- for (c = p->MaxContext; c != c1; c = SUFFIX(c))
- if (--(c->NumStats) == 0)
- {
- s = STATS(c);
- c->Flags = (c->Flags & 0x10) + 0x08 * (s->Symbol >= 0x40);
- *ONE_STATE(c) = *s;
- SpecialFreeUnit(p, s);
- ONE_STATE(c)->Freq = (ONE_STATE(c)->Freq + 11) >> 3;
- }
- else
- Refresh(p, c, (c->NumStats+3) >> 1, 0);
-
- for (; c != p->MinContext; c = SUFFIX(c))
- if (!c->NumStats)
- ONE_STATE(c)->Freq -= ONE_STATE(c)->Freq >> 1;
- else if ((c->SummFreq += 4) > 128 + 4 * c->NumStats)
- Refresh(p, c, (c->NumStats + 2) >> 1, 1);
-
- #ifdef PPMD8_FREEZE_SUPPORT
- if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- p->MaxContext = fSuccessor;
- p->GlueCount += !(p->Stamps[1] & 1);
- }
- else if (p->RestoreMethod == PPMD8_RESTORE_METHOD_FREEZE)
- {
- while (p->MaxContext->Suffix)
- p->MaxContext = SUFFIX(p->MaxContext);
- RemoveBinContexts(p, p->MaxContext, 0);
- p->RestoreMethod++;
- p->GlueCount = 0;
- p->OrderFall = p->MaxOrder;
- }
- else
- #endif
- if (p->RestoreMethod == PPMD8_RESTORE_METHOD_RESTART || GetUsedMemory(p) < (p->Size >> 1))
- RestartModel(p);
- else
- {
- while (p->MaxContext->Suffix)
- p->MaxContext = SUFFIX(p->MaxContext);
- do
- {
- CutOff(p, p->MaxContext, 0);
- ExpandTextArea(p);
- }
- while (GetUsedMemory(p) > 3 * (p->Size >> 2));
- p->GlueCount = 0;
- p->OrderFall = p->MaxOrder;
- }
-}
-
-static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c)
-{
- CPpmd_State upState;
- Byte flags;
- CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
- /* fixed over Shkarin's code. Maybe it could work without + 1 too. */
- CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
- unsigned numPs = 0;
-
- if (!skip)
- ps[numPs++] = p->FoundState;
-
- while (c->Suffix)
- {
- CPpmd_Void_Ref successor;
- CPpmd_State *s;
- c = SUFFIX(c);
- if (s1)
- {
- s = s1;
- s1 = NULL;
- }
- else if (c->NumStats != 0)
- {
- for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq++;
- c->SummFreq++;
- }
- }
- else
- {
- s = ONE_STATE(c);
- s->Freq += (!SUFFIX(c)->NumStats & (s->Freq < 24));
- }
- successor = SUCCESSOR(s);
- if (successor != upBranch)
- {
- c = CTX(successor);
- if (numPs == 0)
- return c;
- break;
- }
- ps[numPs++] = s;
- }
-
- upState.Symbol = *(const Byte *)Ppmd8_GetPtr(p, upBranch);
- SetSuccessor(&upState, upBranch + 1);
- flags = 0x10 * (p->FoundState->Symbol >= 0x40) + 0x08 * (upState.Symbol >= 0x40);
-
- if (c->NumStats == 0)
- upState.Freq = ONE_STATE(c)->Freq;
- else
- {
- UInt32 cf, s0;
- CPpmd_State *s;
- for (s = STATS(c); s->Symbol != upState.Symbol; s++);
- cf = s->Freq - 1;
- s0 = c->SummFreq - c->NumStats - cf;
- upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((cf + 2 * s0 - 3) / s0)));
- }
-
- do
- {
- /* Create Child */
- CTX_PTR c1; /* = AllocContext(p); */
- if (p->HiUnit != p->LoUnit)
- c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);
- else if (p->FreeList[0] != 0)
- c1 = (CTX_PTR)RemoveNode(p, 0);
- else
- {
- c1 = (CTX_PTR)AllocUnitsRare(p, 0);
- if (!c1)
- return NULL;
- }
- c1->NumStats = 0;
- c1->Flags = flags;
- *ONE_STATE(c1) = upState;
- c1->Suffix = REF(c);
- SetSuccessor(ps[--numPs], REF(c1));
- c = c1;
- }
- while (numPs != 0);
-
- return c;
-}
-
-static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c)
-{
- CPpmd_State *s = NULL;
- CTX_PTR c1 = c;
- CPpmd_Void_Ref upBranch = REF(p->Text);
-
- #ifdef PPMD8_FREEZE_SUPPORT
- /* The BUG in Shkarin's code was fixed: ps could overflow in CUT_OFF mode. */
- CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
- unsigned numPs = 0;
- ps[numPs++] = p->FoundState;
- #endif
-
- SetSuccessor(p->FoundState, upBranch);
- p->OrderFall++;
-
- for (;;)
- {
- if (s1)
- {
- c = SUFFIX(c);
- s = s1;
- s1 = NULL;
- }
- else
- {
- if (!c->Suffix)
- {
- #ifdef PPMD8_FREEZE_SUPPORT
- if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs);
- RESET_TEXT(1);
- p->OrderFall = 1;
- }
- #endif
- return c;
- }
- c = SUFFIX(c);
- if (c->NumStats)
- {
- if ((s = STATS(c))->Symbol != p->FoundState->Symbol)
- do { s++; } while (s->Symbol != p->FoundState->Symbol);
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq += 2;
- c->SummFreq += 2;
- }
- }
- else
- {
- s = ONE_STATE(c);
- s->Freq += (s->Freq < 32);
- }
- }
- if (SUCCESSOR(s))
- break;
- #ifdef PPMD8_FREEZE_SUPPORT
- ps[numPs++] = s;
- #endif
- SetSuccessor(s, upBranch);
- p->OrderFall++;
- }
-
- #ifdef PPMD8_FREEZE_SUPPORT
- if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- c = CTX(SUCCESSOR(s));
- do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs);
- RESET_TEXT(1);
- p->OrderFall = 1;
- return c;
- }
- else
- #endif
- if (SUCCESSOR(s) <= upBranch)
- {
- CTX_PTR successor;
- CPpmd_State *s1 = p->FoundState;
- p->FoundState = s;
-
- successor = CreateSuccessors(p, False, NULL, c);
- if (successor == NULL)
- SetSuccessor(s, 0);
- else
- SetSuccessor(s, REF(successor));
- p->FoundState = s1;
- }
-
- if (p->OrderFall == 1 && c1 == p->MaxContext)
- {
- SetSuccessor(p->FoundState, SUCCESSOR(s));
- p->Text--;
- }
- if (SUCCESSOR(s) == 0)
- return NULL;
- return CTX(SUCCESSOR(s));
-}
-
-static void UpdateModel(CPpmd8 *p)
-{
- CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
- CTX_PTR c;
- unsigned s0, ns, fFreq = p->FoundState->Freq;
- Byte flag, fSymbol = p->FoundState->Symbol;
- CPpmd_State *s = NULL;
-
- if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
- {
- c = SUFFIX(p->MinContext);
-
- if (c->NumStats == 0)
- {
- s = ONE_STATE(c);
- if (s->Freq < 32)
- s->Freq++;
- }
- else
- {
- s = STATS(c);
- if (s->Symbol != p->FoundState->Symbol)
- {
- do { s++; } while (s->Symbol != p->FoundState->Symbol);
- if (s[0].Freq >= s[-1].Freq)
- {
- SwapStates(&s[0], &s[-1]);
- s--;
- }
- }
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq += 2;
- c->SummFreq += 2;
- }
- }
- }
-
- c = p->MaxContext;
- if (p->OrderFall == 0 && fSuccessor)
- {
- CTX_PTR cs = CreateSuccessors(p, True, s, p->MinContext);
- if (cs == 0)
- {
- SetSuccessor(p->FoundState, 0);
- RESTORE_MODEL(c, CTX(fSuccessor));
- }
- else
- {
- SetSuccessor(p->FoundState, REF(cs));
- p->MaxContext = cs;
- }
- return;
- }
-
- *p->Text++ = p->FoundState->Symbol;
- successor = REF(p->Text);
- if (p->Text >= p->UnitsStart)
- {
- RESTORE_MODEL(c, CTX(fSuccessor)); /* check it */
- return;
- }
-
- if (!fSuccessor)
- {
- CTX_PTR cs = ReduceOrder(p, s, p->MinContext);
- if (cs == NULL)
- {
- RESTORE_MODEL(c, 0);
- return;
- }
- fSuccessor = REF(cs);
- }
- else if ((Byte *)Ppmd8_GetPtr(p, fSuccessor) < p->UnitsStart)
- {
- CTX_PTR cs = CreateSuccessors(p, False, s, p->MinContext);
- if (cs == NULL)
- {
- RESTORE_MODEL(c, 0);
- return;
- }
- fSuccessor = REF(cs);
- }
-
- if (--p->OrderFall == 0)
- {
- successor = fSuccessor;
- p->Text -= (p->MaxContext != p->MinContext);
- }
- #ifdef PPMD8_FREEZE_SUPPORT
- else if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- successor = fSuccessor;
- RESET_TEXT(0);
- p->OrderFall = 0;
- }
- #endif
-
- s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - fFreq;
- flag = 0x08 * (fSymbol >= 0x40);
-
- for (; c != p->MinContext; c = SUFFIX(c))
- {
- unsigned ns1;
- UInt32 cf, sf;
- if ((ns1 = c->NumStats) != 0)
- {
- if ((ns1 & 1) != 0)
- {
- /* Expand for one UNIT */
- unsigned oldNU = (ns1 + 1) >> 1;
- unsigned i = U2I(oldNU);
- if (i != U2I(oldNU + 1))
- {
- void *ptr = AllocUnits(p, i + 1);
- void *oldPtr;
- if (!ptr)
- {
- RESTORE_MODEL(c, CTX(fSuccessor));
- return;
- }
- oldPtr = STATS(c);
- MyMem12Cpy(ptr, oldPtr, oldNU);
- InsertNode(p, oldPtr, i);
- c->Stats = STATS_REF(ptr);
- }
- }
- c->SummFreq = (UInt16)(c->SummFreq + (3 * ns1 + 1 < ns));
- }
- else
- {
- CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
- if (!s)
- {
- RESTORE_MODEL(c, CTX(fSuccessor));
- return;
- }
- *s = *ONE_STATE(c);
- c->Stats = REF(s);
- if (s->Freq < MAX_FREQ / 4 - 1)
- s->Freq <<= 1;
- else
- s->Freq = MAX_FREQ - 4;
- c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 2));
- }
- cf = 2 * fFreq * (c->SummFreq + 6);
- sf = (UInt32)s0 + c->SummFreq;
- if (cf < 6 * sf)
- {
- cf = 1 + (cf > sf) + (cf >= 4 * sf);
- c->SummFreq += 4;
- }
- else
- {
- cf = 4 + (cf > 9 * sf) + (cf > 12 * sf) + (cf > 15 * sf);
- c->SummFreq = (UInt16)(c->SummFreq + cf);
- }
- {
- CPpmd_State *s = STATS(c) + ns1 + 1;
- SetSuccessor(s, successor);
- s->Symbol = fSymbol;
- s->Freq = (Byte)cf;
- c->Flags |= flag;
- c->NumStats = (Byte)(ns1 + 1);
- }
- }
- p->MaxContext = p->MinContext = CTX(fSuccessor);
-}
-
-static void Rescale(CPpmd8 *p)
-{
- unsigned i, adder, sumFreq, escFreq;
- CPpmd_State *stats = STATS(p->MinContext);
- CPpmd_State *s = p->FoundState;
- {
- CPpmd_State tmp = *s;
- for (; s != stats; s--)
- s[0] = s[-1];
- *s = tmp;
- }
- escFreq = p->MinContext->SummFreq - s->Freq;
- s->Freq += 4;
- adder = (p->OrderFall != 0
- #ifdef PPMD8_FREEZE_SUPPORT
- || p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE
- #endif
- );
- s->Freq = (Byte)((s->Freq + adder) >> 1);
- sumFreq = s->Freq;
-
- i = p->MinContext->NumStats;
- do
- {
- escFreq -= (++s)->Freq;
- s->Freq = (Byte)((s->Freq + adder) >> 1);
- sumFreq += s->Freq;
- if (s[0].Freq > s[-1].Freq)
- {
- CPpmd_State *s1 = s;
- CPpmd_State tmp = *s1;
- do
- s1[0] = s1[-1];
- while (--s1 != stats && tmp.Freq > s1[-1].Freq);
- *s1 = tmp;
- }
- }
- while (--i);
-
- if (s->Freq == 0)
- {
- unsigned numStats = p->MinContext->NumStats;
- unsigned n0, n1;
- do { i++; } while ((--s)->Freq == 0);
- escFreq += i;
- p->MinContext->NumStats = (Byte)(p->MinContext->NumStats - i);
- if (p->MinContext->NumStats == 0)
- {
- CPpmd_State tmp = *stats;
- tmp.Freq = (Byte)((2 * tmp.Freq + escFreq - 1) / escFreq);
- if (tmp.Freq > MAX_FREQ / 3)
- tmp.Freq = MAX_FREQ / 3;
- InsertNode(p, stats, U2I((numStats + 2) >> 1));
- p->MinContext->Flags = (p->MinContext->Flags & 0x10) + 0x08 * (tmp.Symbol >= 0x40);
- *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;
- return;
- }
- n0 = (numStats + 2) >> 1;
- n1 = (p->MinContext->NumStats + 2) >> 1;
- if (n0 != n1)
- p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));
- p->MinContext->Flags &= ~0x08;
- p->MinContext->Flags |= 0x08 * ((s = STATS(p->MinContext))->Symbol >= 0x40);
- i = p->MinContext->NumStats;
- do { p->MinContext->Flags |= 0x08*((++s)->Symbol >= 0x40); } while (--i);
- }
- p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));
- p->MinContext->Flags |= 0x4;
- p->FoundState = STATS(p->MinContext);
-}
-
-CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq)
-{
- CPpmd_See *see;
- if (p->MinContext->NumStats != 0xFF)
- {
- see = p->See[p->NS2Indx[p->MinContext->NumStats + 2] - 3] +
- (p->MinContext->SummFreq > 11 * ((unsigned)p->MinContext->NumStats + 1)) +
- 2 * (2 * (unsigned)p->MinContext->NumStats <
- ((unsigned)SUFFIX(p->MinContext)->NumStats + numMasked1)) +
- p->MinContext->Flags;
- {
- unsigned r = (see->Summ >> see->Shift);
- see->Summ = (UInt16)(see->Summ - r);
- *escFreq = r + (r == 0);
- }
- }
- else
- {
- see = &p->DummySee;
- *escFreq = 1;
- }
- return see;
-}
-
-static void NextContext(CPpmd8 *p)
-{
- CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
- if (p->OrderFall == 0 && (Byte *)c >= p->UnitsStart)
- p->MinContext = p->MaxContext = c;
- else
- {
- UpdateModel(p);
- p->MinContext = p->MaxContext;
- }
-}
-
-void Ppmd8_Update1(CPpmd8 *p)
-{
- CPpmd_State *s = p->FoundState;
- s->Freq += 4;
- p->MinContext->SummFreq += 4;
- if (s[0].Freq > s[-1].Freq)
- {
- SwapStates(&s[0], &s[-1]);
- p->FoundState = --s;
- if (s->Freq > MAX_FREQ)
- Rescale(p);
- }
- NextContext(p);
-}
-
-void Ppmd8_Update1_0(CPpmd8 *p)
-{
- p->PrevSuccess = (2 * p->FoundState->Freq >= p->MinContext->SummFreq);
- p->RunLength += p->PrevSuccess;
- p->MinContext->SummFreq += 4;
- if ((p->FoundState->Freq += 4) > MAX_FREQ)
- Rescale(p);
- NextContext(p);
-}
-
-void Ppmd8_UpdateBin(CPpmd8 *p)
-{
- p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 196));
- p->PrevSuccess = 1;
- p->RunLength++;
- NextContext(p);
-}
-
-void Ppmd8_Update2(CPpmd8 *p)
-{
- p->MinContext->SummFreq += 4;
- if ((p->FoundState->Freq += 4) > MAX_FREQ)
- Rescale(p);
- p->RunLength = p->InitRL;
- UpdateModel(p);
- p->MinContext = p->MaxContext;
-}
-
-/* H->I changes:
- NS2Indx
- GlewCount, and Glue method
- BinSum
- See / EscFreq
- CreateSuccessors updates more suffix contexts
- UpdateModel consts.
- PrevSuccess Update
-*/
diff --git a/src/libs/7zip/win/C/Ppmd8.h b/src/libs/7zip/win/C/Ppmd8.h
deleted file mode 100644
index 870dc9dd8..000000000
--- a/src/libs/7zip/win/C/Ppmd8.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Ppmd8.h -- PPMdI codec
-2010-03-24 : Igor Pavlov : Public domain
-This code is based on:
- PPMd var.I (2002): Dmitry Shkarin : Public domain
- Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
-
-#ifndef __PPMD8_H
-#define __PPMD8_H
-
-#include "Ppmd.h"
-
-EXTERN_C_BEGIN
-
-#define PPMD8_MIN_ORDER 2
-#define PPMD8_MAX_ORDER 16
-
-struct CPpmd8_Context_;
-
-typedef
- #ifdef PPMD_32BIT
- struct CPpmd8_Context_ *
- #else
- UInt32
- #endif
- CPpmd8_Context_Ref;
-
-typedef struct CPpmd8_Context_
-{
- Byte NumStats;
- Byte Flags;
- UInt16 SummFreq;
- CPpmd_State_Ref Stats;
- CPpmd8_Context_Ref Suffix;
-} CPpmd8_Context;
-
-#define Ppmd8Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
-
-/* The BUG in Shkarin's code for FREEZE mode was fixed, but that fixed
- code is not compatible with original code for some files compressed
- in FREEZE mode. So we disable FREEZE mode support. */
-
-enum
-{
- PPMD8_RESTORE_METHOD_RESTART,
- PPMD8_RESTORE_METHOD_CUT_OFF
- #ifdef PPMD8_FREEZE_SUPPORT
- , PPMD8_RESTORE_METHOD_FREEZE
- #endif
-};
-
-typedef struct
-{
- CPpmd8_Context *MinContext, *MaxContext;
- CPpmd_State *FoundState;
- unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder;
- Int32 RunLength, InitRL; /* must be 32-bit at least */
-
- UInt32 Size;
- UInt32 GlueCount;
- Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
- UInt32 AlignOffset;
- unsigned RestoreMethod;
-
- /* Range Coder */
- UInt32 Range;
- UInt32 Code;
- UInt32 Low;
- union
- {
- IByteIn *In;
- IByteOut *Out;
- } Stream;
-
- Byte Indx2Units[PPMD_NUM_INDEXES];
- Byte Units2Indx[128];
- CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
- UInt32 Stamps[PPMD_NUM_INDEXES];
-
- Byte NS2BSIndx[256], NS2Indx[260];
- CPpmd_See DummySee, See[24][32];
- UInt16 BinSumm[25][64];
-} CPpmd8;
-
-void Ppmd8_Construct(CPpmd8 *p);
-Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc);
-void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc);
-void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod);
-#define Ppmd8_WasAllocated(p) ((p)->Base != NULL)
-
-
-/* ---------- Internal Functions ---------- */
-
-extern const Byte PPMD8_kExpEscape[16];
-
-#ifdef PPMD_32BIT
- #define Ppmd8_GetPtr(p, ptr) (ptr)
- #define Ppmd8_GetContext(p, ptr) (ptr)
- #define Ppmd8_GetStats(p, ctx) ((ctx)->Stats)
-#else
- #define Ppmd8_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
- #define Ppmd8_GetContext(p, offs) ((CPpmd8_Context *)Ppmd8_GetPtr((p), (offs)))
- #define Ppmd8_GetStats(p, ctx) ((CPpmd_State *)Ppmd8_GetPtr((p), ((ctx)->Stats)))
-#endif
-
-void Ppmd8_Update1(CPpmd8 *p);
-void Ppmd8_Update1_0(CPpmd8 *p);
-void Ppmd8_Update2(CPpmd8 *p);
-void Ppmd8_UpdateBin(CPpmd8 *p);
-
-#define Ppmd8_GetBinSumm(p) \
- &p->BinSumm[p->NS2Indx[Ppmd8Context_OneState(p->MinContext)->Freq - 1]][ \
- p->NS2BSIndx[Ppmd8_GetContext(p, p->MinContext->Suffix)->NumStats] + \
- p->PrevSuccess + p->MinContext->Flags + ((p->RunLength >> 26) & 0x20)]
-
-CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked, UInt32 *scale);
-
-
-/* ---------- Decode ---------- */
-
-Bool Ppmd8_RangeDec_Init(CPpmd8 *p);
-#define Ppmd8_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
-int Ppmd8_DecodeSymbol(CPpmd8 *p); /* returns: -1 as EndMarker, -2 as DataError */
-
-
-/* ---------- Encode ---------- */
-
-#define Ppmd8_RangeEnc_Init(p) { (p)->Low = 0; (p)->Range = 0xFFFFFFFF; }
-void Ppmd8_RangeEnc_FlushData(CPpmd8 *p);
-void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol); /* symbol = -1 means EndMarker */
-
-EXTERN_C_END
-
-#endif
diff --git a/src/libs/7zip/win/C/Ppmd8Dec.c b/src/libs/7zip/win/C/Ppmd8Dec.c
deleted file mode 100644
index c54e02ab2..000000000
--- a/src/libs/7zip/win/C/Ppmd8Dec.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/* Ppmd8Dec.c -- PPMdI Decoder
-2010-04-16 : Igor Pavlov : Public domain
-This code is based on:
- PPMd var.I (2002): Dmitry Shkarin : Public domain
- Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
-
-#include "Ppmd8.h"
-
-#define kTop (1 << 24)
-#define kBot (1 << 15)
-
-Bool Ppmd8_RangeDec_Init(CPpmd8 *p)
-{
- unsigned i;
- p->Low = 0;
- p->Range = 0xFFFFFFFF;
- p->Code = 0;
- for (i = 0; i < 4; i++)
- p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In);
- return (p->Code < 0xFFFFFFFF);
-}
-
-static UInt32 RangeDec_GetThreshold(CPpmd8 *p, UInt32 total)
-{
- return p->Code / (p->Range /= total);
-}
-
-static void RangeDec_Decode(CPpmd8 *p, UInt32 start, UInt32 size)
-{
- start *= p->Range;
- p->Low += start;
- p->Code -= start;
- p->Range *= size;
-
- while ((p->Low ^ (p->Low + p->Range)) < kTop ||
- (p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1)))
- {
- p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In);
- p->Range <<= 8;
- p->Low <<= 8;
- }
-}
-
-#define MASK(sym) ((signed char *)charMask)[sym]
-
-int Ppmd8_DecodeSymbol(CPpmd8 *p)
-{
- size_t charMask[256 / sizeof(size_t)];
- if (p->MinContext->NumStats != 0)
- {
- CPpmd_State *s = Ppmd8_GetStats(p, p->MinContext);
- unsigned i;
- UInt32 count, hiCnt;
- if ((count = RangeDec_GetThreshold(p, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
- {
- Byte symbol;
- RangeDec_Decode(p, 0, s->Freq);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd8_Update1_0(p);
- return symbol;
- }
- p->PrevSuccess = 0;
- i = p->MinContext->NumStats;
- do
- {
- if ((hiCnt += (++s)->Freq) > count)
- {
- Byte symbol;
- RangeDec_Decode(p, hiCnt - s->Freq, s->Freq);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd8_Update1(p);
- return symbol;
- }
- }
- while (--i);
- if (count >= p->MinContext->SummFreq)
- return -2;
- RangeDec_Decode(p, hiCnt, p->MinContext->SummFreq - hiCnt);
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- i = p->MinContext->NumStats;
- do { MASK((--s)->Symbol) = 0; } while (--i);
- }
- else
- {
- UInt16 *prob = Ppmd8_GetBinSumm(p);
- if (((p->Code / (p->Range >>= 14)) < *prob))
- {
- Byte symbol;
- RangeDec_Decode(p, 0, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
- symbol = (p->FoundState = Ppmd8Context_OneState(p->MinContext))->Symbol;
- Ppmd8_UpdateBin(p);
- return symbol;
- }
- RangeDec_Decode(p, *prob, (1 << 14) - *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
- p->InitEsc = PPMD8_kExpEscape[*prob >> 10];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(Ppmd8Context_OneState(p->MinContext)->Symbol) = 0;
- p->PrevSuccess = 0;
- }
- for (;;)
- {
- CPpmd_State *ps[256], *s;
- UInt32 freqSum, count, hiCnt;
- CPpmd_See *see;
- unsigned i, num, numMasked = p->MinContext->NumStats;
- do
- {
- p->OrderFall++;
- if (!p->MinContext->Suffix)
- return -1;
- p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
- }
- while (p->MinContext->NumStats == numMasked);
- hiCnt = 0;
- s = Ppmd8_GetStats(p, p->MinContext);
- i = 0;
- num = p->MinContext->NumStats - numMasked;
- do
- {
- int k = (int)(MASK(s->Symbol));
- hiCnt += (s->Freq & k);
- ps[i] = s++;
- i -= k;
- }
- while (i != num);
-
- see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum);
- freqSum += hiCnt;
- count = RangeDec_GetThreshold(p, freqSum);
-
- if (count < hiCnt)
- {
- Byte symbol;
- CPpmd_State **pps = ps;
- for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
- s = *pps;
- RangeDec_Decode(p, hiCnt - s->Freq, s->Freq);
- Ppmd_See_Update(see);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd8_Update2(p);
- return symbol;
- }
- if (count >= freqSum)
- return -2;
- RangeDec_Decode(p, hiCnt, freqSum - hiCnt);
- see->Summ = (UInt16)(see->Summ + freqSum);
- do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
- }
-}
diff --git a/src/libs/7zip/win/C/Ppmd8Enc.c b/src/libs/7zip/win/C/Ppmd8Enc.c
deleted file mode 100644
index 8da727eb2..000000000
--- a/src/libs/7zip/win/C/Ppmd8Enc.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/* Ppmd8Enc.c -- PPMdI Encoder
-2010-04-16 : Igor Pavlov : Public domain
-This code is based on:
- PPMd var.I (2002): Dmitry Shkarin : Public domain
- Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
-
-#include "Ppmd8.h"
-
-#define kTop (1 << 24)
-#define kBot (1 << 15)
-
-void Ppmd8_RangeEnc_FlushData(CPpmd8 *p)
-{
- unsigned i;
- for (i = 0; i < 4; i++, p->Low <<= 8 )
- p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24));
-}
-
-static void RangeEnc_Normalize(CPpmd8 *p)
-{
- while ((p->Low ^ (p->Low + p->Range)) < kTop ||
- (p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1)))
- {
- p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24));
- p->Range <<= 8;
- p->Low <<= 8;
- }
-}
-
-static void RangeEnc_Encode(CPpmd8 *p, UInt32 start, UInt32 size, UInt32 total)
-{
- p->Low += start * (p->Range /= total);
- p->Range *= size;
- RangeEnc_Normalize(p);
-}
-
-static void RangeEnc_EncodeBit_0(CPpmd8 *p, UInt32 size0)
-{
- p->Range >>= 14;
- p->Range *= size0;
- RangeEnc_Normalize(p);
-}
-
-static void RangeEnc_EncodeBit_1(CPpmd8 *p, UInt32 size0)
-{
- p->Low += size0 * (p->Range >>= 14);
- p->Range *= ((1 << 14) - size0);
- RangeEnc_Normalize(p);
-}
-
-
-#define MASK(sym) ((signed char *)charMask)[sym]
-
-void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol)
-{
- size_t charMask[256 / sizeof(size_t)];
- if (p->MinContext->NumStats != 0)
- {
- CPpmd_State *s = Ppmd8_GetStats(p, p->MinContext);
- UInt32 sum;
- unsigned i;
- if (s->Symbol == symbol)
- {
- RangeEnc_Encode(p, 0, s->Freq, p->MinContext->SummFreq);
- p->FoundState = s;
- Ppmd8_Update1_0(p);
- return;
- }
- p->PrevSuccess = 0;
- sum = s->Freq;
- i = p->MinContext->NumStats;
- do
- {
- if ((++s)->Symbol == symbol)
- {
- RangeEnc_Encode(p, sum, s->Freq, p->MinContext->SummFreq);
- p->FoundState = s;
- Ppmd8_Update1(p);
- return;
- }
- sum += s->Freq;
- }
- while (--i);
-
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- i = p->MinContext->NumStats;
- do { MASK((--s)->Symbol) = 0; } while (--i);
- RangeEnc_Encode(p, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);
- }
- else
- {
- UInt16 *prob = Ppmd8_GetBinSumm(p);
- CPpmd_State *s = Ppmd8Context_OneState(p->MinContext);
- if (s->Symbol == symbol)
- {
- RangeEnc_EncodeBit_0(p, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
- p->FoundState = s;
- Ppmd8_UpdateBin(p);
- return;
- }
- else
- {
- RangeEnc_EncodeBit_1(p, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
- p->InitEsc = PPMD8_kExpEscape[*prob >> 10];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- p->PrevSuccess = 0;
- }
- }
- for (;;)
- {
- UInt32 escFreq;
- CPpmd_See *see;
- CPpmd_State *s;
- UInt32 sum;
- unsigned i, numMasked = p->MinContext->NumStats;
- do
- {
- p->OrderFall++;
- if (!p->MinContext->Suffix)
- return; /* EndMarker (symbol = -1) */
- p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
- }
- while (p->MinContext->NumStats == numMasked);
-
- see = Ppmd8_MakeEscFreq(p, numMasked, &escFreq);
- s = Ppmd8_GetStats(p, p->MinContext);
- sum = 0;
- i = p->MinContext->NumStats + 1;
- do
- {
- int cur = s->Symbol;
- if (cur == symbol)
- {
- UInt32 low = sum;
- CPpmd_State *s1 = s;
- do
- {
- sum += (s->Freq & (int)(MASK(s->Symbol)));
- s++;
- }
- while (--i);
- RangeEnc_Encode(p, low, s1->Freq, sum + escFreq);
- Ppmd_See_Update(see);
- p->FoundState = s1;
- Ppmd8_Update2(p);
- return;
- }
- sum += (s->Freq & (int)(MASK(cur)));
- MASK(cur) = 0;
- s++;
- }
- while (--i);
-
- RangeEnc_Encode(p, sum, escFreq, sum + escFreq);
- see->Summ = (UInt16)(see->Summ + sum + escFreq);
- }
-}
diff --git a/src/libs/7zip/win/C/Sort.c b/src/libs/7zip/win/C/Sort.c
deleted file mode 100644
index 388d22893..000000000
--- a/src/libs/7zip/win/C/Sort.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Sort.c -- Sort functions
-2010-09-17 : Igor Pavlov : Public domain */
-
-#include "Sort.h"
-
-#define HeapSortDown(p, k, size, temp) \
- { for (;;) { \
- UInt32 s = (k << 1); \
- if (s > size) break; \
- if (s < size && p[s + 1] > p[s]) s++; \
- if (temp >= p[s]) break; \
- p[k] = p[s]; k = s; \
- } p[k] = temp; }
-
-void HeapSort(UInt32 *p, UInt32 size)
-{
- if (size <= 1)
- return;
- p--;
- {
- UInt32 i = size / 2;
- do
- {
- UInt32 temp = p[i];
- UInt32 k = i;
- HeapSortDown(p, k, size, temp)
- }
- while (--i != 0);
- }
- /*
- do
- {
- UInt32 k = 1;
- UInt32 temp = p[size];
- p[size--] = p[1];
- HeapSortDown(p, k, size, temp)
- }
- while (size > 1);
- */
- while (size > 3)
- {
- UInt32 temp = p[size];
- UInt32 k = (p[3] > p[2]) ? 3 : 2;
- p[size--] = p[1];
- p[1] = p[k];
- HeapSortDown(p, k, size, temp)
- }
- {
- UInt32 temp = p[size];
- p[size] = p[1];
- if (size > 2 && p[2] < temp)
- {
- p[1] = p[2];
- p[2] = temp;
- }
- else
- p[1] = temp;
- }
-}
-
-/*
-#define HeapSortRefDown(p, vals, n, size, temp) \
- { UInt32 k = n; UInt32 val = vals[temp]; for (;;) { \
- UInt32 s = (k << 1); \
- if (s > size) break; \
- if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \
- if (val >= vals[p[s]]) break; \
- p[k] = p[s]; k = s; \
- } p[k] = temp; }
-
-void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size)
-{
- if (size <= 1)
- return;
- p--;
- {
- UInt32 i = size / 2;
- do
- {
- UInt32 temp = p[i];
- HeapSortRefDown(p, vals, i, size, temp);
- }
- while (--i != 0);
- }
- do
- {
- UInt32 temp = p[size];
- p[size--] = p[1];
- HeapSortRefDown(p, vals, 1, size, temp);
- }
- while (size > 1);
-}
-*/
diff --git a/src/libs/7zip/win/C/Sort.h b/src/libs/7zip/win/C/Sort.h
deleted file mode 100644
index 65dfc6f6a..000000000
--- a/src/libs/7zip/win/C/Sort.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Sort.h -- Sort functions
-2009-02-07 : Igor Pavlov : Public domain */
-
-#ifndef __7Z_SORT_H
-#define __7Z_SORT_H
-
-#include "Types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void HeapSort(UInt32 *p, UInt32 size);
-/* void HeapSortRef(UInt32 *p, UInt32 *vals, UInt32 size); */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/ApmHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/ApmHandler.cpp
deleted file mode 100644
index a3b5e19b9..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/ApmHandler.cpp
+++ /dev/null
@@ -1,356 +0,0 @@
-// ApmHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-#include "Common/MyString.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-
-#define Get16(p) GetBe16(p)
-#define Get32(p) GetBe32(p)
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NApm {
-
-struct CItem
-{
- UInt32 StartBlock;
- UInt32 NumBlocks;
- char Name[32];
- char Type[32];
- /*
- UInt32 DataStartBlock;
- UInt32 NumDataBlocks;
- UInt32 Status;
- UInt32 BootStartBlock;
- UInt32 BootSize;
- UInt32 BootAddr;
- UInt32 BootEntry;
- UInt32 BootChecksum;
- char Processor[16];
- */
-
- bool Parse(const Byte *p, UInt32 &numBlocksInMap)
- {
- if (p[0] != 0x50 || p[1] != 0x4D || p[2] != 0 || p[3] != 0)
- return false;
- numBlocksInMap = Get32(p + 4);
- StartBlock = Get32(p + 8);
- NumBlocks = Get32(p + 0xC);
- memcpy(Name, p + 0x10, 32);
- memcpy(Type, p + 0x30, 32);
- /*
- DataStartBlock = Get32(p + 0x50);
- NumDataBlocks = Get32(p + 0x54);
- Status = Get32(p + 0x58);
- BootStartBlock = Get32(p + 0x5C);
- BootSize = Get32(p + 0x60);
- BootAddr = Get32(p + 0x64);
- if (Get32(p + 0x68) != 0)
- return false;
- BootEntry = Get32(p + 0x6C);
- if (Get32(p + 0x70) != 0)
- return false;
- BootChecksum = Get32(p + 0x74);
- memcpy(Processor, p + 0x78, 16);
- */
- return true;
- }
-};
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- CRecordVector<CItem> _items;
-
- int _blockSizeLog;
- UInt32 _numBlocks;
-
- HRESULT ReadTables(IInStream *stream);
- UInt64 BlocksToBytes(UInt32 i) const { return (UInt64)i << _blockSizeLog; }
- UInt64 GetItemSize(const CItem &item) { return BlocksToBytes(item.NumBlocks); }
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-static inline int GetLog(UInt32 num)
-{
- for (int i = 0; i < 31; i++)
- if (((UInt32)1 << i) == num)
- return i;
- return -1;
-}
-
-HRESULT CHandler::ReadTables(IInStream *stream)
-{
- const UInt32 kSectorSize = 512;
- Byte buf[kSectorSize];
- {
- RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
- if (buf[0] != 0x45 || buf[1] != 0x52)
- return S_FALSE;
- _blockSizeLog = GetLog(Get16(buf + 2));
- if (_blockSizeLog < 9 || _blockSizeLog > 14)
- return S_FALSE;
- _numBlocks = Get32(buf + 4);
- for (int i = 8; i < 16; i++)
- if (buf[i] != 0)
- return S_FALSE;
- }
-
- unsigned numSkips = (unsigned)1 << (_blockSizeLog - 9);
- for (unsigned j = 1; j < numSkips; j++)
- {
- RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
- }
-
- UInt32 numBlocksInMap = 0;
- for (unsigned i = 0;;)
- {
- RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
-
- CItem item;
-
- UInt32 numBlocksInMap2;
- if (!item.Parse(buf, numBlocksInMap2))
- return S_FALSE;
- if (i == 0)
- {
- numBlocksInMap = numBlocksInMap2;
- if (numBlocksInMap > (1 << 8))
- return S_FALSE;
- }
- else if (numBlocksInMap2 != numBlocksInMap)
- return S_FALSE;
-
- UInt32 finish = item.StartBlock + item.NumBlocks;
- if (finish < item.StartBlock)
- return S_FALSE;
- _numBlocks = MyMax(_numBlocks, finish);
-
- _items.Add(item);
- for (unsigned j = 1; j < numSkips; j++)
- {
- RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
- }
- if (++i == numBlocksInMap)
- break;
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- RINOK(ReadTables(stream));
- _stream = stream;
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _items.Clear();
- _stream.Release();
- return S_OK;
-}
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidOffset, VT_UI8}
-};
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidClusterSize, VT_UI4},
- { NULL, kpidPhySize, VT_UI8}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-static AString GetString(const char *s)
-{
- AString res;
- for (int i = 0; i < 32 && s[i] != 0; i++)
- res += s[i];
- return res;
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMainSubfile:
- {
- int mainIndex = -1;
- for (int i = 0; i < _items.Size(); i++)
- {
- AString s = GetString(_items[i].Type);
- if (s != "Apple_Free" &&
- s != "Apple_partition_map")
- {
- if (mainIndex >= 0)
- {
- mainIndex = -1;
- break;
- }
- mainIndex = i;
- }
- }
- if (mainIndex >= 0)
- prop = (UInt32)mainIndex;
- break;
- }
- case kpidClusterSize: prop = (UInt32)1 << _blockSizeLog; break;
- case kpidPhySize: prop = BlocksToBytes(_numBlocks); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
- const CItem &item = _items[index];
- switch(propID)
- {
- case kpidPath:
- {
- AString s = GetString(item.Name);
- if (s.IsEmpty())
- {
- char s2[32];
- ConvertUInt32ToString(index, s2);
- s = s2;
- }
- AString type = GetString(item.Type);
- if (type == "Apple_HFS")
- type = "hfs";
- if (!type.IsEmpty())
- {
- s += '.';
- s += type;
- }
- prop = s;
- break;
- }
- case kpidSize:
- case kpidPackSize:
- prop = GetItemSize(item);
- break;
- case kpidOffset: prop = BlocksToBytes(item.StartBlock); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _items.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- totalSize += GetItemSize(_items[allFilesMode ? i : indices[i]]);
- extractCallback->SetTotal(totalSize);
-
- totalSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_stream);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = totalSize;
- lps->OutSize = totalSize;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> outStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItem &item = _items[index];
-
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- UInt64 size = GetItemSize(item);
- totalSize += size;
- if (!testMode && !outStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
-
- RINOK(_stream->Seek(BlocksToBytes(item.StartBlock), STREAM_SEEK_SET, NULL));
- streamSpec->Init(size);
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == size ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- const CItem &item = _items[index];
- return CreateLimitedInStream(_stream, BlocksToBytes(item.StartBlock), GetItemSize(item), stream);
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"APM", L"", 0, 0xD4, { 0x50, 0x4D, 0, 0, 0, 0, 0 }, 7, false, CreateArc, 0 };
-
-REGISTER_ARC(Apm)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Archive.def b/src/libs/7zip/win/CPP/7zip/Archive/Archive.def
new file mode 100644
index 000000000..55b530b2d
--- /dev/null
+++ b/src/libs/7zip/win/CPP/7zip/Archive/Archive.def
@@ -0,0 +1,6 @@
+EXPORTS
+ CreateObject PRIVATE
+ GetHandlerProperty PRIVATE
+ GetNumberOfFormats PRIVATE
+ GetHandlerProperty2 PRIVATE
+ CreateObject PRIVATE
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Archive2.def b/src/libs/7zip/win/CPP/7zip/Archive/Archive2.def
new file mode 100644
index 000000000..885d39d14
--- /dev/null
+++ b/src/libs/7zip/win/CPP/7zip/Archive/Archive2.def
@@ -0,0 +1,9 @@
+EXPORTS
+ CreateObject PRIVATE
+ GetHandlerProperty PRIVATE
+ GetNumberOfFormats PRIVATE
+ GetHandlerProperty2 PRIVATE
+ CreateObject PRIVATE
+ GetNumberOfMethods PRIVATE
+ GetMethodProperty PRIVATE
+ SetLargePageMode PRIVATE
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/ArjHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/ArjHandler.cpp
deleted file mode 100644
index 4dd686ec0..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/ArjHandler.cpp
+++ /dev/null
@@ -1,798 +0,0 @@
-// ArjHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/ComTry.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamObjects.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/ArjDecoder1.h"
-#include "../Compress/ArjDecoder2.h"
-#include "../Compress/CopyCoder.h"
-
-#include "Common/ItemNameUtils.h"
-#include "Common/OutStreamWithCRC.h"
-
-using namespace NWindows;
-
-#define Get16(p) GetUi16(p)
-#define Get32(p) GetUi32(p)
-
-namespace NArchive {
-namespace NArj {
-
-const int kBlockSizeMin = 30;
-const int kBlockSizeMax = 2600;
-
-namespace NSignature
-{
- const Byte kSig0 = 0x60;
- const Byte kSig1 = 0xEA;
-}
-
-namespace NFileHeader
-{
- namespace NCompressionMethod
- {
- enum
- {
- kStored = 0,
- kCompressed1a = 1,
- kCompressed1b = 2,
- kCompressed1c = 3,
- kCompressed2 = 4,
- kNoDataNoCRC = 8,
- kNoData = 9
- };
- }
-
- namespace NFileType
- {
- enum
- {
- kBinary = 0,
- k7BitText = 1,
- kArchiveHeader = 2,
- kDirectory = 3,
- kVolumeLablel = 4,
- kChapterLabel = 5
- };
- }
-
- namespace NFlags
- {
- const Byte kGarbled = 1;
- const Byte kVolume = 4;
- const Byte kExtFile = 8;
- const Byte kPathSym = 0x10;
- const Byte kBackup = 0x20;
- }
-
- namespace NHostOS
- {
- enum EEnum
- {
- kMSDOS = 0, // filesystem used by MS-DOS, OS/2, Win32
- // pkarj 2.50 (FAT / VFAT / FAT32 file systems)
- kPRIMOS,
- kUnix,
- kAMIGA,
- kMac,
- kOS_2,
- kAPPLE_GS,
- kAtari_ST,
- kNext,
- kVAX_VMS,
- kWIN95
- };
- }
-}
-
-struct CArchiveHeader
-{
- // Byte ArchiverVersion;
- // Byte ExtractVersion;
- Byte HostOS;
- // Byte Flags;
- // Byte SecuryVersion;
- // Byte FileType;
- // Byte Reserved;
- UInt32 CTime;
- UInt32 MTime;
- UInt32 ArchiveSize;
- // UInt32 SecurityEnvelopeFilePosition;
- // UInt16 FilespecPositionInFilename;
- // UInt16 LengthOfSecurityEnvelopeSata;
- // Byte EncryptionVersion;
- // Byte LastChapter;
- AString Name;
- AString Comment;
-
- HRESULT Parse(const Byte *p, unsigned size);
-};
-
-static HRESULT ReadString(const Byte *p, unsigned &size, AString &res)
-{
- AString s;
- for (unsigned i = 0; i < size;)
- {
- char c = (char)p[i++];
- if (c == 0)
- {
- size = i;
- res = s;
- return S_OK;
- }
- s += c;
- }
- return S_FALSE;
-}
-
-HRESULT CArchiveHeader::Parse(const Byte *p, unsigned size)
-{
- if (size < kBlockSizeMin)
- return S_FALSE;
- Byte firstHeaderSize = p[0];
- if (firstHeaderSize > size)
- return S_FALSE;
- // ArchiverVersion = p[1];
- // ExtractVersion = p[2];
- HostOS = p[3];
- // Flags = p[4];
- // SecuryVersion = p[5];
- if (p[6] != NFileHeader::NFileType::kArchiveHeader)
- return S_FALSE;
- // Reserved = p[7];
- CTime = Get32(p + 8);
- MTime = Get32(p + 12);
- ArchiveSize = Get32(p + 16);
- // SecurityEnvelopeFilePosition = Get32(p + 20);
- // UInt16 filespecPositionInFilename = Get16(p + 24);
- // LengthOfSecurityEnvelopeSata = Get16(p + 26);
- // EncryptionVersion = p[28];
- // LastChapter = p[29];
- unsigned pos = firstHeaderSize;
- unsigned size1 = size - pos;
- RINOK(ReadString(p + pos, size1, Name));
- pos += size1;
- size1 = size - pos;
- RINOK(ReadString(p + pos, size1, Comment));
- pos += size1;
- return S_OK;
-}
-
-struct CItem
-{
- AString Name;
- AString Comment;
-
- UInt32 MTime;
- UInt32 PackSize;
- UInt32 Size;
- UInt32 FileCRC;
- UInt32 SplitPos;
-
- Byte Version;
- Byte ExtractVersion;
- Byte HostOS;
- Byte Flags;
- Byte Method;
- Byte FileType;
-
- // UInt16 FilespecPositionInFilename;
- UInt16 FileAccessMode;
- // Byte FirstChapter;
- // Byte LastChapter;
-
- UInt64 DataPosition;
-
- bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kGarbled) != 0; }
- bool IsDir() const { return (FileType == NFileHeader::NFileType::kDirectory); }
- bool IsSplitAfter() const { return (Flags & NFileHeader::NFlags::kVolume) != 0; }
- bool IsSplitBefore() const { return (Flags & NFileHeader::NFlags::kExtFile) != 0; }
- UInt32 GetWinAttributes() const
- {
- UInt32 winAtrributes;
- switch(HostOS)
- {
- case NFileHeader::NHostOS::kMSDOS:
- case NFileHeader::NHostOS::kWIN95:
- winAtrributes = FileAccessMode;
- break;
- default:
- winAtrributes = 0;
- }
- if (IsDir())
- winAtrributes |= FILE_ATTRIBUTE_DIRECTORY;
- return winAtrributes;
- }
-
- HRESULT Parse(const Byte *p, unsigned size);
-};
-
-HRESULT CItem::Parse(const Byte *p, unsigned size)
-{
- if (size < kBlockSizeMin)
- return S_FALSE;
-
- Byte firstHeaderSize = p[0];
-
- Version = p[1];
- ExtractVersion = p[2];
- HostOS = p[3];
- Flags = p[4];
- Method = p[5];
- FileType = p[6];
- // Reserved = p[7];
- MTime = Get32(p + 8);
- PackSize = Get32(p + 12);
- Size = Get32(p + 16);
- FileCRC = Get32(p + 20);
- // FilespecPositionInFilename = Get16(p + 24);
- FileAccessMode = Get16(p + 26);
- // FirstChapter = p[28];
- // FirstChapter = p[29];
-
- SplitPos = 0;
- if (IsSplitBefore() && firstHeaderSize >= 34)
- SplitPos = Get32(p + 30);
-
- unsigned pos = firstHeaderSize;
- unsigned size1 = size - pos;
- RINOK(ReadString(p + pos, size1, Name));
- pos += size1;
- size1 = size - pos;
- RINOK(ReadString(p + pos, size1, Comment));
- pos += size1;
-
- return S_OK;
-}
-
-struct CInArchiveException
-{
- enum CCauseType
- {
- kUnexpectedEndOfArchive = 0,
- kCRCError,
- kIncorrectArchive
- }
- Cause;
- CInArchiveException(CCauseType cause): Cause(cause) {};
-};
-
-class CInArchive
-{
- UInt32 _blockSize;
- Byte _block[kBlockSizeMax + 4];
-
- HRESULT ReadBlock(bool &filled);
- HRESULT ReadSignatureAndBlock(bool &filled);
- HRESULT SkipExtendedHeaders();
-
- HRESULT SafeReadBytes(void *data, UInt32 size);
-
-public:
- CArchiveHeader Header;
-
- IInStream *Stream;
- IArchiveOpenCallback *Callback;
- UInt64 NumFiles;
- UInt64 NumBytes;
-
- HRESULT Open(const UInt64 *searchHeaderSizeLimit);
- HRESULT GetNextItem(bool &filled, CItem &item);
-};
-
-static inline bool TestMarkerCandidate(const Byte *p, unsigned maxSize)
-{
- if (p[0] != NSignature::kSig0 || p[1] != NSignature::kSig1)
- return false;
- UInt32 blockSize = Get16(p + 2);
- p += 4;
- if (p[6] != NFileHeader::NFileType::kArchiveHeader ||
- p[0] > blockSize ||
- maxSize < 2 + 2 + blockSize + 4 ||
- blockSize < kBlockSizeMin || blockSize > kBlockSizeMax ||
- p[28] > 8) // EncryptionVersion
- return false;
- // return (Get32(p + blockSize) == CrcCalc(p, blockSize));
- return true;
-}
-
-static HRESULT FindAndReadMarker(ISequentialInStream *stream, const UInt64 *searchHeaderSizeLimit, UInt64 &position)
-{
- position = 0;
-
- const int kMarkerSizeMin = 2 + 2 + kBlockSizeMin + 4;
- const int kMarkerSizeMax = 2 + 2 + kBlockSizeMax + 4;
-
- CByteBuffer byteBuffer;
- const UInt32 kBufSize = 1 << 16;
- byteBuffer.SetCapacity(kBufSize);
- Byte *buf = byteBuffer;
-
- size_t processedSize = kMarkerSizeMax;
- RINOK(ReadStream(stream, buf, &processedSize));
- if (processedSize < kMarkerSizeMin)
- return S_FALSE;
- if (TestMarkerCandidate(buf, (unsigned)processedSize))
- return S_OK;
-
- UInt32 numBytesPrev = (UInt32)processedSize - 1;
- memmove(buf, buf + 1, numBytesPrev);
- UInt64 curTestPos = 1;
- for (;;)
- {
- if (searchHeaderSizeLimit != NULL)
- if (curTestPos > *searchHeaderSizeLimit)
- return S_FALSE;
- processedSize = kBufSize - numBytesPrev;
- RINOK(ReadStream(stream, buf + numBytesPrev, &processedSize));
- UInt32 numBytesInBuffer = numBytesPrev + (UInt32)processedSize;
- if (numBytesInBuffer < kMarkerSizeMin)
- return S_FALSE;
- UInt32 numTests = numBytesInBuffer - kMarkerSizeMin + 1;
- UInt32 pos;
- for (pos = 0; pos < numTests; pos++)
- {
- for (; buf[pos] != NSignature::kSig0 && pos < numTests; pos++);
- if (pos == numTests)
- break;
- if (TestMarkerCandidate(buf + pos, numBytesInBuffer - pos))
- {
- position = curTestPos + pos;
- return S_OK;
- }
- }
- curTestPos += pos;
- numBytesPrev = numBytesInBuffer - numTests;
- memmove(buf, buf + numTests, numBytesPrev);
- }
-}
-
-HRESULT CInArchive::SafeReadBytes(void *data, UInt32 size)
-{
- size_t processed = size;
- RINOK(ReadStream(Stream, data, &processed));
- if (processed != size)
- throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
- return S_OK;
-}
-
-HRESULT CInArchive::ReadBlock(bool &filled)
-{
- filled = false;
- Byte buf[2];
- RINOK(SafeReadBytes(buf, 2));
- _blockSize = Get16(buf);
- if (_blockSize == 0)
- return S_OK;
- if (_blockSize > kBlockSizeMax)
- throw CInArchiveException(CInArchiveException::kIncorrectArchive);
- RINOK(SafeReadBytes(_block, _blockSize + 4));
- NumBytes += _blockSize + 6;
- if (Get32(_block + _blockSize) != CrcCalc(_block, _blockSize))
- throw CInArchiveException(CInArchiveException::kCRCError);
- filled = true;
- return S_OK;
-}
-
-HRESULT CInArchive::ReadSignatureAndBlock(bool &filled)
-{
- Byte id[2];
- RINOK(SafeReadBytes(id, 2));
- if (id[0] != NSignature::kSig0 || id[1] != NSignature::kSig1)
- throw CInArchiveException(CInArchiveException::kIncorrectArchive);
- return ReadBlock(filled);
-}
-
-HRESULT CInArchive::SkipExtendedHeaders()
-{
- for (UInt32 i = 0;; i++)
- {
- bool filled;
- RINOK(ReadBlock(filled));
- if (!filled)
- return S_OK;
- if (Callback && (i & 0xFF) == 0)
- RINOK(Callback->SetCompleted(&NumFiles, &NumBytes));
- }
-}
-
-HRESULT CInArchive::Open(const UInt64 *searchHeaderSizeLimit)
-{
- UInt64 position = 0;
- RINOK(FindAndReadMarker(Stream, searchHeaderSizeLimit, position));
- RINOK(Stream->Seek(position, STREAM_SEEK_SET, NULL));
- bool filled;
- RINOK(ReadSignatureAndBlock(filled));
- if (!filled)
- return S_FALSE;
- RINOK(Header.Parse(_block, _blockSize));
- return SkipExtendedHeaders();
-}
-
-HRESULT CInArchive::GetNextItem(bool &filled, CItem &item)
-{
- RINOK(ReadSignatureAndBlock(filled));
- if (!filled)
- return S_OK;
- filled = false;
- RINOK(item.Parse(_block, _blockSize));
- /*
- UInt32 extraData;
- if ((header.Flags & NFileHeader::NFlags::kExtFile) != 0)
- extraData = GetUi32(_block + pos);
- */
-
- RINOK(SkipExtendedHeaders());
- filled = true;
- return S_OK;
-}
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP1(IInArchive)
-
- INTERFACE_IInArchive(;)
-
- HRESULT Open2(IInStream *inStream, const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *callback);
-private:
- CInArchive _archive;
- CObjectVector<CItem> _items;
- CMyComPtr<IInStream> _stream;
-};
-
-const wchar_t *kHostOS[] =
-{
- L"MSDOS",
- L"PRIMOS",
- L"UNIX",
- L"AMIGA",
- L"MAC",
- L"OS/2",
- L"APPLE GS",
- L"ATARI ST",
- L"NEXT",
- L"VAX VMS",
- L"WIN95"
-};
-
-const wchar_t *kUnknownOS = L"Unknown";
-
-const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidName, VT_BSTR},
- { NULL, kpidCTime, VT_BSTR},
- { NULL, kpidMTime, VT_BSTR},
- { NULL, kpidHostOS, VT_BSTR},
- { NULL, kpidComment, VT_BSTR}
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI4},
- { NULL, kpidPosition, VT_UI8},
- { NULL, kpidPackSize, VT_UI4},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidAttrib, VT_UI4},
- { NULL, kpidEncrypted, VT_BOOL},
- { NULL, kpidCRC, VT_UI4},
- { NULL, kpidMethod, VT_UI1},
- { NULL, kpidHostOS, VT_BSTR},
- { NULL, kpidComment, VT_BSTR}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-static void SetTime(UInt32 dosTime, NWindows::NCOM::CPropVariant &prop)
-{
- if (dosTime == 0)
- return;
- FILETIME localFileTime, utc;
- if (NTime::DosTimeToFileTime(dosTime, localFileTime))
- {
- if (!LocalFileTimeToFileTime(&localFileTime, &utc))
- utc.dwHighDateTime = utc.dwLowDateTime = 0;
- }
- else
- utc.dwHighDateTime = utc.dwLowDateTime = 0;
- prop = utc;
-}
-
-static void SetHostOS(Byte hostOS, NWindows::NCOM::CPropVariant &prop)
-{
- prop = hostOS < kNumHostOSes ? kHostOS[hostOS] : kUnknownOS;
-}
-
-static void SetUnicodeString(const AString &s, NWindows::NCOM::CPropVariant &prop)
-{
- if (!s.IsEmpty())
- prop = MultiByteToUnicodeString(s, CP_OEMCP);
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidName: SetUnicodeString(_archive.Header.Name, prop); break;
- case kpidCTime: SetTime(_archive.Header.CTime, prop); break;
- case kpidMTime: SetTime(_archive.Header.MTime, prop); break;
- case kpidHostOS: SetHostOS(_archive.Header.HostOS, prop); break;
- case kpidComment: SetUnicodeString(_archive.Header.Comment, prop); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItem &item = _items[index];
- switch(propID)
- {
- case kpidPath: prop = NItemName::GetOSName(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break;
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize: prop = item.Size; break;
- case kpidPackSize: prop = item.PackSize; break;
- case kpidPosition: if (item.IsSplitBefore() || item.IsSplitAfter()) prop = (UInt64)item.SplitPos; break;
- case kpidAttrib: prop = item.GetWinAttributes(); break;
- case kpidEncrypted: prop = item.IsEncrypted(); break;
- case kpidCRC: prop = item.FileCRC; break;
- case kpidMethod: prop = item.Method; break;
- case kpidHostOS: SetHostOS(item.HostOS, prop); break;
- case kpidMTime: SetTime(item.MTime, prop); break;
- case kpidComment: SetUnicodeString(item.Comment, prop); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-HRESULT CHandler::Open2(IInStream *inStream, const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *callback)
-{
- Close();
-
- UInt64 endPos = 0;
- if (callback != NULL)
- {
- RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
- RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
- }
-
- _archive.Stream = inStream;
- _archive.Callback = callback;
- _archive.NumFiles = _archive.NumBytes = 0;
-
- RINOK(_archive.Open(maxCheckStartPosition));
- if (callback != NULL)
- RINOK(callback->SetTotal(NULL, &endPos));
- for (;;)
- {
- CItem item;
- bool filled;
-
-
- RINOK(_archive.GetNextItem(filled, item));
-
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &item.DataPosition));
-
- if (!filled)
- break;
- _items.Add(item);
-
- if (inStream->Seek(item.PackSize, STREAM_SEEK_CUR, NULL) != S_OK)
- throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
-
- _archive.NumFiles = _items.Size();
- _archive.NumBytes = item.DataPosition;
-
- if (callback != NULL && _items.Size() % 100 == 0)
- {
- RINOK(callback->SetCompleted(&_archive.NumFiles, &_archive.NumBytes));
- }
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- HRESULT res;
- try
- {
- res = Open2(inStream, maxCheckStartPosition, callback);
- if (res == S_OK)
- {
- _stream = inStream;
- return S_OK;
- }
- }
- catch(const CInArchiveException &) { res = S_FALSE; }
- Close();
- return res;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _items.Clear();
- _stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- UInt64 totalUnpacked = 0, totalPacked = 0;
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _items.Size();
- if (numItems == 0)
- return S_OK;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- {
- const CItem &item = _items[allFilesMode ? i : indices[i]];
- totalUnpacked += item.Size;
- totalPacked += item.PackSize;
- }
- extractCallback->SetTotal(totalUnpacked);
-
- totalUnpacked = totalPacked = 0;
- UInt64 curUnpacked, curPacked;
-
- CMyComPtr<ICompressCoder> arj1Decoder;
- CMyComPtr<ICompressCoder> arj2Decoder;
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *inStreamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(inStreamSpec);
- inStreamSpec->SetStream(_stream);
-
- for (i = 0; i < numItems; i++, totalUnpacked += curUnpacked, totalPacked += curPacked)
- {
- lps->InSize = totalPacked;
- lps->OutSize = totalUnpacked;
- RINOK(lps->SetCur());
-
- curUnpacked = curPacked = 0;
-
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItem &item = _items[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- if (item.IsDir())
- {
- // if (!testMode)
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- }
- continue;
- }
-
- if (!testMode && !realOutStream)
- continue;
-
- RINOK(extractCallback->PrepareOperation(askMode));
- curUnpacked = item.Size;
- curPacked = item.PackSize;
-
- {
- COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
- realOutStream.Release();
- outStreamSpec->Init();
-
- inStreamSpec->Init(item.PackSize);
-
- UInt64 pos;
- _stream->Seek(item.DataPosition, STREAM_SEEK_SET, &pos);
-
- HRESULT result = S_OK;
- Int32 opRes = NExtract::NOperationResult::kOK;
-
- if (item.IsEncrypted())
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
- else
- {
- switch(item.Method)
- {
- case NFileHeader::NCompressionMethod::kStored:
- {
- result = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
- if (result == S_OK && copyCoderSpec->TotalSize != item.PackSize)
- result = S_FALSE;
- break;
- }
- case NFileHeader::NCompressionMethod::kCompressed1a:
- case NFileHeader::NCompressionMethod::kCompressed1b:
- case NFileHeader::NCompressionMethod::kCompressed1c:
- {
- if (!arj1Decoder)
- arj1Decoder = new NCompress::NArj::NDecoder1::CCoder;
- result = arj1Decoder->Code(inStream, outStream, NULL, &curUnpacked, progress);
- break;
- }
- case NFileHeader::NCompressionMethod::kCompressed2:
- {
- if (!arj2Decoder)
- arj2Decoder = new NCompress::NArj::NDecoder2::CCoder;
- result = arj2Decoder->Code(inStream, outStream, NULL, &curUnpacked, progress);
- break;
- }
- default:
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
- }
- }
- if (opRes == NExtract::NOperationResult::kOK)
- {
- if (result == S_FALSE)
- opRes = NExtract::NOperationResult::kDataError;
- else
- {
- RINOK(result);
- opRes = (outStreamSpec->GetCRC() == item.FileCRC) ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kCRCError;
- }
- }
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(opRes));
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Arj", L"arj", 0, 4, { 0x60, 0xEA }, 2, false, CreateArc, 0 };
-
-REGISTER_ARC(Arj)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Bz2Handler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Bz2Handler.cpp
deleted file mode 100644
index 98cbcc182..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Bz2Handler.cpp
+++ /dev/null
@@ -1,423 +0,0 @@
-// Bz2Handler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-
-#include "Windows/PropVariant.h"
-
-#ifndef _7ZIP_ST
-#include "../../Windows/System.h"
-#endif
-
-#include "../Common/CreateCoder.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/BZip2Decoder.h"
-#include "../Compress/BZip2Encoder.h"
-#include "../Compress/CopyCoder.h"
-
-#include "Common/DummyOutStream.h"
-#include "Common/ParseProperties.h"
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NBz2 {
-
-static const UInt32 kNumPassesX1 = 1;
-static const UInt32 kNumPassesX7 = 2;
-static const UInt32 kNumPassesX9 = 7;
-
-static const UInt32 kDicSizeX1 = 100000;
-static const UInt32 kDicSizeX3 = 500000;
-static const UInt32 kDicSizeX5 = 900000;
-
-class CHandler:
- public IInArchive,
- public IArchiveOpenSeq,
- public IOutArchive,
- public ISetProperties,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- CMyComPtr<ISequentialInStream> _seqStream;
- UInt64 _packSize;
- UInt64 _startPosition;
- bool _packSizeDefined;
-
- UInt32 _level;
- UInt32 _dicSize;
- UInt32 _numPasses;
- #ifndef _7ZIP_ST
- UInt32 _numThreads;
- #endif
-
- void InitMethodProperties()
- {
- _level = 5;
- _dicSize =
- _numPasses = 0xFFFFFFFF;
- #ifndef _7ZIP_ST
- _numThreads = NWindows::NSystem::GetNumberOfProcessors();;
- #endif
- }
-
-public:
- MY_UNKNOWN_IMP4(IInArchive, IArchiveOpenSeq, IOutArchive, ISetProperties)
-
- INTERFACE_IInArchive(;)
- INTERFACE_IOutArchive(;)
- STDMETHOD(OpenSeq)(ISequentialInStream *stream);
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProps);
-
- CHandler() { InitMethodProperties(); }
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPackSize, VT_UI8}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO_Table
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPhySize: if (_packSizeDefined) prop = _packSize; break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = 1;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
-{
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPackSize: if (_packSizeDefined) prop = _packSize; break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- try
- {
- Close();
- RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_startPosition));
- const int kSignatureSize = 3;
- Byte buf[kSignatureSize];
- RINOK(ReadStream_FALSE(stream, buf, kSignatureSize));
- if (buf[0] != 'B' || buf[1] != 'Z' || buf[2] != 'h')
- return S_FALSE;
-
- UInt64 endPosition;
- RINOK(stream->Seek(0, STREAM_SEEK_END, &endPosition));
- _packSize = endPosition - _startPosition;
- _packSizeDefined = true;
- _stream = stream;
- _seqStream = stream;
- }
- catch(...) { return S_FALSE; }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
-{
- Close();
- _seqStream = stream;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _packSizeDefined = false;
- _seqStream.Release();
- _stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- if (numItems == 0)
- return S_OK;
- if (numItems != (UInt32)-1 && (numItems != 1 || indices[0] != 0))
- return E_INVALIDARG;
-
- if (_stream)
- extractCallback->SetTotal(_packSize);
- UInt64 currentTotalPacked = 0;
- RINOK(extractCallback->SetCompleted(&currentTotalPacked));
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
- if (!testMode && !realOutStream)
- return S_OK;
-
- extractCallback->PrepareOperation(askMode);
-
- NCompress::NBZip2::CDecoder *decoderSpec = new NCompress::NBZip2::CDecoder;
- CMyComPtr<ICompressCoder> decoder = decoderSpec;
-
- if (_stream)
- {
- RINOK(_stream->Seek(_startPosition, STREAM_SEEK_SET, NULL));
- }
-
- decoderSpec->SetInStream(_seqStream);
-
- #ifndef _7ZIP_ST
- RINOK(decoderSpec->SetNumberOfThreads(_numThreads));
- #endif
-
- CDummyOutStream *outStreamSpec = new CDummyOutStream;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init();
-
- realOutStream.Release();
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, true);
-
- HRESULT result = S_OK;
-
- bool firstItem = true;
- for (;;)
- {
- lps->InSize = currentTotalPacked;
- lps->OutSize = outStreamSpec->GetSize();
-
- RINOK(lps->SetCur());
-
- bool isBz2;
- result = decoderSpec->CodeResume(outStream, isBz2, progress);
-
- if (result != S_OK)
- break;
- if (!isBz2)
- {
- if (firstItem)
- result = S_FALSE;
- break;
- }
- firstItem = false;
-
- _packSize = currentTotalPacked = decoderSpec->GetInputProcessedSize();
- _packSizeDefined = true;
- }
- decoderSpec->ReleaseInStream();
- outStream.Release();
-
- Int32 retResult;
- if (result == S_OK)
- retResult = NExtract::NOperationResult::kOK;
- else if (result == S_FALSE)
- retResult = NExtract::NOperationResult::kDataError;
- else
- return result;
- return extractCallback->SetOperationResult(retResult);
-
- COM_TRY_END
-}
-
-static HRESULT UpdateArchive(
- UInt64 unpackSize,
- ISequentialOutStream *outStream,
- int indexInClient,
- UInt32 dictionary,
- UInt32 numPasses,
- #ifndef _7ZIP_ST
- UInt32 numThreads,
- #endif
- IArchiveUpdateCallback *updateCallback)
-{
- RINOK(updateCallback->SetTotal(unpackSize));
- UInt64 complexity = 0;
- RINOK(updateCallback->SetCompleted(&complexity));
-
- CMyComPtr<ISequentialInStream> fileInStream;
-
- RINOK(updateCallback->GetStream(indexInClient, &fileInStream));
-
- CLocalProgress *localProgressSpec = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> localProgress = localProgressSpec;
- localProgressSpec->Init(updateCallback, true);
-
- NCompress::NBZip2::CEncoder *encoderSpec = new NCompress::NBZip2::CEncoder;
- CMyComPtr<ICompressCoder> encoder = encoderSpec;
- {
- NWindows::NCOM::CPropVariant properties[] =
- {
- dictionary,
- numPasses
- #ifndef _7ZIP_ST
- , numThreads
- #endif
- };
- PROPID propIDs[] =
- {
- NCoderPropID::kDictionarySize,
- NCoderPropID::kNumPasses
- #ifndef _7ZIP_ST
- , NCoderPropID::kNumThreads
- #endif
- };
- RINOK(encoderSpec->SetCoderProperties(propIDs, properties, sizeof(propIDs) / sizeof(propIDs[0])));
- }
-
- RINOK(encoder->Code(fileInStream, outStream, NULL, NULL, localProgress));
-
- return updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK);
-}
-
-STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)
-{
- *type = NFileTimeType::kUnix;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
- IArchiveUpdateCallback *updateCallback)
-{
- if (numItems != 1)
- return E_INVALIDARG;
-
- Int32 newData, newProps;
- UInt32 indexInArchive;
- if (!updateCallback)
- return E_FAIL;
- RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProps, &indexInArchive));
-
- if (IntToBool(newProps))
- {
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(0, kpidIsDir, &prop));
- if (prop.vt == VT_BOOL)
- {
- if (prop.boolVal != VARIANT_FALSE)
- return E_INVALIDARG;
- }
- else if (prop.vt != VT_EMPTY)
- return E_INVALIDARG;
- }
- }
-
- if (IntToBool(newData))
- {
- UInt64 size;
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(0, kpidSize, &prop));
- if (prop.vt != VT_UI8)
- return E_INVALIDARG;
- size = prop.uhVal.QuadPart;
- }
-
- UInt32 dicSize = _dicSize;
- if (dicSize == 0xFFFFFFFF)
- dicSize = (_level >= 5 ? kDicSizeX5 :
- (_level >= 3 ? kDicSizeX3 :
- kDicSizeX1));
-
- UInt32 numPasses = _numPasses;
- if (numPasses == 0xFFFFFFFF)
- numPasses = (_level >= 9 ? kNumPassesX9 :
- (_level >= 7 ? kNumPassesX7 :
- kNumPassesX1));
-
- return UpdateArchive(
- size, outStream, 0, dicSize, numPasses,
- #ifndef _7ZIP_ST
- _numThreads,
- #endif
- updateCallback);
- }
- if (indexInArchive != 0)
- return E_INVALIDARG;
- if (_stream)
- RINOK(_stream->Seek(_startPosition, STREAM_SEEK_SET, NULL));
- return NCompress::CopyStream(_stream, outStream, NULL);
-}
-
-STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps)
-{
- InitMethodProperties();
- #ifndef _7ZIP_ST
- const UInt32 numProcessors = NSystem::GetNumberOfProcessors();
- _numThreads = numProcessors;
- #endif
-
- for (int i = 0; i < numProps; i++)
- {
- UString name = names[i];
- name.MakeUpper();
- if (name.IsEmpty())
- return E_INVALIDARG;
- const PROPVARIANT &prop = values[i];
- if (name[0] == L'X')
- {
- UInt32 level = 9;
- RINOK(ParsePropValue(name.Mid(1), prop, level));
- _level = level;
- }
- else if (name[0] == L'D')
- {
- UInt32 dicSize = kDicSizeX5;
- RINOK(ParsePropDictionaryValue(name.Mid(1), prop, dicSize));
- _dicSize = dicSize;
- }
- else if (name.Left(4) == L"PASS")
- {
- UInt32 num = kNumPassesX9;
- RINOK(ParsePropValue(name.Mid(4), prop, num));
- _numPasses = num;
- }
- else if (name.Left(2) == L"MT")
- {
- #ifndef _7ZIP_ST
- RINOK(ParseMtProp(name.Mid(2), prop, numProcessors, _numThreads));
- #endif
- }
- else
- return E_INVALIDARG;
- }
- return S_OK;
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-#ifndef EXTRACT_ONLY
-static IOutArchive *CreateArcOut() { return new CHandler; }
-#else
-#define CreateArcOut 0
-#endif
-
-static CArcInfo g_ArcInfo =
- { L"bzip2", L"bz2 bzip2 tbz2 tbz", L"* * .tar .tar", 2, { 'B', 'Z', 'h' }, 3, true, CreateArc, CreateArcOut };
-
-REGISTER_ARC(BZip2)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
deleted file mode 100644
index 12c73eb5f..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-// CabBlockInStream.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../C/Alloc.h"
-
-#include "Common/Defs.h"
-
-#include "../../Common/StreamUtils.h"
-
-#include "CabBlockInStream.h"
-
-namespace NArchive {
-namespace NCab {
-
-static const UInt32 kBlockSize = (1 << 16);
-
-bool CCabBlockInStream::Create()
-{
- if (!_buffer)
- _buffer = (Byte *)::MyAlloc(kBlockSize);
- return (_buffer != 0);
-}
-
-CCabBlockInStream::~CCabBlockInStream()
-{
- MyFree(_buffer);
-}
-
-class CCheckSum2
-{
- UInt32 m_Value;
- int m_Pos;
- Byte m_Hist[4];
-public:
- CCheckSum2(): m_Value(0){};
- void Init() { m_Value = 0; m_Pos = 0; }
- void Update(const void *data, UInt32 size);
- void FinishDataUpdate()
- {
- for (int i = 0; i < m_Pos; i++)
- m_Value ^= ((UInt32)(m_Hist[i])) << (8 * (m_Pos - i - 1));
- }
- void UpdateUInt32(UInt32 v) { m_Value ^= v; }
- UInt32 GetResult() const { return m_Value; }
-};
-
-void CCheckSum2::Update(const void *data, UInt32 size)
-{
- UInt32 checkSum = m_Value;
- const Byte *dataPointer = (const Byte *)data;
-
- while (size != 0 && m_Pos != 0)
- {
- m_Hist[m_Pos] = *dataPointer++;
- m_Pos = (m_Pos + 1) & 3;
- size--;
- if (m_Pos == 0)
- for (int i = 0; i < 4; i++)
- checkSum ^= ((UInt32)m_Hist[i]) << (8 * i);
- }
-
- int numWords = size / 4;
-
- while (numWords-- != 0)
- {
- UInt32 temp = *dataPointer++;
- temp |= ((UInt32)(*dataPointer++)) << 8;
- temp |= ((UInt32)(*dataPointer++)) << 16;
- temp |= ((UInt32)(*dataPointer++)) << 24;
- checkSum ^= temp;
- }
- m_Value = checkSum;
-
- size &= 3;
-
- while (size != 0)
- {
- m_Hist[m_Pos] = *dataPointer++;
- m_Pos = (m_Pos + 1) & 3;
- size--;
- }
-}
-
-static const UInt32 kDataBlockHeaderSize = 8;
-
-class CTempCabInBuffer2
-{
-public:
- Byte Buffer[kDataBlockHeaderSize];
- UInt32 Pos;
- Byte ReadByte()
- {
- return Buffer[Pos++];
- }
- UInt32 ReadUInt32()
- {
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- value |= (((UInt32)ReadByte()) << (8 * i));
- return value;
- }
- UInt16 ReadUInt16()
- {
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- value |= (((UInt16)ReadByte()) << (8 * i));
- return value;
- }
-};
-
-HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
-{
- CTempCabInBuffer2 inBuffer;
- inBuffer.Pos = 0;
- RINOK(ReadStream_FALSE(_stream, inBuffer.Buffer, kDataBlockHeaderSize))
-
- UInt32 checkSum = inBuffer.ReadUInt32();
- packSize = inBuffer.ReadUInt16();
- unpackSize = inBuffer.ReadUInt16();
- if (ReservedSize != 0)
- {
- RINOK(ReadStream_FALSE(_stream, _buffer, ReservedSize));
- }
- _pos = 0;
- CCheckSum2 checkSumCalc;
- checkSumCalc.Init();
- UInt32 packSize2 = packSize;
- if (MsZip && _size == 0)
- {
- if (packSize < 2)
- return S_FALSE; // bad block;
- Byte sig[2];
- RINOK(ReadStream_FALSE(_stream, sig, 2));
- if (sig[0] != 0x43 || sig[1] != 0x4B)
- return S_FALSE;
- packSize2 -= 2;
- checkSumCalc.Update(sig, 2);
- }
-
- if (kBlockSize - _size < packSize2)
- return S_FALSE;
-
- UInt32 curSize = packSize2;
- if (curSize != 0)
- {
- size_t processedSizeLoc = curSize;
- RINOK(ReadStream(_stream, _buffer + _size, &processedSizeLoc));
- checkSumCalc.Update(_buffer + _size, (UInt32)processedSizeLoc);
- _size += (UInt32)processedSizeLoc;
- if (processedSizeLoc != curSize)
- return S_FALSE;
- }
- TotalPackSize = _size;
-
- checkSumCalc.FinishDataUpdate();
-
- bool dataError;
- if (checkSum == 0)
- dataError = false;
- else
- {
- checkSumCalc.UpdateUInt32(packSize | (((UInt32)unpackSize) << 16));
- dataError = (checkSumCalc.GetResult() != checkSum);
- }
- DataError |= dataError;
- return dataError ? S_FALSE : S_OK;
-}
-
-STDMETHODIMP CCabBlockInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
-{
- if (processedSize != 0)
- *processedSize = 0;
- if (size == 0)
- return S_OK;
- if (_size != 0)
- {
- size = MyMin(_size, size);
- memmove(data, _buffer + _pos, size);
- _pos += size;
- _size -= size;
- if (processedSize != 0)
- *processedSize = size;
- return S_OK;
- }
- return S_OK; // no blocks data
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.h b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.h
deleted file mode 100644
index 1db3835b4..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabBlockInStream.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// CabBlockInStream.cpp
-
-#ifndef __CABBLOCKINSTREAM_H
-#define __CABBLOCKINSTREAM_H
-
-#include "Common/MyCom.h"
-#include "../../IStream.h"
-
-namespace NArchive {
-namespace NCab {
-
-class CCabBlockInStream:
- public ISequentialInStream,
- public CMyUnknownImp
-{
- CMyComPtr<ISequentialInStream> _stream;
- Byte *_buffer;
- UInt32 _pos;
- UInt32 _size;
-
-public:
- UInt32 TotalPackSize;
- UInt32 ReservedSize;
- bool DataError;
- bool MsZip;
-
- CCabBlockInStream(): _buffer(0), ReservedSize(0), MsZip(false), DataError(false), TotalPackSize(0) {}
- ~CCabBlockInStream();
- bool Create();
- void SetStream(ISequentialInStream *stream) { _stream = stream; }
-
- void InitForNewFolder() { TotalPackSize = 0; }
- void InitForNewBlock() { _size = 0; }
-
- MY_UNKNOWN_IMP
-
- STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
-
- HRESULT PreRead(UInt32 &packSize, UInt32 &unpackSize);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.cpp
deleted file mode 100644
index 20f670d35..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.cpp
+++ /dev/null
@@ -1,929 +0,0 @@
-// CabHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../C/Alloc.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.h"
-#include "Common/Defs.h"
-#include "Common/IntToString.h"
-#include "Common/StringConvert.h"
-#include "Common/UTFConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-#include "../../Compress/DeflateDecoder.h"
-#include "../../Compress/LzxDecoder.h"
-#include "../../Compress/QuantumDecoder.h"
-
-#include "../Common/ItemNameUtils.h"
-
-#include "CabBlockInStream.h"
-#include "CabHandler.h"
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NCab {
-
-// #define _CAB_DETAILS
-
-#ifdef _CAB_DETAILS
-enum
-{
- kpidBlockReal = kpidUserDefined
-};
-#endif
-
-static STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidAttrib, VT_UI4},
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidBlock, VT_I4}
- #ifdef _CAB_DETAILS
- ,
- { L"BlockReal", kpidBlockReal, VT_UI4},
- { NULL, kpidOffset, VT_UI4},
- { NULL, kpidVolume, VT_UI4}
- #endif
-};
-
-static const char *kMethods[] =
-{
- "None",
- "MSZip",
- "Quantum",
- "LZX"
-};
-
-static const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
-static const char *kUnknownMethod = "Unknown";
-
-static STATPROPSTG kArcProps[] =
-{
- { NULL, kpidMethod, VT_BSTR},
- // { NULL, kpidSolid, VT_BOOL},
- { NULL, kpidNumBlocks, VT_UI4},
- { NULL, kpidNumVolumes, VT_UI4}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMethod:
- {
- AString resString;
- CRecordVector<Byte> ids;
- int i;
- for (int v = 0; v < m_Database.Volumes.Size(); v++)
- {
- const CDatabaseEx &de = m_Database.Volumes[v];
- for (i = 0; i < de.Folders.Size(); i++)
- ids.AddToUniqueSorted(de.Folders[i].GetCompressionMethod());
- }
- for (i = 0; i < ids.Size(); i++)
- {
- Byte id = ids[i];
- AString method = (id < kNumMethods) ? kMethods[id] : kUnknownMethod;
- if (!resString.IsEmpty())
- resString += ' ';
- resString += method;
- }
- prop = resString;
- break;
- }
- // case kpidSolid: prop = _database.IsSolid(); break;
- case kpidNumBlocks:
- {
- UInt32 numFolders = 0;
- for (int v = 0; v < m_Database.Volumes.Size(); v++)
- numFolders += m_Database.Volumes[v].Folders.Size();
- prop = numFolders;
- break;
- }
- case kpidNumVolumes:
- {
- prop = (UInt32)m_Database.Volumes.Size();
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
-
- const CMvItem &mvItem = m_Database.Items[index];
- const CDatabaseEx &db = m_Database.Volumes[mvItem.VolumeIndex];
- int itemIndex = mvItem.ItemIndex;
- const CItem &item = db.Items[itemIndex];
- switch(propID)
- {
- case kpidPath:
- {
- UString unicodeName;
- if (item.IsNameUTF())
- ConvertUTF8ToUnicode(item.Name, unicodeName);
- else
- unicodeName = MultiByteToUnicodeString(item.Name, CP_ACP);
- prop = (const wchar_t *)NItemName::WinNameToOSName(unicodeName);
- break;
- }
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize: prop = item.Size; break;
- case kpidAttrib: prop = item.GetWinAttributes(); break;
-
- case kpidMTime:
- {
- FILETIME localFileTime, utcFileTime;
- if (NTime::DosTimeToFileTime(item.Time, localFileTime))
- {
- if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- }
- else
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
- prop = utcFileTime;
- break;
- }
-
- case kpidMethod:
- {
- UInt32 realFolderIndex = item.GetFolderIndex(db.Folders.Size());
- const CFolder &folder = db.Folders[realFolderIndex];
- int methodIndex = folder.GetCompressionMethod();
- AString method = (methodIndex < kNumMethods) ? kMethods[methodIndex] : kUnknownMethod;
- if (methodIndex == NHeader::NCompressionMethodMajor::kLZX ||
- methodIndex == NHeader::NCompressionMethodMajor::kQuantum)
- {
- method += ':';
- char temp[32];
- ConvertUInt64ToString(folder.CompressionTypeMinor, temp);
- method += temp;
- }
- prop = method;
- break;
- }
- case kpidBlock: prop = (Int32)m_Database.GetFolderIndex(&mvItem); break;
-
- #ifdef _CAB_DETAILS
-
- case kpidBlockReal: prop = (UInt32)item.FolderIndex; break;
- case kpidOffset: prop = (UInt32)item.Offset; break;
- case kpidVolume: prop = (UInt32)mvItem.VolumeIndex; break;
-
- #endif
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-/*
-class CProgressImp: public CProgressVirt
-{
- CMyComPtr<IArchiveOpenCallback> m_OpenArchiveCallback;
-public:
- STDMETHOD(SetTotal)(const UInt64 *numFiles);
- STDMETHOD(SetCompleted)(const UInt64 *numFiles);
- void Init(IArchiveOpenCallback *openArchiveCallback)
- { m_OpenArchiveCallback = openArchiveCallback; }
-};
-
-STDMETHODIMP CProgressImp::SetTotal(const UInt64 *numFiles)
-{
- if (m_OpenArchiveCallback)
- return m_OpenArchiveCallback->SetCompleted(numFiles, NULL);
- return S_OK;
-}
-
-STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles)
-{
- if (m_OpenArchiveCallback)
- return m_OpenArchiveCallback->SetCompleted(numFiles, NULL);
- return S_OK;
-}
-*/
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- Close();
- HRESULT res = S_FALSE;
- CInArchive archive;
- CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
- callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
-
- CMyComPtr<IInStream> nextStream = inStream;
- bool prevChecked = false;
- UInt64 numItems = 0;
- try
- {
- while (nextStream != 0)
- {
- CDatabaseEx db;
- db.Stream = nextStream;
- res = archive.Open(maxCheckStartPosition, db);
- if (res == S_OK)
- {
- if (!m_Database.Volumes.IsEmpty())
- {
- const CDatabaseEx &dbPrev = m_Database.Volumes[prevChecked ? m_Database.Volumes.Size() - 1 : 0];
- if (dbPrev.ArchiveInfo.SetID != db.ArchiveInfo.SetID ||
- dbPrev.ArchiveInfo.CabinetNumber + (prevChecked ? 1: - 1) !=
- db.ArchiveInfo.CabinetNumber)
- res = S_FALSE;
- }
- }
- if (res == S_OK)
- m_Database.Volumes.Insert(prevChecked ? m_Database.Volumes.Size() : 0, db);
- else if (res != S_FALSE)
- return res;
- else
- {
- if (m_Database.Volumes.IsEmpty())
- return S_FALSE;
- if (prevChecked)
- break;
- prevChecked = true;
- }
-
- numItems += db.Items.Size();
- RINOK(callback->SetCompleted(&numItems, NULL));
-
- nextStream = 0;
- for (;;)
- {
- const COtherArchive *otherArchive = 0;
- if (!prevChecked)
- {
- const CInArchiveInfo &ai = m_Database.Volumes.Front().ArchiveInfo;
- if (ai.IsTherePrev())
- otherArchive = &ai.PrevArc;
- else
- prevChecked = true;
- }
- if (otherArchive == 0)
- {
- const CInArchiveInfo &ai = m_Database.Volumes.Back().ArchiveInfo;
- if (ai.IsThereNext())
- otherArchive = &ai.NextArc;
- }
- if (!otherArchive)
- break;
- const UString fullName = MultiByteToUnicodeString(otherArchive->FileName, CP_ACP);
- if (!openVolumeCallback)
- break;
-
- HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
- if (result == S_OK)
- break;
- if (result != S_FALSE)
- return result;
- if (prevChecked)
- break;
- prevChecked = true;
- }
- }
- if (res == S_OK)
- {
- m_Database.FillSortAndShrink();
- if (!m_Database.Check())
- res = S_FALSE;
- }
- }
- catch(...)
- {
- res = S_FALSE;
- }
- if (res != S_OK)
- {
- Close();
- return res;
- }
- COM_TRY_END
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Close()
-{
- m_Database.Clear();
- return S_OK;
-}
-
-class CFolderOutStream:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-private:
- const CMvDatabaseEx *m_Database;
- const CRecordVector<bool> *m_ExtractStatuses;
-
- Byte *TempBuf;
- UInt32 TempBufSize;
- int NumIdenticalFiles;
- bool TempBufMode;
- UInt32 m_BufStartFolderOffset;
-
- int m_StartIndex;
- int m_CurrentIndex;
- CMyComPtr<IArchiveExtractCallback> m_ExtractCallback;
- bool m_TestMode;
-
- CMyComPtr<ISequentialOutStream> m_RealOutStream;
-
- bool m_IsOk;
- bool m_FileIsOpen;
- UInt32 m_RemainFileSize;
- UInt64 m_FolderSize;
- UInt64 m_PosInFolder;
-
- void FreeTempBuf()
- {
- ::MyFree(TempBuf);
- TempBuf = NULL;
- }
-
- HRESULT OpenFile();
- HRESULT CloseFileWithResOp(Int32 resOp);
- HRESULT CloseFile();
- HRESULT Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK);
-public:
- HRESULT WriteEmptyFiles();
-
- CFolderOutStream(): TempBuf(NULL) {}
- ~CFolderOutStream() { FreeTempBuf(); }
- void Init(
- const CMvDatabaseEx *database,
- const CRecordVector<bool> *extractStatuses,
- int startIndex,
- UInt64 folderSize,
- IArchiveExtractCallback *extractCallback,
- bool testMode);
- HRESULT FlushCorrupted();
- HRESULT Unsupported();
-
- UInt64 GetRemain() const { return m_FolderSize - m_PosInFolder; }
- UInt64 GetPosInFolder() const { return m_PosInFolder; }
-};
-
-void CFolderOutStream::Init(
- const CMvDatabaseEx *database,
- const CRecordVector<bool> *extractStatuses,
- int startIndex,
- UInt64 folderSize,
- IArchiveExtractCallback *extractCallback,
- bool testMode)
-{
- m_Database = database;
- m_ExtractStatuses = extractStatuses;
- m_StartIndex = startIndex;
- m_FolderSize = folderSize;
-
- m_ExtractCallback = extractCallback;
- m_TestMode = testMode;
-
- m_CurrentIndex = 0;
- m_PosInFolder = 0;
- m_FileIsOpen = false;
- m_IsOk = true;
- TempBufMode = false;
- NumIdenticalFiles = 0;
-}
-
-HRESULT CFolderOutStream::CloseFileWithResOp(Int32 resOp)
-{
- m_RealOutStream.Release();
- m_FileIsOpen = false;
- NumIdenticalFiles--;
- return m_ExtractCallback->SetOperationResult(resOp);
-}
-
-HRESULT CFolderOutStream::CloseFile()
-{
- return CloseFileWithResOp(m_IsOk ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError);
-}
-
-HRESULT CFolderOutStream::OpenFile()
-{
- if (NumIdenticalFiles == 0)
- {
- const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
- const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
- int numExtractItems = 0;
- int curIndex;
- for (curIndex = m_CurrentIndex; curIndex < m_ExtractStatuses->Size(); curIndex++)
- {
- const CMvItem &mvItem2 = m_Database->Items[m_StartIndex + curIndex];
- const CItem &item2 = m_Database->Volumes[mvItem2.VolumeIndex].Items[mvItem2.ItemIndex];
- if (item.Offset != item2.Offset ||
- item.Size != item2.Size ||
- item.Size == 0)
- break;
- if (!m_TestMode && (*m_ExtractStatuses)[curIndex])
- numExtractItems++;
- }
- NumIdenticalFiles = (curIndex - m_CurrentIndex);
- if (NumIdenticalFiles == 0)
- NumIdenticalFiles = 1;
- TempBufMode = false;
- if (numExtractItems > 1)
- {
- if (!TempBuf || item.Size > TempBufSize)
- {
- FreeTempBuf();
- TempBuf = (Byte *)MyAlloc(item.Size);
- TempBufSize = item.Size;
- if (TempBuf == NULL)
- return E_OUTOFMEMORY;
- }
- TempBufMode = true;
- m_BufStartFolderOffset = item.Offset;
- }
- else if (numExtractItems == 1)
- {
- while (NumIdenticalFiles && !(*m_ExtractStatuses)[m_CurrentIndex])
- {
- CMyComPtr<ISequentialOutStream> stream;
- RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &stream, NExtract::NAskMode::kSkip));
- if (stream)
- return E_FAIL;
- RINOK(m_ExtractCallback->PrepareOperation(NExtract::NAskMode::kSkip));
- m_CurrentIndex++;
- m_FileIsOpen = true;
- CloseFile();
- }
- }
- }
-
- Int32 askMode = (*m_ExtractStatuses)[m_CurrentIndex] ? (m_TestMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract) :
- NExtract::NAskMode::kSkip;
- RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &m_RealOutStream, askMode));
- if (!m_RealOutStream && !m_TestMode)
- askMode = NExtract::NAskMode::kSkip;
- return m_ExtractCallback->PrepareOperation(askMode);
-}
-
-HRESULT CFolderOutStream::WriteEmptyFiles()
-{
- if (m_FileIsOpen)
- return S_OK;
- for (; m_CurrentIndex < m_ExtractStatuses->Size(); m_CurrentIndex++)
- {
- const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
- const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
- UInt64 fileSize = item.Size;
- if (fileSize != 0)
- return S_OK;
- HRESULT result = OpenFile();
- m_RealOutStream.Release();
- RINOK(result);
- RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- }
- return S_OK;
-}
-
-// This is Write function
-HRESULT CFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK)
-{
- COM_TRY_BEGIN
- UInt32 realProcessed = 0;
- if (processedSize != NULL)
- *processedSize = 0;
- while (size != 0)
- {
- if (m_FileIsOpen)
- {
- UInt32 numBytesToWrite = MyMin(m_RemainFileSize, size);
- HRESULT res = S_OK;
- if (numBytesToWrite > 0)
- {
- if (!isOK)
- m_IsOk = false;
- if (m_RealOutStream)
- {
- UInt32 processedSizeLocal = 0;
- res = m_RealOutStream->Write((const Byte *)data, numBytesToWrite, &processedSizeLocal);
- numBytesToWrite = processedSizeLocal;
- }
- if (TempBufMode && TempBuf)
- memcpy(TempBuf + (m_PosInFolder - m_BufStartFolderOffset), data, numBytesToWrite);
- }
- realProcessed += numBytesToWrite;
- if (processedSize != NULL)
- *processedSize = realProcessed;
- data = (const void *)((const Byte *)data + numBytesToWrite);
- size -= numBytesToWrite;
- m_RemainFileSize -= numBytesToWrite;
- m_PosInFolder += numBytesToWrite;
- if (res != S_OK)
- return res;
- if (m_RemainFileSize == 0)
- {
- RINOK(CloseFile());
-
- while (NumIdenticalFiles)
- {
- HRESULT result = OpenFile();
- m_FileIsOpen = true;
- m_CurrentIndex++;
- if (result == S_OK && m_RealOutStream && TempBuf)
- result = WriteStream(m_RealOutStream, TempBuf, (size_t)(m_PosInFolder - m_BufStartFolderOffset));
-
- if (!TempBuf && TempBufMode && m_RealOutStream)
- {
- RINOK(CloseFileWithResOp(NExtract::NOperationResult::kUnSupportedMethod));
- }
- else
- {
- RINOK(CloseFile());
- }
- RINOK(result);
- }
- TempBufMode = false;
- }
- if (realProcessed > 0)
- break; // with this break this function works as Write-Part
- }
- else
- {
- if (m_CurrentIndex >= m_ExtractStatuses->Size())
- return E_FAIL;
-
- const CMvItem &mvItem = m_Database->Items[m_StartIndex + m_CurrentIndex];
- const CItem &item = m_Database->Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
-
- m_RemainFileSize = item.Size;
-
- UInt32 fileOffset = item.Offset;
- if (fileOffset < m_PosInFolder)
- return E_FAIL;
- if (fileOffset > m_PosInFolder)
- {
- UInt32 numBytesToWrite = MyMin(fileOffset - (UInt32)m_PosInFolder, size);
- realProcessed += numBytesToWrite;
- if (processedSize != NULL)
- *processedSize = realProcessed;
- data = (const void *)((const Byte *)data + numBytesToWrite);
- size -= numBytesToWrite;
- m_PosInFolder += numBytesToWrite;
- }
- if (fileOffset == m_PosInFolder)
- {
- RINOK(OpenFile());
- m_FileIsOpen = true;
- m_CurrentIndex++;
- m_IsOk = true;
- }
- }
- }
- return WriteEmptyFiles();
- COM_TRY_END
-}
-
-STDMETHODIMP CFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- return Write2(data, size, processedSize, true);
-}
-
-HRESULT CFolderOutStream::FlushCorrupted()
-{
- const UInt32 kBufferSize = (1 << 10);
- Byte buffer[kBufferSize];
- for (int i = 0; i < kBufferSize; i++)
- buffer[i] = 0;
- for (;;)
- {
- UInt64 remain = GetRemain();
- if (remain == 0)
- return S_OK;
- UInt32 size = (UInt32)MyMin(remain, (UInt64)kBufferSize);
- UInt32 processedSizeLocal = 0;
- RINOK(Write2(buffer, size, &processedSizeLocal, false));
- }
-}
-
-HRESULT CFolderOutStream::Unsupported()
-{
- while(m_CurrentIndex < m_ExtractStatuses->Size())
- {
- HRESULT result = OpenFile();
- if (result != S_FALSE && result != S_OK)
- return result;
- m_RealOutStream.Release();
- RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
- m_CurrentIndex++;
- }
- return S_OK;
-}
-
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = m_Database.Items.Size();
- if(numItems == 0)
- return S_OK;
- bool testMode = (testModeSpec != 0);
- UInt64 totalUnPacked = 0;
-
- UInt32 i;
- int lastFolder = -2;
- UInt64 lastFolderSize = 0;
- for(i = 0; i < numItems; i++)
- {
- int index = allFilesMode ? i : indices[i];
- const CMvItem &mvItem = m_Database.Items[index];
- const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
- if (item.IsDir())
- continue;
- int folderIndex = m_Database.GetFolderIndex(&mvItem);
- if (folderIndex != lastFolder)
- totalUnPacked += lastFolderSize;
- lastFolder = folderIndex;
- lastFolderSize = item.GetEndOffset();
- }
- totalUnPacked += lastFolderSize;
-
- extractCallback->SetTotal(totalUnPacked);
-
- totalUnPacked = 0;
-
- UInt64 totalPacked = 0;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- NCompress::NDeflate::NDecoder::CCOMCoder *deflateDecoderSpec = NULL;
- CMyComPtr<ICompressCoder> deflateDecoder;
-
- NCompress::NLzx::CDecoder *lzxDecoderSpec = NULL;
- CMyComPtr<ICompressCoder> lzxDecoder;
-
- NCompress::NQuantum::CDecoder *quantumDecoderSpec = NULL;
- CMyComPtr<ICompressCoder> quantumDecoder;
-
- CCabBlockInStream *cabBlockInStreamSpec = new CCabBlockInStream();
- CMyComPtr<ISequentialInStream> cabBlockInStream = cabBlockInStreamSpec;
- if (!cabBlockInStreamSpec->Create())
- return E_OUTOFMEMORY;
-
- CRecordVector<bool> extractStatuses;
- for(i = 0; i < numItems;)
- {
- int index = allFilesMode ? i : indices[i];
-
- const CMvItem &mvItem = m_Database.Items[index];
- const CDatabaseEx &db = m_Database.Volumes[mvItem.VolumeIndex];
- int itemIndex = mvItem.ItemIndex;
- const CItem &item = db.Items[itemIndex];
-
- i++;
- if (item.IsDir())
- {
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- CMyComPtr<ISequentialOutStream> realOutStream;
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- RINOK(extractCallback->PrepareOperation(askMode));
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- int folderIndex = m_Database.GetFolderIndex(&mvItem);
- if (folderIndex < 0)
- {
- // If we need previous archive
- Int32 askMode= testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- CMyComPtr<ISequentialOutStream> realOutStream;
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- RINOK(extractCallback->PrepareOperation(askMode));
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kDataError));
- continue;
- }
- int startIndex2 = m_Database.FolderStartFileIndex[folderIndex];
- int startIndex = startIndex2;
- extractStatuses.Clear();
- for (; startIndex < index; startIndex++)
- extractStatuses.Add(false);
- extractStatuses.Add(true);
- startIndex++;
- UInt64 curUnpack = item.GetEndOffset();
- for(;i < numItems; i++)
- {
- int indexNext = allFilesMode ? i : indices[i];
- const CMvItem &mvItem = m_Database.Items[indexNext];
- const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
- if (item.IsDir())
- continue;
- int newFolderIndex = m_Database.GetFolderIndex(&mvItem);
-
- if (newFolderIndex != folderIndex)
- break;
- for (; startIndex < indexNext; startIndex++)
- extractStatuses.Add(false);
- extractStatuses.Add(true);
- startIndex++;
- curUnpack = item.GetEndOffset();
- }
-
- lps->OutSize = totalUnPacked;
- lps->InSize = totalPacked;
- RINOK(lps->SetCur());
-
- CFolderOutStream *cabFolderOutStream = new CFolderOutStream;
- CMyComPtr<ISequentialOutStream> outStream(cabFolderOutStream);
-
- const CFolder &folder = db.Folders[item.GetFolderIndex(db.Folders.Size())];
-
- cabFolderOutStream->Init(&m_Database, &extractStatuses, startIndex2,
- curUnpack, extractCallback, testMode);
-
- cabBlockInStreamSpec->MsZip = false;
- switch(folder.GetCompressionMethod())
- {
- case NHeader::NCompressionMethodMajor::kNone:
- break;
- case NHeader::NCompressionMethodMajor::kMSZip:
- if(deflateDecoderSpec == NULL)
- {
- deflateDecoderSpec = new NCompress::NDeflate::NDecoder::CCOMCoder;
- deflateDecoder = deflateDecoderSpec;
- }
- cabBlockInStreamSpec->MsZip = true;
- break;
- case NHeader::NCompressionMethodMajor::kLZX:
- if(lzxDecoderSpec == NULL)
- {
- lzxDecoderSpec = new NCompress::NLzx::CDecoder;
- lzxDecoder = lzxDecoderSpec;
- }
- RINOK(lzxDecoderSpec->SetParams(folder.CompressionTypeMinor));
- break;
- case NHeader::NCompressionMethodMajor::kQuantum:
- if(quantumDecoderSpec == NULL)
- {
- quantumDecoderSpec = new NCompress::NQuantum::CDecoder;
- quantumDecoder = quantumDecoderSpec;
- }
- quantumDecoderSpec->SetParams(folder.CompressionTypeMinor);
- break;
- default:
- {
- RINOK(cabFolderOutStream->Unsupported());
- totalUnPacked += curUnpack;
- continue;
- }
- }
-
- cabBlockInStreamSpec->InitForNewFolder();
-
- HRESULT res = S_OK;
-
- {
- int volIndex = mvItem.VolumeIndex;
- int locFolderIndex = item.GetFolderIndex(db.Folders.Size());
- bool keepHistory = false;
- bool keepInputBuffer = false;
- for (UInt32 f = 0; cabFolderOutStream->GetRemain() != 0;)
- {
- if (volIndex >= m_Database.Volumes.Size())
- {
- res = S_FALSE;
- break;
- }
-
- const CDatabaseEx &db = m_Database.Volumes[volIndex];
- const CFolder &folder = db.Folders[locFolderIndex];
- if (f == 0)
- {
- cabBlockInStreamSpec->SetStream(db.Stream);
- cabBlockInStreamSpec->ReservedSize = db.ArchiveInfo.GetDataBlockReserveSize();
- RINOK(db.Stream->Seek(db.StartPosition + folder.DataStart, STREAM_SEEK_SET, NULL));
- }
- if (f == folder.NumDataBlocks)
- {
- volIndex++;
- locFolderIndex = 0;
- f = 0;
- continue;
- }
- f++;
-
- cabBlockInStreamSpec->DataError = false;
-
- if (!keepInputBuffer)
- cabBlockInStreamSpec->InitForNewBlock();
-
- UInt32 packSize, unpackSize;
- res = cabBlockInStreamSpec->PreRead(packSize, unpackSize);
- if (res == S_FALSE)
- break;
- RINOK(res);
- keepInputBuffer = (unpackSize == 0);
- if (keepInputBuffer)
- continue;
-
- UInt64 totalUnPacked2 = totalUnPacked + cabFolderOutStream->GetPosInFolder();
- totalPacked += packSize;
-
- lps->OutSize = totalUnPacked2;
- lps->InSize = totalPacked;
- RINOK(lps->SetCur());
-
- UInt64 unpackRemain = cabFolderOutStream->GetRemain();
-
- const UInt32 kBlockSizeMax = (1 << 15);
- if (unpackRemain > kBlockSizeMax)
- unpackRemain = kBlockSizeMax;
- if (unpackRemain > unpackSize)
- unpackRemain = unpackSize;
-
- switch(folder.GetCompressionMethod())
- {
- case NHeader::NCompressionMethodMajor::kNone:
- res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
- break;
- case NHeader::NCompressionMethodMajor::kMSZip:
- deflateDecoderSpec->SetKeepHistory(keepHistory);
- res = deflateDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
- break;
- case NHeader::NCompressionMethodMajor::kLZX:
- lzxDecoderSpec->SetKeepHistory(keepHistory);
- res = lzxDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
- break;
- case NHeader::NCompressionMethodMajor::kQuantum:
- quantumDecoderSpec->SetKeepHistory(keepHistory);
- res = quantumDecoder->Code(cabBlockInStream, outStream, NULL, &unpackRemain, NULL);
- break;
- }
- if (res != S_OK)
- {
- if (res != S_FALSE)
- RINOK(res);
- break;
- }
- keepHistory = true;
- }
- if (res == S_OK)
- {
- RINOK(cabFolderOutStream->WriteEmptyFiles());
- }
- }
- if (res != S_OK || cabFolderOutStream->GetRemain() != 0)
- {
- RINOK(cabFolderOutStream->FlushCorrupted());
- }
- totalUnPacked += curUnpack;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = m_Database.Items.Size();
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.h
deleted file mode 100644
index 1edcd11e2..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHandler.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// CabHandler.h
-
-#ifndef __CAB_HANDLER_H
-#define __CAB_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-#include "CabIn.h"
-
-namespace NArchive {
-namespace NCab {
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP1(IInArchive)
-
- INTERFACE_IInArchive(;)
-
-private:
- CMvDatabaseEx m_Database;
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.cpp
deleted file mode 100644
index 0cba1b0b7..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// CabHeader.cpp
-
-#include "StdAfx.h"
-
-#include "CabHeader.h"
-
-namespace NArchive {
-namespace NCab {
-namespace NHeader {
-
-Byte kMarker[kMarkerSize] = {'M', 'S', 'C', 'F', 0, 0, 0, 0 };
-
-// struct CSignatureInitializer { CSignatureInitializer() { kMarker[0]--; }; } g_SignatureInitializer;
-
-}}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.h b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.h
deleted file mode 100644
index 0f0d2af35..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabHeader.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Archive/Cab/Header.h
-
-#ifndef __ARCHIVE_CAB_HEADER_H
-#define __ARCHIVE_CAB_HEADER_H
-
-#include "Common/Types.h"
-
-namespace NArchive {
-namespace NCab {
-namespace NHeader {
-
-const unsigned kMarkerSize = 8;
-extern Byte kMarker[kMarkerSize];
-
-namespace NArchive
-{
- namespace NFlags
- {
- const int kPrevCabinet = 0x0001;
- const int kNextCabinet = 0x0002;
- const int kReservePresent = 0x0004;
- }
-}
-
-namespace NCompressionMethodMajor
-{
- const Byte kNone = 0;
- const Byte kMSZip = 1;
- const Byte kQuantum = 2;
- const Byte kLZX = 3;
-}
-
-const int kFileNameIsUTFAttributeMask = 0x80;
-
-namespace NFolderIndex
-{
- const int kContinuedFromPrev = 0xFFFD;
- const int kContinuedToNext = 0xFFFE;
- const int kContinuedPrevAndNext = 0xFFFF;
-}
-
-}}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.cpp
deleted file mode 100644
index c0bffa2d2..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-// Archive/CabIn.cpp
-
-#include "StdAfx.h"
-
-#include "../Common/FindSignature.h"
-
-#include "CabIn.h"
-
-namespace NArchive {
-namespace NCab {
-
-Byte CInArchive::Read8()
-{
- Byte b;
- if (!inBuffer.ReadByte(b))
- throw CInArchiveException(CInArchiveException::kUnsupported);
- return b;
-}
-
-UInt16 CInArchive::Read16()
-{
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- {
- Byte b = Read8();
- value |= (UInt16(b) << (8 * i));
- }
- return value;
-}
-
-UInt32 CInArchive::Read32()
-{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- {
- Byte b = Read8();
- value |= (UInt32(b) << (8 * i));
- }
- return value;
-}
-
-AString CInArchive::SafeReadName()
-{
- AString name;
- for (;;)
- {
- Byte b = Read8();
- if (b == 0)
- return name;
- name += (char)b;
- }
-}
-
-void CInArchive::ReadOtherArchive(COtherArchive &oa)
-{
- oa.FileName = SafeReadName();
- oa.DiskName = SafeReadName();
-}
-
-void CInArchive::Skip(UInt32 size)
-{
- while (size-- != 0)
- Read8();
-}
-
-HRESULT CInArchive::Open(const UInt64 *searchHeaderSizeLimit, CDatabaseEx &db)
-{
- IInStream *stream = db.Stream;
- db.Clear();
- RINOK(stream->Seek(0, STREAM_SEEK_SET, &db.StartPosition));
-
- RINOK(FindSignatureInStream(stream, NHeader::kMarker, NHeader::kMarkerSize,
- searchHeaderSizeLimit, db.StartPosition));
-
- RINOK(stream->Seek(db.StartPosition + NHeader::kMarkerSize, STREAM_SEEK_SET, NULL));
- if (!inBuffer.Create(1 << 17))
- return E_OUTOFMEMORY;
- inBuffer.SetStream(stream);
- inBuffer.Init();
-
- CInArchiveInfo &ai = db.ArchiveInfo;
-
- ai.Size = Read32();
- if (Read32() != 0)
- return S_FALSE;
- ai.FileHeadersOffset = Read32();
- if (Read32() != 0)
- return S_FALSE;
-
- ai.VersionMinor = Read8();
- ai.VersionMajor = Read8();
- ai.NumFolders = Read16();
- ai.NumFiles = Read16();
- ai.Flags = Read16();
- if (ai.Flags > 7)
- return S_FALSE;
- ai.SetID = Read16();
- ai.CabinetNumber = Read16();
-
- if (ai.ReserveBlockPresent())
- {
- ai.PerCabinetAreaSize = Read16();
- ai.PerFolderAreaSize = Read8();
- ai.PerDataBlockAreaSize = Read8();
-
- Skip(ai.PerCabinetAreaSize);
- }
-
- {
- if (ai.IsTherePrev())
- ReadOtherArchive(ai.PrevArc);
- if (ai.IsThereNext())
- ReadOtherArchive(ai.NextArc);
- }
-
- int i;
- for (i = 0; i < ai.NumFolders; i++)
- {
- CFolder folder;
-
- folder.DataStart = Read32();
- folder.NumDataBlocks = Read16();
- folder.CompressionTypeMajor = Read8();
- folder.CompressionTypeMinor = Read8();
-
- Skip(ai.PerFolderAreaSize);
- db.Folders.Add(folder);
- }
-
- RINOK(stream->Seek(db.StartPosition + ai.FileHeadersOffset, STREAM_SEEK_SET, NULL));
-
- inBuffer.SetStream(stream);
- inBuffer.Init();
- for (i = 0; i < ai.NumFiles; i++)
- {
- CItem item;
- item.Size = Read32();
- item.Offset = Read32();
- item.FolderIndex = Read16();
- UInt16 pureDate = Read16();
- UInt16 pureTime = Read16();
- item.Time = ((UInt32(pureDate) << 16)) | pureTime;
- item.Attributes = Read16();
- item.Name = SafeReadName();
- int folderIndex = item.GetFolderIndex(db.Folders.Size());
- if (folderIndex >= db.Folders.Size())
- return S_FALSE;
- db.Items.Add(item);
- }
- return S_OK;
-}
-
-#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
-
-static int CompareMvItems(const CMvItem *p1, const CMvItem *p2, void *param)
-{
- const CMvDatabaseEx &mvDb = *(const CMvDatabaseEx *)param;
- const CDatabaseEx &db1 = mvDb.Volumes[p1->VolumeIndex];
- const CDatabaseEx &db2 = mvDb.Volumes[p2->VolumeIndex];
- const CItem &item1 = db1.Items[p1->ItemIndex];
- const CItem &item2 = db2.Items[p2->ItemIndex];;
- bool isDir1 = item1.IsDir();
- bool isDir2 = item2.IsDir();
- if (isDir1 && !isDir2)
- return -1;
- if (isDir2 && !isDir1)
- return 1;
- int f1 = mvDb.GetFolderIndex(p1);
- int f2 = mvDb.GetFolderIndex(p2);
- RINOZ(MyCompare(f1, f2));
- RINOZ(MyCompare(item1.Offset, item2.Offset));
- RINOZ(MyCompare(item1.Size, item2.Size));
- RINOZ(MyCompare(p1->VolumeIndex, p2->VolumeIndex));
- return MyCompare(p1->ItemIndex, p2->ItemIndex);
-}
-
-bool CMvDatabaseEx::AreItemsEqual(int i1, int i2)
-{
- const CMvItem *p1 = &Items[i1];
- const CMvItem *p2 = &Items[i2];
- const CDatabaseEx &db1 = Volumes[p1->VolumeIndex];
- const CDatabaseEx &db2 = Volumes[p2->VolumeIndex];
- const CItem &item1 = db1.Items[p1->ItemIndex];
- const CItem &item2 = db2.Items[p2->ItemIndex];;
- return GetFolderIndex(p1) == GetFolderIndex(p2) &&
- item1.Offset == item2.Offset &&
- item1.Size == item2.Size &&
- item1.Name == item2.Name;
-}
-
-void CMvDatabaseEx::FillSortAndShrink()
-{
- Items.Clear();
- StartFolderOfVol.Clear();
- FolderStartFileIndex.Clear();
- int offset = 0;
- for (int v = 0; v < Volumes.Size(); v++)
- {
- const CDatabaseEx &db = Volumes[v];
- int curOffset = offset;
- if (db.IsTherePrevFolder())
- curOffset--;
- StartFolderOfVol.Add(curOffset);
- offset += db.GetNumberOfNewFolders();
-
- CMvItem mvItem;
- mvItem.VolumeIndex = v;
- for (int i = 0 ; i < db.Items.Size(); i++)
- {
- mvItem.ItemIndex = i;
- Items.Add(mvItem);
- }
- }
-
- Items.Sort(CompareMvItems, (void *)this);
- int j = 1;
- int i;
- for (i = 1; i < Items.Size(); i++)
- if (!AreItemsEqual(i, i -1))
- Items[j++] = Items[i];
- Items.DeleteFrom(j);
-
- for (i = 0; i < Items.Size(); i++)
- {
- int folderIndex = GetFolderIndex(&Items[i]);
- if (folderIndex >= FolderStartFileIndex.Size())
- FolderStartFileIndex.Add(i);
- }
-}
-
-bool CMvDatabaseEx::Check()
-{
- for (int v = 1; v < Volumes.Size(); v++)
- {
- const CDatabaseEx &db1 = Volumes[v];
- if (db1.IsTherePrevFolder())
- {
- const CDatabaseEx &db0 = Volumes[v - 1];
- if (db0.Folders.IsEmpty() || db1.Folders.IsEmpty())
- return false;
- const CFolder &f0 = db0.Folders.Back();
- const CFolder &f1 = db1.Folders.Front();
- if (f0.CompressionTypeMajor != f1.CompressionTypeMajor ||
- f0.CompressionTypeMinor != f1.CompressionTypeMinor)
- return false;
- }
- }
- UInt32 beginPos = 0;
- UInt64 endPos = 0;
- int prevFolder = -2;
- for (int i = 0; i < Items.Size(); i++)
- {
- const CMvItem &mvItem = Items[i];
- int fIndex = GetFolderIndex(&mvItem);
- if (fIndex >= FolderStartFileIndex.Size())
- return false;
- const CItem &item = Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
- if (item.IsDir())
- continue;
- int folderIndex = GetFolderIndex(&mvItem);
- if (folderIndex != prevFolder)
- prevFolder = folderIndex;
- else if (item.Offset < endPos &&
- (item.Offset != beginPos || item.GetEndOffset() != endPos))
- return false;
- beginPos = item.Offset;
- endPos = item.GetEndOffset();
- }
- return true;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.h b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.h
deleted file mode 100644
index 1e9b188b5..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabIn.h
+++ /dev/null
@@ -1,161 +0,0 @@
-// Archive/CabIn.h
-
-#ifndef __ARCHIVE_CAB_IN_H
-#define __ARCHIVE_CAB_IN_H
-
-#include "../../IStream.h"
-#include "../../Common/InBuffer.h"
-#include "CabHeader.h"
-#include "CabItem.h"
-
-namespace NArchive {
-namespace NCab {
-
-class CInArchiveException
-{
-public:
- enum CCauseType
- {
- kUnexpectedEndOfArchive = 0,
- kIncorrectArchive,
- kUnsupported
- } Cause;
- CInArchiveException(CCauseType cause) : Cause(cause) {}
-};
-
-struct COtherArchive
-{
- AString FileName;
- AString DiskName;
-};
-
-struct CArchiveInfo
-{
- Byte VersionMinor; /* cabinet file format version, minor */
- Byte VersionMajor; /* cabinet file format version, major */
- UInt16 NumFolders; /* number of CFFOLDER entries in this cabinet */
- UInt16 NumFiles; /* number of CFFILE entries in this cabinet */
- UInt16 Flags; /* cabinet file option indicators */
- UInt16 SetID; /* must be the same for all cabinets in a set */
- UInt16 CabinetNumber; /* number of this cabinet file in a set */
-
- bool ReserveBlockPresent() const { return (Flags & NHeader::NArchive::NFlags::kReservePresent) != 0; }
-
- bool IsTherePrev() const { return (Flags & NHeader::NArchive::NFlags::kPrevCabinet) != 0; }
- bool IsThereNext() const { return (Flags & NHeader::NArchive::NFlags::kNextCabinet) != 0; }
-
- UInt16 PerCabinetAreaSize; // (optional) size of per-cabinet reserved area
- Byte PerFolderAreaSize; // (optional) size of per-folder reserved area
- Byte PerDataBlockAreaSize; // (optional) size of per-datablock reserved area
-
- Byte GetDataBlockReserveSize() const { return (Byte)(ReserveBlockPresent() ? PerDataBlockAreaSize : 0); }
-
- COtherArchive PrevArc;
- COtherArchive NextArc;
-
- CArchiveInfo()
- {
- Clear();
- }
-
- void Clear()
- {
- PerCabinetAreaSize = 0;
- PerFolderAreaSize = 0;
- PerDataBlockAreaSize = 0;
- }
-};
-
-struct CInArchiveInfo: public CArchiveInfo
-{
- UInt32 Size; /* size of this cabinet file in bytes */
- UInt32 FileHeadersOffset; // offset of the first CFFILE entry
-};
-
-
-struct CDatabase
-{
- UInt64 StartPosition;
- CInArchiveInfo ArchiveInfo;
- CObjectVector<CFolder> Folders;
- CObjectVector<CItem> Items;
-
- void Clear()
- {
- ArchiveInfo.Clear();
- Folders.Clear();
- Items.Clear();
- }
- bool IsTherePrevFolder() const
- {
- for (int i = 0; i < Items.Size(); i++)
- if (Items[i].ContinuedFromPrev())
- return true;
- return false;
- }
- int GetNumberOfNewFolders() const
- {
- int res = Folders.Size();
- if (IsTherePrevFolder())
- res--;
- return res;
- }
- UInt32 GetFileOffset(int index) const { return Items[index].Offset; }
- UInt32 GetFileSize(int index) const { return Items[index].Size; }
-};
-
-struct CDatabaseEx: public CDatabase
-{
- CMyComPtr<IInStream> Stream;
-};
-
-struct CMvItem
-{
- int VolumeIndex;
- int ItemIndex;
-};
-
-class CMvDatabaseEx
-{
- bool AreItemsEqual(int i1, int i2);
-public:
- CObjectVector<CDatabaseEx> Volumes;
- CRecordVector<CMvItem> Items;
- CRecordVector<int> StartFolderOfVol;
- CRecordVector<int> FolderStartFileIndex;
-
- int GetFolderIndex(const CMvItem *mvi) const
- {
- const CDatabaseEx &db = Volumes[mvi->VolumeIndex];
- return StartFolderOfVol[mvi->VolumeIndex] +
- db.Items[mvi->ItemIndex].GetFolderIndex(db.Folders.Size());
- }
- void Clear()
- {
- Volumes.Clear();
- Items.Clear();
- StartFolderOfVol.Clear();
- FolderStartFileIndex.Clear();
- }
- void FillSortAndShrink();
- bool Check();
-};
-
-class CInArchive
-{
- CInBuffer inBuffer;
-
- Byte Read8();
- UInt16 Read16();
- UInt32 Read32();
- AString SafeReadName();
- void Skip(UInt32 size);
- void ReadOtherArchive(COtherArchive &oa);
-
-public:
- HRESULT Open(const UInt64 *searchHeaderSizeLimit, CDatabaseEx &db);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabItem.h b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabItem.h
deleted file mode 100644
index 63a1e856c..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabItem.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Archive/CabItem.h
-
-#ifndef __ARCHIVE_CAB_ITEM_H
-#define __ARCHIVE_CAB_ITEM_H
-
-#include "Common/Types.h"
-#include "Common/MyString.h"
-#include "CabHeader.h"
-
-namespace NArchive {
-namespace NCab {
-
-struct CFolder
-{
- UInt32 DataStart; // offset of the first CFDATA block in this folder
- UInt16 NumDataBlocks; // number of CFDATA blocks in this folder
- Byte CompressionTypeMajor;
- Byte CompressionTypeMinor;
- Byte GetCompressionMethod() const { return (Byte)(CompressionTypeMajor & 0xF); }
-};
-
-struct CItem
-{
- AString Name;
- UInt32 Offset;
- UInt32 Size;
- UInt32 Time;
- UInt16 FolderIndex;
- UInt16 Flags;
- UInt16 Attributes;
-
- UInt64 GetEndOffset() const { return (UInt64)Offset + Size; }
- UInt32 GetWinAttributes() const { return (Attributes & ~NHeader::kFileNameIsUTFAttributeMask); }
- bool IsNameUTF() const { return (Attributes & NHeader::kFileNameIsUTFAttributeMask) != 0; }
- bool IsDir() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }
-
- bool ContinuedFromPrev() const
- {
- return
- (FolderIndex == NHeader::NFolderIndex::kContinuedFromPrev) ||
- (FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext);
- }
-
- bool ContinuedToNext() const
- {
- return
- (FolderIndex == NHeader::NFolderIndex::kContinuedToNext) ||
- (FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext);
- }
-
- int GetFolderIndex(int numFolders) const
- {
- if (ContinuedFromPrev())
- return 0;
- if (ContinuedToNext())
- return (numFolders - 1);
- return FolderIndex;
- }
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabRegister.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabRegister.cpp
deleted file mode 100644
index 15fe4099f..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/CabRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// CabRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "CabHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NCab::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Cab", L"cab", 0, 8, { 0x4D, 0x53, 0x43, 0x46 }, 4, false, CreateArc, 0 };
-
-REGISTER_ARC(Cab)
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Cab/StdAfx.h b/src/libs/7zip/win/CPP/7zip/Archive/Cab/StdAfx.h
deleted file mode 100644
index e7fb6986d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Cab/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.cpp
deleted file mode 100644
index a9e334b03..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.cpp
+++ /dev/null
@@ -1,721 +0,0 @@
-// ChmHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/Defs.h"
-#include "Common/StringConvert.h"
-#include "Common/UTFConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-#include "../../Compress/LzxDecoder.h"
-
-#include "../Common/ItemNameUtils.h"
-
-#include "ChmHandler.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-namespace NArchive {
-namespace NChm {
-
-// #define _CHM_DETAILS
-
-#ifdef _CHM_DETAILS
-
-enum
-{
- kpidSection = kpidUserDefined
-};
-
-#endif
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidBlock, VT_UI4}
-
- #ifdef _CHM_DETAILS
- ,
- { L"Section", kpidSection, VT_UI4},
- { NULL, kpidOffset, VT_UI4}
- #endif
-};
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidNumBlocks, VT_UI8}
-};
-
-IMP_IInArchive_Props
-
-IMP_IInArchive_ArcProps_NO
-/*
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidNumBlocks:
- {
- UInt64 numBlocks = 0;
- for (int i = 0; i < m_Database.Sections.Size(); i++)
- {
- const CSectionInfo &s = m_Database.Sections[i];
- for (int j = 0; j < s.Methods.Size(); j++)
- {
- const CMethodInfo &m = s.Methods[j];
- if (m.IsLzx())
- numBlocks += m.LzxInfo.ResetTable.GetNumBlocks();
- }
- }
- prop = numBlocks;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-*/
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- if (m_Database.NewFormat)
- {
- switch(propID)
- {
- case kpidSize:
- prop = (UInt64)m_Database.NewFormatString.Length();
- break;
- }
- prop.Detach(value);
- return S_OK;
- }
- int entryIndex;
- if (m_Database.LowLevel)
- entryIndex = index;
- else
- entryIndex = m_Database.Indices[index];
- const CItem &item = m_Database.Items[entryIndex];
- switch(propID)
- {
- case kpidPath:
- {
- UString us;
- if (ConvertUTF8ToUnicode(item.Name, us))
- {
- if (!m_Database.LowLevel)
- {
- if (us.Length() > 1)
- if (us[0] == L'/')
- us.Delete(0);
- }
- prop = NItemName::GetOSName2(us);
- }
- break;
- }
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize: prop = item.Size; break;
- case kpidMethod:
- {
- if (!item.IsDir())
- if (item.Section == 0)
- prop = L"Copy";
- else if (item.Section < m_Database.Sections.Size())
- prop = m_Database.Sections[(int)item.Section].GetMethodName();
- break;
- }
- case kpidBlock:
- if (m_Database.LowLevel)
- prop = item.Section;
- else if (item.Section != 0)
- prop = m_Database.GetFolder(index);
- break;
-
- #ifdef _CHM_DETAILS
-
- case kpidSection: prop = (UInt32)item.Section; break;
- case kpidOffset: prop = (UInt32)item.Offset; break;
-
- #endif
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-class CProgressImp: public CProgressVirt
-{
- CMyComPtr<IArchiveOpenCallback> _callback;
-public:
- STDMETHOD(SetTotal)(const UInt64 *numFiles);
- STDMETHOD(SetCompleted)(const UInt64 *numFiles);
- CProgressImp(IArchiveOpenCallback *callback): _callback(callback) {};
-};
-
-STDMETHODIMP CProgressImp::SetTotal(const UInt64 *numFiles)
-{
- if (_callback)
- return _callback->SetCompleted(numFiles, NULL);
- return S_OK;
-}
-
-STDMETHODIMP CProgressImp::SetCompleted(const UInt64 *numFiles)
-{
- if (_callback)
- return _callback->SetCompleted(numFiles, NULL);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 *maxCheckStartPosition,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- m_Stream.Release();
- try
- {
- CInArchive archive;
- // CProgressImp progressImp(openArchiveCallback);
- RINOK(archive.Open(inStream, maxCheckStartPosition, m_Database));
- /*
- if (m_Database.LowLevel)
- return S_FALSE;
- */
- m_Stream = inStream;
- }
- catch(...)
- {
- return S_FALSE;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- m_Database.Clear();
- m_Stream.Release();
- return S_OK;
-}
-
-class CChmFolderOutStream:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- HRESULT Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK);
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-
- UInt64 m_FolderSize;
- UInt64 m_PosInFolder;
- UInt64 m_PosInSection;
- const CRecordVector<bool> *m_ExtractStatuses;
- int m_StartIndex;
- int m_CurrentIndex;
- int m_NumFiles;
-
-private:
- const CFilesDatabase *m_Database;
- CMyComPtr<IArchiveExtractCallback> m_ExtractCallback;
- bool m_TestMode;
-
- bool m_IsOk;
- bool m_FileIsOpen;
- UInt64 m_RemainFileSize;
- CMyComPtr<ISequentialOutStream> m_RealOutStream;
-
- HRESULT OpenFile();
- HRESULT WriteEmptyFiles();
-public:
- void Init(
- const CFilesDatabase *database,
- IArchiveExtractCallback *extractCallback,
- bool testMode);
- HRESULT FlushCorrupted(UInt64 maxSize);
-};
-
-void CChmFolderOutStream::Init(
- const CFilesDatabase *database,
- IArchiveExtractCallback *extractCallback,
- bool testMode)
-{
- m_Database = database;
- m_ExtractCallback = extractCallback;
- m_TestMode = testMode;
-
- m_CurrentIndex = 0;
- m_FileIsOpen = false;
-}
-
-HRESULT CChmFolderOutStream::OpenFile()
-{
- Int32 askMode = (*m_ExtractStatuses)[m_CurrentIndex] ? (m_TestMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract) :
- NExtract::NAskMode::kSkip;
- m_RealOutStream.Release();
- RINOK(m_ExtractCallback->GetStream(m_StartIndex + m_CurrentIndex, &m_RealOutStream, askMode));
- if (!m_RealOutStream && !m_TestMode)
- askMode = NExtract::NAskMode::kSkip;
- return m_ExtractCallback->PrepareOperation(askMode);
-}
-
-HRESULT CChmFolderOutStream::WriteEmptyFiles()
-{
- if (m_FileIsOpen)
- return S_OK;
- for (;m_CurrentIndex < m_NumFiles; m_CurrentIndex++)
- {
- UInt64 fileSize = m_Database->GetFileSize(m_StartIndex + m_CurrentIndex);
- if (fileSize != 0)
- return S_OK;
- HRESULT result = OpenFile();
- m_RealOutStream.Release();
- RINOK(result);
- RINOK(m_ExtractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- }
- return S_OK;
-}
-
-// This is WritePart function
-HRESULT CChmFolderOutStream::Write2(const void *data, UInt32 size, UInt32 *processedSize, bool isOK)
-{
- UInt32 realProcessed = 0;
- if (processedSize != NULL)
- *processedSize = 0;
- while(size != 0)
- {
- if (m_FileIsOpen)
- {
- UInt32 numBytesToWrite = (UInt32)MyMin(m_RemainFileSize, (UInt64)(size));
- HRESULT res = S_OK;
- if (numBytesToWrite > 0)
- {
- if (!isOK)
- m_IsOk = false;
- if (m_RealOutStream)
- {
- UInt32 processedSizeLocal = 0;
- res = m_RealOutStream->Write((const Byte *)data, numBytesToWrite, &processedSizeLocal);
- numBytesToWrite = processedSizeLocal;
- }
- }
- realProcessed += numBytesToWrite;
- if (processedSize != NULL)
- *processedSize = realProcessed;
- data = (const void *)((const Byte *)data + numBytesToWrite);
- size -= numBytesToWrite;
- m_RemainFileSize -= numBytesToWrite;
- m_PosInSection += numBytesToWrite;
- m_PosInFolder += numBytesToWrite;
- if (res != S_OK)
- return res;
- if (m_RemainFileSize == 0)
- {
- m_RealOutStream.Release();
- RINOK(m_ExtractCallback->SetOperationResult(
- m_IsOk ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- m_FileIsOpen = false;
- }
- if (realProcessed > 0)
- break; // with this break this function works as write part
- }
- else
- {
- if (m_CurrentIndex >= m_NumFiles)
- return E_FAIL;
- int fullIndex = m_StartIndex + m_CurrentIndex;
- m_RemainFileSize = m_Database->GetFileSize(fullIndex);
- UInt64 fileOffset = m_Database->GetFileOffset(fullIndex);
- if (fileOffset < m_PosInSection)
- return E_FAIL;
- if (fileOffset > m_PosInSection)
- {
- UInt32 numBytesToWrite = (UInt32)MyMin(fileOffset - m_PosInSection, UInt64(size));
- realProcessed += numBytesToWrite;
- if (processedSize != NULL)
- *processedSize = realProcessed;
- data = (const void *)((const Byte *)data + numBytesToWrite);
- size -= numBytesToWrite;
- m_PosInSection += numBytesToWrite;
- m_PosInFolder += numBytesToWrite;
- }
- if (fileOffset == m_PosInSection)
- {
- RINOK(OpenFile());
- m_FileIsOpen = true;
- m_CurrentIndex++;
- m_IsOk = true;
- }
- }
- }
- return WriteEmptyFiles();
-}
-
-STDMETHODIMP CChmFolderOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- return Write2(data, size, processedSize, true);
-}
-
-HRESULT CChmFolderOutStream::FlushCorrupted(UInt64 maxSize)
-{
- const UInt32 kBufferSize = (1 << 10);
- Byte buffer[kBufferSize];
- for (int i = 0; i < kBufferSize; i++)
- buffer[i] = 0;
- if (maxSize > m_FolderSize)
- maxSize = m_FolderSize;
- while (m_PosInFolder < maxSize)
- {
- UInt32 size = (UInt32)MyMin(maxSize - m_PosInFolder, (UInt64)kBufferSize);
- UInt32 processedSizeLocal = 0;
- RINOK(Write2(buffer, size, &processedSizeLocal, false));
- if (processedSizeLocal == 0)
- return S_OK;
- }
- return S_OK;
-}
-
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
-
- if (allFilesMode)
- numItems = m_Database.NewFormat ? 1:
- (m_Database.LowLevel ?
- m_Database.Items.Size():
- m_Database.Indices.Size());
- if (numItems == 0)
- return S_OK;
- bool testMode = (testModeSpec != 0);
-
- UInt64 currentTotalSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
- UInt32 i;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(m_Stream);
-
- if (m_Database.LowLevel)
- {
- UInt64 currentItemSize = 0;
- UInt64 totalSize = 0;
- if (m_Database.NewFormat)
- totalSize = m_Database.NewFormatString.Length();
- else
- for (i = 0; i < numItems; i++)
- totalSize += m_Database.Items[allFilesMode ? i : indices[i]].Size;
- extractCallback->SetTotal(totalSize);
-
- for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
- {
- currentItemSize = 0;
- lps->InSize = currentTotalSize; // Change it
- lps->OutSize = currentTotalSize;
-
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode= testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- if (m_Database.NewFormat)
- {
- if (index != 0)
- return E_FAIL;
- if (!testMode && !realOutStream)
- continue;
- if (!testMode)
- {
- UInt32 size = m_Database.NewFormatString.Length();
- RINOK(WriteStream(realOutStream, (const char *)m_Database.NewFormatString, size));
- }
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- const CItem &item = m_Database.Items[index];
-
- currentItemSize = item.Size;
-
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- if (item.Section != 0)
- {
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
-
- if (testMode)
- {
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
-
- RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL));
- streamSpec->Init(item.Size);
-
- RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- }
- return S_OK;
- }
-
- UInt64 lastFolderIndex = ((UInt64)0 - 1);
- for (i = 0; i < numItems; i++)
- {
- UInt32 index = allFilesMode ? i : indices[i];
- int entryIndex = m_Database.Indices[index];
- const CItem &item = m_Database.Items[entryIndex];
- UInt64 sectionIndex = item.Section;
- if (item.IsDir() || item.Size == 0)
- continue;
- if (sectionIndex == 0)
- {
- currentTotalSize += item.Size;
- continue;
- }
- const CSectionInfo &section = m_Database.Sections[(int)item.Section];
- if (section.IsLzx())
- {
- const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
- UInt64 folderIndex = m_Database.GetFolder(index);
- if (lastFolderIndex == folderIndex)
- folderIndex++;
- lastFolderIndex = m_Database.GetLastFolder(index);
- for (; folderIndex <= lastFolderIndex; folderIndex++)
- currentTotalSize += lzxInfo.GetFolderSize();
- }
- }
-
- RINOK(extractCallback->SetTotal(currentTotalSize));
-
- NCompress::NLzx::CDecoder *lzxDecoderSpec = 0;
- CMyComPtr<ICompressCoder> lzxDecoder;
- CChmFolderOutStream *chmFolderOutStream = 0;
- CMyComPtr<ISequentialOutStream> outStream;
-
- currentTotalSize = 0;
-
- CRecordVector<bool> extractStatuses;
- for (i = 0; i < numItems;)
- {
- RINOK(extractCallback->SetCompleted(&currentTotalSize));
- UInt32 index = allFilesMode ? i : indices[i];
- i++;
- int entryIndex = m_Database.Indices[index];
- const CItem &item = m_Database.Items[entryIndex];
- UInt64 sectionIndex = item.Section;
- Int32 askMode= testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- if (item.IsDir())
- {
- CMyComPtr<ISequentialOutStream> realOutStream;
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- RINOK(extractCallback->PrepareOperation(askMode));
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
-
- lps->InSize = currentTotalSize; // Change it
- lps->OutSize = currentTotalSize;
-
- if (item.Size == 0 || sectionIndex == 0)
- {
- CMyComPtr<ISequentialOutStream> realOutStream;
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- Int32 opRes = NExtract::NOperationResult::kOK;
- if (!testMode && item.Size != 0)
- {
- RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL));
- streamSpec->Init(item.Size);
- RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
- if (copyCoderSpec->TotalSize != item.Size)
- opRes = NExtract::NOperationResult::kDataError;
- }
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult(opRes));
- currentTotalSize += item.Size;
- continue;
- }
-
- const CSectionInfo &section = m_Database.Sections[(int)sectionIndex];
-
- if (!section.IsLzx())
- {
- CMyComPtr<ISequentialOutStream> realOutStream;
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kUnSupportedMethod));
- continue;
- }
-
- const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
-
- if (chmFolderOutStream == 0)
- {
- chmFolderOutStream = new CChmFolderOutStream;
- outStream = chmFolderOutStream;
- }
-
- chmFolderOutStream->Init(&m_Database, extractCallback, testMode);
-
- if (lzxDecoderSpec == NULL)
- {
- lzxDecoderSpec = new NCompress::NLzx::CDecoder;
- lzxDecoder = lzxDecoderSpec;
- }
-
- UInt64 folderIndex = m_Database.GetFolder(index);
-
- UInt64 compressedPos = m_Database.ContentOffset + section.Offset;
- UInt32 numDictBits = lzxInfo.GetNumDictBits();
- RINOK(lzxDecoderSpec->SetParams(numDictBits));
-
- const CItem *lastItem = &item;
- extractStatuses.Clear();
- extractStatuses.Add(true);
-
- for (;; folderIndex++)
- {
- RINOK(extractCallback->SetCompleted(&currentTotalSize));
-
- UInt64 startPos = lzxInfo.GetFolderPos(folderIndex);
- UInt64 finishPos = lastItem->Offset + lastItem->Size;
- UInt64 limitFolderIndex = lzxInfo.GetFolder(finishPos);
-
- lastFolderIndex = m_Database.GetLastFolder(index);
- UInt64 folderSize = lzxInfo.GetFolderSize();
- UInt64 unPackSize = folderSize;
- if (extractStatuses.IsEmpty())
- chmFolderOutStream->m_StartIndex = index + 1;
- else
- chmFolderOutStream->m_StartIndex = index;
- if (limitFolderIndex == folderIndex)
- {
- for (; i < numItems; i++)
- {
- UInt32 nextIndex = allFilesMode ? i : indices[i];
- int entryIndex = m_Database.Indices[nextIndex];
- const CItem &nextItem = m_Database.Items[entryIndex];
- if (nextItem.Section != sectionIndex)
- break;
- UInt64 nextFolderIndex = m_Database.GetFolder(nextIndex);
- if (nextFolderIndex != folderIndex)
- break;
- for (index++; index < nextIndex; index++)
- extractStatuses.Add(false);
- extractStatuses.Add(true);
- index = nextIndex;
- lastItem = &nextItem;
- if (nextItem.Size != 0)
- finishPos = nextItem.Offset + nextItem.Size;
- lastFolderIndex = m_Database.GetLastFolder(index);
- }
- }
- unPackSize = MyMin(finishPos - startPos, unPackSize);
-
- chmFolderOutStream->m_FolderSize = folderSize;
- chmFolderOutStream->m_PosInFolder = 0;
- chmFolderOutStream->m_PosInSection = startPos;
- chmFolderOutStream->m_ExtractStatuses = &extractStatuses;
- chmFolderOutStream->m_NumFiles = extractStatuses.Size();
- chmFolderOutStream->m_CurrentIndex = 0;
- try
- {
- UInt64 startBlock = lzxInfo.GetBlockIndexFromFolderIndex(folderIndex);
- const CResetTable &rt = lzxInfo.ResetTable;
- UInt32 numBlocks = (UInt32)rt.GetNumBlocks(unPackSize);
- for (UInt32 b = 0; b < numBlocks; b++)
- {
- UInt64 completedSize = currentTotalSize + chmFolderOutStream->m_PosInSection - startPos;
- RINOK(extractCallback->SetCompleted(&completedSize));
- UInt64 bCur = startBlock + b;
- if (bCur >= rt.ResetOffsets.Size())
- return E_FAIL;
- UInt64 offset = rt.ResetOffsets[(int)bCur];
- UInt64 compressedSize;
- rt.GetCompressedSizeOfBlock(bCur, compressedSize);
- UInt64 rem = finishPos - chmFolderOutStream->m_PosInSection;
- if (rem > rt.BlockSize)
- rem = rt.BlockSize;
- RINOK(m_Stream->Seek(compressedPos + offset, STREAM_SEEK_SET, NULL));
- streamSpec->SetStream(m_Stream);
- streamSpec->Init(compressedSize);
- lzxDecoderSpec->SetKeepHistory(b > 0);
- HRESULT res = lzxDecoder->Code(inStream, outStream, NULL, &rem, NULL);
- if (res != S_OK)
- {
- if (res != S_FALSE)
- return res;
- throw 1;
- }
- }
- }
- catch(...)
- {
- RINOK(chmFolderOutStream->FlushCorrupted(unPackSize));
- }
- currentTotalSize += folderSize;
- if (folderIndex == lastFolderIndex)
- break;
- extractStatuses.Clear();
- }
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = m_Database.NewFormat ? 1:
- (m_Database.LowLevel ?
- m_Database.Items.Size():
- m_Database.Indices.Size());
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.h
deleted file mode 100644
index 440c50f11..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHandler.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// ChmHandler.h
-
-#ifndef __ARCHIVE_CHM_HANDLER_H
-#define __ARCHIVE_CHM_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-#include "ChmIn.h"
-
-namespace NArchive {
-namespace NChm {
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP1(IInArchive)
-
- INTERFACE_IInArchive(;)
-
-private:
- CFilesDatabase m_Database;
- CMyComPtr<IInStream> m_Stream;
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.cpp
deleted file mode 100644
index e8dc9f3e8..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Archive/Chm/Header.h
-
-#include "StdAfx.h"
-
-#include "ChmHeader.h"
-
-namespace NArchive{
-namespace NChm{
-namespace NHeader{
-
-UInt32 kItsfSignature = 0x46535449 + 1;
-UInt32 kItolSignature = 0x4C4F5449 + 1;
-static class CSignatureInitializer
-{
-public:
- CSignatureInitializer()
- {
- kItsfSignature--;
- kItolSignature--;
- }
-}g_SignatureInitializer;
-
-
-}}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.h b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.h
deleted file mode 100644
index 9f1bd42b6..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmHeader.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Archive/Chm/Header.h
-
-#ifndef __ARCHIVE_CHM_HEADER_H
-#define __ARCHIVE_CHM_HEADER_H
-
-#include "Common/Types.h"
-
-namespace NArchive {
-namespace NChm {
-namespace NHeader{
-
-const UInt32 kItspSignature = 0x50535449;
-const UInt32 kPmglSignature = 0x4C474D50;
-const UInt32 kLzxcSignature = 0x43585A4C;
-
-const UInt32 kIfcmSignature = 0x4D434649;
-const UInt32 kAollSignature = 0x4C4C4F41;
-const UInt32 kCaolSignature = 0x4C4F4143;
-
-extern UInt32 kItsfSignature;
-
-extern UInt32 kItolSignature;
-const UInt32 kItlsSignature = 0x534C5449;
-UInt64 inline GetHxsSignature() { return ((UInt64)kItlsSignature << 32) | kItolSignature; }
-
-}}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.cpp
deleted file mode 100644
index d52b9ba6c..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.cpp
+++ /dev/null
@@ -1,937 +0,0 @@
-// Archive/ChmIn.cpp
-
-#include "StdAfx.h"
-
-#include "Common/IntToString.h"
-#include "Common/UTFConvert.h"
-
-#include "../../Common/LimitedStreams.h"
-
-#include "ChmIn.h"
-
-namespace NArchive {
-namespace NChm {
-
-// define CHM_LOW, if you want to see low level items
-// #define CHM_LOW
-
-static const GUID kChmLzxGuid = { 0x7FC28940, 0x9D31, 0x11D0, { 0x9B, 0x27, 0x00, 0xA0, 0xC9, 0x1E, 0x9C, 0x7C } };
-static const GUID kHelp2LzxGuid = { 0x0A9007C6, 0x4076, 0x11D3, { 0x87, 0x89, 0x00, 0x00, 0xF8, 0x10, 0x57, 0x54 } };
-static const GUID kDesGuid = { 0x67F6E4A2, 0x60BF, 0x11D3, { 0x85, 0x40, 0x00, 0xC0, 0x4F, 0x58, 0xC3, 0xCF } };
-
-static bool AreGuidsEqual(REFGUID g1, REFGUID g2)
-{
- if (g1.Data1 != g2.Data1 ||
- g1.Data2 != g2.Data2 ||
- g1.Data3 != g2.Data3)
- return false;
- for (int i = 0; i < 8; i++)
- if (g1.Data4[i] != g2.Data4[i])
- return false;
- return true;
-}
-
-static char GetHex(Byte value)
-{
- return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10)));
-}
-
-static void PrintByte(Byte b, AString &s)
-{
- s += GetHex(b >> 4);
- s += GetHex(b & 0xF);
-}
-
-static void PrintUInt16(UInt16 v, AString &s)
-{
- PrintByte((Byte)(v >> 8), s);
- PrintByte((Byte)v, s);
-}
-
-static void PrintUInt32(UInt32 v, AString &s)
-{
- PrintUInt16((UInt16)(v >> 16), s);
- PrintUInt16((UInt16)v, s);
-}
-
-AString CMethodInfo::GetGuidString() const
-{
- AString s;
- s += '{';
- PrintUInt32(Guid.Data1, s);
- s += '-';
- PrintUInt16(Guid.Data2, s);
- s += '-';
- PrintUInt16(Guid.Data3, s);
- s += '-';
- PrintByte(Guid.Data4[0], s);
- PrintByte(Guid.Data4[1], s);
- s += '-';
- for (int i = 2; i < 8; i++)
- PrintByte(Guid.Data4[i], s);
- s += '}';
- return s;
-}
-
-bool CMethodInfo::IsLzx() const
-{
- if (AreGuidsEqual(Guid, kChmLzxGuid))
- return true;
- return AreGuidsEqual(Guid, kHelp2LzxGuid);
-}
-
-bool CMethodInfo::IsDes() const
-{
- return AreGuidsEqual(Guid, kDesGuid);
-}
-
-UString CMethodInfo::GetName() const
-{
- UString s;
- if (IsLzx())
- {
- s = L"LZX:";
- wchar_t temp[16];
- ConvertUInt32ToString(LzxInfo.GetNumDictBits(), temp);
- s += temp;
- }
- else
- {
- AString s2;
- if (IsDes())
- s2 = "DES";
- else
- {
- s2 = GetGuidString();
- if (ControlData.GetCapacity() > 0)
- {
- s2 += ':';
- for (size_t i = 0; i < ControlData.GetCapacity(); i++)
- PrintByte(ControlData[i], s2);
- }
- }
- ConvertUTF8ToUnicode(s2, s);
- }
- return s;
-}
-
-bool CSectionInfo::IsLzx() const
-{
- if (Methods.Size() != 1)
- return false;
- return Methods[0].IsLzx();
-}
-
-UString CSectionInfo::GetMethodName() const
-{
- UString s;
- if (!IsLzx())
- {
- UString temp;
- if (ConvertUTF8ToUnicode(Name, temp))
- s += temp;
- s += L": ";
- }
- for (int i = 0; i < Methods.Size(); i++)
- {
- if (i != 0)
- s += L' ';
- s += Methods[i].GetName();
- }
- return s;
-}
-
-Byte CInArchive::ReadByte()
-{
- Byte b;
- if (!_inBuffer.ReadByte(b))
- throw 1;
- return b;
-}
-
-void CInArchive::Skip(size_t size)
-{
- while (size-- != 0)
- ReadByte();
-}
-
-void CInArchive::ReadBytes(Byte *data, UInt32 size)
-{
- for (UInt32 i = 0; i < size; i++)
- data[i] = ReadByte();
-}
-
-UInt16 CInArchive::ReadUInt16()
-{
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- value |= ((UInt16)(ReadByte()) << (8 * i));
- return value;
-}
-
-UInt32 CInArchive::ReadUInt32()
-{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- value |= ((UInt32)(ReadByte()) << (8 * i));
- return value;
-}
-
-UInt64 CInArchive::ReadUInt64()
-{
- UInt64 value = 0;
- for (int i = 0; i < 8; i++)
- value |= ((UInt64)(ReadByte()) << (8 * i));
- return value;
-}
-
-UInt64 CInArchive::ReadEncInt()
-{
- UInt64 val = 0;;
- for (int i = 0; i < 10; i++)
- {
- Byte b = ReadByte();
- val |= (b & 0x7F);
- if (b < 0x80)
- return val;
- val <<= 7;
- }
- throw 1;
-}
-
-void CInArchive::ReadGUID(GUID &g)
-{
- g.Data1 = ReadUInt32();
- g.Data2 = ReadUInt16();
- g.Data3 = ReadUInt16();
- ReadBytes(g.Data4, 8);
-}
-
-void CInArchive::ReadString(int size, AString &s)
-{
- s.Empty();
- while(size-- != 0)
- {
- char c = (char)ReadByte();
- if (c == 0)
- {
- Skip(size);
- return;
- }
- s += c;
- }
-}
-
-void CInArchive::ReadUString(int size, UString &s)
-{
- s.Empty();
- while(size-- != 0)
- {
- wchar_t c = ReadUInt16();
- if (c == 0)
- {
- Skip(2 * size);
- return;
- }
- s += c;
- }
-}
-
-HRESULT CInArchive::ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size)
-{
- RINOK(inStream->Seek(pos, STREAM_SEEK_SET, NULL));
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> limitedStream(streamSpec);
- streamSpec->SetStream(inStream);
- streamSpec->Init(size);
- _inBuffer.SetStream(limitedStream);
- _inBuffer.Init();
- return S_OK;
-}
-
-HRESULT CInArchive::ReadDirEntry(CDatabase &database)
-{
- CItem item;
- UInt64 nameLength = ReadEncInt();
- if (nameLength == 0 || nameLength >= 0x10000000)
- return S_FALSE;
- ReadString((int)nameLength, item.Name);
- item.Section = ReadEncInt();
- item.Offset = ReadEncInt();
- item.Size = ReadEncInt();
- database.Items.Add(item);
- return S_OK;
-}
-
-HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database)
-{
- UInt32 headerSize = ReadUInt32();
- if (headerSize != 0x60)
- return S_FALSE;
- UInt32 unknown1 = ReadUInt32();
- if (unknown1 != 0 && unknown1 != 1) // it's 0 in one .sll file
- return S_FALSE;
- /* UInt32 timeStamp = */ ReadUInt32();
- // Considered as a big-endian DWORD, it appears to contain seconds (MSB) and
- // fractional seconds (second byte).
- // The third and fourth bytes may contain even more fractional bits.
- // The 4 least significant bits in the last byte are constant.
- /* UInt32 lang = */ ReadUInt32();
- GUID g;
- ReadGUID(g); // {7C01FD10-7BAA-11D0-9E0C-00A0-C922-E6EC}
- ReadGUID(g); // {7C01FD11-7BAA-11D0-9E0C-00A0-C922-E6EC}
- const int kNumSections = 2;
- UInt64 sectionOffsets[kNumSections];
- UInt64 sectionSizes[kNumSections];
- int i;
- for (i = 0; i < kNumSections; i++)
- {
- sectionOffsets[i] = ReadUInt64();
- sectionSizes[i] = ReadUInt64();
- }
- // if (chmVersion == 3)
- database.ContentOffset = ReadUInt64();
- /*
- else
- database.ContentOffset = _startPosition + 0x58
- */
-
- /*
- // Section 0
- ReadChunk(inStream, sectionOffsets[0], sectionSizes[0]);
- if (sectionSizes[0] != 0x18)
- return S_FALSE;
- ReadUInt32(); // unknown: 01FE
- ReadUInt32(); // unknown: 0
- UInt64 fileSize = ReadUInt64();
- ReadUInt32(); // unknown: 0
- ReadUInt32(); // unknown: 0
- */
-
- // Section 1: The Directory Listing
- ReadChunk(inStream, sectionOffsets[1], sectionSizes[1]);
- if (ReadUInt32() != NHeader::kItspSignature)
- return S_FALSE;
- if (ReadUInt32() != 1) // version
- return S_FALSE;
- /* UInt32 dirHeaderSize = */ ReadUInt32();
- ReadUInt32(); // 0x0A (unknown)
- UInt32 dirChunkSize = ReadUInt32(); // $1000
- if (dirChunkSize < 32)
- return S_FALSE;
- /* UInt32 density = */ ReadUInt32(); // "Density" of quickref section, usually 2.
- /* UInt32 depth = */ ReadUInt32(); // Depth of the index tree: 1 there is no index,
- // 2 if there is one level of PMGI chunks.
-
- /* UInt32 chunkNumber = */ ReadUInt32(); // Chunk number of root index chunk, -1 if there is none
- // (though at least one file has 0 despite there being no
- // index chunk, probably a bug.)
- /* UInt32 firstPmglChunkNumber = */ ReadUInt32(); // Chunk number of first PMGL (listing) chunk
- /* UInt32 lastPmglChunkNumber = */ ReadUInt32(); // Chunk number of last PMGL (listing) chunk
- ReadUInt32(); // -1 (unknown)
- UInt32 numDirChunks = ReadUInt32(); // Number of directory chunks (total)
- /* UInt32 windowsLangId = */ ReadUInt32();
- ReadGUID(g); // {5D02926A-212E-11D0-9DF9-00A0C922E6EC}
- ReadUInt32(); // 0x54 (This is the length again)
- ReadUInt32(); // -1 (unknown)
- ReadUInt32(); // -1 (unknown)
- ReadUInt32(); // -1 (unknown)
-
- for (UInt32 ci = 0; ci < numDirChunks; ci++)
- {
- UInt64 chunkPos = _inBuffer.GetProcessedSize();
- if (ReadUInt32() == NHeader::kPmglSignature)
- {
- // The quickref area is written backwards from the end of the chunk.
- // One quickref entry exists for every n entries in the file, where n
- // is calculated as 1 + (1 << quickref density). So for density = 2, n = 5.
-
- UInt32 quickrefLength = ReadUInt32(); // Length of free space and/or quickref area at end of directory chunk
- if (quickrefLength > dirChunkSize || quickrefLength < 2)
- return S_FALSE;
- ReadUInt32(); // Always 0
- ReadUInt32(); // Chunk number of previous listing chunk when reading
- // directory in sequence (-1 if this is the first listing chunk)
- ReadUInt32(); // Chunk number of next listing chunk when reading
- // directory in sequence (-1 if this is the last listing chunk)
- int numItems = 0;
- for (;;)
- {
- UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos;
- UInt32 offsetLimit = dirChunkSize - quickrefLength;
- if (offset > offsetLimit)
- return S_FALSE;
- if (offset == offsetLimit)
- break;
- RINOK(ReadDirEntry(database));
- numItems++;
- }
- Skip(quickrefLength - 2);
- if (ReadUInt16() != numItems)
- return S_FALSE;
- }
- else
- Skip(dirChunkSize - 4);
- }
- return S_OK;
-}
-
-HRESULT CInArchive::OpenHelp2(IInStream *inStream, CDatabase &database)
-{
- if (ReadUInt32() != 1) // version
- return S_FALSE;
- if (ReadUInt32() != 0x28) // Location of header section table
- return S_FALSE;
- UInt32 numHeaderSections = ReadUInt32();
- const int kNumHeaderSectionsMax = 5;
- if (numHeaderSections != kNumHeaderSectionsMax)
- return S_FALSE;
- ReadUInt32(); // Length of post-header table
- GUID g;
- ReadGUID(g); // {0A9007C1-4076-11D3-8789-0000F8105754}
-
- // header section table
- UInt64 sectionOffsets[kNumHeaderSectionsMax];
- UInt64 sectionSizes[kNumHeaderSectionsMax];
- UInt32 i;
- for (i = 0; i < numHeaderSections; i++)
- {
- sectionOffsets[i] = ReadUInt64();
- sectionSizes[i] = ReadUInt64();
- }
-
- // Post-Header
- ReadUInt32(); // 2
- ReadUInt32(); // 0x98: offset to CAOL from beginning of post-header)
- // ----- Directory information
- ReadUInt64(); // Chunk number of top-level AOLI chunk in directory, or -1
- ReadUInt64(); // Chunk number of first AOLL chunk in directory
- ReadUInt64(); // Chunk number of last AOLL chunk in directory
- ReadUInt64(); // 0 (unknown)
- ReadUInt32(); // $2000 (Directory chunk size of directory)
- ReadUInt32(); // Quickref density for main directory, usually 2
- ReadUInt32(); // 0 (unknown)
- ReadUInt32(); // Depth of main directory index tree
- // 1 there is no index, 2 if there is one level of AOLI chunks.
- ReadUInt64(); // 0 (unknown)
- UInt64 numDirEntries = ReadUInt64(); // Number of directory entries
- // ----- Directory Index Information
- ReadUInt64(); // -1 (unknown, probably chunk number of top-level AOLI in directory index)
- ReadUInt64(); // Chunk number of first AOLL chunk in directory index
- ReadUInt64(); // Chunk number of last AOLL chunk in directory index
- ReadUInt64(); // 0 (unknown)
- ReadUInt32(); // $200 (Directory chunk size of directory index)
- ReadUInt32(); // Quickref density for directory index, usually 2
- ReadUInt32(); // 0 (unknown)
- ReadUInt32(); // Depth of directory index index tree.
- ReadUInt64(); // Possibly flags -- sometimes 1, sometimes 0.
- ReadUInt64(); // Number of directory index entries (same as number of AOLL
- // chunks in main directory)
-
- // (The obvious guess for the following two fields, which recur in a number
- // of places, is they are maximum sizes for the directory and directory index.
- // However, I have seen no direct evidence that this is the case.)
-
- ReadUInt32(); // $100000 (Same as field following chunk size in directory)
- ReadUInt32(); // $20000 (Same as field following chunk size in directory index)
-
- ReadUInt64(); // 0 (unknown)
- if (ReadUInt32() != NHeader::kCaolSignature)
- return S_FALSE;
- if (ReadUInt32() != 2) // (Most likely a version number)
- return S_FALSE;
- UInt32 caolLength = ReadUInt32(); // $50 (Length of the CAOL section, which includes the ITSF section)
- if (caolLength >= 0x2C)
- {
- /* UInt32 c7 = */ ReadUInt16(); // Unknown. Remains the same when identical files are built.
- // Does not appear to be a checksum. Many files have
- // 'HH' (HTML Help?) here, indicating this may be a compiler ID
- // field. But at least one ITOL/ITLS compiler does not set this
- // field to a constant value.
- ReadUInt16(); // 0 (Unknown. Possibly part of 00A4 field)
- ReadUInt32(); // Unknown. Two values have been seen -- $43ED, and 0.
- ReadUInt32(); // $2000 (Directory chunk size of directory)
- ReadUInt32(); // $200 (Directory chunk size of directory index)
- ReadUInt32(); // $100000 (Same as field following chunk size in directory)
- ReadUInt32(); // $20000 (Same as field following chunk size in directory index)
- ReadUInt32(); // 0 (unknown)
- ReadUInt32(); // 0 (Unknown)
- if (caolLength == 0x2C)
- {
- database.ContentOffset = 0;
- database.NewFormat = true;
- }
- else if (caolLength == 0x50)
- {
- ReadUInt32(); // 0 (Unknown)
- if (ReadUInt32() != NHeader::kItsfSignature)
- return S_FALSE;
- if (ReadUInt32() != 4) // $4 (Version number -- CHM uses 3)
- return S_FALSE;
- if (ReadUInt32() != 0x20) // $20 (length of ITSF)
- return S_FALSE;
- UInt32 unknown = ReadUInt32();
- if (unknown != 0 && unknown != 1) // = 0 for some HxW files, 1 in other cases;
- return S_FALSE;
- database.ContentOffset = _startPosition + ReadUInt64();
- /* UInt32 timeStamp = */ ReadUInt32();
- // A timestamp of some sort.
- // Considered as a big-endian DWORD, it appears to contain
- // seconds (MSB) and fractional seconds (second byte).
- // The third and fourth bytes may contain even more fractional
- // bits. The 4 least significant bits in the last byte are constant.
- /* UInt32 lang = */ ReadUInt32(); // BE?
- }
- else
- return S_FALSE;
- }
-
- /*
- // Section 0
- ReadChunk(inStream, _startPosition + sectionOffsets[0], sectionSizes[0]);
- if (sectionSizes[0] != 0x18)
- return S_FALSE;
- ReadUInt32(); // unknown: 01FE
- ReadUInt32(); // unknown: 0
- UInt64 fileSize = ReadUInt64();
- ReadUInt32(); // unknown: 0
- ReadUInt32(); // unknown: 0
- */
-
- // Section 1: The Directory Listing
- ReadChunk(inStream, _startPosition + sectionOffsets[1], sectionSizes[1]);
- if (ReadUInt32() != NHeader::kIfcmSignature)
- return S_FALSE;
- if (ReadUInt32() != 1) // (probably a version number)
- return S_FALSE;
- UInt32 dirChunkSize = ReadUInt32(); // $2000
- if (dirChunkSize < 64)
- return S_FALSE;
- ReadUInt32(); // $100000 (unknown)
- ReadUInt32(); // -1 (unknown)
- ReadUInt32(); // -1 (unknown)
- UInt32 numDirChunks = ReadUInt32();
- ReadUInt32(); // 0 (unknown, probably high word of above)
-
- for (UInt32 ci = 0; ci < numDirChunks; ci++)
- {
- UInt64 chunkPos = _inBuffer.GetProcessedSize();
- if (ReadUInt32() == NHeader::kAollSignature)
- {
- UInt32 quickrefLength = ReadUInt32(); // Length of quickref area at end of directory chunk
- if (quickrefLength > dirChunkSize || quickrefLength < 2)
- return S_FALSE;
- ReadUInt64(); // Directory chunk number
- // This must match physical position in file, that is
- // the chunk size times the chunk number must be the
- // offset from the end of the directory header.
- ReadUInt64(); // Chunk number of previous listing chunk when reading
- // directory in sequence (-1 if first listing chunk)
- ReadUInt64(); // Chunk number of next listing chunk when reading
- // directory in sequence (-1 if last listing chunk)
- ReadUInt64(); // Number of first listing entry in this chunk
- ReadUInt32(); // 1 (unknown -- other values have also been seen here)
- ReadUInt32(); // 0 (unknown)
-
- int numItems = 0;
- for (;;)
- {
- UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos;
- UInt32 offsetLimit = dirChunkSize - quickrefLength;
- if (offset > offsetLimit)
- return S_FALSE;
- if (offset == offsetLimit)
- break;
- if (database.NewFormat)
- {
- UInt16 nameLength = ReadUInt16();
- if (nameLength == 0)
- return S_FALSE;
- UString name;
- ReadUString((int)nameLength, name);
- AString s;
- ConvertUnicodeToUTF8(name, s);
- Byte b = ReadByte();
- s += ' ';
- PrintByte(b, s);
- s += ' ';
- UInt64 len = ReadEncInt();
- // then number of items ?
- // then length ?
- // then some data (binary encoding?)
- while (len-- != 0)
- {
- b = ReadByte();
- PrintByte(b, s);
- }
- database.NewFormatString += s;
- database.NewFormatString += "\r\n";
- }
- else
- {
- RINOK(ReadDirEntry(database));
- }
- numItems++;
- }
- Skip(quickrefLength - 2);
- if (ReadUInt16() != numItems)
- return S_FALSE;
- if (numItems > numDirEntries)
- return S_FALSE;
- numDirEntries -= numItems;
- }
- else
- Skip(dirChunkSize - 4);
- }
- return numDirEntries == 0 ? S_OK : S_FALSE;
-}
-
-HRESULT CInArchive::DecompressStream(IInStream *inStream, const CDatabase &database, const AString &name)
-{
- int index = database.FindItem(name);
- if (index < 0)
- return S_FALSE;
- const CItem &item = database.Items[index];
- _chunkSize = item.Size;
- return ReadChunk(inStream, database.ContentOffset + item.Offset, item.Size);
-}
-
-
-#define DATA_SPACE "::DataSpace/"
-static const char *kNameList = DATA_SPACE "NameList";
-static const char *kStorage = DATA_SPACE "Storage/";
-static const char *kContent = "Content";
-static const char *kControlData = "ControlData";
-static const char *kSpanInfo = "SpanInfo";
-static const char *kTransform = "Transform/";
-static const char *kResetTable = "/InstanceData/ResetTable";
-static const char *kTransformList = "List";
-
-static AString GetSectionPrefix(const AString &name)
-{
- return AString(kStorage) + name + AString("/");
-}
-
-#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
-
-static int CompareFiles(const int *p1, const int *p2, void *param)
-{
- const CObjectVector<CItem> &items = *(const CObjectVector<CItem> *)param;
- const CItem &item1 = items[*p1];
- const CItem &item2 = items[*p2];
- bool isDir1 = item1.IsDir();
- bool isDir2 = item2.IsDir();
- if (isDir1 && !isDir2)
- return -1;
- if (isDir2)
- {
- if (isDir1)
- return MyCompare(*p1, *p2);
- return 1;
- }
- RINOZ(MyCompare(item1.Section, item2.Section));
- RINOZ(MyCompare(item1.Offset, item2.Offset));
- RINOZ(MyCompare(item1.Size, item2.Size));
- return MyCompare(*p1, *p2);
-}
-
-void CFilesDatabase::SetIndices()
-{
- for (int i = 0; i < Items.Size(); i++)
- {
- const CItem &item = Items[i];
- if (item.IsUserItem() && item.Name.Length() != 1)
- Indices.Add(i);
- }
-}
-
-void CFilesDatabase::Sort()
-{
- Indices.Sort(CompareFiles, (void *)&Items);
-}
-
-bool CFilesDatabase::Check()
-{
- UInt64 maxPos = 0;
- UInt64 prevSection = 0;
- for(int i = 0; i < Indices.Size(); i++)
- {
- const CItem &item = Items[Indices[i]];
- if (item.Section == 0 || item.IsDir())
- continue;
- if (item.Section != prevSection)
- {
- prevSection = item.Section;
- maxPos = 0;
- continue;
- }
- if (item.Offset < maxPos)
- return false;
- maxPos = item.Offset + item.Size;
- if (maxPos < item.Offset)
- return false;
- }
- return true;
-}
-
-HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
-{
- {
- // The NameList file
- RINOK(DecompressStream(inStream, database, kNameList));
- /* UInt16 length = */ ReadUInt16();
- UInt16 numSections = ReadUInt16();
- for (int i = 0; i < numSections; i++)
- {
- CSectionInfo section;
- UInt16 nameLength = ReadUInt16();
- UString name;
- ReadUString(nameLength, name);
- if (ReadUInt16() != 0)
- return S_FALSE;
- if (!ConvertUnicodeToUTF8(name, section.Name))
- return S_FALSE;
- database.Sections.Add(section);
- }
- }
-
- int i;
- for (i = 1; i < database.Sections.Size(); i++)
- {
- CSectionInfo &section = database.Sections[i];
- AString sectionPrefix = GetSectionPrefix(section.Name);
- {
- // Content
- int index = database.FindItem(sectionPrefix + kContent);
- if (index < 0)
- return S_FALSE;
- const CItem &item = database.Items[index];
- section.Offset = item.Offset;
- section.CompressedSize = item.Size;
- }
- AString transformPrefix = sectionPrefix + kTransform;
- if (database.Help2Format)
- {
- // Transform List
- RINOK(DecompressStream(inStream, database, transformPrefix + kTransformList));
- if ((_chunkSize & 0xF) != 0)
- return S_FALSE;
- int numGuids = (int)(_chunkSize / 0x10);
- if (numGuids < 1)
- return S_FALSE;
- for (int i = 0; i < numGuids; i++)
- {
- CMethodInfo method;
- ReadGUID(method.Guid);
- section.Methods.Add(method);
- }
- }
- else
- {
- CMethodInfo method;
- method.Guid = kChmLzxGuid;
- section.Methods.Add(method);
- }
-
- {
- // Control Data
- RINOK(DecompressStream(inStream, database, sectionPrefix + kControlData));
- for (int mi = 0; mi < section.Methods.Size(); mi++)
- {
- CMethodInfo &method = section.Methods[mi];
- UInt32 numDWORDS = ReadUInt32();
- if (method.IsLzx())
- {
- if (numDWORDS < 5)
- return S_FALSE;
- if (ReadUInt32() != NHeader::kLzxcSignature)
- return S_FALSE;
- CLzxInfo &li = method.LzxInfo;
- li.Version = ReadUInt32();
- if (li.Version != 2 && li.Version != 3)
- return S_FALSE;
- li.ResetInterval = ReadUInt32();
- li.WindowSize = ReadUInt32();
- li.CacheSize = ReadUInt32();
- if (
- li.ResetInterval != 1 &&
- li.ResetInterval != 2 &&
- li.ResetInterval != 4 &&
- li.ResetInterval != 8 &&
- li.ResetInterval != 16 &&
- li.ResetInterval != 32 &&
- li.ResetInterval != 64)
- return S_FALSE;
- if (
- li.WindowSize != 1 &&
- li.WindowSize != 2 &&
- li.WindowSize != 4 &&
- li.WindowSize != 8 &&
- li.WindowSize != 16 &&
- li.WindowSize != 32 &&
- li.WindowSize != 64)
- return S_FALSE;
- numDWORDS -= 5;
- while (numDWORDS-- != 0)
- ReadUInt32();
- }
- else
- {
- UInt32 numBytes = numDWORDS * 4;
- method.ControlData.SetCapacity(numBytes);
- ReadBytes(method.ControlData, numBytes);
- }
- }
- }
-
- {
- // SpanInfo
- RINOK(DecompressStream(inStream, database, sectionPrefix + kSpanInfo));
- section.UncompressedSize = ReadUInt64();
- }
-
- // read ResetTable for LZX
- for (int mi = 0; mi < section.Methods.Size(); mi++)
- {
- CMethodInfo &method = section.Methods[mi];
- if (method.IsLzx())
- {
- // ResetTable;
- RINOK(DecompressStream(inStream, database, transformPrefix +
- method.GetGuidString() + kResetTable));
- CResetTable &rt = method.LzxInfo.ResetTable;
- if (_chunkSize < 4)
- {
- if (_chunkSize != 0)
- return S_FALSE;
- // ResetTable is empty in .chw files
- if (section.UncompressedSize != 0)
- return S_FALSE;
- rt.UncompressedSize = 0;
- rt.CompressedSize = 0;
- rt.BlockSize = 0;
- }
- else
- {
- UInt32 ver = ReadUInt32(); // 2 unknown (possibly a version number)
- if (ver != 2 && ver != 3)
- return S_FALSE;
- UInt32 numEntries = ReadUInt32();
- if (ReadUInt32() != 8) // Size of table entry (bytes)
- return S_FALSE;
- if (ReadUInt32() != 0x28) // Length of table header
- return S_FALSE;
- rt.UncompressedSize = ReadUInt64();
- rt.CompressedSize = ReadUInt64();
- rt.BlockSize = ReadUInt64(); // 0x8000 block size for locations below
- if (rt.BlockSize != 0x8000)
- return S_FALSE;
- rt.ResetOffsets.Reserve(numEntries);
- for (UInt32 i = 0; i < numEntries; i++)
- rt.ResetOffsets.Add(ReadUInt64());
- }
- }
- }
- }
-
- database.SetIndices();
- database.Sort();
- return database.Check() ? S_OK : S_FALSE;
-}
-
-HRESULT CInArchive::Open2(IInStream *inStream,
- const UInt64 *searchHeaderSizeLimit,
- CFilesDatabase &database)
-{
- database.Clear();
-
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &_startPosition));
-
- database.Help2Format = false;
- const UInt32 chmVersion = 3;
- {
- if (!_inBuffer.Create(1 << 14))
- return E_OUTOFMEMORY;
- _inBuffer.SetStream(inStream);
- _inBuffer.Init();
- UInt64 value = 0;
- const int kSignatureSize = 8;
- UInt64 hxsSignature = NHeader::GetHxsSignature();
- UInt64 chmSignature = ((UInt64)chmVersion << 32)| NHeader::kItsfSignature;
- UInt64 limit = 1 << 18;
- if (searchHeaderSizeLimit)
- if (limit > *searchHeaderSizeLimit)
- limit = *searchHeaderSizeLimit;
-
- for (;;)
- {
- Byte b;
- if (!_inBuffer.ReadByte(b))
- return S_FALSE;
- value >>= 8;
- value |= ((UInt64)b) << ((kSignatureSize - 1) * 8);
- if (_inBuffer.GetProcessedSize() >= kSignatureSize)
- {
- if (value == chmSignature)
- break;
- if (value == hxsSignature)
- {
- database.Help2Format = true;
- break;
- }
- if (_inBuffer.GetProcessedSize() > limit)
- return S_FALSE;
- }
- }
- _startPosition += _inBuffer.GetProcessedSize() - kSignatureSize;
- }
-
- if (database.Help2Format)
- {
- RINOK(OpenHelp2(inStream, database));
- if (database.NewFormat)
- return S_OK;
- }
- else
- {
- RINOK(OpenChm(inStream, database));
- }
-
- #ifndef CHM_LOW
- try
- {
- HRESULT res = OpenHighLevel(inStream, database);
- if (res == S_FALSE)
- {
- database.HighLevelClear();
- return S_OK;
- }
- RINOK(res);
- database.LowLevel = false;
- }
- catch(...)
- {
- return S_OK;
- }
- #endif
- return S_OK;
-}
-
-HRESULT CInArchive::Open(IInStream *inStream,
- const UInt64 *searchHeaderSizeLimit,
- CFilesDatabase &database)
-{
- try
- {
- HRESULT res = Open2(inStream, searchHeaderSizeLimit, database);
- _inBuffer.ReleaseStream();
- return res;
- }
- catch(...)
- {
- _inBuffer.ReleaseStream();
- throw;
- }
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.h b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.h
deleted file mode 100644
index 4719a484d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmIn.h
+++ /dev/null
@@ -1,244 +0,0 @@
-// Archive/ChmIn.h
-
-#ifndef __ARCHIVE_CHM_IN_H
-#define __ARCHIVE_CHM_IN_H
-
-#include "Common/Buffer.h"
-#include "Common/MyString.h"
-
-#include "../../IStream.h"
-#include "../../Common/InBuffer.h"
-
-#include "ChmHeader.h"
-
-namespace NArchive {
-namespace NChm {
-
-struct CItem
-{
- UInt64 Section;
- UInt64 Offset;
- UInt64 Size;
- AString Name;
-
- bool IsFormatRelatedItem() const
- {
- if (Name.Length() < 2)
- return false;
- return Name[0] == ':' && Name[1] == ':';
- }
-
- bool IsUserItem() const
- {
- if (Name.Length() < 2)
- return false;
- return Name[0] == '/';
- }
-
- bool IsDir() const
- {
- if (Name.Length() == 0)
- return false;
- return (Name[Name.Length() - 1] == '/');
- }
-};
-
-struct CDatabase
-{
- UInt64 ContentOffset;
- CObjectVector<CItem> Items;
- AString NewFormatString;
- bool Help2Format;
- bool NewFormat;
-
- int FindItem(const AString &name) const
- {
- for (int i = 0; i < Items.Size(); i++)
- if (Items[i].Name == name)
- return i;
- return -1;
- }
-
- void Clear()
- {
- NewFormat = false;
- NewFormatString.Empty();
- Help2Format = false;
- Items.Clear();
- }
-};
-
-struct CResetTable
-{
- UInt64 UncompressedSize;
- UInt64 CompressedSize;
- UInt64 BlockSize;
- CRecordVector<UInt64> ResetOffsets;
- bool GetCompressedSizeOfBlocks(UInt64 blockIndex, UInt32 numBlocks, UInt64 &size) const
- {
- if (blockIndex >= ResetOffsets.Size())
- return false;
- UInt64 startPos = ResetOffsets[(int)blockIndex];
- if (blockIndex + numBlocks >= ResetOffsets.Size())
- size = CompressedSize - startPos;
- else
- size = ResetOffsets[(int)(blockIndex + numBlocks)] - startPos;
- return true;
- }
- bool GetCompressedSizeOfBlock(UInt64 blockIndex, UInt64 &size) const
- {
- return GetCompressedSizeOfBlocks(blockIndex, 1, size);
- }
- UInt64 GetNumBlocks(UInt64 size) const
- {
- return (size + BlockSize - 1) / BlockSize;
- }
-};
-
-struct CLzxInfo
-{
- UInt32 Version;
- UInt32 ResetInterval;
- UInt32 WindowSize;
- UInt32 CacheSize;
- CResetTable ResetTable;
-
- UInt32 GetNumDictBits() const
- {
- if (Version == 2 || Version == 3)
- {
- for (int i = 0; i <= 31; i++)
- if (((UInt32)1 << i) >= WindowSize)
- return 15 + i;
- }
- return 0;
- }
-
- UInt64 GetFolderSize() const { return ResetTable.BlockSize * ResetInterval; };
- UInt64 GetFolder(UInt64 offset) const { return offset / GetFolderSize(); };
- UInt64 GetFolderPos(UInt64 folderIndex) const { return folderIndex * GetFolderSize(); };
- UInt64 GetBlockIndexFromFolderIndex(UInt64 folderIndex) const { return folderIndex * ResetInterval; };
- bool GetOffsetOfFolder(UInt64 folderIndex, UInt64 &offset) const
- {
- UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
- if (blockIndex >= ResetTable.ResetOffsets.Size())
- return false;
- offset = ResetTable.ResetOffsets[(int)blockIndex];
- return true;
- }
- bool GetCompressedSizeOfFolder(UInt64 folderIndex, UInt64 &size) const
- {
- UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex);
- return ResetTable.GetCompressedSizeOfBlocks(blockIndex, ResetInterval, size);
- }
-};
-
-struct CMethodInfo
-{
- GUID Guid;
- CByteBuffer ControlData;
- CLzxInfo LzxInfo;
- bool IsLzx() const;
- bool IsDes() const;
- AString GetGuidString() const;
- UString GetName() const;
-};
-
-struct CSectionInfo
-{
- UInt64 Offset;
- UInt64 CompressedSize;
- UInt64 UncompressedSize;
-
- AString Name;
- CObjectVector<CMethodInfo> Methods;
-
- bool IsLzx() const;
- UString GetMethodName() const;
-};
-
-class CFilesDatabase: public CDatabase
-{
-public:
- bool LowLevel;
- CRecordVector<int> Indices;
- CObjectVector<CSectionInfo> Sections;
-
- UInt64 GetFileSize(int fileIndex) const { return Items[Indices[fileIndex]].Size; }
- UInt64 GetFileOffset(int fileIndex) const { return Items[Indices[fileIndex]].Offset; }
-
- UInt64 GetFolder(int fileIndex) const
- {
- const CItem &item = Items[Indices[fileIndex]];
- const CSectionInfo &section = Sections[(int)item.Section];
- if (section.IsLzx())
- return section.Methods[0].LzxInfo.GetFolder(item.Offset);
- return 0;
- }
-
- UInt64 GetLastFolder(int fileIndex) const
- {
- const CItem &item = Items[Indices[fileIndex]];
- const CSectionInfo &section = Sections[(int)item.Section];
- if (section.IsLzx())
- return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
- return 0;
- }
-
- void HighLevelClear()
- {
- LowLevel = true;
- Indices.Clear();
- Sections.Clear();
- }
-
- void Clear()
- {
- CDatabase::Clear();
- HighLevelClear();
- }
- void SetIndices();
- void Sort();
- bool Check();
-};
-
-class CProgressVirt
-{
-public:
- STDMETHOD(SetTotal)(const UInt64 *numFiles) PURE;
- STDMETHOD(SetCompleted)(const UInt64 *numFiles) PURE;
-};
-
-class CInArchive
-{
- UInt64 _startPosition;
- ::CInBuffer _inBuffer;
- UInt64 _chunkSize;
-
- Byte ReadByte();
- void ReadBytes(Byte *data, UInt32 size);
- void Skip(size_t size);
- UInt16 ReadUInt16();
- UInt32 ReadUInt32();
- UInt64 ReadUInt64();
- UInt64 ReadEncInt();
- void ReadString(int size, AString &s);
- void ReadUString(int size, UString &s);
- void ReadGUID(GUID &g);
-
- HRESULT ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size);
-
- HRESULT ReadDirEntry(CDatabase &database);
- HRESULT DecompressStream(IInStream *inStream, const CDatabase &database, const AString &name);
-
-public:
- HRESULT OpenChm(IInStream *inStream, CDatabase &database);
- HRESULT OpenHelp2(IInStream *inStream, CDatabase &database);
- HRESULT OpenHighLevel(IInStream *inStream, CFilesDatabase &database);
- HRESULT Open2(IInStream *inStream, const UInt64 *searchHeaderSizeLimit, CFilesDatabase &database);
- HRESULT Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit, CFilesDatabase &database);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmRegister.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmRegister.cpp
deleted file mode 100644
index e5f38afa4..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/ChmRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// ChmRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "ChmHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NChm::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Chm", L"chm chi chq chw hxs hxi hxr hxq hxw lit", 0, 0xE9, { 'I', 'T', 'S', 'F' }, 4, false, CreateArc, 0 };
-
-REGISTER_ARC(Chm)
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Chm/StdAfx.h b/src/libs/7zip/win/CPP/7zip/Archive/Chm/StdAfx.h
deleted file mode 100644
index e7fb6986d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Chm/StdAfx.h
+++ /dev/null
@@ -1,8 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.cpp
deleted file mode 100644
index 58f76439f..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-// ComHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/ProgressUtils.h"
-#include "../../Common/StreamUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-
-#include "ComHandler.h"
-
-namespace NArchive {
-namespace NCom {
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidCTime, VT_FILETIME},
- { NULL, kpidMTime, VT_FILETIME}
-};
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidClusterSize, VT_UI4},
- { NULL, kpidSectorSize, VT_UI4}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidClusterSize: prop = (UInt32)1 << _db.SectorSizeBits; break;
- case kpidSectorSize: prop = (UInt32)1 << _db.MiniSectorSizeBits; break;
- case kpidMainSubfile: if (_db.MainSubfile >= 0) prop = (UInt32)_db.MainSubfile; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CRef &ref = _db.Refs[index];
- const CItem &item = _db.Items[ref.Did];
-
- switch(propID)
- {
- case kpidPath: prop = _db.GetItemPath(index); break;
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidCTime: prop = item.CTime; break;
- case kpidMTime: prop = item.MTime; break;
- case kpidPackSize: if (!item.IsDir()) prop = _db.GetItemPackSize(item.Size); break;
- case kpidSize: if (!item.IsDir()) prop = item.Size; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- try
- {
- if (_db.Open(inStream) != S_OK)
- return S_FALSE;
- _stream = inStream;
- }
- catch(...) { return S_FALSE; }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _db.Clear();
- _stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _db.Refs.Size();
- if (numItems == 0)
- return S_OK;
- UInt32 i;
- UInt64 totalSize = 0;
- for(i = 0; i < numItems; i++)
- {
- const CItem &item = _db.Items[_db.Refs[allFilesMode ? i : indices[i]].Did];
- if (!item.IsDir())
- totalSize += item.Size;
- }
- RINOK(extractCallback->SetTotal(totalSize));
-
- UInt64 totalPackSize;
- totalSize = totalPackSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = totalPackSize;
- lps->OutSize = totalSize;
- RINOK(lps->SetCur());
- Int32 index = allFilesMode ? i : indices[i];
- const CItem &item = _db.Items[_db.Refs[index].Did];
-
- CMyComPtr<ISequentialOutStream> outStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
-
- if (item.IsDir())
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
-
- totalPackSize += _db.GetItemPackSize(item.Size);
- totalSize += item.Size;
-
- if (!testMode && !outStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- Int32 res = NExtract::NOperationResult::kDataError;
- CMyComPtr<ISequentialInStream> inStream;
- HRESULT hres = GetStream(index, &inStream);
- if (hres == S_FALSE)
- res = NExtract::NOperationResult::kDataError;
- else if (hres == E_NOTIMPL)
- res = NExtract::NOperationResult::kUnSupportedMethod;
- else
- {
- RINOK(hres);
- if (inStream)
- {
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
- if (copyCoderSpec->TotalSize == item.Size)
- res = NExtract::NOperationResult::kOK;
- }
- }
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(res));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _db.Refs.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- *stream = 0;
- const CItem &item = _db.Items[_db.Refs[index].Did];
- CClusterInStream *streamSpec = new CClusterInStream;
- CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
- streamSpec->Stream = _stream;
- streamSpec->StartOffset = 0;
-
- bool isLargeStream = _db.IsLargeStream(item.Size);
- int bsLog = isLargeStream ? _db.SectorSizeBits : _db.MiniSectorSizeBits;
- streamSpec->BlockSizeLog = bsLog;
- streamSpec->Size = item.Size;
-
- UInt32 clusterSize = (UInt32)1 << bsLog;
- UInt64 numClusters64 = (item.Size + clusterSize - 1) >> bsLog;
- if (numClusters64 >= ((UInt32)1 << 31))
- return E_NOTIMPL;
- streamSpec->Vector.Reserve((int)numClusters64);
- UInt32 sid = item.Sid;
- UInt64 size = item.Size;
-
- if (size != 0)
- {
- for (;; size -= clusterSize)
- {
- if (isLargeStream)
- {
- if (sid >= _db.FatSize)
- return S_FALSE;
- streamSpec->Vector.Add(sid + 1);
- sid = _db.Fat[sid];
- }
- else
- {
- UInt64 val;
- if (sid >= _db.MatSize || !_db.GetMiniCluster(sid, val) || val >= (UInt64)1 << 32)
- return S_FALSE;
- streamSpec->Vector.Add((UInt32)val);
- sid = _db.Mat[sid];
- }
- if (size <= clusterSize)
- break;
- }
- }
- if (sid != NFatID::kEndOfChain)
- return S_FALSE;
- RINOK(streamSpec->InitAndSeek());
- *stream = streamTemp.Detach();
- return S_OK;
- COM_TRY_END
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.h
deleted file mode 100644
index f2b7de96d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComHandler.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// ComHandler.h
-
-#ifndef __ARCHIVE_COM_HANDLER_H
-#define __ARCHIVE_COM_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-#include "ComIn.h"
-
-namespace NArchive {
-namespace NCom {
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- CDatabase _db;
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.cpp
deleted file mode 100644
index 2203ca531..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.cpp
+++ /dev/null
@@ -1,389 +0,0 @@
-// Archive/ComIn.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../C/Alloc.h"
-#include "../../../../C/CpuArch.h"
-
-#include "Common/IntToString.h"
-#include "Common/MyCom.h"
-
-#include "../../Common/StreamUtils.h"
-
-#include "ComIn.h"
-
-#define Get16(p) GetUi16(p)
-#define Get32(p) GetUi32(p)
-
-namespace NArchive{
-namespace NCom{
-
-static const UInt32 kSignatureSize = 8;
-static const Byte kSignature[kSignatureSize] = { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 };
-
-void CUInt32Buf::Free()
-{
- MyFree(_buf);
- _buf = 0;
-}
-
-bool CUInt32Buf::Allocate(UInt32 numItems)
-{
- Free();
- if (numItems == 0)
- return true;
- size_t newSize = (size_t)numItems * sizeof(UInt32);
- if (newSize / sizeof(UInt32) != numItems)
- return false;
- _buf = (UInt32 *)MyAlloc(newSize);
- return (_buf != 0);
-}
-
-static HRESULT ReadSector(IInStream *inStream, Byte *buf, int sectorSizeBits, UInt32 sid)
-{
- RINOK(inStream->Seek((((UInt64)sid + 1) << sectorSizeBits), STREAM_SEEK_SET, NULL));
- return ReadStream_FALSE(inStream, buf, (UInt32)1 << sectorSizeBits);
-}
-
-static HRESULT ReadIDs(IInStream *inStream, Byte *buf, int sectorSizeBits, UInt32 sid, UInt32 *dest)
-{
- RINOK(ReadSector(inStream, buf, sectorSizeBits, sid));
- UInt32 sectorSize = (UInt32)1 << sectorSizeBits;
- for (UInt32 t = 0; t < sectorSize; t += 4)
- *dest++ = Get32(buf + t);
- return S_OK;
-}
-
-static void GetFileTimeFromMem(const Byte *p, FILETIME *ft)
-{
- ft->dwLowDateTime = Get32(p);
- ft->dwHighDateTime = Get32(p + 4);
-}
-
-void CItem::Parse(const Byte *p, bool mode64bit)
-{
- memcpy(Name, p, kNameSizeMax);
- // NameSize = Get16(p + 64);
- Type = p[66];
- LeftDid = Get32(p + 68);
- RightDid = Get32(p + 72);
- SonDid = Get32(p + 76);
- // Flags = Get32(p + 96);
- GetFileTimeFromMem(p + 100, &CTime);
- GetFileTimeFromMem(p + 108, &MTime);
- Sid = Get32(p + 116);
- Size = Get32(p + 120);
- if (mode64bit)
- Size |= ((UInt64)Get32(p + 124) << 32);
-}
-
-void CDatabase::Clear()
-{
- Fat.Free();
- MiniSids.Free();
- Mat.Free();
- Items.Clear();
- Refs.Clear();
-}
-
-static const UInt32 kNoDid = 0xFFFFFFFF;
-
-HRESULT CDatabase::AddNode(int parent, UInt32 did)
-{
- if (did == kNoDid)
- return S_OK;
- if (did >= (UInt32)Items.Size())
- return S_FALSE;
- const CItem &item = Items[did];
- if (item.IsEmpty())
- return S_FALSE;
- CRef ref;
- ref.Parent = parent;
- ref.Did = did;
- int index = Refs.Add(ref);
- if (Refs.Size() > Items.Size())
- return S_FALSE;
- RINOK(AddNode(parent, item.LeftDid));
- RINOK(AddNode(parent, item.RightDid));
- if (item.IsDir())
- {
- RINOK(AddNode(index, item.SonDid));
- }
- return S_OK;
-}
-
-static const char kCharOpenBracket = '[';
-static const char kCharCloseBracket = ']';
-
-static UString CompoundNameToFileName(const UString &s)
-{
- UString res;
- for (int i = 0; i < s.Length(); i++)
- {
- wchar_t c = s[i];
- if (c < 0x20)
- {
- res += kCharOpenBracket;
- wchar_t buf[32];
- ConvertUInt32ToString(c, buf);
- res += buf;
- res += kCharCloseBracket;
- }
- else
- res += c;
- }
- return res;
-}
-
-static char g_MsiChars[] =
-"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._";
-
-static const wchar_t *kMsi_ID = L""; // L"{msi}";
-
-static const int kMsiNumBits = 6;
-static const UInt32 kMsiNumChars = 1 << kMsiNumBits;
-static const UInt32 kMsiCharMask = kMsiNumChars - 1;
-static const UInt32 kMsiStartUnicodeChar = 0x3800;
-static const UInt32 kMsiUnicodeRange = kMsiNumChars * (kMsiNumChars + 1);
-
-bool CompoundMsiNameToFileName(const UString &name, UString &resultName)
-{
- resultName.Empty();
- for (int i = 0; i < name.Length(); i++)
- {
- wchar_t c = name[i];
- if (c < kMsiStartUnicodeChar || c > kMsiStartUnicodeChar + kMsiUnicodeRange)
- return false;
- if (i == 0)
- resultName += kMsi_ID;
- c -= kMsiStartUnicodeChar;
-
- UInt32 c0 = c & kMsiCharMask;
- UInt32 c1 = c >> kMsiNumBits;
-
- if (c1 <= kMsiNumChars)
- {
- resultName += (wchar_t)g_MsiChars[c0];
- if (c1 == kMsiNumChars)
- break;
- resultName += (wchar_t)g_MsiChars[c1];
- }
- else
- resultName += L'!';
- }
- return true;
-}
-
-static UString ConvertName(const Byte *p, bool &isMsi)
-{
- isMsi = false;
- UString s;
- for (int i = 0; i < kNameSizeMax; i += 2)
- {
- wchar_t c = (p[i] | (wchar_t)p[i + 1] << 8);
- if (c == 0)
- break;
- s += c;
- }
- UString msiName;
- if (CompoundMsiNameToFileName(s, msiName))
- {
- isMsi = true;
- return msiName;
- }
- return CompoundNameToFileName(s);
-}
-
-static UString ConvertName(const Byte *p)
-{
- bool isMsi;
- return ConvertName(p, isMsi);
-}
-
-UString CDatabase::GetItemPath(UInt32 index) const
-{
- UString s;
- while (index != kNoDid)
- {
- const CRef &ref = Refs[index];
- const CItem &item = Items[ref.Did];
- if (!s.IsEmpty())
- s = (UString)WCHAR_PATH_SEPARATOR + s;
- s = ConvertName(item.Name) + s;
- index = ref.Parent;
- }
- return s;
-}
-
-HRESULT CDatabase::Open(IInStream *inStream)
-{
- MainSubfile = -1;
- static const UInt32 kHeaderSize = 512;
- Byte p[kHeaderSize];
- RINOK(ReadStream_FALSE(inStream, p, kHeaderSize));
- if (memcmp(p, kSignature, kSignatureSize) != 0)
- return S_FALSE;
- if (Get16(p + 0x1A) > 4) // majorVer
- return S_FALSE;
- if (Get16(p + 0x1C) != 0xFFFE)
- return S_FALSE;
- int sectorSizeBits = Get16(p + 0x1E);
- bool mode64bit = (sectorSizeBits >= 12);
- int miniSectorSizeBits = Get16(p + 0x20);
- SectorSizeBits = sectorSizeBits;
- MiniSectorSizeBits = miniSectorSizeBits;
-
- if (sectorSizeBits > 28 || miniSectorSizeBits > 28 ||
- sectorSizeBits < 7 || miniSectorSizeBits < 2 || miniSectorSizeBits > sectorSizeBits)
- return S_FALSE;
- UInt32 numSectorsForFAT = Get32(p + 0x2C);
- LongStreamMinSize = Get32(p + 0x38);
-
- UInt32 sectSize = (UInt32)1 << (int)sectorSizeBits;
-
- CByteBuffer sect;
- sect.SetCapacity(sectSize);
-
- int ssb2 = (int)(sectorSizeBits - 2);
- UInt32 numSidsInSec = (UInt32)1 << ssb2;
- UInt32 numFatItems = numSectorsForFAT << ssb2;
- if ((numFatItems >> ssb2) != numSectorsForFAT)
- return S_FALSE;
- FatSize = numFatItems;
-
- {
- CUInt32Buf bat;
- UInt32 numSectorsForBat = Get32(p + 0x48);
- const UInt32 kNumHeaderBatItems = 109;
- UInt32 numBatItems = kNumHeaderBatItems + (numSectorsForBat << ssb2);
- if (numBatItems < kNumHeaderBatItems || ((numBatItems - kNumHeaderBatItems) >> ssb2) != numSectorsForBat)
- return S_FALSE;
- if (!bat.Allocate(numBatItems))
- return S_FALSE;
- UInt32 i;
- for (i = 0; i < kNumHeaderBatItems; i++)
- bat[i] = Get32(p + 0x4c + i * 4);
- UInt32 sid = Get32(p + 0x44);
- for (UInt32 s = 0; s < numSectorsForBat; s++)
- {
- RINOK(ReadIDs(inStream, sect, sectorSizeBits, sid, bat + i));
- i += numSidsInSec - 1;
- sid = bat[i];
- }
- numBatItems = i;
-
- if (!Fat.Allocate(numFatItems))
- return S_FALSE;
- UInt32 j = 0;
-
- for (i = 0; i < numFatItems; j++, i += numSidsInSec)
- {
- if (j >= numBatItems)
- return S_FALSE;
- RINOK(ReadIDs(inStream, sect, sectorSizeBits, bat[j], Fat + i));
- }
- }
-
- UInt32 numMatItems;
- {
- UInt32 numSectorsForMat = Get32(p + 0x40);
- numMatItems = (UInt32)numSectorsForMat << ssb2;
- if ((numMatItems >> ssb2) != numSectorsForMat)
- return S_FALSE;
- if (!Mat.Allocate(numMatItems))
- return S_FALSE;
- UInt32 i;
- UInt32 sid = Get32(p + 0x3C);
- for (i = 0; i < numMatItems; i += numSidsInSec)
- {
- RINOK(ReadIDs(inStream, sect, sectorSizeBits, sid, Mat + i));
- if (sid >= numFatItems)
- return S_FALSE;
- sid = Fat[sid];
- }
- if (sid != NFatID::kEndOfChain)
- return S_FALSE;
- }
-
- {
- UInt32 sid = Get32(p + 0x30);
- for (;;)
- {
- if (sid >= numFatItems)
- return S_FALSE;
- RINOK(ReadSector(inStream, sect, sectorSizeBits, sid));
- for (UInt32 i = 0; i < sectSize; i += 128)
- {
- CItem item;
- item.Parse(sect + i, mode64bit);
- Items.Add(item);
- }
- sid = Fat[sid];
- if (sid == NFatID::kEndOfChain)
- break;
- }
- }
-
- CItem root = Items[0];
-
- {
- UInt32 numSectorsInMiniStream;
- {
- UInt64 numSatSects64 = (root.Size + sectSize - 1) >> sectorSizeBits;
- if (numSatSects64 > NFatID::kMaxValue)
- return S_FALSE;
- numSectorsInMiniStream = (UInt32)numSatSects64;
- }
- NumSectorsInMiniStream = numSectorsInMiniStream;
- if (!MiniSids.Allocate(numSectorsInMiniStream))
- return S_FALSE;
- {
- UInt64 matSize64 = (root.Size + ((UInt64)1 << miniSectorSizeBits) - 1) >> miniSectorSizeBits;
- if (matSize64 > NFatID::kMaxValue)
- return S_FALSE;
- MatSize = (UInt32)matSize64;
- if (numMatItems < MatSize)
- return S_FALSE;
- }
-
- UInt32 sid = root.Sid;
- for (UInt32 i = 0; ; i++)
- {
- if (sid == NFatID::kEndOfChain)
- {
- if (i != numSectorsInMiniStream)
- return S_FALSE;
- break;
- }
- if (i >= numSectorsInMiniStream)
- return S_FALSE;
- MiniSids[i] = sid;
- if (sid >= numFatItems)
- return S_FALSE;
- sid = Fat[sid];
- }
- }
-
- RINOK(AddNode(-1, root.SonDid));
-
- unsigned numCabs = 0;
- for (int i = 0; i < Refs.Size(); i++)
- {
- const CItem &item = Items[Refs[i].Did];
- if (item.IsDir() || numCabs > 1)
- continue;
- bool isMsiName;
- UString msiName = ConvertName(item.Name, isMsiName);
- if (isMsiName && msiName.Right(4).CompareNoCase(L".cab") == 0)
- {
- numCabs++;
- MainSubfile = i;
- }
- }
- if (numCabs > 1)
- MainSubfile = -1;
-
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.h b/src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.h
deleted file mode 100644
index 429d3796e..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComIn.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// Archive/ComIn.h
-
-#ifndef __ARCHIVE_COM_IN_H
-#define __ARCHIVE_COM_IN_H
-
-#include "Common/MyString.h"
-#include "Common/Buffer.h"
-
-namespace NArchive {
-namespace NCom {
-
-struct CUInt32Buf
-{
- UInt32 *_buf;
-public:
- CUInt32Buf(): _buf(0) {}
- ~CUInt32Buf() { Free(); }
- void Free();
- bool Allocate(UInt32 numItems);
- operator UInt32 *() const { return _buf; };
-};
-
-namespace NFatID
-{
- const UInt32 kFree = 0xFFFFFFFF;
- const UInt32 kEndOfChain = 0xFFFFFFFE;
- const UInt32 kFatSector = 0xFFFFFFFD;
- const UInt32 kMatSector = 0xFFFFFFFC;
- const UInt32 kMaxValue = 0xFFFFFFFA;
-}
-
-namespace NItemType
-{
- const Byte kEmpty = 0;
- const Byte kStorage = 1;
- const Byte kStream = 2;
- const Byte kLockBytes = 3;
- const Byte kProperty = 4;
- const Byte kRootStorage = 5;
-}
-
-const UInt32 kNameSizeMax = 64;
-
-struct CItem
-{
- Byte Name[kNameSizeMax];
- // UInt16 NameSize;
- // UInt32 Flags;
- FILETIME CTime;
- FILETIME MTime;
- UInt64 Size;
- UInt32 LeftDid;
- UInt32 RightDid;
- UInt32 SonDid;
- UInt32 Sid;
- Byte Type;
-
- bool IsEmpty() const { return Type == NItemType::kEmpty; }
- bool IsDir() const { return Type == NItemType::kStorage || Type == NItemType::kRootStorage; }
-
- void Parse(const Byte *p, bool mode64bit);
-};
-
-struct CRef
-{
- int Parent;
- UInt32 Did;
-};
-
-class CDatabase
-{
- UInt32 NumSectorsInMiniStream;
- CUInt32Buf MiniSids;
-
- HRESULT AddNode(int parent, UInt32 did);
-public:
-
- CUInt32Buf Fat;
- UInt32 FatSize;
-
- CUInt32Buf Mat;
- UInt32 MatSize;
-
- CObjectVector<CItem> Items;
- CRecordVector<CRef> Refs;
-
- UInt32 LongStreamMinSize;
- int SectorSizeBits;
- int MiniSectorSizeBits;
-
- Int32 MainSubfile;
-
- void Clear();
- bool IsLargeStream(UInt64 size) const { return size >= LongStreamMinSize; }
- UString GetItemPath(UInt32 index) const;
-
- UInt64 GetItemPackSize(UInt64 size) const
- {
- UInt64 mask = ((UInt64)1 << (IsLargeStream(size) ? SectorSizeBits : MiniSectorSizeBits)) - 1;
- return (size + mask) & ~mask;
- }
-
- bool GetMiniCluster(UInt32 sid, UInt64 &res) const
- {
- int subBits = SectorSizeBits - MiniSectorSizeBits;
- UInt32 fid = sid >> subBits;
- if (fid >= NumSectorsInMiniStream)
- return false;
- res = (((UInt64)MiniSids[fid] + 1) << subBits) + (sid & ((1 << subBits) - 1));
- return true;
- }
-
- HRESULT Open(IInStream *inStream);
-};
-
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComRegister.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Com/ComRegister.cpp
deleted file mode 100644
index 6712b890f..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Com/ComRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// ComRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "ComHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NCom::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Compound", L"msi msp doc xls ppt", 0, 0xE5, { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 }, 8, false, CreateArc, 0 };
-
-REGISTER_ARC(Com)
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.cpp
deleted file mode 100644
index a19f04579..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// CoderMixer.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer.h"
-
-namespace NCoderMixer {
-
-void CCoderInfo::SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize)
-{
- InSizeAssigned = (inSize != 0);
- if (InSizeAssigned)
- InSizeValue = *inSize;
- OutSizeAssigned = (outSize != 0);
- if (OutSizeAssigned)
- OutSizeValue = *outSize;
-}
-
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.h b/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.h
deleted file mode 100644
index 6379dd808..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// CoderMixer.h
-
-#ifndef __CODER_MIXER_H
-#define __CODER_MIXER_H
-
-#include "../../../Common/MyCom.h"
-#include "../../ICoder.h"
-
-namespace NCoderMixer {
-
-struct CCoderInfo
-{
- CMyComPtr<ICompressCoder> Coder;
- CMyComPtr<ISequentialInStream> InStream;
- CMyComPtr<ISequentialOutStream> OutStream;
- CMyComPtr<ICompressProgressInfo> Progress;
-
- UInt64 InSizeValue;
- UInt64 OutSizeValue;
- bool InSizeAssigned;
- bool OutSizeAssigned;
-
- void ReInit()
- {
- InSizeAssigned = OutSizeAssigned = false;
- }
-
- void SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize);
-};
-
-}
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
deleted file mode 100644
index a59ce5fc0..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-// CoderMixer2ST.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixer2ST.h"
-
-namespace NCoderMixer2 {
-
-CCoderMixer2ST::CCoderMixer2ST() {}
-
-CCoderMixer2ST::~CCoderMixer2ST(){ }
-
-HRESULT CCoderMixer2ST::SetBindInfo(const CBindInfo &bindInfo)
-{
- _bindInfo = bindInfo;
- return S_OK;
-}
-
-void CCoderMixer2ST::AddCoderCommon(bool isMain)
-{
- const CCoderStreamsInfo &csi = _bindInfo.Coders[_coders.Size()];
- _coders.Add(CSTCoderInfo(csi.NumInStreams, csi.NumOutStreams, isMain));
-}
-
-void CCoderMixer2ST::AddCoder(ICompressCoder *coder, bool isMain)
-{
- AddCoderCommon(isMain);
- _coders.Back().Coder = coder;
-}
-
-void CCoderMixer2ST::AddCoder2(ICompressCoder2 *coder, bool isMain)
-{
- AddCoderCommon(isMain);
- _coders.Back().Coder2 = coder;
-}
-
-void CCoderMixer2ST::ReInit() { }
-
-HRESULT CCoderMixer2ST::GetInStream(
- ISequentialInStream **inStreams, const UInt64 **inSizes,
- UInt32 streamIndex, ISequentialInStream **inStreamRes)
-{
- CMyComPtr<ISequentialInStream> seqInStream;
- int i;
- for(i = 0; i < _bindInfo.InStreams.Size(); i++)
- if (_bindInfo.InStreams[i] == streamIndex)
- {
- seqInStream = inStreams[i];
- *inStreamRes = seqInStream.Detach();
- return S_OK;
- }
- int binderIndex = _bindInfo.FindBinderForInStream(streamIndex);
- if (binderIndex < 0)
- return E_INVALIDARG;
-
- UInt32 coderIndex, coderStreamIndex;
- _bindInfo.FindOutStream(_bindInfo.BindPairs[binderIndex].OutIndex,
- coderIndex, coderStreamIndex);
-
- CCoderInfo &coder = _coders[coderIndex];
- if (!coder.Coder)
- return E_NOTIMPL;
- coder.Coder.QueryInterface(IID_ISequentialInStream, &seqInStream);
- if (!seqInStream)
- return E_NOTIMPL;
-
- UInt32 startIndex = _bindInfo.GetCoderInStreamIndex(coderIndex);
-
- CMyComPtr<ICompressSetInStream> setInStream;
- if (!coder.Coder)
- return E_NOTIMPL;
- coder.Coder.QueryInterface(IID_ICompressSetInStream, &setInStream);
- if (!setInStream)
- return E_NOTIMPL;
-
- if (coder.NumInStreams > 1)
- return E_NOTIMPL;
- for (i = 0; i < (int)coder.NumInStreams; i++)
- {
- CMyComPtr<ISequentialInStream> seqInStream2;
- RINOK(GetInStream(inStreams, inSizes, startIndex + i, &seqInStream2));
- RINOK(setInStream->SetInStream(seqInStream2));
- }
- *inStreamRes = seqInStream.Detach();
- return S_OK;
-}
-
-HRESULT CCoderMixer2ST::GetOutStream(
- ISequentialOutStream **outStreams, const UInt64 **outSizes,
- UInt32 streamIndex, ISequentialOutStream **outStreamRes)
-{
- CMyComPtr<ISequentialOutStream> seqOutStream;
- int i;
- for(i = 0; i < _bindInfo.OutStreams.Size(); i++)
- if (_bindInfo.OutStreams[i] == streamIndex)
- {
- seqOutStream = outStreams[i];
- *outStreamRes = seqOutStream.Detach();
- return S_OK;
- }
- int binderIndex = _bindInfo.FindBinderForOutStream(streamIndex);
- if (binderIndex < 0)
- return E_INVALIDARG;
-
- UInt32 coderIndex, coderStreamIndex;
- _bindInfo.FindInStream(_bindInfo.BindPairs[binderIndex].InIndex,
- coderIndex, coderStreamIndex);
-
- CCoderInfo &coder = _coders[coderIndex];
- if (!coder.Coder)
- return E_NOTIMPL;
- coder.Coder.QueryInterface(IID_ISequentialOutStream, &seqOutStream);
- if (!seqOutStream)
- return E_NOTIMPL;
-
- UInt32 startIndex = _bindInfo.GetCoderOutStreamIndex(coderIndex);
-
- CMyComPtr<ICompressSetOutStream> setOutStream;
- if (!coder.Coder)
- return E_NOTIMPL;
- coder.Coder.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
- if (!setOutStream)
- return E_NOTIMPL;
-
- if (coder.NumOutStreams > 1)
- return E_NOTIMPL;
- for (i = 0; i < (int)coder.NumOutStreams; i++)
- {
- CMyComPtr<ISequentialOutStream> seqOutStream2;
- RINOK(GetOutStream(outStreams, outSizes, startIndex + i, &seqOutStream2));
- RINOK(setOutStream->SetOutStream(seqOutStream2));
- }
- *outStreamRes = seqOutStream.Detach();
- return S_OK;
-}
-
-
-STDMETHODIMP CCoderMixer2ST::Code(ISequentialInStream **inStreams,
- const UInt64 **inSizes,
- UInt32 numInStreams,
- ISequentialOutStream **outStreams,
- const UInt64 **outSizes,
- UInt32 numOutStreams,
- ICompressProgressInfo *progress)
-{
- if (numInStreams != (UInt32)_bindInfo.InStreams.Size() ||
- numOutStreams != (UInt32)_bindInfo.OutStreams.Size())
- return E_INVALIDARG;
-
- // Find main coder
- int _mainCoderIndex = -1;
- int i;
- for (i = 0; i < _coders.Size(); i++)
- if (_coders[i].IsMain)
- {
- _mainCoderIndex = i;
- break;
- }
- if (_mainCoderIndex < 0)
- for (i = 0; i < _coders.Size(); i++)
- if (_coders[i].NumInStreams > 1)
- {
- if (_mainCoderIndex >= 0)
- return E_NOTIMPL;
- _mainCoderIndex = i;
- }
- if (_mainCoderIndex < 0)
- _mainCoderIndex = 0;
-
- // _mainCoderIndex = 0;
- // _mainCoderIndex = _coders.Size() - 1;
- CCoderInfo &mainCoder = _coders[_mainCoderIndex];
-
- CObjectVector< CMyComPtr<ISequentialInStream> > seqInStreams;
- CObjectVector< CMyComPtr<ISequentialOutStream> > seqOutStreams;
- UInt32 startInIndex = _bindInfo.GetCoderInStreamIndex(_mainCoderIndex);
- UInt32 startOutIndex = _bindInfo.GetCoderOutStreamIndex(_mainCoderIndex);
- for (i = 0; i < (int)mainCoder.NumInStreams; i++)
- {
- CMyComPtr<ISequentialInStream> seqInStream;
- RINOK(GetInStream(inStreams, inSizes, startInIndex + i, &seqInStream));
- seqInStreams.Add(seqInStream);
- }
- for (i = 0; i < (int)mainCoder.NumOutStreams; i++)
- {
- CMyComPtr<ISequentialOutStream> seqOutStream;
- RINOK(GetOutStream(outStreams, outSizes, startOutIndex + i, &seqOutStream));
- seqOutStreams.Add(seqOutStream);
- }
- CRecordVector< ISequentialInStream * > seqInStreamsSpec;
- CRecordVector< ISequentialOutStream * > seqOutStreamsSpec;
- for (i = 0; i < (int)mainCoder.NumInStreams; i++)
- seqInStreamsSpec.Add(seqInStreams[i]);
- for (i = 0; i < (int)mainCoder.NumOutStreams; i++)
- seqOutStreamsSpec.Add(seqOutStreams[i]);
-
- for (i = 0; i < _coders.Size(); i++)
- {
- if (i == _mainCoderIndex)
- continue;
- CCoderInfo &coder = _coders[i];
- CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
- coder.Coder.QueryInterface(IID_ICompressSetOutStreamSize, &setOutStreamSize);
- if (setOutStreamSize)
- {
- RINOK(setOutStreamSize->SetOutStreamSize(coder.OutSizePointers[0]));
- }
- }
- if (mainCoder.Coder)
- {
- RINOK(mainCoder.Coder->Code(
- seqInStreamsSpec[0], seqOutStreamsSpec[0],
- mainCoder.InSizePointers[0], mainCoder.OutSizePointers[0],
- progress));
- }
- else
- {
- RINOK(mainCoder.Coder2->Code(
- &seqInStreamsSpec.Front(),
- &mainCoder.InSizePointers.Front(), mainCoder.NumInStreams,
- &seqOutStreamsSpec.Front(),
- &mainCoder.OutSizePointers.Front(), mainCoder.NumOutStreams,
- progress));
- }
- CMyComPtr<IOutStreamFlush> flush;
- seqOutStreams.Front().QueryInterface(IID_IOutStreamFlush, &flush);
- if (flush)
- return flush->Flush();
- return S_OK;
-}
-
-/*
-UInt64 CCoderMixer2ST::GetWriteProcessedSize(UInt32 binderIndex) const
-{
- return _streamBinders[binderIndex].ProcessedSize;
-}
-*/
-
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.h b/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.h
deleted file mode 100644
index a4ea7e80d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixer2ST.h
+++ /dev/null
@@ -1,88 +0,0 @@
-// CoderMixer2ST.h
-
-#ifndef __CODER_MIXER2_ST_H
-#define __CODER_MIXER2_ST_H
-
-#include "CoderMixer2.h"
-#include "../../../Common/MyCom.h"
-#include "../../ICoder.h"
-
-namespace NCoderMixer2 {
-
-// SetBindInfo()
-// for each coder
-// {
-// AddCoder[2]()
-// }
-//
-// for each file
-// {
-// ReInit()
-// for each coder
-// {
-// SetCoderInfo
-// }
-// SetProgressIndex(UInt32 coderIndex);
-// Code
-// }
-
-struct CSTCoderInfo: public CCoderInfo
-{
- bool IsMain;
- CSTCoderInfo(UInt32 numInStreams, UInt32 numOutStreams, bool isMain):
- CCoderInfo(numInStreams, numOutStreams),IsMain(isMain) {}
-};
-
-class CCoderMixer2ST:
- public ICompressCoder2,
- public CCoderMixer2,
- public CMyUnknownImp
-{
- MY_UNKNOWN_IMP
-
- HRESULT GetInStream(
- ISequentialInStream **inStreams, const UInt64 **inSizes,
- UInt32 streamIndex, ISequentialInStream **inStreamRes);
- HRESULT GetOutStream(
- ISequentialOutStream **outStreams, const UInt64 **outSizes,
- UInt32 streamIndex, ISequentialOutStream **outStreamRes);
-public:
- STDMETHOD(Code)(ISequentialInStream **inStreams,
- const UInt64 **inSizes,
- UInt32 numInStreams,
- ISequentialOutStream **outStreams,
- const UInt64 **outSizes,
- UInt32 numOutStreams,
- ICompressProgressInfo *progress);
-
- CCoderMixer2ST();
- ~CCoderMixer2ST();
- void AddCoderCommon(bool isMain);
- void AddCoder(ICompressCoder *coder, bool isMain);
- void AddCoder2(ICompressCoder2 *coder, bool isMain);
-
- void ReInit();
- void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
- {
- { _coders[coderIndex].SetCoderInfo(inSizes, outSizes); }
- }
-
- void SetProgressCoderIndex(UInt32 /*coderIndex*/)
- {
- // _progressCoderIndex = coderIndex;
- }
-
- // UInt64 GetWriteProcessedSize(UInt32 binderIndex) const;
-
-private:
- CBindInfo _bindInfo;
- CObjectVector<CSTCoderInfo> _coders;
- int _mainCoderIndex;
-public:
- HRESULT SetBindInfo(const CBindInfo &bindInfo);
-
-};
-
-}
-#endif
-
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.cpp
deleted file mode 100644
index f43d1612d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-// CoderMixerMT.cpp
-
-#include "StdAfx.h"
-
-#include "CoderMixerMT.h"
-
-namespace NCoderMixer {
-
-void CCoder::Execute() { Code(NULL); }
-
-void CCoder::Code(ICompressProgressInfo *progress)
-{
- Result = Coder->Code(InStream, OutStream,
- InSizeAssigned ? &InSizeValue : NULL,
- OutSizeAssigned ? &OutSizeValue : NULL,
- progress);
- InStream.Release();
- OutStream.Release();
-}
-
-void CCoderMixerMT::AddCoder(ICompressCoder *coder)
-{
- _coders.Add(CCoder());
- _coders.Back().Coder = coder;
-}
-
-void CCoderMixerMT::ReInit()
-{
- for(int i = 0; i < _coders.Size(); i++)
- _coders[i].ReInit();
-}
-
-HRESULT CCoderMixerMT::ReturnIfError(HRESULT code)
-{
- for (int i = 0; i < _coders.Size(); i++)
- if (_coders[i].Result == code)
- return code;
- return S_OK;
-}
-
-STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 * /* inSize */, const UInt64 * /* outSize */,
- ICompressProgressInfo *progress)
-{
- _coders.Front().InStream = inStream;
- int i;
- _coders.Back().OutStream = outStream;
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- {
- RINOK(_coders[i].Create());
- }
-
- _streamBinders.Clear();
- for (i = 0; i + 1 < _coders.Size(); i++)
- {
- _streamBinders.Add(CStreamBinder());
- CStreamBinder &sb = _streamBinders[i];
- RINOK(sb.CreateEvents());
- sb.CreateStreams(&_coders[i + 1].InStream, &_coders[i].OutStream);
- }
-
- for(i = 0; i < _streamBinders.Size(); i++)
- _streamBinders[i].ReInit();
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- _coders[i].Start();
-
- _coders[_progressCoderIndex].Code(progress);
-
- for (i = 0; i < _coders.Size(); i++)
- if (i != _progressCoderIndex)
- _coders[i].WaitFinish();
-
- RINOK(ReturnIfError(E_ABORT));
- RINOK(ReturnIfError(E_OUTOFMEMORY));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK && result != E_FAIL && result != S_FALSE)
- return result;
- }
-
- RINOK(ReturnIfError(S_FALSE));
-
- for (i = 0; i < _coders.Size(); i++)
- {
- HRESULT result = _coders[i].Result;
- if (result != S_OK)
- return result;
- }
- return S_OK;
-}
-
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.h b/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.h
deleted file mode 100644
index c70e1829f..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/CoderMixerMT.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// CoderMixerMT.h
-
-#ifndef __CODER_MIXER_MT_H
-#define __CODER_MIXER_MT_H
-
-#include "../../../Common/MyVector.h"
-#include "../../../Common/MyCom.h"
-#include "../../ICoder.h"
-#include "../../Common/StreamBinder.h"
-#include "../../Common/VirtThread.h"
-#include "CoderMixer.h"
-
-namespace NCoderMixer {
-
-struct CCoder: public CCoderInfo, public CVirtThread
-{
- HRESULT Result;
-
- virtual void Execute();
- void Code(ICompressProgressInfo *progress);
-};
-
-/*
- for each coder
- AddCoder()
- SetProgressIndex(UInt32 coderIndex);
-
- for each file
- {
- ReInit()
- for each coder
- SetCoderInfo
- Code
- }
-*/
-
-
-class CCoderMixerMT:
- public ICompressCoder,
- public CMyUnknownImp
-{
- CObjectVector<CStreamBinder> _streamBinders;
- int _progressCoderIndex;
-
- HRESULT ReturnIfError(HRESULT code);
-public:
- CObjectVector<CCoder> _coders;
- MY_UNKNOWN_IMP
-
- STDMETHOD(Code)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
- const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-
- void AddCoder(ICompressCoder *coder);
- void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; }
-
- void ReInit();
- void SetCoderInfo(UInt32 coderIndex, const UInt64 *inSize, const UInt64 *outSize)
- { _coders[coderIndex].SetCoderInfo(inSize, outSize); }
-
- /*
- UInt64 GetWriteProcessedSize(UInt32 binderIndex) const
- { return _streamBinders[binderIndex].ProcessedSize; }
- */
-};
-
-}
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.cpp
deleted file mode 100644
index 15aa6ceae..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// FindSignature.cpp
-
-#include "StdAfx.h"
-
-#include "Common/Buffer.h"
-
-#include "FindSignature.h"
-
-#include "../../Common/StreamUtils.h"
-
-HRESULT FindSignatureInStream(ISequentialInStream *stream,
- const Byte *signature, unsigned signatureSize,
- const UInt64 *limit, UInt64 &resPos)
-{
- resPos = 0;
- CByteBuffer byteBuffer2;
- byteBuffer2.SetCapacity(signatureSize);
- RINOK(ReadStream_FALSE(stream, byteBuffer2, signatureSize));
-
- if (memcmp(byteBuffer2, signature, signatureSize) == 0)
- return S_OK;
-
- const UInt32 kBufferSize = (1 << 16);
- CByteBuffer byteBuffer;
- byteBuffer.SetCapacity(kBufferSize);
- Byte *buffer = byteBuffer;
- UInt32 numPrevBytes = signatureSize - 1;
- memcpy(buffer, (const Byte *)byteBuffer2 + 1, numPrevBytes);
- resPos = 1;
- for (;;)
- {
- if (limit != NULL)
- if (resPos > *limit)
- return S_FALSE;
- do
- {
- UInt32 numReadBytes = kBufferSize - numPrevBytes;
- UInt32 processedSize;
- RINOK(stream->Read(buffer + numPrevBytes, numReadBytes, &processedSize));
- numPrevBytes += processedSize;
- if (processedSize == 0)
- return S_FALSE;
- }
- while (numPrevBytes < signatureSize);
- UInt32 numTests = numPrevBytes - signatureSize + 1;
- for (UInt32 pos = 0; pos < numTests; pos++)
- {
- Byte b = signature[0];
- for (; buffer[pos] != b && pos < numTests; pos++);
- if (pos == numTests)
- break;
- if (memcmp(buffer + pos, signature, signatureSize) == 0)
- {
- resPos += pos;
- return S_OK;
- }
- }
- resPos += numTests;
- numPrevBytes -= numTests;
- memmove(buffer, buffer + numTests, numPrevBytes);
- }
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.h b/src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.h
deleted file mode 100644
index e15af5732..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/FindSignature.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// FindSignature.h
-
-#ifndef __FINDSIGNATURE_H
-#define __FINDSIGNATURE_H
-
-#include "../../IStream.h"
-
-HRESULT FindSignatureInStream(ISequentialInStream *stream,
- const Byte *signature, unsigned signatureSize,
- const UInt64 *limit, UInt64 &resPos);
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp
deleted file mode 100644
index 0526c1b1d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// OutStreamWithSha1.cpp
-
-#include "StdAfx.h"
-
-#include "OutStreamWithSha1.h"
-
-STDMETHODIMP COutStreamWithSha1::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- HRESULT result = S_OK;
- if (_stream)
- result = _stream->Write(data, size, &size);
- if (_calculate)
- _sha.Update((const Byte *)data, size);
- _size += size;
- if (processedSize != NULL)
- *processedSize = size;
- return result;
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.h b/src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.h
deleted file mode 100644
index 3bbfbbe19..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Common/OutStreamWithSha1.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// OutStreamWithSha1.h
-
-#ifndef __OUT_STREAM_WITH_SHA1_H
-#define __OUT_STREAM_WITH_SHA1_H
-
-#include "../../Crypto/Sha1.h"
-
-#include "../../../Common/MyCom.h"
-
-#include "../../IStream.h"
-
-class COutStreamWithSha1:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
- CMyComPtr<ISequentialOutStream> _stream;
- UInt64 _size;
- NCrypto::NSha1::CContext _sha;
- bool _calculate;
-public:
- MY_UNKNOWN_IMP
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
- void SetStream(ISequentialOutStream *stream) { _stream = stream; }
- void ReleaseStream() { _stream.Release(); }
- void Init(bool calculate = true)
- {
- _size = 0;
- _calculate = calculate;
- _sha.Init();
- }
- void InitSha1() { _sha.Init(); }
- UInt64 GetSize() const { return _size; }
- void Final(Byte *digest) { _sha.Final(digest); }
-};
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/CpioHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/CpioHandler.cpp
deleted file mode 100644
index 0f32ef663..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/CpioHandler.cpp
+++ /dev/null
@@ -1,624 +0,0 @@
-// CpioHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/StringConvert.h"
-#include "Common/StringToInt.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-
-#include "Common/ItemNameUtils.h"
-
-namespace NArchive {
-namespace NCpio {
-
-namespace NFileHeader
-{
- namespace NMagic
- {
- const char *kMagic1 = "070701";
- const char *kMagic2 = "070702";
- const char *kMagic3 = "070707";
- const char *kEndName = "TRAILER!!!";
-
- const Byte kMagicForRecord2[2] = { 0xC7, 0x71 };
- }
-
- const UInt32 kRecord2Size = 26;
- /*
- struct CRecord2
- {
- unsigned short c_magic;
- short c_dev;
- unsigned short c_ino;
- unsigned short c_mode;
- unsigned short c_uid;
- unsigned short c_gid;
- unsigned short c_nlink;
- short c_rdev;
- unsigned short c_mtimes[2];
- unsigned short c_namesize;
- unsigned short c_filesizes[2];
- };
- */
-
- const UInt32 kRecordSize = 110;
- /*
- struct CRecord
- {
- char Magic[6]; // "070701" for "new" portable format, "070702" for CRC format
- char inode[8];
- char Mode[8];
- char UID[8];
- char GID[8];
- char nlink[8];
- char mtime[8];
- char Size[8]; // must be 0 for FIFOs and directories
- char DevMajor[8];
- char DevMinor[8];
- char RDevMajor[8]; //only valid for chr and blk special files
- char RDevMinor[8]; //only valid for chr and blk special files
- char NameSize[8]; // count includes terminating NUL in pathname
- char ChkSum[8]; // 0 for "new" portable format; for CRC format the sum of all the bytes in the file
- bool CheckMagic() const
- { return memcmp(Magic, NMagic::kMagic1, 6) == 0 ||
- memcmp(Magic, NMagic::kMagic2, 6) == 0; };
- };
- */
-
- const UInt32 kOctRecordSize = 76;
-
-}
-
-struct CItem
-{
- AString Name;
- UInt32 inode;
- UInt32 Mode;
- UInt32 UID;
- UInt32 GID;
- UInt32 Size;
- UInt32 MTime;
-
- // char LinkFlag;
- // AString LinkName; ?????
- char Magic[8];
- UInt32 NumLinks;
- UInt32 DevMajor;
- UInt32 DevMinor;
- UInt32 RDevMajor;
- UInt32 RDevMinor;
- UInt32 ChkSum;
-
- UInt32 Align;
-
- bool IsDir() const { return (Mode & 0170000) == 0040000; }
-};
-
-class CItemEx: public CItem
-{
-public:
- UInt64 HeaderPosition;
- UInt32 HeaderSize;
- UInt64 GetDataPosition() const { return HeaderPosition + HeaderSize; };
-};
-
-const UInt32 kMaxBlockSize = NFileHeader::kRecordSize;
-
-class CInArchive
-{
- CMyComPtr<IInStream> m_Stream;
- UInt64 m_Position;
-
- UInt16 _blockSize;
- Byte _block[kMaxBlockSize];
- UInt32 _blockPos;
- Byte ReadByte();
- UInt16 ReadUInt16();
- UInt32 ReadUInt32();
-
- bool ReadNumber(UInt32 &resultValue);
- bool ReadOctNumber(int size, UInt32 &resultValue);
-
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
-public:
- HRESULT Open(IInStream *inStream);
- HRESULT GetNextItem(bool &filled, CItemEx &itemInfo);
- HRESULT Skip(UInt64 numBytes);
- HRESULT SkipDataRecords(UInt64 dataSize, UInt32 align);
-};
-
-HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
-{
- size_t realProcessedSize = size;
- RINOK(ReadStream(m_Stream, data, &realProcessedSize));
- processedSize = (UInt32)realProcessedSize;
- m_Position += processedSize;
- return S_OK;
-}
-
-Byte CInArchive::ReadByte()
-{
- if (_blockPos >= _blockSize)
- throw "Incorrect cpio archive";
- return _block[_blockPos++];
-}
-
-UInt16 CInArchive::ReadUInt16()
-{
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- {
- Byte b = ReadByte();
- value |= (UInt16(b) << (8 * i));
- }
- return value;
-}
-
-UInt32 CInArchive::ReadUInt32()
-{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- {
- Byte b = ReadByte();
- value |= (UInt32(b) << (8 * i));
- }
- return value;
-}
-
-HRESULT CInArchive::Open(IInStream *inStream)
-{
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Position));
- m_Stream = inStream;
- return S_OK;
-}
-
-bool CInArchive::ReadNumber(UInt32 &resultValue)
-{
- resultValue = 0;
- for (int i = 0; i < 8; i++)
- {
- char c = char(ReadByte());
- int d;
- if (c >= '0' && c <= '9')
- d = c - '0';
- else if (c >= 'A' && c <= 'F')
- d = 10 + c - 'A';
- else if (c >= 'a' && c <= 'f')
- d = 10 + c - 'a';
- else
- return false;
- resultValue *= 0x10;
- resultValue += d;
- }
- return true;
-}
-
-static bool OctalToNumber(const char *s, UInt64 &res)
-{
- const char *end;
- res = ConvertOctStringToUInt64(s, &end);
- return (*end == ' ' || *end == 0);
-}
-
-static bool OctalToNumber32(const char *s, UInt32 &res)
-{
- UInt64 res64;
- if (!OctalToNumber(s, res64))
- return false;
- res = (UInt32)res64;
- return (res64 <= 0xFFFFFFFF);
-}
-
-bool CInArchive::ReadOctNumber(int size, UInt32 &resultValue)
-{
- char sz[32 + 4];
- int i;
- for (i = 0; i < size && i < 32; i++)
- sz[i] = (char)ReadByte();
- sz[i] = 0;
- return OctalToNumber32(sz, resultValue);
-}
-
-#define GetFromHex(y) { if (!ReadNumber(y)) return S_FALSE; }
-#define GetFromOct6(y) { if (!ReadOctNumber(6, y)) return S_FALSE; }
-#define GetFromOct11(y) { if (!ReadOctNumber(11, y)) return S_FALSE; }
-
-static unsigned short ConvertValue(unsigned short value, bool convert)
-{
- if (!convert)
- return value;
- return (unsigned short)((((unsigned short)(value & 0xFF)) << 8) | (value >> 8));
-}
-
-static UInt32 GetAlignedSize(UInt32 size, UInt32 align)
-{
- while ((size & (align - 1)) != 0)
- size++;
- return size;
-}
-
-
-HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
-{
- filled = false;
-
- UInt32 processedSize;
- item.HeaderPosition = m_Position;
-
- _blockSize = kMaxBlockSize;
- RINOK(ReadBytes(_block, 2, processedSize));
- if (processedSize != 2)
- return S_FALSE;
- _blockPos = 0;
-
- UInt32 nameSize;
-
- bool oldBE =
- _block[0] == NFileHeader::NMagic::kMagicForRecord2[1] &&
- _block[1] == NFileHeader::NMagic::kMagicForRecord2[0];
-
- bool binMode = (_block[0] == NFileHeader::NMagic::kMagicForRecord2[0] &&
- _block[1] == NFileHeader::NMagic::kMagicForRecord2[1]) ||
- oldBE;
-
- if (binMode)
- {
- RINOK(ReadBytes(_block + 2, NFileHeader::kRecord2Size - 2, processedSize));
- if (processedSize != NFileHeader::kRecord2Size - 2)
- return S_FALSE;
- item.Align = 2;
- _blockPos = 2;
- item.DevMajor = 0;
- item.DevMinor = ConvertValue(ReadUInt16(), oldBE);
- item.inode = ConvertValue(ReadUInt16(), oldBE);
- item.Mode = ConvertValue(ReadUInt16(), oldBE);
- item.UID = ConvertValue(ReadUInt16(), oldBE);
- item.GID = ConvertValue(ReadUInt16(), oldBE);
- item.NumLinks = ConvertValue(ReadUInt16(), oldBE);
- item.RDevMajor =0;
- item.RDevMinor = ConvertValue(ReadUInt16(), oldBE);
- UInt16 timeHigh = ConvertValue(ReadUInt16(), oldBE);
- UInt16 timeLow = ConvertValue(ReadUInt16(), oldBE);
- item.MTime = (UInt32(timeHigh) << 16) + timeLow;
- nameSize = ConvertValue(ReadUInt16(), oldBE);
- UInt16 sizeHigh = ConvertValue(ReadUInt16(), oldBE);
- UInt16 sizeLow = ConvertValue(ReadUInt16(), oldBE);
- item.Size = (UInt32(sizeHigh) << 16) + sizeLow;
-
- item.ChkSum = 0;
- item.HeaderSize = GetAlignedSize(
- nameSize + NFileHeader::kRecord2Size, item.Align);
- nameSize = item.HeaderSize - NFileHeader::kRecord2Size;
- }
- else
- {
- RINOK(ReadBytes(_block + 2, 4, processedSize));
- if (processedSize != 4)
- return S_FALSE;
-
- bool magicOK =
- memcmp(_block, NFileHeader::NMagic::kMagic1, 6) == 0 ||
- memcmp(_block, NFileHeader::NMagic::kMagic2, 6) == 0;
- _blockPos = 6;
- if (magicOK)
- {
- RINOK(ReadBytes(_block + 6, NFileHeader::kRecordSize - 6, processedSize));
- if (processedSize != NFileHeader::kRecordSize - 6)
- return S_FALSE;
- item.Align = 4;
-
- GetFromHex(item.inode);
- GetFromHex(item.Mode);
- GetFromHex(item.UID);
- GetFromHex(item.GID);
- GetFromHex(item.NumLinks);
- UInt32 mTime;
- GetFromHex(mTime);
- item.MTime = mTime;
- GetFromHex(item.Size);
- GetFromHex(item.DevMajor);
- GetFromHex(item.DevMinor);
- GetFromHex(item.RDevMajor);
- GetFromHex(item.RDevMinor);
- GetFromHex(nameSize);
- GetFromHex(item.ChkSum);
- item.HeaderSize = GetAlignedSize(
- nameSize + NFileHeader::kRecordSize, item.Align);
- nameSize = item.HeaderSize - NFileHeader::kRecordSize;
- }
- else
- {
- if (!memcmp(_block, NFileHeader::NMagic::kMagic3, 6) == 0)
- return S_FALSE;
- RINOK(ReadBytes(_block + 6, NFileHeader::kOctRecordSize - 6, processedSize));
- if (processedSize != NFileHeader::kOctRecordSize - 6)
- return S_FALSE;
- item.Align = 1;
- item.DevMajor = 0;
- GetFromOct6(item.DevMinor);
- GetFromOct6(item.inode);
- GetFromOct6(item.Mode);
- GetFromOct6(item.UID);
- GetFromOct6(item.GID);
- GetFromOct6(item.NumLinks);
- item.RDevMajor = 0;
- GetFromOct6(item.RDevMinor);
- UInt32 mTime;
- GetFromOct11(mTime);
- item.MTime = mTime;
- GetFromOct6(nameSize);
- GetFromOct11(item.Size); // ?????
- item.HeaderSize = GetAlignedSize(
- nameSize + NFileHeader::kOctRecordSize, item.Align);
- nameSize = item.HeaderSize - NFileHeader::kOctRecordSize;
- }
- }
- if (nameSize == 0 || nameSize >= (1 << 27))
- return E_FAIL;
- RINOK(ReadBytes(item.Name.GetBuffer(nameSize), nameSize, processedSize));
- if (processedSize != nameSize)
- return E_FAIL;
- item.Name.ReleaseBuffer();
- if (strcmp(item.Name, NFileHeader::NMagic::kEndName) == 0)
- return S_OK;
- filled = true;
- return S_OK;
-}
-
-HRESULT CInArchive::Skip(UInt64 numBytes)
-{
- UInt64 newPostion;
- RINOK(m_Stream->Seek(numBytes, STREAM_SEEK_CUR, &newPostion));
- m_Position += numBytes;
- if (m_Position != newPostion)
- return E_FAIL;
- return S_OK;
-}
-
-HRESULT CInArchive::SkipDataRecords(UInt64 dataSize, UInt32 align)
-{
- while ((dataSize & (align - 1)) != 0)
- dataSize++;
- return Skip(dataSize);
-}
-
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CObjectVector<CItemEx> _items;
- CMyComPtr<IInStream> _stream;
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-/*
-enum
-{
- kpidinode = kpidUserDefined,
- kpidiChkSum
-};
-*/
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidPosixAttrib, VT_UI4},
- // { L"inode", kpidinode, VT_UI4}
- // { L"CheckSum", kpidiChkSum, VT_UI4}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- // try
- {
- CInArchive archive;
-
- UInt64 endPos = 0;
- bool needSetTotal = true;
-
- if (callback != NULL)
- {
- RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
- RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
- }
-
- RINOK(archive.Open(stream));
-
- _items.Clear();
-
- for (;;)
- {
- CItemEx item;
- bool filled;
- HRESULT result = archive.GetNextItem(filled, item);
- if (result == S_FALSE)
- return S_FALSE;
- if (result != S_OK)
- return S_FALSE;
- if (!filled)
- break;
- _items.Add(item);
- archive.SkipDataRecords(item.Size, item.Align);
- if (callback != NULL)
- {
- if (needSetTotal)
- {
- RINOK(callback->SetTotal(NULL, &endPos));
- needSetTotal = false;
- }
- if (_items.Size() % 100 == 0)
- {
- UInt64 numFiles = _items.Size();
- UInt64 numBytes = item.HeaderPosition;
- RINOK(callback->SetCompleted(&numFiles, &numBytes));
- }
- }
- }
- if (_items.Size() == 0)
- return S_FALSE;
-
- _stream = stream;
- }
- /*
- catch(...)
- {
- return S_FALSE;
- }
- */
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _items.Clear();
- _stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItemEx &item = _items[index];
-
- switch(propID)
- {
- case kpidPath: prop = NItemName::GetOSName(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break;
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize:
- case kpidPackSize:
- prop = (UInt64)item.Size;
- break;
- case kpidMTime:
- {
- if (item.MTime != 0)
- {
- FILETIME utc;
- NWindows::NTime::UnixTimeToFileTime(item.MTime, utc);
- prop = utc;
- }
- break;
- }
- case kpidPosixAttrib: prop = item.Mode; break;
- /*
- case kpidinode: prop = item.inode; break;
- case kpidiChkSum: prop = item.ChkSum; break;
- */
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _items.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- totalSize += _items[allFilesMode ? i : indices[i]].Size;
- extractCallback->SetTotal(totalSize);
-
- UInt64 currentTotalSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_stream);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = lps->OutSize = currentTotalSize;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> outStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItemEx &item = _items[index];
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- currentTotalSize += item.Size;
- if (item.IsDir())
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- if (!testMode && !outStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- if (testMode)
- {
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- RINOK(_stream->Seek(item.GetDataPosition(), STREAM_SEEK_SET, NULL));
- streamSpec->Init(item.Size);
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
- outStream.Release();
- RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- const CItemEx &item = _items[index];
- return CreateLimitedInStream(_stream, item.GetDataPosition(), item.Size, stream);
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new NArchive::NCpio::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Cpio", L"cpio", 0, 0xED, { 0 }, 0, false, CreateArc, 0 };
-
-REGISTER_ARC(Cpio)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/CramfsHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/CramfsHandler.cpp
deleted file mode 100644
index a55e3743d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/CramfsHandler.cpp
+++ /dev/null
@@ -1,644 +0,0 @@
-// CramfsHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/7zCrc.h"
-#include "../../../C/CpuArch.h"
-#include "../../../C/Alloc.h"
-
-#include "Common/ComTry.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariantUtils.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamObjects.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-#include "../Compress/ZlibDecoder.h"
-
-namespace NArchive {
-namespace NCramfs {
-
-#define SIGNATURE { 'C','o','m','p','r','e','s','s','e','d',' ','R','O','M','F','S' }
-
-static const UInt32 kSignatureSize = 16;
-static const char kSignature[kSignatureSize] = SIGNATURE;
-
-static const UInt32 kArcSizeMax = (256 + 16) << 20;
-static const UInt32 kNumFilesMax = (1 << 19);
-static const unsigned kNumDirLevelsMax = (1 << 8);
-
-static const UInt32 kHeaderSize = 0x40;
-static const unsigned kHeaderNameSize = 16;
-static const UInt32 kNodeSize = 12;
-
-static const UInt32 kFlag_FsVer2 = (1 << 0);
-
-static const CUInt32PCharPair k_Flags[] =
-{
- { 0, "Ver2" },
- { 1, "SortedDirs" },
- { 8, "Holes" },
- { 9, "WrongSignature" },
- { 10, "ShiftedRootOffset" }
-};
-
-static const unsigned kBlockSizeLog = 12;
-static const UInt32 kBlockSize = 1 << kBlockSizeLog;
-
-/*
-struct CNode
-{
- UInt16 Mode;
- UInt16 Uid;
- UInt32 Size;
- Byte Gid;
- UInt32 NameLen;
- UInt32 Offset;
-
- void Parse(const Byte *p)
- {
- Mode = GetUi16(p);
- Uid = GetUi16(p + 2);
- Size = Get32(p + 4) & 0xFFFFFF;
- Gid = p[7];
- NameLen = p[8] & 0x3F;
- Offset = Get32(p + 8) >> 6;
- }
-};
-*/
-
-#define Get32(p) (be ? GetBe32(p) : GetUi32(p))
-
-static UInt32 GetMode(const Byte *p, bool be) { return be ? GetBe16(p) : GetUi16(p); }
-static bool IsDir(const Byte *p, bool be) { return (GetMode(p, be) & 0xF000) == 0x4000; }
-
-static UInt32 GetSize(const Byte *p, bool be)
-{
- if (be)
- return GetBe32(p + 4) >> 8;
- else
- return GetUi32(p + 4) & 0xFFFFFF;
-}
-
-static UInt32 GetNameLen(const Byte *p, bool be)
-{
- if (be)
- return (p[8] & 0xFC);
- else
- return (p[8] & 0x3F) << 2;
-}
-
-static UInt32 GetOffset(const Byte *p, bool be)
-{
- if (be)
- return (GetBe32(p + 8) & 0x03FFFFFF) << 2;
- else
- return GetUi32(p + 8) >> 6 << 2;
-}
-
-struct CItem
-{
- UInt32 Offset;
- int Parent;
-};
-
-struct CHeader
-{
- bool be;
- UInt32 Size;
- UInt32 Flags;
- // UInt32 Future;
- UInt32 Crc;
- // UInt32 Edition;
- UInt32 NumBlocks;
- UInt32 NumFiles;
- char Name[kHeaderNameSize];
-
- bool Parse(const Byte *p)
- {
- if (memcmp(p + 16, kSignature, kSignatureSize) != 0)
- return false;
- switch(GetUi32(p))
- {
- case 0x28CD3D45: be = false; break;
- case 0x453DCD28: be = true; break;
- default: return false;
- }
- Size = Get32(p + 4);
- Flags = Get32(p + 8);
- // Future = Get32(p + 0xC);
- Crc = Get32(p + 0x20);
- // Edition = Get32(p + 0x24);
- NumBlocks = Get32(p + 0x28);
- NumFiles = Get32(p + 0x2C);
- memcpy(Name, p + 0x30, kHeaderNameSize);
- return true;
- }
-
- bool IsVer2() const { return (Flags & kFlag_FsVer2) != 0; }
-};
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CRecordVector<CItem> _items;
- CMyComPtr<IInStream> _stream;
- Byte *_data;
- UInt32 _size;
- UInt32 _headersSize;
- AString _errorMessage;
- CHeader _h;
-
- // Current file
-
- NCompress::NZlib::CDecoder *_zlibDecoderSpec;
- CMyComPtr<ICompressCoder> _zlibDecoder;
-
- CBufInStream *_inStreamSpec;
- CMyComPtr<ISequentialInStream> _inStream;
-
- CBufPtrSeqOutStream *_outStreamSpec;
- CMyComPtr<ISequentialOutStream> _outStream;
-
- UInt32 _curBlocksOffset;
- UInt32 _curNumBlocks;
-
- HRESULT OpenDir(int parent, UInt32 baseOffsetBase, unsigned level);
- HRESULT Open2(IInStream *inStream);
- AString GetPath(int index) const;
- bool GetPackSize(int index, UInt32 &res) const;
- void Free();
-public:
- CHandler(): _data(0) {}
- ~CHandler() { Free(); }
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
- HRESULT ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize);
-};
-
-static const STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI4},
- { NULL, kpidPackSize, VT_UI4},
- { NULL, kpidPosixAttrib, VT_UI4}
- // { NULL, kpidOffset, VT_UI4}
-};
-
-static const STATPROPSTG kArcProps[] =
-{
- { NULL, kpidName, VT_BSTR},
- { NULL, kpidBigEndian, VT_BOOL},
- { NULL, kpidCharacts, VT_BSTR},
- { NULL, kpidPhySize, VT_UI4},
- { NULL, kpidHeadersSize, VT_UI4},
- { NULL, kpidNumSubFiles, VT_UI4},
- { NULL, kpidNumBlocks, VT_UI4}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-HRESULT CHandler::OpenDir(int parent, UInt32 baseOffset, unsigned level)
-{
- const Byte *p = _data + baseOffset;
- bool be = _h.be;
- if (!IsDir(p, be))
- return S_OK;
- UInt32 offset = GetOffset(p, be);
- UInt32 size = GetSize(p, be);
- if (offset == 0 && size == 0)
- return S_OK;
- UInt32 end = offset + size;
- if (offset < kHeaderSize || end > _size || level > kNumDirLevelsMax)
- return S_FALSE;
- if (end > _headersSize)
- _headersSize = end;
-
- int startIndex = _items.Size();
-
- while (size != 0)
- {
- if (size < kNodeSize || (UInt32)_items.Size() >= kNumFilesMax)
- return S_FALSE;
- CItem item;
- item.Parent = parent;
- item.Offset = offset;
- _items.Add(item);
- UInt32 nodeLen = kNodeSize + GetNameLen(_data + offset, be);
- if (size < nodeLen)
- return S_FALSE;
- offset += nodeLen;
- size -= nodeLen;
- }
-
- int endIndex = _items.Size();
- for (int i = startIndex; i < endIndex; i++)
- {
- RINOK(OpenDir(i, _items[i].Offset, level + 1));
- }
- return S_OK;
-}
-
-HRESULT CHandler::Open2(IInStream *inStream)
-{
- Byte buf[kHeaderSize];
- RINOK(ReadStream_FALSE(inStream, buf, kHeaderSize));
- if (!_h.Parse(buf))
- return S_FALSE;
- if (_h.IsVer2())
- {
- if (_h.Size < kHeaderSize || _h.Size > kArcSizeMax || _h.NumFiles > kNumFilesMax)
- return S_FALSE;
- }
- else
- {
- UInt64 size;
- RINOK(inStream->Seek(0, STREAM_SEEK_END, &size));
- if (size > kArcSizeMax)
- return S_FALSE;
- _h.Size = (UInt32)size;
- RINOK(inStream->Seek(kHeaderSize, STREAM_SEEK_SET, NULL));
- }
- _data = (Byte *)MidAlloc(_h.Size);
- if (_data == 0)
- return E_OUTOFMEMORY;
- memcpy(_data, buf, kHeaderSize);
- size_t processed = _h.Size - kHeaderSize;
- RINOK(ReadStream(inStream, _data + kHeaderSize, &processed));
- if (processed < kNodeSize)
- return S_FALSE;
- _size = kHeaderSize + (UInt32)processed;
- if (_size != _h.Size)
- _errorMessage = "Unexpected end of archive";
- else
- {
- SetUi32(_data + 0x20, 0);
- if (_h.IsVer2())
- if (CrcCalc(_data, _h.Size) != _h.Crc)
- _errorMessage = "CRC error";
- }
- if (_h.IsVer2())
- _items.Reserve(_h.NumFiles - 1);
- return OpenDir(-1, kHeaderSize, 0);
-}
-
-AString CHandler::GetPath(int index) const
-{
- unsigned len = 0;
- int indexMem = index;
- do
- {
- const CItem &item = _items[index];
- index = item.Parent;
- const Byte *p = _data + item.Offset;
- unsigned size = GetNameLen(p, _h.be);
- p += kNodeSize;
- unsigned i;
- for (i = 0; i < size && p[i]; i++);
- len += i + 1;
- }
- while (index >= 0);
- len--;
-
- AString path;
- char *dest = path.GetBuffer(len) + len;
- index = indexMem;
- for (;;)
- {
- const CItem &item = _items[index];
- index = item.Parent;
- const Byte *p = _data + item.Offset;
- unsigned size = GetNameLen(p, _h.be);
- p += kNodeSize;
- unsigned i;
- for (i = 0; i < size && p[i]; i++);
- dest -= i;
- memcpy(dest, p, i);
- if (index < 0)
- break;
- *(--dest) = CHAR_PATH_SEPARATOR;
- }
- path.ReleaseBuffer(len);
- return path;
-}
-
-bool CHandler::GetPackSize(int index, UInt32 &res) const
-{
- const CItem &item = _items[index];
- const Byte *p = _data + item.Offset;
- bool be = _h.be;
- UInt32 offset = GetOffset(p, be);
- if (offset < kHeaderSize)
- return false;
- UInt32 numBlocks = (GetSize(p, be) + kBlockSize - 1) >> kBlockSizeLog;
- UInt32 start = offset + numBlocks * 4;
- if (start > _size)
- return false;
- UInt32 end = Get32(_data + start - 4);
- if (end < start)
- return false;
- res = end - start;
- return true;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback * /* callback */)
-{
- COM_TRY_BEGIN
- {
- Close();
- RINOK(Open2(stream));
- _stream = stream;
- }
- return S_OK;
- COM_TRY_END
-}
-
-void CHandler::Free()
-{
- MidFree(_data);
- _data = 0;
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _headersSize = 0;
- _items.Clear();
- _stream.Release();
- _errorMessage.Empty();
- Free();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidName:
- {
- char dest[kHeaderNameSize + 4];
- memcpy(dest, _h.Name, kHeaderNameSize);
- dest[kHeaderNameSize] = 0;
- prop = dest;
- break;
- }
- case kpidBigEndian: prop = _h.be; break;
- case kpidCharacts: FLAGS_TO_PROP(k_Flags, _h.Flags, prop); break;
- case kpidNumBlocks: if (_h.IsVer2()) prop = _h.NumBlocks; break;
- case kpidNumSubFiles: if (_h.IsVer2()) prop = _h.NumFiles; break;
- case kpidPhySize: if (_h.IsVer2()) prop = _h.Size; break;
- case kpidHeadersSize: prop = _headersSize; break;
- case kpidError: if (!_errorMessage.IsEmpty()) prop = _errorMessage; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItem &item = _items[index];
- const Byte *p = _data + item.Offset;
- bool be = _h.be;
- bool isDir = IsDir(p, be);
- switch(propID)
- {
- case kpidPath: prop = MultiByteToUnicodeString(GetPath(index), CP_OEMCP); break;
- case kpidIsDir: prop = isDir; break;
- // case kpidOffset: prop = (UInt32)GetOffset(p, be); break;
- case kpidSize: if (!isDir) prop = GetSize(p, be); break;
- case kpidPackSize:
- if (!isDir)
- {
- UInt32 size;
- if (GetPackSize(index, size))
- prop = size;
- }
- break;
- case kpidPosixAttrib: prop = (UInt32)GetMode(p, be); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-class CCramfsInStream: public CCachedInStream
-{
- HRESULT ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize);
-public:
- CHandler *Handler;
-};
-
-HRESULT CCramfsInStream::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
-{
- return Handler->ReadBlock(blockIndex, dest, blockSize);
-}
-
-HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
-{
- if (!_zlibDecoder)
- {
- _zlibDecoderSpec = new NCompress::NZlib::CDecoder();
- _zlibDecoder = _zlibDecoderSpec;
- }
- if (!_inStream)
- {
- _inStreamSpec = new CBufInStream();
- _inStream = _inStreamSpec;
- }
- if (!_outStream)
- {
- _outStreamSpec = new CBufPtrSeqOutStream();
- _outStream = _outStreamSpec;
- }
- bool be = _h.be;
- const Byte *p = _data + (_curBlocksOffset + (UInt32)blockIndex * 4);
- UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p - 4));
- UInt32 end = Get32(p);
- if (end < start || end > _size)
- return S_FALSE;
- UInt32 inSize = end - start;
- _inStreamSpec->Init(_data + start, inSize);
- _outStreamSpec->Init(dest, blockSize);
- RINOK(_zlibDecoder->Code(_inStream, _outStream, NULL, NULL, NULL));
- return (_zlibDecoderSpec->GetInputProcessedSize() == inSize &&
- _outStreamSpec->GetPos() == blockSize) ? S_OK : S_FALSE;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _items.Size();
- if (numItems == 0)
- return S_OK;
- bool be = _h.be;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- {
- const Byte *p = _data + _items[allFilesMode ? i : indices[i]].Offset;
- if (!IsDir(p, be))
- totalSize += GetSize(p, be);
- }
- extractCallback->SetTotal(totalSize);
-
- UInt64 totalPackSize;
- totalSize = totalPackSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_stream);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = totalPackSize;
- lps->OutSize = totalSize;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> outStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- UInt32 index = allFilesMode ? i : indices[i];
- const CItem &item = _items[index];
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- const Byte *p = _data + item.Offset;
-
- if (IsDir(p, be))
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- UInt32 curSize = GetSize(p, be);
- totalSize += curSize;
- UInt32 packSize;
- if (GetPackSize(index, packSize))
- totalPackSize += packSize;
-
- if (!testMode && !outStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
-
- UInt32 offset = GetOffset(p, be);
- if (offset < kHeaderSize)
- curSize = 0;
-
- int res = NExtract::NOperationResult::kDataError;
- {
- CMyComPtr<ISequentialInStream> inSeqStream;
- CMyComPtr<IInStream> inStream;
- HRESULT hres = GetStream(index, &inSeqStream);
- if (inSeqStream)
- inSeqStream.QueryInterface(IID_IInStream, &inStream);
- if (hres == E_OUTOFMEMORY)
- return E_OUTOFMEMORY;
- if (hres == S_FALSE || !inStream)
- res = NExtract::NOperationResult::kUnSupportedMethod;
- else
- {
- RINOK(hres);
- if (inStream)
- {
- HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
- if (hres != S_OK && hres != S_FALSE)
- {
- RINOK(hres);
- }
- if (copyCoderSpec->TotalSize == curSize && hres == S_OK)
- res = NExtract::NOperationResult::kOK;
- }
- }
- }
- RINOK(extractCallback->SetOperationResult(res));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
-
- const CItem &item = _items[index];
- const Byte *p = _data + item.Offset;
-
- bool be = _h.be;
- if (IsDir(p, be))
- return E_FAIL;
-
- UInt32 size = GetSize(p, be);
- UInt32 numBlocks = (size + kBlockSize - 1) >> kBlockSizeLog;
- UInt32 offset = GetOffset(p, be);
- if (offset < kHeaderSize)
- {
- if (offset != 0)
- return S_FALSE;
- CBufInStream *streamSpec = new CBufInStream;
- CMyComPtr<IInStream> streamTemp = streamSpec;
- streamSpec->Init(NULL, 0);
- *stream = streamTemp.Detach();
- return S_OK;
- }
-
- if (offset + numBlocks * 4 > _size)
- return S_FALSE;
- UInt32 prev = offset;
- for (UInt32 i = 0; i < numBlocks; i++)
- {
- UInt32 next = Get32(_data + offset + i * 4);
- if (next < prev || next > _size)
- return S_FALSE;
- prev = next;
- }
-
- CCramfsInStream *streamSpec = new CCramfsInStream;
- CMyComPtr<IInStream> streamTemp = streamSpec;
- _curNumBlocks = numBlocks;
- _curBlocksOffset = offset;
- streamSpec->Handler = this;
- if (!streamSpec->Alloc(kBlockSizeLog, 21 - kBlockSizeLog))
- return E_OUTOFMEMORY;
- streamSpec->Init(size);
- *stream = streamTemp.Detach();
-
- return S_OK;
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new NArchive::NCramfs::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"CramFS", L"cramfs", 0, 0xD3, SIGNATURE, kSignatureSize, false, CreateArc, 0 };
-
-REGISTER_ARC(Cramfs)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/DebHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/DebHandler.cpp
deleted file mode 100644
index 82d2cde88..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/DebHandler.cpp
+++ /dev/null
@@ -1,413 +0,0 @@
-// DebHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/StringConvert.h"
-#include "Common/StringToInt.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-
-#include "Common/ItemNameUtils.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-namespace NArchive {
-namespace NDeb {
-
-namespace NHeader
-{
- const int kSignatureLen = 8;
-
- const char *kSignature = "!<arch>\n";
-
- const int kNameSize = 16;
- const int kTimeSize = 12;
- const int kModeSize = 8;
- const int kSizeSize = 10;
-
- /*
- struct CHeader
- {
- char Name[kNameSize];
- char MTime[kTimeSize];
- char Number0[6];
- char Number1[6];
- char Mode[kModeSize];
- char Size[kSizeSize];
- char Quote;
- char NewLine;
- };
- */
- const int kHeaderSize = kNameSize + kTimeSize + 6 + 6 + kModeSize + kSizeSize + 1 + 1;
-}
-
-struct CItem
-{
- AString Name;
- UInt64 Size;
- UInt32 MTime;
- UInt32 Mode;
-
- UInt64 HeaderPos;
- UInt64 GetDataPos() const { return HeaderPos + NHeader::kHeaderSize; };
- // UInt64 GetFullSize() const { return NFileHeader::kRecordSize + Size; };
-};
-
-class CInArchive
-{
- CMyComPtr<IInStream> m_Stream;
-
- HRESULT GetNextItemReal(bool &filled, CItem &itemInfo);
-public:
- UInt64 m_Position;
- HRESULT Open(IInStream *inStream);
- HRESULT GetNextItem(bool &filled, CItem &itemInfo);
- HRESULT SkipData(UInt64 dataSize);
-};
-
-HRESULT CInArchive::Open(IInStream *inStream)
-{
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Position));
- char signature[NHeader::kSignatureLen];
- RINOK(ReadStream_FALSE(inStream, signature, NHeader::kSignatureLen));
- m_Position += NHeader::kSignatureLen;
- if (memcmp(signature, NHeader::kSignature, NHeader::kSignatureLen) != 0)
- return S_FALSE;
- m_Stream = inStream;
- return S_OK;
-}
-
-static void MyStrNCpy(char *dest, const char *src, int size)
-{
- for (int i = 0; i < size; i++)
- {
- char c = src[i];
- dest[i] = c;
- if (c == 0)
- break;
- }
-}
-
-static bool OctalToNumber(const char *s, int size, UInt64 &res)
-{
- char sz[32];
- MyStrNCpy(sz, s, size);
- sz[size] = 0;
- const char *end;
- int i;
- for (i = 0; sz[i] == ' '; i++);
- res = ConvertOctStringToUInt64(sz + i, &end);
- return (*end == ' ' || *end == 0);
-}
-
-static bool OctalToNumber32(const char *s, int size, UInt32 &res)
-{
- UInt64 res64;
- if (!OctalToNumber(s, size, res64))
- return false;
- res = (UInt32)res64;
- return (res64 <= 0xFFFFFFFF);
-}
-
-static bool DecimalToNumber(const char *s, int size, UInt64 &res)
-{
- char sz[32];
- MyStrNCpy(sz, s, size);
- sz[size] = 0;
- const char *end;
- int i;
- for (i = 0; sz[i] == ' '; i++);
- res = ConvertStringToUInt64(sz + i, &end);
- return (*end == ' ' || *end == 0);
-}
-
-static bool DecimalToNumber32(const char *s, int size, UInt32 &res)
-{
- UInt64 res64;
- if (!DecimalToNumber(s, size, res64))
- return false;
- res = (UInt32)res64;
- return (res64 <= 0xFFFFFFFF);
-}
-
-#define RIF(x) { if (!(x)) return S_FALSE; }
-
-
-HRESULT CInArchive::GetNextItemReal(bool &filled, CItem &item)
-{
- filled = false;
-
- char header[NHeader::kHeaderSize];
- const char *cur = header;
-
- size_t processedSize = sizeof(header);
- item.HeaderPos = m_Position;
- RINOK(ReadStream(m_Stream, header, &processedSize));
- if (processedSize != sizeof(header))
- return S_OK;
- m_Position += processedSize;
-
- char tempString[NHeader::kNameSize + 1];
- MyStrNCpy(tempString, cur, NHeader::kNameSize);
- cur += NHeader::kNameSize;
- tempString[NHeader::kNameSize] = '\0';
- item.Name = tempString;
- item.Name.Trim();
-
- for (int i = 0; i < item.Name.Length(); i++)
- if (((Byte)item.Name[i]) < 0x20)
- return S_FALSE;
-
- RIF(DecimalToNumber32(cur, NHeader::kTimeSize, item.MTime));
- cur += NHeader::kTimeSize;
-
- cur += 6 + 6;
-
- RIF(OctalToNumber32(cur, NHeader::kModeSize, item.Mode));
- cur += NHeader::kModeSize;
-
- RIF(DecimalToNumber(cur, NHeader::kSizeSize, item.Size));
- cur += NHeader::kSizeSize;
-
- filled = true;
- return S_OK;
-}
-
-HRESULT CInArchive::GetNextItem(bool &filled, CItem &item)
-{
- for (;;)
- {
- RINOK(GetNextItemReal(filled, item));
- if (!filled)
- return S_OK;
- if (item.Name.Compare("debian-binary") != 0)
- return S_OK;
- if (item.Size != 4)
- return S_OK;
- SkipData(item.Size);
- }
-}
-
-HRESULT CInArchive::SkipData(UInt64 dataSize)
-{
- return m_Stream->Seek((dataSize + 1) & (~((UInt64)0x1)), STREAM_SEEK_CUR, &m_Position);
-}
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CObjectVector<CItem> _items;
- CMyComPtr<IInStream> _stream;
- Int32 _mainSubfile;
- UInt64 _phySize;
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-static STATPROPSTG kArcProps[] =
-{
- { NULL, kpidPhySize, VT_UI8}
-};
-
-static STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback *openArchiveCallback)
-{
- COM_TRY_BEGIN
- {
- _mainSubfile = -1;
- CInArchive archive;
- if (archive.Open(stream) != S_OK)
- return S_FALSE;
- _items.Clear();
-
- if (openArchiveCallback != NULL)
- {
- RINOK(openArchiveCallback->SetTotal(NULL, NULL));
- UInt64 numFiles = _items.Size();
- RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
- }
-
- for (;;)
- {
- CItem item;
- bool filled;
- HRESULT result = archive.GetNextItem(filled, item);
- if (result == S_FALSE)
- return S_FALSE;
- if (result != S_OK)
- return S_FALSE;
- if (!filled)
- break;
- if (item.Name.Left(5) == "data.")
- _mainSubfile = _items.Size();
- _items.Add(item);
- archive.SkipData(item.Size);
- if (openArchiveCallback != NULL)
- {
- UInt64 numFiles = _items.Size();
- RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
- }
- }
- _stream = stream;
- _phySize = archive.m_Position;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _stream.Release();
- _items.Clear();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPhySize: prop = _phySize; break;
- case kpidMainSubfile: if (_mainSubfile >= 0) prop = (UInt32)_mainSubfile; break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItem &item = _items[index];
-
- switch(propID)
- {
- case kpidPath: prop = (const wchar_t *)NItemName::GetOSName2(MultiByteToUnicodeString(item.Name, CP_OEMCP)); break;
- case kpidSize:
- case kpidPackSize:
- prop = item.Size;
- break;
- case kpidMTime:
- {
- if (item.MTime != 0)
- {
- FILETIME fileTime;
- NTime::UnixTimeToFileTime(item.MTime, fileTime);
- prop = fileTime;
- }
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _items.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- totalSize += _items[allFilesMode ? i : indices[i]].Size;
- extractCallback->SetTotal(totalSize);
-
- UInt64 currentTotalSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_stream);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = lps->OutSize = currentTotalSize;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItem &item = _items[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- currentTotalSize += item.Size;
-
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- if (testMode)
- {
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- RINOK(_stream->Seek(item.GetDataPos(), STREAM_SEEK_SET, NULL));
- streamSpec->Init(item.Size);
- RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult((copyCoderSpec->TotalSize == item.Size) ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- const CItem &item = _items[index];
- return CreateLimitedInStream(_stream, item.GetDataPos(), item.Size, stream);
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new NArchive::NDeb::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Deb", L"deb", 0, 0xEC, { '!', '<', 'a', 'r', 'c', 'h', '>', '\n' }, 8, false, CreateArc, 0 };
-
-REGISTER_ARC(Deb)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.cpp b/src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.cpp
deleted file mode 100644
index 8498e0565..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-// DeflateProps.cpp
-
-#include "StdAfx.h"
-
-#include "Windows/PropVariant.h"
-
-#include "Common/ParseProperties.h"
-
-#include "DeflateProps.h"
-
-namespace NArchive {
-
-static const UInt32 kAlgo1 = 0;
-static const UInt32 kAlgo5 = 1;
-
-static const UInt32 kPasses1 = 1;
-static const UInt32 kPasses7 = 3;
-static const UInt32 kPasses9 = 10;
-
-static const UInt32 kFb1 = 32;
-static const UInt32 kFb7 = 64;
-static const UInt32 kFb9 = 128;
-
-void CDeflateProps::Normalize()
-{
- UInt32 level = Level;
- if (level == 0xFFFFFFFF)
- level = 5;
-
- if (Algo == 0xFFFFFFFF)
- Algo = (level >= 5 ?
- kAlgo5 :
- kAlgo1);
-
- if (NumPasses == 0xFFFFFFFF)
- NumPasses =
- (level >= 9 ? kPasses9 :
- (level >= 7 ? kPasses7 :
- kPasses1));
- if (Fb == 0xFFFFFFFF)
- Fb =
- (level >= 9 ? kFb9 :
- (level >= 7 ? kFb7 :
- kFb1));
-}
-
-HRESULT CDeflateProps::SetCoderProperties(ICompressSetCoderProperties *setCoderProperties)
-{
- Normalize();
-
- NWindows::NCOM::CPropVariant props[] =
- {
- Algo,
- NumPasses,
- Fb,
- Mc
- };
- PROPID propIDs[] =
- {
- NCoderPropID::kAlgorithm,
- NCoderPropID::kNumPasses,
- NCoderPropID::kNumFastBytes,
- NCoderPropID::kMatchFinderCycles
- };
- int numProps = sizeof(propIDs) / sizeof(propIDs[0]);
- if (!McDefined)
- numProps--;
- return setCoderProperties->SetCoderProperties(propIDs, props, numProps);
-}
-
-HRESULT CDeflateProps::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps)
-{
- Init();
- for (int i = 0; i < numProps; i++)
- {
- UString name = names[i];
- name.MakeUpper();
- if (name.IsEmpty())
- return E_INVALIDARG;
- const PROPVARIANT &prop = values[i];
- if (name[0] == L'X')
- {
- UInt32 a = 9;
- RINOK(ParsePropValue(name.Mid(1), prop, a));
- Level = a;
- }
- else if (name.Left(1) == L"A")
- {
- UInt32 a = kAlgo5;
- RINOK(ParsePropValue(name.Mid(1), prop, a));
- Algo = a;
- }
- else if (name.Left(4) == L"PASS")
- {
- UInt32 a = kPasses9;
- RINOK(ParsePropValue(name.Mid(4), prop, a));
- NumPasses = a;
- }
- else if (name.Left(2) == L"FB")
- {
- UInt32 a = kFb9;
- RINOK(ParsePropValue(name.Mid(2), prop, a));
- Fb = a;
- }
- else if (name.Left(2) == L"MC")
- {
- UInt32 a = 0xFFFFFFFF;
- RINOK(ParsePropValue(name.Mid(2), prop, a));
- Mc = a;
- McDefined = true;
- }
- else
- return E_INVALIDARG;
- }
- return S_OK;
-}
-
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.h b/src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.h
deleted file mode 100644
index e05a9d4aa..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/DeflateProps.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// DeflateProps.h
-
-#ifndef __DEFLATE_PROPS_H
-#define __DEFLATE_PROPS_H
-
-#include "../ICoder.h"
-
-namespace NArchive {
-
-class CDeflateProps
-{
- UInt32 Level;
- UInt32 NumPasses;
- UInt32 Fb;
- UInt32 Algo;
- UInt32 Mc;
- bool McDefined;
-
- void Init()
- {
- Level = NumPasses = Fb = Algo = Mc = 0xFFFFFFFF;
- McDefined = false;
- }
- void Normalize();
-public:
- CDeflateProps() { Init(); }
- bool IsMaximum() const { return Algo > 0; }
-
- HRESULT SetCoderProperties(ICompressSetCoderProperties *setCoderProperties);
- HRESULT SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps);
-};
-
-}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/DllExports.cpp b/src/libs/7zip/win/CPP/7zip/Archive/DllExports.cpp
deleted file mode 100644
index 6c72dea71..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/DllExports.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// DLLExports.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/MyInitGuid.h"
-#include "../../Common/ComTry.h"
-#include "../../Common/Types.h"
-
-#include "../../Windows/NtCheck.h"
-#include "../../Windows/PropVariant.h"
-
-#include "IArchive.h"
-#include "../ICoder.h"
-#include "../IPassword.h"
-
-HINSTANCE g_hInstance;
-
-#define NT_CHECK_FAIL_ACTION return FALSE;
-
-extern "C"
-BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
-{
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- g_hInstance = hInstance;
- NT_CHECK;
- }
- return TRUE;
-}
-
-DEFINE_GUID(CLSID_CArchiveHandler,
-0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00);
-
-STDAPI CreateArchiver(const GUID *classID, const GUID *iid, void **outObject);
-
-STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
-{
- return CreateArchiver(clsid, iid, outObject);
-}
-
-STDAPI SetLargePageMode()
-{
- #if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
- SetLargePageSize();
- #endif
- return S_OK;
-}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/DmgHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/DmgHandler.cpp
deleted file mode 100644
index 5040d5182..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/DmgHandler.cpp
+++ /dev/null
@@ -1,918 +0,0 @@
-// DmgHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-#include "Common/MyXml.h"
-#include "Common/UTFConvert.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/BZip2Decoder.h"
-#include "../Compress/CopyCoder.h"
-#include "../Compress/ZlibDecoder.h"
-
-// #define DMG_SHOW_RAW
-
-// #include <stdio.h>
-#define PRF(x) // x
-
-#define Get32(p) GetBe32(p)
-#define Get64(p) GetBe64(p)
-
-static int Base64ToByte(char c)
-{
- if (c >= 'A' && c <= 'Z') return c - 'A';
- if (c >= 'a' && c <= 'z') return c - 'a' + 26;
- if (c >= '0' && c <= '9') return c - '0' + 52;
- if (c == '+') return 62;
- if (c == '/') return 63;
- if (c == '=') return 0;
- return -1;
-}
-
-static int Base64ToBin(Byte *dest, const char *src, int srcLen)
-{
- int srcPos = 0;
- int destPos = 0;
- while (srcPos < srcLen)
- {
- Byte buf[4];
- int filled = 0;
- while (srcPos < srcLen)
- {
- int n = Base64ToByte(src[srcPos++]);
- if (n >= 0)
- {
- buf[filled++] = (Byte)n;
- if (filled == 4)
- break;
- }
- }
- if (filled >= 2) { if (dest) dest[destPos] = (buf[0] << 2) | (buf[1] >> 4); destPos++; }
- if (filled >= 3) { if (dest) dest[destPos] = (buf[1] << 4) | (buf[2] >> 2); destPos++; }
- if (filled >= 4) { if (dest) dest[destPos] = (buf[2] << 6) | (buf[3] ); destPos++; }
- }
- return destPos;
-}
-
-static UString GetSizeString(UInt64 value)
-{
- wchar_t s[32];
- wchar_t c;
- if (value < (UInt64)20000) c = 0;
- else if (value < ((UInt64)20000 << 10)) { value >>= 10; c = L'K'; }
- else if (value < ((UInt64)20000 << 20)) { value >>= 20; c = L'M'; }
- else { value >>= 30; c = L'G'; }
- ConvertUInt64ToString(value, s);
- int p = MyStringLen(s);
- s[p++] = c;
- s[p++] = L'\0';
- return s;
-}
-
-namespace NArchive {
-namespace NDmg {
-
-struct CBlock
-{
- UInt32 Type;
- UInt64 UnpPos;
- UInt64 UnpSize;
- UInt64 PackPos;
- UInt64 PackSize;
-
- UInt64 GetNextPackOffset() const { return PackPos + PackSize; }
-};
-
-struct CFile
-{
- CByteBuffer Raw;
- UInt64 StartPos;
- CRecordVector<CBlock> Blocks;
- UInt64 GetUnpackSize() const
- {
- UInt64 size = 0;
- for (int i = 0; i < Blocks.Size(); i++)
- size += Blocks[i].UnpSize;
- return size;
- };
- UInt64 GetPackSize() const
- {
- UInt64 size = 0;
- for (int i = 0; i < Blocks.Size(); i++)
- size += Blocks[i].PackSize;
- return size;
- };
-
- AString Name;
-};
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _inStream;
-
- AString _xml;
- CObjectVector<CFile> _files;
- CRecordVector<int> _fileIndices;
-
- HRESULT Open2(IInStream *stream);
- HRESULT Extract(IInStream *stream);
-public:
- MY_UNKNOWN_IMP1(IInArchive)
- INTERFACE_IInArchive(;)
-};
-
-const UInt32 kXmlSizeMax = ((UInt32)1 << 31) - (1 << 14);
-
-enum
-{
- METHOD_ZERO_0 = 0,
- METHOD_COPY = 1,
- METHOD_ZERO_2 = 2,
- METHOD_ADC = 0x80000004,
- METHOD_ZLIB = 0x80000005,
- METHOD_BZIP2 = 0x80000006,
- METHOD_DUMMY = 0x7FFFFFFE,
- METHOD_END = 0xFFFFFFFF
-};
-
-struct CMethodStat
-{
- UInt32 NumBlocks;
- UInt64 PackSize;
- UInt64 UnpSize;
- CMethodStat(): NumBlocks(0), PackSize(0), UnpSize(0) {}
-};
-
-struct CMethods
-{
- CRecordVector<CMethodStat> Stats;
- CRecordVector<UInt32> Types;
- void Update(const CFile &file);
- UString GetString() const;
-};
-
-void CMethods::Update(const CFile &file)
-{
- for (int i = 0; i < file.Blocks.Size(); i++)
- {
- const CBlock &b = file.Blocks[i];
- int index = Types.FindInSorted(b.Type);
- if (index < 0)
- {
- index = Types.AddToUniqueSorted(b.Type);
- Stats.Insert(index, CMethodStat());
- }
- CMethodStat &m = Stats[index];
- m.PackSize += b.PackSize;
- m.UnpSize += b.UnpSize;
- m.NumBlocks++;
- }
-}
-
-UString CMethods::GetString() const
-{
- UString res;
- for (int i = 0; i < Types.Size(); i++)
- {
- if (i != 0)
- res += L' ';
- wchar_t buf[32];
- const wchar_t *s;
- const CMethodStat &m = Stats[i];
- bool showPack = true;
- UInt32 type = Types[i];
- switch(type)
- {
- case METHOD_ZERO_0: s = L"zero0"; showPack = (m.PackSize != 0); break;
- case METHOD_ZERO_2: s = L"zero2"; showPack = (m.PackSize != 0); break;
- case METHOD_COPY: s = L"copy"; showPack = (m.UnpSize != m.PackSize); break;
- case METHOD_ADC: s = L"adc"; break;
- case METHOD_ZLIB: s = L"zlib"; break;
- case METHOD_BZIP2: s = L"bzip2"; break;
- default: ConvertUInt64ToString(type, buf); s = buf;
- }
- res += s;
- if (m.NumBlocks != 1)
- {
- res += L'[';
- ConvertUInt64ToString(m.NumBlocks, buf);
- res += buf;
- res += L']';
- }
- res += L'-';
- res += GetSizeString(m.UnpSize);
- if (showPack)
- {
- res += L'-';
- res += GetSizeString(m.PackSize);
- }
- }
- return res;
-}
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidComment, VT_BSTR},
- { NULL, kpidMethod, VT_BSTR}
-};
-
-IMP_IInArchive_Props
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidNumBlocks, VT_UI4}
-};
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMethod:
- {
- CMethods m;
- for (int i = 0; i < _files.Size(); i++)
- m.Update(_files[i]);
- prop = m.GetString();
- break;
- }
- case kpidNumBlocks:
- {
- UInt64 numBlocks = 0;
- for (int i = 0; i < _files.Size(); i++)
- numBlocks += _files[i].Blocks.Size();
- prop = numBlocks;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-IMP_IInArchive_ArcProps
-
-static int FindKeyPair(const CXmlItem &item, const AString &key, const AString &nextTag)
-{
- for (int i = 0; i + 1 < item.SubItems.Size(); i++)
- {
- const CXmlItem &si = item.SubItems[i];
- if (si.IsTagged("key") && si.GetSubString() == key && item.SubItems[i + 1].IsTagged(nextTag))
- return i + 1;
- }
- return -1;
-}
-
-static AString GetStringFromKeyPair(const CXmlItem &item, const AString &key, const AString &nextTag)
-{
- int index = FindKeyPair(item, key, nextTag);
- if (index >= 0)
- return item.SubItems[index].GetSubString();
- return AString();
-}
-
-HRESULT CHandler::Open2(IInStream *stream)
-{
- const int HEADER_SIZE = 0x1E0;
-
- UInt64 headerPos;
- RINOK(stream->Seek(-HEADER_SIZE, STREAM_SEEK_END, &headerPos));
- Byte buf[HEADER_SIZE];
- RINOK(ReadStream_FALSE(stream, buf, HEADER_SIZE));
- UInt64 address1 = Get64(buf + 0);
- UInt64 address2 = Get64(buf + 0xB8);
- UInt64 size64 = Get64(buf + 0xC0);
- if (address1 != address2 || size64 >= kXmlSizeMax || size64 == 0 ||
- address1 >= headerPos || address1 + size64 > headerPos)
- return S_FALSE;
- RINOK(stream->Seek(address1, STREAM_SEEK_SET, NULL));
- size_t size = (size_t)size64;
-
- char *ss = _xml.GetBuffer((int)size + 1);
- RINOK(ReadStream_FALSE(stream, ss, size));
- ss[size] = 0;
- _xml.ReleaseBuffer();
-
- CXml xml;
- if (!xml.Parse(_xml))
- return S_FALSE;
- if (xml.Root.Name != "plist")
- return S_FALSE;
-
- int dictIndex = xml.Root.FindSubTag("dict");
- if (dictIndex < 0)
- return S_FALSE;
-
- const CXmlItem &dictItem = xml.Root.SubItems[dictIndex];
- int rfDictIndex = FindKeyPair(dictItem, "resource-fork", "dict");
- if (rfDictIndex < 0)
- return S_FALSE;
-
- const CXmlItem &rfDictItem = dictItem.SubItems[rfDictIndex];
- int arrIndex = FindKeyPair(rfDictItem, "blkx", "array");
- if (arrIndex < 0)
- return S_FALSE;
-
- const CXmlItem &arrItem = rfDictItem.SubItems[arrIndex];
-
- int i;
- for (i = 0; i < arrItem.SubItems.Size(); i++)
- {
- const CXmlItem &item = arrItem.SubItems[i];
- if (!item.IsTagged("dict"))
- continue;
-
- CFile file;
- file.StartPos = 0;
-
- int destLen;
- {
- AString dataString;
- AString name = GetStringFromKeyPair(item, "Name", "string");
- if (name.IsEmpty())
- name = GetStringFromKeyPair(item, "CFName", "string");
- file.Name = name;
- dataString = GetStringFromKeyPair(item, "Data", "data");
-
- destLen = Base64ToBin(NULL, dataString, dataString.Length());
- file.Raw.SetCapacity(destLen);
- Base64ToBin(file.Raw, dataString, dataString.Length());
- }
-
- if (destLen > 0xCC && Get32(file.Raw) == 0x6D697368)
- {
- PRF(printf("\n\n index = %d", _files.Size()));
- const int kRecordSize = 40;
- for (int offset = 0xCC; offset + kRecordSize <= destLen; offset += kRecordSize)
- {
- const Byte *p = (const Byte *)file.Raw + offset;
- CBlock b;
- b.Type = Get32(p);
- if (b.Type == METHOD_END)
- break;
- if (b.Type == METHOD_DUMMY)
- continue;
-
- b.UnpPos = Get64(p + 0x08) << 9;
- b.UnpSize = Get64(p + 0x10) << 9;
- b.PackPos = Get64(p + 0x18);
- b.PackSize = Get64(p + 0x20);
-
- file.Blocks.Add(b);
-
- PRF(printf("\nType=%8x m[1]=%8x uPos=%8x uSize=%7x pPos=%8x pSize=%7x",
- b.Type, Get32(p + 4), (UInt32)b.UnpPos, (UInt32)b.UnpSize, (UInt32)b.PackPos, (UInt32)b.PackSize));
- }
- }
- int itemIndex = _files.Add(file);
- if (file.Blocks.Size() > 0)
- {
- // if (file.Name.Find("HFS") >= 0)
- _fileIndices.Add(itemIndex);
- }
- }
-
- // PackPos for each new file is 0 in some DMG files. So we use additional StartPos
-
- bool allStartAreZeros = true;
- for (i = 0; i < _files.Size(); i++)
- {
- const CFile &file = _files[i];
- if (!file.Blocks.IsEmpty() && file.Blocks[0].PackPos != 0)
- allStartAreZeros = false;
- }
- UInt64 startPos = 0;
- if (allStartAreZeros)
- {
- for (i = 0; i < _files.Size(); i++)
- {
- CFile &file = _files[i];
- file.StartPos = startPos;
- if (!file.Blocks.IsEmpty())
- startPos += file.Blocks.Back().GetNextPackOffset();
- }
- }
-
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- {
- Close();
- if (Open2(stream) != S_OK)
- return S_FALSE;
- _inStream = stream;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _inStream.Release();
- _fileIndices.Clear();
- _files.Clear();
- _xml.Empty();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _fileIndices.Size()
- #ifdef DMG_SHOW_RAW
- + _files.Size() + 1;
- #endif
- ;
- return S_OK;
-}
-
-#define RAW_PREFIX L"raw" WSTRING_PATH_SEPARATOR
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
-
- #ifdef DMG_SHOW_RAW
- if ((int)index == _fileIndices.Size())
- {
- switch(propID)
- {
- case kpidPath:
- prop = RAW_PREFIX L"a.xml";
- break;
- case kpidSize:
- case kpidPackSize:
- prop = (UInt64)_xml.Length();
- break;
- }
- }
- else if ((int)index > _fileIndices.Size())
- {
- int rawIndex = (int)index - (_fileIndices.Size() + 1);
- switch(propID)
- {
- case kpidPath:
- {
- wchar_t s[32] = RAW_PREFIX;
- ConvertUInt64ToString(rawIndex, s + MyStringLen(s));
- prop = s;
- break;
- }
- case kpidSize:
- case kpidPackSize:
- prop = (UInt64)_files[rawIndex].Raw.GetCapacity();
- break;
- }
- }
- else
- #endif
- {
- int itemIndex = _fileIndices[index];
- const CFile &item = _files[itemIndex];
- switch(propID)
- {
- case kpidMethod:
- {
- CMethods m;
- m.Update(item);
- UString resString = m.GetString();
- if (!resString.IsEmpty())
- prop = resString;
- break;
- }
-
- // case kpidExtension: prop = L"hfs"; break;
-
- case kpidPath:
- {
- // break;
- UString name;
- wchar_t s[32];
- ConvertUInt64ToString(index, s);
- name = s;
- int num = 10;
- int numDigits;
- for (numDigits = 1; num < _fileIndices.Size(); numDigits++)
- num *= 10;
- while (name.Length() < numDigits)
- name = L'0' + name;
-
- AString subName;
- int pos1 = item.Name.Find('(');
- if (pos1 >= 0)
- {
- pos1++;
- int pos2 = item.Name.Find(')', pos1);
- if (pos2 >= 0)
- {
- subName = item.Name.Mid(pos1, pos2 - pos1);
- pos1 = subName.Find(':');
- if (pos1 >= 0)
- subName = subName.Left(pos1);
- }
- }
- subName.Trim();
- if (!subName.IsEmpty())
- {
- if (subName == "Apple_HFS")
- subName = "hfs";
- else if (subName == "Apple_HFSX")
- subName = "hfsx";
- else if (subName == "Apple_Free")
- subName = "free";
- else if (subName == "DDM")
- subName = "ddm";
- UString name2;
- ConvertUTF8ToUnicode(subName, name2);
- name += L'.';
- name += name2;
- }
- else
- {
- UString name2;
- ConvertUTF8ToUnicode(item.Name, name2);
- if (!name2.IsEmpty())
- name += L" - ";
- name += name2;
- }
- prop = name;
- break;
- }
- case kpidComment:
- {
- UString name;
- ConvertUTF8ToUnicode(item.Name, name);
- prop = name;
- break;
- }
-
- case kpidSize: prop = item.GetUnpackSize(); break;
- case kpidPackSize: prop = item.GetPackSize(); break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-class CAdcDecoder:
- public ICompressCoder,
- public CMyUnknownImp
-{
- CLzOutWindow m_OutWindowStream;
- CInBuffer m_InStream;
-
- void ReleaseStreams()
- {
- m_OutWindowStream.ReleaseStream();
- m_InStream.ReleaseStream();
- }
-
- class CCoderReleaser
- {
- CAdcDecoder *m_Coder;
- public:
- bool NeedFlush;
- CCoderReleaser(CAdcDecoder *coder): m_Coder(coder), NeedFlush(true) {}
- ~CCoderReleaser()
- {
- if (NeedFlush)
- m_Coder->m_OutWindowStream.Flush();
- m_Coder->ReleaseStreams();
- }
- };
- friend class CCoderReleaser;
-
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(CodeReal)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-
- STDMETHOD(Code)(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress);
-};
-
-STDMETHODIMP CAdcDecoder::CodeReal(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress)
-{
- if (!m_OutWindowStream.Create(1 << 18))
- return E_OUTOFMEMORY;
- if (!m_InStream.Create(1 << 18))
- return E_OUTOFMEMORY;
-
- m_OutWindowStream.SetStream(outStream);
- m_OutWindowStream.Init(false);
- m_InStream.SetStream(inStream);
- m_InStream.Init();
-
- CCoderReleaser coderReleaser(this);
-
- const UInt32 kStep = (1 << 20);
- UInt64 nextLimit = kStep;
-
- UInt64 pos = 0;
- while (pos < *outSize)
- {
- if (pos > nextLimit && progress)
- {
- UInt64 packSize = m_InStream.GetProcessedSize();
- RINOK(progress->SetRatioInfo(&packSize, &pos));
- nextLimit += kStep;
- }
- Byte b;
- if (!m_InStream.ReadByte(b))
- return S_FALSE;
- UInt64 rem = *outSize - pos;
- if (b & 0x80)
- {
- unsigned num = (b & 0x7F) + 1;
- if (num > rem)
- return S_FALSE;
- for (unsigned i = 0; i < num; i++)
- {
- if (!m_InStream.ReadByte(b))
- return S_FALSE;
- m_OutWindowStream.PutByte(b);
- }
- pos += num;
- continue;
- }
- Byte b1;
- if (!m_InStream.ReadByte(b1))
- return S_FALSE;
-
- UInt32 len, distance;
-
- if (b & 0x40)
- {
- len = ((UInt32)b & 0x3F) + 4;
- Byte b2;
- if (!m_InStream.ReadByte(b2))
- return S_FALSE;
- distance = ((UInt32)b1 << 8) + b2;
- }
- else
- {
- b &= 0x3F;
- len = ((UInt32)b >> 2) + 3;
- distance = (((UInt32)b & 3) << 8) + b1;
- }
-
- if (distance >= pos || len > rem)
- return S_FALSE;
- m_OutWindowStream.CopyBlock(distance, len);
- pos += len;
- }
- if (*inSize != m_InStream.GetProcessedSize())
- return S_FALSE;
- coderReleaser.NeedFlush = false;
- return m_OutWindowStream.Flush();
-}
-
-STDMETHODIMP CAdcDecoder::Code(ISequentialInStream *inStream,
- ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
- ICompressProgressInfo *progress)
-{
- try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
- catch(const CInBufferException &e) { return e.ErrorCode; }
- catch(const CLzOutWindowException &e) { return e.ErrorCode; }
- catch(...) { return S_FALSE; }
-}
-
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _files.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- {
- int index = (int)(allFilesMode ? i : indices[i]);
- #ifdef DMG_SHOW_RAW
- if (index == _fileIndices.Size())
- totalSize += _xml.Length();
- else if (index > _fileIndices.Size())
- totalSize += _files[index - (_fileIndices.Size() + 1)].Raw.GetCapacity();
- else
- #endif
- totalSize += _files[_fileIndices[index]].GetUnpackSize();
- }
- extractCallback->SetTotal(totalSize);
-
- UInt64 currentPackTotal = 0;
- UInt64 currentUnpTotal = 0;
- UInt64 currentPackSize = 0;
- UInt64 currentUnpSize = 0;
-
- const UInt32 kZeroBufSize = (1 << 14);
- CByteBuffer zeroBuf;
- zeroBuf.SetCapacity(kZeroBufSize);
- memset(zeroBuf, 0, kZeroBufSize);
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- NCompress::NBZip2::CDecoder *bzip2CoderSpec = new NCompress::NBZip2::CDecoder();
- CMyComPtr<ICompressCoder> bzip2Coder = bzip2CoderSpec;
-
- NCompress::NZlib::CDecoder *zlibCoderSpec = new NCompress::NZlib::CDecoder();
- CMyComPtr<ICompressCoder> zlibCoder = zlibCoderSpec;
-
- CAdcDecoder *adcCoderSpec = new CAdcDecoder();
- CMyComPtr<ICompressCoder> adcCoder = adcCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_inStream);
-
- for (i = 0; i < numItems; i++, currentPackTotal += currentPackSize, currentUnpTotal += currentUnpSize)
- {
- lps->InSize = currentPackTotal;
- lps->OutSize = currentUnpTotal;
- currentPackSize = 0;
- currentUnpSize = 0;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- // const CItemEx &item = _files[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
-
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
-
- CLimitedSequentialOutStream *outStreamSpec = new CLimitedSequentialOutStream;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
-
- realOutStream.Release();
-
- Int32 opRes = NExtract::NOperationResult::kOK;
- #ifdef DMG_SHOW_RAW
- if (index > _fileIndices.Size())
- {
- const CByteBuffer &buf = _files[index - (_fileIndices.Size() + 1)].Raw;
- outStreamSpec->Init(buf.GetCapacity());
- RINOK(WriteStream(outStream, buf, buf.GetCapacity()));
- currentPackSize = currentUnpSize = buf.GetCapacity();
- }
- else if (index == _fileIndices.Size())
- {
- outStreamSpec->Init(_xml.Length());
- RINOK(WriteStream(outStream, (const char *)_xml, _xml.Length()));
- currentPackSize = currentUnpSize = _xml.Length();
- }
- else
- #endif
- {
- const CFile &item = _files[_fileIndices[index]];
- currentPackSize = item.GetPackSize();
- currentUnpSize = item.GetUnpackSize();
-
- UInt64 unpPos = 0;
- UInt64 packPos = 0;
- {
- for (int j = 0; j < item.Blocks.Size(); j++)
- {
- lps->InSize = currentPackTotal + packPos;
- lps->OutSize = currentUnpTotal + unpPos;
- RINOK(lps->SetCur());
-
- const CBlock &block = item.Blocks[j];
-
- packPos += block.PackSize;
- if (block.UnpPos != unpPos)
- {
- opRes = NExtract::NOperationResult::kDataError;
- break;
- }
-
- RINOK(_inStream->Seek(item.StartPos + block.PackPos, STREAM_SEEK_SET, NULL));
- streamSpec->Init(block.PackSize);
- // UInt64 startSize = outStreamSpec->GetSize();
- bool realMethod = true;
- outStreamSpec->Init(block.UnpSize);
- HRESULT res = S_OK;
-
- switch(block.Type)
- {
- case METHOD_ZERO_0:
- case METHOD_ZERO_2:
- realMethod = false;
- if (block.PackSize != 0)
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
- break;
-
- case METHOD_COPY:
- if (block.UnpSize != block.PackSize)
- {
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
- break;
- }
- res = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
- break;
-
- case METHOD_ADC:
- {
- res = adcCoder->Code(inStream, outStream, &block.PackSize, &block.UnpSize, progress);
- break;
- }
-
- case METHOD_ZLIB:
- {
- res = zlibCoder->Code(inStream, outStream, NULL, NULL, progress);
- break;
- }
-
- case METHOD_BZIP2:
- {
- res = bzip2Coder->Code(inStream, outStream, NULL, NULL, progress);
- if (res == S_OK)
- if (streamSpec->GetSize() != block.PackSize)
- opRes = NExtract::NOperationResult::kDataError;
- break;
- }
-
- default:
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
- break;
- }
- if (res != S_OK)
- {
- if (res != S_FALSE)
- return res;
- if (opRes == NExtract::NOperationResult::kOK)
- opRes = NExtract::NOperationResult::kDataError;
- }
- unpPos += block.UnpSize;
- if (!outStreamSpec->IsFinishedOK())
- {
- if (realMethod && opRes == NExtract::NOperationResult::kOK)
- opRes = NExtract::NOperationResult::kDataError;
-
- while (outStreamSpec->GetRem() != 0)
- {
- UInt64 rem = outStreamSpec->GetRem();
- UInt32 size = (UInt32)MyMin(rem, (UInt64)kZeroBufSize);
- RINOK(WriteStream(outStream, zeroBuf, size));
- }
- }
- }
- }
- }
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(opRes));
- }
- return S_OK;
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Dmg", L"dmg", 0, 0xE4, { 0 }, 0, false, CreateArc, 0 };
-
-REGISTER_ARC(Dmg)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/ElfHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/ElfHandler.cpp
deleted file mode 100644
index c4ad78e9e..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/ElfHandler.cpp
+++ /dev/null
@@ -1,534 +0,0 @@
-// ElfHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-
-#include "Windows/PropVariantUtils.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-
-static UInt16 Get16(const Byte *p, int be) { if (be) return GetBe16(p); return GetUi16(p); }
-static UInt32 Get32(const Byte *p, int be) { if (be) return GetBe32(p); return GetUi32(p); }
-static UInt64 Get64(const Byte *p, int be) { if (be) return GetBe64(p); return GetUi64(p); }
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NElf {
-
-#define ELF_CLASS_32 1
-#define ELF_CLASS_64 2
-
-#define ELF_DATA_2LSB 1
-#define ELF_DATA_2MSB 2
-
-#define NUM_SCAN_SECTIONS_MAX (1 << 6)
-
-struct CHeader
-{
- bool Mode64;
- bool Be;
- Byte Os;
- Byte AbiVer;
-
- UInt16 Type;
- UInt16 Machine;
- // UInt32 Version;
-
- // UInt64 EntryVa;
- UInt64 ProgOffset;
- UInt64 SectOffset;
- UInt32 Flags;
- UInt16 ElfHeaderSize;
- UInt16 SegmentEntrySize;
- UInt16 NumSegments;
- UInt16 SectEntrySize;
- UInt16 NumSections;
- // UInt16 SectNameStringTableIndex;
-
- bool Parse(const Byte *buf);
-
- bool CheckSegmentEntrySize() const
- {
- return (Mode64 && SegmentEntrySize == 0x38) || (!Mode64 && SegmentEntrySize == 0x20);
- };
-
- UInt64 GetHeadersSize() const
- { return ElfHeaderSize +
- (UInt64)SegmentEntrySize * NumSegments +
- (UInt64)SectEntrySize * NumSections; }
-
-};
-
-bool CHeader::Parse(const Byte *p)
-{
- switch(p[4])
- {
- case ELF_CLASS_32: Mode64 = false; break;
- case ELF_CLASS_64: Mode64 = true; break;
- default: return false;
- }
- bool be;
- switch(p[5])
- {
- case ELF_DATA_2LSB: be = false; break;
- case ELF_DATA_2MSB: be = true; break;
- default: return false;
- }
- Be = be;
- if (p[6] != 1) // Version
- return false;
- Os = p[7];
- AbiVer = p[8];
- for (int i = 9; i < 16; i++)
- if (p[i] != 0)
- return false;
-
- Type = Get16(p + 0x10, be);
- Machine = Get16(p + 0x12, be);
- if (Get32(p + 0x14, be) != 1) // Version
- return false;
-
- if (Mode64)
- {
- // EntryVa = Get64(p + 0x18, be);
- ProgOffset = Get64(p + 0x20, be);
- SectOffset = Get64(p + 0x28, be);
- p += 0x30;
- }
- else
- {
- // EntryVa = Get32(p + 0x18, be);
- ProgOffset = Get32(p + 0x1C, be);
- SectOffset = Get32(p + 0x20, be);
- p += 0x24;
- }
-
- Flags = Get32(p + 0, be);
- ElfHeaderSize = Get16(p + 4, be);
- SegmentEntrySize = Get16(p + 6, be);
- NumSegments = Get16(p + 8, be);
- SectEntrySize = Get16(p + 10, be);
- NumSections = Get16(p + 12, be);
- // SectNameStringTableIndex = Get16(p + 14, be);
- return CheckSegmentEntrySize();
-}
-
-struct CSegment
-{
- UInt32 Type;
- UInt32 Flags;
- UInt64 Offset;
- UInt64 Va;
- // UInt64 Pa;
- UInt64 PSize;
- UInt64 VSize;
- // UInt64 Align;
-
- void UpdateTotalSize(UInt64 &totalSize)
- {
- UInt64 t = Offset + PSize;
- if (t > totalSize)
- totalSize = t;
- }
- void Parse(const Byte *p, bool mode64, bool be);
-};
-
-void CSegment::Parse(const Byte *p, bool mode64, bool be)
-{
- Type = Get32(p, be);
- if (mode64)
- {
- Flags = Get32(p + 4, be);
- Offset = Get64(p + 8, be);
- Va = Get64(p + 0x10, be);
- // Pa = Get64(p + 0x18, be);
- PSize = Get64(p + 0x20, be);
- VSize = Get64(p + 0x28, be);
- // Align = Get64(p + 0x30, be);
- }
- else
- {
- Offset = Get32(p + 4, be);
- Va = Get32(p + 8, be);
- // Pa = Get32(p + 12, be);
- PSize = Get32(p + 16, be);
- VSize = Get32(p + 20, be);
- Flags = Get32(p + 24, be);
- // Align = Get32(p + 28, be);
- }
-}
-
-static const CUInt32PCharPair g_MachinePairs[] =
-{
- { 0, "None" },
- { 1, "AT&T WE 32100" },
- { 2, "SPARC" },
- { 3, "Intel 386" },
- { 4, "Motorola 68000" },
- { 5, "Motorola 88000" },
- { 6, "Intel 486" },
- { 7, "Intel i860" },
- { 8, "MIPS" },
- { 9, "IBM S/370" },
- { 10, "MIPS RS3000 LE" },
- { 11, "RS6000" },
-
- { 15, "PA-RISC" },
- { 16, "nCUBE" },
- { 17, "Fujitsu VPP500" },
- { 18, "SPARC 32+" },
- { 19, "Intel i960" },
- { 20, "PowerPC" },
- { 21, "PowerPC 64-bit" },
- { 22, "IBM S/390" },
-
- { 36, "NEX v800" },
- { 37, "Fujitsu FR20" },
- { 38, "TRW RH-32" },
- { 39, "Motorola RCE" },
- { 40, "ARM" },
- { 41, "Alpha" },
- { 42, "Hitachi SH" },
- { 43, "SPARC-V9" },
- { 44, "Siemens Tricore" },
- { 45, "ARC" },
- { 46, "H8/300" },
- { 47, "H8/300H" },
- { 48, "H8S" },
- { 49, "H8/500" },
- { 50, "IA-64" },
- { 51, "Stanford MIPS-X" },
- { 52, "Motorola ColdFire" },
- { 53, "M68HC12" },
- { 54, "Fujitsu MMA" },
- { 55, "Siemens PCP" },
- { 56, "Sony nCPU" },
- { 57, "Denso NDR1" },
- { 58, "Motorola StarCore" },
- { 59, "Toyota ME16" },
- { 60, "ST100" },
- { 61, "Advanced Logic TinyJ" },
- { 62, "AMD64" },
- { 63, "Sony DSP" },
-
- { 66, "Siemens FX66" },
- { 67, "ST9+" },
- { 68, "ST7" },
- { 69, "MC68HC16" },
- { 70, "MC68HC11" },
- { 71, "MC68HC08" },
- { 72, "MC68HC05" },
- { 73, "Silicon Graphics SVx" },
- { 74, "ST19" },
- { 75, "Digital VAX" },
- { 76, "Axis CRIS" },
- { 77, "Infineon JAVELIN" },
- { 78, "Element 14 FirePath" },
- { 79, "LSI ZSP" },
- { 80, "MMIX" },
- { 81, "HUANY" },
- { 82, "SiTera Prism" },
- { 83, "Atmel AVR" },
- { 84, "Fujitsu FR30" },
- { 85, "Mitsubishi D10V" },
- { 86, "Mitsubishi D30V" },
- { 87, "NEC v850" },
- { 88, "Mitsubishi M32R" },
- { 89, "Matsushita MN10300" },
- { 90, "Matsushita MN10200" },
- { 91, "picoJava" },
- { 92, "OpenRISC" },
- { 93, "ARC Tangent-A5" },
- { 94, "Tensilica Xtensa" },
- { 0x9026, "Alpha" }
-};
-
-static const CUInt32PCharPair g_AbiOS[] =
-{
- { 0, "None" },
- { 1, "HP-UX" },
- { 2, "NetBSD" },
- { 3, "Linux" },
-
- { 6, "Solaris" },
- { 7, "AIX" },
- { 8, "IRIX" },
- { 9, "FreeBSD" },
- { 10, "TRU64" },
- { 11, "Novell Modesto" },
- { 12, "OpenBSD" },
- { 13, "OpenVMS" },
- { 14, "HP NSK" },
- { 15, "AROS" },
- { 97, "ARM" },
- { 255, "Standalone" }
-};
-
-static const CUInt32PCharPair g_SegmentFlags[] =
-{
- { 0, "Execute" },
- { 1, "Write" },
- { 2, "Read" }
-};
-
-static const char *g_Types[] =
-{
- "None",
- "Relocatable file",
- "Executable file",
- "Shared object file",
- "Core file"
-};
-
-static const char *g_SegnmentTypes[] =
-{
- "Unused",
- "Loadable segment",
- "Dynamic linking tables",
- "Program interpreter path name",
- "Note section",
- "SHLIB",
- "Program header table",
- "TLS"
-};
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _inStream;
- CObjectVector<CSegment> _sections;
- UInt32 _peOffset;
- CHeader _header;
- UInt64 _totalSize;
- HRESULT Open2(IInStream *stream);
- bool Parse(const Byte *buf, UInt32 size);
-public:
- MY_UNKNOWN_IMP1(IInArchive)
- INTERFACE_IInArchive(;)
-};
-
-#define ELF_PT_PHDR 6
-
-bool CHandler::Parse(const Byte *buf, UInt32 size)
-{
- if (size < 64)
- return false;
- if (!_header.Parse(buf))
- return false;
- if (_header.ProgOffset > size ||
- _header.ProgOffset + (UInt64)_header.SegmentEntrySize * _header.NumSegments > size ||
- _header.NumSegments > NUM_SCAN_SECTIONS_MAX)
- return false;
- const Byte *p = buf + _header.ProgOffset;
- _totalSize = _header.ProgOffset;
-
- for (int i = 0; i < _header.NumSegments; i++, p += _header.SegmentEntrySize)
- {
- CSegment sect;
- sect.Parse(p, _header.Mode64, _header.Be);
- sect.UpdateTotalSize(_totalSize);
- if (sect.Type != ELF_PT_PHDR)
- _sections.Add(sect);
- }
- UInt64 total2 = _header.SectOffset + (UInt64)_header.SectEntrySize * _header.NumSections;
- if (total2 > _totalSize)
- _totalSize = total2;
- return true;
-}
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidCpu, VT_BSTR},
- { NULL, kpidBit64, VT_BOOL},
- { NULL, kpidBigEndian, VT_BOOL},
- { NULL, kpidHostOS, VT_BSTR},
- { NULL, kpidCharacts, VT_BSTR},
- { NULL, kpidPhySize, VT_UI8},
- { NULL, kpidHeadersSize, VT_UI8}
- };
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidType, VT_BSTR},
- { NULL, kpidCharacts, VT_BSTR},
- { NULL, kpidOffset, VT_UI8},
- { NULL, kpidVa, VT_UI8}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPhySize: prop = _totalSize; break;
- case kpidHeadersSize: prop = _header.GetHeadersSize(); break;
- case kpidBit64: if (_header.Mode64) prop = _header.Mode64; break;
- case kpidBigEndian: if (_header.Be) prop = _header.Be; break;
- case kpidCpu: PAIR_TO_PROP(g_MachinePairs, _header.Machine, prop); break;
- case kpidHostOS: PAIR_TO_PROP(g_AbiOS, _header.Os, prop); break;
- case kpidCharacts: TYPE_TO_PROP(g_Types, _header.Type, prop); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
- const CSegment &item = _sections[index];
- switch(propID)
- {
- case kpidPath:
- {
- wchar_t sz[32];
- ConvertUInt64ToString(index, sz);
- prop = sz;
- break;
- }
- case kpidSize: prop = (UInt64)item.VSize; break;
- case kpidPackSize: prop = (UInt64)item.PSize; break;
- case kpidOffset: prop = item.Offset; break;
- case kpidVa: prop = item.Va; break;
- case kpidType: TYPE_TO_PROP(g_SegnmentTypes, item.Type, prop); break;
- case kpidCharacts: FLAGS_TO_PROP(g_SegmentFlags, item.Flags, prop); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-HRESULT CHandler::Open2(IInStream *stream)
-{
- const UInt32 kBufSize = 1 << 18;
- const UInt32 kSigSize = 4;
-
- CByteBuffer buffer;
- buffer.SetCapacity(kBufSize);
- Byte *buf = buffer;
-
- size_t processed = kSigSize;
- RINOK(ReadStream_FALSE(stream, buf, processed));
- if (buf[0] != 0x7F || buf[1] != 'E' || buf[2] != 'L' || buf[3] != 'F')
- return S_FALSE;
- processed = kBufSize - kSigSize;
- RINOK(ReadStream(stream, buf + kSigSize, &processed));
- processed += kSigSize;
- if (!Parse(buf, (UInt32)processed))
- return S_FALSE;
- UInt64 fileSize;
- RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
- return (fileSize == _totalSize) ? S_OK : S_FALSE;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- RINOK(Open2(inStream));
- _inStream = inStream;
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _inStream.Release();
- _sections.Clear();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _sections.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _sections.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- totalSize += _sections[allFilesMode ? i : indices[i]].PSize;
- extractCallback->SetTotal(totalSize);
-
- UInt64 currentTotalSize = 0;
- UInt64 currentItemSize;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_inStream);
-
- for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
- {
- lps->InSize = lps->OutSize = currentTotalSize;
- RINOK(lps->SetCur());
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- UInt32 index = allFilesMode ? i : indices[i];
- const CSegment &item = _sections[index];
- currentItemSize = item.PSize;
-
- CMyComPtr<ISequentialOutStream> outStream;
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- if (!testMode && !outStream)
- continue;
-
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(_inStream->Seek(item.Offset, STREAM_SEEK_SET, NULL));
- streamSpec->Init(currentItemSize);
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
- outStream.Release();
- RINOK(extractCallback->SetOperationResult(copyCoderSpec->TotalSize == currentItemSize ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- }
- return S_OK;
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"ELF", L"", 0, 0xDE, { 0 }, 0, false, CreateArc, 0 };
-
-REGISTER_ARC(Elf)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/FatHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/FatHandler.cpp
deleted file mode 100644
index 1c374a444..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/FatHandler.cpp
+++ /dev/null
@@ -1,996 +0,0 @@
-// FatHandler.cpp
-
-#include "StdAfx.h"
-
-// #include <stdio.h>
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-#include "Common/MyCom.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-
-#include "Common/DummyOutStream.h"
-
-#define Get16(p) GetUi16(p)
-#define Get32(p) GetUi32(p)
-
-#define PRF(x) /* x */
-
-namespace NArchive {
-namespace NFat {
-
-static const UInt32 kFatItemUsedByDirMask = (UInt32)1 << 31;
-
-struct CHeader
-{
- UInt32 NumSectors;
- UInt16 NumReservedSectors;
- Byte NumFats;
- UInt32 NumFatSectors;
- UInt32 RootDirSector;
- UInt32 NumRootDirSectors;
- UInt32 DataSector;
-
- UInt32 FatSize;
- UInt32 BadCluster;
-
- Byte NumFatBits;
- Byte SectorSizeLog;
- Byte SectorsPerClusterLog;
- Byte ClusterSizeLog;
-
- UInt16 SectorsPerTrack;
- UInt16 NumHeads;
- UInt32 NumHiddenSectors;
-
- bool VolFieldsDefined;
-
- UInt32 VolId;
- // Byte VolName[11];
- // Byte FileSys[8];
-
- // Byte OemName[5];
- Byte MediaType;
-
- // 32-bit FAT
- UInt16 Flags;
- UInt16 FsInfoSector;
- UInt32 RootCluster;
-
- bool IsFat32() const { return NumFatBits == 32; }
- UInt64 GetPhySize() const { return (UInt64)NumSectors << SectorSizeLog; }
- UInt32 SectorSize() const { return (UInt32)1 << SectorSizeLog; }
- UInt32 ClusterSize() const { return (UInt32)1 << ClusterSizeLog; }
- UInt32 ClusterToSector(UInt32 c) const { return DataSector + ((c - 2) << SectorsPerClusterLog); }
- UInt32 IsEoc(UInt32 c) const { return c > BadCluster; }
- UInt32 IsEocAndUnused(UInt32 c) const { return c > BadCluster && (c & kFatItemUsedByDirMask) == 0; }
- UInt32 IsValidCluster(UInt32 c) const { return c >= 2 && c < FatSize; }
- UInt32 SizeToSectors(UInt32 size) const { return (size + SectorSize() - 1) >> SectorSizeLog; }
- UInt32 CalcFatSizeInSectors() const { return SizeToSectors((FatSize * (NumFatBits / 4) + 1) / 2); }
-
- UInt32 GetFatSector() const
- {
- UInt32 index = (IsFat32() && (Flags & 0x80) != 0) ? (Flags & 0xF) : 0;
- if (index > NumFats)
- index = 0;
- return NumReservedSectors + index * NumFatSectors;
- }
-
- UInt64 GetFilePackSize(UInt32 unpackSize) const
- {
- UInt64 mask = ClusterSize() - 1;
- return (unpackSize + mask) & ~mask;
- }
-
- UInt32 GetNumClusters(UInt32 size) const
- { return (UInt32)(((UInt64)size + ClusterSize() - 1) >> ClusterSizeLog); }
-
- bool Parse(const Byte *p);
-};
-
-static int GetLog(UInt32 num)
-{
- for (int i = 0; i < 31; i++)
- if (((UInt32)1 << i) == num)
- return i;
- return -1;
-}
-
-bool CHeader::Parse(const Byte *p)
-{
- if (p[0x1FE] != 0x55 || p[0x1FF] != 0xAA)
- return false;
-
- int codeOffset = 0;
- switch (p[0])
- {
- case 0xE9: codeOffset = 3 + (Int16)Get16(p + 1); break;
- case 0xEB: if (p[2] != 0x90) return false; codeOffset = 2 + (signed char)p[1]; break;
- default: return false;
- }
- {
- int s = GetLog(Get16(p + 11));
- if (s < 9 || s > 12)
- return false;
- SectorSizeLog = (Byte)s;
- s = GetLog(p[13]);
- if (s < 0)
- return false;
- SectorsPerClusterLog = (Byte)s;
- ClusterSizeLog = SectorSizeLog + SectorsPerClusterLog;
- }
-
- NumReservedSectors = Get16(p + 14);
- if (NumReservedSectors == 0)
- return false;
-
- NumFats = p[16];
- if (NumFats < 1 || NumFats > 4)
- return false;
-
- UInt16 numRootDirEntries = Get16(p + 17);
- if (numRootDirEntries == 0)
- {
- if (codeOffset < 90)
- return false;
- NumFatBits = 32;
- NumRootDirSectors = 0;
- }
- else
- {
- if (codeOffset < 62)
- return false;
- NumFatBits = 0;
- UInt32 mask = (1 << (SectorSizeLog - 5)) - 1;
- if ((numRootDirEntries & mask) != 0)
- return false;
- NumRootDirSectors = (numRootDirEntries + mask) >> (SectorSizeLog - 5);
- }
-
- NumSectors = Get16(p + 19);
- if (NumSectors == 0)
- NumSectors = Get32(p + 32);
- else if (IsFat32())
- return false;
-
- MediaType = p[21];
- NumFatSectors = Get16(p + 22);
- SectorsPerTrack = Get16(p + 24);
- NumHeads = Get16(p + 26);
- NumHiddenSectors = Get32(p + 28);
-
- // memcpy(OemName, p + 3, 5);
-
- p += 36;
- if (IsFat32())
- {
- if (NumFatSectors != 0)
- return false;
- NumFatSectors = Get32(p);
- if (NumFatSectors >= (1 << 24))
- return false;
-
- Flags = Get16(p + 4);
- if (Get16(p + 6) != 0)
- return false;
- RootCluster = Get32(p + 8);
- FsInfoSector = Get16(p + 12);
- for (int i = 16; i < 28; i++)
- if (p[i] != 0)
- return false;
- p += 28;
- }
-
- // DriveNumber = p[0];
- VolFieldsDefined = (p[2] == 0x29); // ExtendedBootSig
- VolId = Get32(p + 3);
- // memcpy(VolName, p + 7, 11);
- // memcpy(FileSys, p + 18, 8);
-
- if (NumFatSectors == 0)
- return false;
- RootDirSector = NumReservedSectors + NumFatSectors * NumFats;
- DataSector = RootDirSector + NumRootDirSectors;
- if (NumSectors < DataSector)
- return false;
- UInt32 numDataSectors = NumSectors - DataSector;
- UInt32 numClusters = numDataSectors >> SectorsPerClusterLog;
-
- BadCluster = 0x0FFFFFF7;
- if (numClusters < 0xFFF5)
- {
- if (NumFatBits == 32)
- return false;
- NumFatBits = (numClusters < 0xFF5) ? 12: 16;
- BadCluster &= ((1 << NumFatBits) - 1);
- }
- else if (NumFatBits != 32)
- return false;
-
- FatSize = numClusters + 2;
- if (FatSize > BadCluster || CalcFatSizeInSectors() > NumFatSectors)
- return false;
- return true;
-}
-
-struct CItem
-{
- UString UName;
- char DosName[11];
- Byte CTime2;
- UInt32 CTime;
- UInt32 MTime;
- UInt16 ADate;
- Byte Attrib;
- Byte Flags;
- UInt32 Size;
- UInt32 Cluster;
- Int32 Parent;
-
- // NT uses Flags to store Low Case status
- bool NameIsLow() const { return (Flags & 0x8) != 0; }
- bool ExtIsLow() const { return (Flags & 0x10) != 0; }
- bool IsDir() const { return (Attrib & 0x10) != 0; }
- UString GetShortName() const;
- UString GetName() const;
- UString GetVolName() const;
-};
-
-static int CopyAndTrim(char *dest, const char *src, int size, bool toLower)
-{
- int i;
- memcpy(dest, src, size);
- if (toLower)
- for (i = 0; i < size; i++)
- {
- char c = dest[i];
- if (c >= 'A' && c <= 'Z')
- dest[i] = c + 0x20;
- }
- for (i = size - 1; i >= 0 && dest[i] == ' '; i--);
- return i + 1;
-}
-
-static UString FatStringToUnicode(const char *s)
-{
- return MultiByteToUnicodeString(s, CP_OEMCP);
-}
-
-UString CItem::GetShortName() const
-{
- char s[16];
- int i = CopyAndTrim(s, DosName, 8, NameIsLow());
- s[i++] = '.';
- int j = CopyAndTrim(s + i, DosName + 8, 3, ExtIsLow());
- if (j == 0)
- j--;
- s[i + j] = 0;
- return FatStringToUnicode(s);
-}
-
-UString CItem::GetName() const
-{
- if (!UName.IsEmpty())
- return UName;
- return GetShortName();
-}
-
-UString CItem::GetVolName() const
-{
- if (!UName.IsEmpty())
- return UName;
- char s[12];
- int i = CopyAndTrim(s, DosName, 11, false);
- s[i] = 0;
- return FatStringToUnicode(s);
-}
-
-struct CDatabase
-{
- CHeader Header;
- CObjectVector<CItem> Items;
- UInt32 *Fat;
- CMyComPtr<IInStream> InStream;
- IArchiveOpenCallback *OpenCallback;
-
- UInt32 NumFreeClusters;
- bool VolItemDefined;
- CItem VolItem;
- UInt32 NumDirClusters;
- CByteBuffer ByteBuf;
- UInt64 NumCurUsedBytes;
-
- CDatabase(): Fat(0) {}
- ~CDatabase() { ClearAndClose(); }
-
- void Clear();
- void ClearAndClose();
- HRESULT OpenProgressFat(bool changeTotal = true);
- HRESULT OpenProgress();
-
- UString GetItemPath(Int32 index) const;
- HRESULT Open();
- HRESULT ReadDir(Int32 parent, UInt32 cluster, int level);
-
- UInt64 GetHeadersSize() const
- {
- return (UInt64)(Header.DataSector + (NumDirClusters << Header.SectorsPerClusterLog)) << Header.SectorSizeLog;
- }
- HRESULT SeekToSector(UInt32 sector);
- HRESULT SeekToCluster(UInt32 cluster) { return SeekToSector(Header.ClusterToSector(cluster)); }
-};
-
-HRESULT CDatabase::SeekToSector(UInt32 sector)
-{
- return InStream->Seek((UInt64)sector << Header.SectorSizeLog, STREAM_SEEK_SET, NULL);
-}
-
-void CDatabase::Clear()
-{
- VolItemDefined = false;
- NumDirClusters = 0;
- NumCurUsedBytes = 0;
-
- Items.Clear();
- delete []Fat;
- Fat = 0;
-}
-
-void CDatabase::ClearAndClose()
-{
- Clear();
- InStream.Release();
-}
-
-HRESULT CDatabase::OpenProgressFat(bool changeTotal)
-{
- if (!OpenCallback)
- return S_OK;
- if (changeTotal)
- {
- UInt64 numTotalBytes = (Header.CalcFatSizeInSectors() << Header.SectorSizeLog) +
- ((UInt64)(Header.FatSize - NumFreeClusters) << Header.ClusterSizeLog);
- RINOK(OpenCallback->SetTotal(NULL, &numTotalBytes));
- }
- return OpenCallback->SetCompleted(NULL, &NumCurUsedBytes);
-}
-
-HRESULT CDatabase::OpenProgress()
-{
- if (!OpenCallback)
- return S_OK;
- UInt64 numItems = Items.Size();
- return OpenCallback->SetCompleted(&numItems, &NumCurUsedBytes);
-}
-
-UString CDatabase::GetItemPath(Int32 index) const
-{
- const CItem *item = &Items[index];
- UString name = item->GetName();
- for (;;)
- {
- index = item->Parent;
- if (index < 0)
- return name;
- item = &Items[index];
- name = item->GetName() + WCHAR_PATH_SEPARATOR + name;
- }
-}
-
-static wchar_t *AddSubStringToName(wchar_t *dest, const Byte *p, int numChars)
-{
- for (int i = 0; i < numChars; i++)
- {
- wchar_t c = Get16(p + i * 2);
- if (c != 0 && c != 0xFFFF)
- *dest++ = c;
- }
- *dest = 0;
- return dest;
-}
-
-HRESULT CDatabase::ReadDir(Int32 parent, UInt32 cluster, int level)
-{
- int startIndex = Items.Size();
- if (startIndex >= (1 << 30) || level > 256)
- return S_FALSE;
-
- UInt32 sectorIndex = 0;
- UInt32 blockSize = Header.ClusterSize();
- bool clusterMode = (Header.IsFat32() || parent >= 0);
- if (!clusterMode)
- {
- blockSize = Header.SectorSize();
- RINOK(SeekToSector(Header.RootDirSector));
- }
-
- ByteBuf.SetCapacity(blockSize);
- UString curName;
- int checkSum = -1;
- int numLongRecords = -1;
- for (UInt32 pos = blockSize;; pos += 32)
- {
- if (pos == blockSize)
- {
- pos = 0;
-
- if ((NumDirClusters & 0xFF) == 0)
- {
- RINOK(OpenProgress());
- }
-
- if (clusterMode)
- {
- if (Header.IsEoc(cluster))
- break;
- if (!Header.IsValidCluster(cluster))
- return S_FALSE;
- PRF(printf("\nCluster = %4X", cluster));
- RINOK(SeekToCluster(cluster));
- UInt32 newCluster = Fat[cluster];
- if ((newCluster & kFatItemUsedByDirMask) != 0)
- return S_FALSE;
- Fat[cluster] |= kFatItemUsedByDirMask;
- cluster = newCluster;
- NumDirClusters++;
- NumCurUsedBytes += Header.ClusterSize();
- }
- else if (sectorIndex++ >= Header.NumRootDirSectors)
- break;
-
- RINOK(ReadStream_FALSE(InStream, ByteBuf, blockSize));
- }
- const Byte *p = ByteBuf + pos;
- if (p[0] == 0)
- {
- /*
- // FreeDOS formats FAT partition with cluster chain longer than required.
- if (clusterMode && !Header.IsEoc(cluster))
- return S_FALSE;
- */
- break;
- }
- if (p[0] == 0xE5)
- {
- if (numLongRecords > 0)
- return S_FALSE;
- continue;
- }
-
- Byte attrib = p[11];
- if ((attrib & 0x3F) == 0xF)
- {
- if (p[0] > 0x7F || Get16(p + 26) != 0)
- return S_FALSE;
- int longIndex = p[0] & 0x3F;
- if (longIndex == 0)
- return S_FALSE;
- bool isLast = (p[0] & 0x40) != 0;
- if (numLongRecords < 0)
- {
- if (!isLast)
- return S_FALSE;
- numLongRecords = longIndex;
- }
- else if (isLast || numLongRecords != longIndex)
- return S_FALSE;
-
- numLongRecords--;
-
- if (p[12] == 0)
- {
- wchar_t nameBuf[14];
- wchar_t *dest;
-
- dest = AddSubStringToName(nameBuf, p + 1, 5);
- dest = AddSubStringToName(dest, p + 14, 6);
- AddSubStringToName(dest, p + 28, 2);
- curName = nameBuf + curName;
- if (isLast)
- checkSum = p[13];
- if (checkSum != p[13])
- return S_FALSE;
- }
- }
- else
- {
- if (numLongRecords > 0)
- return S_FALSE;
- CItem item;
- memcpy(item.DosName, p, 11);
-
- if (checkSum >= 0)
- {
- Byte sum = 0;
- for (int i = 0; i < 11; i++)
- sum = ((sum & 1) ? 0x80 : 0) + (sum >> 1) + (Byte)item.DosName[i];
- if (sum == checkSum)
- item.UName = curName;
- }
-
- if (item.DosName[0] == 5)
- item.DosName[0] = (char)(Byte)0xE5;
- item.Attrib = attrib;
- item.Flags = p[12];
- item.Size = Get32(p + 28);
- item.Cluster = Get16(p + 26);
- if (Header.NumFatBits > 16)
- item.Cluster |= ((UInt32)Get16(p + 20) << 16);
- else
- {
- // OS/2 and WinNT probably can store EA (extended atributes) in that field.
- }
-
- item.CTime = Get32(p + 14);
- item.CTime2 = p[13];
- item.ADate = Get16(p + 18);
- item.MTime = Get32(p + 22);
- item.Parent = parent;
-
- if (attrib == 8)
- {
- VolItem = item;
- VolItemDefined = true;
- }
- else
- if (memcmp(item.DosName, ". ", 11) != 0 &&
- memcmp(item.DosName, ".. ", 11) != 0)
- {
- if (!item.IsDir())
- NumCurUsedBytes += Header.GetFilePackSize(item.Size);
- Items.Add(item);
- PRF(printf("\n%7d: %S", Items.Size(), GetItemPath(Items.Size() - 1)));
- }
- numLongRecords = -1;
- curName.Empty();
- checkSum = -1;
- }
- }
-
- int finishIndex = Items.Size();
- for (int i = startIndex; i < finishIndex; i++)
- {
- const CItem &item = Items[i];
- if (item.IsDir())
- {
- PRF(printf("\n%S", GetItemPath(i)));
- RINOK(CDatabase::ReadDir(i, item.Cluster, level + 1));
- }
- }
- return S_OK;
-}
-
-HRESULT CDatabase::Open()
-{
- Clear();
- bool numFreeClustersDefined = false;
- {
- static const UInt32 kHeaderSize = 512;
- Byte buf[kHeaderSize];
- RINOK(ReadStream_FALSE(InStream, buf, kHeaderSize));
- if (!Header.Parse(buf))
- return S_FALSE;
- UInt64 fileSize;
- RINOK(InStream->Seek(0, STREAM_SEEK_END, &fileSize));
-
- /* we comment that check to support truncated images */
- /*
- if (fileSize < Header.GetPhySize())
- return S_FALSE;
- */
-
- if (Header.IsFat32())
- {
- SeekToSector(Header.FsInfoSector);
- RINOK(ReadStream_FALSE(InStream, buf, kHeaderSize));
- if (buf[0x1FE] != 0x55 || buf[0x1FF] != 0xAA)
- return S_FALSE;
- if (Get32(buf) == 0x41615252 && Get32(buf + 484) == 0x61417272)
- {
- NumFreeClusters = Get32(buf + 488);
- numFreeClustersDefined = (NumFreeClusters <= Header.FatSize);
- }
- }
- }
-
- // numFreeClustersDefined = false; // to recalculate NumFreeClusters
- if (!numFreeClustersDefined)
- NumFreeClusters = 0;
-
- CByteBuffer byteBuf;
- Fat = new UInt32[Header.FatSize];
-
- RINOK(OpenProgressFat());
- RINOK(SeekToSector(Header.GetFatSector()));
- if (Header.NumFatBits == 32)
- {
- const UInt32 kBufSize = (1 << 15);
- byteBuf.SetCapacity(kBufSize);
- for (UInt32 i = 0; i < Header.FatSize;)
- {
- UInt32 size = Header.FatSize - i;
- const UInt32 kBufSize32 = kBufSize / 4;
- if (size > kBufSize32)
- size = kBufSize32;
- UInt32 readSize = Header.SizeToSectors(size * 4) << Header.SectorSizeLog;
- RINOK(ReadStream_FALSE(InStream, byteBuf, readSize));
- NumCurUsedBytes += readSize;
-
- const UInt32 *src = (const UInt32 *)(const Byte *)byteBuf;
- UInt32 *dest = Fat + i;
- if (numFreeClustersDefined)
- for (UInt32 j = 0; j < size; j++)
- dest[j] = Get32(src + j) & 0x0FFFFFFF;
- else
- {
- UInt32 numFreeClusters = 0;
- for (UInt32 j = 0; j < size; j++)
- {
- UInt32 v = Get32(src + j) & 0x0FFFFFFF;
- numFreeClusters += (UInt32)(v - 1) >> 31;
- dest[j] = v;
- }
- NumFreeClusters += numFreeClusters;
- }
- i += size;
- if ((i & 0xFFFFF) == 0)
- {
- RINOK(OpenProgressFat(!numFreeClustersDefined));
- }
- }
- }
- else
- {
- const UInt32 kBufSize = (UInt32)Header.CalcFatSizeInSectors() << Header.SectorSizeLog;
- NumCurUsedBytes += kBufSize;
- byteBuf.SetCapacity(kBufSize);
- Byte *p = byteBuf;
- RINOK(ReadStream_FALSE(InStream, p, kBufSize));
- UInt32 fatSize = Header.FatSize;
- UInt32 *fat = &Fat[0];
- if (Header.NumFatBits == 16)
- for (UInt32 j = 0; j < fatSize; j++)
- fat[j] = Get16(p + j * 2);
- else
- for (UInt32 j = 0; j < fatSize; j++)
- fat[j] = (Get16(p + j * 3 / 2) >> ((j & 1) << 2)) & 0xFFF;
-
- if (!numFreeClustersDefined)
- {
- UInt32 numFreeClusters = 0;
- for (UInt32 i = 0; i < fatSize; i++)
- numFreeClusters += (UInt32)(fat[i] - 1) >> 31;
- NumFreeClusters = numFreeClusters;
- }
- }
-
- RINOK(OpenProgressFat());
-
- if ((Fat[0] & 0xFF) != Header.MediaType)
- return S_FALSE;
-
- return ReadDir(-1, Header.RootCluster, 0);
-}
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp,
- CDatabase
-{
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- *stream = 0;
- const CItem &item = Items[index];
- CClusterInStream *streamSpec = new CClusterInStream;
- CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
- streamSpec->Stream = InStream;
- streamSpec->StartOffset = Header.DataSector << Header.SectorSizeLog;
- streamSpec->BlockSizeLog = Header.ClusterSizeLog;
- streamSpec->Size = item.Size;
-
- UInt32 numClusters = Header.GetNumClusters(item.Size);
- streamSpec->Vector.Reserve(numClusters);
- UInt32 cluster = item.Cluster;
- UInt32 size = item.Size;
-
- if (size == 0)
- {
- if (cluster != 0)
- return S_FALSE;
- }
- else
- {
- UInt32 clusterSize = Header.ClusterSize();
- for (;; size -= clusterSize)
- {
- if (!Header.IsValidCluster(cluster))
- return S_FALSE;
- streamSpec->Vector.Add(cluster - 2);
- cluster = Fat[cluster];
- if (size <= clusterSize)
- break;
- }
- if (!Header.IsEocAndUnused(cluster))
- return S_FALSE;
- }
- RINOK(streamSpec->InitAndSeek());
- *stream = streamTemp.Detach();
- return S_OK;
- COM_TRY_END
-}
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidCTime, VT_FILETIME},
- { NULL, kpidATime, VT_FILETIME},
- { NULL, kpidAttrib, VT_UI8},
- { NULL, kpidShortName, VT_BSTR}
-};
-
-enum
-{
- kpidNumFats = kpidUserDefined
- // kpidOemName,
- // kpidVolName,
- // kpidFileSysType
-};
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidFileSystem, VT_BSTR},
- { NULL, kpidClusterSize, VT_UI4},
- { NULL, kpidPhySize, VT_UI8},
- { NULL, kpidFreeSpace, VT_UI8},
- { NULL, kpidHeadersSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidVolumeName, VT_BSTR},
-
- { L"FATs", kpidNumFats, VT_UI4},
- { NULL, kpidSectorSize, VT_UI4},
- { NULL, kpidId, VT_UI4},
- // { L"OEM Name", kpidOemName, VT_BSTR},
- // { L"Volume Name", kpidVolName, VT_BSTR},
- // { L"File System Type", kpidFileSysType, VT_BSTR}
- // { NULL, kpidSectorsPerTrack, VT_UI4},
- // { NULL, kpidNumHeads, VT_UI4},
- // { NULL, kpidHiddenSectors, VT_UI4}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_WITH_NAME
-
-static void FatTimeToProp(UInt32 dosTime, UInt32 ms10, NWindows::NCOM::CPropVariant &prop)
-{
- FILETIME localFileTime, utc;
- if (NWindows::NTime::DosTimeToFileTime(dosTime, localFileTime))
- if (LocalFileTimeToFileTime(&localFileTime, &utc))
- {
- UInt64 t64 = (((UInt64)utc.dwHighDateTime) << 32) + utc.dwLowDateTime;
- t64 += ms10 * 100000;
- utc.dwLowDateTime = (DWORD)t64;
- utc.dwHighDateTime = (DWORD)(t64 >> 32);
- prop = utc;
- }
-}
-
-/*
-static void StringToProp(const Byte *src, int size, NWindows::NCOM::CPropVariant &prop)
-{
- char dest[32];
- memcpy(dest, src, size);
- dest[size] = 0;
- prop = FatStringToUnicode(dest);
-}
-
-#define STRING_TO_PROP(s, p) StringToProp(s, sizeof(s), prop)
-*/
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidFileSystem:
- {
- wchar_t s[32] = { L'F', L'A', L'T' };
- ConvertUInt32ToString(Header.NumFatBits, s + 3);
- prop = s;
- break;
- }
- case kpidClusterSize: prop = Header.ClusterSize(); break;
- case kpidPhySize: prop = Header.GetPhySize(); break;
- case kpidFreeSpace: prop = (UInt64)NumFreeClusters << Header.ClusterSizeLog; break;
- case kpidHeadersSize: prop = GetHeadersSize(); break;
- case kpidMTime: if (VolItemDefined) FatTimeToProp(VolItem.MTime, 0, prop); break;
- case kpidVolumeName: if (VolItemDefined) prop = VolItem.GetVolName(); break;
- case kpidNumFats: if (Header.NumFats != 2) prop = Header.NumFats; break;
- case kpidSectorSize: prop = (UInt32)1 << Header.SectorSizeLog; break;
- // case kpidSectorsPerTrack: prop = Header.SectorsPerTrack; break;
- // case kpidNumHeads: prop = Header.NumHeads; break;
- // case kpidOemName: STRING_TO_PROP(Header.OemName, prop); break;
- case kpidId: if (Header.VolFieldsDefined) prop = Header.VolId; break;
- // case kpidVolName: if (Header.VolFieldsDefined) STRING_TO_PROP(Header.VolName, prop); break;
- // case kpidFileSysType: if (Header.VolFieldsDefined) STRING_TO_PROP(Header.FileSys, prop); break;
- // case kpidHiddenSectors: prop = Header.NumHiddenSectors; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItem &item = Items[index];
- switch(propID)
- {
- case kpidPath: prop = GetItemPath(index); break;
- case kpidShortName: prop = item.GetShortName(); break;
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidMTime: FatTimeToProp(item.MTime, 0, prop); break;
- case kpidCTime: FatTimeToProp(item.CTime, item.CTime2, prop); break;
- case kpidATime: FatTimeToProp(((UInt32)item.ADate << 16), 0, prop); break;
- case kpidAttrib: prop = (UInt32)item.Attrib; break;
- case kpidSize: if (!item.IsDir()) prop = item.Size; break;
- case kpidPackSize: if (!item.IsDir()) prop = Header.GetFilePackSize(item.Size); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- {
- OpenCallback = callback;
- InStream = stream;
- HRESULT res;
- try
- {
- res = CDatabase::Open();
- if (res == S_OK)
- return S_OK;
- }
- catch(...)
- {
- Close();
- throw;
- }
- Close();
- return res;
- }
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- ClearAndClose();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = Items.Size();
- if (numItems == 0)
- return S_OK;
- UInt32 i;
- UInt64 totalSize = 0;
- for (i = 0; i < numItems; i++)
- {
- const CItem &item = Items[allFilesMode ? i : indices[i]];
- if (!item.IsDir())
- totalSize += item.Size;
- }
- RINOK(extractCallback->SetTotal(totalSize));
-
- UInt64 totalPackSize;
- totalSize = totalPackSize = 0;
-
- NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
- CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- CDummyOutStream *outStreamSpec = new CDummyOutStream;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = totalPackSize;
- lps->OutSize = totalSize;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItem &item = Items[index];
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- if (item.IsDir())
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
-
- totalPackSize += Header.GetFilePackSize(item.Size);
- totalSize += item.Size;
-
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
-
- outStreamSpec->SetStream(realOutStream);
- realOutStream.Release();
- outStreamSpec->Init();
-
- int res = NExtract::NOperationResult::kDataError;
- CMyComPtr<ISequentialInStream> inStream;
- HRESULT hres = GetStream(index, &inStream);
- if (hres != S_FALSE)
- {
- RINOK(hres);
- if (inStream)
- {
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
- if (copyCoderSpec->TotalSize == item.Size)
- res = NExtract::NOperationResult::kOK;
- }
- }
- outStreamSpec->ReleaseStream();
- RINOK(extractCallback->SetOperationResult(res));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = Items.Size();
- return S_OK;
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"FAT", L"fat img", 0, 0xDA, { 0x55, 0xAA }, 2, false, CreateArc, 0 };
-
-REGISTER_ARC(Fat)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/FlvHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/FlvHandler.cpp
deleted file mode 100644
index a22c29e30..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/FlvHandler.cpp
+++ /dev/null
@@ -1,544 +0,0 @@
-// FlvHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.h"
-// #include "Common/Defs.h"
-#include "Common/MyString.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamObjects.h"
-#include "../Common/StreamUtils.h"
-
-#define GetBe24(p) ( \
- ((UInt32)((const Byte *)(p))[0] << 16) | \
- ((UInt32)((const Byte *)(p))[1] << 8) | \
- ((const Byte *)(p))[2] )
-
-#define Get16(p) GetBe16(p)
-#define Get24(p) GetBe24(p)
-#define Get32(p) GetBe32(p)
-
-namespace NArchive {
-namespace NFlv {
-
-static const UInt32 kFileSizeMax = (UInt32)1 << 30;
-static const int kNumChunksMax = (UInt32)1 << 23;
-
-const UInt32 kTagHeaderSize = 11;
-
-static const Byte kFlag_Video = 1;
-static const Byte kFlag_Audio = 4;
-
-static const Byte kType_Audio = 8;
-static const Byte kType_Video = 9;
-static const Byte kType_Meta = 18;
-static const int kNumTypes = 19;
-
-struct CItem
-{
- UInt32 Offset;
- UInt32 Size;
- // UInt32 Time;
- Byte Type;
-};
-
-struct CItem2
-{
- Byte Type;
- Byte SubType;
- Byte Props;
- bool SameSubTypes;
- int NumChunks;
- size_t Size;
-
- CReferenceBuf *BufSpec;
- CMyComPtr<IUnknown> RefBuf;
-
- bool IsAudio() const { return Type == kType_Audio; }
-};
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- int _isRaw;
- CMyComPtr<IInStream> _stream;
- CObjectVector<CItem2> _items2;
- // CByteBuffer _metadata;
- HRESULT Open2(IInStream *stream, IArchiveOpenCallback *callback);
- AString GetComment();
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidNumBlocks, VT_UI4},
- { NULL, kpidComment, VT_BSTR}
-};
-
-/*
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidComment, VT_BSTR}
-};
-*/
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-static const char *g_AudioTypes[16] =
-{
- "pcm",
- "adpcm",
- "mp3",
- "pcm_le",
- "nellymoser16",
- "nellymoser8",
- "nellymoser",
- "g711a",
- "g711m",
- "audio9",
- "aac",
- "speex",
- "audio12",
- "audio13",
- "mp3",
- "audio15"
-};
-
-static const char *g_VideoTypes[16] =
-{
- "video0",
- "jpeg",
- "h263",
- "screen",
- "vp6",
- "vp6alpha",
- "screen2",
- "avc",
- "video8",
- "video9",
- "video10",
- "video11",
- "video12",
- "video13",
- "video14",
- "video15"
-};
-
-static const char *g_Rates[4] =
-{
- "5.5 kHz",
- "11 kHz",
- "22 kHz",
- "44 kHz"
-};
-
-static void MyStrCat(char *d, const char *s)
-{
- MyStringCopy(d + MyStringLen(d), s);
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- NWindows::NCOM::CPropVariant prop;
- const CItem2 &item = _items2[index];
- switch(propID)
- {
- case kpidExtension:
- prop = _isRaw ?
- (item.IsAudio() ? g_AudioTypes[item.SubType] : g_VideoTypes[item.SubType]) :
- (item.IsAudio() ? "audio.flv" : "video.flv");
- break;
- case kpidSize:
- case kpidPackSize:
- prop = (UInt64)item.Size;
- break;
- case kpidNumBlocks: prop = (UInt32)item.NumChunks; break;
- case kpidComment:
- {
- char sz[64];
- MyStringCopy(sz, (item.IsAudio() ? g_AudioTypes[item.SubType] : g_VideoTypes[item.SubType]) );
- if (item.IsAudio())
- {
- MyStrCat(sz, " ");
- MyStrCat(sz, g_Rates[(item.Props >> 2) & 3]);
- MyStrCat(sz, (item.Props & 2) ? " 16-bit" : " 8-bit");
- MyStrCat(sz, (item.Props & 1) ? " stereo" : " mono");
- }
- prop = sz;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
-}
-
-/*
-AString CHandler::GetComment()
-{
- const Byte *p = _metadata;
- size_t size = _metadata.GetCapacity();
- AString res;
- if (size > 0)
- {
- p++;
- size--;
- for (;;)
- {
- if (size < 2)
- break;
- int len = Get16(p);
- p += 2;
- size -= 2;
- if (len == 0 || (size_t)len > size)
- break;
- {
- AString temp;
- char *sz = temp.GetBuffer(len);
- memcpy(sz, p, len);
- sz[len] = 0;
- temp.ReleaseBuffer();
- if (!res.IsEmpty())
- res += '\n';
- res += temp;
- }
- p += len;
- size -= len;
- if (size < 1)
- break;
- Byte type = *p++;
- size--;
- bool ok = false;
- switch(type)
- {
- case 0:
- {
- if (size < 8)
- break;
- ok = true;
- Byte reverse[8];
- for (int i = 0; i < 8; i++)
- {
- bool little_endian = 1;
- if (little_endian)
- reverse[i] = p[7 - i];
- else
- reverse[i] = p[i];
- }
- double d = *(double *)reverse;
- char temp[32];
- sprintf(temp, " = %.3f", d);
- res += temp;
- p += 8;
- size -= 8;
- break;
- }
- case 8:
- {
- if (size < 4)
- break;
- ok = true;
- // UInt32 numItems = Get32(p);
- p += 4;
- size -= 4;
- break;
- }
- }
- if (!ok)
- break;
- }
- }
- return res;
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidComment: prop = GetComment(); break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-*/
-
-HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
-{
- CRecordVector<CItem> items;
-
- const UInt32 kHeaderSize = 13;
- Byte header[kHeaderSize];
- RINOK(ReadStream_FALSE(stream, header, kHeaderSize));
- if (header[0] != 'F' ||
- header[1] != 'L' ||
- header[2] != 'V' ||
- header[3] != 1 ||
- (header[4] & 0xFA) != 0)
- return S_FALSE;
- UInt32 offset = Get32(header + 5);
- if (offset != 9 || Get32(header + 9) != 0)
- return S_FALSE;
- offset += 4;
-
- CByteBuffer inBuf;
- size_t fileSize;
- {
- UInt64 fileSize64;
- RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize64));
- if (fileSize64 > kFileSizeMax)
- return S_FALSE;
-
- if (callback)
- RINOK(callback->SetTotal(NULL, &fileSize64))
-
- RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
- fileSize = (size_t)fileSize64;
- inBuf.SetCapacity(fileSize);
- for (size_t pos = 0; pos < fileSize;)
- {
- UInt64 offset64 = pos;
- if (callback)
- RINOK(callback->SetCompleted(NULL, &offset64))
- size_t rem = MyMin(fileSize - pos, (size_t)(1 << 20));
- RINOK(ReadStream_FALSE(stream, inBuf + pos, rem));
- pos += rem;
- }
- }
-
- int lasts[kNumTypes];
- int i;
- for (i = 0; i < kNumTypes; i++)
- lasts[i] = -1;
-
- while (offset < fileSize)
- {
- CItem item;
- item.Offset = offset;
- const Byte *buf = inBuf + offset;
- offset += kTagHeaderSize;
- if (offset > fileSize)
- return S_FALSE;
-
- item.Type = buf[0];
- UInt32 size = Get24(buf + 1);
- if (size < 1)
- return S_FALSE;
- // item.Time = Get24(buf + 4);
- // item.Time |= (UInt32)buf[7] << 24;
- if (Get24(buf + 8) != 0) // streamID
- return S_FALSE;
-
- UInt32 curSize = kTagHeaderSize + size + 4;
- item.Size = curSize;
-
- offset += curSize - kTagHeaderSize;
- if (offset > fileSize)
- return S_FALSE;
-
- if (Get32(buf + kTagHeaderSize + size) != kTagHeaderSize + size)
- return S_FALSE;
-
- // printf("\noffset = %6X type = %2d time = %6d size = %6d", (UInt32)offset, item.Type, item.Time, item.Size);
-
- if (item.Type == kType_Meta)
- {
- // _metadata = item.Buf;
- }
- else
- {
- if (item.Type != kType_Audio && item.Type != kType_Video)
- return S_FALSE;
- if (items.Size() >= kNumChunksMax)
- return S_FALSE;
- Byte firstByte = buf[kTagHeaderSize];
- Byte subType, props;
- if (item.Type == kType_Audio)
- {
- subType = firstByte >> 4;
- props = firstByte & 0xF;
- }
- else
- {
- subType = firstByte & 0xF;
- props = firstByte >> 4;
- }
- int last = lasts[item.Type];
- if (last < 0)
- {
- CItem2 item2;
- item2.RefBuf = item2.BufSpec = new CReferenceBuf;
- item2.Size = curSize;
- item2.Type = item.Type;
- item2.SubType = subType;
- item2.Props = props;
- item2.NumChunks = 1;
- item2.SameSubTypes = true;
- lasts[item.Type] = _items2.Add(item2);
- }
- else
- {
- CItem2 &item2 = _items2[last];
- if (subType != item2.SubType)
- item2.SameSubTypes = false;
- item2.Size += curSize;
- item2.NumChunks++;
- }
- items.Add(item);
- }
- }
-
- _isRaw = (_items2.Size() == 1);
- for (i = 0; i < _items2.Size(); i++)
- {
- CItem2 &item2 = _items2[i];
- CByteBuffer &itemBuf = item2.BufSpec->Buf;
- if (_isRaw)
- {
- if (!item2.SameSubTypes)
- return S_FALSE;
- itemBuf.SetCapacity((size_t)item2.Size - (kTagHeaderSize + 4 + 1) * item2.NumChunks);
- item2.Size = 0;
- }
- else
- {
- itemBuf.SetCapacity(kHeaderSize + (size_t)item2.Size);
- memcpy(itemBuf, header, kHeaderSize);
- itemBuf[4] = item2.IsAudio() ? kFlag_Audio : kFlag_Video;
- item2.Size = kHeaderSize;
- }
- }
-
- for (i = 0; i < items.Size(); i++)
- {
- const CItem &item = items[i];
- CItem2 &item2 = _items2[lasts[item.Type]];
- size_t size = item.Size;
- const Byte *src = inBuf + item.Offset;
- if (_isRaw)
- {
- src += kTagHeaderSize + 1;
- size -= (kTagHeaderSize + 4 + 1);
- }
- memcpy(item2.BufSpec->Buf + item2.Size, src, size);
- item2.Size += size;
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream, const UInt64 *, IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- Close();
- HRESULT res;
- try
- {
- res = Open2(inStream, callback);
- if (res == S_OK)
- _stream = inStream;
- }
- catch(...) { res = S_FALSE; }
- if (res != S_OK)
- {
- Close();
- return S_FALSE;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _stream.Release();
- _items2.Clear();
- // _metadata.SetCapacity(0);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _items2.Size();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _items2.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for (i = 0; i < numItems; i++)
- totalSize += _items2[allFilesMode ? i : indices[i]].Size;
- extractCallback->SetTotal(totalSize);
-
- totalSize = 0;
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, false);
-
- for (i = 0; i < numItems; i++)
- {
- lps->InSize = lps->OutSize = totalSize;
- RINOK(lps->SetCur());
- CMyComPtr<ISequentialOutStream> outStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- UInt32 index = allFilesMode ? i : indices[i];
- const CItem2 &item = _items2[index];
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- totalSize += item.Size;
- if (!testMode && !outStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- if (outStream)
- {
- RINOK(WriteStream(outStream, item.BufSpec->Buf, item.BufSpec->Buf.GetCapacity()));
- }
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- *stream = 0;
- CBufInStream *streamSpec = new CBufInStream;
- CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
- streamSpec->Init(_items2[index].BufSpec);
- *stream = streamTemp.Detach();
- return S_OK;
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"FLV", L"flv", 0, 0xD6, { 'F', 'L', 'V' }, 3, false, CreateArc, 0 };
-
-REGISTER_ARC(Flv)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/GzHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/GzHandler.cpp
deleted file mode 100644
index 7b73bddc3..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/GzHandler.cpp
+++ /dev/null
@@ -1,698 +0,0 @@
-// GzHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/ComTry.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-#include "../Compress/DeflateDecoder.h"
-#include "../Compress/DeflateEncoder.h"
-
-#include "Common/InStreamWithCRC.h"
-#include "Common/OutStreamWithCRC.h"
-
-#include "DeflateProps.h"
-
-#define Get32(p) GetUi32(p)
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NGz {
-
-static const UInt16 kSignature = 0x8B1F;
-
-namespace NHeader
-{
- namespace NFlags
- {
- const Byte kIsText = 1 << 0;
- const Byte kCrc = 1 << 1;
- const Byte kExtra = 1 << 2;
- const Byte kName = 1 << 3;
- const Byte kComment = 1 << 4;
- }
-
- namespace NExtraFlags
- {
- const Byte kMaximum = 2;
- const Byte kFastest = 4;
- }
-
- namespace NCompressionMethod
- {
- const Byte kDeflate = 8;
- }
-
- namespace NHostOS
- {
- enum EEnum
- {
- kFAT = 0,
- kAMIGA,
- kVMS,
- kUnix,
- kVM_CMS,
- kAtari,
- kHPFS,
- kMac,
- kZ_System,
- kCPM,
- kTOPS20,
- kNTFS,
- kQDOS,
- kAcorn,
- kVFAT,
- kMVS,
- kBeOS,
- kTandem,
-
- kUnknown = 255
- };
- }
-}
-
-static const char *kHostOSes[] =
-{
- "FAT",
- "AMIGA",
- "VMS",
- "Unix",
- "VM/CMS",
- "Atari",
- "HPFS",
- "Macintosh",
- "Z-System",
- "CP/M",
- "TOPS-20",
- "NTFS",
- "SMS/QDOS",
- "Acorn",
- "VFAT",
- "MVS",
- "BeOS",
- "Tandem",
- "OS/400",
- "OS/X"
-};
-
-static const char *kUnknownOS = "Unknown";
-
-class CItem
-{
- bool TestFlag(Byte flag) const { return (Flags & flag) != 0; }
-public:
- Byte Method;
- Byte Flags;
- Byte ExtraFlags;
- Byte HostOS;
- UInt32 Time;
- UInt32 Crc;
- UInt32 Size32;
-
- AString Name;
- AString Comment;
- // CByteBuffer Extra;
-
- // bool IsText() const { return TestFlag(NHeader::NFlags::kIsText); }
- bool HeaderCrcIsPresent() const { return TestFlag(NHeader::NFlags::kCrc); }
- bool ExtraFieldIsPresent() const { return TestFlag(NHeader::NFlags::kExtra); }
- bool NameIsPresent() const { return TestFlag(NHeader::NFlags::kName); }
- bool CommentIsPresent() const { return TestFlag(NHeader::NFlags::kComment); }
-
- void Clear()
- {
- Name.Empty();
- Comment.Empty();
- // Extra.SetCapacity(0);
- }
-
- HRESULT ReadHeader(NCompress::NDeflate::NDecoder::CCOMCoder *stream);
- HRESULT ReadFooter1(NCompress::NDeflate::NDecoder::CCOMCoder *stream);
- HRESULT ReadFooter2(ISequentialInStream *stream);
-
- HRESULT WriteHeader(ISequentialOutStream *stream);
- HRESULT WriteFooter(ISequentialOutStream *stream);
-};
-
-static HRESULT ReadBytes(NCompress::NDeflate::NDecoder::CCOMCoder *stream, Byte *data, UInt32 size)
-{
- for (UInt32 i = 0; i < size; i++)
- data[i] = stream->ReadByte();
- return stream->InputEofError() ? S_FALSE : S_OK;
-}
-
-static HRESULT SkipBytes(NCompress::NDeflate::NDecoder::CCOMCoder *stream, UInt32 size)
-{
- for (UInt32 i = 0; i < size; i++)
- stream->ReadByte();
- return stream->InputEofError() ? S_FALSE : S_OK;
-}
-
-static HRESULT ReadUInt16(NCompress::NDeflate::NDecoder::CCOMCoder *stream, UInt16 &value /* , UInt32 &crc */)
-{
- value = 0;
- for (int i = 0; i < 2; i++)
- {
- Byte b = stream->ReadByte();
- if (stream->InputEofError())
- return S_FALSE;
- // crc = CRC_UPDATE_BYTE(crc, b);
- value |= (UInt16(b) << (8 * i));
- }
- return S_OK;
-}
-
-static HRESULT ReadString(NCompress::NDeflate::NDecoder::CCOMCoder *stream, AString &s, UInt32 limit /* , UInt32 &crc */)
-{
- s.Empty();
- for (UInt32 i = 0; i < limit; i++)
- {
- Byte b = stream->ReadByte();
- if (stream->InputEofError())
- return S_FALSE;
- // crc = CRC_UPDATE_BYTE(crc, b);
- if (b == 0)
- return S_OK;
- s += (char)b;
- }
- return S_FALSE;
-}
-
-HRESULT CItem::ReadHeader(NCompress::NDeflate::NDecoder::CCOMCoder *stream)
-{
- Clear();
-
- // Header-CRC field had another meaning in old version of gzip!
- // UInt32 crc = CRC_INIT_VAL;
- Byte buf[10];
-
- RINOK(ReadBytes(stream, buf, 10));
-
- if (GetUi16(buf) != kSignature)
- return S_FALSE;
-
- Method = buf[2];
-
- if (Method != NHeader::NCompressionMethod::kDeflate)
- return S_FALSE;
-
- Flags = buf[3];
- Time = Get32(buf + 4);
- ExtraFlags = buf[8];
- HostOS = buf[9];
-
- // crc = CrcUpdate(crc, buf, 10);
-
- if (ExtraFieldIsPresent())
- {
- UInt16 extraSize;
- RINOK(ReadUInt16(stream, extraSize /* , crc */));
- RINOK(SkipBytes(stream, extraSize));
- // Extra.SetCapacity(extraSize);
- // RINOK(ReadStream_FALSE(stream, Extra, extraSize));
- // crc = CrcUpdate(crc, Extra, extraSize);
- }
- if (NameIsPresent())
- RINOK(ReadString(stream, Name, (1 << 10) /* , crc */));
- if (CommentIsPresent())
- RINOK(ReadString(stream, Comment, (1 << 16) /* , crc */));
-
- if (HeaderCrcIsPresent())
- {
- UInt16 headerCRC;
- // UInt32 dummy = 0;
- RINOK(ReadUInt16(stream, headerCRC /* , dummy */));
- /*
- if ((UInt16)CRC_GET_DIGEST(crc) != headerCRC)
- return S_FALSE;
- */
- }
- return stream->InputEofError() ? S_FALSE : S_OK;
-}
-
-HRESULT CItem::ReadFooter1(NCompress::NDeflate::NDecoder::CCOMCoder *stream)
-{
- Byte buf[8];
- RINOK(ReadBytes(stream, buf, 8));
- Crc = Get32(buf);
- Size32 = Get32(buf + 4);
- return stream->InputEofError() ? S_FALSE : S_OK;
-}
-
-HRESULT CItem::ReadFooter2(ISequentialInStream *stream)
-{
- Byte buf[8];
- RINOK(ReadStream_FALSE(stream, buf, 8));
- Crc = Get32(buf);
- Size32 = Get32(buf + 4);
- return S_OK;
-}
-
-HRESULT CItem::WriteHeader(ISequentialOutStream *stream)
-{
- Byte buf[10];
- SetUi16(buf, kSignature);
- buf[2] = Method;
- buf[3] = Flags & NHeader::NFlags::kName;
- // buf[3] |= NHeader::NFlags::kCrc;
- SetUi32(buf + 4, Time);
- buf[8] = ExtraFlags;
- buf[9] = HostOS;
- RINOK(WriteStream(stream, buf, 10));
- // crc = CrcUpdate(CRC_INIT_VAL, buf, 10);
- if (NameIsPresent())
- {
- // crc = CrcUpdate(crc, (const char *)Name, Name.Length() + 1);
- RINOK(WriteStream(stream, (const char *)Name, Name.Length() + 1));
- }
- // SetUi16(buf, (UInt16)CRC_GET_DIGEST(crc));
- // RINOK(WriteStream(stream, buf, 2));
- return S_OK;
-}
-
-HRESULT CItem::WriteFooter(ISequentialOutStream *stream)
-{
- Byte buf[8];
- SetUi32(buf, Crc);
- SetUi32(buf + 4, Size32);
- return WriteStream(stream, buf, 8);
-}
-
-class CHandler:
- public IInArchive,
- public IArchiveOpenSeq,
- public IOutArchive,
- public ISetProperties,
- public CMyUnknownImp
-{
- CItem _item;
- UInt64 _startPosition;
- UInt64 _headerSize;
- UInt64 _packSize;
- bool _packSizeDefined;
- CMyComPtr<IInStream> _stream;
- CMyComPtr<ICompressCoder> _decoder;
- NCompress::NDeflate::NDecoder::CCOMCoder *_decoderSpec;
-
- CDeflateProps _method;
-
-public:
- MY_UNKNOWN_IMP4(IInArchive, IArchiveOpenSeq, IOutArchive, ISetProperties)
- INTERFACE_IInArchive(;)
- INTERFACE_IOutArchive(;)
- STDMETHOD(OpenSeq)(ISequentialInStream *stream);
- STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProps);
-
- CHandler()
- {
- _decoderSpec = new NCompress::NDeflate::NDecoder::CCOMCoder;
- _decoder = _decoderSpec;
- }
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidHostOS, VT_BSTR},
- { NULL, kpidCRC, VT_UI4}
- // { NULL, kpidComment, VT_BSTR}
-}
-;
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO_Table
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPhySize: if (_packSizeDefined) prop = _packSize; break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = 1;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidPath:
- if (_item.NameIsPresent())
- prop = MultiByteToUnicodeString(_item.Name, CP_ACP);
- break;
- // case kpidComment: if (_item.CommentIsPresent()) prop = MultiByteToUnicodeString(_item.Comment, CP_ACP); break;
- case kpidMTime:
- {
- if (_item.Time != 0)
- {
- FILETIME utc;
- NTime::UnixTimeToFileTime(_item.Time, utc);
- prop = utc;
- }
- break;
- }
- case kpidSize: if (_stream) prop = (UInt64)_item.Size32; break;
- case kpidPackSize: if (_packSizeDefined) prop = _packSize; break;
- case kpidHostOS: prop = (_item.HostOS < sizeof(kHostOSes) / sizeof(kHostOSes[0])) ?
- kHostOSes[_item.HostOS] : kUnknownOS; break;
- case kpidCRC: if (_stream) prop = _item.Crc; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *)
-{
- COM_TRY_BEGIN
- HRESULT res;
- try
- {
- RINOK(stream->Seek(0, STREAM_SEEK_CUR, &_startPosition));
- res = OpenSeq(stream);
- if (res == S_OK)
- {
- UInt64 endPos;
- res = stream->Seek(-8, STREAM_SEEK_END, &endPos);
- _packSize = endPos + 8 - _startPosition;
- _packSizeDefined = true;
- if (res == S_OK)
- {
- res = _item.ReadFooter2(stream);
- _stream = stream;
- }
- }
- }
- catch(...) { res = S_FALSE; }
- if (res != S_OK)
- Close();
- return res;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
-{
- COM_TRY_BEGIN
- HRESULT res;
- try
- {
- Close();
- _decoderSpec->SetInStream(stream);
- _decoderSpec->InitInStream(true);
- res = _item.ReadHeader(_decoderSpec);
- _headerSize = _decoderSpec->GetInputProcessedSize();
- }
- catch(...) { res = S_FALSE; }
- if (res != S_OK)
- Close();
- return res;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _packSizeDefined = false;
- _stream.Release();
- _decoderSpec->ReleaseInStream();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- if (numItems == 0)
- return S_OK;
- if (numItems != (UInt32)-1 && (numItems != 1 || indices[0] != 0))
- return E_INVALIDARG;
-
- if (_stream)
- extractCallback->SetTotal(_packSize);
- UInt64 currentTotalPacked = 0;
- RINOK(extractCallback->SetCompleted(&currentTotalPacked));
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- RINOK(extractCallback->GetStream(0, &realOutStream, askMode));
- if (!testMode && !realOutStream)
- return S_OK;
-
- extractCallback->PrepareOperation(askMode);
-
- COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
- outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init();
- realOutStream.Release();
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(extractCallback, true);
-
- if (_stream)
- {
- RINOK(_stream->Seek(_startPosition, STREAM_SEEK_SET, NULL));
- _decoderSpec->InitInStream(true);
- }
- bool firstItem = true;
- Int32 opRes;
- for (;;)
- {
- lps->InSize = _packSize = _decoderSpec->GetInputProcessedSize();
- _packSizeDefined = true;
- lps->OutSize = outStreamSpec->GetSize();
- RINOK(lps->SetCur());
-
- CItem item;
- if (!firstItem || _stream)
- {
- HRESULT result = item.ReadHeader(_decoderSpec);
- if (result != S_OK)
- {
- if (result != S_FALSE)
- return result;
- opRes = firstItem ?
- NExtract::NOperationResult::kDataError :
- NExtract::NOperationResult::kOK;
- break;
- }
- }
- firstItem = false;
-
- UInt64 startOffset = outStreamSpec->GetSize();
- outStreamSpec->InitCRC();
-
- HRESULT result = _decoderSpec->CodeResume(outStream, NULL, progress);
- if (result != S_OK)
- {
- if (result != S_FALSE)
- return result;
- opRes = NExtract::NOperationResult::kDataError;
- break;
- }
-
- _decoderSpec->AlignToByte();
- if (item.ReadFooter1(_decoderSpec) != S_OK)
- {
- opRes = NExtract::NOperationResult::kDataError;
- break;
- }
- if (item.Crc != outStreamSpec->GetCRC() ||
- item.Size32 != (UInt32)(outStreamSpec->GetSize() - startOffset))
- {
- opRes = NExtract::NOperationResult::kCRCError;
- break;
- }
- }
- outStream.Release();
- return extractCallback->SetOperationResult(opRes);
- COM_TRY_END
-}
-
-static const Byte kHostOS =
- #ifdef _WIN32
- NHeader::NHostOS::kFAT;
- #else
- NHeader::NHostOS::kUnix;
- #endif
-
-static HRESULT UpdateArchive(
- ISequentialOutStream *outStream,
- UInt64 unpackSize,
- const CItem &newItem,
- CDeflateProps &deflateProps,
- IArchiveUpdateCallback *updateCallback)
-{
- UInt64 complexity = 0;
- RINOK(updateCallback->SetTotal(unpackSize));
- RINOK(updateCallback->SetCompleted(&complexity));
-
- CMyComPtr<ISequentialInStream> fileInStream;
-
- RINOK(updateCallback->GetStream(0, &fileInStream));
-
- CSequentialInStreamWithCRC *inStreamSpec = new CSequentialInStreamWithCRC;
- CMyComPtr<ISequentialInStream> crcStream(inStreamSpec);
- inStreamSpec->SetStream(fileInStream);
- inStreamSpec->Init();
-
- CLocalProgress *lps = new CLocalProgress;
- CMyComPtr<ICompressProgressInfo> progress = lps;
- lps->Init(updateCallback, true);
-
- CItem item = newItem;
- item.Method = NHeader::NCompressionMethod::kDeflate;
- item.ExtraFlags = deflateProps.IsMaximum() ?
- NHeader::NExtraFlags::kMaximum :
- NHeader::NExtraFlags::kFastest;
-
- item.HostOS = kHostOS;
-
- RINOK(item.WriteHeader(outStream));
-
- NCompress::NDeflate::NEncoder::CCOMCoder *deflateEncoderSpec = new NCompress::NDeflate::NEncoder::CCOMCoder;
- CMyComPtr<ICompressCoder> deflateEncoder = deflateEncoderSpec;
- RINOK(deflateProps.SetCoderProperties(deflateEncoderSpec));
- RINOK(deflateEncoder->Code(crcStream, outStream, NULL, NULL, progress));
-
- item.Crc = inStreamSpec->GetCRC();
- item.Size32 = (UInt32)inStreamSpec->GetSize();
- RINOK(item.WriteFooter(outStream));
- return updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK);
-}
-
-STDMETHODIMP CHandler::GetFileTimeType(UInt32 *timeType)
-{
- *timeType = NFileTimeType::kUnix;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
- IArchiveUpdateCallback *updateCallback)
-{
- if (numItems != 1)
- return E_INVALIDARG;
-
- Int32 newData, newProps;
- UInt32 indexInArchive;
- if (!updateCallback)
- return E_FAIL;
- RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProps, &indexInArchive));
-
- CItem newItem = _item;
- newItem.ExtraFlags = 0;
- newItem.Flags = 0;
- if (IntToBool(newProps))
- {
- {
- FILETIME utcTime;
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(0, kpidMTime, &prop));
- if (prop.vt != VT_FILETIME)
- return E_INVALIDARG;
- utcTime = prop.filetime;
- if (!NTime::FileTimeToUnixTime(utcTime, newItem.Time))
- return E_INVALIDARG;
- }
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(0, kpidPath, &prop));
- if (prop.vt == VT_BSTR)
- {
- UString name = prop.bstrVal;
- int dirDelimiterPos = name.ReverseFind(CHAR_PATH_SEPARATOR);
- if (dirDelimiterPos >= 0)
- name = name.Mid(dirDelimiterPos + 1);
- newItem.Name = UnicodeStringToMultiByte(name, CP_ACP);
- if (!newItem.Name.IsEmpty())
- newItem.Flags |= NHeader::NFlags::kName;
- }
- else if (prop.vt != VT_EMPTY)
- return E_INVALIDARG;
- }
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(0, kpidIsDir, &prop));
- if (prop.vt == VT_BOOL)
- {
- if (prop.boolVal != VARIANT_FALSE)
- return E_INVALIDARG;
- }
- else if (prop.vt != VT_EMPTY)
- return E_INVALIDARG;
- }
- }
-
- if (IntToBool(newData))
- {
- UInt64 size;
- {
- NCOM::CPropVariant prop;
- RINOK(updateCallback->GetProperty(0, kpidSize, &prop));
- if (prop.vt != VT_UI8)
- return E_INVALIDARG;
- size = prop.uhVal.QuadPart;
- }
-
- return UpdateArchive(outStream, size, newItem, _method, updateCallback);
- }
-
- if (indexInArchive != 0)
- return E_INVALIDARG;
-
- if (!_stream)
- return E_NOTIMPL;
-
- UInt64 offset = _startPosition;
- if (IntToBool(newProps))
- {
- newItem.WriteHeader(outStream);
- offset += _headerSize;
- }
- RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL));
- return NCompress::CopyStream(_stream, outStream, NULL);
-}
-
-STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProps)
-{
- return _method.SetProperties(names, values, numProps);
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-#ifndef EXTRACT_ONLY
-static IOutArchive *CreateArcOut() { return new CHandler; }
-#else
-#define CreateArcOut 0
-#endif
-
-static CArcInfo g_ArcInfo =
- { L"gzip", L"gz gzip tgz tpz", L"* * .tar .tar", 0xEF, { 0x1F, 0x8B, 8 }, 3, true, CreateArc, CreateArcOut };
-
-REGISTER_ARC(GZip)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.cpp
deleted file mode 100644
index f226458d4..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-// HfsHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Windows/PropVariant.h"
-#include "../../Common/StreamUtils.h"
-#include "HfsHandler.h"
-
-namespace NArchive {
-namespace NHfs {
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidCTime, VT_FILETIME},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidATime, VT_FILETIME}
-};
-
-STATPROPSTG kArcProps[] =
-{
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidClusterSize, VT_UI4},
- { NULL, kpidFreeSpace, VT_UI8},
- { NULL, kpidCTime, VT_FILETIME},
- { NULL, kpidMTime, VT_FILETIME}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-static void HfsTimeToProp(UInt32 hfsTime, NWindows::NCOM::CPropVariant &prop)
-{
- FILETIME ft;
- HfsTimeToFileTime(hfsTime, ft);
- prop = ft;
-}
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMethod: prop = _db.Header.IsHfsX() ? L"HFSX" : L"HFS+"; break;
- case kpidClusterSize: prop = (UInt32)1 << _db.Header.BlockSizeLog; break;
- case kpidFreeSpace: prop = (UInt64)_db.Header.NumFreeBlocks << _db.Header.BlockSizeLog; break;
- case kpidMTime: HfsTimeToProp(_db.Header.MTime, prop); break;
- case kpidCTime:
- {
- FILETIME localFt, ft;
- HfsTimeToFileTime(_db.Header.CTime, localFt);
- if (LocalFileTimeToFileTime(&localFt, &ft))
- prop = ft;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CItem &item = _db.Items[index];
- switch(propID)
- {
- case kpidPath: prop = _db.GetItemPath(index); break;
- case kpidIsDir: prop = item.IsDir(); break;
-
- case kpidCTime: HfsTimeToProp(item.CTime, prop); break;
- case kpidMTime: HfsTimeToProp(item.MTime, prop); break;
- case kpidATime: HfsTimeToProp(item.ATime, prop); break;
-
- case kpidPackSize: if (!item.IsDir()) prop = (UInt64)item.NumBlocks << _db.Header.BlockSizeLog; break;
- case kpidSize: if (!item.IsDir()) prop = item.Size; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-class CProgressImp: public CProgressVirt
-{
- CMyComPtr<IArchiveOpenCallback> _callback;
-public:
- HRESULT SetTotal(UInt64 numFiles);
- HRESULT SetCompleted(UInt64 numFiles);
- CProgressImp(IArchiveOpenCallback *callback): _callback(callback) {}
-};
-
-HRESULT CProgressImp::SetTotal(UInt64 numFiles)
-{
- if (_callback)
- return _callback->SetTotal(&numFiles, NULL);
- return S_OK;
-}
-
-HRESULT CProgressImp::SetCompleted(UInt64 numFiles)
-{
- if (_callback)
- return _callback->SetCompleted(&numFiles, NULL);
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- Close();
- try
- {
- CProgressImp progressImp(callback);
- HRESULT res = _db.Open(inStream, &progressImp);
- if (res == E_ABORT)
- return res;
- if (res != S_OK)
- return S_FALSE;
- _stream = inStream;
- }
- catch(...) { return S_FALSE; }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _stream.Release();
- _db.Clear();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testMode, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool allFilesMode = (numItems == (UInt32)-1);
- if (allFilesMode)
- numItems = _db.Items.Size();
- if (numItems == 0)
- return S_OK;
- UInt32 i;
- UInt64 totalSize = 0;
- for (i = 0; i < numItems; i++)
- {
- const CItem &item = _db.Items[allFilesMode ? i : indices[i]];
- if (!item.IsDir())
- totalSize += item.Size;
- }
- RINOK(extractCallback->SetTotal(totalSize));
-
- UInt64 currentTotalSize = 0, currentItemSize = 0;
-
- CByteBuffer buf;
- const UInt32 kBufSize = (1 << 16);
- buf.SetCapacity(kBufSize);
-
- for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
- {
- RINOK(extractCallback->SetCompleted(&currentTotalSize));
- Int32 index = allFilesMode ? i : indices[i];
- const CItem &item = _db.Items[index];
- currentItemSize = 0;
- if (!item.IsDir())
- currentItemSize = item.Size;
-
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- if (item.IsDir())
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- UInt64 pos = 0;
- int res = NExtract::NOperationResult::kOK;
- int i;
- for (i = 0; i < item.Extents.Size(); i++)
- {
- if (item.Size == pos)
- break;
- if (res != NExtract::NOperationResult::kOK)
- break;
- const CExtent &e = item.Extents[i];
- RINOK(_stream->Seek((UInt64)e.Pos << _db.Header.BlockSizeLog, STREAM_SEEK_SET, NULL));
- UInt64 extentSize = (UInt64)e.NumBlocks << _db.Header.BlockSizeLog;
- for (;;)
- {
- if (extentSize == 0)
- break;
- UInt64 rem = item.Size - pos;
- if (rem == 0)
- {
- if (extentSize >= (UInt64)((UInt32)1 << _db.Header.BlockSizeLog))
- res = NExtract::NOperationResult::kDataError;
- break;
- }
- UInt32 curSize = kBufSize;
- if (curSize > rem)
- curSize = (UInt32)rem;
- if (curSize > extentSize)
- curSize = (UInt32)extentSize;
- RINOK(ReadStream_FALSE(_stream, buf, curSize));
- if (realOutStream)
- {
- RINOK(WriteStream(realOutStream, buf, curSize));
- }
- pos += curSize;
- extentSize -= curSize;
- UInt64 processed = currentTotalSize + pos;
- RINOK(extractCallback->SetCompleted(&processed));
- }
- }
- if (i != item.Extents.Size() || item.Size != pos)
- res = NExtract::NOperationResult::kDataError;
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult(res));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _db.Items.Size();
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.h
deleted file mode 100644
index 269af218e..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsHandler.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// HfsHandler.h
-
-#ifndef __ARCHIVE_HFS_HANDLER_H
-#define __ARCHIVE_HFS_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-#include "HfsIn.h"
-
-namespace NArchive {
-namespace NHfs {
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- CDatabase _db;
-public:
- MY_UNKNOWN_IMP1(IInArchive)
- INTERFACE_IInArchive(;)
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.cpp
deleted file mode 100644
index 8391dd936..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.cpp
+++ /dev/null
@@ -1,480 +0,0 @@
-// HfsIn.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/StreamUtils.h"
-#include "Common/IntToString.h"
-
-#include "HfsIn.h"
-
-#include "../../../../C/CpuArch.h"
-
-#define Get16(p) GetBe16(p)
-#define Get32(p) GetBe32(p)
-#define Get64(p) GetBe64(p)
-
-namespace NArchive {
-namespace NHfs {
-
-#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
-
-static int CompareIdToIndex(const CIdIndexPair *p1, const CIdIndexPair *p2, void * /* param */)
-{
- RINOZ(MyCompare(p1->ID, p2->ID));
- return MyCompare(p1->Index, p2->Index);
-}
-
-bool operator< (const CIdIndexPair &a1, const CIdIndexPair &a2) { return (a1.ID < a2.ID); }
-bool operator> (const CIdIndexPair &a1, const CIdIndexPair &a2) { return (a1.ID > a2.ID); }
-bool operator==(const CIdIndexPair &a1, const CIdIndexPair &a2) { return (a1.ID == a2.ID); }
-bool operator!=(const CIdIndexPair &a1, const CIdIndexPair &a2) { return (a1.ID != a2.ID); }
-
-static UString GetSpecName(const UString &name, UInt32 /* id */)
-{
- UString name2 = name;
- name2.Trim();
- if (name2.IsEmpty())
- {
- /*
- wchar_t s[32];
- ConvertUInt64ToString(id, s);
- return L"[" + (UString)s + L"]";
- */
- return L"[]";
- }
- return name;
-}
-
-UString CDatabase::GetItemPath(int index) const
-{
- const CItem *item = &Items[index];
- UString name = GetSpecName(item->Name, item->ID);
-
- for (int i = 0; i < 1000; i++)
- {
- if (item->ParentID < 16 && item->ParentID != 2)
- {
- if (item->ParentID != 1)
- break;
- return name;
- }
- CIdIndexPair pair;
- pair.ID = item->ParentID;
- pair.Index = 0;
- int indexInMap = IdToIndexMap.FindInSorted(pair);
- if (indexInMap < 0)
- break;
- item = &Items[IdToIndexMap[indexInMap].Index];
- name = GetSpecName(item->Name, item->ID) + WCHAR_PATH_SEPARATOR + name;
- }
- return (UString)L"Unknown" + WCHAR_PATH_SEPARATOR + name;
-}
-
-void CFork::Parse(const Byte *p)
-{
- Size = Get64(p);
- // ClumpSize = Get32(p + 8);
- NumBlocks = Get32(p + 0xC);
- for (int i = 0; i < 8; i++)
- {
- CExtent &e = Extents[i];
- e.Pos = Get32(p + 0x10 + i * 8);
- e.NumBlocks = Get32(p + 0x10 + i * 8 + 4);
- }
-}
-
-static HRESULT ReadExtent(int blockSizeLog, IInStream *inStream, Byte *buf, const CExtent &e)
-{
- RINOK(inStream->Seek((UInt64)e.Pos << blockSizeLog, STREAM_SEEK_SET, NULL));
- return ReadStream_FALSE(inStream, buf, (size_t)e.NumBlocks << blockSizeLog);
-}
-
-HRESULT CDatabase::ReadFile(const CFork &fork, CByteBuffer &buf, IInStream *inStream)
-{
- if (fork.NumBlocks >= Header.NumBlocks)
- return S_FALSE;
- size_t totalSize = (size_t)fork.NumBlocks << Header.BlockSizeLog;
- if ((totalSize >> Header.BlockSizeLog) != fork.NumBlocks)
- return S_FALSE;
- buf.SetCapacity(totalSize);
- UInt32 curBlock = 0;
- for (int i = 0; i < 8; i++)
- {
- if (curBlock >= fork.NumBlocks)
- break;
- const CExtent &e = fork.Extents[i];
- if (fork.NumBlocks - curBlock < e.NumBlocks || e.Pos >= Header.NumBlocks)
- return S_FALSE;
- RINOK(ReadExtent(Header.BlockSizeLog, inStream,
- (Byte *)buf + ((size_t)curBlock << Header.BlockSizeLog), e));
- curBlock += e.NumBlocks;
- }
- return S_OK;
-}
-
-struct CNodeDescriptor
-{
- UInt32 fLink;
- UInt32 bLink;
- Byte Kind;
- Byte Height;
- UInt16 NumRecords;
- // UInt16 Reserved;
- void Parse(const Byte *p);
-};
-
-void CNodeDescriptor::Parse(const Byte *p)
-{
- fLink = Get32(p);
- bLink = Get32(p + 4);
- Kind = p[8];
- Height = p[9];
- NumRecords = Get16(p + 10);
-}
-
-struct CHeaderRec
-{
- // UInt16 TreeDepth;
- // UInt32 RootNode;
- // UInt32 LeafRecords;
- UInt32 FirstLeafNode;
- // UInt32 LastLeafNode;
- int NodeSizeLog;
- // UInt16 MaxKeyLength;
- UInt32 TotalNodes;
- // UInt32 FreeNodes;
- // UInt16 Reserved1;
- // UInt32 ClumpSize;
- // Byte BtreeType;
- // Byte KeyCompareType;
- // UInt32 Attributes;
- // UInt32 Reserved3[16];
-
- HRESULT Parse(const Byte *p);
-};
-
-HRESULT CHeaderRec::Parse(const Byte *p)
-{
- // TreeDepth = Get16(p);
- // RootNode = Get32(p + 2);
- // LeafRecords = Get32(p + 6);
- FirstLeafNode = Get32(p + 0xA);
- // LastLeafNode = Get32(p + 0xE);
- UInt32 nodeSize = Get16(p + 0x12);
-
- int i;
- for (i = 9; ((UInt32)1 << i) != nodeSize; i++)
- if (i == 16)
- return S_FALSE;
- NodeSizeLog = i;
-
- // MaxKeyLength = Get16(p + 0x14);
- TotalNodes = Get32(p + 0x16);
- // FreeNodes = Get32(p + 0x1A);
- // Reserved1 = Get16(p + 0x1E);
- // ClumpSize = Get32(p + 0x20);
- // BtreeType = p[0x24];
- // KeyCompareType = p[0x25];
- // Attributes = Get32(p + 0x26);
- /*
- for (int i = 0; i < 16; i++)
- Reserved3[i] = Get32(p + 0x2A + i * 4);
- */
- return S_OK;
-}
-
-
-enum ENodeType
-{
- NODE_TYPE_LEAF = 0xFF,
- NODE_TYPE_INDEX = 0,
- NODE_TYPE_HEADER = 1,
- NODE_TYPE_MODE = 2
-};
-
-HRESULT CDatabase::LoadExtentFile(IInStream *inStream)
-{
- // FileExtents.Clear();
- // ResExtents.Clear();
-
- CByteBuffer extents;
- RINOK(ReadFile(Header.ExtentsFile, extents, inStream));
-
- const Byte *p = (const Byte *)extents;
-
- // CNodeDescriptor nodeDesc;
- // nodeDesc.Parse(p);
- CHeaderRec hr;
- RINOK(hr.Parse(p + 14));
-
- UInt32 node = hr.FirstLeafNode;
- if (node != 0)
- return S_FALSE;
- /*
- while (node != 0)
- {
- size_t nodeOffset = node * hr.NodeSize;
- if ((node + 1)* hr.NodeSize > CatalogBuf.GetCapacity())
- return S_FALSE;
- CNodeDescriptor desc;
- desc.Parse(p + nodeOffset);
- if (desc.Kind != NODE_TYPE_LEAF)
- return S_FALSE;
- UInt32 ptr = hr.NodeSize;
- for (int i = 0; i < desc.NumRecords; i++)
- {
- UInt32 offs = Get16(p + nodeOffset + hr.NodeSize - (i + 1) * 2);
- UInt32 offsNext = Get16(p + nodeOffset + hr.NodeSize - (i + 2) * 2);
-
- const Byte *r = p + nodeOffset + offs;
- int keyLength = Get16(r);
- Byte forkType = r[2];
- UInt32 id = Get16(r + 4);
- UInt32 startBlock = Get16(r + 4);
- CObjectVector<CIdExtents> *extents = (forkType == 0) ? &FileExtents : &ResExtents;
- if (extents->Size() == 0)
- extents->Add(CIdExtents());
- else
- {
- CIdExtents &e = extents->Back();
- if (e.ID != id)
- {
- if (e.ID > id)
- return S_FALSE;
- extents->Add(CIdExtents());
- }
- }
- CIdExtents &e = extents->Back();
- for (UInt32 k = offs + 10 + 2; k + 8 <= offsNext; k += 8)
- {
- CExtent ee;
- ee.Pos = Get32(p + nodeOffset + k);
- ee.NumBlocks = Get32(p + nodeOffset + k * 4);
- e.Extents.Add(ee);
- }
- }
- node