summaryrefslogtreecommitdiffstats
path: root/src/libs/7zip/win/CPP
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/CPP
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/CPP')
-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
292 files changed, 17 insertions, 61710 deletions
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 = desc.fLink;
- }
- */
- return S_OK;
-}
-
-
-HRESULT CDatabase::LoadCatalog(IInStream *inStream, CProgressVirt *progress)
-{
- Items.Clear();
- IdToIndexMap.ClearAndFree();
-
- CByteBuffer catalogBuf;
- RINOK(ReadFile(Header.CatalogFile, catalogBuf, inStream));
- const Byte *p = (const Byte *)catalogBuf;
-
- // CNodeDescriptor nodeDesc;
- // nodeDesc.Parse(p);
- CHeaderRec hr;
- hr.Parse(p + 14);
-
- // CaseSensetive = (Header.IsHfsX() && hr.KeyCompareType == 0xBC);
-
- if ((catalogBuf.GetCapacity() >> hr.NodeSizeLog) < hr.TotalNodes)
- return S_FALSE;
-
- CByteBuffer usedBuf;
- usedBuf.SetCapacity(hr.TotalNodes);
- for (UInt32 i = 0; i < hr.TotalNodes; i++)
- usedBuf[i] = 0;
-
- UInt32 node = hr.FirstLeafNode;
- while (node != 0)
- {
- if (node >= hr.TotalNodes)
- return S_FALSE;
- if (usedBuf[node])
- return S_FALSE;
- usedBuf[node] = 1;
- size_t nodeOffset = (size_t)node << hr.NodeSizeLog;
- CNodeDescriptor desc;
- desc.Parse(p + nodeOffset);
- if (desc.Kind != NODE_TYPE_LEAF)
- return S_FALSE;
- for (int i = 0; i < desc.NumRecords; i++)
- {
- UInt32 nodeSize = (1 << hr.NodeSizeLog);
- UInt32 offs = Get16(p + nodeOffset + nodeSize - (i + 1) * 2);
- UInt32 offsNext = Get16(p + nodeOffset + nodeSize - (i + 2) * 2);
- UInt32 recSize = offsNext - offs;
- if (offsNext >= nodeSize || offsNext < offs || recSize < 6)
- return S_FALSE;
-
- CItem item;
-
- const Byte *r = p + nodeOffset + offs;
- UInt32 keyLength = Get16(r);
- item.ParentID = Get32(r + 2);
- UString name;
- if (keyLength < 6 || (keyLength & 1) != 0 || keyLength + 2 > recSize)
- return S_FALSE;
- r += 6;
- recSize -= 6;
- keyLength -= 6;
-
- int nameLength = Get16(r);
- if (nameLength * 2 != (int)keyLength)
- return S_FALSE;
- r += 2;
- recSize -= 2;
-
- wchar_t *pp = name.GetBuffer(nameLength + 1);
-
- int j;
- for (j = 0; j < nameLength; j++)
- pp[j] = ((wchar_t)r[j * 2] << 8) | r[j * 2 + 1];
- pp[j] = 0;
- name.ReleaseBuffer();
- r += j * 2;
- recSize -= j * 2;
-
- if (recSize < 2)
- return S_FALSE;
- item.Type = Get16(r);
-
- if (item.Type != RECORD_TYPE_FOLDER && item.Type != RECORD_TYPE_FILE)
- continue;
- if (recSize < 0x58)
- return S_FALSE;
-
- // item.Flags = Get16(r + 2);
- // item.Valence = Get32(r + 4);
- item.ID = Get32(r + 8);
- item.CTime = Get32(r + 0xC);
- item.MTime = Get32(r + 0x10);
- // item.AttrMTime = Get32(r + 0x14);
- item.ATime = Get32(r + 0x18);
- // item.BackupDate = Get32(r + 0x1C);
-
- /*
- item.OwnerID = Get32(r + 0x20);
- item.GroupID = Get32(r + 0x24);
- item.AdminFlags = r[0x28];
- item.OwnerFlags = r[0x29];
- item.FileMode = Get16(r + 0x2A);
- item.special.iNodeNum = Get16(r + 0x2C);
- */
-
- item.Name = name;
-
- if (item.IsDir())
- {
- CIdIndexPair pair;
- pair.ID = item.ID;
- pair.Index = Items.Size();
- IdToIndexMap.Add(pair);
- }
- else
- {
- CFork fd;
- recSize -= 0x58;
- r += 0x58;
- if (recSize < 0x50 * 2)
- return S_FALSE;
- fd.Parse(r);
- item.Size = fd.Size;
- item.NumBlocks = fd.NumBlocks;
- UInt32 curBlock = 0;
- for (int j = 0; j < 8; j++)
- {
- if (curBlock >= fd.NumBlocks)
- break;
- const CExtent &e = fd.Extents[j];
- item.Extents.Add(e);
- curBlock += e.NumBlocks;
- }
- }
- Items.Add(item);
- if (progress && Items.Size() % 100 == 0)
- {
- RINOK(progress->SetCompleted(Items.Size()));
- }
- }
- node = desc.fLink;
- }
- IdToIndexMap.Sort(CompareIdToIndex, NULL);
- return S_OK;
-}
-
-HRESULT CDatabase::Open(IInStream *inStream, CProgressVirt *progress)
-{
- static const UInt32 kHeaderSize = 1024 + 512;
- Byte buf[kHeaderSize];
- RINOK(ReadStream_FALSE(inStream, buf, kHeaderSize));
- int i;
- for (i = 0; i < 1024; i++)
- if (buf[i] != 0)
- return S_FALSE;
- const Byte *p = buf + 1024;
- CVolHeader &h = Header;
-
- h.Header[0] = p[0];
- h.Header[1] = p[1];
- if (p[0] != 'H' || (p[1] != '+' && p[1] != 'X'))
- return S_FALSE;
- h.Version = Get16(p + 2);
- if (h.Version < 4 || h.Version > 5)
- return S_FALSE;
-
- // h.Attr = Get32(p + 4);
- // h.LastMountedVersion = Get32(p + 8);
- // h.JournalInfoBlock = Get32(p + 0xC);
-
- h.CTime = Get32(p + 0x10);
- h.MTime = Get32(p + 0x14);
- // h.BackupTime = Get32(p + 0x18);
- // h.CheckedTime = Get32(p + 0x1C);
-
- // h.NumFiles = Get32(p + 0x20);
- // h.NumFolders = Get32(p + 0x24);
-
- UInt32 numFiles = Get32(p + 0x20);
- UInt32 numFolders = Get32(p + 0x24);;
- if (progress)
- {
- RINOK(progress->SetTotal(numFolders + numFiles));
- }
-
- UInt32 blockSize = Get32(p + 0x28);
-
- for (i = 9; ((UInt32)1 << i) != blockSize; i++)
- if (i == 31)
- return S_FALSE;
- h.BlockSizeLog = i;
-
- h.NumBlocks = Get32(p + 0x2C);
- h.NumFreeBlocks = Get32(p + 0x30);
-
- /*
- h.WriteCount = Get32(p + 0x44);
- for (i = 0; i < 6; i++)
- h.FinderInfo[i] = Get32(p + 0x50 + i * 4);
- h.VolID = Get64(p + 0x68);
- */
-
- UInt64 endPos;
- RINOK(inStream->Seek(0, STREAM_SEEK_END, &endPos));
- if ((endPos >> h.BlockSizeLog) < h.NumBlocks)
- return S_FALSE;
-
- // h.AllocationFile.Parse(p + 0x70 + 0x50 * 0);
- h.ExtentsFile.Parse( p + 0x70 + 0x50 * 1);
- h.CatalogFile.Parse( p + 0x70 + 0x50 * 2);
- // h.AttributesFile.Parse(p + 0x70 + 0x50 * 3);
- // h.StartupFile.Parse( p + 0x70 + 0x50 * 4);
-
- RINOK(LoadExtentFile(inStream));
- RINOK(LoadCatalog(inStream, progress));
-
- // if (Header.NumFiles + Header.NumFolders != (UInt32)Items.Size()) return S_OK;
-
- return S_OK;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.h b/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.h
deleted file mode 100644
index c19539057..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsIn.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// HfsIn.h
-
-#ifndef __ARCHIVE_HFS_IN_H
-#define __ARCHIVE_HFS_IN_H
-
-#include "Common/MyString.h"
-#include "Common/Buffer.h"
-
-namespace NArchive {
-namespace NHfs {
-
-struct CExtent
-{
- UInt32 Pos;
- UInt32 NumBlocks;
-};
-
-struct CFork
-{
- UInt64 Size;
- // UInt32 ClumpSize;
- UInt32 NumBlocks;
- CExtent Extents[8];
- void Parse(const Byte *p);
-};
-
-struct CVolHeader
-{
- Byte Header[2];
- UInt16 Version;
- // UInt32 Attr;
- // UInt32 LastMountedVersion;
- // UInt32 JournalInfoBlock;
-
- UInt32 CTime;
- UInt32 MTime;
- // UInt32 BackupTime;
- // UInt32 CheckedTime;
-
- // UInt32 NumFiles;
- // UInt32 NumFolders;
- int BlockSizeLog;
- UInt32 NumBlocks;
- UInt32 NumFreeBlocks;
-
- // UInt32 WriteCount;
- // UInt32 FinderInfo[8];
- // UInt64 VolID;
-
- // CFork AllocationFile;
- CFork ExtentsFile;
- CFork CatalogFile;
- // CFork AttributesFile;
- // CFork StartupFile;
-
- bool IsHfsX() const { return Version > 4; }
-};
-
-inline void HfsTimeToFileTime(UInt32 hfsTime, FILETIME &ft)
-{
- UInt64 v = ((UInt64)3600 * 24 * (365 * 303 + 24 * 3) + hfsTime) * 10000000;
- ft.dwLowDateTime = (DWORD)v;
- ft.dwHighDateTime = (DWORD)(v >> 32);
-}
-
-enum ERecordType
-{
- RECORD_TYPE_FOLDER = 1,
- RECORD_TYPE_FILE = 2,
- RECORD_TYPE_FOLDER_THREAD = 3,
- RECORD_TYPE_FILE_THREAD = 4
-};
-
-struct CItem
-{
- UString Name;
-
- UInt32 ParentID;
-
- UInt16 Type;
- // UInt16 Flags;
- // UInt32 Valence;
- UInt32 ID;
- UInt32 CTime;
- UInt32 MTime;
- // UInt32 AttrMTime;
- UInt32 ATime;
- // UInt32 BackupDate;
-
- /*
- UInt32 OwnerID;
- UInt32 GroupID;
- Byte AdminFlags;
- Byte OwnerFlags;
- UInt16 FileMode;
- union
- {
- UInt32 iNodeNum;
- UInt32 LinkCount;
- UInt32 RawDevice;
- } special;
- */
-
- UInt64 Size;
- UInt32 NumBlocks;
- CRecordVector<CExtent> Extents;
-
- bool IsDir() const { return Type == RECORD_TYPE_FOLDER; }
- CItem(): Size(0), NumBlocks(0) {}
-};
-
-struct CIdIndexPair
-{
- UInt32 ID;
- int Index;
-};
-
-struct CProgressVirt
-{
- virtual HRESULT SetTotal(UInt64 numFiles) PURE;
- virtual HRESULT SetCompleted(UInt64 numFiles) PURE;
-};
-
-class CDatabase
-{
- // CObjectVector<CIdExtents> FileExtents;
- // CObjectVector<CIdExtents> ResExtents;
- CRecordVector<CIdIndexPair> IdToIndexMap;
-
- HRESULT LoadExtentFile(IInStream *inStream);
- HRESULT LoadCatalog(IInStream *inStream, CProgressVirt *progress);
-
- HRESULT ReadFile(const CFork &fork, CByteBuffer &buf, IInStream *inStream);
-public:
- CVolHeader Header;
- CObjectVector<CItem> Items;
- // bool CaseSensetive;
-
- void Clear()
- {
- // CaseSensetive = false;
- Items.Clear();
- // FileExtents.Clear();
- // ResExtents.Clear();
- IdToIndexMap.Clear();
- }
-
- UString GetItemPath(int index) const;
- HRESULT Open(IInStream *inStream, CProgressVirt *progress);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsRegister.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsRegister.cpp
deleted file mode 100644
index 51c3c2b15..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Hfs/HfsRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// HfsRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "HfsHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NHfs::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"HFS", L"hfs", 0, 0xE3, { 'H', '+', 0, 4 }, 4, false, CreateArc, 0 };
-
-REGISTER_ARC(Hfs)
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.cpp
deleted file mode 100644
index 4bfb7dc68..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.cpp
+++ /dev/null
@@ -1,326 +0,0 @@
-// IsoHandler.cpp
-
-#include "StdAfx.h"
-
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/ProgressUtils.h"
-
-#include "../../Compress/CopyCoder.h"
-
-#include "../Common/ItemNameUtils.h"
-
-#include "IsoHandler.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-namespace NArchive {
-namespace NIso {
-
-static const STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME}
-};
-
-static const STATPROPSTG kArcProps[] =
-{
- { NULL, kpidComment, VT_BSTR},
- { NULL, kpidCTime, VT_FILETIME},
- { NULL, kpidMTime, VT_FILETIME}
- // { NULL, kpidPhySize, VT_UI8},
- // { NULL, kpidHeadersSize, VT_UI8}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- // try
- {
- if (_archive.Open(stream) != S_OK)
- return S_FALSE;
- _stream = stream;
- }
- // catch(...) { return S_FALSE; }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _archive.Clear();
- _stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _archive.Refs.Size() + _archive.BootEntries.Size();
- return S_OK;
-}
-
-static void AddString(AString &s, const char *name, const Byte *p, int size)
-{
- int i;
- for (i = 0; i < size && p[i]; i++);
- for (; i > 0 && p[i - 1] == ' '; i--);
- if (i != 0)
- {
- AString d;
- memcpy(d.GetBuffer(i), p, i);
- d.ReleaseBuffer(i);
- s += '\n';
- s += name;
- s += ": ";
- s += d;
- }
-}
-
-#define ADD_STRING(n, v) AddString(s, n, vol. ## v, sizeof(vol. ## v))
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- const CVolumeDescriptor &vol = _archive.VolDescs[_archive.MainVolDescIndex];
- switch(propID)
- {
- case kpidComment:
- {
- AString s;
- ADD_STRING("System", SystemId);
- ADD_STRING("Volume", VolumeId);
- ADD_STRING("VolumeSet", VolumeSetId);
- ADD_STRING("Publisher", PublisherId);
- ADD_STRING("Preparer", DataPreparerId);
- ADD_STRING("Application", ApplicationId);
- ADD_STRING("Copyright", CopyrightFileId);
- ADD_STRING("Abstract", AbstractFileId);
- ADD_STRING("Bib", BibFileId);
- prop = s;
- break;
- }
- case kpidCTime: { FILETIME utc; if (vol.CTime.GetFileTime(utc)) prop = utc; break; }
- case kpidMTime: { FILETIME utc; if (vol.MTime.GetFileTime(utc)) prop = utc; break; }
- // case kpidPhySize: break;
- // case kpidHeadersSize: break;
- case kpidError: if (_archive.IncorrectBigEndian) prop = "Incorrect big-endian headers"; 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 (index >= (UInt32)_archive.Refs.Size())
- {
- index -= _archive.Refs.Size();
- const CBootInitialEntry &be = _archive.BootEntries[index];
- switch(propID)
- {
- case kpidPath:
- {
- // wchar_t name[32];
- // ConvertUInt64ToString(index + 1, name);
- UString s = L"[BOOT]" WSTRING_PATH_SEPARATOR;
- // s += name;
- // s += L"-";
- s += be.GetName();
- prop = (const wchar_t *)s;
- break;
- }
- case kpidIsDir: prop = false; break;
- case kpidSize:
- case kpidPackSize:
- prop = (UInt64)_archive.GetBootItemSize(index);
- break;
- }
- }
- else
- {
- const CRef &ref = _archive.Refs[index];
- const CDir &item = ref.Dir->_subItems[ref.Index];
- switch(propID)
- {
- case kpidPath:
- // if (item.FileId.GetCapacity() >= 0)
- {
- UString s;
- if (_archive.IsJoliet())
- s = item.GetPathU();
- else
- s = MultiByteToUnicodeString(item.GetPath(_archive.IsSusp, _archive.SuspSkipSize), CP_OEMCP);
-
- int pos = s.ReverseFind(L';');
- if (pos >= 0 && pos == s.Length() - 2)
- if (s[s.Length() - 1] == L'1')
- s = s.Left(pos);
- if (!s.IsEmpty())
- if (s[s.Length() - 1] == L'.')
- s = s.Left(s.Length() - 1);
- prop = (const wchar_t *)NItemName::GetOSName2(s);
- }
- break;
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize:
- case kpidPackSize:
- if (!item.IsDir())
- prop = (UInt64)item.DataLength;
- break;
- case kpidMTime:
- {
- FILETIME utc;
- if (item.DateTime.GetFileTime(utc))
- prop = utc;
- 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 = _archive.Refs.Size();
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
- UInt32 i;
- for(i = 0; i < numItems; i++)
- {
- UInt32 index = (allFilesMode ? i : indices[i]);
- if (index < (UInt32)_archive.Refs.Size())
- {
- const CRef &ref = _archive.Refs[index];
- const CDir &item = ref.Dir->_subItems[ref.Index];
- totalSize += item.DataLength;
- }
- else
- {
- totalSize += _archive.GetBootItemSize(index - _archive.Refs.Size());
- }
- }
- 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(_stream);
-
- CLimitedSequentialOutStream *outStreamSpec = new CLimitedSequentialOutStream;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
-
- for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
- {
- lps->InSize = lps->OutSize = currentTotalSize;
- RINOK(lps->SetCur());
- currentItemSize = 0;
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- UInt32 index = allFilesMode ? i : indices[i];
-
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- UInt64 blockIndex;
- if (index < (UInt32)_archive.Refs.Size())
- {
- const CRef &ref = _archive.Refs[index];
- const CDir &item = ref.Dir->_subItems[ref.Index];
- if (item.IsDir())
- {
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
- continue;
- }
- currentItemSize = item.DataLength;
- blockIndex = item.ExtentLocation;
- }
- else
- {
- int bootIndex = index - _archive.Refs.Size();
- const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
- currentItemSize = _archive.GetBootItemSize(bootIndex);
- blockIndex = be.LoadRBA;
- }
-
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- outStreamSpec->SetStream(realOutStream);
- realOutStream.Release();
- outStreamSpec->Init(currentItemSize);
- RINOK(_stream->Seek(blockIndex * _archive.BlockSize, STREAM_SEEK_SET, NULL));
- streamSpec->Init(currentItemSize);
- RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
- outStreamSpec->ReleaseStream();
- RINOK(extractCallback->SetOperationResult(outStreamSpec->IsFinishedOK() ?
- NExtract::NOperationResult::kOK:
- NExtract::NOperationResult::kDataError));
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- *stream = 0;
- UInt64 blockIndex;
- UInt64 currentItemSize;
- if (index < (UInt32)_archive.Refs.Size())
- {
- const CRef &ref = _archive.Refs[index];
- const CDir &item = ref.Dir->_subItems[ref.Index];
- if (item.IsDir())
- return S_FALSE;
- currentItemSize = item.DataLength;
- blockIndex = item.ExtentLocation;
- }
- else
- {
- int bootIndex = index - _archive.Refs.Size();
- const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
- currentItemSize = _archive.GetBootItemSize(bootIndex);
- blockIndex = be.LoadRBA;
- }
- return CreateLimitedInStream(_stream, blockIndex * _archive.BlockSize, currentItemSize, stream);
- COM_TRY_END
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.h
deleted file mode 100644
index 1dcade8f9..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHandler.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// IsoHandler.h
-
-#ifndef __ISO_HANDLER_H
-#define __ISO_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-
-#include "IsoIn.h"
-#include "IsoItem.h"
-
-namespace NArchive {
-namespace NIso {
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- CInArchive _archive;
-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/Iso/IsoHeader.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.cpp
deleted file mode 100644
index b3e418bbc..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// Archive/Iso/Header.h
-
-#include "StdAfx.h"
-
-#include "IsoHeader.h"
-
-namespace NArchive {
-namespace NIso {
-
-const char *kElToritoSpec = "EL TORITO SPECIFICATION\0\0\0\0\0\0\0\0\0";
-
-const wchar_t *kMediaTypes[5] =
-{
- L"NoEmulation",
- L"1.2M",
- L"1.44M",
- L"2.88M",
- L"HardDisk"
-};
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.h b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.h
deleted file mode 100644
index 9702d70ae..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoHeader.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Archive/IsoHeader.h
-
-#ifndef __ARCHIVE_ISO_HEADER_H
-#define __ARCHIVE_ISO_HEADER_H
-
-#include "Common/Types.h"
-
-namespace NArchive {
-namespace NIso {
-
-namespace NVolDescType
-{
- const Byte kBootRecord = 0;
- const Byte kPrimaryVol = 1;
- const Byte kSupplementaryVol = 2;
- const Byte kVolParttition = 3;
- const Byte kTerminator = 255;
-}
-
-const Byte kVersion = 1;
-
-namespace NFileFlags
-{
- const Byte kDirectory = 1 << 1;
-}
-
-extern const char *kElToritoSpec;
-
-const UInt32 kStartPos = 0x8000;
-
-namespace NBootEntryId
-{
- const Byte kValidationEntry = 1;
- const Byte kInitialEntryNotBootable = 0;
- const Byte kInitialEntryBootable = 0x88;
-}
-
-namespace NBootPlatformId
-{
- const Byte kX86 = 0;
- const Byte kPowerPC = 1;
- const Byte kMac = 2;
-}
-
-const BYTE kBootMediaTypeMask = 0xF;
-
-namespace NBootMediaType
-{
- const Byte kNoEmulation = 0;
- const Byte k1d2Floppy = 1;
- const Byte k1d44Floppy = 2;
- const Byte k2d88Floppy = 3;
- const Byte kHardDisk = 4;
-}
-
-const int kNumBootMediaTypes = 5;
-extern const wchar_t *kMediaTypes[];
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.cpp
deleted file mode 100644
index 7ed618d29..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.cpp
+++ /dev/null
@@ -1,453 +0,0 @@
-// Archive/IsoIn.cpp
-
-#include "StdAfx.h"
-
-#include "IsoIn.h"
-
-#include "../../Common/StreamUtils.h"
-
-namespace NArchive {
-namespace NIso {
-
-Byte CInArchive::ReadByte()
-{
- if (m_BufferPos >= BlockSize)
- m_BufferPos = 0;
- if (m_BufferPos == 0)
- {
- size_t processedSize = BlockSize;
- if (ReadStream(_stream, m_Buffer, &processedSize) != S_OK)
- throw 1;
- if (processedSize != BlockSize)
- throw 1;
- }
- Byte b = m_Buffer[m_BufferPos++];
- _position++;
- return b;
-}
-
-void CInArchive::ReadBytes(Byte *data, UInt32 size)
-{
- for (UInt32 i = 0; i < size; i++)
- data[i] = ReadByte();
-}
-
-void CInArchive::Skip(size_t size)
-{
- while (size-- != 0)
- ReadByte();
-}
-
-void CInArchive::SkipZeros(size_t size)
-{
- while (size-- != 0)
- {
- Byte b = ReadByte();
- if (b != 0)
- throw 1;
- }
-}
-
-UInt16 CInArchive::ReadUInt16Spec()
-{
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- value |= ((UInt16)(ReadByte()) << (8 * i));
- return value;
-}
-
-
-UInt16 CInArchive::ReadUInt16()
-{
- Byte b[4];
- ReadBytes(b, 4);
- UInt32 value = 0;
- for (int i = 0; i < 2; i++)
- {
- if (b[i] != b[3 - i])
- IncorrectBigEndian = true;
- value |= ((UInt16)(b[i]) << (8 * i));
- }
- return (UInt16)value;
-}
-
-UInt32 CInArchive::ReadUInt32Le()
-{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- value |= ((UInt32)(ReadByte()) << (8 * i));
- return value;
-}
-
-UInt32 CInArchive::ReadUInt32Be()
-{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- {
- value <<= 8;
- value |= ReadByte();
- }
- return value;
-}
-
-UInt32 CInArchive::ReadUInt32()
-{
- Byte b[8];
- ReadBytes(b, 8);
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- {
- if (b[i] != b[7 - i])
- throw 1;
- value |= ((UInt32)(b[i]) << (8 * i));
- }
- return value;
-}
-
-UInt32 CInArchive::ReadDigits(int numDigits)
-{
- UInt32 res = 0;
- for (int i = 0; i < numDigits; i++)
- {
- Byte b = ReadByte();
- if (b < '0' || b > '9')
- {
- if (b == 0) // it's bug in some CD's
- b = '0';
- else
- throw 1;
- }
- UInt32 d = (UInt32)(b - '0');
- res *= 10;
- res += d;
- }
- return res;
-}
-
-void CInArchive::ReadDateTime(CDateTime &d)
-{
- d.Year = (UInt16)ReadDigits(4);
- d.Month = (Byte)ReadDigits(2);
- d.Day = (Byte)ReadDigits(2);
- d.Hour = (Byte)ReadDigits(2);
- d.Minute = (Byte)ReadDigits(2);
- d.Second = (Byte)ReadDigits(2);
- d.Hundredths = (Byte)ReadDigits(2);
- d.GmtOffset = (signed char)ReadByte();
-}
-
-void CInArchive::ReadBootRecordDescriptor(CBootRecordDescriptor &d)
-{
- ReadBytes(d.BootSystemId, sizeof(d.BootSystemId));
- ReadBytes(d.BootId, sizeof(d.BootId));
- ReadBytes(d.BootSystemUse, sizeof(d.BootSystemUse));
-}
-
-void CInArchive::ReadRecordingDateTime(CRecordingDateTime &t)
-{
- t.Year = ReadByte();
- t.Month = ReadByte();
- t.Day = ReadByte();
- t.Hour = ReadByte();
- t.Minute = ReadByte();
- t.Second = ReadByte();
- t.GmtOffset = (signed char)ReadByte();
-}
-
-void CInArchive::ReadDirRecord2(CDirRecord &r, Byte len)
-{
- r.ExtendedAttributeRecordLen = ReadByte();
- if (r.ExtendedAttributeRecordLen != 0)
- throw 1;
- r.ExtentLocation = ReadUInt32();
- r.DataLength = ReadUInt32();
- ReadRecordingDateTime(r.DateTime);
- r.FileFlags = ReadByte();
- r.FileUnitSize = ReadByte();
- r.InterleaveGapSize = ReadByte();
- r.VolSequenceNumber = ReadUInt16();
- Byte idLen = ReadByte();
- r.FileId.SetCapacity(idLen);
- ReadBytes((Byte *)r.FileId, idLen);
- int padSize = 1 - (idLen & 1);
-
- // SkipZeros(1 - (idLen & 1));
- Skip(1 - (idLen & 1)); // it's bug in some cd's. Must be zeros
-
- int curPos = 33 + idLen + padSize;
- if (curPos > len)
- throw 1;
- int rem = len - curPos;
- r.SystemUse.SetCapacity(rem);
- ReadBytes((Byte *)r.SystemUse, rem);
-}
-
-void CInArchive::ReadDirRecord(CDirRecord &r)
-{
- Byte len = ReadByte();
- // Some CDs can have incorrect value len = 48 ('0') in VolumeDescriptor.
- // But maybe we must use real "len" for other records.
- len = 34;
- ReadDirRecord2(r, len);
-}
-
-void CInArchive::ReadVolumeDescriptor(CVolumeDescriptor &d)
-{
- d.VolFlags = ReadByte();
- ReadBytes(d.SystemId, sizeof(d.SystemId));
- ReadBytes(d.VolumeId, sizeof(d.VolumeId));
- SkipZeros(8);
- d.VolumeSpaceSize = ReadUInt32();
- ReadBytes(d.EscapeSequence, sizeof(d.EscapeSequence));
- d.VolumeSetSize = ReadUInt16();
- d.VolumeSequenceNumber = ReadUInt16();
- d.LogicalBlockSize = ReadUInt16();
- d.PathTableSize = ReadUInt32();
- d.LPathTableLocation = ReadUInt32Le();
- d.LOptionalPathTableLocation = ReadUInt32Le();
- d.MPathTableLocation = ReadUInt32Be();
- d.MOptionalPathTableLocation = ReadUInt32Be();
- ReadDirRecord(d.RootDirRecord);
- ReadBytes(d.VolumeSetId, sizeof(d.VolumeSetId));
- ReadBytes(d.PublisherId, sizeof(d.PublisherId));
- ReadBytes(d.DataPreparerId, sizeof(d.DataPreparerId));
- ReadBytes(d.ApplicationId, sizeof(d.ApplicationId));
- ReadBytes(d.CopyrightFileId, sizeof(d.CopyrightFileId));
- ReadBytes(d.AbstractFileId, sizeof(d.AbstractFileId));
- ReadBytes(d.BibFileId, sizeof(d.BibFileId));
- ReadDateTime(d.CTime);
- ReadDateTime(d.MTime);
- ReadDateTime(d.ExpirationTime);
- ReadDateTime(d.EffectiveTime);
- d.FileStructureVersion = ReadByte(); // = 1
- SkipZeros(1);
- ReadBytes(d.ApplicationUse, sizeof(d.ApplicationUse));
- SkipZeros(653);
-}
-
-static const Byte kSig_CD001[5] = { 'C', 'D', '0', '0', '1' };
-
-static const Byte kSig_NSR02[5] = { 'N', 'S', 'R', '0', '2' };
-static const Byte kSig_NSR03[5] = { 'N', 'S', 'R', '0', '3' };
-static const Byte kSig_BEA01[5] = { 'B', 'E', 'A', '0', '1' };
-static const Byte kSig_TEA01[5] = { 'T', 'E', 'A', '0', '1' };
-
-static inline bool CheckSignature(const Byte *sig, const Byte *data)
-{
- for (int i = 0; i < 5; i++)
- if (sig[i] != data[i])
- return false;
- return true;
-}
-
-void CInArchive::SeekToBlock(UInt32 blockIndex)
-{
- if (_stream->Seek((UInt64)blockIndex * VolDescs[MainVolDescIndex].LogicalBlockSize, STREAM_SEEK_SET, &_position) != S_OK)
- throw 1;
- m_BufferPos = 0;
-}
-
-void CInArchive::ReadDir(CDir &d, int level)
-{
- if (!d.IsDir())
- return;
- SeekToBlock(d.ExtentLocation);
- UInt64 startPos = _position;
-
- bool firstItem = true;
- for (;;)
- {
- UInt64 offset = _position - startPos;
- if (offset >= d.DataLength)
- break;
- Byte len = ReadByte();
- if (len == 0)
- continue;
- CDir subItem;
- ReadDirRecord2(subItem, len);
- if (firstItem && level == 0)
- IsSusp = subItem.CheckSusp(SuspSkipSize);
-
- if (!subItem.IsSystemItem())
- d._subItems.Add(subItem);
-
- firstItem = false;
- }
- for (int i = 0; i < d._subItems.Size(); i++)
- ReadDir(d._subItems[i], level + 1);
-}
-
-void CInArchive::CreateRefs(CDir &d)
-{
- if (!d.IsDir())
- return;
- for (int i = 0; i < d._subItems.Size(); i++)
- {
- CRef ref;
- CDir &subItem = d._subItems[i];
- subItem.Parent = &d;
- ref.Dir = &d;
- ref.Index = i;
- Refs.Add(ref);
- CreateRefs(subItem);
- }
-}
-
-void CInArchive::ReadBootInfo()
-{
- if (!_bootIsDefined)
- return;
- if (memcmp(_bootDesc.BootSystemId, kElToritoSpec, sizeof(_bootDesc.BootSystemId)) != 0)
- return;
-
- const Byte *p = (const Byte *)_bootDesc.BootSystemUse;
- UInt32 blockIndex = p[0] | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16) | ((UInt32)p[3] << 24);
- SeekToBlock(blockIndex);
- Byte b = ReadByte();
- if (b != NBootEntryId::kValidationEntry)
- return;
- {
- CBootValidationEntry e;
- e.PlatformId = ReadByte();
- if (ReadUInt16Spec() != 0)
- throw 1;
- ReadBytes(e.Id, sizeof(e.Id));
- /* UInt16 checkSum = */ ReadUInt16Spec();
- if (ReadByte() != 0x55)
- throw 1;
- if (ReadByte() != 0xAA)
- throw 1;
- }
- b = ReadByte();
- if (b == NBootEntryId::kInitialEntryBootable || b == NBootEntryId::kInitialEntryNotBootable)
- {
- CBootInitialEntry e;
- e.Bootable = (b == NBootEntryId::kInitialEntryBootable);
- e.BootMediaType = ReadByte();
- e.LoadSegment = ReadUInt16Spec();
- e.SystemType = ReadByte();
- if (ReadByte() != 0)
- throw 1;
- e.SectorCount = ReadUInt16Spec();
- e.LoadRBA = ReadUInt32Le();
- if (ReadByte() != 0)
- throw 1;
- BootEntries.Add(e);
- }
- else
- return;
-}
-
-HRESULT CInArchive::Open2()
-{
- Clear();
- RINOK(_stream->Seek(kStartPos, STREAM_SEEK_CUR, &_position));
-
- m_BufferPos = 0;
- BlockSize = kBlockSize;
- for (;;)
- {
- Byte sig[7];
- ReadBytes(sig, 7);
- Byte ver = sig[6];
- if (!CheckSignature(kSig_CD001, sig + 1))
- {
- return S_FALSE;
- /*
- if (sig[0] != 0 || ver != 1)
- break;
- if (CheckSignature(kSig_BEA01, sig + 1))
- {
- }
- else if (CheckSignature(kSig_TEA01, sig + 1))
- {
- break;
- }
- else if (CheckSignature(kSig_NSR02, sig + 1))
- {
- }
- else
- break;
- SkipZeros(0x800 - 7);
- continue;
- */
- }
- // version = 2 for ISO 9660:1999?
- if (ver > 2)
- throw S_FALSE;
-
- if (sig[0] == NVolDescType::kTerminator)
- {
- break;
- // Skip(0x800 - 7);
- // continue;
- }
- switch(sig[0])
- {
- case NVolDescType::kBootRecord:
- {
- _bootIsDefined = true;
- ReadBootRecordDescriptor(_bootDesc);
- break;
- }
- case NVolDescType::kPrimaryVol:
- case NVolDescType::kSupplementaryVol:
- {
- // some ISOs have two PrimaryVols.
- CVolumeDescriptor vd;
- ReadVolumeDescriptor(vd);
- if (sig[0] == NVolDescType::kPrimaryVol)
- {
- // some burners write "Joliet" Escape Sequence to primary volume
- memset(vd.EscapeSequence, 0, sizeof(vd.EscapeSequence));
- }
- VolDescs.Add(vd);
- break;
- }
- default:
- break;
- }
- }
- if (VolDescs.IsEmpty())
- return S_FALSE;
- for (MainVolDescIndex = VolDescs.Size() - 1; MainVolDescIndex > 0; MainVolDescIndex--)
- if (VolDescs[MainVolDescIndex].IsJoliet())
- break;
- // MainVolDescIndex = 0; // to read primary volume
- const CVolumeDescriptor &vd = VolDescs[MainVolDescIndex];
- if (vd.LogicalBlockSize != kBlockSize)
- return S_FALSE;
- (CDirRecord &)_rootDir = vd.RootDirRecord;
- ReadDir(_rootDir, 0);
- CreateRefs(_rootDir);
- ReadBootInfo();
- return S_OK;
-}
-
-HRESULT CInArchive::Open(IInStream *inStream)
-{
- _stream = inStream;
- UInt64 pos;
- RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &pos));
- RINOK(_stream->Seek(0, STREAM_SEEK_END, &_archiveSize));
- RINOK(_stream->Seek(pos, STREAM_SEEK_SET, &_position));
- HRESULT res = S_FALSE;
- try { res = Open2(); }
- catch(...) { Clear(); res = S_FALSE; }
- _stream.Release();
- return res;
-}
-
-void CInArchive::Clear()
-{
- IncorrectBigEndian = false;
- Refs.Clear();
- _rootDir.Clear();
- VolDescs.Clear();
- _bootIsDefined = false;
- BootEntries.Clear();
- SuspSkipSize = 0;
- IsSusp = false;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.h b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.h
deleted file mode 100644
index f9c6f6403..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoIn.h
+++ /dev/null
@@ -1,315 +0,0 @@
-// Archive/IsoIn.h
-
-#ifndef __ARCHIVE_ISO_IN_H
-#define __ARCHIVE_ISO_IN_H
-
-#include "Common/IntToString.h"
-#include "Common/MyCom.h"
-
-#include "../../IStream.h"
-
-#include "IsoHeader.h"
-#include "IsoItem.h"
-
-namespace NArchive {
-namespace NIso {
-
-struct CDir: public CDirRecord
-{
- CDir *Parent;
- CObjectVector<CDir> _subItems;
-
- void Clear()
- {
- Parent = 0;
- _subItems.Clear();
- }
-
- int GetLength(bool checkSusp, int skipSize) const
- {
- int len = GetLengthCur(checkSusp, skipSize);
- if (Parent != 0)
- if (Parent->Parent != 0)
- len += 1 + Parent->GetLength(checkSusp, skipSize);
- return len;
- }
-
- int GetLengthU() const
- {
- int len = (int)(FileId.GetCapacity() / 2);
- if (Parent != 0)
- if (Parent->Parent != 0)
- len += 1 + Parent->GetLengthU();
- return len;
- }
-
- AString GetPath(bool checkSusp, int skipSize) const
- {
- AString s;
- int len = GetLength(checkSusp, skipSize);
- char *p = s.GetBuffer(len + 1);
- p += len;
- *p = 0;
- const CDir *cur = this;
- for (;;)
- {
- int curLen = cur->GetLengthCur(checkSusp, skipSize);
- p -= curLen;
- memmove(p, (const char *)(const Byte *)cur->GetNameCur(checkSusp, skipSize), curLen);
- cur = cur->Parent;
- if (cur == 0)
- break;
- if (cur->Parent == 0)
- break;
- p--;
- *p = CHAR_PATH_SEPARATOR;
- }
- s.ReleaseBuffer();
- return s;
- }
-
- UString GetPathU() const
- {
- UString s;
- int len = GetLengthU();
- wchar_t *p = s.GetBuffer(len + 1);
- p += len;
- *p = 0;
- const CDir *cur = this;
- for (;;)
- {
- int curLen = (int)(cur->FileId.GetCapacity() / 2);
- p -= curLen;
- for (int i = 0; i < curLen; i++)
- {
- Byte b0 = ((const Byte *)cur->FileId)[i * 2];
- Byte b1 = ((const Byte *)cur->FileId)[i * 2 + 1];
- p[i] = (wchar_t)(((wchar_t)b0 << 8) | b1);
- }
- cur = cur->Parent;
- if (cur == 0)
- break;
- if (cur->Parent == 0)
- break;
- p--;
- *p = WCHAR_PATH_SEPARATOR;
- }
- s.ReleaseBuffer();
- return s;
- }
-};
-
-struct CDateTime
-{
- UInt16 Year;
- Byte Month;
- Byte Day;
- Byte Hour;
- Byte Minute;
- Byte Second;
- Byte Hundredths;
- signed char GmtOffset; // min intervals from -48 (West) to +52 (East) recorded.
- bool NotSpecified() const { return Year == 0 && Month == 0 && Day == 0 &&
- Hour == 0 && Minute == 0 && Second == 0 && GmtOffset == 0; }
-
- bool GetFileTime(FILETIME &ft) const
- {
- UInt64 value;
- bool res = NWindows::NTime::GetSecondsSince1601(Year, Month, Day, Hour, Minute, Second, value);
- if (res)
- {
- value -= (UInt64)((Int64)GmtOffset * 15 * 60);
- value *= 10000000;
- }
- ft.dwLowDateTime = (DWORD)value;
- ft.dwHighDateTime = (DWORD)(value >> 32);
- return res;
- }
-};
-
-struct CBootRecordDescriptor
-{
- Byte BootSystemId[32]; // a-characters
- Byte BootId[32]; // a-characters
- Byte BootSystemUse[1977];
-};
-
-struct CBootValidationEntry
-{
- Byte PlatformId;
- Byte Id[24]; // to identify the manufacturer/developer of the CD-ROM.
-};
-
-struct CBootInitialEntry
-{
- bool Bootable;
- Byte BootMediaType;
- UInt16 LoadSegment;
- /* This is the load segment for the initial boot image. If this
- value is 0 the system will use the traditional segment of 7C0. If this value
- is non-zero the system will use the specified segment. This applies to x86
- architectures only. For "flat" model architectures (such as Motorola) this
- is the address divided by 10. */
- Byte SystemType; // This must be a copy of byte 5 (System Type) from the
- // Partition Table found in the boot image.
- UInt16 SectorCount; // This is the number of virtual/emulated sectors the system
- // will store at Load Segment during the initial boot procedure.
- UInt32 LoadRBA; // This is the start address of the virtual disk. CD’s use
- // Relative/Logical block addressing.
-
- UInt64 GetSize() const
- {
- // if (BootMediaType == NBootMediaType::k1d44Floppy) (1440 << 10);
- return SectorCount * 512;
- }
-
- UString GetName() const
- {
- UString s;
- if (Bootable)
- s += L"Bootable";
- else
- s += L"NotBootable";
- s += L"_";
- if (BootMediaType >= kNumBootMediaTypes)
- {
- wchar_t name[16];
- ConvertUInt32ToString(BootMediaType, name);
- s += name;
- }
- else
- s += kMediaTypes[BootMediaType];
- s += L".img";
- return s;
- }
-};
-
-struct CVolumeDescriptor
-{
- Byte VolFlags;
- Byte SystemId[32]; // a-characters. An identification of a system
- // which can recognize and act upon the content of the Logical
- // Sectors with logical Sector Numbers 0 to 15 of the volume.
- Byte VolumeId[32]; // d-characters. An identification of the volume.
- UInt32 VolumeSpaceSize; // the number of Logical Blocks in which the Volume Space of the volume is recorded
- Byte EscapeSequence[32];
- UInt16 VolumeSetSize;
- UInt16 VolumeSequenceNumber; // the ordinal number of the volume in the Volume Set of which the volume is a member.
- UInt16 LogicalBlockSize;
- UInt32 PathTableSize;
- UInt32 LPathTableLocation;
- UInt32 LOptionalPathTableLocation;
- UInt32 MPathTableLocation;
- UInt32 MOptionalPathTableLocation;
- CDirRecord RootDirRecord;
- Byte VolumeSetId[128];
- Byte PublisherId[128];
- Byte DataPreparerId[128];
- Byte ApplicationId[128];
- Byte CopyrightFileId[37];
- Byte AbstractFileId[37];
- Byte BibFileId[37];
- CDateTime CTime;
- CDateTime MTime;
- CDateTime ExpirationTime;
- CDateTime EffectiveTime;
- Byte FileStructureVersion; // = 1;
- Byte ApplicationUse[512];
-
- bool IsJoliet() const
- {
- if ((VolFlags & 1) != 0)
- return false;
- Byte b = EscapeSequence[2];
- return (EscapeSequence[0] == 0x25 && EscapeSequence[1] == 0x2F &&
- (b == 0x40 || b == 0x43 || b == 0x45));
- }
-};
-
-struct CRef
-{
- CDir *Dir;
- UInt32 Index;
-};
-
-const UInt32 kBlockSize = 1 << 11;
-
-class CInArchive
-{
- CMyComPtr<IInStream> _stream;
- UInt64 _position;
-
- Byte m_Buffer[kBlockSize];
- UInt32 m_BufferPos;
-
- CDir _rootDir;
- bool _bootIsDefined;
- CBootRecordDescriptor _bootDesc;
-
- void Skip(size_t size);
- void SkipZeros(size_t size);
- Byte ReadByte();
- void ReadBytes(Byte *data, UInt32 size);
- UInt16 ReadUInt16Spec();
- UInt16 ReadUInt16();
- UInt32 ReadUInt32Le();
- UInt32 ReadUInt32Be();
- UInt32 ReadUInt32();
- UInt64 ReadUInt64();
- UInt32 ReadDigits(int numDigits);
- void ReadDateTime(CDateTime &d);
- void ReadRecordingDateTime(CRecordingDateTime &t);
- void ReadDirRecord2(CDirRecord &r, Byte len);
- void ReadDirRecord(CDirRecord &r);
-
- void ReadBootRecordDescriptor(CBootRecordDescriptor &d);
- void ReadVolumeDescriptor(CVolumeDescriptor &d);
-
- void SeekToBlock(UInt32 blockIndex);
- void ReadDir(CDir &d, int level);
- void CreateRefs(CDir &d);
-
- void ReadBootInfo();
- HRESULT Open2();
-public:
- HRESULT Open(IInStream *inStream);
- void Clear();
-
- UInt64 _archiveSize;
-
- CRecordVector<CRef> Refs;
- CObjectVector<CVolumeDescriptor> VolDescs;
- int MainVolDescIndex;
- UInt32 BlockSize;
- CObjectVector<CBootInitialEntry> BootEntries;
- bool IncorrectBigEndian;
-
-
- bool IsJoliet() const { return VolDescs[MainVolDescIndex].IsJoliet(); }
-
- UInt64 GetBootItemSize(int index) const
- {
- const CBootInitialEntry &be = BootEntries[index];
- UInt64 size = be.GetSize();
- if (be.BootMediaType == NBootMediaType::k1d2Floppy)
- size = (1200 << 10);
- else if (be.BootMediaType == NBootMediaType::k1d44Floppy)
- size = (1440 << 10);
- else if (be.BootMediaType == NBootMediaType::k2d88Floppy)
- size = (2880 << 10);
- UInt64 startPos = be.LoadRBA * BlockSize;
- if (startPos < _archiveSize)
- {
- if (_archiveSize - startPos < size)
- size = _archiveSize - startPos;
- }
- return size;
- }
-
- bool IsSusp;
- int SuspSkipSize;
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoItem.h b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoItem.h
deleted file mode 100644
index f39c2f5d2..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoItem.h
+++ /dev/null
@@ -1,141 +0,0 @@
-// Archive/IsoItem.h
-
-#ifndef __ARCHIVE_ISO_ITEM_H
-#define __ARCHIVE_ISO_ITEM_H
-
-#include "Common/Types.h"
-#include "Common/MyString.h"
-#include "Common/Buffer.h"
-
-#include "Windows/Time.h"
-
-#include "IsoHeader.h"
-
-namespace NArchive {
-namespace NIso {
-
-struct CRecordingDateTime
-{
- Byte Year;
- Byte Month;
- Byte Day;
- Byte Hour;
- Byte Minute;
- Byte Second;
- signed char GmtOffset; // min intervals from -48 (West) to +52 (East) recorded.
-
- bool GetFileTime(FILETIME &ft) const
- {
- UInt64 value;
- bool res = NWindows::NTime::GetSecondsSince1601(Year + 1900, Month, Day, Hour, Minute, Second, value);
- if (res)
- {
- value -= (UInt64)((Int64)GmtOffset * 15 * 60);
- value *= 10000000;
- }
- ft.dwLowDateTime = (DWORD)value;
- ft.dwHighDateTime = (DWORD)(value >> 32);
- return res;
- }
-};
-
-struct CDirRecord
-{
- Byte ExtendedAttributeRecordLen;
- UInt32 ExtentLocation;
- UInt32 DataLength;
- CRecordingDateTime DateTime;
- Byte FileFlags;
- Byte FileUnitSize;
- Byte InterleaveGapSize;
- UInt16 VolSequenceNumber;
- CByteBuffer FileId;
- CByteBuffer SystemUse;
-
- bool IsDir() const { return (FileFlags & NFileFlags::kDirectory) != 0; }
- bool IsSystemItem() const
- {
- if (FileId.GetCapacity() != 1)
- return false;
- Byte b = *(const Byte *)FileId;
- return (b == 0 || b == 1);
- }
-
- const Byte* FindSuspName(int skipSize, int &lenRes) const
- {
- lenRes = 0;
- const Byte *p = (const Byte *)SystemUse + skipSize;
- int length = (int)(SystemUse.GetCapacity() - skipSize);
- while (length >= 5)
- {
- int len = p[2];
- if (p[0] == 'N' && p[1] == 'M' && p[3] == 1)
- {
- lenRes = len - 5;
- return p + 5;
- }
- p += len;
- length -= len;
- }
- return 0;
- }
-
- int GetLengthCur(bool checkSusp, int skipSize) const
- {
- if (checkSusp)
- {
- int len;
- const Byte *res = FindSuspName(skipSize, len);
- if (res != 0)
- return len;
- }
- return (int)FileId.GetCapacity();
- }
-
- const Byte* GetNameCur(bool checkSusp, int skipSize) const
- {
- if (checkSusp)
- {
- int len;
- const Byte *res = FindSuspName(skipSize, len);
- if (res != 0)
- return res;
- }
- return (const Byte *)FileId;
- }
-
-
- bool CheckSusp(const Byte *p, int &startPos) const
- {
- if (p[0] == 'S' &&
- p[1] == 'P' &&
- p[2] == 0x7 &&
- p[3] == 0x1 &&
- p[4] == 0xBE &&
- p[5] == 0xEF)
- {
- startPos = p[6];
- return true;
- }
- return false;
- }
-
- bool CheckSusp(int &startPos) const
- {
- const Byte *p = (const Byte *)SystemUse;
- int length = (int)SystemUse.GetCapacity();
- const int kMinLen = 7;
- if (length < kMinLen)
- return false;
- if (CheckSusp(p, startPos))
- return true;
- const int kOffset2 = 14;
- if (length < kOffset2 + kMinLen)
- return false;
- return CheckSusp(p + kOffset2, startPos);
- }
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoRegister.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoRegister.cpp
deleted file mode 100644
index 67a09c769..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/IsoRegister.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// IsoRegister.cpp
-
-#include "StdAfx.h"
-
-#include "../../Common/RegisterArc.h"
-
-#include "IsoHandler.h"
-static IInArchive *CreateArc() { return new NArchive::NIso::CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Iso", L"iso img", 0, 0xE7, { 'C', 'D', '0', '0', '1', 0x1 }, 7, false, CreateArc, 0 };
-
-REGISTER_ARC(Iso)
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Iso/StdAfx.h b/src/libs/7zip/win/CPP/7zip/Archive/Iso/StdAfx.h
deleted file mode 100644
index 2e4be10b2..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Iso/StdAfx.h
+++ /dev/null
@@ -1,9 +0,0 @@
-// StdAfx.h
-
-#ifndef __STDAFX_H
-#define __STDAFX_H
-
-#include "../../../Common/MyWindows.h"
-#include "../../../Common/NewHandler.h"
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/LzhHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/LzhHandler.cpp
deleted file mode 100644
index 95efc5013..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/LzhHandler.cpp
+++ /dev/null
@@ -1,775 +0,0 @@
-// LzhHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.h"
-#include "Common/StringConvert.h"
-
-#include "Windows/PropVariant.h"
-#include "Windows/Time.h"
-
-#include "../ICoder.h"
-
-#include "../Common/LimitedStreams.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "../Compress/CopyCoder.h"
-#include "../Compress/LzhDecoder.h"
-
-#include "IArchive.h"
-
-#include "Common/ItemNameUtils.h"
-
-using namespace NWindows;
-using namespace NTime;
-
-#define Get16(p) GetUi16(p)
-#define Get32(p) GetUi32(p)
-
-namespace NArchive {
-namespace NLzh{
-
-const int kMethodIdSize = 5;
-
-const Byte kExtIdFileName = 0x01;
-const Byte kExtIdDirName = 0x02;
-const Byte kExtIdUnixTime = 0x54;
-
-struct CExtension
-{
- Byte Type;
- CByteBuffer Data;
- AString GetString() const
- {
- AString s;
- for (size_t i = 0; i < Data.GetCapacity(); i++)
- {
- char c = (char)Data[i];
- if (c == 0)
- break;
- s += c;
- }
- return s;
- }
-};
-
-struct CItem
-{
- AString Name;
- Byte Method[kMethodIdSize];
- Byte Attributes;
- Byte Level;
- Byte OsId;
- UInt32 PackSize;
- UInt32 Size;
- UInt32 ModifiedTime;
- UInt16 CRC;
- CObjectVector<CExtension> Extensions;
-
- bool IsValidMethod() const { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); }
- bool IsLhMethod() const {return (IsValidMethod() && Method[2] == 'h'); }
- bool IsDir() const {return (IsLhMethod() && Method[3] == 'd'); }
-
- bool IsCopyMethod() const
- {
- return (IsLhMethod() && Method[3] == '0') ||
- (IsValidMethod() && Method[2] == 'z' && Method[3] == '4');
- }
-
- bool IsLh1GroupMethod() const
- {
- if (!IsLhMethod())
- return false;
- switch(Method[3])
- {
- case '1':
- return true;
- }
- return false;
- }
-
- bool IsLh4GroupMethod() const
- {
- if (!IsLhMethod())
- return false;
- switch(Method[3])
- {
- case '4':
- case '5':
- case '6':
- case '7':
- return true;
- }
- return false;
- }
-
- int GetNumDictBits() const
- {
- if (!IsLhMethod())
- return 0;
- switch(Method[3])
- {
- case '1': return 12;
- case '2': return 13;
- case '3': return 13;
- case '4': return 12;
- case '5': return 13;
- case '6': return 15;
- case '7': return 16;
- }
- return 0;
- }
-
- int FindExt(Byte type) const
- {
- for (int i = 0; i < Extensions.Size(); i++)
- if (Extensions[i].Type == type)
- return i;
- return -1;
- }
- bool GetUnixTime(UInt32 &value) const
- {
- int index = FindExt(kExtIdUnixTime);
- if (index < 0)
- {
- if (Level == 2)
- {
- value = ModifiedTime;
- return true;
- }
- return false;
- }
- const Byte *data = (const Byte *)(Extensions[index].Data);
- value = GetUi32(data);
- return true;
- }
-
- AString GetDirName() const
- {
- int index = FindExt(kExtIdDirName);
- if (index < 0)
- return AString();
- return Extensions[index].GetString();
- }
-
- AString GetFileName() const
- {
- int index = FindExt(kExtIdFileName);
- if (index < 0)
- return Name;
- return Extensions[index].GetString();
- }
-
- AString GetName() const
- {
- AString dirName = GetDirName();
- const char kDirSeparator = '\\';
- // check kDirSeparator in Linux
- dirName.Replace((char)(unsigned char)0xFF, kDirSeparator);
- if (!dirName.IsEmpty() && dirName.Back() != kDirSeparator)
- dirName += kDirSeparator;
- return dirName + GetFileName();
- }
-};
-
-struct CItemEx: public CItem
-{
- UInt64 DataPosition;
-};
-
-class CInArchive
-{
- CMyComPtr<IInStream> m_Stream;
- UInt64 m_Position;
-
- HRESULT ReadBytes(void *data, UInt32 size, UInt32 &processedSize);
- HRESULT CheckReadBytes(void *data, UInt32 size);
-public:
- HRESULT Open(IInStream *inStream);
- HRESULT GetNextItem(bool &filled, CItemEx &itemInfo);
- HRESULT Skip(UInt64 numBytes);
-};
-
-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;
-}
-
-HRESULT CInArchive::CheckReadBytes(void *data, UInt32 size)
-{
- UInt32 processedSize;
- RINOK(ReadBytes(data, size, processedSize));
- return (processedSize == size) ? S_OK: S_FALSE;
-}
-
-HRESULT CInArchive::Open(IInStream *inStream)
-{
- RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &m_Position));
- m_Stream = inStream;
- return S_OK;
-}
-
-static const Byte *ReadUInt16(const Byte *p, UInt16 &v)
-{
- v = Get16(p);
- return p + 2;
-}
-
-static const Byte *ReadString(const Byte *p, size_t size, AString &s)
-{
- s.Empty();
- for (size_t i = 0; i < size; i++)
- {
- char c = p[i];
- if (c == 0)
- break;
- s += c;
- }
- return p + size;
-}
-
-static Byte CalcSum(const Byte *data, size_t size)
-{
- Byte sum = 0;
- for (size_t i = 0; i < size; i++)
- sum = (Byte)(sum + data[i]);
- return sum;
-}
-
-HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
-{
- filled = false;
-
- UInt32 processedSize;
- Byte startHeader[2];
- RINOK(ReadBytes(startHeader, 2, processedSize))
- if (processedSize == 0)
- return S_OK;
- if (processedSize == 1)
- return (startHeader[0] == 0) ? S_OK: S_FALSE;
- if (startHeader[0] == 0 && startHeader[1] == 0)
- return S_OK;
-
- Byte header[256];
- const UInt32 kBasicPartSize = 22;
- RINOK(ReadBytes(header, kBasicPartSize, processedSize));
- if (processedSize != kBasicPartSize)
- return (startHeader[0] == 0) ? S_OK: S_FALSE;
-
- const Byte *p = header;
- memcpy(item.Method, p, kMethodIdSize);
- if (!item.IsValidMethod())
- return S_OK;
- p += kMethodIdSize;
- item.PackSize = Get32(p);
- item.Size = Get32(p + 4);
- item.ModifiedTime = Get32(p + 8);
- item.Attributes = p[12];
- item.Level = p[13];
- p += 14;
- if (item.Level > 2)
- return S_FALSE;
- UInt32 headerSize;
- if (item.Level < 2)
- {
- headerSize = startHeader[0];
- if (headerSize < kBasicPartSize)
- return S_FALSE;
- UInt32 remain = headerSize - kBasicPartSize;
- RINOK(CheckReadBytes(header + kBasicPartSize, remain));
- if (startHeader[1] != CalcSum(header, headerSize))
- return S_FALSE;
- size_t nameLength = *p++;
- if ((p - header) + nameLength + 2 > headerSize)
- return S_FALSE;
- p = ReadString(p, nameLength, item.Name);
- }
- else
- headerSize = startHeader[0] | ((UInt32)startHeader[1] << 8);
- p = ReadUInt16(p, item.CRC);
- if (item.Level != 0)
- {
- if (item.Level == 2)
- {
- RINOK(CheckReadBytes(header + kBasicPartSize, 2));
- }
- if ((size_t)(p - header) + 3 > headerSize)
- return S_FALSE;
- item.OsId = *p++;
- UInt16 nextSize;
- p = ReadUInt16(p, nextSize);
- while (nextSize != 0)
- {
- if (nextSize < 3)
- return S_FALSE;
- if (item.Level == 1)
- {
- if (item.PackSize < nextSize)
- return S_FALSE;
- item.PackSize -= nextSize;
- }
- CExtension ext;
- RINOK(CheckReadBytes(&ext.Type, 1))
- nextSize -= 3;
- ext.Data.SetCapacity(nextSize);
- RINOK(CheckReadBytes((Byte *)ext.Data, nextSize))
- item.Extensions.Add(ext);
- Byte hdr2[2];
- RINOK(CheckReadBytes(hdr2, 2));
- ReadUInt16(hdr2, nextSize);
- }
- }
- item.DataPosition = m_Position;
- 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;
-}
-
-struct COsPair
-{
- Byte Id;
- const char *Name;
-};
-
-static COsPair g_OsPairs[] =
-{
- { 0, "MS-DOS" },
- { 'M', "MS-DOS" },
- { '2', "OS/2" },
- { '9', "OS9" },
- { 'K', "OS/68K" },
- { '3', "OS/386" },
- { 'H', "HUMAN" },
- { 'U', "UNIX" },
- { 'C', "CP/M" },
- { 'F', "FLEX" },
- { 'm', "Mac" },
- { 'R', "Runser" },
- { 'T', "TownsOS" },
- { 'X', "XOSK" },
- { 'w', "Windows 95" },
- { 'W', "Windows NT" },
- { 'J', "Java VM" }
-};
-
-static const char *kUnknownOS = "Unknown";
-
-static const char *GetOS(Byte osId)
-{
- for (int i = 0; i < sizeof(g_OsPairs) / sizeof(g_OsPairs[0]); i++)
- if (g_OsPairs[i].Id == osId)
- return g_OsPairs[i].Name;
- return kUnknownOS;
-}
-
-static STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidIsDir, VT_BOOL},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- // { NULL, kpidAttrib, VT_UI4},
- { NULL, kpidCRC, VT_UI4},
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidHostOS, VT_BSTR}
-};
-
-class CCRC
-{
- UInt16 _value;
-public:
- static UInt16 Table[256];
- static void InitTable();
-
- CCRC(): _value(0) {}
- void Init() { _value = 0; }
- void Update(const void *data, size_t size);
- UInt16 GetDigest() const { return _value; }
-};
-
-static const UInt16 kCRCPoly = 0xA001;
-
-UInt16 CCRC::Table[256];
-
-void CCRC::InitTable()
-{
- for (UInt32 i = 0; i < 256; i++)
- {
- UInt32 r = i;
- for (int j = 0; j < 8; j++)
- if (r & 1)
- r = (r >> 1) ^ kCRCPoly;
- else
- r >>= 1;
- CCRC::Table[i] = (UInt16)r;
- }
-}
-
-class CCRCTableInit
-{
-public:
- CCRCTableInit() { CCRC::InitTable(); }
-} g_CRCTableInit;
-
-void CCRC::Update(const void *data, size_t size)
-{
- UInt16 v = _value;
- const Byte *p = (const Byte *)data;
- for (; size > 0; size--, p++)
- v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8));
- _value = v;
-}
-
-
-class COutStreamWithCRC:
- public ISequentialOutStream,
- public CMyUnknownImp
-{
-public:
- MY_UNKNOWN_IMP
-
- STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
-private:
- CCRC _crc;
- CMyComPtr<ISequentialOutStream> _stream;
-public:
- void Init(ISequentialOutStream *stream)
- {
- _stream = stream;
- _crc.Init();
- }
- void ReleaseStream() { _stream.Release(); }
- UInt32 GetCRC() const { return _crc.GetDigest(); }
- void InitCRC() { _crc.Init(); }
-};
-
-STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize)
-{
- UInt32 realProcessedSize;
- HRESULT result;
- if (!_stream)
- {
- realProcessedSize = size;
- result = S_OK;
- }
- else
- result = _stream->Write(data, size, &realProcessedSize);
- _crc.Update(data, realProcessedSize);
- if (processedSize != NULL)
- *processedSize = realProcessedSize;
- return result;
-}
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
- CObjectVector<CItemEx> _items;
- CMyComPtr<IInStream> _stream;
-public:
- MY_UNKNOWN_IMP1(IInArchive)
- INTERFACE_IInArchive(;)
- CHandler();
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-CHandler::CHandler() {}
-
-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:
- {
- UString s = NItemName::WinNameToOSName(MultiByteToUnicodeString(item.GetName(), CP_OEMCP));
- if (!s.IsEmpty())
- {
- if (s[s.Length() - 1] == WCHAR_PATH_SEPARATOR)
- s.Delete(s.Length() - 1);
- prop = s;
- }
- break;
- }
- case kpidIsDir: prop = item.IsDir(); break;
- case kpidSize: prop = item.Size; break;
- case kpidPackSize: prop = item.PackSize; break;
- case kpidCRC: prop = (UInt32)item.CRC; break;
- case kpidHostOS: prop = GetOS(item.OsId); break;
- case kpidMTime:
- {
- FILETIME utc;
- UInt32 unixTime;
- if (item.GetUnixTime(unixTime))
- NTime::UnixTimeToFileTime(unixTime, utc);
- else
- {
- FILETIME localFileTime;
- if (DosTimeToFileTime(item.ModifiedTime, localFileTime))
- {
- if (!LocalFileTimeToFileTime(&localFileTime, &utc))
- utc.dwHighDateTime = utc.dwLowDateTime = 0;
- }
- else
- utc.dwHighDateTime = utc.dwLowDateTime = 0;
- }
- prop = utc;
- break;
- }
- // case kpidAttrib: prop = (UInt32)item.Attributes; break;
- case kpidMethod:
- {
- char method2[kMethodIdSize + 1];
- method2[kMethodIdSize] = 0;
- memcpy(method2, item.Method, kMethodIdSize);
- prop = method2;
- break;
- }
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- try
- {
- _items.Clear();
- 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));
- 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.Skip(item.PackSize);
- if (callback != NULL)
- {
- if (needSetTotal)
- {
- RINOK(callback->SetTotal(NULL, &endPos));
- needSetTotal = false;
- }
- if (_items.Size() % 100 == 0)
- {
- UInt64 numFiles = _items.Size();
- UInt64 numBytes = item.DataPosition;
- RINOK(callback->SetCompleted(&numFiles, &numBytes));
- }
- }
- }
- if (_items.IsEmpty())
- return S_FALSE;
-
- _stream = stream;
- }
- catch(...)
- {
- return S_FALSE;
- }
- COM_TRY_END
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _items.Clear();
- _stream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
- Int32 testModeSpec, IArchiveExtractCallback *extractCallback)
-{
- COM_TRY_BEGIN
- bool testMode = (testModeSpec != 0);
- 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 CItemEx &item = _items[allFilesMode ? i : indices[i]];
- totalUnPacked += item.Size;
- totalPacked += item.PackSize;
- }
- RINOK(extractCallback->SetTotal(totalUnPacked));
-
- UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0;
- UInt64 currentItemUnPacked, currentItemPacked;
-
- NCompress::NLzh::NDecoder::CCoder *lzhDecoderSpec = 0;
- CMyComPtr<ICompressCoder> lzhDecoder;
- CMyComPtr<ICompressCoder> lzh1Decoder;
- 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 *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
- streamSpec->SetStream(_stream);
-
- for (i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked,
- currentTotalPacked += currentItemPacked)
- {
- currentItemUnPacked = 0;
- currentItemPacked = 0;
-
- lps->InSize = currentTotalPacked;
- lps->OutSize = currentTotalUnPacked;
- RINOK(lps->SetCur());
-
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode;
- askMode = testMode ? NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- Int32 index = allFilesMode ? i : indices[i];
- const CItemEx &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));
- currentItemUnPacked = item.Size;
- currentItemPacked = item.PackSize;
-
- {
- COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;
- CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
- outStreamSpec->Init(realOutStream);
- realOutStream.Release();
-
- UInt64 pos;
- _stream->Seek(item.DataPosition, STREAM_SEEK_SET, &pos);
-
- streamSpec->Init(item.PackSize);
-
- HRESULT result = S_OK;
- Int32 opRes = NExtract::NOperationResult::kOK;
-
- if (item.IsCopyMethod())
- {
- result = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
- if (result == S_OK && copyCoderSpec->TotalSize != item.PackSize)
- result = S_FALSE;
- }
- else if (item.IsLh4GroupMethod())
- {
- if (!lzhDecoder)
- {
- lzhDecoderSpec = new NCompress::NLzh::NDecoder::CCoder;
- lzhDecoder = lzhDecoderSpec;
- }
- lzhDecoderSpec->SetDictionary(item.GetNumDictBits());
- result = lzhDecoder->Code(inStream, outStream, NULL, &currentItemUnPacked, progress);
- }
- /*
- else if (item.IsLh1GroupMethod())
- {
- if (!lzh1Decoder)
- {
- lzh1DecoderSpec = new NCompress::NLzh1::NDecoder::CCoder;
- lzh1Decoder = lzh1DecoderSpec;
- }
- lzh1DecoderSpec->SetDictionary(item.GetNumDictBits());
- result = lzh1Decoder->Code(inStream, outStream, NULL, &currentItemUnPacked, progress);
- }
- */
- else
- opRes = NExtract::NOperationResult::kUnSupportedMethod;
-
- if (opRes == NExtract::NOperationResult::kOK)
- {
- if (result == S_FALSE)
- opRes = NExtract::NOperationResult::kDataError;
- else
- {
- RINOK(result);
- if (outStreamSpec->GetCRC() != item.CRC)
- opRes = 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"Lzh", L"lzh lha", 0, 6, { '-', 'l' }, 2, false, CreateArc, 0 };
-
-REGISTER_ARC(Lzh)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/MachoHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/MachoHandler.cpp
deleted file mode 100644
index a6261f34d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/MachoHandler.cpp
+++ /dev/null
@@ -1,500 +0,0 @@
-// MachoHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.h"
-#include "Common/ComTry.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 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 NMacho {
-
-#define MACH_ARCH_ABI64 (1 << 24)
-#define MACH_MACHINE_386 7
-#define MACH_MACHINE_ARM 12
-#define MACH_MACHINE_SPARC 14
-#define MACH_MACHINE_PPC 18
-
-#define MACH_MACHINE_PPC64 (MACH_ARCH_ABI64 | MACH_MACHINE_PPC)
-#define MACH_MACHINE_AMD64 (MACH_ARCH_ABI64 | MACH_MACHINE_386)
-
-#define MACH_CMD_SEGMENT_32 1
-#define MACH_CMD_SEGMENT_64 0x19
-
-#define MACH_SECT_TYPE_MASK 0x000000FF
-#define MACH_SECT_ATTR_MASK 0xFFFFFF00
-
-#define MACH_SECT_ATTR_ZEROFILL 1
-
-static const char *g_SectTypes[] =
-{
- "REGULAR",
- "ZEROFILL",
- "CSTRINGS",
- "4BYTE_LITERALS",
- "8BYTE_LITERALS",
- "LITERAL_POINTERS",
- "NON_LAZY_SYMBOL_POINTERS",
- "LAZY_SYMBOL_POINTERS",
- "SYMBOL_STUBS",
- "MOD_INIT_FUNC_POINTERS",
- "MOD_TERM_FUNC_POINTERS",
- "COALESCED",
- "GB_ZEROFILL",
- "INTERPOSING",
- "16BYTE_LITERALS"
-};
-
-static const char *g_FileTypes[] =
-{
- "0",
- "OBJECT",
- "EXECUTE",
- "FVMLIB",
- "CORE",
- "PRELOAD",
- "DYLIB",
- "DYLINKER",
- "BUNDLE",
- "DYLIB_STUB",
- "DSYM"
-};
-
-static const CUInt32PCharPair g_Flags[] =
-{
- { 31, "PURE_INSTRUCTIONS" },
- { 30, "NO_TOC" },
- { 29, "STRIP_STATIC_SYMS" },
- { 28, "NO_DEAD_STRIP" },
- { 27, "LIVE_SUPPORT" },
- { 26, "SELF_MODIFYING_CODE" },
- { 25, "DEBUG" },
- { 10, "SOME_INSTRUCTIONS" },
- { 9, "EXT_RELOC" },
- { 8, "LOC_RELOC" }
-};
-
-static const CUInt32PCharPair g_MachinePairs[] =
-{
- { MACH_MACHINE_386, "x86" },
- { MACH_MACHINE_ARM, "ARM" },
- { MACH_MACHINE_SPARC, "SPARC" },
- { MACH_MACHINE_PPC, "PowerPC" },
- { MACH_MACHINE_PPC64, "PowerPC 64-bit" },
- { MACH_MACHINE_AMD64, "x64" }
-};
-
-static const int kNameSize = 16;
-
-struct CSegment
-{
- char Name[kNameSize];
-};
-
-struct CSection
-{
- char Name[kNameSize];
- char SegName[kNameSize];
- UInt64 Va;
- UInt64 Pa;
- UInt64 VSize;
- UInt64 PSize;
-
- UInt32 Flags;
- int SegmentIndex;
-
- bool IsDummy;
-
- CSection(): IsDummy(false) {}
- // UInt64 GetPackSize() const { return Flags == MACH_SECT_ATTR_ZEROFILL ? 0 : Size; }
- UInt64 GetPackSize() const { return PSize; }
-};
-
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _inStream;
- CObjectVector<CSegment> _segments;
- CObjectVector<CSection> _sections;
- bool _mode64;
- bool _be;
- UInt32 _machine;
- UInt32 _type;
- UInt32 _headersSize;
- UInt64 _totalSize;
- HRESULT Open2(ISequentialInStream *stream);
- bool Parse(const Byte *buf, UInt32 size);
-public:
- MY_UNKNOWN_IMP1(IInArchive)
- INTERFACE_IInArchive(;)
-};
-
-bool CHandler::Parse(const Byte *buf, UInt32 size)
-{
- bool mode64 = _mode64;
- bool be = _be;
-
- const Byte *bufStart = buf;
- bool reduceCommands = false;
- if (size < 512)
- return false;
-
- _machine = Get32(buf + 4, be);
- _type = Get32(buf + 0xC, be);
-
- UInt32 numCommands = Get32(buf + 0x10, be);
- UInt32 commandsSize = Get32(buf + 0x14, be);
- if (commandsSize > size)
- return false;
-
- if (commandsSize > (1 << 24) || numCommands > (1 << 18))
- return false;
-
- if (numCommands > 16)
- {
- reduceCommands = true;
- numCommands = 16;
- }
-
- _headersSize = 0;
-
- buf += 0x1C;
- size -= 0x1C;
-
- if (mode64)
- {
- buf += 4;
- size -= 4;
- }
-
- _totalSize = (UInt32)(buf - bufStart);
- if (commandsSize < size)
- size = commandsSize;
-
- for (UInt32 cmdIndex = 0; cmdIndex < numCommands; cmdIndex++)
- {
- if (size < 8)
- return false;
- UInt32 cmd = Get32(buf, be);
- UInt32 cmdSize = Get32(buf + 4, be);
- if (size < cmdSize)
- return false;
- if (cmd == MACH_CMD_SEGMENT_32 || cmd == MACH_CMD_SEGMENT_64)
- {
- UInt32 offs = (cmd == MACH_CMD_SEGMENT_64) ? 0x48 : 0x38;
- if (cmdSize < offs)
- break;
-
- UInt64 vmAddr, vmSize, phAddr, phSize;
-
- {
- if (cmd == MACH_CMD_SEGMENT_64)
- {
- vmAddr = Get64(buf + 0x18, be);
- vmSize = Get64(buf + 0x20, be);
- phAddr = Get64(buf + 0x28, be);
- phSize = Get64(buf + 0x30, be);
- }
- else
- {
- vmAddr = Get32(buf + 0x18, be);
- vmSize = Get32(buf + 0x1C, be);
- phAddr = Get32(buf + 0x20, be);
- phSize = Get32(buf + 0x24, be);
- }
- {
- UInt64 totalSize = phAddr + phSize;
- if (totalSize > _totalSize)
- _totalSize = totalSize;
- }
- }
-
- CSegment seg;
- memcpy(seg.Name, buf + 8, kNameSize);
- _segments.Add(seg);
-
- UInt32 numSections = Get32(buf + offs - 8, be);
- if (numSections > (1 << 8))
- return false;
-
- if (numSections == 0)
- {
- CSection section;
- section.IsDummy = true;
- section.SegmentIndex = _segments.Size() - 1;
- section.Va = vmAddr;
- section.PSize = phSize;
- section.VSize = vmSize;
- section.Pa = phAddr;
- section.Flags = 0;
- _sections.Add(section);
- }
- else do
- {
- CSection section;
- UInt32 headerSize = (cmd == MACH_CMD_SEGMENT_64) ? 0x50 : 0x44;
- const Byte *p = buf + offs;
- if (cmdSize - offs < headerSize)
- break;
- if (cmd == MACH_CMD_SEGMENT_64)
- {
- section.Va = Get64(p + 0x20, be);
- section.VSize = Get64(p + 0x28, be);
- section.Pa = Get32(p + 0x30, be);
- section.Flags = Get32(p + 0x40, be);
- }
- else
- {
- section.Va = Get32(p + 0x20, be);
- section.VSize = Get32(p + 0x24, be);
- section.Pa = Get32(p + 0x28, be);
- section.Flags = Get32(p + 0x38, be);
- }
- if (section.Flags == MACH_SECT_ATTR_ZEROFILL)
- section.PSize = 0;
- else
- section.PSize = section.VSize;
- memcpy(section.Name, p, kNameSize);
- memcpy(section.SegName, p + kNameSize, kNameSize);
- section.SegmentIndex = _segments.Size() - 1;
- _sections.Add(section);
- offs += headerSize;
- }
- while (--numSections);
-
- if (offs != cmdSize)
- return false;
- }
- buf += cmdSize;
- size -= cmdSize;
- }
- _headersSize = (UInt32)(buf - bufStart);
- return reduceCommands || (size == 0);
-}
-
-static STATPROPSTG kArcProps[] =
-{
- { NULL, kpidCpu, VT_BSTR},
- { NULL, kpidBit64, VT_BOOL},
- { NULL, kpidBigEndian, VT_BOOL},
- { NULL, kpidCharacts, VT_BSTR},
- { NULL, kpidPhySize, VT_UI8},
- { NULL, kpidHeadersSize, VT_UI4}
-};
-
-static STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { 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 kpidCpu: PAIR_TO_PROP(g_MachinePairs, _machine, prop); break;
- case kpidCharacts: TYPE_TO_PROP(g_FileTypes, _type, prop); break;
- case kpidPhySize: prop = _totalSize; break;
- case kpidHeadersSize: prop = _headersSize; break;
- case kpidBit64: if (_mode64) prop = _mode64; break;
- case kpidBigEndian: if (_be) prop = _be; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-static AString GetName(const char *name)
-{
- char res[kNameSize + 1];
- memcpy(res, name, kNameSize);
- res[kNameSize] = 0;
- return res;
-}
-
-static AString SectFlagsToString(UInt32 flags)
-{
- AString res = TypeToString(g_SectTypes, sizeof(g_SectTypes) / sizeof(g_SectTypes[0]),
- flags & MACH_SECT_TYPE_MASK);
- AString s = FlagsToString(g_Flags, sizeof(g_Flags) / sizeof(g_Flags[0]),
- flags & MACH_SECT_ATTR_MASK);
- if (!s.IsEmpty())
- {
- res += ' ';
- res += s;
- }
- return res;
-}
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NCOM::CPropVariant prop;
- const CSection &item = _sections[index];
- switch(propID)
- {
- case kpidPath:
- {
- AString s = GetName(_segments[item.SegmentIndex].Name);
- if (!item.IsDummy)
- s += GetName(item.Name);
- StringToProp(s, prop);
- break;
- }
- case kpidSize: /* prop = (UInt64)item.VSize; break; */
- case kpidPackSize: prop = (UInt64)item.GetPackSize(); break;
- case kpidCharacts: if (!item.IsDummy) StringToProp(SectFlagsToString(item.Flags), prop); break;
- case kpidOffset: prop = item.Pa; break;
- case kpidVa: prop = item.Va; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-HRESULT CHandler::Open2(ISequentialInStream *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));
- UInt32 sig = GetUi32(buf);
- bool be, mode64;
- switch(sig)
- {
- case 0xCEFAEDFE: be = true; mode64 = false; break;
- case 0xCFFAEDFE: be = true; mode64 = true; break;
- case 0xFEEDFACE: be = false; mode64 = false; break;
- case 0xFEEDFACF: be = false; mode64 = true; break;
- default: return S_FALSE;
- }
- processed = kBufSize - kSigSize;
- RINOK(ReadStream(stream, buf + kSigSize, &processed));
- _mode64 = mode64;
- _be = be;
- return Parse(buf, (UInt32)processed + kSigSize) ? 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();
- _segments.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]].GetPackSize();
- 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 CSection &item = _sections[index];
- currentItemSize = item.GetPackSize();
-
- CMyComPtr<ISequentialOutStream> outStream;
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- if (!testMode && !outStream)
- continue;
-
- RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(_inStream->Seek(item.Pa, 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"MachO", L"", 0, 0xDF, { 0 }, 0, false, CreateArc, 0 };
-
-REGISTER_ARC(Macho)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/MbrHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/MbrHandler.cpp
deleted file mode 100644
index b6d791829..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/MbrHandler.cpp
+++ /dev/null
@@ -1,507 +0,0 @@
-// MbrHandler.cpp
-
-#include "StdAfx.h"
-
-// #define SHOW_DEBUG_INFO
-
-#ifdef SHOW_DEBUG_INFO
-#include <stdio.h>
-#endif
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/Buffer.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"
-
-#ifdef SHOW_DEBUG_INFO
-#define PRF(x) x
-#else
-#define PRF(x)
-#endif
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NMbr {
-
-struct CChs
-{
- Byte Head;
- Byte SectCyl;
- Byte Cyl8;
-
- UInt32 GetSector() const { return SectCyl & 0x3F; }
- UInt32 GetCyl() const { return ((UInt32)SectCyl >> 6 << 8) | Cyl8; }
- void ToString(NCOM::CPropVariant &prop) const;
-
- void Parse(const Byte *p)
- {
- Head = p[0];
- SectCyl = p[1];
- Cyl8 = p[2];
- }
- bool Check() const { return GetSector() > 0; }
-};
-
-#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
-
-static int CompareChs(const CChs &c1, const CChs &c2)
-{
- RINOZ(MyCompare(c1.GetCyl(), c2.GetCyl()));
- RINOZ(MyCompare(c1.Head, c2.Head));
- return MyCompare(c1.GetSector(), c2.GetSector());
-}
-
-static void AddUIntToString(UInt32 val, AString &res)
-{
- char s[16];
- ConvertUInt32ToString(val, s);
- res += s;
-}
-
-void CChs::ToString(NCOM::CPropVariant &prop) const
-{
- AString s;
- AddUIntToString(GetCyl(), s);
- s += '-';
- AddUIntToString(Head, s);
- s += '-';
- AddUIntToString(GetSector(), s);
- prop = s;
-}
-
-struct CPartition
-{
- Byte Status;
- CChs BeginChs;
- Byte Type;
- CChs EndChs;
- UInt32 Lba;
- UInt32 NumBlocks;
-
- CPartition() { memset (this, 0, sizeof(*this)); }
-
- bool IsEmpty() const { return Type == 0; }
- bool IsExtended() const { return Type == 5 || Type == 0xF; }
- UInt32 GetLimit() const { return Lba + NumBlocks; }
- // bool IsActive() const { return Status == 0x80; }
- UInt64 GetPos() const { return (UInt64)Lba * 512; }
- UInt64 GetSize() const { return (UInt64)NumBlocks * 512; }
-
- bool CheckLbaLimits() const { return (UInt32)0xFFFFFFFF - Lba >= NumBlocks; }
- bool Parse(const Byte *p)
- {
- Status = p[0];
- BeginChs.Parse(p + 1);
- Type = p[4];
- EndChs.Parse(p + 5);
- Lba = GetUi32(p + 8);
- NumBlocks = GetUi32(p + 12);
- if (Type == 0)
- return true;
- if (Status != 0 && Status != 0x80)
- return false;
- return
- BeginChs.Check() &&
- EndChs.Check() &&
- CompareChs(BeginChs, EndChs) <= 0 &&
- NumBlocks > 0 &&
- CheckLbaLimits();
- }
-
- #ifdef SHOW_DEBUG_INFO
- void Print() const
- {
- NCOM::CPropVariant prop, prop2;
- BeginChs.ToString(prop);
- EndChs.ToString(prop2);
- printf(" %2x %2x %8X %8X %12S %12S", (int)Status, (int)Type, Lba, NumBlocks, prop.bstrVal, prop2.bstrVal);
- }
- #endif
-};
-
-struct CPartType
-{
- UInt32 Id;
- const char *Ext;
- const char *Name;
-};
-
-static const char *kFat = "fat";
-
-static const CPartType kPartTypes[] =
-{
- { 0x01, kFat, "FAT12" },
- { 0x04, kFat, "FAT16 DOS 3.0+" },
- { 0x05, 0, "Extended" },
- { 0x06, kFat, "FAT16 DOS 3.31+" },
- { 0x07, "ntfs", "NTFS" },
- { 0x0B, kFat, "FAT32" },
- { 0x0C, kFat, "FAT32-LBA" },
- { 0x0E, kFat, "FAT16-LBA" },
- { 0x0F, 0, "Extended-LBA" },
- { 0x11, kFat, "FAT12-Hidden" },
- { 0x14, kFat, "FAT16-Hidden < 32 MB" },
- { 0x16, kFat, "FAT16-Hidden >= 32 MB" },
- { 0x1B, kFat, "FAT32-Hidden" },
- { 0x1C, kFat, "FAT32-LBA-Hidden" },
- { 0x1E, kFat, "FAT16-LBA-WIN95-Hidden" },
- { 0x82, 0, "Solaris x86 / Linux swap" },
- { 0x83, 0, "Linux" },
- { 0xBE, 0, "Solaris 8 boot" },
- { 0xBF, 0, "New Solaris x86" },
- { 0xC2, 0, "Linux-Hidden" },
- { 0xC3, 0, "Linux swap-Hidden" },
- { 0xEE, 0, "EFI-MBR" },
- { 0xEE, 0, "EFI" }
-};
-
-static int FindPartType(UInt32 type)
-{
- for (int i = 0; i < sizeof(kPartTypes) / sizeof(kPartTypes[0]); i++)
- if (kPartTypes[i].Id == type)
- return i;
- return -1;
-}
-
-struct CItem
-{
- bool IsReal;
- bool IsPrim;
- UInt64 Size;
- CPartition Part;
-};
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- CObjectVector<CItem> _items;
- UInt64 _totalSize;
- CByteBuffer _buffer;
-
- HRESULT ReadTables(IInStream *stream, UInt32 baseLba, UInt32 lba, int level);
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-HRESULT CHandler::ReadTables(IInStream *stream, UInt32 baseLba, UInt32 lba, int level)
-{
- if (level >= 128 || _items.Size() >= 128)
- return S_FALSE;
-
- const int kNumHeaderParts = 4;
- CPartition parts[kNumHeaderParts];
-
- {
- const UInt32 kSectorSize = 512;
- _buffer.SetCapacity(kSectorSize);
- Byte *buf = _buffer;
- UInt64 newPos = (UInt64)lba << 9;
- if (newPos + 512 > _totalSize)
- return S_FALSE;
- RINOK(stream->Seek(newPos, STREAM_SEEK_SET, NULL));
- RINOK(ReadStream_FALSE(stream, buf, kSectorSize));
-
- if (buf[0x1FE] != 0x55 || buf[0x1FF] != 0xAA)
- return S_FALSE;
-
- for (int i = 0; i < kNumHeaderParts; i++)
- if (!parts[i].Parse(buf + 0x1BE + 16 * i))
- return S_FALSE;
- }
-
- PRF(printf("\n# %8X", lba));
-
- UInt32 limLba = lba + 1;
- if (limLba == 0)
- return S_FALSE;
-
- for (int i = 0; i < kNumHeaderParts; i++)
- {
- CPartition &part = parts[i];
-
- if (part.IsEmpty())
- continue;
- PRF(printf("\n %2d ", (int)level));
- #ifdef SHOW_DEBUG_INFO
- part.Print();
- #endif
-
- int numItems = _items.Size();
- UInt32 newLba = lba + part.Lba;
-
- if (part.IsExtended())
- {
- // if (part.Type == 5) // Check it!
- newLba = baseLba + part.Lba;
- if (newLba < limLba)
- return S_FALSE;
- HRESULT res = ReadTables(stream, level < 1 ? newLba : baseLba, newLba, level + 1);
- if (res != S_FALSE && res != S_OK)
- return res;
- }
- if (newLba < limLba)
- return S_FALSE;
- part.Lba = newLba;
- if (!part.CheckLbaLimits())
- return S_FALSE;
-
- CItem n;
- n.Part = part;
- bool addItem = false;
- if (numItems == _items.Size())
- {
- n.IsPrim = (level == 0);
- n.IsReal = true;
- addItem = true;
- }
- else
- {
- const CItem &back = _items.Back();
- UInt32 backLimit = back.Part.GetLimit();
- UInt32 partLimit = part.GetLimit();
- if (backLimit < partLimit)
- {
- n.IsReal = false;
- n.Part.Lba = backLimit;
- n.Part.NumBlocks = partLimit - backLimit;
- addItem = true;
- }
- }
- if (addItem)
- {
- if (n.Part.GetLimit() < limLba)
- return S_FALSE;
- limLba = n.Part.GetLimit();
- n.Size = n.Part.GetSize();
- _items.Add(n);
- }
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *stream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- RINOK(stream->Seek(0, STREAM_SEEK_END, &_totalSize));
- RINOK(ReadTables(stream, 0, 0, 0));
- if (_items.IsEmpty())
- return S_FALSE;
- UInt32 lbaLimit = _items.Back().Part.GetLimit();
- UInt64 lim = (UInt64)lbaLimit << 9;
- if (lim < _totalSize)
- {
- CItem n;
- n.Part.Lba = lbaLimit;
- n.Size = _totalSize - lim;
- n.IsReal = false;
- _items.Add(n);
- }
- _stream = stream;
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _items.Clear();
- _stream.Release();
- return S_OK;
-}
-
-enum
-{
- kpidPrimary = kpidUserDefined,
- kpidBegChs,
- kpidEndChs
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidFileSystem, VT_BSTR},
- { NULL, kpidOffset, VT_UI8},
- { L"Primary", kpidPrimary, VT_BOOL},
- { L"Begin CHS", kpidBegChs, VT_BSTR},
- { L"End CHS", kpidEndChs, VT_BSTR}
-};
-
-IMP_IInArchive_Props_WITH_NAME
-IMP_IInArchive_ArcProps_NO_Table
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMainSubfile:
- {
- int mainIndex = -1;
- for (int i = 0; i < _items.Size(); i++)
- if (_items[i].IsReal)
- {
- if (mainIndex >= 0)
- {
- mainIndex = -1;
- break;
- }
- mainIndex = i;
- }
- if (mainIndex >= 0)
- prop = (UInt32)mainIndex;
- break;
- }
- }
- prop.Detach(value);
- 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
- NCOM::CPropVariant prop;
-
- const CItem &item = _items[index];
- const CPartition &part = item.Part;
- switch(propID)
- {
- case kpidPath:
- {
- AString s;
- AddUIntToString(index, s);
- if (item.IsReal)
- {
- int typeIndex = FindPartType(part.Type);
- s += '.';
- const char *ext = "img";
- if (typeIndex >= 0 && kPartTypes[typeIndex].Ext != 0)
- ext = kPartTypes[typeIndex].Ext;
- s += ext;
- }
- prop = s;
- break;
- }
- case kpidFileSystem:
- if (item.IsReal)
- {
- char s[32];
- ConvertUInt32ToString(part.Type, s);
- const char *res = s;
- int typeIndex = FindPartType(part.Type);
- if (typeIndex >= 0 && kPartTypes[typeIndex].Name)
- res = kPartTypes[typeIndex].Name;
- prop = res;
- }
- break;
- case kpidSize: prop = item.Size; break;;
- case kpidPackSize: prop = item.Size; break;
- case kpidOffset: prop = part.GetPos(); break;
- case kpidPrimary: if (item.IsReal) prop = item.IsPrim; break;
- case kpidBegChs: if (item.IsReal) part.BeginChs.ToString(prop); break;
- case kpidEndChs: if (item.IsReal) part.EndChs.ToString(prop); 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);
-
- 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];
- const CPartition &part = item.Part;
- RINOK(extractCallback->GetStream(index, &outStream, askMode));
- totalSize += item.Size;
- if (!testMode && !outStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
-
- RINOK(_stream->Seek(part.GetPos(), 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 CItem &item = _items[index];
- return CreateLimitedInStream(_stream, item.Part.GetPos(), item.Size, stream);
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"MBR", L"mbr", 0, 0xDB, { 1, 1, 0 }, 3, false, CreateArc, 0 };
-
-REGISTER_ARC(Mbr)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/MslzHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/MslzHandler.cpp
deleted file mode 100644
index 67495e765..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/MslzHandler.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-// MslzHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/ComTry.h"
-#include "Common/MyString.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../Common/InBuffer.h"
-#include "../Common/ProgressUtils.h"
-#include "../Common/RegisterArc.h"
-#include "../Common/StreamUtils.h"
-
-#include "Common/DummyOutStream.h"
-
-namespace NArchive {
-namespace NMslz {
-
-class CHandler:
- public IInArchive,
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _stream;
- UInt32 _size;
- UInt64 _packSize;
- UString _name;
-public:
- MY_UNKNOWN_IMP1(IInArchive)
- INTERFACE_IInArchive(;)
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-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 (!_name.IsEmpty()) prop = _name; break;
- case kpidSize: prop = _size; break;
- case kpidPackSize: prop = _packSize; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-static const unsigned kSignatureSize = 9;
-static const unsigned kHeaderSize = kSignatureSize + 1 + 4;
-#define MSLZ_SIGNATURE { 0x53, 0x5A, 0x44, 0x44, 0x88, 0xF0, 0x27, 0x33, 0x41 }
-// old signature: 53 5A 20 88 F0 27 33
-static const Byte signature[kSignatureSize] = MSLZ_SIGNATURE;
-
-static const wchar_t *g_Exts[] =
-{
- L"dll",
- L"exe",
- L"kmd",
- L"sys"
-};
-
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback *callback)
-{
- COM_TRY_BEGIN
- {
- Close();
- Byte buffer[kHeaderSize];
- RINOK(ReadStream_FALSE(stream, buffer, kHeaderSize));
- if (memcmp(buffer, signature, kSignatureSize) != 0)
- return S_FALSE;
- _size = GetUi32(buffer + 10);
- if (_size > 0xFFFFFFE0)
- return S_FALSE;
- RINOK(stream->Seek(0, STREAM_SEEK_END, &_packSize));
-
- if (callback)
- {
- CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
- callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
- if (openVolumeCallback)
- {
- NWindows::NCOM::CPropVariant prop;
- if (openVolumeCallback->GetProperty(kpidName, &prop) == S_OK && prop.vt == VT_BSTR)
- {
- UString baseName = prop.bstrVal;
- if (!baseName.IsEmpty() && baseName.Back() == L'_')
- {
- baseName.DeleteBack();
- Byte replaceByte = buffer[kSignatureSize];
- if (replaceByte == 0)
- {
- for (int i = 0; i < sizeof(g_Exts) / sizeof(g_Exts[0]); i++)
- {
- UString s = g_Exts[i];
- int len = s.Length();
- Byte b = (Byte)s.Back();
- s.DeleteBack();
- if (baseName.Length() >= len &&
- baseName[baseName.Length() - len] == '.' &&
- s.CompareNoCase(baseName.Right(len - 1)) == 0)
- {
- replaceByte = b;
- break;
- }
- }
- }
- if (replaceByte >= 0x20 && replaceByte < 0x80)
- _name = baseName + (wchar_t)replaceByte;
- }
- }
- }
- }
- _stream = stream;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _stream.Release();
- _name.Empty();
- return S_OK;
-}
-
-// MslzDec is modified LZSS algorithm of Haruhiko Okumura:
-// maxLen = 18; Okumura
-// maxLen = 16; MS
-
-#define PROGRESS_AND_WRITE \
- if ((dest & kMask) == 0) { RINOK(WriteStream(outStream, buf, kBufSize)); \
- if ((dest & ((1 << 20) - 1)) == 0) \
- { UInt64 inSize = inStream.GetProcessedSize(); UInt64 outSize = dest; \
- RINOK(progress->SetRatioInfo(&inSize, &outSize)); }}
-
-static HRESULT MslzDec(CInBuffer &inStream, ISequentialOutStream *outStream, UInt32 unpackSize, ICompressProgressInfo *progress)
-{
- const unsigned kBufSize = (1 << 12);
- const unsigned kMask = kBufSize - 1;
- Byte buf[kBufSize];
- UInt32 dest = 0;
- memset(buf, ' ', kBufSize);
- while (dest < unpackSize)
- {
- Byte b;
- if (!inStream.ReadByte(b))
- return S_FALSE;
- for (unsigned mask = (unsigned)b | 0x100; mask > 1 && dest < unpackSize; mask >>= 1)
- {
- if (!inStream.ReadByte(b))
- return S_FALSE;
- if (mask & 1)
- {
- buf[dest++ & kMask] = b;
- PROGRESS_AND_WRITE
- }
- else
- {
- Byte b1;
- if (!inStream.ReadByte(b1))
- return S_FALSE;
- const unsigned kMaxLen = 16; // 18 in Okumura's code.
- unsigned src = (((((unsigned)b1 & 0xF0) << 4) | b) + kMaxLen) & kMask;
- unsigned len = (b1 & 0xF) + 3;
- if (len > kMaxLen || dest + len > unpackSize)
- return S_FALSE;
- do
- {
- buf[dest++ & kMask] = buf[src++ & kMask];
- PROGRESS_AND_WRITE
- }
- while (--len != 0);
- }
- }
- }
- return WriteStream(outStream, buf, dest & kMask);
-}
-
-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;
-
- extractCallback->SetTotal(_size);
-
- 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);
-
- 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, false);
-
- RINOK(_stream->Seek(0, STREAM_SEEK_SET, NULL));
- CInBuffer s;
- if (!s.Create(1 << 20))
- return E_OUTOFMEMORY;
- s.SetStream(_stream);
- s.Init();
- Byte buffer[kHeaderSize];
- Int32 opRes = NExtract::NOperationResult::kDataError;
- if (s.ReadBytes(buffer, kHeaderSize) == kHeaderSize)
- {
- HRESULT result = MslzDec(s, outStream, _size, progress);
- if (result == S_OK)
- opRes = NExtract::NOperationResult::kOK;
- else if (result != S_FALSE)
- return result;
- }
- outStream.Release();
- return extractCallback->SetOperationResult(opRes);
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"MsLZ", L"", 0, 0xD5, MSLZ_SIGNATURE, kSignatureSize, false, CreateArc, 0 };
-
-REGISTER_ARC(Mslz)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/MubHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/MubHandler.cpp
deleted file mode 100644
index da4df24c9..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/MubHandler.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-// MubHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../C/CpuArch.h"
-
-#include "Common/ComTry.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 Get32(p) GetBe32(p)
-
-namespace NArchive {
-namespace NMub {
-
-struct CItem
-{
- UInt32 Type;
- UInt32 SubType;
- UInt64 Offset;
- UInt64 Size;
- UInt32 Align;
- bool IsTail;
-};
-
-const UInt32 kNumFilesMax = 10;
-
-class CHandler:
- public IInArchive,
- public IInArchiveGetStream,
- public CMyUnknownImp
-{
- UInt64 _startPos;
- CMyComPtr<IInStream> _stream;
- UInt32 _numItems;
- CItem _items[kNumFilesMax + 1];
- HRESULT Open2(IInStream *stream);
-public:
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
- INTERFACE_IInArchive(;)
- STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
-};
-
-STATPROPSTG kProps[] =
-{
- { NULL, kpidSize, VT_UI8}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps_NO
-
-#define MACH_ARCH_ABI64 0x1000000
-#define MACH_MACHINE_386 7
-#define MACH_MACHINE_ARM 12
-#define MACH_MACHINE_SPARC 14
-#define MACH_MACHINE_PPC 18
-
-#define MACH_MACHINE_PPC64 (MACH_MACHINE_PPC | MACH_ARCH_ABI64)
-#define MACH_MACHINE_AMD64 (MACH_MACHINE_386 | MACH_ARCH_ABI64)
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- NWindows::NCOM::CPropVariant prop;
- const CItem &item = _items[index];
- switch(propID)
- {
- case kpidExtension:
- {
- const wchar_t *ext;
- if (item.IsTail)
- ext = L"tail";
- else
- {
- switch(item.Type)
- {
- case MACH_MACHINE_386: ext = L"86"; break;
- case MACH_MACHINE_ARM: ext = L"arm"; break;
- case MACH_MACHINE_SPARC: ext = L"sparc"; break;
- case MACH_MACHINE_PPC: ext = L"ppc"; break;
- case MACH_MACHINE_PPC64: ext = L"ppc64"; break;
- case MACH_MACHINE_AMD64: ext = L"x64"; break;
- default: ext = L"unknown"; break;
- }
- }
- prop = ext;
- break;
- }
- case kpidSize:
- case kpidPackSize:
- prop = (UInt64)item.Size;
- break;
- }
- prop.Detach(value);
- return S_OK;
-}
-
-#define MACH_TYPE_ABI64 (1 << 24)
-#define MACH_SUBTYPE_ABI64 (1 << 31)
-
-HRESULT CHandler::Open2(IInStream *stream)
-{
- RINOK(stream->Seek(0, STREAM_SEEK_SET, &_startPos));
-
- const UInt32 kHeaderSize = 8;
- const UInt32 kRecordSize = 5 * 4;
- const UInt32 kBufSize = kHeaderSize + kNumFilesMax * kRecordSize;
- Byte buf[kBufSize];
- size_t processed = kBufSize;
- RINOK(ReadStream(stream, buf, &processed));
- if (processed < kHeaderSize)
- return S_FALSE;
- UInt32 num = Get32(buf + 4);
- if (Get32(buf) != 0xCAFEBABE || num > kNumFilesMax || processed < kHeaderSize + num * kRecordSize)
- return S_FALSE;
- UInt64 endPosMax = kHeaderSize;
- for (UInt32 i = 0; i < num; i++)
- {
- const Byte *p = buf + kHeaderSize + i * kRecordSize;
- CItem &sb = _items[i];
- sb.IsTail = false;
- sb.Type = Get32(p);
- sb.SubType = Get32(p + 4);
- sb.Offset = Get32(p + 8);
- sb.Size = Get32(p + 12);
- sb.Align = Get32(p + 16);
-
- if ((sb.Type & ~MACH_TYPE_ABI64) >= 0x100 ||
- (sb.SubType & ~MACH_SUBTYPE_ABI64) >= 0x100 ||
- sb.Align > 31)
- return S_FALSE;
-
- UInt64 endPos = (UInt64)sb.Offset + sb.Size;
- if (endPos > endPosMax)
- endPosMax = endPos;
- }
- UInt64 fileSize;
- RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
- fileSize -= _startPos;
- _numItems = num;
- if (fileSize > endPosMax)
- {
- CItem &sb = _items[_numItems++];
- sb.IsTail = true;
- sb.Type = 0;
- sb.SubType = 0;
- sb.Offset = endPosMax;
- sb.Size = fileSize - endPosMax;
- sb.Align = 0;
- }
- return S_OK;
-}
-
-STDMETHODIMP CHandler::Open(IInStream *inStream,
- const UInt64 * /* maxCheckStartPosition */,
- IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- try
- {
- if (Open2(inStream) != S_OK)
- return S_FALSE;
- _stream = inStream;
- }
- catch(...) { return S_FALSE; }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _stream.Release();
- _numItems = 0;
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _numItems;
- 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 = _numItems;
- 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;
- UInt32 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(_startPos + 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;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
-{
- COM_TRY_BEGIN
- const CItem &item = _items[index];
- return CreateLimitedInStream(_stream, _startPos + item.Offset, item.Size, stream);
- COM_TRY_END
-}
-
-static IInArchive *CreateArc() { return new CHandler; }
-
-static CArcInfo g_ArcInfo =
- { L"Mub", L"", 0, 0xE2, { 0xCA, 0xFE, 0xBA, 0xBE, 0, 0, 0 }, 7, false, CreateArc, 0 };
-
-REGISTER_ARC(Mub)
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.cpp
deleted file mode 100644
index 0845f965d..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-// NsisDecode.cpp
-
-#include "StdAfx.h"
-
-#include "NsisDecode.h"
-
-#include "../../Common/StreamUtils.h"
-
-#include "../../Common/MethodId.h"
-
-#include "../../Compress/BZip2Decoder.h"
-#include "../../Compress/DeflateDecoder.h"
-#include "../../Compress/LzmaDecoder.h"
-
-namespace NArchive {
-namespace NNsis {
-
-static const CMethodId k_BCJ_X86 = 0x03030103;
-
-HRESULT CDecoder::Init(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream, NMethodType::EEnum method, bool thereIsFilterFlag, bool &useFilter)
-{
- useFilter = false;
- CObjectVector< CMyComPtr<ISequentialInStream> > inStreams;
-
- if (_decoderInStream)
- if (method != _method)
- Release();
- _method = method;
- if (!_codecInStream)
- {
- switch (method)
- {
- // case NMethodType::kCopy: return E_NOTIMPL;
- case NMethodType::kDeflate: _codecInStream = new NCompress::NDeflate::NDecoder::CNsisCOMCoder(); break;
- case NMethodType::kBZip2: _codecInStream = new NCompress::NBZip2::CNsisDecoder(); break;
- case NMethodType::kLZMA: _codecInStream = new NCompress::NLzma::CDecoder(); break;
- default: return E_NOTIMPL;
- }
- }
-
- if (thereIsFilterFlag)
- {
- UInt32 processedSize;
- BYTE flag;
- RINOK(inStream->Read(&flag, 1, &processedSize));
- if (processedSize != 1)
- return E_FAIL;
- if (flag > 1)
- return E_NOTIMPL;
- useFilter = (flag != 0);
- }
-
- if (useFilter)
- {
- if (!_filterInStream)
- {
- CMyComPtr<ICompressCoder> coder;
- RINOK(CreateCoder(
- EXTERNAL_CODECS_LOC_VARS
- k_BCJ_X86, coder, false));
- if (!coder)
- return E_NOTIMPL;
- coder.QueryInterface(IID_ISequentialInStream, &_filterInStream);
- if (!_filterInStream)
- return E_NOTIMPL;
- }
- CMyComPtr<ICompressSetInStream> setInStream;
- _filterInStream.QueryInterface(IID_ICompressSetInStream, &setInStream);
- if (!setInStream)
- return E_NOTIMPL;
- RINOK(setInStream->SetInStream(_codecInStream));
- _decoderInStream = _filterInStream;
- }
- else
- _decoderInStream = _codecInStream;
-
- if (method == NMethodType::kLZMA)
- {
- CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
- _codecInStream.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
- if (setDecoderProperties)
- {
- static const UInt32 kPropertiesSize = 5;
- BYTE properties[kPropertiesSize];
- UInt32 processedSize;
- RINOK(inStream->Read(properties, kPropertiesSize, &processedSize));
- if (processedSize != kPropertiesSize)
- return E_FAIL;
- RINOK(setDecoderProperties->SetDecoderProperties2((const Byte *)properties, kPropertiesSize));
- }
- }
-
- {
- CMyComPtr<ICompressSetInStream> setInStream;
- _codecInStream.QueryInterface(IID_ICompressSetInStream, &setInStream);
- if (!setInStream)
- return E_NOTIMPL;
- RINOK(setInStream->SetInStream(inStream));
- }
-
- {
- CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
- _codecInStream.QueryInterface(IID_ICompressSetOutStreamSize, &setOutStreamSize);
- if (!setOutStreamSize)
- return E_NOTIMPL;
- RINOK(setOutStreamSize->SetOutStreamSize(NULL));
- }
-
- if (useFilter)
- {
- /*
- CMyComPtr<ICompressSetOutStreamSize> setOutStreamSize;
- _filterInStream.QueryInterface(IID_ICompressSetOutStreamSize, &setOutStreamSize);
- if (!setOutStreamSize)
- return E_NOTIMPL;
- RINOK(setOutStreamSize->SetOutStreamSize(NULL));
- */
- }
-
- return S_OK;
-}
-
-HRESULT CDecoder::Read(void *data, size_t *processedSize)
-{
- return ReadStream(_decoderInStream, data, processedSize);;
-}
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.h b/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.h
deleted file mode 100644
index 36aeb2b14..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisDecode.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// NsisDecode.h
-
-#ifndef __NSIS_DECODE_H
-#define __NSIS_DECODE_H
-
-#include "../../IStream.h"
-
-#include "../../Common/CreateCoder.h"
-
-namespace NArchive {
-namespace NNsis {
-
-namespace NMethodType
-{
- enum EEnum
- {
- kCopy,
- kDeflate,
- kBZip2,
- kLZMA
- };
-}
-
-class CDecoder
-{
- NMethodType::EEnum _method;
-
- CMyComPtr<ISequentialInStream> _filterInStream;
- CMyComPtr<ISequentialInStream> _codecInStream;
- CMyComPtr<ISequentialInStream> _decoderInStream;
-
-public:
- void Release()
- {
- _filterInStream.Release();
- _codecInStream.Release();
- _decoderInStream.Release();
- }
- HRESULT Init(
- DECL_EXTERNAL_CODECS_LOC_VARS
- IInStream *inStream, NMethodType::EEnum method, bool thereIsFilterFlag, bool &useFilter);
- HRESULT Read(void *data, size_t *processedSize);
-};
-
-}}
-
-#endif
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.cpp b/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.cpp
deleted file mode 100644
index 4058bd2af..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.cpp
+++ /dev/null
@@ -1,510 +0,0 @@
-// NSisHandler.cpp
-
-#include "StdAfx.h"
-
-#include "../../../../C/CpuArch.h"
-
-#include "Common/ComTry.h"
-#include "Common/IntToString.h"
-
-#include "Windows/PropVariant.h"
-
-#include "../../Common/StreamUtils.h"
-
-#include "../Common/ItemNameUtils.h"
-
-#include "NsisHandler.h"
-
-#define Get32(p) GetUi32(p)
-
-using namespace NWindows;
-
-namespace NArchive {
-namespace NNsis {
-
-static const char *kBcjMethod = "BCJ";
-static const char *kUnknownMethod = "Unknown";
-
-static const char *kMethods[] =
-{
- "Copy",
- "Deflate",
- "BZip2",
- "LZMA"
-};
-
-static const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
-
-static STATPROPSTG kProps[] =
-{
- { NULL, kpidPath, VT_BSTR},
- { NULL, kpidSize, VT_UI8},
- { NULL, kpidPackSize, VT_UI8},
- { NULL, kpidMTime, VT_FILETIME},
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidSolid, VT_BOOL}
-};
-
-static STATPROPSTG kArcProps[] =
-{
- { NULL, kpidMethod, VT_BSTR},
- { NULL, kpidSolid, VT_BOOL}
-};
-
-IMP_IInArchive_Props
-IMP_IInArchive_ArcProps
-
-STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- switch(propID)
- {
- case kpidMethod:
- {
- UInt32 dict = 1;
- bool filter = false;
- for (int i = 0; i < _archive.Items.Size(); i++)
- {
- const CItem &item = _archive.Items[i];
- filter |= item.UseFilter;
- if (item.DictionarySize > dict)
- dict = item.DictionarySize;
- }
- prop = GetMethod(filter, dict);
- break;
- }
- case kpidSolid: prop = _archive.IsSolid; break;
- }
- prop.Detach(value);
- return S_OK;
- COM_TRY_END
-}
-
-
-STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 * maxCheckStartPosition, IArchiveOpenCallback * /* openArchiveCallback */)
-{
- COM_TRY_BEGIN
- Close();
- {
- if (_archive.Open(
- EXTERNAL_CODECS_VARS
- stream, maxCheckStartPosition) != S_OK)
- return S_FALSE;
- _inStream = stream;
- }
- return S_OK;
- COM_TRY_END
-}
-
-STDMETHODIMP CHandler::Close()
-{
- _archive.Clear();
- _archive.Release();
- _inStream.Release();
- return S_OK;
-}
-
-STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
-{
- *numItems = _archive.Items.Size()
- #ifdef NSIS_SCRIPT
- + 1
- #endif
- ;
- return S_OK;
-}
-
-static AString UInt32ToString(UInt32 value)
-{
- char buffer[16];
- ConvertUInt32ToString(value, buffer);
- return buffer;
-}
-
-static AString GetStringForSizeValue(UInt32 value)
-{
- for (int i = 31; i >= 0; i--)
- if (((UInt32)1 << i) == value)
- return UInt32ToString(i);
- char c = 'b';
- if (value % (1 << 20) == 0)
- {
- value >>= 20;
- c = 'm';
- }
- else if (value % (1 << 10) == 0)
- {
- value >>= 10;
- c = 'k';
- }
- return UInt32ToString(value) + c;
-}
-
-AString CHandler::GetMethod(bool useItemFilter, UInt32 dictionary) const
-{
- NMethodType::EEnum methodIndex = _archive.Method;
- AString method;
- if (_archive.IsSolid && _archive.UseFilter || !_archive.IsSolid && useItemFilter)
- {
- method += kBcjMethod;
- method += ' ';
- }
- method += (methodIndex < kNumMethods) ? kMethods[methodIndex] : kUnknownMethod;
- if (methodIndex == NMethodType::kLZMA)
- {
- method += ':';
- method += GetStringForSizeValue(_archive.IsSolid ? _archive.DictionarySize: dictionary);
- }
- return method;
-}
-
-bool CHandler::GetUncompressedSize(int index, UInt32 &size)
-{
- size = 0;
- const CItem &item = _archive.Items[index];
- if (item.SizeIsDefined)
- size = item.Size;
- else if (_archive.IsSolid && item.EstimatedSizeIsDefined)
- size = item.EstimatedSize;
- else
- return false;
- return true;
-}
-
-bool CHandler::GetCompressedSize(int index, UInt32 &size)
-{
- size = 0;
- const CItem &item = _archive.Items[index];
- if (item.CompressedSizeIsDefined)
- size = item.CompressedSize;
- else
- {
- if (_archive.IsSolid)
- {
- if (index == 0)
- size = _archive.FirstHeader.GetDataSize();
- else
- return false;
- }
- else
- {
- if (!item.IsCompressed)
- size = item.Size;
- else
- return false;
- }
- }
- return true;
-}
-
-
-STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
-{
- COM_TRY_BEGIN
- NWindows::NCOM::CPropVariant prop;
- #ifdef NSIS_SCRIPT
- if (index >= (UInt32)_archive.Items.Size())
- {
- switch(propID)
- {
- case kpidPath: prop = L"[NSIS].nsi"; break;
- case kpidSize:
- case kpidPackSize: prop = (UInt64)_archive.Script.Length(); break;
- case kpidSolid: prop = false; break;
- }
- }
- else
- #endif
- {
- const CItem &item = _archive.Items[index];
- switch(propID)
- {
- case kpidPath:
- {
- UString s = NItemName::WinNameToOSName(item.GetReducedName(_archive.IsUnicode));
- if (!s.IsEmpty())
- prop = (const wchar_t *)s;
- break;
- }
- case kpidSize:
- {
- UInt32 size;
- if (GetUncompressedSize(index, size))
- prop = (UInt64)size;
- break;
- }
- case kpidPackSize:
- {
- UInt32 size;
- if (GetCompressedSize(index, size))
- prop = (UInt64)size;
- break;
- }
- case kpidMTime:
- {
- if (item.MTime.dwHighDateTime > 0x01000000 &&
- item.MTime.dwHighDateTime < 0xFF000000)
- prop = item.MTime;
- break;
- }
- case kpidMethod: prop = GetMethod(item.UseFilter, item.DictionarySize); break;
- case kpidSolid: prop = _archive.IsSolid; 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)
- GetNumberOfItems(&numItems);
- if (numItems == 0)
- return S_OK;
- UInt64 totalSize = 0;
-
- UInt32 i;
- for (i = 0; i < numItems; i++)
- {
- UInt32 index = (allFilesMode ? i : indices[i]);
- #ifdef NSIS_SCRIPT
- if (index >= (UInt32)_archive.Items.Size())
- totalSize += _archive.Script.Length();
- else
- #endif
- {
- UInt32 size;
- if (_archive.IsSolid)
- {
- GetUncompressedSize(index, size);
- UInt64 pos = _archive.GetPosOfSolidItem(index);
- if (pos > totalSize)
- totalSize = pos + size;
- }
- else
- {
- GetCompressedSize(index, size);
- totalSize += size;
- }
- }
- }
- extractCallback->SetTotal(totalSize);
-
- UInt64 currentTotalSize = 0;
- UInt32 currentItemSize = 0;
-
- UInt64 streamPos = 0;
- if (_archive.IsSolid)
- {
- RINOK(_inStream->Seek(_archive.StreamOffset, STREAM_SEEK_SET, NULL));
- bool useFilter;
- RINOK(_archive.Decoder.Init(
- EXTERNAL_CODECS_VARS
- _inStream, _archive.Method, _archive.FilterFlag, useFilter));
- }
-
- CByteBuffer byteBuf;
- const UInt32 kBufferLength = 1 << 16;
- byteBuf.SetCapacity(kBufferLength);
- Byte *buffer = byteBuf;
-
- CByteBuffer tempBuf;
-
- bool dataError = false;
- for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
- {
- currentItemSize = 0;
- RINOK(extractCallback->SetCompleted(&currentTotalSize));
- CMyComPtr<ISequentialOutStream> realOutStream;
- Int32 askMode = testMode ?
- NExtract::NAskMode::kTest :
- NExtract::NAskMode::kExtract;
- UInt32 index = allFilesMode ? i : indices[i];
-
- RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
-
- #ifdef NSIS_SCRIPT
- if (index >= (UInt32)_archive.Items.Size())
- {
- currentItemSize = _archive.Script.Length();
- if (!testMode && !realOutStream)
- continue;
- RINOK(extractCallback->PrepareOperation(askMode));
- if (!testMode)
- RINOK(WriteStream(realOutStream, (const char *)_archive.Script, (UInt32)_archive.Script.Length()));
- }
- else
- #endif
- {
- const CItem &item = _archive.Items[index];
-
- if (_archive.IsSolid)
- GetUncompressedSize(index, currentItemSize);
- else
- GetCompressedSize(index, currentItemSize);
-
- if (!testMode && !realOutStream)
- continue;
-
- RINOK(extractCallback->PrepareOperation(askMode));
-
- if (!dataError)
- {
- bool needDecompress = false;
- bool sizeIsKnown = false;
- UInt32 fullSize = 0;
-
- bool writeToTemp = false;
- bool readFromTemp = false;
-
- if (_archive.IsSolid)
- {
- UInt64 pos = _archive.GetPosOfSolidItem(index);
- while (streamPos < pos)
- {
- size_t processedSize = (UInt32)MyMin(pos - streamPos, (UInt64)kBufferLength);
- HRESULT res = _archive.Decoder.Read(buffer, &processedSize);
- if (res != S_OK)
- {
- if (res != S_FALSE)
- return res;
- dataError = true;
- break;
- }
- if (processedSize == 0)
- {
- dataError = true;
- break;
- }
- streamPos += processedSize;
- }
- if (streamPos == pos)
- {
- Byte buffer2[4];
- size_t processedSize = 4;
- RINOK(_archive.Decoder.Read(buffer2, &processedSize));
- if (processedSize != 4)
- return E_FAIL;
- streamPos += processedSize;
- fullSize = Get32(buffer2);
- sizeIsKnown = true;
- needDecompress = true;
-
- if (!testMode && i + 1 < numItems)
- {
- UInt64 nextPos = _archive.GetPosOfSolidItem(allFilesMode ? i : indices[i + 1]);
- if (nextPos < streamPos + fullSize)
- {
- tempBuf.Free();
- tempBuf.SetCapacity(fullSize);
- writeToTemp = true;
- }
- }
- }
- else
- readFromTemp = true;
- }
- else
- {
- RINOK(_inStream->Seek(_archive.GetPosOfNonSolidItem(index) + 4, STREAM_SEEK_SET, NULL));
- if (item.IsCompressed)
- {
- needDecompress = true;
- bool useFilter;
- RINOK(_archive.Decoder.Init(
- EXTERNAL_CODECS_VARS
- _inStream, _archive.Method, _archive.FilterFlag, useFilter));
- // fullSize = Get32(buffer); // It's bug !!!
- // Test it: what is exact fullSize?
- fullSize = 0xFFFFFFFF;
- }
- else
- fullSize = item.Size;
- }
- if (!dataError)
- {
- if (needDecompress)
- {
- UInt64 offset = 0;
- while (!sizeIsKnown || fullSize > 0)
- {
- UInt32 curSize = kBufferLength;
- if (sizeIsKnown && curSize > fullSize)
- curSize = fullSize;
- size_t processedSize = curSize;
- HRESULT res = _archive.Decoder.Read(buffer, &processedSize);
- if (res != S_OK)
- {
- if (res != S_FALSE)
- return res;
- dataError = true;
- break;
- }
- if (processedSize == 0)
- {
- if (sizeIsKnown)
- dataError = true;
- break;
- }
-
- if (writeToTemp)
- memcpy((Byte *)tempBuf + (size_t)offset, buffer, processedSize);
-
- fullSize -= (UInt32)processedSize;
- streamPos += processedSize;
- offset += processedSize;
-
- UInt64 completed;
- if (_archive.IsSolid)
- completed = currentTotalSize + offset;
- else
- completed = streamPos;
- RINOK(extractCallback->SetCompleted(&completed));
- if (!testMode)
- RINOK(WriteStream(realOutStream, buffer, processedSize));
- }
- }
- else
- {
- if (readFromTemp)
- {
- if (!testMode)
- RINOK(WriteStream(realOutStream, tempBuf, tempBuf.GetCapacity()));
- }
- else
- while (fullSize > 0)
- {
- UInt32 curSize = MyMin(fullSize, kBufferLength);
- UInt32 processedSize;
- RINOK(_inStream->Read(buffer, curSize, &processedSize));
- if (processedSize == 0)
- {
- dataError = true;
- break;
- }
- fullSize -= processedSize;
- streamPos += processedSize;
- if (!testMode)
- RINOK(WriteStream(realOutStream, buffer, processedSize));
- }
- }
- }
- }
- }
- realOutStream.Release();
- RINOK(extractCallback->SetOperationResult(dataError ?
- NExtract::NOperationResult::kDataError :
- NExtract::NOperationResult::kOK));
- }
- return S_OK;
- COM_TRY_END
-}
-
-IMPL_ISetCompressCodecsInfo
-
-}}
diff --git a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.h b/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.h
deleted file mode 100644
index 6de493df8..000000000
--- a/src/libs/7zip/win/CPP/7zip/Archive/Nsis/NsisHandler.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// NSisHandler.h
-
-#ifndef __NSIS_HANDLER_H
-#define __NSIS_HANDLER_H
-
-#include "Common/MyCom.h"
-#include "../IArchive.h"
-
-#include "NsisIn.h"
-
-#include "../../Common/CreateCoder.h"
-
-namespace NArchive {
-namespace NNsis {
-
-class CHandler:
- public IInArchive,
- PUBLIC_ISetCompressCodecsInfo
- public CMyUnknownImp
-{
- CMyComPtr<IInStream> _inStream;
- CInArchive _archive;
-
- DECL_EXTERNAL_CODECS_VARS