From 804edc5756fede54dbb1aefda6d39d306111938d Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Fri, 15 Sep 2006 00:00:00 +0000 Subject: 4.43 beta --- 7zip/Archive/7z/7zDecode.cpp | 13 +- 7zip/Archive/7z/7zDecode.h | 2 +- 7zip/Archive/7z/7zEncode.cpp | 10 +- 7zip/Archive/7z/7zFolderInStream.cpp | 3 +- 7zip/Archive/7z/7zFolderOutStream.cpp | 3 +- 7zip/Archive/7z/7zHandler.cpp | 107 +- 7zip/Archive/7z/7zHandler.h | 21 +- 7zip/Archive/7z/7zHandlerOut.cpp | 98 +- 7zip/Archive/7z/7zIn.cpp | 93 +- 7zip/Archive/7z/7zIn.h | 6 +- 7zip/Archive/7z/7zMethodID.cpp | 16 +- 7zip/Archive/7z/7zMethods.cpp | 2 +- 7zip/Archive/7z/7zOut.cpp | 43 +- 7zip/Archive/7z/7zOut.h | 19 +- 7zip/Archive/7z/7zUpdate.cpp | 206 ++- 7zip/Archive/7z/7zUpdate.h | 20 +- 7zip/Archive/7z_C/7zExtract.c | 2 + 7zip/Archive/7z_C/7zIn.c | 76 +- 7zip/Archive/7z_C/7zMain.c | 165 ++- 7zip/Archive/7z_C/7zTypes.h | 40 +- 7zip/Archive/7z_C/7z_C.dsp | 8 +- 7zip/Archive/Arj/ArjHandler.cpp | 14 +- 7zip/Archive/Arj/ArjIn.cpp | 8 +- 7zip/Archive/Arj/DllExports.cpp | 2 +- 7zip/Archive/BZip2/BZip2Handler.cpp | 14 +- 7zip/Archive/BZip2/BZip2HandlerOut.cpp | 5 +- 7zip/Archive/Cab/CabHandler.cpp | 17 +- 7zip/Archive/Cab/CabIn.cpp | 6 +- 7zip/Archive/Chm/ChmHandler.cpp | 27 +- 7zip/Archive/Chm/ChmIn.cpp | 37 +- 7zip/Archive/Chm/ChmIn.h | 10 +- 7zip/Archive/Chm/DllExports.cpp | 2 +- 7zip/Archive/Common/CoderMixer2.h | 2 +- 7zip/Archive/Common/CoderMixer2MT.cpp | 12 +- 7zip/Archive/Common/CoderMixer2ST.h | 3 +- 7zip/Archive/Common/FilterCoder.cpp | 5 +- 7zip/Archive/Common/InStreamWithCRC.cpp | 10 +- 7zip/Archive/Common/InStreamWithCRC.h | 14 +- 7zip/Archive/Common/ItemNameUtils.cpp | 2 +- 7zip/Archive/Common/MultiStream.cpp | 4 +- 7zip/Archive/Common/OutStreamWithCRC.cpp | 7 +- 7zip/Archive/Common/OutStreamWithCRC.h | 12 +- 7zip/Archive/Deb/DebHandler.cpp | 14 +- 7zip/Archive/Deb/DebIn.cpp | 20 +- 7zip/Archive/Deb/DllExports.cpp | 4 +- 7zip/Archive/GZip/GZipHandler.cpp | 22 +- 7zip/Archive/GZip/GZipHandlerOut.cpp | 8 +- 7zip/Archive/GZip/GZipIn.cpp | 2 +- 7zip/Archive/GZip/GZipOut.cpp | 2 +- 7zip/Archive/GZip/GZipUpdate.cpp | 5 +- 7zip/Archive/Iso/DllExports.cpp | 2 +- 7zip/Archive/Iso/IsoHandler.cpp | 14 +- 7zip/Archive/Iso/IsoIn.cpp | 29 +- 7zip/Archive/Iso/IsoIn.h | 10 +- 7zip/Archive/Iso/IsoItem.h | 8 +- 7zip/Archive/Lzh/DllExports.cpp | 2 +- 7zip/Archive/Lzh/LzhCRC.cpp | 2 +- 7zip/Archive/Lzh/LzhCRC.h | 2 +- 7zip/Archive/Lzh/LzhHandler.cpp | 15 +- 7zip/Archive/Lzh/LzhIn.cpp | 6 +- 7zip/Archive/Lzh/LzhItem.h | 2 +- 7zip/Archive/Nsis/NsisHandler.cpp | 8 +- 7zip/Archive/Nsis/NsisIn.cpp | 29 +- 7zip/Archive/RPM/DllExports.cpp | 4 +- 7zip/Archive/RPM/RpmHandler.cpp | 12 +- 7zip/Archive/RPM/RpmIn.cpp | 2 +- 7zip/Archive/Rar/Rar.dsp | 30 +- 7zip/Archive/Rar/RarHandler.cpp | 15 +- 7zip/Archive/Rar/RarIn.cpp | 41 +- 7zip/Archive/Rar/RarItem.cpp | 54 +- 7zip/Archive/Rar/RarItem.h | 18 +- 7zip/Archive/Rar/makefile | 7 +- 7zip/Archive/Split/DllExports.cpp | 4 +- 7zip/Archive/Split/SplitHandler.cpp | 12 +- 7zip/Archive/Tar/DllExports.cpp | 2 +- 7zip/Archive/Tar/TarHandler.cpp | 13 +- 7zip/Archive/Tar/TarHeader.cpp | 1 + 7zip/Archive/Tar/TarHeader.h | 3 +- 7zip/Archive/Tar/TarIn.cpp | 24 +- 7zip/Archive/Tar/TarOut.cpp | 17 +- 7zip/Archive/Tar/TarUpdate.cpp | 6 +- 7zip/Archive/Z/DllExports.cpp | 6 +- 7zip/Archive/Z/ZHandler.cpp | 10 +- 7zip/Archive/Zip/DllExports.cpp | 8 + 7zip/Archive/Zip/Zip.dsp | 126 ++ 7zip/Archive/Zip/ZipAddCommon.cpp | 109 +- 7zip/Archive/Zip/ZipAddCommon.h | 12 +- 7zip/Archive/Zip/ZipCompressionMode.h | 10 +- 7zip/Archive/Zip/ZipHandler.cpp | 627 +++++---- 7zip/Archive/Zip/ZipHandler.h | 5 + 7zip/Archive/Zip/ZipHandlerOut.cpp | 62 +- 7zip/Archive/Zip/ZipHeader.h | 17 +- 7zip/Archive/Zip/ZipIn.cpp | 583 ++++++--- 7zip/Archive/Zip/ZipIn.h | 30 +- 7zip/Archive/Zip/ZipItem.cpp | 43 +- 7zip/Archive/Zip/ZipItem.h | 131 +- 7zip/Archive/Zip/ZipItemEx.h | 1 + 7zip/Archive/Zip/ZipOut.cpp | 96 +- 7zip/Archive/Zip/ZipOut.h | 9 +- 7zip/Archive/Zip/ZipUpdate.cpp | 669 +++++++--- 7zip/Archive/Zip/ZipUpdate.h | 1 + 7zip/Archive/Zip/makefile | 20 +- 7zip/Archive/cpio/CpioHandler.cpp | 14 +- 7zip/Archive/cpio/CpioIn.cpp | 2 +- 7zip/Archive/cpio/DllExports.cpp | 4 +- 7zip/Bundles/Alone/Alone.dsp | 101 +- 7zip/Bundles/Alone/makefile | 24 +- 7zip/Bundles/Alone7z/Alone.dsp | 1366 ++++++++++++++++++++ 7zip/Bundles/Alone7z/Alone.dsw | 29 + 7zip/Bundles/Format7z/Format7z.dsp | 22 +- 7zip/Bundles/Format7z/makefile | 9 +- 7zip/Bundles/Format7zExtract/Format7z.dsp | 22 +- 7zip/Bundles/Format7zExtract/makefile | 9 +- 7zip/Bundles/SFXCon/Main.cpp | 85 +- 7zip/Bundles/SFXCon/SFXCon.dsp | 28 +- 7zip/Bundles/SFXCon/makefile | 10 +- 7zip/Bundles/SFXSetup/ExtractCallback.cpp | 2 +- 7zip/Bundles/SFXSetup/Main.cpp | 42 +- 7zip/Bundles/SFXWin/Main.cpp | 6 +- 7zip/Bundles/SFXWin/SFXWin.dsp | 12 +- 7zip/Bundles/SFXWin/makefile | 9 +- 7zip/Bundles/makefile | 1 + 7zip/Common/InMemStream.cpp | 222 ++++ 7zip/Common/InMemStream.h | 282 ++++ 7zip/Common/InOutTempBuffer.cpp | 2 +- 7zip/Common/LSBFDecoder.h | 6 +- 7zip/Common/LimitedStreams.cpp | 22 +- 7zip/Common/LimitedStreams.h | 14 +- 7zip/Common/MSBFEncoder.h | 2 +- 7zip/Common/MemBlocks.cpp | 184 +++ 7zip/Common/MemBlocks.h | 73 ++ 7zip/Common/OutMemStream.cpp | 137 ++ 7zip/Common/OutMemStream.h | 88 ++ 7zip/Common/ProgressMt.cpp | 53 + 7zip/Common/ProgressMt.h | 47 + 7zip/Common/ProgressUtils.cpp | 3 - 7zip/Common/StreamObjects.cpp | 34 - 7zip/Common/StreamObjects.h | 49 +- 7zip/Compress/Arj/ArjDecoder1.cpp | 4 +- 7zip/Compress/Arj/ArjDecoder2.cpp | 6 +- 7zip/Compress/BWT/BlockSort.cpp | 7 +- 7zip/Compress/BWT/Mtf8.h | 2 +- 7zip/Compress/BZip2/BZip2Decoder.cpp | 10 +- 7zip/Compress/BZip2/BZip2Encoder.cpp | 28 +- 7zip/Compress/BZip2/DllExports.cpp | 2 +- 7zip/Compress/BZip2Original/BZip2Decoder.cpp | 2 +- 7zip/Compress/BZip2Original/BZip2Encoder.cpp | 2 +- 7zip/Compress/Branch/BranchARM.c | 8 +- 7zip/Compress/Branch/BranchARMThumb.c | 10 +- 7zip/Compress/Branch/BranchIA64.c | 6 +- 7zip/Compress/Branch/BranchPPC.c | 12 +- 7zip/Compress/Branch/BranchSPARC.c | 2 +- 7zip/Compress/Branch/BranchTypes.h | 10 + 7zip/Compress/Branch/BranchX86.c | 2 +- 7zip/Compress/Branch/DllExports.cpp | 4 +- 7zip/Compress/Branch/x86_2.cpp | 16 +- 7zip/Compress/ByteSwap/DllExports.cpp | 4 +- 7zip/Compress/Copy/CopyCoder.cpp | 4 +- 7zip/Compress/Copy/DllExports.cpp | 4 +- 7zip/Compress/Copy/StdAfx.h | 1 - 7zip/Compress/Deflate/DeflateDecoder.cpp | 4 +- 7zip/Compress/Deflate/DeflateEncoder.cpp | 26 +- 7zip/Compress/Deflate/DllExports.cpp | 4 +- 7zip/Compress/Implode/ImplodeDecoder.cpp | 4 +- 7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp | 2 +- 7zip/Compress/LZ/BinTree/BinTreeMain.h | 4 +- 7zip/Compress/LZ/LZInWindow.cpp | 2 +- 7zip/Compress/LZ/LZInWindow.h | 2 +- 7zip/Compress/LZ/MT/MT.cpp | 8 +- 7zip/Compress/LZMA/DllExports.cpp | 4 +- 7zip/Compress/LZMA/LZMADecoder.cpp | 5 +- 7zip/Compress/LZMA/LZMAEncoder.cpp | 27 +- 7zip/Compress/LZMA/LZMAEncoder.h | 2 +- 7zip/Compress/LZMA_Alone/LzmaAlone.cpp | 10 +- 7zip/Compress/LZMA_Alone/LzmaBench.cpp | 4 +- 7zip/Compress/LZMA_Alone/LzmaRam.cpp | 7 +- 7zip/Compress/LZMA_Alone/makefile | 16 +- 7zip/Compress/LZMA_C/LzmaTypes.h | 13 + 7zip/Compress/Lzh/LzhDecoder.cpp | 4 +- 7zip/Compress/Lzx/LzxDecoder.cpp | 12 +- 7zip/Compress/PPMD/DllExports.cpp | 2 +- 7zip/Compress/PPMD/PPMDContext.h | 55 +- 7zip/Compress/PPMD/PPMDDecode.h | 10 +- 7zip/Compress/PPMD/PPMDDecoder.cpp | 9 +- 7zip/Compress/PPMD/PPMDEncode.h | 8 +- 7zip/Compress/PPMD/PPMDEncoder.cpp | 4 +- 7zip/Compress/PPMD/PPMDSubAlloc.h | 19 +- 7zip/Compress/Quantum/QuantumDecoder.cpp | 3 +- 7zip/Compress/Quantum/QuantumDecoder.h | 8 +- 7zip/Compress/Rar20/Rar20Decoder.cpp | 2 +- 7zip/Compress/Rar29/DllExports.cpp | 4 +- 7zip/Compress/Rar29/makefile | 4 +- 7zip/Compress/Shrink/ShrinkDecoder.cpp | 4 +- 7zip/Compress/Z/ZDecoder.cpp | 4 +- 7zip/Crypto/7zAES/7zAES.cpp | 22 +- 7zip/Crypto/7zAES/7zAES.dsp | 16 +- 7zip/Crypto/7zAES/7zAES.h | 10 +- 7zip/Crypto/7zAES/DllExports.cpp | 2 +- 7zip/Crypto/7zAES/SHA256.cpp | 189 --- 7zip/Crypto/7zAES/SHA256.h | 30 - 7zip/Crypto/7zAES/makefile | 7 +- 7zip/Crypto/AES/DllExports.cpp | 12 +- 7zip/Crypto/AES/MyAES.cpp | 55 +- 7zip/Crypto/AES/MyAES.h | 49 +- 7zip/Crypto/AES/makefile | 2 +- 7zip/Crypto/Hash/HmacSha1.cpp | 109 ++ 7zip/Crypto/Hash/HmacSha1.h | 39 + 7zip/Crypto/Hash/Pbkdf2HmacSha1.cpp | 83 ++ 7zip/Crypto/Hash/Pbkdf2HmacSha1.h | 21 + 7zip/Crypto/Hash/RandGen.cpp | 78 ++ 7zip/Crypto/Hash/RandGen.h | 21 + 7zip/Crypto/Hash/RotateDefs.h | 19 + 7zip/Crypto/Hash/Sha1.cpp | 210 +++ 7zip/Crypto/Hash/Sha1.h | 68 + 7zip/Crypto/Hash/Sha256.cpp | 210 +++ 7zip/Crypto/Hash/Sha256.h | 30 + 7zip/Crypto/Hash/StdAfx.h | 8 + 7zip/Crypto/Rar20/Rar20Cipher.cpp | 2 +- 7zip/Crypto/RarAES/RarAES.cpp | 23 +- 7zip/Crypto/RarAES/RarAES.h | 3 + 7zip/Crypto/RarAES/sha1.cpp | 169 --- 7zip/Crypto/RarAES/sha1.h | 32 - 7zip/Crypto/WzAES/StdAfx.cpp | 3 + 7zip/Crypto/WzAES/StdAfx.h | 8 + 7zip/Crypto/WzAES/WzAES.cpp | 246 ++++ 7zip/Crypto/WzAES/WzAES.h | 126 ++ 7zip/Crypto/Zip/ZipCipher.cpp | 25 +- 7zip/Crypto/Zip/ZipCipher.h | 13 - 7zip/Crypto/Zip/ZipCrypto.cpp | 8 +- 7zip/FileManager/App.cpp | 16 +- 7zip/FileManager/ExtractCallback.cpp | 26 +- 7zip/FileManager/ExtractCallback.h | 2 +- 7zip/FileManager/FM.cpp | 19 +- 7zip/FileManager/FSDrives.cpp | 2 +- 7zip/FileManager/FSFolder.cpp | 18 +- 7zip/FileManager/FSFolderCopy.cpp | 22 +- 7zip/FileManager/LangUtils.cpp | 6 +- 7zip/FileManager/MyLoadMenu.cpp | 9 +- 7zip/FileManager/NetFolder.cpp | 6 +- 7zip/FileManager/OpenCallback.cpp | 8 +- 7zip/FileManager/OptionsDialog.cpp | 4 +- 7zip/FileManager/Panel.cpp | 27 +- 7zip/FileManager/Panel.h | 48 +- 7zip/FileManager/PanelCrc.cpp | 12 +- 7zip/FileManager/PanelDrag.cpp | 26 +- 7zip/FileManager/PanelFolderChange.cpp | 2 +- 7zip/FileManager/PanelItemOpen.cpp | 31 +- 7zip/FileManager/PanelItems.cpp | 7 +- 7zip/FileManager/PanelKey.cpp | 2 +- 7zip/FileManager/PanelListNotify.cpp | 16 +- 7zip/FileManager/PanelMenu.cpp | 4 +- 7zip/FileManager/PanelOperations.cpp | 2 +- 7zip/FileManager/PanelSort.cpp | 24 +- 7zip/FileManager/PanelSplitFile.cpp | 6 +- 7zip/FileManager/PhysDriveFolder.cpp | 34 +- 7zip/FileManager/RegistryUtils.cpp | 2 + .../Resource/BenchmarkDialog/BenchmarkDialog.cpp | 20 +- 7zip/FileManager/Resource/LangPage/LangPage.cpp | 6 +- .../Resource/ListViewDialog/ListViewDialog.cpp | 4 +- .../Resource/ProgressDialog/ProgressDialog.cpp | 2 +- .../Resource/ProgressDialog2/ProgressDialog.cpp | 6 +- .../FileManager/Resource/SystemPage/SystemPage.cpp | 4 +- 7zip/FileManager/RootFolder.cpp | 2 +- 7zip/FileManager/SplitUtils.cpp | 2 +- 7zip/FileManager/TextPairs.cpp | 2 +- 7zip/FileManager/UpdateCallback100.cpp | 6 +- 7zip/FileManager/ViewSettings.cpp | 8 +- 7zip/MyVersion.h | 10 +- 7zip/UI/Agent/Agent.cpp | 6 +- 7zip/UI/Agent/AgentOut.cpp | 8 +- 7zip/UI/Agent/AgentProxy.cpp | 4 +- 7zip/UI/Agent/ArchiveFolder.cpp | 4 +- 7zip/UI/Agent/ArchiveFolderOpen.cpp | 3 +- 7zip/UI/Agent/ArchiveFolderOut.cpp | 10 +- 7zip/UI/Agent/UpdateCallbackAgent.cpp | 2 +- 7zip/UI/Client7z/Client7z.cpp | 838 +++++++++++- 7zip/UI/Client7z/Client7z.dsp | 48 + 7zip/UI/Client7z/makefile | 45 + 7zip/UI/Common/ArchiveCommandLine.cpp | 72 +- 7zip/UI/Common/ArchiveCommandLine.h | 5 + 7zip/UI/Common/ArchiveExtractCallback.cpp | 178 ++- 7zip/UI/Common/ArchiveExtractCallback.h | 31 +- 7zip/UI/Common/ArchiveOpenCallback.cpp | 14 +- 7zip/UI/Common/ArchiverInfo.cpp | 2 +- 7zip/UI/Common/CompressCall.cpp | 23 +- 7zip/UI/Common/CompressCall.h | 1 + 7zip/UI/Common/EnumDirItems.cpp | 8 +- 7zip/UI/Common/Extract.cpp | 16 +- 7zip/UI/Common/Extract.h | 3 +- 7zip/UI/Common/IFileExtractCallback.h | 2 +- 7zip/UI/Common/OpenArchive.cpp | 10 +- 7zip/UI/Common/Update.cpp | 12 +- 7zip/UI/Common/Update.h | 3 + 7zip/UI/Common/UpdateCallback.cpp | 22 +- 7zip/UI/Common/UpdateProduce.cpp | 2 - 7zip/UI/Common/UpdateProduce.h | 2 - 7zip/UI/Common/ZipRegistry.cpp | 80 +- 7zip/UI/Common/ZipRegistry.h | 8 +- 7zip/UI/Console/ConsoleClose.cpp | 12 +- 7zip/UI/Console/ExtractCallbackConsole.cpp | 18 +- 7zip/UI/Console/ExtractCallbackConsole.h | 2 +- 7zip/UI/Console/List.cpp | 2 +- 7zip/UI/Console/Main.cpp | 14 +- 7zip/UI/Console/MainAr.cpp | 10 +- 7zip/UI/Console/OpenCallbackConsole.cpp | 4 +- 7zip/UI/Console/PercentPrinter.cpp | 7 +- 7zip/UI/Console/UpdateCallbackConsole.cpp | 12 +- 7zip/UI/Console/UserInputUtils.cpp | 3 +- 7zip/UI/Explorer/ContextMenu.cpp | 141 +- 7zip/UI/Explorer/ContextMenu.h | 9 +- 7zip/UI/Explorer/ContextMenuFlags.h | 14 +- 7zip/UI/Explorer/DllExports.cpp | 2 +- 7zip/UI/Explorer/Explorer.dsp | 4 + 7zip/UI/Explorer/MyMessages.cpp | 19 +- 7zip/UI/Explorer/MyMessages.h | 6 + 7zip/UI/Explorer/OptionsDialog.cpp | 6 +- 7zip/UI/Explorer/SystemPage/SystemPage.cpp | 24 +- 7zip/UI/Far/ExtractEngine.cpp | 18 +- 7zip/UI/Far/ExtractEngine.h | 2 +- 7zip/UI/Far/FarPlugin.h | 10 +- 7zip/UI/Far/FarUtils.cpp | 23 +- 7zip/UI/Far/Main.cpp | 6 +- 7zip/UI/Far/Plugin.cpp | 2 +- 7zip/UI/Far/PluginRead.cpp | 2 +- 7zip/UI/Far/PluginWrite.cpp | 2 +- 7zip/UI/GUI/CompressDialog.cpp | 168 ++- 7zip/UI/GUI/CompressDialog.h | 15 +- 7zip/UI/GUI/ExtractGUI.cpp | 2 +- 7zip/UI/GUI/GUI.cpp | 17 +- 7zip/UI/GUI/GUI.dsp | 4 + 7zip/UI/GUI/OpenCallbackGUI.cpp | 4 +- 7zip/UI/GUI/UpdateCallbackGUI.cpp | 10 +- 7zip/UI/GUI/UpdateGUI.cpp | 102 +- 7zip/UI/GUI/resource.h | 5 + 7zip/UI/GUI/resource.rc | 6 + 7zip/UI/Resource/CompressDialog/resource.h | 16 +- 7zip/UI/Resource/CompressDialog/resource.rc | 27 +- 7zip/UI/Resource/Extract/resource.h | 8 +- 7zip/UI/Resource/Extract/resource.rc | 4 +- 7zip/UI/makefile | 1 + Build.mak | 15 +- Common/Alloc.cpp | 15 + Common/CommandLineParser.cpp | 4 +- Common/CommandLineParser.h | 2 +- Common/IntToString.cpp | 4 +- Common/StdInStream.cpp | 10 +- Common/StdOutStream.cpp | 14 +- Common/StdOutStream.h | 2 +- Common/String.cpp | 18 +- Common/String.h | 8 +- Common/StringConvert.h | 6 +- Common/StringToInt.cpp | 6 +- Common/TextConfig.cpp | 9 +- Common/Types.h | 38 + Common/Vector.cpp | 11 +- Common/Vector.h | 13 +- DOC/7zC.txt | 4 +- DOC/7zFormat.txt | 4 +- DOC/7zip.nsi | 8 +- DOC/7zip.wxs | 6 +- DOC/Methods.txt | 3 +- DOC/lzma.txt | 2 +- DOC/lzma_format.txt | 28 - DOC/readme.txt | 2 +- Windows/CommonDialog.cpp | 8 +- Windows/Control/ComboBox.cpp | 2 +- Windows/Control/ComboBox.h | 16 +- Windows/Control/Dialog.cpp | 4 +- Windows/Control/Dialog.h | 9 +- Windows/Control/ProgressBar.h | 18 +- Windows/Control/PropertyPage.cpp | 12 +- Windows/Control/PropertyPage.h | 12 +- Windows/Control/ReBar.h | 14 +- Windows/Control/StatusBar.h | 6 +- Windows/Control/ToolBar.h | 8 +- Windows/Control/Window2.cpp | 4 +- Windows/Control/Window2.h | 6 +- Windows/DLL.h | 2 +- Windows/Defs.h | 3 + Windows/FileDevice.h | 6 +- Windows/FileDir.cpp | 37 +- Windows/FileDir.h | 2 + Windows/FileFind.cpp | 13 +- Windows/Memory.h | 2 +- Windows/PropVariantConversions.cpp | 55 +- Windows/Registry.cpp | 4 +- Windows/Security.cpp | 6 +- Windows/Security.h | 2 +- Windows/Shell.cpp | 4 +- Windows/Synchronization.h | 33 +- Windows/System.h | 2 +- Windows/Window.h | 20 +- 392 files changed, 9697 insertions(+), 3140 deletions(-) create mode 100755 7zip/Bundles/Alone7z/Alone.dsp create mode 100755 7zip/Bundles/Alone7z/Alone.dsw create mode 100755 7zip/Common/InMemStream.cpp create mode 100755 7zip/Common/InMemStream.h create mode 100755 7zip/Common/MemBlocks.cpp create mode 100755 7zip/Common/MemBlocks.h create mode 100755 7zip/Common/OutMemStream.cpp create mode 100755 7zip/Common/OutMemStream.h create mode 100755 7zip/Common/ProgressMt.cpp create mode 100755 7zip/Common/ProgressMt.h delete mode 100755 7zip/Crypto/7zAES/SHA256.cpp delete mode 100755 7zip/Crypto/7zAES/SHA256.h create mode 100755 7zip/Crypto/Hash/HmacSha1.cpp create mode 100755 7zip/Crypto/Hash/HmacSha1.h create mode 100755 7zip/Crypto/Hash/Pbkdf2HmacSha1.cpp create mode 100755 7zip/Crypto/Hash/Pbkdf2HmacSha1.h create mode 100755 7zip/Crypto/Hash/RandGen.cpp create mode 100755 7zip/Crypto/Hash/RandGen.h create mode 100755 7zip/Crypto/Hash/RotateDefs.h create mode 100755 7zip/Crypto/Hash/Sha1.cpp create mode 100755 7zip/Crypto/Hash/Sha1.h create mode 100755 7zip/Crypto/Hash/Sha256.cpp create mode 100755 7zip/Crypto/Hash/Sha256.h create mode 100755 7zip/Crypto/Hash/StdAfx.h delete mode 100755 7zip/Crypto/RarAES/sha1.cpp delete mode 100755 7zip/Crypto/RarAES/sha1.h create mode 100755 7zip/Crypto/WzAES/StdAfx.cpp create mode 100755 7zip/Crypto/WzAES/StdAfx.h create mode 100755 7zip/Crypto/WzAES/WzAES.cpp create mode 100755 7zip/Crypto/WzAES/WzAES.h create mode 100755 7zip/UI/Client7z/makefile delete mode 100755 DOC/lzma_format.txt diff --git a/7zip/Archive/7z/7zDecode.cpp b/7zip/Archive/7z/7zDecode.cpp index 7621282a..5c58f817 100755 --- a/7zip/Archive/7z/7zDecode.cpp +++ b/7zip/Archive/7z/7zDecode.cpp @@ -140,7 +140,7 @@ CDecoder::CDecoder(bool multiThread) multiThread = true; #endif _multiThread = multiThread; - _bindInfoExPrevIsDefinded = false; + _bindInfoExPrevIsDefined = false; #ifndef EXCLUDE_COM LoadMethodMap(); #endif @@ -176,7 +176,8 @@ HRESULT CDecoder::Decode(IInStream *inStream, CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream = streamSpec; - streamSpec->Init(lockedStreamImp, packSizes[j]); + streamSpec->SetStream(lockedStreamImp); + streamSpec->Init(packSizes[j]); inStreams.Add(inStream); } @@ -185,7 +186,7 @@ HRESULT CDecoder::Decode(IInStream *inStream, CBindInfoEx bindInfo; ConvertFolderItemInfoToBindInfo(folderInfo, bindInfo); bool createNewCoders; - if (!_bindInfoExPrevIsDefinded) + if (!_bindInfoExPrevIsDefined) createNewCoders = true; else createNewCoders = !AreBindInfoExEqual(bindInfo, _bindInfoExPrev); @@ -319,7 +320,7 @@ HRESULT CDecoder::Decode(IInStream *inStream, } } _bindInfoExPrev = bindInfo; - _bindInfoExPrevIsDefinded = true; + _bindInfoExPrevIsDefined = true; } int i; _mixerCoderCommon->ReInit(); @@ -336,7 +337,7 @@ HRESULT CDecoder::Decode(IInStream *inStream, { CMyComPtr setDecoderProperties; - HRESULT result = decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties); + decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties); if (setDecoderProperties) { const CByteBuffer &properties = altCoderInfo.Properties; @@ -365,7 +366,7 @@ HRESULT CDecoder::Decode(IInStream *inStream, #ifndef _NO_CRYPTO { CMyComPtr cryptoSetPassword; - HRESULT result = decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword); + decoder.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword); if (cryptoSetPassword) { if (getTextPassword == 0) diff --git a/7zip/Archive/7z/7zDecode.h b/7zip/Archive/7z/7zDecode.h index 0e510b5b..50f80d4c 100755 --- a/7zip/Archive/7z/7zDecode.h +++ b/7zip/Archive/7z/7zDecode.h @@ -36,7 +36,7 @@ class CDecoder CCoderLibraries _libraries; #endif - bool _bindInfoExPrevIsDefinded; + bool _bindInfoExPrevIsDefined; CBindInfoEx _bindInfoExPrev; bool _multiThread; diff --git a/7zip/Archive/7z/7zEncode.cpp b/7zip/Archive/7z/7zEncode.cpp index b246d2ac..a9fe2d0a 100755 --- a/7zip/Archive/7z/7zEncode.cpp +++ b/7zip/Archive/7z/7zEncode.cpp @@ -19,6 +19,7 @@ static NArchive::N7z::CMethodID k_Copy = { { 0x0 }, 1 }; #endif static NArchive::N7z::CMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 }; +static NArchive::N7z::CMethodID k_LZMA2 = { { 0x3, 0x1, 0x2 }, 3 }; #ifdef COMPRESS_LZMA #include "../../Compress/LZMA/LZMAEncoder.h" @@ -207,9 +208,9 @@ HRESULT CEncoder::CreateMixerCoder(const UInt64 *inSizeForReduce) bool tryReduce = false; UInt32 reducedDictionarySize = 1 << 10; - if (inSizeForReduce != 0 && methodFull.MethodID == k_LZMA) + if (inSizeForReduce != 0 && (methodFull.MethodID == k_LZMA || methodFull.MethodID == k_LZMA2)) { - while (true) + for (;;) { const UInt32 step = (reducedDictionarySize >> 1); if (reducedDictionarySize >= *inSizeForReduce) @@ -383,7 +384,8 @@ HRESULT CEncoder::Encode(ISequentialInStream *inStream, CMyComPtr outStreamSizeCount = outStreamSizeCountSpec; inStreamSizeCountSpec->Init(inStream); - outStreamSizeCountSpec->Init(outStream); + outStreamSizeCountSpec->SetStream(outStream); + outStreamSizeCountSpec->Init(); CRecordVector inStreamPointers; CRecordVector outStreamPointers; @@ -528,7 +530,7 @@ CEncoder::CEncoder(const CCompressionMethodMode &options): // Make main stream first in list int inIndex = _bindInfo.InStreams[0]; - while (true) + for (;;) { UInt32 coderIndex, coderStreamIndex; _bindInfo.FindInStream(inIndex, coderIndex, coderStreamIndex); diff --git a/7zip/Archive/7z/7zFolderInStream.cpp b/7zip/Archive/7z/7zFolderInStream.cpp index 1b3e2a06..fb1cfd3a 100755 --- a/7zip/Archive/7z/7zFolderInStream.cpp +++ b/7zip/Archive/7z/7zFolderInStream.cpp @@ -38,7 +38,8 @@ HRESULT CFolderInStream::OpenStream() if (result != S_OK && result != S_FALSE) return result; _fileIndex++; - _inStreamWithHashSpec->Init(stream); + _inStreamWithHashSpec->SetStream(stream); + _inStreamWithHashSpec->Init(); if (!stream) { RINOK(_updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); diff --git a/7zip/Archive/7z/7zFolderOutStream.cpp b/7zip/Archive/7z/7zFolderOutStream.cpp index bb770ccc..93bed3d9 100755 --- a/7zip/Archive/7z/7zFolderOutStream.cpp +++ b/7zip/Archive/7z/7zFolderOutStream.cpp @@ -48,7 +48,8 @@ HRESULT CFolderOutStream::OpenFile() UInt32 index = _startIndex + _currentIndex; RINOK(_extractCallback->GetStream(_ref2Offset + index, &realOutStream, askMode)); - _outStreamWithHashSpec->Init(realOutStream); + _outStreamWithHashSpec->SetStream(realOutStream); + _outStreamWithHashSpec->Init(); if (askMode == NArchive::NExtract::NAskMode::kExtract && (!realOutStream)) { diff --git a/7zip/Archive/7z/7zHandler.cpp b/7zip/Archive/7z/7zHandler.cpp index ac1e2405..3321fd71 100755 --- a/7zip/Archive/7z/7zHandler.cpp +++ b/7zip/Archive/7z/7zHandler.cpp @@ -40,7 +40,6 @@ CHandler::CHandler() STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) { - COM_TRY_BEGIN *numItems = #ifdef _7Z_VOL _refs.Size(); @@ -48,10 +47,9 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) *numItems = _database.Files.Size(); #endif return S_OK; - COM_TRY_END } -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -59,13 +57,13 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) #ifdef _SFX -STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 *numProperties) +STDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */) { return E_NOTIMPL; } -STDMETHODIMP CHandler::GetPropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_NOTIMPL; } @@ -79,8 +77,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_NOTIMPL; } @@ -93,26 +91,6 @@ static void MySetFileTime(bool timeDefined, FILETIME unixTime, propVariant = unixTime; } -/* -inline static wchar_t GetHex(Byte value) -{ - return (value < 10) ? ('0' + value) : ('A' + (value - 10)); -} - -static UString ConvertBytesToHexString(const Byte *data, UInt32 size) -{ - UString result; - for (UInt32 i = 0; i < size; i++) - { - Byte b = data[i]; - result += GetHex(b >> 4); - result += GetHex(b & 0xF); - } - return result; -} -*/ - - #ifndef _SFX static UString ConvertUInt32ToString(UInt32 value) @@ -151,28 +129,48 @@ static CMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 }; static CMethodID k_BCJ = { { 0x3, 0x3, 0x1, 0x3 }, 4 }; static CMethodID k_BCJ2 = { { 0x3, 0x3, 0x1, 0x1B }, 4 }; static CMethodID k_PPMD = { { 0x3, 0x4, 0x1 }, 3 }; -static CMethodID k_Deflate = { { 0x4, 0x1, 0x8 }, 3 }; +static CMethodID k_Deflate = { { 0x4, 0x1, 0x8 }, 3 }; +static CMethodID k_Deflate64 = { { 0x4, 0x1, 0x9 }, 3 }; static CMethodID k_BZip2 = { { 0x4, 0x2, 0x2 }, 3 }; -static inline char GetHex(Byte value) +static wchar_t GetHex(Byte value) { - return (value < 10) ? ('0' + value) : ('A' + (value - 10)); + return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10))); } static inline UString GetHex2(Byte value) { UString result; - result += GetHex(value >> 4); - result += GetHex(value & 0xF); + result += GetHex((Byte)(value >> 4)); + result += GetHex((Byte)(value & 0xF)); return result; } #endif +static CMethodID k_AES = { { 0x6, 0xF1, 0x7, 0x1}, 4 }; + static inline UInt32 GetUInt32FromMemLE(const Byte *p) { return p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24); } +bool CHandler::IsEncrypted(UInt32 index2) const +{ + CNum folderIndex = _database.FileIndexToFolderIndexMap[index2]; + if (folderIndex != kNumNoIndex) + { + const CFolder &folderInfo = _database.Folders[folderIndex]; + for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--) + { + const CCoderInfo &coderInfo = folderInfo.Coders[i]; + for (int j = 0; j < coderInfo.AltCoders.Size(); j++) + if (coderInfo.AltCoders[j].MethodID == k_AES) + return true; + } + } + return false; +} + STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN @@ -260,6 +258,11 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va if (item.IsFileCRCDefined) propVariant = item.FileCRC; break; + case kpidEncrypted: + { + propVariant = IsEncrypted(index2); + break; + } #ifndef _SFX case kpidMethod: { @@ -299,8 +302,12 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va methodName = L"PPMD"; else if (altCoderInfo.MethodID == k_Deflate) methodName = L"Deflate"; + else if (altCoderInfo.MethodID == k_Deflate64) + methodName = L"Deflate64"; else if (altCoderInfo.MethodID == k_BZip2) methodName = L"BZip2"; + else if (altCoderInfo.MethodID == k_AES) + methodName = L"7zAES"; else methodIsKnown = false; @@ -338,6 +345,32 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va methodsString += GetStringForSizeValue(dicSize); } } + else if (altCoderInfo.MethodID == k_AES) + { + if (altCoderInfo.Properties.GetCapacity() >= 1) + { + methodsString += L":"; + const Byte *data = (const Byte *)altCoderInfo.Properties; + Byte firstByte = *data++; + UInt32 numCyclesPower = firstByte & 0x3F; + methodsString += ConvertUInt32ToString(numCyclesPower); + /* + if ((firstByte & 0xC0) != 0) + { + methodsString += L":"; + return S_OK; + UInt32 saltSize = (firstByte >> 7) & 1; + UInt32 ivSize = (firstByte >> 6) & 1; + if (altCoderInfo.Properties.GetCapacity() >= 2) + { + Byte secondByte = *data++; + saltSize += (secondByte >> 4); + ivSize += (secondByte & 0x0F); + } + } + */ + } + } else { if (altCoderInfo.Properties.GetCapacity() > 0) @@ -345,7 +378,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va methodsString += L":["; for (size_t bi = 0; bi < altCoderInfo.Properties.GetCapacity(); bi++) { - if (bi > 2 && bi + 1 < altCoderInfo.Properties.GetCapacity()) + if (bi > 5 && bi + 1 < altCoderInfo.Properties.GetCapacity()) { methodsString += L".."; break; @@ -517,7 +550,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, { openArchiveCallbackTemp.QueryInterface(IID_IArchiveOpenVolumeCallback, &openVolumeCallback); } - while(true) + for (;;) { CMyComPtr inStream; if (!_volumes.IsEmpty()) @@ -724,8 +757,10 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream) STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) { COM_TRY_BEGIN + #ifdef COMPRESS_MT const UInt32 numProcessors = NSystem::GetNumberOfProcessors(); _numThreads = numProcessors; + #endif for (int i = 0; i < numProperties; i++) { @@ -740,7 +775,9 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v { if(name.Left(2).CompareNoCase(L"MT") == 0) { + #ifdef COMPRESS_MT RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads)); + #endif continue; } else diff --git a/7zip/Archive/7z/7zHandler.h b/7zip/Archive/7z/7zHandler.h index cf0e1f8a..8be9f398 100755 --- a/7zip/Archive/7z/7zHandler.h +++ b/7zip/Archive/7z/7zHandler.h @@ -85,6 +85,9 @@ class CHandler: public CMyUnknownImp { public: + #if !defined(_7Z_VOL) && !defined(__7Z_SET_PROPERTIES) && defined(EXTRACT_ONLY) + MY_UNKNOWN_IMP + #else MY_QUERYINTERFACE_BEGIN #ifdef _7Z_VOL MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream) @@ -97,6 +100,8 @@ public: #endif MY_QUERYINTERFACE_END MY_ADDREF_RELEASE + #endif + STDMETHOD(Open)(IInStream *stream, const UInt64 *maxCheckStartPosition, @@ -167,6 +172,11 @@ private: bool _compressHeadersFull; bool _encryptHeaders; + bool WriteModified; + bool WriteCreated; + bool WriteAccessed; + + bool _autoFilter; UInt32 _level; @@ -176,8 +186,7 @@ private: HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value); HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString); - HRESULT SetPassword(CCompressionMethodMode &methodMode, - IArchiveUpdateCallback *updateCallback); + HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback); HRESULT SetCompressionMethod(CCompressionMethodMode &method, CObjectVector &methodsInfo @@ -191,7 +200,8 @@ private: CCompressionMethodMode &headerMethod); #endif - + + bool IsEncrypted(UInt32 index2) const; #ifndef _SFX CRecordVector _fileInfoPopIDs; @@ -217,6 +227,11 @@ private: _compressHeaders = true; _compressHeadersFull = true; _encryptHeaders = false; + + WriteModified = true; + WriteCreated = false; + WriteAccessed = false; + #ifdef COMPRESS_MT _numThreads = NWindows::NSystem::GetNumberOfProcessors(); #endif diff --git a/7zip/Archive/7z/7zHandlerOut.cpp b/7zip/Archive/7z/7zHandlerOut.cpp index 302caa90..fdd336ea 100755 --- a/7zip/Archive/7z/7zHandlerOut.cpp +++ b/7zip/Archive/7z/7zHandlerOut.cpp @@ -24,6 +24,7 @@ namespace N7z { #ifdef COMPRESS_LZMA static CMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 }; +static CMethodID k_LZMA2 = { { 0x3, 0x1, 0x2 }, 3 }; #endif #ifdef COMPRESS_PPMD @@ -64,6 +65,7 @@ static CMethodID k_BZip2 = { { 0x4, 0x2, 0x2 }, 3 }; const wchar_t *kCopyMethod = L"Copy"; const wchar_t *kLZMAMethodName = L"LZMA"; +const wchar_t *kLZMA2MethodName = L"LZMA2"; const wchar_t *kBZip2MethodName = L"BZip2"; const wchar_t *kPpmdMethodName = L"PPMd"; const wchar_t *kDeflateMethodName = L"Deflate"; @@ -121,9 +123,16 @@ static bool IsCopyMethod(const UString &methodName) { return (methodName.CompareNoCase(kCopyMethod) == 0); } static bool IsLZMAMethod(const UString &methodName) - { return (methodName.CompareNoCase(kLZMAMethodName) == 0); } +{ + return + (methodName.CompareNoCase(kLZMAMethodName) == 0) || + (methodName.CompareNoCase(kLZMA2MethodName) == 0); +} + +/* static bool IsLZMethod(const UString &methodName) { return IsLZMAMethod(methodName); } +*/ static bool IsBZip2Method(const UString &methodName) { return (methodName.CompareNoCase(kBZip2MethodName) == 0); } @@ -157,7 +166,8 @@ HRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode, Int32 passwordIsDefined; RINOK(getTextPassword->CryptoGetTextPassword2( &passwordIsDefined, &password)); - if (methodMode.PasswordIsDefined = IntToBool(passwordIsDefined)) + methodMode.PasswordIsDefined = IntToBool(passwordIsDefined); + if (methodMode.PasswordIsDefined) methodMode.Password = password; } else @@ -532,6 +542,21 @@ HRESULT CHandler::SetCompressionMethod( return S_OK; } +static HRESULT GetTime(IArchiveUpdateCallback *updateCallback, int index, PROPID propID, CArchiveFileTime &filetime, bool &filetimeIsDefined) +{ + filetimeIsDefined = false; + NCOM::CPropVariant propVariant; + RINOK(updateCallback->GetProperty(index, propID, &propVariant)); + if (propVariant.vt == VT_FILETIME) + { + filetime = propVariant.filetime; + filetimeIsDefined = true; + } + else if (propVariant.vt != VT_EMPTY) + return E_INVALIDARG; + return S_OK; +} + STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) { @@ -583,8 +608,13 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt updateItem.IsDirectory = fileItem.IsDirectory; updateItem.Size = fileItem.UnPackSize; updateItem.IsAnti = fileItem.IsAnti; + + updateItem.CreationTime = fileItem.CreationTime; + updateItem.IsCreationTimeDefined = fileItem.IsCreationTimeDefined; updateItem.LastWriteTime = fileItem.LastWriteTime; - updateItem.LastWriteTimeIsDefined = fileItem.IsLastWriteTimeDefined; + updateItem.IsLastWriteTimeDefined = fileItem.IsLastWriteTimeDefined; + updateItem.LastAccessTime = fileItem.LastAccessTime; + updateItem.IsLastAccessTimeDefined = fileItem.IsLastAccessTimeDefined; } if (updateItem.NewProperties) @@ -604,32 +634,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt updateItem.AttributesAreDefined = true; } } - { - NCOM::CPropVariant propVariant; - RINOK(updateCallback->GetProperty(i, kpidCreationTime, &propVariant)); - if (propVariant.vt == VT_EMPTY) - updateItem.CreationTimeIsDefined = false; - else if (propVariant.vt != VT_FILETIME) - return E_INVALIDARG; - else - { - updateItem.CreationTime = propVariant.filetime; - updateItem.CreationTimeIsDefined = true; - } - } - { - NCOM::CPropVariant propVariant; - RINOK(updateCallback->GetProperty(i, kpidLastWriteTime, &propVariant)); - if (propVariant.vt == VT_EMPTY) - updateItem.LastWriteTimeIsDefined = false; - else if (propVariant.vt != VT_FILETIME) - return E_INVALIDARG; - else - { - updateItem.LastWriteTime = propVariant.filetime; - updateItem.LastWriteTimeIsDefined = true; - } - } + + RINOK(GetTime(updateCallback, i, kpidCreationTime, updateItem.CreationTime, updateItem.IsCreationTimeDefined)); + RINOK(GetTime(updateCallback, i, kpidLastWriteTime, updateItem.LastWriteTime , updateItem.IsLastWriteTimeDefined)); + RINOK(GetTime(updateCallback, i, kpidLastAccessTime, updateItem.LastAccessTime, updateItem.IsLastAccessTimeDefined)); + { NCOM::CPropVariant propVariant; RINOK(updateCallback->GetProperty(i, kpidPath, &propVariant)); @@ -671,8 +680,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt if (updateItem.IsAnti) { updateItem.AttributesAreDefined = false; - updateItem.CreationTimeIsDefined = false; - updateItem.LastWriteTimeIsDefined = false; + + updateItem.IsCreationTimeDefined = false; + updateItem.IsLastWriteTimeDefined = false; + updateItem.IsLastAccessTimeDefined = false; + updateItem.Size = 0; } @@ -728,8 +740,13 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt &headerMethod : 0; options.UseFilters = _level != 0 && _autoFilter; options.MaxFilter = _level >= 8; - options.UseAdditionalHeaderStreams = useAdditionalHeaderStreams; - options.CompressMainHeader = compressMainHeader; + + options.HeaderOptions.UseAdditionalHeaderStreams = useAdditionalHeaderStreams; + options.HeaderOptions.CompressMainHeader = compressMainHeader; + options.HeaderOptions.WriteModified = WriteModified; + options.HeaderOptions.WriteCreated = WriteCreated; + options.HeaderOptions.WriteAccessed = WriteAccessed; + options.NumSolidFiles = _numSolidFiles; options.NumSolidBytes = _numSolidBytes; options.SolidExtension = _solidExtension; @@ -1048,6 +1065,21 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v RINOK(SetBoolProperty(_encryptHeaders, value)); continue; } + else if (name.CompareNoCase(L"TM") == 0) + { + RINOK(SetBoolProperty(WriteModified, value)); + continue; + } + else if (name.CompareNoCase(L"TC") == 0) + { + RINOK(SetBoolProperty(WriteCreated, value)); + continue; + } + else if (name.CompareNoCase(L"TA") == 0) + { + RINOK(SetBoolProperty(WriteAccessed, value)); + continue; + } else if (name.CompareNoCase(L"V") == 0) { RINOK(SetBoolProperty(_volumeMode, value)); diff --git a/7zip/Archive/7z/7zIn.cpp b/7zip/Archive/7z/7zIn.cpp index cd7fea3a..53d78b1a 100755 --- a/7zip/Archive/7z/7zIn.cpp +++ b/7zip/Archive/7z/7zIn.cpp @@ -9,6 +9,9 @@ #include "../../Common/StreamUtils.h" #include "../../../Common/CRC.h" +// define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader +// #define FORMAT_7Z_RECOVERY + namespace NArchive { namespace N7z { @@ -214,16 +217,16 @@ HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *search UInt32 numPrevBytes = kSignatureSize - 1; memmove(buffer, signature + 1, numPrevBytes); UInt64 curTestPos = _arhiveBeginStreamPosition + 1; - while(true) + for (;;) { if (searchHeaderSizeLimit != NULL) if (curTestPos - _arhiveBeginStreamPosition > *searchHeaderSizeLimit) - return S_FALSE; + break; UInt32 numReadBytes = kBufferSize - numPrevBytes; RINOK(ReadDirect(stream, buffer + numPrevBytes, numReadBytes, &processedSize)); UInt32 numBytesInBuffer = numPrevBytes + processedSize; if (numBytesInBuffer < kSignatureSize) - return S_FALSE; + break; UInt32 numTests = numBytesInBuffer - kSignatureSize + 1; for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++) { @@ -237,6 +240,7 @@ HRESULT CInArchive::FindAndReadSignature(IInStream *stream, const UInt64 *search numPrevBytes = numBytesInBuffer - numTests; memmove(buffer, buffer + numTests, numPrevBytes); } + return S_FALSE; } // Out: _position must point to end of signature @@ -335,9 +339,9 @@ HRESULT CInArchive::SkeepData() return SkeepData(size); } -HRESULT CInArchive::ReadArchiveProperties(CInArchiveInfo &archiveInfo) +HRESULT CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */) { - while(true) + for (;;) { UInt64 type; RINOK(ReadID(type)); @@ -363,13 +367,13 @@ HRESULT CInArchive::GetNextFolderItem(CFolder &folder) folder.Coders.Add(CCoderInfo()); CCoderInfo &coder = folder.Coders.Back(); - while (true) + for (;;) { coder.AltCoders.Add(CAltCoderInfo()); CAltCoderInfo &altCoder = coder.AltCoders.Back(); - Byte mainByte; + Byte mainByte = 0; RINOK(ReadByte(mainByte)); - altCoder.MethodID.IDSize = mainByte & 0xF; + altCoder.MethodID.IDSize = (Byte)(mainByte & 0xF); RINOK(ReadBytes(altCoder.MethodID.ID, altCoder.MethodID.IDSize)); if ((mainByte & 0x10) != 0) { @@ -432,7 +436,7 @@ HRESULT CInArchive::GetNextFolderItem(CFolder &folder) HRESULT CInArchive::WaitAttribute(UInt64 attribute) { - while(true) + for (;;) { UInt64 type; RINOK(ReadID(type)); @@ -453,7 +457,7 @@ HRESULT CInArchive::ReadHashDigests(int numItems, digests.Reserve(numItems); for(int i = 0; i < numItems; i++) { - UInt32 crc; + UInt32 crc = 0; if (digestsDefined[i]) RINOK(ReadUInt32(crc)); digests.Add(crc); @@ -482,7 +486,7 @@ HRESULT CInArchive::ReadPackInfo( } UInt64 type; - while(true) + for (;;) { RINOK(ReadID(type)); if (type == NID::kEnd) @@ -545,7 +549,7 @@ HRESULT CInArchive::ReadUnPackInfo( } } - while(true) + for (;;) { UInt64 type; RINOK(ReadID(type)); @@ -578,7 +582,7 @@ HRESULT CInArchive::ReadSubStreamsInfo( numUnPackStreamsInFolders.Clear(); numUnPackStreamsInFolders.Reserve(folders.Size()); UInt64 type; - while(true) + for (;;) { RINOK(ReadID(type)); if (type == NID::kNumUnPackStream) @@ -638,7 +642,7 @@ HRESULT CInArchive::ReadSubStreamsInfo( numDigestsTotal += numSubstreams; } - while(true) + for (;;) { if (type == NID::kCRC) { @@ -697,7 +701,7 @@ HRESULT CInArchive::ReadStreamsInfo( CRecordVector &digestsDefined, CRecordVector &digests) { - while(true) + for (;;) { UInt64 type; RINOK(ReadID(type)); @@ -732,7 +736,7 @@ HRESULT CInArchive::ReadFileNames(CObjectVector &files) { UString &name = files[i].Name; name.Empty(); - while (true) + for (;;) { wchar_t c; RINOK(ReadWideCharLE(c)); @@ -748,7 +752,7 @@ HRESULT CInArchive::ReadBoolVector(int numItems, CBoolVector &v) { v.Clear(); v.Reserve(numItems); - Byte b; + Byte b = 0; Byte mask = 0; for(int i = 0; i < numItems; i++) { @@ -789,6 +793,8 @@ HRESULT CInArchive::ReadTime(const CObjectVector &dataVector, { CFileItem &file = files[i]; CArchiveFileTime fileTime; + fileTime.dwLowDateTime = 0; + fileTime.dwHighDateTime = 0; bool defined = boolVector[i]; if (defined) { @@ -989,7 +995,7 @@ HRESULT CInArchive::ReadHeader(CArchiveDatabaseEx &database // int sizePrev = -1; // int posPrev = 0; - while(true) + for (;;) { /* if (sizePrev >= 0) @@ -1025,7 +1031,8 @@ HRESULT CInArchive::ReadHeader(CArchiveDatabaseEx &database for(i = 0; i < numFiles; i++) { CFileItem &file = database.Files[i]; - if (file.AreAttributesDefined = boolVector[i]) + file.AreAttributesDefined = boolVector[i]; + if (file.AreAttributesDefined) { RINOK(ReadUInt32(file.Attributes)); } @@ -1041,7 +1048,8 @@ HRESULT CInArchive::ReadHeader(CArchiveDatabaseEx &database for(i = 0; i < numFiles; i++) { CFileItem &file = database.Files[i]; - if (file.IsStartPosDefined = boolVector[i]) + file.IsStartPosDefined = boolVector[i]; + if (file.IsStartPosDefined) { RINOK(ReadUInt64(file.StartPos)); } @@ -1162,7 +1170,7 @@ void CArchiveDatabaseEx::FillFolderStartFileIndex() { // v3.13 incorrectly worked with empty folders // v4.07: Loop for skipping empty folders - while(true) + for (;;) { if (folderIndex >= Folders.Size()) throw CInArchiveException(CInArchiveException::kIncorrectHeader); @@ -1208,19 +1216,52 @@ HRESULT CInArchive::ReadDatabase(CArchiveDatabaseEx &database #endif UInt32 crcFromArchive; - RINOK(SafeReadDirectUInt32(crcFromArchive)); - UInt64 nextHeaderOffset; UInt64 nextHeaderSize; UInt32 nextHeaderCRC; CCRC crc; + RINOK(SafeReadDirectUInt32(crcFromArchive)); RINOK(SafeReadDirectUInt64(nextHeaderOffset)); - crc.UpdateUInt64(nextHeaderOffset); RINOK(SafeReadDirectUInt64(nextHeaderSize)); - crc.UpdateUInt64(nextHeaderSize); RINOK(SafeReadDirectUInt32(nextHeaderCRC)); + + #ifdef FORMAT_7Z_RECOVERY + if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0) + { + UInt64 cur, cur2; + RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur)); + const int kCheckSize = 500; + Byte buf[kCheckSize]; + RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2)); + int checkSize = kCheckSize; + if (cur2 - cur < kCheckSize) + checkSize = (int)(cur2 - cur); + RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2)); + + UInt32 realProcessedSize; + RINOK(ReadDirect(buf, (UInt32)kCheckSize, &realProcessedSize)); + + int i; + for (i = (int)realProcessedSize - 2; i >= 0; i--) + if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04) + break; + if (i < 0) + return S_FALSE; + nextHeaderSize = realProcessedSize - i; + nextHeaderOffset = cur2 - cur + i; + nextHeaderCRC = CCRC::CalculateDigest(buf + i, (size_t)nextHeaderSize); + RINOK(_stream->Seek(cur, STREAM_SEEK_SET, &_position)); + } + #endif + + crc.UpdateUInt64(nextHeaderOffset); + crc.UpdateUInt64(nextHeaderSize); crc.UpdateUInt32(nextHeaderCRC); + #ifdef FORMAT_7Z_RECOVERY + crcFromArchive = crc.GetDigest(); + #endif + #ifdef _7Z_VOL UInt64 archiveStartOffset; // data offset from end if that struct UInt64 additionalStartBlockSize; // start signature & start header size @@ -1259,7 +1300,7 @@ HRESULT CInArchive::ReadDatabase(CArchiveDatabaseEx &database CObjectVector dataVector; - while (true) + for (;;) { UInt64 type; RINOK(ReadID(type)); diff --git a/7zip/Archive/7z/7zIn.h b/7zip/Archive/7z/7zIn.h index b2dcbf53..4f27aa75 100755 --- a/7zip/Archive/7z/7zIn.h +++ b/7zip/Archive/7z/7zIn.h @@ -201,13 +201,13 @@ private: HRESULT ReadWideCharLE(wchar_t &c) { - Byte b1; + Byte b1 = 0; if (!_inByteBack->ReadByte(b1)) return E_FAIL; - Byte b2; + Byte b2 = 0; if (!_inByteBack->ReadByte(b2)) return E_FAIL; - c = (wchar_t(b2) << 8) + b1; + c = (wchar_t)(((wchar_t)(b2) << 8) + b1); return S_OK; } diff --git a/7zip/Archive/7z/7zMethodID.cpp b/7zip/Archive/7z/7zMethodID.cpp index d5b78f05..0d45b732 100755 --- a/7zip/Archive/7z/7zMethodID.cpp +++ b/7zip/Archive/7z/7zMethodID.cpp @@ -9,17 +9,17 @@ namespace N7z { static wchar_t GetHex(Byte value) { - return (value < 10) ? ('0' + value) : ('A' + (value - 10)); + return (wchar_t)((value < 10) ? ('0' + value) : ('A' + (value - 10))); } static bool HexCharToInt(wchar_t value, Byte &result) { if (value >= '0' && value <= '9') - result = value - '0'; + result = (Byte)(value - '0'); else if (value >= 'a' && value <= 'f') - result = 10 + value - 'a'; + result = (Byte)(10 + value - 'a'); else if (value >= 'A' && value <= 'F') - result = 10 + value - 'A'; + result = (Byte)(10 + value - 'A'); else return false; return true; @@ -32,7 +32,7 @@ static bool TwoHexCharsToInt(wchar_t valueHigh, wchar_t valueLow, Byte &result) return false; if (!HexCharToInt(valueLow, resultLow)) return false; - result = (resultHigh << 4) + resultLow; + result = (Byte)((resultHigh << 4) + resultLow); return true; } @@ -42,8 +42,8 @@ UString CMethodID::ConvertToString() const for (int i = 0; i < IDSize; i++) { Byte b = ID[i]; - result += GetHex(b >> 4); - result += GetHex(b & 0xF); + result += GetHex((Byte)(b >> 4)); + result += GetHex((Byte)(b & 0xF)); } return result; } @@ -53,7 +53,7 @@ bool CMethodID::ConvertFromString(const UString &srcString) int length = srcString.Length(); if ((length & 1) != 0 || (length >> 1) > kMethodIDSize) return false; - IDSize = length / 2; + IDSize = (Byte)(length / 2); UInt32 i; for(i = 0; i < IDSize; i++) if (!TwoHexCharsToInt(srcString[i * 2], srcString[i * 2 + 1], ID[i])) diff --git a/7zip/Archive/7z/7zMethods.cpp b/7zip/Archive/7z/7zMethods.cpp index 56ed5b99..19270aa4 100755 --- a/7zip/Archive/7z/7zMethods.cpp +++ b/7zip/Archive/7z/7zMethods.cpp @@ -64,7 +64,7 @@ static void Load(const CSysString &folderPrefix) continue; if (propVariant.vt != VT_BSTR) continue; - info.MethodID.IDSize = SysStringByteLen(propVariant.bstrVal); + info.MethodID.IDSize = (Byte)SysStringByteLen(propVariant.bstrVal); memmove(info.MethodID.ID, propVariant.bstrVal, info.MethodID.IDSize); propVariant.Clear(); diff --git a/7zip/Archive/7z/7zOut.cpp b/7zip/Archive/7z/7zOut.cpp index b1ad2677..5a81a0d5 100755 --- a/7zip/Archive/7z/7zOut.cpp +++ b/7zip/Archive/7z/7zOut.cpp @@ -274,7 +274,7 @@ HRESULT COutArchive::WriteFolder(const CFolder &folder) size_t propertiesSize = altCoder.Properties.GetCapacity(); Byte b; - b = altCoder.MethodID.IDSize & 0xF; + b = (Byte)(altCoder.MethodID.IDSize & 0xF); bool isComplex = !coder.IsSimpleCoder(); b |= (isComplex ? 0x10 : 0); b |= ((propertiesSize != 0) ? 0x20 : 0 ); @@ -548,6 +548,8 @@ HRESULT COutArchive::WriteTime( { const CFileItem &item = files[i]; CArchiveFileTime timeValue; + timeValue.dwLowDateTime = 0; + timeValue.dwHighDateTime = 0; switch(type) { case NID::kCreationTime: @@ -608,7 +610,9 @@ static void WriteUInt64ToBuffer(Byte *data, UInt64 value) HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, - const CCompressionMethodMode *options, UInt64 &headerOffset) + const CCompressionMethodMode *options, + const CHeaderOptions &headerOptions, + UInt64 &headerOffset) { CObjectVector folders; @@ -628,7 +632,7 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, ////////////////////////// // Folders - CNum externalFoldersStreamIndex; + CNum externalFoldersStreamIndex = 0; bool externalFolders = (compressHeaders && database.Folders.Size() > 8); if (externalFolders) { @@ -675,7 +679,7 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, } CByteBuffer namesData; - CNum externalNamesStreamIndex; + CNum externalNamesStreamIndex = 0; bool externalNames = (compressHeaders && database.Files.Size() > 8); if (numDefinedNames > 0) { @@ -715,7 +719,7 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, } CByteBuffer attributesData; - CNum externalAttributesStreamIndex; + CNum externalAttributesStreamIndex = 0; bool externalAttributes = (compressHeaders && numDefinedAttributes > 8); if (numDefinedAttributes > 0) { @@ -751,7 +755,7 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, } CByteBuffer startsData; - CNum externalStartStreamIndex; + CNum externalStartStreamIndex = 0; bool externalStarts = (compressHeaders && numDefinedStarts > 8); if (numDefinedStarts > 0) { @@ -775,7 +779,7 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, ///////////////////////////////// // Write Last Write Time - CNum externalLastWriteTimeStreamIndex; + CNum externalLastWriteTimeStreamIndex = 0; bool externalLastWriteTime = false; // /* CNum numDefinedLastWriteTimes = 0; @@ -949,11 +953,20 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, } - RINOK(WriteTime(database.Files, NID::kCreationTime, false, 0)); - RINOK(WriteTime(database.Files, NID::kLastAccessTime, false, 0)); - RINOK(WriteTime(database.Files, NID::kLastWriteTime, + if (headerOptions.WriteCreated) + { + RINOK(WriteTime(database.Files, NID::kCreationTime, false, 0)); + } + if (headerOptions.WriteModified) + { + RINOK(WriteTime(database.Files, NID::kLastWriteTime, // false, 0)); externalLastWriteTime, externalLastWriteTimeStreamIndex)); + } + if (headerOptions.WriteAccessed) + { + RINOK(WriteTime(database.Files, NID::kLastAccessTime, false, 0)); + } if (numDefinedAttributes > 0) { @@ -1031,7 +1044,7 @@ HRESULT COutArchive::WriteHeader(const CArchiveDatabase &database, HRESULT COutArchive::WriteDatabase(const CArchiveDatabase &database, const CCompressionMethodMode *options, - bool useAdditionalStreams, bool compressMainHeader) + const CHeaderOptions &headerOptions) { UInt64 headerOffset; UInt32 headerCRC; @@ -1051,23 +1064,23 @@ HRESULT COutArchive::WriteDatabase(const CArchiveDatabase &database, if (options->IsEmpty()) options = 0; const CCompressionMethodMode *additionalStreamsOptions = options; - if (!useAdditionalStreams) + if (!headerOptions.UseAdditionalHeaderStreams) additionalStreamsOptions = 0; /* if (database.Files.Size() < 2) compressMainHeader = false; */ if (options != 0) - if (options->PasswordIsDefined || compressMainHeader) + if (options->PasswordIsDefined || headerOptions.CompressMainHeader) _dynamicMode = true; - RINOK(WriteHeader(database, additionalStreamsOptions, headerOffset)); + RINOK(WriteHeader(database, additionalStreamsOptions, headerOptions, headerOffset)); if (_dynamicMode) { CCompressionMethodMode encryptOptions; encryptOptions.PasswordIsDefined = options->PasswordIsDefined; encryptOptions.Password = options->Password; - CEncoder encoder(compressMainHeader ? *options : encryptOptions); + CEncoder encoder(headerOptions.CompressMainHeader ? *options : encryptOptions); CRecordVector packSizes; CObjectVector folders; RINOK(EncodeStream(encoder, _dynamicBuffer, diff --git a/7zip/Archive/7z/7zOut.h b/7zip/Archive/7z/7zOut.h index ede61381..cccc813a 100755 --- a/7zip/Archive/7z/7zOut.h +++ b/7zip/Archive/7z/7zOut.h @@ -60,6 +60,21 @@ public: size_t GetSize() const { return _pos; } }; +struct CHeaderOptions +{ + bool UseAdditionalHeaderStreams; + bool CompressMainHeader; + bool WriteModified; + bool WriteCreated; + bool WriteAccessed; + + CHeaderOptions(): + UseAdditionalHeaderStreams(false), + CompressMainHeader(true), + WriteModified(true), + WriteCreated(false), + WriteAccessed(false) {} +}; class COutArchive { @@ -127,6 +142,7 @@ class COutArchive CRecordVector &packSizes, CObjectVector &folders); HRESULT WriteHeader(const CArchiveDatabase &database, const CCompressionMethodMode *options, + const CHeaderOptions &headerOptions, UInt64 &headerOffset); bool _mainMode; @@ -162,8 +178,7 @@ public: HRESULT SkeepPrefixArchiveHeader(); HRESULT WriteDatabase(const CArchiveDatabase &database, const CCompressionMethodMode *options, - bool useAdditionalHeaderStreams, - bool compressMainHeader); + const CHeaderOptions &headerOptions); #ifdef _7Z_VOL static UInt32 GetVolHeadersSize(UInt64 dataSize, int nameLength = 0, bool props = false); diff --git a/7zip/Archive/7z/7zUpdate.cpp b/7zip/Archive/7z/7zUpdate.cpp index b75219a3..0b4866d8 100755 --- a/7zip/Archive/7z/7zUpdate.cpp +++ b/7zip/Archive/7z/7zUpdate.cpp @@ -43,7 +43,8 @@ static HRESULT WriteRange( CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStreamLimited(streamSpec); - streamSpec->Init(inStream, size); + streamSpec->SetStream(inStream); + streamSpec->Init(size); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr localProgress = localProgressSpec; @@ -195,49 +196,125 @@ static int CompareEmptyItems(const int *p1, const int *p2, void *param) const CUpdateItem &u1 = updateItems[*p1]; const CUpdateItem &u2 = updateItems[*p2]; if (u1.IsDirectory != u2.IsDirectory) - { - if (u1.IsDirectory) - return u1.IsAnti ? 1: -1; - return u2.IsAnti ? -1: 1; - } + return (u1.IsDirectory) ? 1 : -1; if (u1.IsDirectory) { if (u1.IsAnti != u2.IsAnti) return (u1.IsAnti ? 1 : -1); int n = MyStringCompareNoCase(u1.Name, u2.Name); - return (u1.IsAnti ? (-n) : n); + return -n; } if (u1.IsAnti != u2.IsAnti) return (u1.IsAnti ? 1 : -1); return MyStringCompareNoCase(u1.Name, u2.Name); } +static const char *g_Exts = + " lzma 7z ace arc arj bz bz2 deb lzo lzx gz pak rpm sit tgz tbz tbz2 tgz cab ha lha lzh rar zoo" + " zip jar ear war msi" + " 3gp avi mov mpeg mpg mpe wmv" + " aac ape fla flac la mp3 m4a mp4 ofr ogg pac ra rm rka shn swa tta wv wma wav" + " swf " + " chm hxi hxs" + " gif jpeg jpg jp2 png tiff bmp ico psd psp" + " awg ps eps cgm dxf svg vrml wmf emf ai md" + " cad dwg pps key sxi" + " max 3ds" + " iso bin nrg mdf img pdi tar cpio xpi" + " vfd vhd vud vmc vsv" + " vmdk dsk nvram vmem vmsd vmsn vmss vmtm" + " inl inc idl acf asa h hpp hxx c cpp cxx rc java cs pas bas vb cls ctl frm dlg def" + " f77 f f90 f95" + " asm sql manifest dep " + " mak clw csproj vcproj sln dsp dsw " + " class " + " bat cmd" + " xml xsd xsl xslt hxk hxc htm html xhtml xht mht mhtml htw asp aspx css cgi jsp shtml" + " awk sed hta js php php3 php4 php5 phptml pl pm py pyo rb sh tcl vbs" + " text txt tex ans asc srt reg ini doc docx mcw dot rtf hlp xls xlr xlt xlw ppt pdf" + " sxc sxd sxi sxg sxw stc sti stw stm odt ott odg otg odp otp ods ots odf" + " abw afp cwk lwp wpd wps wpt wrf wri" + " abf afm bdf fon mgf otf pcf pfa snf ttf" + " dbf mdb nsf ntf wdb db fdb gdb" + " exe dll ocx vbx sfx sys tlb awx com obj lib out o so " + " pdb pch idb ncb opt"; + +int GetExtIndex(const char *ext) +{ + int extIndex = 1; + const char *p = g_Exts; + for (;;) + { + char c = *p++; + if (c == 0) + return extIndex; + if (c == ' ') + continue; + int pos = 0; + for (;;) + { + char c2 = ext[pos++]; + if (c2 == 0 && (c == 0 || c == ' ')) + return extIndex; + if (c != c2) + break; + c = *p++; + } + extIndex++; + for (;;) + { + if (c == 0) + return extIndex; + if (c == ' ') + break; + c = *p++; + } + } +} + struct CRefItem { UInt32 Index; const CUpdateItem *UpdateItem; UInt32 ExtensionPos; UInt32 NamePos; - bool SortByType; + int ExtensionIndex; CRefItem(UInt32 index, const CUpdateItem &updateItem, bool sortByType): - SortByType(sortByType), Index(index), UpdateItem(&updateItem), ExtensionPos(0), - NamePos(0) + NamePos(0), + ExtensionIndex(0) { if (sortByType) { int slashPos = GetReverseSlashPos(updateItem.Name); - if (slashPos >= 0) - NamePos = slashPos + 1; - else - NamePos = 0; + NamePos = ((slashPos >= 0) ? (slashPos + 1) : 0); int dotPos = updateItem.Name.ReverseFind(L'.'); if (dotPos < 0 || (dotPos < slashPos && slashPos >= 0)) ExtensionPos = updateItem.Name.Length(); else + { ExtensionPos = dotPos + 1; + UString us = updateItem.Name.Mid(ExtensionPos); + if (!us.IsEmpty()) + { + us.MakeLower(); + int i; + AString s; + for (i = 0; i < us.Length(); i++) + { + wchar_t c = us[i]; + if (c >= 0x80) + break; + s += (char)c; + } + if (i == us.Length()) + ExtensionIndex = GetExtIndex(s); + else + ExtensionIndex = 0; + } + } } } }; @@ -250,23 +327,21 @@ static int CompareUpdateItems(const CRefItem *p1, const CRefItem *p2, void *para const CUpdateItem &u2 = *a2.UpdateItem; int n; if (u1.IsDirectory != u2.IsDirectory) - { - if (u1.IsDirectory) - return u1.IsAnti ? 1: -1; - return u2.IsAnti ? -1: 1; - } + return (u1.IsDirectory) ? 1 : -1; if (u1.IsDirectory) { if (u1.IsAnti != u2.IsAnti) return (u1.IsAnti ? 1 : -1); n = MyStringCompareNoCase(u1.Name, u2.Name); - return (u1.IsAnti ? (-n) : n); + return -n; } - if (a1.SortByType) + bool sortByType = *(bool *)param; + if (sortByType) { + RINOZ(MyCompare(a1.ExtensionIndex, a2.ExtensionIndex)) RINOZ(MyStringCompareNoCase(u1.Name + a1.ExtensionPos, u2.Name + a2.ExtensionPos)); RINOZ(MyStringCompareNoCase(u1.Name + a1.NamePos, u2.Name + a2.NamePos)); - if (u1.LastWriteTimeIsDefined && u2.LastWriteTimeIsDefined) + if (u1.IsLastWriteTimeDefined && u2.IsLastWriteTimeDefined) RINOZ(CompareFileTime(&u1.LastWriteTime, &u2.LastWriteTime)); RINOZ(MyCompare(u1.Size, u2.Size)) } @@ -448,11 +523,12 @@ static void FromUpdateItemToFileItem(const CUpdateItem &updateItem, if (updateItem.AttributesAreDefined) file.SetAttributes(updateItem.Attributes); - // if (updateItem.CreationTimeIsDefined) - // file.SetCreationTime(updateItem.ItemInfo.CreationTime); - - if (updateItem.LastWriteTimeIsDefined) + if (updateItem.IsCreationTimeDefined) + file.SetCreationTime(updateItem.CreationTime); + if (updateItem.IsLastWriteTimeDefined) file.SetLastWriteTime(updateItem.LastWriteTime); + if (updateItem.IsLastAccessTimeDefined) + file.SetLastAccessTime(updateItem.LastAccessTime); file.UnPackSize = updateItem.Size; file.IsDirectory = updateItem.IsDirectory; @@ -485,7 +561,8 @@ static HRESULT Update2( CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr limitedStream(streamSpec); RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL)); - streamSpec->Init(inStream, startBlockSize); + streamSpec->SetStream(inStream); + streamSpec->Init(startBlockSize); RINOK(CopyBlock(limitedStream, seqOutStream, NULL)); } @@ -534,36 +611,6 @@ static HRESULT Update2( CArchiveDatabase newDatabase; - ///////////////////////////////////////// - // Write Empty Files & Folders - - CRecordVector emptyRefs; - for(i = 0; i < updateItems.Size(); i++) - { - const CUpdateItem &updateItem = updateItems[i]; - if (updateItem.NewData) - { - if (updateItem.HasStream()) - continue; - } - else - if (updateItem.IndexInArchive != -1) - if (database->Files[updateItem.IndexInArchive].HasStream) - continue; - emptyRefs.Add(i); - } - emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems); - for(i = 0; i < emptyRefs.Size(); i++) - { - const CUpdateItem &updateItem = updateItems[emptyRefs[i]]; - CFileItem file; - if (updateItem.NewProperties) - FromUpdateItemToFileItem(updateItem, file); - else - file = database->Files[updateItem.IndexInArchive]; - newDatabase.Files.Add(file); - } - //////////////////////////// COutArchive archive; @@ -664,10 +711,10 @@ static HRESULT Update2( continue; CRecordVector refItems; refItems.Reserve(numFiles); + bool sortByType = (numSolidFiles > 1); for (i = 0; i < numFiles; i++) - refItems.Add(CRefItem(group.Indices[i], - updateItems[group.Indices[i]], numSolidFiles > 1)); - refItems.Sort(CompareUpdateItems, 0); + refItems.Add(CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType)); + refItems.Sort(CompareUpdateItems, (void *)&sortByType); CRecordVector indices; indices.Reserve(numFiles); @@ -780,15 +827,49 @@ static HRESULT Update2( i += numSubFiles; } } + + { + ///////////////////////////////////////// + // Write Empty Files & Folders + + CRecordVector emptyRefs; + for(i = 0; i < updateItems.Size(); i++) + { + const CUpdateItem &updateItem = updateItems[i]; + if (updateItem.NewData) + { + if (updateItem.HasStream()) + continue; + } + else + if (updateItem.IndexInArchive != -1) + if (database->Files[updateItem.IndexInArchive].HasStream) + continue; + emptyRefs.Add(i); + } + emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems); + for(i = 0; i < emptyRefs.Size(); i++) + { + const CUpdateItem &updateItem = updateItems[emptyRefs[i]]; + CFileItem file; + if (updateItem.NewProperties) + FromUpdateItemToFileItem(updateItem, file); + else + file = database->Files[updateItem.IndexInArchive]; + newDatabase.Files.Add(file); + } + } + /* if (newDatabase.Files.Size() != updateItems.Size()) return E_FAIL; */ - return archive.WriteDatabase(newDatabase, options.HeaderMethod, - options.UseAdditionalHeaderStreams, options.CompressMainHeader); + return archive.WriteDatabase(newDatabase, options.HeaderMethod, options.HeaderOptions); } +#ifdef _7Z_VOL + static HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CUpdateOptions &options) { CAltCoderInfo altCoder; @@ -831,7 +912,6 @@ static HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CU false); } -#ifdef _7Z_VOL HRESULT UpdateVolume( IInStream *inStream, const CArchiveDatabaseEx *database, diff --git a/7zip/Archive/7z/7zUpdate.h b/7zip/Archive/7z/7zUpdate.h index 7567864a..385bd942 100755 --- a/7zip/Archive/7z/7zUpdate.h +++ b/7zip/Archive/7z/7zUpdate.h @@ -4,6 +4,7 @@ #define __7Z_UPDATE_H #include "7zIn.h" +#include "7zOut.h" #include "7zCompressionMode.h" #include "../IArchive.h" @@ -21,6 +22,7 @@ struct CUpdateItem UInt32 Attributes; FILETIME CreationTime; FILETIME LastWriteTime; + FILETIME LastAccessTime; UInt64 Size; UString Name; @@ -28,13 +30,20 @@ struct CUpdateItem bool IsAnti; bool IsDirectory; - bool CreationTimeIsDefined; - bool LastWriteTimeIsDefined; + bool IsCreationTimeDefined; + bool IsLastWriteTimeDefined; + bool IsLastAccessTimeDefined; bool AttributesAreDefined; const bool HasStream() const { return !IsDirectory && !IsAnti && Size != 0; } - CUpdateItem(): IsAnti(false) {} + CUpdateItem(): + IsAnti(false), + AttributesAreDefined(false), + IsCreationTimeDefined(false), + IsLastWriteTimeDefined(false), + IsLastAccessTimeDefined(false) + {} void SetDirectoryStatusFromAttributes() { IsDirectory = ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0); }; @@ -48,8 +57,9 @@ struct CUpdateOptions const CCompressionMethodMode *HeaderMethod; bool UseFilters; bool MaxFilter; - bool UseAdditionalHeaderStreams; - bool CompressMainHeader; + + CHeaderOptions HeaderOptions; + UInt64 NumSolidFiles; UInt64 NumSolidBytes; bool SolidExtension; diff --git a/7zip/Archive/7z_C/7zExtract.c b/7zip/Archive/7z_C/7zExtract.c index 6ef872c3..aa75659b 100755 --- a/7zip/Archive/7z_C/7zExtract.c +++ b/7zip/Archive/7z_C/7zExtract.c @@ -38,6 +38,8 @@ SZ_RESULT SzExtract( Byte *inBuffer = 0; size_t processedSize; #endif + if (unPackSize != (size_t)unPackSize) + return SZE_OUTOFMEMORY; *blockIndex = folderIndex; allocMain->Free(*outBuffer); *outBuffer = 0; diff --git a/7zip/Archive/7z_C/7zIn.c b/7zip/Archive/7z_C/7zIn.c index 2eea5717..0b9d9bd7 100755 --- a/7zip/Archive/7z_C/7zIn.c +++ b/7zip/Archive/7z_C/7zIn.c @@ -44,18 +44,8 @@ CFileSize GetFilePackSize(int fileIndex) const } */ - -SZ_RESULT MySzInAlloc(void **p, size_t size, void * (*allocFunc)(size_t size)) -{ - if (size == 0) - *p = 0; - else - { - *p = allocFunc(size); - RINOM(*p); - } - return SZ_OK; -} +#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \ + if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; } SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size)) { @@ -64,14 +54,14 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size)) UInt32 i; UInt32 folderIndex = 0; UInt32 indexInFolder = 0; - RINOK(MySzInAlloc((void **)&db->FolderStartPackStreamIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc)); + MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc); for(i = 0; i < db->Database.NumFolders; i++) { db->FolderStartPackStreamIndex[i] = startPos; startPos += db->Database.Folders[i].NumPackStreams; } - RINOK(MySzInAlloc((void **)&db->PackStreamStartPositions, db->Database.NumPackStreams * sizeof(CFileSize), allocFunc)); + MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc); for(i = 0; i < db->Database.NumPackStreams; i++) { @@ -79,8 +69,8 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size)) startPosSize += db->Database.PackSizes[i]; } - RINOK(MySzInAlloc((void **)&db->FolderStartFileIndex, db->Database.NumFolders * sizeof(UInt32), allocFunc)); - RINOK(MySzInAlloc((void **)&db->FileIndexToFolderIndexMap, db->Database.NumFiles * sizeof(UInt32), allocFunc)); + MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc); + MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc); for (i = 0; i < db->Database.NumFiles; i++) { @@ -97,7 +87,7 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size)) v3.13 incorrectly worked with empty folders v4.07: Loop for skipping empty folders */ - while(1) + for (;;) { if (folderIndex >= db->Database.NumFolders) return SZE_ARCHIVE_ERROR; @@ -237,7 +227,7 @@ SZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value) { Byte b; RINOK(SafeReadDirectByte(inStream, &b)); - *value |= ((UInt32)b << (8 * i)); + *value |= ((UInt64)b << (8 * i)); } return SZ_OK; } @@ -355,7 +345,7 @@ SZ_RESULT SzSkeepData(CSzData *sd) SZ_RESULT SzReadArchiveProperties(CSzData *sd) { - while(1) + for (;;) { UInt64 type; RINOK(SzReadID(sd, &type)); @@ -368,7 +358,7 @@ SZ_RESULT SzReadArchiveProperties(CSzData *sd) SZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute) { - while(1) + for (;;) { UInt64 type; RINOK(SzReadID(sd, &type)); @@ -385,8 +375,8 @@ SZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allo Byte b = 0; Byte mask = 0; size_t i; - RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc)); - for(i = 0; i < numItems; i++) + MY_ALLOC(Byte, *v, numItems, allocFunc); + for (i = 0; i < numItems; i++) { if (mask == 0) { @@ -406,7 +396,7 @@ SZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*all RINOK(SzReadByte(sd, &allAreDefined)); if (allAreDefined == 0) return SzReadBoolVector(sd, numItems, v, allocFunc); - RINOK(MySzInAlloc((void **)v, numItems * sizeof(Byte), allocFunc)); + MY_ALLOC(Byte, *v, numItems, allocFunc); for(i = 0; i < numItems; i++) (*v)[i] = 1; return SZ_OK; @@ -421,7 +411,7 @@ SZ_RESULT SzReadHashDigests( { size_t i; RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc)); - RINOK(MySzInAlloc((void **)digests, numItems * sizeof(UInt32), allocFunc)); + MY_ALLOC(UInt32, *digests, numItems, allocFunc); for(i = 0; i < numItems; i++) if ((*digestsDefined)[i]) { @@ -445,14 +435,14 @@ SZ_RESULT SzReadPackInfo( RINOK(SzWaitAttribute(sd, k7zIdSize)); - RINOK(MySzInAlloc((void **)packSizes, (size_t)*numPackStreams * sizeof(CFileSize), allocFunc)); + MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc); for(i = 0; i < *numPackStreams; i++) { RINOK(SzReadSize(sd, (*packSizes) + i)); } - while(1) + for (;;) { UInt64 type; RINOK(SzReadID(sd, &type)); @@ -467,8 +457,8 @@ SZ_RESULT SzReadPackInfo( } if (*packCRCsDefined == 0) { - RINOK(MySzInAlloc((void **)packCRCsDefined, (size_t)*numPackStreams * sizeof(Byte), allocFunc)); - RINOK(MySzInAlloc((void **)packCRCs, (size_t)*numPackStreams * sizeof(UInt32), allocFunc)); + MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc); + MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc); for(i = 0; i < *numPackStreams; i++) { (*packCRCsDefined)[i] = 0; @@ -496,7 +486,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)( RINOK(SzReadNumber32(sd, &numCoders)); folder->NumCoders = numCoders; - RINOK(MySzInAlloc((void **)&folder->Coders, (size_t)numCoders * sizeof(CCoderInfo), allocFunc)); + MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc); for (i = 0; i < numCoders; i++) SzCoderInfoInit(folder->Coders + i); @@ -553,7 +543,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)( folder->NumBindPairs = numBindPairs; - RINOK(MySzInAlloc((void **)&folder->BindPairs, (size_t)numBindPairs * sizeof(CBindPair), allocFunc)); + MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc); for (i = 0; i < numBindPairs; i++) { @@ -565,7 +555,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)( numPackedStreams = numInStreams - (UInt32)numBindPairs; folder->NumPackStreams = numPackedStreams; - RINOK(MySzInAlloc((void **)&folder->PackStreams, (size_t)numPackedStreams * sizeof(UInt32), allocFunc)); + MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc); if (numPackedStreams == 1) { @@ -599,8 +589,7 @@ SZ_RESULT SzReadUnPackInfo( { RINOK(SzReadSwitch(sd)); - - RINOK(MySzInAlloc((void **)folders, (size_t)*numFolders * sizeof(CFolder), allocFunc)); + MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc); for(i = 0; i < *numFolders; i++) SzFolderInit((*folders) + i); @@ -619,7 +608,7 @@ SZ_RESULT SzReadUnPackInfo( CFolder *folder = (*folders) + i; UInt32 numOutStreams = SzFolderGetNumOutStreams(folder); - RINOK(MySzInAlloc((void **)&folder->UnPackSizes, (size_t)numOutStreams * sizeof(CFileSize), allocFunc)); + MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc); for(j = 0; j < numOutStreams; j++) { @@ -627,7 +616,7 @@ SZ_RESULT SzReadUnPackInfo( } } - while(1) + for (;;) { UInt64 type; RINOK(SzReadID(sd, &type)); @@ -676,7 +665,7 @@ SZ_RESULT SzReadSubStreamsInfo( folders[i].NumUnPackStreams = 1; *numUnPackStreams = numFolders; - while(1) + for (;;) { RINOK(SzReadID(sd, &type)); if (type == k7zIdNumUnPackStream) @@ -756,7 +745,7 @@ SZ_RESULT SzReadSubStreamsInfo( si = 0; - while(1) + for (;;) { if (type == k7zIdCRC) { @@ -814,7 +803,7 @@ SZ_RESULT SzReadStreamsInfo( void * (*allocFunc)(size_t size), ISzAlloc *allocTemp) { - while(1) + for (;;) { UInt64 type; RINOK(SzReadID(sd, &type)); @@ -887,7 +876,7 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, len += numAdds; } - RINOK(MySzInAlloc((void **)&file->Name, (size_t)len * sizeof(char), allocFunc)); + MY_ALLOC(char, file->Name, (size_t)len, allocFunc); len = 0; while(2 <= sd->Size) @@ -973,13 +962,13 @@ SZ_RESULT SzReadHeader2( RINOK(SzReadNumber32(sd, &numFiles)); db->Database.NumFiles = numFiles; - RINOK(MySzInAlloc((void **)&files, (size_t)numFiles * sizeof(CFileItem), allocMain->Alloc)); + MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc); db->Database.Files = files; for(i = 0; i < numFiles; i++) SzFileInit(files + i); - while(1) + for (;;) { UInt64 type; UInt64 size; @@ -1122,7 +1111,7 @@ SZ_RESULT SzReadAndDecodePackedStreams2( for (i = 0; i < db->NumPackStreams; i++) packSize += db->PackSizes[i]; - RINOK(MySzInAlloc((void **)inBuffer, (size_t)packSize, allocTemp->Alloc)); + MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc); RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize)); #endif @@ -1238,9 +1227,10 @@ SZ_RESULT SzArchiveOpen2( res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize); if (res == SZ_OK) { + res = SZE_ARCHIVE_ERROR; if (CrcVerifyDigest(nextHeaderCRC, buffer.Items, (UInt32)nextHeaderSize)) { - while (1) + for (;;) { UInt64 type; sd.Data = buffer.Items; diff --git a/7zip/Archive/7z_C/7zMain.c b/7zip/Archive/7z_C/7zMain.c index d5c5ed91..10900c54 100755 --- a/7zip/Archive/7z_C/7zMain.c +++ b/7zip/Archive/7z_C/7zMain.c @@ -1,21 +1,122 @@ /* 7zMain.c Test application for 7z Decoder -LZMA SDK 4.26 Copyright (c) 1999-2005 Igor Pavlov (2005-08-02) +LZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04) */ #include #include #include +#ifdef _WIN32 +#define USE_WINDOWS_FUNCTIONS +#endif + +#ifdef USE_WINDOWS_FUNCTIONS +#include +#endif + #include "7zCrc.h" #include "7zIn.h" #include "7zExtract.h" + +#ifdef USE_WINDOWS_FUNCTIONS +typedef HANDLE MY_FILE_HANDLE; +#else +typedef FILE *MY_FILE_HANDLE; +#endif + +void ConvertNumberToString(CFileSize value, char *s) +{ + char temp[32]; + int pos = 0; + do + { + temp[pos++] = (char)('0' + (int)(value % 10)); + value /= 10; + } + while (value != 0); + do + *s++ = temp[--pos]; + while(pos > 0); + *s = '\0'; +} + + +#ifdef USE_WINDOWS_FUNCTIONS +// ReadFile and WriteFile functions in Windows have BUG: +// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) +// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES +// (Insufficient system resources exist to complete the requested service). +#define kChunkSizeMax (1 << 24) +#endif + +size_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size) +{ + if (size == 0) + return 0; + #ifdef USE_WINDOWS_FUNCTIONS + { + size_t processedSize = 0; + do + { + DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size; + DWORD processedLoc = 0; + BOOL res = ReadFile(file, data, curSize, &processedLoc, NULL); + data = (void *)((unsigned char *)data + processedLoc); + size -= processedLoc; + processedSize += processedLoc; + if (!res || processedLoc == 0) + break; + } + while (size > 0); + return processedSize; + } + #else + return fread(data, 1, size, file); + #endif +} + +size_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size) +{ + if (size == 0) + return 0; + #ifdef USE_WINDOWS_FUNCTIONS + { + size_t processedSize = 0; + do + { + DWORD curSize = (size > kChunkSizeMax) ? kChunkSizeMax : (DWORD)size; + DWORD processedLoc = 0; + BOOL res = WriteFile(file, data, curSize, &processedLoc, NULL); + data = (void *)((unsigned char *)data + processedLoc); + size -= processedLoc; + processedSize += processedLoc; + if (!res) + break; + } + while (size > 0); + return processedSize; + } + #else + return fwrite(data, 1, size, file); + #endif +} + +int MyCloseFile(MY_FILE_HANDLE file) +{ + #ifdef USE_WINDOWS_FUNCTIONS + return (CloseHandle(file) != FALSE) ? 0 : 1; + #else + return fclose(file); + #endif +} + typedef struct _CFileInStream { ISzInStream InStream; - FILE *File; + MY_FILE_HANDLE File; } CFileInStream; #ifdef _LZMA_IN_CB @@ -29,7 +130,7 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz size_t processedSizeLoc; if (maxRequiredSize > kBufferSize) maxRequiredSize = kBufferSize; - processedSizeLoc = fread(g_Buffer, 1, maxRequiredSize, s->File); + processedSizeLoc = MyReadFile(s->File, g_Buffer, maxRequiredSize); *buffer = g_Buffer; if (processedSize != 0) *processedSize = processedSizeLoc; @@ -41,7 +142,7 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize) { CFileInStream *s = (CFileInStream *)object; - size_t processedSizeLoc = fread(buffer, 1, size, s->File); + size_t processedSizeLoc = MyReadFile(s->File, buffer, size); if (processedSize != 0) *processedSize = processedSizeLoc; return SZ_OK; @@ -52,10 +153,24 @@ SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *process SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) { CFileInStream *s = (CFileInStream *)object; + + #ifdef USE_WINDOWS_FUNCTIONS + { + LARGE_INTEGER value; + value.LowPart = (DWORD)pos; + value.HighPart = (LONG)(pos >> 32); + value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN); + if (value.LowPart == 0xFFFFFFFF) + if(GetLastError() != NO_ERROR) + return SZE_FAIL; + return SZ_OK; + } + #else int res = fseek(s->File, (long)pos, SEEK_SET); if (res == 0) return SZ_OK; return SZE_FAIL; + #endif } void PrintError(char *sz) @@ -71,7 +186,7 @@ int main(int numargs, char *args[]) ISzAlloc allocImp; ISzAlloc allocTempImp; - printf("\n7z ANSI-C Decoder 4.30 Copyright (c) 1999-2005 Igor Pavlov 2005-11-20\n"); + printf("\n7z ANSI-C Decoder 4.44 Copyright (c) 1999-2006 Igor Pavlov 2006-08-27\n"); if (numargs == 1) { printf( @@ -88,8 +203,15 @@ int main(int numargs, char *args[]) return 1; } + archiveStream.File = + #ifdef USE_WINDOWS_FUNCTIONS + CreateFile(args[2], GENERIC_READ, FILE_SHARE_READ, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (archiveStream.File == INVALID_HANDLE_VALUE) + #else archiveStream.File = fopen(args[2], "rb"); if (archiveStream.File == 0) + #endif { PrintError("can not open input file"); return 1; @@ -126,18 +248,22 @@ int main(int numargs, char *args[]) for (i = 0; i < db.Database.NumFiles; i++) { CFileItem *f = db.Database.Files + i; - printf("%10d %s\n", (int)f->Size, f->Name); + char s[32]; + ConvertNumberToString(f->Size, s); + printf("%10s %s\n", s, f->Name); } } else if (testCommand || extractCommand) { UInt32 i; - // if you need cache, use these 3 variables. - // if you use external function, you can make these variable as static. - UInt32 blockIndex = 0xFFFFFFFF; // it can have any value before first call (if outBuffer = 0) - Byte *outBuffer = 0; // it must be 0 before first call for each new archive. - size_t outBufferSize = 0; // it can have any value before first call (if outBuffer = 0) + /* + if you need cache, use these 3 variables. + if you use external function, you can make these variable as static. + */ + UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ + Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ + size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ printf("\n"); for (i = 0; i < db.Database.NumFiles; i++) @@ -165,7 +291,7 @@ int main(int numargs, char *args[]) break; if (!testCommand) { - FILE *outputHandle; + MY_FILE_HANDLE outputHandle; UInt32 processedSize; char *fileName = f->Name; size_t nameLen = strlen(f->Name); @@ -176,21 +302,28 @@ int main(int numargs, char *args[]) break; } - outputHandle = fopen(fileName, "wb+"); + outputHandle = + #ifdef USE_WINDOWS_FUNCTIONS + CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ, + NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (outputHandle == INVALID_HANDLE_VALUE) + #else + fopen(fileName, "wb+"); if (outputHandle == 0) + #endif { PrintError("can not open output file"); res = SZE_FAIL; break; } - processedSize = fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle); + processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed); if (processedSize != outSizeProcessed) { PrintError("can not write output file"); res = SZE_FAIL; break; } - if (fclose(outputHandle)) + if (MyCloseFile(outputHandle)) { PrintError("can not close output file"); res = SZE_FAIL; @@ -209,7 +342,7 @@ int main(int numargs, char *args[]) } SzArDbExFree(&db, allocImp.Free); - fclose(archiveStream.File); + MyCloseFile(archiveStream.File); if (res == SZ_OK) { printf("\nEverything is Ok\n"); diff --git a/7zip/Archive/7z_C/7zTypes.h b/7zip/Archive/7z_C/7zTypes.h index fdef1458..60dd68c3 100755 --- a/7zip/Archive/7z_C/7zTypes.h +++ b/7zip/Archive/7z_C/7zTypes.h @@ -3,32 +3,38 @@ #ifndef __COMMON_TYPES_H #define __COMMON_TYPES_H -#ifndef UInt32 -#ifdef _LZMA_UINT32_IS_ULONG -#define UInt32 unsigned long -#else -#define UInt32 unsigned int -#endif -#endif +#ifndef _7ZIP_BYTE_DEFINED +#define _7ZIP_BYTE_DEFINED +typedef unsigned char Byte; +#endif -#ifndef Byte -#define Byte unsigned char -#endif +#ifndef _7ZIP_UINT16_DEFINED +#define _7ZIP_UINT16_DEFINED +typedef unsigned short UInt16; +#endif -#ifndef UInt16 -#define UInt16 unsigned short +#ifndef _7ZIP_UINT32_DEFINED +#define _7ZIP_UINT32_DEFINED +#ifdef _LZMA_UINT32_IS_ULONG +typedef unsigned long UInt32; +#else +typedef unsigned int UInt32; #endif +#endif /* #define _SZ_NO_INT_64 */ /* define it your compiler doesn't support long long int */ +#ifndef _7ZIP_UINT64_DEFINED +#define _7ZIP_UINT64_DEFINED #ifdef _SZ_NO_INT_64 -#define UInt64 unsigned long +typedef unsigned long UInt64; #else #ifdef _MSC_VER -#define UInt64 unsigned __int64 +typedef unsigned __int64 UInt64; #else -#define UInt64 unsigned long long int +typedef unsigned long long int UInt64; +#endif #endif #endif @@ -38,9 +44,9 @@ #ifndef CFileSize #ifdef _SZ_FILE_SIZE_64 -#define CFileSize UInt64 +typedef UInt64 CFileSize; #else -#define CFileSize UInt32 +typedef UInt32 CFileSize; #endif #endif diff --git a/7zip/Archive/7z_C/7z_C.dsp b/7zip/Archive/7z_C/7z_C.dsp index 1e871520..6129fa86 100755 --- a/7zip/Archive/7z_C/7z_C.dsp +++ b/7zip/Archive/7z_C/7z_C.dsp @@ -42,7 +42,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /c +# ADD CPP /nologo /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /D "_SZ_FILE_SIZE_64" /YX /FD /c # ADD BASE RSC /l 0x419 /d "NDEBUG" # ADD RSC /l 0x419 /d "NDEBUG" BSC32=bscmake.exe @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /GZ /c +# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /D "_SZ_FILE_SIZE_64" /YX /FD /GZ /c # ADD BASE RSC /l 0x419 /d "_DEBUG" # ADD RSC /l 0x419 /d "_DEBUG" BSC32=bscmake.exe @@ -93,6 +93,10 @@ SOURCE=..\..\Compress\LZMA_C\LzmaDecode.c SOURCE=..\..\Compress\LZMA_C\LzmaDecode.h # End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZMA_C\LzmaTypes.h +# End Source File # End Group # Begin Source File diff --git a/7zip/Archive/Arj/ArjHandler.cpp b/7zip/Archive/Arj/ArjHandler.cpp index b3edb02d..a61cc775 100755 --- a/7zip/Archive/Arj/ArjHandler.cpp +++ b/7zip/Archive/Arj/ArjHandler.cpp @@ -87,7 +87,7 @@ STATPROPSTG kProperties[] = CHandler::CHandler() {} -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -117,8 +117,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_NOTIMPL; } @@ -225,7 +225,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream, UInt64 numFiles = _items.Size(); RINOK(callback->SetCompleted(&numFiles, NULL)); } - while(true) + for (;;) { CItemEx itemInfo; bool filled; @@ -328,7 +328,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, { COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC; CMyComPtr outStream(outStreamSpec); - outStreamSpec->Init(realOutStream); + outStreamSpec->SetStream(realOutStream); + outStreamSpec->Init(); realOutStream.Release(); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; @@ -337,7 +338,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, UInt64 pos; _stream->Seek(itemInfo.DataPosition, STREAM_SEEK_SET, &pos); - streamSpec->Init(_stream, itemInfo.PackSize); + streamSpec->SetStream(_stream); + streamSpec->Init(itemInfo.PackSize); CLocalProgress *localProgressSpec = new CLocalProgress; diff --git a/7zip/Archive/Arj/ArjIn.cpp b/7zip/Archive/Arj/ArjIn.cpp index 03346824..5d03ea65 100755 --- a/7zip/Archive/Arj/ArjIn.cpp +++ b/7zip/Archive/Arj/ArjIn.cpp @@ -25,7 +25,7 @@ HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize) static inline UInt16 GetUInt16FromMemLE(const Byte *p) { - return p[0] | (((UInt32)p[1]) << 8); + return (UInt16)(p[0] | (((UInt16)p[1]) << 8)); } static inline UInt32 GetUInt32FromMemLE(const Byte *p) @@ -79,7 +79,7 @@ bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit) UInt32 numBytesPrev = processedSize - 1; memmove(buffer, buffer + 1, numBytesPrev); UInt64 curTestPos = _streamStartPosition + 1; - while(true) + for (;;) { if (searchHeaderSizeLimit != NULL) if (curTestPos - _streamStartPosition > *searchHeaderSizeLimit) @@ -192,7 +192,7 @@ bool CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit) return false; if (!ReadBlock2()) return false; - while(true) + for (;;) if (!ReadBlock()) break; return true; @@ -270,7 +270,7 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item) for (; _blockPos < _blockSize;) item.Name += (char)ReadByte(); - while(true) + for (;;) if (!ReadBlock()) break; diff --git a/7zip/Archive/Arj/DllExports.cpp b/7zip/Archive/Arj/DllExports.cpp index 202fbe0d..31fbc495 100755 --- a/7zip/Archive/Arj/DllExports.cpp +++ b/7zip/Archive/Arj/DllExports.cpp @@ -13,7 +13,7 @@ DEFINE_GUID(CLSID_CArjHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x04, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { return TRUE; } diff --git a/7zip/Archive/BZip2/BZip2Handler.cpp b/7zip/Archive/BZip2/BZip2Handler.cpp index a2b5a797..e1065f4f 100755 --- a/7zip/Archive/BZip2/BZip2Handler.cpp +++ b/7zip/Archive/BZip2/BZip2Handler.cpp @@ -38,7 +38,7 @@ STATPROPSTG kProperties[] = { NULL, kpidPackedSize, VT_UI8}, }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -68,8 +68,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } @@ -101,8 +101,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va } STDMETHODIMP CHandler::Open(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback) + const UInt64 * /* maxCheckStartPosition */, + IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN try @@ -219,10 +219,10 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(_stream->Seek(_streamStartPosition, STREAM_SEEK_SET, NULL)); - HRESULT result; + HRESULT result = S_OK; bool firstItem = true; - while(true) + for (;;) { localCompressProgressSpec->Init(progress, ¤tTotalPacked, diff --git a/7zip/Archive/BZip2/BZip2HandlerOut.cpp b/7zip/Archive/BZip2/BZip2HandlerOut.cpp index f1eb43e0..b5fc72a9 100755 --- a/7zip/Archive/BZip2/BZip2HandlerOut.cpp +++ b/7zip/Archive/BZip2/BZip2HandlerOut.cpp @@ -33,8 +33,7 @@ STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type) return S_OK; } -static HRESULT CopyStreams(ISequentialInStream *inStream, - ISequentialOutStream *outStream, IArchiveUpdateCallback *updateCallback) +static HRESULT CopyStreams(ISequentialInStream *inStream, ISequentialOutStream *outStream) { CMyComPtr copyCoder = new NCompress::CCopyCoder; return copyCoder->Code(inStream, outStream, NULL, NULL, NULL); @@ -101,7 +100,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt if (indexInArchive != 0) return E_INVALIDARG; RINOK(_stream->Seek(_streamStartPosition, STREAM_SEEK_SET, NULL)); - return CopyStreams(_stream, outStream, updateCallback); + return CopyStreams(_stream, outStream); } STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) diff --git a/7zip/Archive/Cab/CabHandler.cpp b/7zip/Archive/Cab/CabHandler.cpp index 83edaee5..cac79b11 100755 --- a/7zip/Archive/Cab/CabHandler.cpp +++ b/7zip/Archive/Cab/CabHandler.cpp @@ -68,7 +68,7 @@ static const wchar_t *kMethods[] = static const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]); static const wchar_t *kUnknownMethod = L"Unknown"; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -101,8 +101,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } @@ -153,7 +153,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va case kpidMethod: { - UInt16 realFolderIndex = item.GetFolderIndex(db.Folders.Size()); + UInt32 realFolderIndex = item.GetFolderIndex(db.Folders.Size()); const CFolder &folder = db.Folders[realFolderIndex]; int methodIndex = folder.GetCompressionMethod(); UString method = (methodIndex < kNumMethods) ? kMethods[methodIndex] : kUnknownMethod; @@ -223,7 +223,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream, { COM_TRY_BEGIN Close(); - HRESULT res; + HRESULT res = S_FALSE; CInArchive archive; CMyComPtr openVolumeCallback; { @@ -269,7 +269,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream, RINOK(openArchiveCallback->SetCompleted(&numItems, NULL)); nextStream = 0; - while(true) + for (;;) { const COtherArchive *otherArchive = 0; if (!prevChecked) @@ -511,7 +511,7 @@ HRESULT CCabFolderOutStream::FlushCorrupted() Byte buffer[kBufferSize]; for (int i = 0; i < kBufferSize; i++) buffer[i] = 0; - while(true) + for (;;) { UInt64 remain = GetRemain(); if (remain == 0) @@ -548,7 +548,6 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, return S_OK; bool testMode = (_aTestMode != 0); UInt64 totalUnPacked = 0; - int lastIndex = 0; UInt32 i; int lastFolder = -2; @@ -806,10 +805,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) { - COM_TRY_BEGIN *numItems = m_Database.Items.Size(); return S_OK; - COM_TRY_END } }} diff --git a/7zip/Archive/Cab/CabIn.cpp b/7zip/Archive/Cab/CabIn.cpp index 1d47502c..447c1f42 100755 --- a/7zip/Archive/Cab/CabIn.cpp +++ b/7zip/Archive/Cab/CabIn.cpp @@ -12,6 +12,7 @@ namespace NArchive{ namespace NCab{ +/* static HRESULT ReadBytes(IInStream *inStream, void *data, UInt32 size) { UInt32 realProcessedSize; @@ -37,6 +38,7 @@ static void SafeInByteRead(::CInBuffer &inBuffer, void *data, UInt32 size) if(realProcessedSize != size) throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive); } +*/ Byte CInArchive::ReadByte() { @@ -71,7 +73,7 @@ UInt32 CInArchive::ReadUInt32() AString CInArchive::SafeReadName() { AString name; - while(true) + for (;;) { Byte b = ReadByte(); if (b == 0) @@ -107,7 +109,7 @@ HRESULT CInArchive::Open2(IInStream *inStream, UInt64 value = 0; const int kSignatureSize = 8; UInt64 kSignature64 = NHeader::NArchive::kSignature; - while(true) + for (;;) { Byte b; if (!inBuffer.ReadByte(b)) diff --git a/7zip/Archive/Chm/ChmHandler.cpp b/7zip/Archive/Chm/ChmHandler.cpp index 6baf35c6..6b37c73e 100755 --- a/7zip/Archive/Chm/ChmHandler.cpp +++ b/7zip/Archive/Chm/ChmHandler.cpp @@ -57,7 +57,7 @@ STATPROPSTG kProperties[] = static const int kNumProperties = sizeof(kProperties) / sizeof(kProperties[0]); -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -90,8 +90,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } @@ -146,7 +146,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va if (item.Section == 0) propVariant = L"Copy"; else if (item.Section < m_Database.Sections.Size()) - propVariant = m_Database.Sections[(size_t)item.Section].GetMethodName(); + propVariant = m_Database.Sections[(int)item.Section].GetMethodName(); break; } case kpidBlock: @@ -486,7 +486,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, } RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL)); - streamSpec->Init(m_Stream, item.Size); + streamSpec->SetStream(m_Stream); + streamSpec->Init(item.Size); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr progress = localProgressSpec; @@ -519,7 +520,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, currentTotalSize += item.Size; continue; } - const CSectionInfo §ion = m_Database.Sections[(size_t)item.Section]; + const CSectionInfo §ion = m_Database.Sections[(int)item.Section]; if (section.IsLzx()) { const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo; @@ -581,7 +582,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, if (!testMode && item.Size != 0) { RINOK(m_Stream->Seek(m_Database.ContentOffset + item.Offset, STREAM_SEEK_SET, NULL)); - streamSpec->Init(m_Stream, item.Size); + streamSpec->SetStream(m_Stream); + streamSpec->Init(item.Size); if(!copyCoder) copyCoder = new NCompress::CCopyCoder; RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, compressProgress)); @@ -592,7 +594,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, continue; } - const CSectionInfo §ion = m_Database.Sections[(size_t)sectionIndex]; + const CSectionInfo §ion = m_Database.Sections[(int)sectionIndex]; if (!section.IsLzx()) { @@ -631,7 +633,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, extractStatuses.Clear(); extractStatuses.Add(true); - for (;true; folderIndex++) + for (;; folderIndex++) { RINOK(extractCallback->SetCompleted(¤tTotalSize)); @@ -695,9 +697,10 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, UInt64 rem = finishPos - chmFolderOutStream->m_PosInSection; if (rem > rt.BlockSize) rem = rt.BlockSize; - const UInt64 *offsets = (const UInt64 *)&rt.ResetOffsets.Front(); + // const UInt64 *offsets = (const UInt64 *)&rt.ResetOffsets.Front(); RINOK(m_Stream->Seek(compressedPos + offset, STREAM_SEEK_SET, NULL)); - streamSpec->Init(m_Stream, compressedSize); + streamSpec->SetStream(m_Stream); + streamSpec->Init(compressedSize); lzxDecoderSpec->SetKeepHistory(b > 0, (int)((offset - startOffset) & 1)); RINOK(lzxDecoder->Code(inStream, outStream, NULL, &rem, NULL)); } @@ -718,13 +721,11 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) { - COM_TRY_BEGIN *numItems = m_Database.NewFormat ? 1: (m_Database.LowLevel ? m_Database.Items.Size(): m_Database.Indices.Size()); return S_OK; - COM_TRY_END } }} diff --git a/7zip/Archive/Chm/ChmIn.cpp b/7zip/Archive/Chm/ChmIn.cpp index 79e934ad..8c56ec91 100755 --- a/7zip/Archive/Chm/ChmIn.cpp +++ b/7zip/Archive/Chm/ChmIn.cpp @@ -38,7 +38,7 @@ static bool AreGuidsEqual(REFGUID g1, REFGUID g2) static char GetHex(Byte value) { - return (value < 10) ? ('0' + value) : ('A' + (value - 10)); + return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10))); } static void PrintByte(Byte b, AString &s) @@ -248,7 +248,8 @@ HRESULT CInArchive::ReadChunk(IInStream *inStream, UInt64 pos, UInt64 size) RINOK(inStream->Seek(pos, STREAM_SEEK_SET, NULL)); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr limitedStream(streamSpec); - streamSpec->Init(inStream, size); + streamSpec->SetStream(inStream); + streamSpec->Init(size); _inBuffer.SetStream(limitedStream); _inBuffer.Init(); return S_OK; @@ -276,12 +277,12 @@ HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database) UInt32 unknown1 = ReadUInt32(); if (unknown1 != 0 && unknown1 != 1) // it's 0 in one .sll file return S_FALSE; - UInt32 timeStamp = ReadUInt32(); + /* 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(); + /* UInt32 lang = */ ReadUInt32(); GUID g; ReadGUID(g); // {7C01FD10-7BAA-11D0-9E0C-00A0-C922-E6EC} ReadGUID(g); // {7C01FD11-7BAA-11D0-9E0C-00A0-C922-E6EC} @@ -319,23 +320,23 @@ HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database) return S_FALSE; if (ReadUInt32() != 1) // version return S_FALSE; - UInt32 dirHeaderSize = ReadUInt32(); + /* 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, + /* 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 + /* 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 + /* 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(); + /* UInt32 windowsLangId = */ ReadUInt32(); ReadGUID(g); // {5D02926A-212E-11D0-9DF9-00A0C922E6EC} ReadUInt32(); // 0x54 (This is the length again) ReadUInt32(); // -1 (unknown) @@ -360,7 +361,7 @@ HRESULT CInArchive::OpenChm(IInStream *inStream, CDatabase &database) ReadUInt32(); // Chunk number of next listing chunk when reading // directory in sequence (-1 if this is the last listing chunk) int numItems = 0; - while (true) + for (;;) { UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos; UInt32 offsetLimit = dirChunkSize - quickrefLength; @@ -448,7 +449,7 @@ HRESULT CInArchive::OpenHelp2(IInStream *inStream, CDatabase &database) 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. + /* 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 @@ -479,13 +480,13 @@ HRESULT CInArchive::OpenHelp2(IInStream *inStream, CDatabase &database) if (unknown != 0 && unknown != 1) // = 0 for some HxW files, 1 in other cases; return S_FALSE; database.ContentOffset = _startPosition + ReadUInt64(); - UInt32 timeStamp = ReadUInt32(); + /* 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? + /* UInt32 lang = */ ReadUInt32(); // BE? } else return S_FALSE; @@ -539,7 +540,7 @@ HRESULT CInArchive::OpenHelp2(IInStream *inStream, CDatabase &database) ReadUInt32(); // 0 (unknown) int numItems = 0; - while (true) + for (;;) { UInt64 offset = _inBuffer.GetProcessedSize() - chunkPos; UInt32 offsetLimit = dirChunkSize - quickrefLength; @@ -684,7 +685,7 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database) { // The NameList file RINOK(DecompressStream(inStream, database, kNameList)); - UInt16 length = ReadUInt16(); + /* UInt16 length = */ ReadUInt16(); UInt16 numSections = ReadUInt16(); for (int i = 0; i < numSections; i++) { @@ -849,7 +850,7 @@ HRESULT CInArchive::Open2(IInStream *inStream, const int kSignatureSize = 8; UInt64 hxsSignature = NHeader::GetHxsSignature(); UInt64 chmSignature = ((UInt64)chmVersion << 32)| NHeader::kItsfSignature; - while(true) + for (;;) { Byte b; if (!_inBuffer.ReadByte(b)) diff --git a/7zip/Archive/Chm/ChmIn.h b/7zip/Archive/Chm/ChmIn.h index d2ddb378..ebf3c4be 100755 --- a/7zip/Archive/Chm/ChmIn.h +++ b/7zip/Archive/Chm/ChmIn.h @@ -76,11 +76,11 @@ struct CResetTable { if (blockIndex >= ResetOffsets.Size()) return false; - UInt64 startPos = ResetOffsets[(size_t)blockIndex]; + UInt64 startPos = ResetOffsets[(int)blockIndex]; if (blockIndex + numBlocks >= ResetOffsets.Size()) size = CompressedSize - startPos; else - size = ResetOffsets[(size_t)blockIndex + numBlocks] - startPos; + size = ResetOffsets[(int)(blockIndex + numBlocks)] - startPos; return true; } bool GetCompressedSizeOfBlock(UInt64 blockIndex, UInt64 &size) const @@ -121,7 +121,7 @@ struct CLzxInfo UInt64 blockIndex = GetBlockIndexFromFolderIndex(folderIndex); if (blockIndex >= ResetTable.ResetOffsets.Size()) return false; - offset = ResetTable.ResetOffsets[(size_t)blockIndex]; + offset = ResetTable.ResetOffsets[(int)blockIndex]; return true; } bool GetCompressedSizeOfFolder(UInt64 folderIndex, UInt64 &size) const @@ -168,7 +168,7 @@ public: UInt64 GetFolder(int fileIndex) const { const CItem &item = Items[Indices[fileIndex]]; - const CSectionInfo §ion = Sections[(size_t)item.Section]; + const CSectionInfo §ion = Sections[(int)item.Section]; if (section.IsLzx()) return section.Methods[0].LzxInfo.GetFolder(item.Offset); return 0; @@ -177,7 +177,7 @@ public: UInt64 GetLastFolder(int fileIndex) const { const CItem &item = Items[Indices[fileIndex]]; - const CSectionInfo §ion = Sections[(size_t)item.Section]; + const CSectionInfo §ion = Sections[(int)item.Section]; if (section.IsLzx()) return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1); return 0; diff --git a/7zip/Archive/Chm/DllExports.cpp b/7zip/Archive/Chm/DllExports.cpp index edc87a8c..ad822094 100755 --- a/7zip/Archive/Chm/DllExports.cpp +++ b/7zip/Archive/Chm/DllExports.cpp @@ -13,7 +13,7 @@ DEFINE_GUID(CLSID_CChmHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xE9, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { return TRUE; } diff --git a/7zip/Archive/Common/CoderMixer2.h b/7zip/Archive/Common/CoderMixer2.h index e80f4bfe..78a3f280 100755 --- a/7zip/Archive/Common/CoderMixer2.h +++ b/7zip/Archive/Common/CoderMixer2.h @@ -127,7 +127,7 @@ struct CBindInfo class CBindReverseConverter { UInt32 _numSrcOutStreams; - const NCoderMixer2::CBindInfo _srcBindInfo; + NCoderMixer2::CBindInfo _srcBindInfo; CRecordVector _srcInToDestOutMap; CRecordVector _srcOutToDestInMap; CRecordVector _destInToSrcOutMap; diff --git a/7zip/Archive/Common/CoderMixer2MT.cpp b/7zip/Archive/Common/CoderMixer2MT.cpp index 43b150cc..28fd3d6a 100755 --- a/7zip/Archive/Common/CoderMixer2MT.cpp +++ b/7zip/Archive/Common/CoderMixer2MT.cpp @@ -125,7 +125,7 @@ void CThreadCoderInfo::SetCoderInfo(const UInt64 **inSizes, static DWORD WINAPI CoderThread(void *threadCoderInfo) { - while(true) + for (;;) { if (!((CThreadCoderInfo *)threadCoderInfo)->WaitAndCode()) return 0; @@ -137,7 +137,7 @@ static DWORD WINAPI CoderThread(void *threadCoderInfo) static DWORD WINAPI MainCoderThread(void *threadCoderInfo) { - while(true) + for (;;) { if (!((CCoderMixer2MT *)threadCoderInfo)->MyCode()) return 0; @@ -282,7 +282,7 @@ bool CCoderMixer2MT::MyCode() for(int i = 0; i < _coderInfoVector.Size(); i++) _coderInfoVector[i].CompressEvent->Set(); - DWORD result = ::WaitForMultipleObjects(_compressingCompletedEvents.Size(), + /* DWORD result = */ ::WaitForMultipleObjects(_compressingCompletedEvents.Size(), &_compressingCompletedEvents.Front(), TRUE, INFINITE); _compressingFinishedEvent.Set(); @@ -292,10 +292,10 @@ bool CCoderMixer2MT::MyCode() STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams, - const UInt64 **inSizes, + const UInt64 ** /* inSizes */, UInt32 numInStreams, ISequentialOutStream **outStreams, - const UInt64 **outSizes, + const UInt64 ** /* outSizes */, UInt32 numOutStreams, ICompressProgressInfo *progress) { @@ -315,7 +315,7 @@ STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams, _startCompressingEvent.Set(); - while (true) + for (;;) { HANDLE events[2] = {_compressingFinishedEvent, progressSpec->ProgressEvent }; DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); diff --git a/7zip/Archive/Common/CoderMixer2ST.h b/7zip/Archive/Common/CoderMixer2ST.h index 3cddc171..3144918b 100755 --- a/7zip/Archive/Common/CoderMixer2ST.h +++ b/7zip/Archive/Common/CoderMixer2ST.h @@ -66,7 +66,8 @@ public: { { _coders[coderIndex].SetCoderInfo(inSizes, outSizes); } } - void SetProgressCoderIndex(UInt32 coderIndex) + + void SetProgressCoderIndex(UInt32 /*coderIndex*/) { // _progressCoderIndex = coderIndex; } diff --git a/7zip/Archive/Common/FilterCoder.cpp b/7zip/Archive/Common/FilterCoder.cpp index 4dce89bf..5e104c84 100755 --- a/7zip/Archive/Common/FilterCoder.cpp +++ b/7zip/Archive/Common/FilterCoder.cpp @@ -37,12 +37,13 @@ HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 siz STDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { RINOK(Init()); UInt32 bufferPos = 0; - if (_outSizeIsDefined = (outSize != 0)) + _outSizeIsDefined = (outSize != 0); + if (_outSizeIsDefined) _outSize = *outSize; while(NeedMore()) diff --git a/7zip/Archive/Common/InStreamWithCRC.cpp b/7zip/Archive/Common/InStreamWithCRC.cpp index 86151b9d..74dff7e1 100755 --- a/7zip/Archive/Common/InStreamWithCRC.cpp +++ b/7zip/Archive/Common/InStreamWithCRC.cpp @@ -4,23 +4,25 @@ #include "InStreamWithCRC.h" -STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, - UInt32 size, UInt32 *processedSize) +STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize) { UInt32 realProcessedSize; HRESULT result = _stream->Read(data, size, &realProcessedSize); _size += realProcessedSize; + if (size > 0 && realProcessedSize == 0) + _wasFinished = true; _crc.Update(data, realProcessedSize); if(processedSize != NULL) *processedSize = realProcessedSize; return result; } -STDMETHODIMP CInStreamWithCRC::Read(void *data, - UInt32 size, UInt32 *processedSize) +STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSize) { UInt32 realProcessedSize; HRESULT result = _stream->Read(data, size, &realProcessedSize); + if (size > 0 && realProcessedSize == 0) + _wasFinished = true; _size += realProcessedSize; _crc.Update(data, realProcessedSize); if(processedSize != NULL) diff --git a/7zip/Archive/Common/InStreamWithCRC.h b/7zip/Archive/Common/InStreamWithCRC.h index ba7e8564..770a1437 100755 --- a/7zip/Archive/Common/InStreamWithCRC.h +++ b/7zip/Archive/Common/InStreamWithCRC.h @@ -19,16 +19,19 @@ private: CMyComPtr _stream; UInt64 _size; CCRC _crc; + bool _wasFinished; public: - void Init(ISequentialInStream *stream) + void SetStream(ISequentialInStream *stream) { _stream = stream; } + void Init() { - _stream = stream; _size = 0; + _wasFinished = false; _crc.Init(); } void ReleaseStream() { _stream.Release(); } UInt32 GetCRC() const { return _crc.GetDigest(); } UInt64 GetSize() const { return _size; } + bool WasFinished() const { return _wasFinished; } }; class CInStreamWithCRC: @@ -44,16 +47,19 @@ private: CMyComPtr _stream; UInt64 _size; CCRC _crc; + bool _wasFinished; public: - void Init(IInStream *stream) + void SetStream(IInStream *stream) { _stream = stream; } + void Init() { - _stream = stream; _size = 0; + _wasFinished = false; _crc.Init(); } void ReleaseStream() { _stream.Release(); } UInt32 GetCRC() const { return _crc.GetDigest(); } UInt64 GetSize() const { return _size; } + bool WasFinished() const { return _wasFinished; } }; #endif diff --git a/7zip/Archive/Common/ItemNameUtils.cpp b/7zip/Archive/Common/ItemNameUtils.cpp index fcb8f544..f7c3fcd9 100755 --- a/7zip/Archive/Common/ItemNameUtils.cpp +++ b/7zip/Archive/Common/ItemNameUtils.cpp @@ -40,7 +40,7 @@ bool HasTailSlash(const AString &name, UINT codePage) return false; LPCSTR prev = #ifdef _WIN32 - CharPrevExA(codePage, name, &name[name.Length()], 0); + CharPrevExA((WORD)codePage, name, &name[name.Length()], 0); #else (LPCSTR)(name) + (name.Length() - 1); #endif diff --git a/7zip/Archive/Common/MultiStream.cpp b/7zip/Archive/Common/MultiStream.cpp index 7ef4f155..a8cb333e 100755 --- a/7zip/Archive/Common/MultiStream.cpp +++ b/7zip/Archive/Common/MultiStream.cpp @@ -37,8 +37,6 @@ STDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) { UInt64 newPos; - if(seekOrigin >= 3) - return STG_E_INVALIDFUNCTION; switch(seekOrigin) { case STREAM_SEEK_SET: @@ -50,6 +48,8 @@ STDMETHODIMP CMultiStream::Seek(Int64 offset, UInt32 seekOrigin, case STREAM_SEEK_END: newPos = _totalLength + offset; break; + default: + return STG_E_INVALIDFUNCTION; } _seekPos = 0; for (_streamIndex = 0; _streamIndex < Streams.Size(); _streamIndex++) diff --git a/7zip/Archive/Common/OutStreamWithCRC.cpp b/7zip/Archive/Common/OutStreamWithCRC.cpp index 4fbce564..7ac3f123 100755 --- a/7zip/Archive/Common/OutStreamWithCRC.cpp +++ b/7zip/Archive/Common/OutStreamWithCRC.cpp @@ -4,8 +4,7 @@ #include "OutStreamWithCRC.h" -STDMETHODIMP COutStreamWithCRC::Write(const void *data, - UInt32 size, UInt32 *processedSize) +STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *processedSize) { UInt32 realProcessedSize; HRESULT result; @@ -16,7 +15,9 @@ STDMETHODIMP COutStreamWithCRC::Write(const void *data, } else result = _stream->Write(data, size, &realProcessedSize); - _crc.Update(data, realProcessedSize); + if (_calculateCrc) + _crc.Update(data, realProcessedSize); + _size += realProcessedSize; if(processedSize != NULL) *processedSize = realProcessedSize; return result; diff --git a/7zip/Archive/Common/OutStreamWithCRC.h b/7zip/Archive/Common/OutStreamWithCRC.h index 23c69e04..0feb542b 100755 --- a/7zip/Archive/Common/OutStreamWithCRC.h +++ b/7zip/Archive/Common/OutStreamWithCRC.h @@ -16,18 +16,22 @@ public: STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); private: - CCRC _crc; CMyComPtr _stream; + UInt64 _size; + CCRC _crc; + bool _calculateCrc; public: - void Init(ISequentialOutStream *stream) + void SetStream(ISequentialOutStream *stream) { _stream = stream; } + void Init(bool calculateCrc = true) { - _stream = stream; + _size = 0; + _calculateCrc = calculateCrc; _crc.Init(); } void ReleaseStream() { _stream.Release(); } + UInt64 GetSize() const { return _size; } UInt32 GetCRC() const { return _crc.GetDigest(); } void InitCRC() { _crc.Init(); } - }; #endif diff --git a/7zip/Archive/Deb/DebHandler.cpp b/7zip/Archive/Deb/DebHandler.cpp index bfcb1f20..8728cec8 100755 --- a/7zip/Archive/Deb/DebHandler.cpp +++ b/7zip/Archive/Deb/DebHandler.cpp @@ -35,7 +35,7 @@ STATPROPSTG kProperties[] = { NULL, kpidLastWriteTime, VT_FILETIME} }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -65,19 +65,18 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } STDMETHODIMP CHandler::Open(IInStream *stream, - const UInt64 *maxCheckStartPosition, + const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *openArchiveCallback) { COM_TRY_BEGIN - bool mustBeClosed = true; { CInArchive archive; if(archive.Open(stream) != S_OK) @@ -91,7 +90,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL)); } - while(true) + for (;;) { CItemEx itemInfo; bool filled; @@ -217,7 +216,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(_inStream->Seek(itemInfo.GetDataPosition(), STREAM_SEEK_SET, NULL)); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream(streamSpec); - streamSpec->Init(_inStream, itemInfo.Size); + streamSpec->SetStream(_inStream); + streamSpec->Init(itemInfo.Size); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr progress = localProgressSpec; diff --git a/7zip/Archive/Deb/DebIn.cpp b/7zip/Archive/Deb/DebIn.cpp index 4900517b..c2221d12 100755 --- a/7zip/Archive/Deb/DebIn.cpp +++ b/7zip/Archive/Deb/DebIn.cpp @@ -37,10 +37,21 @@ HRESULT CInArchive::Open(IInStream *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]; - strncpy(sz, s, size); + MyStrNCpy(sz, s, size); sz[size] = 0; const char *end; int i; @@ -61,7 +72,7 @@ static bool OctalToNumber32(const char *s, int size, UInt32 &res) static bool DecimalToNumber(const char *s, int size, UInt64 &res) { char sz[32]; - strncpy(sz, s, size); + MyStrNCpy(sz, s, size); sz[size] = 0; const char *end; int i; @@ -96,7 +107,7 @@ HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item) return S_OK; char tempString[kNameSize + 1]; - strncpy(tempString, cur, kNameSize); + MyStrNCpy(tempString, cur, kNameSize); cur += kNameSize; tempString[kNameSize] = '\0'; item.Name = tempString; @@ -123,7 +134,7 @@ HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item) HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item) { - while(true) + for (;;) { RINOK(GetNextItemReal(filled, item)); if (!filled) @@ -134,7 +145,6 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item) return S_OK; SkeepData(item.Size); } - return S_OK; } HRESULT CInArchive::Skeep(UInt64 numBytes) diff --git a/7zip/Archive/Deb/DllExports.cpp b/7zip/Archive/Deb/DllExports.cpp index cb314000..fe320531 100755 --- a/7zip/Archive/Deb/DllExports.cpp +++ b/7zip/Archive/Deb/DllExports.cpp @@ -13,9 +13,9 @@ DEFINE_GUID(CLSID_CDebHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xEC, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject( diff --git a/7zip/Archive/GZip/GZipHandler.cpp b/7zip/Archive/GZip/GZipHandler.cpp index ca5951f5..ff592324 100755 --- a/7zip/Archive/GZip/GZipHandler.cpp +++ b/7zip/Archive/GZip/GZipHandler.cpp @@ -85,7 +85,7 @@ STATPROPSTG kProperties[] = // { L"Is Text", kpidIsText, VT_BOOL}, }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -113,21 +113,19 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_NOTIMPL; } STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) { - COM_TRY_BEGIN *numItems = 1; return S_OK; - COM_TRY_END } -STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN NWindows::NCOM::CPropVariant propVariant; @@ -192,8 +190,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va } STDMETHODIMP CHandler::Open(IInStream *inStream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback) + const UInt64 * /* maxCheckStartPosition */, + IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN try @@ -259,7 +257,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC; CMyComPtr outStream(outStreamSpec); - outStreamSpec->Init(realOutStream); + outStreamSpec->SetStream(realOutStream); + outStreamSpec->Init(); realOutStream.Release(); CLocalProgress *localProgressSpec = new CLocalProgress; @@ -276,7 +275,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, CMyComPtr deflateDecoder; bool firstItem = true; RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL)); - while(true) + for (;;) { localCompressProgressSpec->Init(progress, ¤tTotalPacked, @@ -352,10 +351,11 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, if((outStreamSpec->GetCRC() != postItem.FileCRC)) { RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kCRCError)) - return S_OK; + break; } } COM_TRY_END + return S_OK; } }} diff --git a/7zip/Archive/GZip/GZipHandlerOut.cpp b/7zip/Archive/GZip/GZipHandlerOut.cpp index be71a0f5..cc896016 100755 --- a/7zip/Archive/GZip/GZipHandlerOut.cpp +++ b/7zip/Archive/GZip/GZipHandlerOut.cpp @@ -36,8 +36,7 @@ STDMETHODIMP CHandler::GetFileTimeType(UInt32 *timeType) return S_OK; } -static HRESULT CopyStreams(ISequentialInStream *inStream, - ISequentialOutStream *outStream, IArchiveUpdateCallback *updateCallback) +static HRESULT CopyStreams(ISequentialInStream *inStream, ISequentialOutStream *outStream) { CMyComPtr copyCoder = new NCompress::CCopyCoder; return copyCoder->Code(inStream, outStream, NULL, NULL, NULL); @@ -56,8 +55,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt UInt32 itemIndex = 0; if (!updateCallback) return E_FAIL; - RINOK(updateCallback->GetUpdateItemInfo(0, - &newData, &newProperties, &indexInArchive)); + RINOK(updateCallback->GetUpdateItemInfo(0, &newData, &newProperties, &indexInArchive)); CItem newItem = m_Item; newItem.ExtraFlags = 0; @@ -157,7 +155,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt { RINOK(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL)); } - return CopyStreams(m_Stream, outStream, updateCallback); + return CopyStreams(m_Stream, outStream); } STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) diff --git a/7zip/Archive/GZip/GZipIn.cpp b/7zip/Archive/GZip/GZipIn.cpp index d36ce5d0..2b16d369 100755 --- a/7zip/Archive/GZip/GZipIn.cpp +++ b/7zip/Archive/GZip/GZipIn.cpp @@ -55,7 +55,7 @@ HRESULT CInArchive::ReadUInt32(ISequentialInStream *inStream, UInt32 &value) HRESULT CInArchive::ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, CCRC &crc) { resString.Empty(); - while(true) + for (;;) { Byte c; RINOK(ReadByte(inStream, c)); diff --git a/7zip/Archive/GZip/GZipOut.cpp b/7zip/Archive/GZip/GZipOut.cpp index 99b08319..afa8a931 100755 --- a/7zip/Archive/GZip/GZipOut.cpp +++ b/7zip/Archive/GZip/GZipOut.cpp @@ -48,7 +48,7 @@ HRESULT COutArchive::WriteHeader(const CItem &item) { RINOK(WriteUInt16(kSignature)); RINOK(WriteByte(item.CompressionMethod)); - RINOK(WriteByte(item.Flags & NFileHeader::NFlags::kNameIsPresent)); + RINOK(WriteByte((Byte)(item.Flags & NFileHeader::NFlags::kNameIsPresent))); RINOK(WriteUInt32(item.Time)); RINOK(WriteByte(item.ExtraFlags)); RINOK(WriteByte(item.HostOS)); diff --git a/7zip/Archive/GZip/GZipUpdate.cpp b/7zip/Archive/GZip/GZipUpdate.cpp index 9bc54522..45e6e985 100755 --- a/7zip/Archive/GZip/GZipUpdate.cpp +++ b/7zip/Archive/GZip/GZipUpdate.cpp @@ -31,7 +31,7 @@ namespace NGZip { static const Byte kHostOS = NFileHeader::NHostOS::kFAT; -HRESULT UpdateArchive(IInStream *inStream, +HRESULT UpdateArchive(IInStream * /* inStream */, UInt64 unpackSize, ISequentialOutStream *outStream, const CItem &newItem, @@ -59,7 +59,8 @@ HRESULT UpdateArchive(IInStream *inStream, CSequentialInStreamWithCRC *inStreamSpec = new CSequentialInStreamWithCRC; CMyComPtr crcStream(inStreamSpec); - inStreamSpec->Init(fileInStream); + inStreamSpec->SetStream(fileInStream); + inStreamSpec->Init(); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr localProgress = localProgressSpec; diff --git a/7zip/Archive/Iso/DllExports.cpp b/7zip/Archive/Iso/DllExports.cpp index 3bc48470..f746eea1 100755 --- a/7zip/Archive/Iso/DllExports.cpp +++ b/7zip/Archive/Iso/DllExports.cpp @@ -13,7 +13,7 @@ DEFINE_GUID(CLSID_CIsoHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xE7, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { return TRUE; } diff --git a/7zip/Archive/Iso/IsoHandler.cpp b/7zip/Archive/Iso/IsoHandler.cpp index 793ddc48..1831e913 100755 --- a/7zip/Archive/Iso/IsoHandler.cpp +++ b/7zip/Archive/Iso/IsoHandler.cpp @@ -34,7 +34,7 @@ STATPROPSTG kProperties[] = { NULL, kpidLastWriteTime, VT_FILETIME} }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -64,18 +64,17 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } STDMETHODIMP CHandler::Open(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback) + const UInt64 * /* maxCheckStartPosition */, + IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN - bool mustBeClosed = true; Close(); // try { @@ -267,7 +266,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(_inStream->Seek(blockIndex * _archive.BlockSize, STREAM_SEEK_SET, NULL)); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream(streamSpec); - streamSpec->Init(_inStream, currentItemSize); + streamSpec->SetStream(_inStream); + streamSpec->Init(currentItemSize); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr progress = localProgressSpec; diff --git a/7zip/Archive/Iso/IsoIn.cpp b/7zip/Archive/Iso/IsoIn.cpp index 8501802c..213b3014 100755 --- a/7zip/Archive/Iso/IsoIn.cpp +++ b/7zip/Archive/Iso/IsoIn.cpp @@ -76,7 +76,7 @@ UInt16 CInArchive::ReadUInt16() throw 1; value |= ((UInt16)(b[i]) << (8 * i)); } - return value; + return (UInt16)value; } UInt32 CInArchive::ReadUInt32Le() @@ -134,13 +134,13 @@ UInt32 CInArchive::ReadDigits(int numDigits) void CInArchive::ReadDateTime(CDateTime &d) { - d.Year = ReadDigits(4); - d.Month = ReadDigits(2); - d.Day = ReadDigits(2); - d.Hour = ReadDigits(2); - d.Minute = ReadDigits(2); - d.Second = ReadDigits(2); - d.Hundredths = ReadDigits(2); + 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(); } @@ -254,7 +254,7 @@ void CInArchive::ReadDir(CDir &d, int level) UInt64 startPos = _position; bool firstItem = true; - while(true) + for (;;) { UInt64 offset = _position - startPos; if (offset >= d.DataLength) @@ -311,7 +311,7 @@ void CInArchive::ReadBootInfo() if (ReadUInt16Spec() != 0) throw 1; ReadBytes(e.Id, sizeof(e.Id)); - UInt16 checkSum = ReadUInt16Spec(); + /* UInt16 checkSum = */ ReadUInt16Spec(); if (ReadByte() != 0x55) throw 1; if (ReadByte() != 0xAA) @@ -346,14 +346,17 @@ HRESULT CInArchive::Open2() m_BufferPos = 0; BlockSize = kBlockSize; VolDescs.Add(CVolumeDescriptor()); - while(true) + for (;;) { Byte sig[6]; ReadBytes(sig, 6); if (!CheckDescriptorSignature(sig + 1)) return S_FALSE; - if (ReadByte() != kVersion) - throw 1; + // version = 2 for ISO 9660:1999? + Byte ver = ReadByte(); + if (ver > 2) + throw S_FALSE; + if (sig[0] == NVolDescType::kTerminator) break; switch(sig[0]) diff --git a/7zip/Archive/Iso/IsoIn.h b/7zip/Archive/Iso/IsoIn.h index f1d33aaa..ab850bd9 100755 --- a/7zip/Archive/Iso/IsoIn.h +++ b/7zip/Archive/Iso/IsoIn.h @@ -36,7 +36,7 @@ struct CDir: public CDirRecord int GetLengthU() const { - int len = FileId.GetCapacity() / 2; + int len = (int)(FileId.GetCapacity() / 2); if (Parent != 0) if (Parent->Parent != 0) len += 1 + Parent->GetLengthU(); @@ -51,7 +51,7 @@ struct CDir: public CDirRecord p += len; *p = 0; const CDir *cur = this; - while(true) + for (;;) { int curLen = cur->GetLengthCur(checkSusp, skipSize); p -= curLen; @@ -76,15 +76,15 @@ struct CDir: public CDirRecord p += len; *p = 0; const CDir *cur = this; - while(true) + for (;;) { - int curLen = cur->FileId.GetCapacity() / 2; + 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)b0 << 8) | (wchar_t)b1; + p[i] = (wchar_t)(((wchar_t)b0 << 8) | b1); } cur = cur->Parent; if (cur == 0) diff --git a/7zip/Archive/Iso/IsoItem.h b/7zip/Archive/Iso/IsoItem.h index d874ab74..14024d8d 100755 --- a/7zip/Archive/Iso/IsoItem.h +++ b/7zip/Archive/Iso/IsoItem.h @@ -25,7 +25,7 @@ struct CRecordingDateTime bool GetFileTime(FILETIME &ft) const { SYSTEMTIME st; - st.wYear = Year + 1900; + st.wYear = (WORD)(Year + 1900); st.wMonth = Month; st.wDayOfWeek = 0; // check it st.wDay = Day; @@ -69,7 +69,7 @@ struct CDirRecord { lenRes = 0; const Byte *p = (const Byte *)SystemUse + skipSize; - int length = SystemUse.GetCapacity() - skipSize; + int length = (int)(SystemUse.GetCapacity() - skipSize); while (length >= 5) { int len = p[2]; @@ -93,7 +93,7 @@ struct CDirRecord if (res != 0) return len; } - return FileId.GetCapacity(); + return (int)FileId.GetCapacity(); } const Byte* GetNameCur(bool checkSusp, int skipSize) const @@ -127,7 +127,7 @@ struct CDirRecord bool CheckSusp(int &startPos) const { const Byte *p = (const Byte *)SystemUse; - int length = SystemUse.GetCapacity(); + int length = (int)SystemUse.GetCapacity(); const int kMinLen = 7; if (length < kMinLen) return false; diff --git a/7zip/Archive/Lzh/DllExports.cpp b/7zip/Archive/Lzh/DllExports.cpp index ee5006f3..c2b30945 100755 --- a/7zip/Archive/Lzh/DllExports.cpp +++ b/7zip/Archive/Lzh/DllExports.cpp @@ -13,7 +13,7 @@ DEFINE_GUID(CLSID_CLzhHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x06, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { return TRUE; } diff --git a/7zip/Archive/Lzh/LzhCRC.cpp b/7zip/Archive/Lzh/LzhCRC.cpp index f11564a5..ca1235bb 100755 --- a/7zip/Archive/Lzh/LzhCRC.cpp +++ b/7zip/Archive/Lzh/LzhCRC.cpp @@ -36,7 +36,7 @@ void CCRC::Update(const void *data, size_t size) UInt16 v = _value; const Byte *p = (const Byte *)data; for (; size > 0; size--, p++) - v = Table[((Byte)(v)) ^ *p] ^ (v >> 8); + v = (UInt16)(Table[((Byte)(v)) ^ *p] ^ (v >> 8)); _value = v; } diff --git a/7zip/Archive/Lzh/LzhCRC.h b/7zip/Archive/Lzh/LzhCRC.h index 22512563..bb5546db 100755 --- a/7zip/Archive/Lzh/LzhCRC.h +++ b/7zip/Archive/Lzh/LzhCRC.h @@ -11,7 +11,7 @@ namespace NLzh { class CCRC { - UInt32 _value; + UInt16 _value; public: static UInt16 Table[256]; static void InitTable(); diff --git a/7zip/Archive/Lzh/LzhHandler.cpp b/7zip/Archive/Lzh/LzhHandler.cpp index fcfeaef1..03af11d1 100755 --- a/7zip/Archive/Lzh/LzhHandler.cpp +++ b/7zip/Archive/Lzh/LzhHandler.cpp @@ -89,7 +89,7 @@ STATPROPSTG kProperties[] = CHandler::CHandler() {} -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -119,8 +119,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_NOTIMPL; } @@ -226,7 +226,7 @@ STDMETHODIMP CPropgressImp::SetCompleted(const UInt64 *numFiles) */ STDMETHODIMP CHandler::Open(IInStream *inStream, - const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *callback) + const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *callback) { COM_TRY_BEGIN try @@ -240,7 +240,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream, UInt64 numFiles = _items.Size(); RINOK(callback->SetCompleted(&numFiles, NULL)); } - while(true) + for (;;) { CItemEx itemInfo; bool filled; @@ -307,7 +307,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0; UInt64 currentItemUnPacked, currentItemPacked; - NCompress::NLzh::NDecoder::CCoder *lzhDecoderSpec; + NCompress::NLzh::NDecoder::CCoder *lzhDecoderSpec = 0; CMyComPtr lzhDecoder; CMyComPtr lzh1Decoder; CMyComPtr arj2Decoder; @@ -357,7 +357,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, UInt64 pos; _stream->Seek(itemInfo.DataPosition, STREAM_SEEK_SET, &pos); - streamSpec->Init(_stream, itemInfo.PackSize); + streamSpec->SetStream(_stream); + streamSpec->Init(itemInfo.PackSize); CLocalProgress *localProgressSpec = new CLocalProgress; diff --git a/7zip/Archive/Lzh/LzhIn.cpp b/7zip/Archive/Lzh/LzhIn.cpp index 5344ef13..42ef50e4 100755 --- a/7zip/Archive/Lzh/LzhIn.cpp +++ b/7zip/Archive/Lzh/LzhIn.cpp @@ -66,9 +66,9 @@ static const Byte *ReadString(const Byte *p, size_t size, AString &s) static Byte CalcSum(const Byte *data, size_t size) { Byte sum = 0; - for (size_t i = 0; i < size; i++) - sum += data[i]; - return sum; + for (size_t i = 0; i < size; i++) + sum = (Byte)(sum + data[i]); + return sum; } HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item) diff --git a/7zip/Archive/Lzh/LzhItem.h b/7zip/Archive/Lzh/LzhItem.h index 448d8b33..66d4ed75 100755 --- a/7zip/Archive/Lzh/LzhItem.h +++ b/7zip/Archive/Lzh/LzhItem.h @@ -150,7 +150,7 @@ public: AString GetName() const { AString dirName = GetDirName(); - dirName.Replace((char)0xFF, '\\'); + dirName.Replace((char)(unsigned char)0xFF, '\\'); if (!dirName.IsEmpty()) { char c = dirName[dirName.Length() - 1]; diff --git a/7zip/Archive/Nsis/NsisHandler.cpp b/7zip/Archive/Nsis/NsisHandler.cpp index 6d26722e..0d840479 100755 --- a/7zip/Archive/Nsis/NsisHandler.cpp +++ b/7zip/Archive/Nsis/NsisHandler.cpp @@ -42,7 +42,7 @@ STATPROPSTG kProperties[] = { NULL, kpidSolid, VT_BOOL} }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -71,15 +71,15 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } -STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback *openArchiveCallback) +STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 * maxCheckStartPosition, IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN - bool mustBeClosed = true; Close(); { if(_archive.Open(stream, maxCheckStartPosition) != S_OK) diff --git a/7zip/Archive/Nsis/NsisIn.cpp b/7zip/Archive/Nsis/NsisIn.cpp index 47cfdcb4..0db6ccfd 100755 --- a/7zip/Archive/Nsis/NsisIn.cpp +++ b/7zip/Archive/Nsis/NsisIn.cpp @@ -53,7 +53,7 @@ void CInArchive::ReadBlockHeader(CBlockHeader &bh) #define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; } -static int CompareItems(void *const *p1, void *const *p2, void *param) +static int CompareItems(void *const *p1, void *const *p2, void * /* param */) { RINOZ(MyCompare( (**(const CItem **)p1).Pos, @@ -65,17 +65,19 @@ AString CInArchive::ReadString(UInt32 pos) { AString s; UInt32 offset = GetOffset() + _stringsPos + pos; - while(true) + for (;;) { if (offset >= _size) throw 1; char c = _data[offset++]; if (c == 0) - return s; + break; s += c; } + return s; } +/* static AString ParsePrefix(const AString &prefix) { AString res = prefix; @@ -88,7 +90,7 @@ static AString ParsePrefix(const AString &prefix) } return res; } - +*/ #define SYSREGKEY "Software\\Microsoft\\Windows\\CurrentVersion" @@ -525,13 +527,19 @@ AString CInArchive::ReadString2(UInt32 pos) #define DEL_REBOOT 4 // #define DEL_SIMPLE 8 -const int kNumEntryParams = 6; +static const int kNumEntryParams = 6; struct CEntry { UInt32 Which; UInt32 Params[kNumEntryParams]; AString GetParamsString(int numParams); + CEntry() + { + Which = 0; + for (UInt32 j = 0; j < kNumEntryParams; j++) + Params[j] = 0; + } }; AString CEntry::GetParamsString(int numParams) @@ -584,12 +592,12 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh) { CItem item; item.Prefix = prefix; - UInt32 overwriteFlag = e.Params[0]; + /* UInt32 overwriteFlag = e.Params[0]; */ item.Name = ReadString2(e.Params[1]); item.Pos = e.Params[2]; item.DateTime.dwLowDateTime = e.Params[3]; item.DateTime.dwHighDateTime = e.Params[4]; - UInt32 allowIgnore = e.Params[5]; + /* UInt32 allowIgnore = e.Params[5]; */ if (Items.Size() > 0) { /* @@ -949,7 +957,7 @@ HRESULT CInArchive::Parse() { // UInt32 offset = ReadUInt32(); // ???? offset == FirstHeader.HeaderLength - UInt32 ehFlags = ReadUInt32(); + /* UInt32 ehFlags = */ ReadUInt32(); CBlockHeader bhPages, bhSections, bhEntries, bhStrings, bhLangTables, bhCtlColors, bhData; // CBlockHeader bgFont; ReadBlockHeader(bhPages); @@ -1034,7 +1042,8 @@ HRESULT CInArchive::Open2() _posInData = 0; if (!IsSolid) { - if (_headerIsCompressed = ((compressedHeaderSize & 0x80000000) != 0)) + _headerIsCompressed = ((compressedHeaderSize & 0x80000000) != 0); + if (_headerIsCompressed) compressedHeaderSize &= ~0x80000000; _nonSolidStartOffset = compressedHeaderSize; RINOK(_stream->Seek(StreamOffset + 4, STREAM_SEEK_SET, NULL)); @@ -1113,7 +1122,7 @@ HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *maxCheckStartPositio Byte buffer[kStep]; bool found = false; - UInt64 headerPosition; + UInt64 headerPosition = 0; while (position <= maxSize) { UInt32 processedSize; diff --git a/7zip/Archive/RPM/DllExports.cpp b/7zip/Archive/RPM/DllExports.cpp index 2319857c..ed21e64f 100755 --- a/7zip/Archive/RPM/DllExports.cpp +++ b/7zip/Archive/RPM/DllExports.cpp @@ -13,9 +13,9 @@ DEFINE_GUID(CLSID_CRpmHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xEB, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { - return TRUE; + return TRUE; } STDAPI CreateObject( diff --git a/7zip/Archive/RPM/RpmHandler.cpp b/7zip/Archive/RPM/RpmHandler.cpp index 78789081..b1a5bf7d 100755 --- a/7zip/Archive/RPM/RpmHandler.cpp +++ b/7zip/Archive/RPM/RpmHandler.cpp @@ -33,7 +33,7 @@ STATPROPSTG kProperties[] = { NULL, kpidPackedSize, VT_UI8} }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -63,15 +63,15 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } STDMETHODIMP CHandler::Open(IInStream *inStream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback) + const UInt64 * /* maxCheckStartPosition */, + IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN try @@ -104,7 +104,7 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) return S_OK; } -STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN NWindows::NCOM::CPropVariant propVariant; diff --git a/7zip/Archive/RPM/RpmIn.cpp b/7zip/Archive/RPM/RpmIn.cpp index 03373d9c..c1600894 100755 --- a/7zip/Archive/RPM/RpmIn.cpp +++ b/7zip/Archive/RPM/RpmIn.cpp @@ -16,7 +16,7 @@ namespace NRpm { static UInt16 GetUInt16(const char *data) { - return (Byte)data[1] | (((UInt16)(Byte)data[0]) << 8); + return (UInt16)((Byte)data[1] | (((UInt16)(Byte)data[0]) << 8)); } static UInt32 GetUInt32(const char *data) diff --git a/7zip/Archive/Rar/Rar.dsp b/7zip/Archive/Rar/Rar.dsp index 9aee468e..739024da 100755 --- a/7zip/Archive/Rar/Rar.dsp +++ b/7zip/Archive/Rar/Rar.dsp @@ -351,14 +351,6 @@ SOURCE=..\..\Crypto\RarAES\RarAES.cpp SOURCE=..\..\Crypto\RarAES\RarAES.h # End Source File -# Begin Source File - -SOURCE=..\..\Crypto\RarAES\sha1.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\RarAES\sha1.h -# End Source File # End Group # Begin Group "Rar20" @@ -380,6 +372,28 @@ SOURCE=..\..\Crypto\Rar20\Rar20Crypto.cpp SOURCE=..\..\Crypto\Rar20\Rar20Crypto.h # End Source File # End Group +# Begin Group "Hash" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha1.cpp + +!IF "$(CFG)" == "Rar - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Rar - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha1.h +# End Source File +# End Group # End Group # Begin Group "7-zip Common" diff --git a/7zip/Archive/Rar/RarHandler.cpp b/7zip/Archive/Rar/RarHandler.cpp index cd654ec2..3389f0e2 100755 --- a/7zip/Archive/Rar/RarHandler.cpp +++ b/7zip/Archive/Rar/RarHandler.cpp @@ -360,7 +360,6 @@ public: } int numLetters = 1; - bool splitStyle = false; if (basePart.Right(numLetters) == L"1") { while (numLetters < basePart.Length()) @@ -432,7 +431,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, openArchiveCallbackWrap.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword); } - while(true) + for (;;) { CMyComPtr inStream; if (!_archives.IsEmpty()) @@ -475,7 +474,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, archive.GetArchiveInfo(_archiveInfo); CItemEx item; - while(true) + for (;;) { HRESULT result = archive.GetNextItem(item, getTextPassword); if (result == S_FALSE) @@ -618,9 +617,9 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, CFilterCoder *filterStreamSpec = new CFilterCoder; CMyComPtr filterStream = filterStreamSpec; - NCrypto::NRar20::CDecoder *rar20CryptoDecoderSpec; + NCrypto::NRar20::CDecoder *rar20CryptoDecoderSpec = NULL; CMyComPtr rar20CryptoDecoder; - NCrypto::NRar29::CDecoder *rar29CryptoDecoderSpec; + NCrypto::NRar29::CDecoder *rar29CryptoDecoderSpec = NULL; CMyComPtr rar29CryptoDecoder; CFolderInStream *folderInStreamSpec = NULL; @@ -681,7 +680,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC; CMyComPtr outStream(outStreamSpec); - outStreamSpec->Init(realOutStream); + outStreamSpec->SetStream(realOutStream); + outStreamSpec->Init(); realOutStream.Release(); UInt64 packedPos = currentImportantTotalPacked; @@ -866,8 +866,7 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties)); - Byte isSolid = - (IsSolid(index) || item.IsSplitBefore()) ? 1: 0; + Byte isSolid = (Byte)((IsSolid(index) || item.IsSplitBefore()) ? 1: 0); RINOK(compressSetDecoderProperties->SetDecoderProperties2(&isSolid, 1)); diff --git a/7zip/Archive/Rar/RarIn.cpp b/7zip/Archive/Rar/RarIn.cpp index 36d8b824..9a88feb7 100755 --- a/7zip/Archive/Rar/RarIn.cpp +++ b/7zip/Archive/Rar/RarIn.cpp @@ -72,16 +72,16 @@ bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit) UInt32 numBytesPrev = NHeader::kMarkerSize - 1; memmove(buffer, marker + 1, numBytesPrev); UInt64 curTestPos = m_StreamStartPosition + 1; - while(true) + for (;;) { if (searchHeaderSizeLimit != NULL) if (curTestPos - m_StreamStartPosition > *searchHeaderSizeLimit) - return false; + break; UInt32 numReadBytes = kSearchMarkerBufferSize - numBytesPrev; ReadBytes(buffer + numBytesPrev, numReadBytes, &processedSize); UInt32 numBytesInBuffer = numBytesPrev + processedSize; if (numBytesInBuffer < NHeader::kMarkerSize) - return false; + break; UInt32 numTests = numBytesInBuffer - NHeader::kMarkerSize + 1; for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++) { @@ -174,7 +174,6 @@ bool CInArchive::ReadMarkerAndArchiveHeader(const UInt64 *searchHeaderSizeLimit) crc.UpdateByte(m_ArchiveHeader.EncryptVersion); } - UInt32 u = crc.GetDigest(); if(m_ArchiveHeader.CRC != (crc.GetDigest() & 0xFFFF)) ThrowExceptionWithCode(CInArchiveException::kArchiveHeaderCRCError); if (m_ArchiveHeader.Type != NHeader::NBlockType::kArchiveHeader) @@ -197,7 +196,7 @@ void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const archiveInfo.StartPosition = m_ArchiveStartPosition; archiveInfo.Flags = m_ArchiveHeader.Flags; archiveInfo.CommentPosition = m_ArchiveCommentPosition; - archiveInfo.CommentSize = m_ArchiveHeader.Size - NHeader::NArchive::kArchiveHeaderSize; + archiveInfo.CommentSize = (UInt16)(m_ArchiveHeader.Size - NHeader::NArchive::kArchiveHeaderSize); } static void DecodeUnicodeFileName(const char *name, const Byte *encName, @@ -221,10 +220,10 @@ static void DecodeUnicodeFileName(const char *name, const Byte *encName, unicodeName[decPos++] = encName[encPos++]; break; case 1: - unicodeName[decPos++] = encName[encPos++] + (highByte << 8); + unicodeName[decPos++] = (wchar_t)(encName[encPos++] + (highByte << 8)); break; case 2: - unicodeName[decPos++] = encName[encPos] + (encName[encPos + 1] << 8); + unicodeName[decPos++] = (wchar_t)(encName[encPos] + (encName[encPos + 1] << 8)); encPos += 2; break; case 3: @@ -235,7 +234,7 @@ static void DecodeUnicodeFileName(const char *name, const Byte *encName, Byte correction = encName[encPos++]; for (length = (length & 0x7f) + 2; length > 0 && decPos < maxDecSize; length--, decPos++) - unicodeName[decPos] = ((name[decPos] + correction) & 0xff) + (highByte << 8); + unicodeName[decPos] = (wchar_t)(((name[decPos] + correction) & 0xff) + (highByte << 8)); } else for (length += 2; length > 0 && decPos < maxDecSize; length--, decPos++) @@ -316,7 +315,7 @@ UInt32 CInArchive::ReadUInt32() void CInArchive::ReadTime(Byte mask, CRarTime &rarTime) { - rarTime.LowSecond = ((mask & 4) != 0) ? 1 : 0; + rarTime.LowSecond = (Byte)(((mask & 4) != 0) ? 1 : 0); int numDigits = (mask & 3); rarTime.SubTime[0] = rarTime.SubTime[1] = rarTime.SubTime[2] = 0; for (int i = 0; i < numDigits; i++) @@ -353,20 +352,23 @@ void CInArchive::ReadHeaderReal(CItemEx &item) for (int i = 0; i < sizeof(item.Salt); i++) item.Salt[i] = ReadByte(); - if (item.HasExtTime()) + // some rar archives have HasExtTime flag without field. + if (m_CurPos < m_PosLimit && item.HasExtTime()) { - Byte accessMask = ReadByte() >> 4; + Byte accessMask = (Byte)(ReadByte() >> 4); Byte b = ReadByte(); - Byte modifMask = b >> 4; - Byte createMask = b & 0xF; + Byte modifMask = (Byte)(b >> 4); + Byte createMask = (Byte)(b & 0xF); if ((modifMask & 8) != 0) ReadTime(modifMask, item.LastWriteTime); - if (item.IsCreationTimeDefined = ((createMask & 8) != 0)) + item.IsCreationTimeDefined = ((createMask & 8) != 0); + if (item.IsCreationTimeDefined) { item.CreationTime.DosTime = ReadUInt32(); ReadTime(createMask, item.CreationTime); } - if (item.IsLastAccessTimeDefined = ((accessMask & 8) != 0)) + item.IsLastAccessTimeDefined = ((accessMask & 8) != 0); + if (item.IsLastAccessTimeDefined) { item.LastAccessTime.DosTime = ReadUInt32(); ReadTime(accessMask, item.LastAccessTime); @@ -377,10 +379,10 @@ void CInArchive::ReadHeaderReal(CItemEx &item) item.Position = m_Position; item.MainPartSize = fileHeaderWithNameSize; - item.CommentSize = m_BlockHeader.HeadSize - fileHeaderWithNameSize; + item.CommentSize = (UInt16)(m_BlockHeader.HeadSize - fileHeaderWithNameSize); if (m_CryptoMode) - item.AlignSize = (16 - ((m_BlockHeader.HeadSize) & 0xF)) & 0xF; + item.AlignSize = (UInt16)((16 - ((m_BlockHeader.HeadSize) & 0xF)) & 0xF); else item.AlignSize = 0; AddToSeekValue(m_BlockHeader.HeadSize); @@ -395,7 +397,7 @@ HRESULT CInArchive::GetNextItem(CItemEx &item, ICryptoGetTextPassword *getTextPa { if (m_SeekOnArchiveComment) SkipArchiveComment(); - while (true) + for (;;) { if(!SeekInArchive(m_Position)) return S_FALSE; @@ -525,7 +527,8 @@ ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 siz CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream(streamSpec); SeekInArchive(position); - streamSpec->Init(m_Stream, size); + streamSpec->SetStream(m_Stream); + streamSpec->Init(size); return inStream.Detach(); } diff --git a/7zip/Archive/Rar/RarItem.cpp b/7zip/Archive/Rar/RarItem.cpp index 8114728f..61a72557 100755 --- a/7zip/Archive/Rar/RarItem.cpp +++ b/7zip/Archive/Rar/RarItem.cpp @@ -44,7 +44,17 @@ UInt32 CItem::GetDictSize() const bool CItem::IsDirectory() const { - return (GetDictSize() == NHeader::NFile::kDictDirectoryValue); + if (GetDictSize() == NHeader::NFile::kDictDirectoryValue) + return true; + switch(HostOS) + { + case NHeader::NFile::kHostMSDOS: + case NHeader::NFile::kHostOS2: + case NHeader::NFile::kHostWin32: + if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) + return true; + } + return false; } UInt32 CItem::GetWinAttributes() const @@ -68,41 +78,41 @@ UInt32 CItem::GetWinAttributes() const void CItem::ClearFlags() { Flags = 0; } -void CItem::SetFlagBits(int aStartBitNumber, int aNumBits, int aValue) +void CItem::SetFlagBits(int startBitNumber, int numBits, int value) { - UInt16 mask = ((1 << aNumBits) - 1) << aStartBitNumber; + UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber); Flags &= ~mask; - Flags |= aValue << aStartBitNumber; + Flags |= value << startBitNumber; } -void CItem::SetBitMask(int aBitMask, bool anEnable) +void CItem::SetBitMask(int bitMask, bool enable) { - if(anEnable) - Flags |= aBitMask; + if(enable) + Flags |= bitMask; else - Flags &= ~aBitMask; + Flags &= ~bitMask; } -void CItem::SetDictSize(UInt32 aSize) +void CItem::SetDictSize(UInt32 size) { - SetFlagBits(NHeader::NFile::kDictBitStart, NHeader::NFile::kNumDictBits, (aSize & NHeader::NFile::kDictMask)); + SetFlagBits(NHeader::NFile::kDictBitStart, NHeader::NFile::kNumDictBits, (size & NHeader::NFile::kDictMask)); } -void CItem::SetAsDirectory(bool aDirectory) +void CItem::SetAsDirectory(bool directory) { - if (aDirectory) + if (directory) SetDictSize(NHeader::NFile::kDictDirectoryValue); } -void CItem::SetEncrypted(bool anEncrypted) - { SetBitMask(NHeader::NFile::kEncrypted, anEncrypted); } -void CItem::SetSolid(bool aSolid) - { SetBitMask(NHeader::NFile::kSolid, aSolid); } -void CItem::SetCommented(bool aCommented) - { SetBitMask(NHeader::NFile::kComment, aCommented); } -void CItem::SetSplitBefore(bool aSplitBefore) - { SetBitMask(NHeader::NFile::kSplitBefore, aSplitBefore); } -void CItem::SetSplitAfter(bool aSplitAfter) - { SetBitMask(NHeader::NFile::kSplitAfter, aSplitAfter); } +void CItem::SetEncrypted(bool encrypted) + { SetBitMask(NHeader::NFile::kEncrypted, encrypted); } +void CItem::SetSolid(bool solid) + { SetBitMask(NHeader::NFile::kSolid, solid); } +void CItem::SetCommented(bool commented) + { SetBitMask(NHeader::NFile::kComment, commented); } +void CItem::SetSplitBefore(bool splitBefore) + { SetBitMask(NHeader::NFile::kSplitBefore, splitBefore); } +void CItem::SetSplitAfter(bool splitAfter) + { SetBitMask(NHeader::NFile::kSplitAfter, splitAfter); } }} diff --git a/7zip/Archive/Rar/RarItem.h b/7zip/Archive/Rar/RarItem.h index 0140f888..85050a42 100755 --- a/7zip/Archive/Rar/RarItem.h +++ b/7zip/Archive/Rar/RarItem.h @@ -58,17 +58,17 @@ public: CItem(): IsCreationTimeDefined(false), IsLastAccessTimeDefined(false) {} private: - void SetFlagBits(int aStartBitNumber, int aNumBits, int aValue); - void SetBitMask(int aBitMask, bool anEnable); + void SetFlagBits(int startBitNumber, int numBits, int value); + void SetBitMask(int bitMask, bool enable); public: void ClearFlags(); - void SetDictSize(UInt32 aSize); - void SetAsDirectory(bool aDirectory); - void SetEncrypted(bool anEncrypted); - void SetSolid(bool aSolid); - void SetCommented(bool aCommented); - void SetSplitBefore(bool aSplitBefore); - void SetSplitAfter(bool aSplitAfter); + void SetDictSize(UInt32 size); + void SetAsDirectory(bool directory); + void SetEncrypted(bool encrypted); + void SetSolid(bool solid); + void SetCommented(bool commented); + void SetSplitBefore(bool splitBefore); + void SetSplitAfter(bool splitAfter); }; class CItemEx: public CItem diff --git a/7zip/Archive/Rar/makefile b/7zip/Archive/Rar/makefile index 42942f74..678dd412 100755 --- a/7zip/Archive/Rar/makefile +++ b/7zip/Archive/Rar/makefile @@ -42,13 +42,15 @@ AR_COMMON_OBJS = \ $O\7zMethodID.obj \ $O\7zMethods.obj \ +CRYPTO_HASH_OBJS = \ + $O\Sha1.obj \ + CRYPTO_RAR20_OBJS = \ $O\Rar20Cipher.obj \ $O\Rar20Crypto.obj \ CRYPTO_RARAES_OBJS = \ $O\RarAES.obj \ - $O\sha1.obj \ OBJS = \ $O\StdAfx.obj \ @@ -58,6 +60,7 @@ OBJS = \ $(7ZIP_COMMON_OBJS) \ $(AR_COMMON_OBJS) \ $(7Z_OBJS) \ + $(CRYPTO_HASH_OBJS) \ $(CRYPTO_RAR20_OBJS) \ $(CRYPTO_RARAES_OBJS) \ $O\CopyCoder.obj \ @@ -77,6 +80,8 @@ $(AR_COMMON_OBJS): ../Common/$(*B).cpp $(COMPL) $(7Z_OBJS): ../7z/$(*B).cpp $(COMPL) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL_O2) $(CRYPTO_RAR20_OBJS): ../../Crypto/Rar20/$(*B).cpp $(COMPL) $(CRYPTO_RARAES_OBJS): ../../Crypto/RarAES/$(*B).cpp diff --git a/7zip/Archive/Split/DllExports.cpp b/7zip/Archive/Split/DllExports.cpp index f9e8a83b..e28f64ce 100755 --- a/7zip/Archive/Split/DllExports.cpp +++ b/7zip/Archive/Split/DllExports.cpp @@ -13,9 +13,9 @@ DEFINE_GUID(CLSID_CSplitHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xEA, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { - return TRUE; + return TRUE; } STDAPI CreateObject( diff --git a/7zip/Archive/Split/SplitHandler.cpp b/7zip/Archive/Split/SplitHandler.cpp index 79f9af2b..e919154f 100755 --- a/7zip/Archive/Split/SplitHandler.cpp +++ b/7zip/Archive/Split/SplitHandler.cpp @@ -31,7 +31,7 @@ STATPROPSTG kProperties[] = { NULL, kpidPackedSize, VT_UI8}, }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -61,8 +61,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } @@ -142,7 +142,7 @@ public: }; STDMETHODIMP CHandler::Open(IInStream *stream, - const UInt64 *maxCheckStartPosition, + const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *openArchiveCallback) { COM_TRY_BEGIN @@ -235,7 +235,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL)); } - while (true) + for (;;) { UString fullName = seqName.GetNextName(); CMyComPtr nextStream; @@ -286,7 +286,7 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) return S_OK; } -STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value) { COM_TRY_BEGIN NWindows::NCOM::CPropVariant propVariant; diff --git a/7zip/Archive/Tar/DllExports.cpp b/7zip/Archive/Tar/DllExports.cpp index e1535bd1..afa2fd24 100755 --- a/7zip/Archive/Tar/DllExports.cpp +++ b/7zip/Archive/Tar/DllExports.cpp @@ -13,7 +13,7 @@ DEFINE_GUID(CLSID_CTarHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xEE, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { return TRUE; } diff --git a/7zip/Archive/Tar/TarHandler.cpp b/7zip/Archive/Tar/TarHandler.cpp index 67c8940a..9c2cd006 100755 --- a/7zip/Archive/Tar/TarHandler.cpp +++ b/7zip/Archive/Tar/TarHandler.cpp @@ -36,7 +36,7 @@ STATPROPSTG kProperties[] = { NULL, kpidGroup, VT_BSTR}, }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -66,14 +66,14 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } STDMETHODIMP CHandler::Open(IInStream *stream, - const UInt64 *maxCheckStartPosition, + const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *openArchiveCallback) { COM_TRY_BEGIN @@ -93,7 +93,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL)); } - while(true) + for (;;) { CItemEx item; bool filled; @@ -242,7 +242,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(_inStream->Seek(item.GetDataPosition(), STREAM_SEEK_SET, NULL)); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream(streamSpec); - streamSpec->Init(_inStream, item.Size); + streamSpec->SetStream(_inStream); + streamSpec->Init(item.Size); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr progress = localProgressSpec; diff --git a/7zip/Archive/Tar/TarHeader.cpp b/7zip/Archive/Tar/TarHeader.cpp index 41fb2137..35f0d0cf 100755 --- a/7zip/Archive/Tar/TarHeader.cpp +++ b/7zip/Archive/Tar/TarHeader.cpp @@ -12,6 +12,7 @@ namespace NFileHeader { const char *kCheckSumBlanks = " "; // 8 blanks, no null const char *kLongLink = "././@LongLink"; + const char *kLongLink2 = "@LongLink"; // The magic field is filled with this if uname and gname are valid. namespace NMagic diff --git a/7zip/Archive/Tar/TarHeader.h b/7zip/Archive/Tar/TarHeader.h index 1436293f..0ab31e52 100755 --- a/7zip/Archive/Tar/TarHeader.h +++ b/7zip/Archive/Tar/TarHeader.h @@ -81,7 +81,8 @@ namespace NFileHeader // The checksum field is filled with this while the checksum is computed. extern const char *kCheckSumBlanks;// = " "; // 8 blanks, no null - extern const char *kLongLink; // = "././@LongLink"; + extern const char *kLongLink; // = "././@LongLink"; + extern const char *kLongLink2; // = "@LongLink"; // The magic field is filled with this if uname and gname are valid. namespace NMagic diff --git a/7zip/Archive/Tar/TarIn.cpp b/7zip/Archive/Tar/TarIn.cpp index 81a58b50..86afc482 100755 --- a/7zip/Archive/Tar/TarIn.cpp +++ b/7zip/Archive/Tar/TarIn.cpp @@ -27,10 +27,21 @@ HRESULT CInArchive::Open(IInStream *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 *srcString, int size, UInt64 &res) { char sz[32]; - strncpy(sz, srcString, size); + MyStrNCpy(sz, srcString, size); sz[size] = 0; const char *end; int i; @@ -63,14 +74,14 @@ static void ReadString(const char *s, int size, AString &result) if (size > NFileHeader::kRecordSize) size = NFileHeader::kNameSize; char tempString[NFileHeader::kRecordSize + 1]; - strncpy(tempString, s, size); + MyStrNCpy(tempString, s, size); tempString[size] = '\0'; result = tempString; } static char GetHex(Byte value) { - return (value < 10) ? ('0' + value) : ('A' + (value - 10)); + return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10))); } HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item) @@ -109,8 +120,8 @@ HRESULT CInArchive::GetNextItemReal(bool &filled, CItemEx &item) if (((Byte)c) < 0x20) { item.Name += '['; - item.Name += GetHex(((Byte)c) >> 4); - item.Name += GetHex(((Byte)c) & 0xF); + item.Name += GetHex((Byte)(((Byte)c) >> 4)); + item.Name += GetHex((Byte)(((Byte)c) & 0xF)); item.Name += ']'; } else @@ -190,7 +201,8 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item) if (item.LinkFlag == 'L') { if (item.Name.Compare(NFileHeader::kLongLink) != 0) - return S_FALSE; + if (item.Name.Compare(NFileHeader::kLongLink2) != 0) + return S_FALSE; UInt64 headerPosition = item.HeaderPosition; UInt32 processedSize; diff --git a/7zip/Archive/Tar/TarOut.cpp b/7zip/Archive/Tar/TarOut.cpp index 28146c34..e278edda 100755 --- a/7zip/Archive/Tar/TarOut.cpp +++ b/7zip/Archive/Tar/TarOut.cpp @@ -33,6 +33,17 @@ static AString MakeOctalString(UInt64 value) return AString(s) + ' '; } +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 MakeOctalString8(char *s, UInt32 value) { AString tempString = MakeOctalString(value); @@ -43,7 +54,7 @@ static bool MakeOctalString8(char *s, UInt32 value) int numSpaces = kMaxSize - (tempString.Length() + 1); for(int i = 0; i < numSpaces; i++) s[i] = ' '; - strcpy(s + numSpaces, tempString); + MyStringCopy(s + numSpaces, (const char *)tempString); return true; } @@ -64,7 +75,7 @@ static bool CopyString(char *dest, const AString &src, int maxSize) { if (src.Length() >= maxSize) return false; - strcpy(dest, src); + MyStringCopy(dest, (const char *)src); return true; } @@ -81,7 +92,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item) // RETURN_IF_NOT_TRUE(CopyString(header.Name, item.Name, NFileHeader::kNameSize)); if (item.Name.Length() > NFileHeader::kNameSize) return E_FAIL; - strncpy(cur, item.Name, NFileHeader::kNameSize); + MyStrNCpy(cur, item.Name, NFileHeader::kNameSize); cur += NFileHeader::kNameSize; RETURN_IF_NOT_TRUE(MakeOctalString8(cur, item.Mode)); diff --git a/7zip/Archive/Tar/TarUpdate.cpp b/7zip/Archive/Tar/TarUpdate.cpp index 98133fb1..9a6f64e2 100755 --- a/7zip/Archive/Tar/TarUpdate.cpp +++ b/7zip/Archive/Tar/TarUpdate.cpp @@ -139,13 +139,15 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream, RINOK(outArchive.WriteHeader(item)); RINOK(inStream->Seek(existItemInfo.GetDataPosition(), STREAM_SEEK_SET, NULL)); - streamSpec->Init(inStream, existItemInfo.Size); + streamSpec->SetStream(inStream); + streamSpec->Init(existItemInfo.Size); } else { RINOK(inStream->Seek(existItemInfo.HeaderPosition, STREAM_SEEK_SET, NULL)); - streamSpec->Init(inStream, existItemInfo.GetFullSize()); + streamSpec->SetStream(inStream); + streamSpec->Init(existItemInfo.GetFullSize()); } RINOK(CopyBlock(inStreamLimited, outStream, compressProgress)); RINOK(outArchive.FillDataResidual(existItemInfo.Size)); diff --git a/7zip/Archive/Z/DllExports.cpp b/7zip/Archive/Z/DllExports.cpp index 9de69c9c..b8df85f4 100755 --- a/7zip/Archive/Z/DllExports.cpp +++ b/7zip/Archive/Z/DllExports.cpp @@ -12,13 +12,9 @@ DEFINE_GUID(CLSID_CZHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x05, 0x00, 0x00); -HINSTANCE g_hInstance; - extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { - if (dwReason == DLL_PROCESS_ATTACH) - g_hInstance = hInstance; return TRUE; } diff --git a/7zip/Archive/Z/ZHandler.cpp b/7zip/Archive/Z/ZHandler.cpp index 5787273b..33887690 100755 --- a/7zip/Archive/Z/ZHandler.cpp +++ b/7zip/Archive/Z/ZHandler.cpp @@ -25,7 +25,7 @@ STATPROPSTG kProperties[] = { NULL, kpidPackedSize, VT_UI8}, }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -55,8 +55,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } @@ -90,8 +90,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va static const int kSignatureSize = 3; STDMETHODIMP CHandler::Open(IInStream *stream, - const UInt64 *maxCheckStartPosition, - IArchiveOpenCallback *openArchiveCallback) + const UInt64 * /* maxCheckStartPosition */, + IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN try diff --git a/7zip/Archive/Zip/DllExports.cpp b/7zip/Archive/Zip/DllExports.cpp index 53d5a4b6..da2a15a4 100755 --- a/7zip/Archive/Zip/DllExports.cpp +++ b/7zip/Archive/Zip/DllExports.cpp @@ -8,6 +8,8 @@ #include "Windows/PropVariant.h" #include "../../ICoder.h" #include "../../IPassword.h" +#include "../../Crypto/WzAES/WzAES.h" +#include "../Common/CodecsPath.h" // {23170F69-40C1-278B-0401-080000000100} DEFINE_GUID(CLSID_CCompressDeflateEncoder, @@ -62,6 +64,12 @@ static bool IsItWindowsNT() } #endif +void GetCryptoFolderPrefix(TCHAR *path) +{ + CSysString s = GetCodecsFolderPrefix(); + lstrcpy(path, s); +} + extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) { diff --git a/7zip/Archive/Zip/Zip.dsp b/7zip/Archive/Zip/Zip.dsp index 00ef44e6..2ac27f4f 100755 --- a/7zip/Archive/Zip/Zip.dsp +++ b/7zip/Archive/Zip/Zip.dsp @@ -142,6 +142,14 @@ SOURCE=..\..\..\Common\CRC.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\IntToString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\IntToString.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File @@ -216,6 +224,18 @@ SOURCE=..\..\..\Windows\PropVariant.cpp SOURCE=..\..\..\Windows\PropVariant.h # End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Synchronization.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Synchronization.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Thread.h +# End Source File # End Group # Begin Group "Archive Common" @@ -306,6 +326,14 @@ SOURCE=..\..\Common\LSBFDecoder.h # End Source File # Begin Source File +SOURCE=..\..\Common\MemBlocks.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MemBlocks.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\OffsetStream.cpp # End Source File # Begin Source File @@ -322,6 +350,22 @@ SOURCE=..\..\Common\OutBuffer.h # End Source File # Begin Source File +SOURCE=..\..\Common\OutMemStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OutMemStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressMt.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressMt.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\ProgressUtils.cpp # End Source File # Begin Source File @@ -420,6 +464,88 @@ SOURCE=.\ZipUpdate.h # Begin Group "Crypto" # PROP Default_Filter "" +# Begin Group "WzAes" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Crypto\WzAES\WzAES.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\WzAES\WzAES.h +# End Source File +# End Group +# Begin Group "Hash" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Crypto\Hash\HmacSha1.cpp + +!IF "$(CFG)" == "Zip - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Zip - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\HmacSha1.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Pbkdf2HmacSha1.cpp + +!IF "$(CFG)" == "Zip - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Zip - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Pbkdf2HmacSha1.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\RandGen.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\RandGen.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\RotateDefs.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha1.cpp + +!IF "$(CFG)" == "Zip - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Zip - Win32 Debug" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha1.h +# End Source File +# End Group # Begin Source File SOURCE=..\..\Crypto\Zip\ZipCipher.cpp diff --git a/7zip/Archive/Zip/ZipAddCommon.cpp b/7zip/Archive/Zip/ZipAddCommon.cpp index c2b79212..7eb2787f 100755 --- a/7zip/Archive/Zip/ZipAddCommon.cpp +++ b/7zip/Archive/Zip/ZipAddCommon.cpp @@ -7,6 +7,7 @@ #include "Windows/Defs.h" #include "../../ICoder.h" #include "../../IPassword.h" +#include "../Common/InStreamWithCRC.h" #include "../7z/7zMethods.h" #include "ZipAddCommon.h" @@ -48,9 +49,6 @@ DEFINE_GUID(CLSID_CCryptoZipEncoder, namespace NArchive { namespace NZip { -static const Byte kMethodIDForEmptyStream = NFileHeader::NCompressionMethod::kStored; -static const Byte kExtractVersionForEmptyStream = NFileHeader::NCompressionMethod::kStoreExtractVersion; - CAddCommon::CAddCommon(const CCompressionMethodMode &options): _options(options), _copyCoderSpec(NULL), @@ -63,7 +61,7 @@ static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC) crc.Init(); const UInt32 kBufferSize = (1 << 14); Byte buffer[kBufferSize]; - while(true) + for (;;) { UInt32 realProcessedSize; RINOK(inStream->Read(buffer, kBufferSize, &realProcessedSize)); @@ -77,36 +75,47 @@ static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC) } HRESULT CAddCommon::Compress(ISequentialInStream *inStream, IOutStream *outStream, - UInt64 inSize, ICompressProgressInfo *progress, CCompressingResult &operationResult) + ICompressProgressInfo *progress, CCompressingResult &operationResult) { - /* - if(inSize == 0) + CSequentialInStreamWithCRC *inSecCrcStreamSpec = 0; + CInStreamWithCRC *inCrcStreamSpec = 0; + CMyComPtr inCrcStream; { - operationResult.PackSize = 0; - operationResult.Method = kMethodIDForEmptyStream; - operationResult.ExtractVersion = kExtractVersionForEmptyStream; - return S_OK; + CMyComPtr inStream2; + // we don't support stdin, since stream from stdin can require 64-bit size header + RINOK(inStream->QueryInterface(IID_IInStream, (void **)&inStream2)); + if (inStream2) + { + inCrcStreamSpec = new CInStreamWithCRC; + inCrcStream = inCrcStreamSpec; + inCrcStreamSpec->SetStream(inStream2); + inCrcStreamSpec->Init(); + } + else + { + inSecCrcStreamSpec = new CSequentialInStreamWithCRC; + inCrcStream = inSecCrcStreamSpec; + inSecCrcStreamSpec->SetStream(inStream); + inSecCrcStreamSpec->Init(); + } } - */ - CMyComPtr inStream2; + int numTestMethods = _options.MethodSequence.Size(); if (numTestMethods > 1 || _options.PasswordIsDefined) { - inStream->QueryInterface(IID_IInStream, (void **)&inStream2); - if (!inStream2) + if (inCrcStreamSpec == 0) { if (_options.PasswordIsDefined) return E_NOTIMPL; numTestMethods = 1; } } - Byte method; - UInt64 resultSize = 0; + Byte method = 0; COutStreamReleaser outStreamReleaser; for(int i = 0; i < numTestMethods; i++) { - if (inStream2) - RINOK(inStream2->Seek(0, STREAM_SEEK_SET, NULL)); + if (inCrcStreamSpec != 0) + RINOK(inCrcStreamSpec->Seek(0, STREAM_SEEK_SET, NULL)); RINOK(outStream->Seek(0, STREAM_SEEK_SET, NULL)); if (_options.PasswordIsDefined) { @@ -114,18 +123,28 @@ HRESULT CAddCommon::Compress(ISequentialInStream *inStream, IOutStream *outStrea { _cryptoStreamSpec = new CFilterCoder; _cryptoStream = _cryptoStreamSpec; - _filterSpec = new NCrypto::NZip::CEncoder; - _cryptoStreamSpec->Filter = _filterSpec; } - RINOK(_filterSpec->CryptoSetPassword( - (const Byte *)(const char *)_options.Password, _options.Password.Length())); - UInt32 crc; - RINOK(GetStreamCRC(inStream, crc)); - RINOK(inStream2->Seek(0, STREAM_SEEK_SET, NULL)); + if (_options.IsAesMode) + { + _cryptoStreamSpec->Filter = _aesFilter = _filterAesSpec = new NCrypto::NWzAES::CEncoder; + _filterAesSpec->SetKeyMode(_options.AesKeyMode); + RINOK(_filterAesSpec->CryptoSetPassword( + (const Byte *)(const char *)_options.Password, _options.Password.Length())); + RINOK(_filterAesSpec->WriteHeader(outStream)); + } + else + { + _cryptoStreamSpec->Filter = _zipCryptoFilter = _filterSpec = new NCrypto::NZip::CEncoder; + RINOK(_filterSpec->CryptoSetPassword( + (const Byte *)(const char *)_options.Password, _options.Password.Length())); + UInt32 crc = 0; + RINOK(GetStreamCRC(inStream, crc)); + RINOK(inCrcStreamSpec->Seek(0, STREAM_SEEK_SET, NULL)); + RINOK(_filterSpec->CryptoSetCRC(crc)); + RINOK(_filterSpec->WriteHeader(outStream)); + } RINOK(_cryptoStreamSpec->SetOutStream(outStream)); outStreamReleaser.FilterCoder = _cryptoStreamSpec; - RINOK(_filterSpec->CryptoSetCRC(crc)); - RINOK(_filterSpec->WriteHeader(outStream)); } method = _options.MethodSequence[i]; @@ -143,8 +162,7 @@ HRESULT CAddCommon::Compress(ISequentialInStream *inStream, IOutStream *outStrea outStreamNew = _cryptoStream; else outStreamNew = outStream; - RINOK(_copyCoder->Code(inStream, outStreamNew, - NULL, NULL, progress)); + RINOK(_copyCoder->Code(inCrcStream, outStreamNew, NULL, NULL, progress)); operationResult.ExtractVersion = NFileHeader::NCompressionMethod::kStoreExtractVersion; break; } @@ -251,24 +269,41 @@ HRESULT CAddCommon::Compress(ISequentialInStream *inStream, IOutStream *outStrea outStreamNew = _cryptoStream; else outStreamNew = outStream; - RINOK(_compressEncoder->Code(inStream, outStreamNew, NULL, NULL, progress)); + RINOK(_compressEncoder->Code(inCrcStream, outStreamNew, NULL, NULL, progress)); operationResult.ExtractVersion = NFileHeader::NCompressionMethod::kDeflateExtractVersion; break; } } - outStream->Seek(0, STREAM_SEEK_CUR, &resultSize); + + RINOK(outStream->Seek(0, STREAM_SEEK_CUR, &operationResult.PackSize)); + + if (inCrcStreamSpec != 0) + { + operationResult.CRC = inCrcStreamSpec->GetCRC(); + operationResult.UnpackSize = inCrcStreamSpec->GetSize(); + } + else + { + operationResult.CRC = inSecCrcStreamSpec->GetCRC(); + operationResult.UnpackSize = inSecCrcStreamSpec->GetSize(); + } + if (_options.PasswordIsDefined) { - if(resultSize < inSize + 12) + if (operationResult.PackSize < operationResult.UnpackSize + + (_options.IsAesMode ? _filterAesSpec->GetHeaderSize() : NCrypto::NZip::kHeaderSize)) break; } - else if(resultSize < inSize) + else if (operationResult.PackSize < operationResult.UnpackSize) break; } - RINOK(outStream->SetSize(resultSize)); - operationResult.PackSize = resultSize; + if (_options.IsAesMode) + { + RINOK(_filterAesSpec->WriteFooter(outStream)); + RINOK(outStream->Seek(0, STREAM_SEEK_CUR, &operationResult.PackSize)); + } operationResult.Method = method; - return S_OK; + return outStream->SetSize(operationResult.PackSize); } }} diff --git a/7zip/Archive/Zip/ZipAddCommon.h b/7zip/Archive/Zip/ZipAddCommon.h index e116ea9c..26cec643 100755 --- a/7zip/Archive/Zip/ZipAddCommon.h +++ b/7zip/Archive/Zip/ZipAddCommon.h @@ -12,14 +12,17 @@ #include "../Common/FilterCoder.h" #include "ZipCompressionMode.h" #include "../../Crypto/Zip/ZipCipher.h" +#include "../../Crypto/WzAES/WzAES.h" namespace NArchive { namespace NZip { struct CCompressingResult { - Byte Method; + UInt64 UnpackSize; UInt64 PackSize; + UInt32 CRC; + UInt16 Method; Byte ExtractVersion; }; @@ -38,11 +41,16 @@ class CAddCommon CMyComPtr _cryptoStream; NCrypto::NZip::CEncoder *_filterSpec; + NCrypto::NWzAES::CEncoder *_filterAesSpec; + + CMyComPtr _zipCryptoFilter; + CMyComPtr _aesFilter; + public: CAddCommon(const CCompressionMethodMode &options); HRESULT Compress(ISequentialInStream *inStream, IOutStream *outStream, - UInt64 inSize, ICompressProgressInfo *progress, CCompressingResult &operationResult); + ICompressProgressInfo *progress, CCompressingResult &operationResult); }; }} diff --git a/7zip/Archive/Zip/ZipCompressionMode.h b/7zip/Archive/Zip/ZipCompressionMode.h index 83b8fe44..f1c79918 100755 --- a/7zip/Archive/Zip/ZipCompressionMode.h +++ b/7zip/Archive/Zip/ZipCompressionMode.h @@ -23,7 +23,15 @@ struct CCompressionMethodMode #endif bool PasswordIsDefined; AString Password; - CCompressionMethodMode(): NumMatchFinderCyclesDefined(false) {} + bool IsAesMode; + Byte AesKeyMode; + + CCompressionMethodMode(): + NumMatchFinderCyclesDefined(false), + PasswordIsDefined(false), + IsAesMode(false), + AesKeyMode(3) + {} }; }} diff --git a/7zip/Archive/Zip/ZipHandler.cpp b/7zip/Archive/Zip/ZipHandler.cpp index 149ed666..4672d768 100755 --- a/7zip/Archive/Zip/ZipHandler.cpp +++ b/7zip/Archive/Zip/ZipHandler.cpp @@ -8,6 +8,7 @@ #include "Common/CRC.h" #include "Common/StringConvert.h" #include "Common/ComTry.h" +#include "Common/IntToString.h" #include "Windows/Time.h" #include "Windows/PropVariant.h" @@ -61,6 +62,7 @@ DEFINE_GUID(CLSID_CCompressBZip2Decoder, #endif #include "../../Crypto/Zip/ZipCipher.h" +#include "../../Crypto/WzAES/WzAES.h" #ifndef EXCLUDE_COM #include "../Common/CoderLoader.h" @@ -147,8 +149,10 @@ const wchar_t *kMethods[] = }; const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]); -const wchar_t *kUnknownMethod = L"Unknown"; +// const wchar_t *kUnknownMethod = L"Unknown"; const wchar_t *kPPMdMethod = L"PPMd"; +const wchar_t *kAESMethod = L"AES"; +const wchar_t *kZipCryptoMethod = L"ZipCrypto"; CHandler::CHandler(): m_ArchiveIsOpen(false) @@ -156,7 +160,7 @@ CHandler::CHandler(): InitMethodProperties(); } -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -186,8 +190,8 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_NOTIMPL; } @@ -198,6 +202,17 @@ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) 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; + } +} + STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *aValue) { COM_TRY_BEGIN @@ -244,7 +259,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *a { AString s; char *p = s.GetBuffer(size + 1); - strncpy(p, (const char *)(const Byte *)item.Comment, size); + MyStrNCpy(p, (const char *)(const Byte *)item.Comment, size); p[size] = '\0'; s.ReleaseBuffer(); propVariant = MultiByteToUnicodeString(s, item.GetCodePage()); @@ -252,19 +267,46 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID aPropID, PROPVARIANT *a break; } case kpidCRC: - propVariant = item.FileCRC; + if (item.IsThereCrc()) + propVariant = item.FileCRC; break; case kpidMethod: { + UInt16 methodId = item.CompressionMethod; UString method; - if (item.CompressionMethod < kNumMethods) - method = kMethods[item.CompressionMethod]; - else if (item.CompressionMethod == NFileHeader::NCompressionMethod::kWinZipPPMd) - method = kPPMdMethod; + if (item.IsEncrypted()) + { + if (methodId == NFileHeader::NCompressionMethod::kWzAES) + { + method = kAESMethod; + CWzAesExtraField aesField; + if (item.CentralExtra.GetWzAesField(aesField)) + { + method += L"-"; + wchar_t s[32]; + ConvertUInt64ToString((aesField.Strength + 1) * 64 , s); + method += s; + method += L" "; + methodId = aesField.Method; + } + } + else + { + method += kZipCryptoMethod; + method += L" "; + } + } + if (methodId < kNumMethods) + method += kMethods[methodId]; + else if (methodId == NFileHeader::NCompressionMethod::kWzPPMd) + method += kPPMdMethod; else - method = kUnknownMethod; + { + wchar_t s[32]; + ConvertUInt64ToString(methodId, s); + method += s; + } propVariant = method; - // propVariant = item.CompressionMethod; break; } case kpidHostOS: @@ -334,17 +376,303 @@ STDMETHODIMP CHandler::Close() struct CMethodItem { - Byte ZipMethod; + UInt16 ZipMethod; CMyComPtr Coder; }; +class CZipDecoder +{ + NCrypto::NZip::CDecoder *_zipCryptoDecoderSpec; + NCrypto::NWzAES::CDecoder *_aesDecoderSpec; + CMyComPtr _zipCryptoDecoder; + CMyComPtr _aesDecoder; + CFilterCoder *filterStreamSpec; + CMyComPtr filterStream; + CMyComPtr getTextPassword; + #ifndef EXCLUDE_COM + CCoderLibraries libraries; + #endif + CObjectVector methodItems; + +public: + CZipDecoder(): _zipCryptoDecoderSpec(0), _aesDecoderSpec(0), filterStreamSpec(0) {} + + static void Init() + { + #ifndef EXCLUDE_COM + N7z::LoadMethodMap(); + #endif + } + + HRESULT Decode(CInArchive &archive, const CItemEx &item, + ISequentialOutStream *realOutStream, + IArchiveExtractCallback *extractCallback, + ICompressProgressInfo *compressProgress, + UInt32 numThreads, Int32 &res); +}; + +HRESULT CZipDecoder::Decode(CInArchive &archive, const CItemEx &item, + ISequentialOutStream *realOutStream, + IArchiveExtractCallback *extractCallback, + ICompressProgressInfo *compressProgress, + UInt32 numThreads, Int32 &res) +{ + res = NArchive::NExtract::NOperationResult::kDataError; + CInStreamReleaser inStreamReleaser; + + bool needCRC = true; + bool aesMode = false; + UInt16 methodId = item.CompressionMethod; + if (item.IsEncrypted()) + if (methodId == NFileHeader::NCompressionMethod::kWzAES) + { + CWzAesExtraField aesField; + if (item.CentralExtra.GetWzAesField(aesField)) + { + aesMode = true; + needCRC = aesField.NeedCrc(); + } + } + + COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC;; + CMyComPtr outStream = outStreamSpec; + outStreamSpec->SetStream(realOutStream); + outStreamSpec->Init(needCRC); + + UInt64 authenticationPos; + + CMyComPtr inStream; + { + UInt64 packSize = item.PackSize; + if (aesMode) + { + if (packSize < NCrypto::NWzAES::kMacSize) + return S_OK; + packSize -= NCrypto::NWzAES::kMacSize; + } + UInt64 dataPos = item.GetDataPosition(); + inStream.Attach(archive.CreateLimitedStream(dataPos, packSize)); + authenticationPos = dataPos + packSize; + } + + CMyComPtr cryptoFilter; + if (item.IsEncrypted()) + { + if (aesMode) + { + CWzAesExtraField aesField; + if (!item.CentralExtra.GetWzAesField(aesField)) + return S_OK; + methodId = aesField.Method; + if (!_aesDecoder) + { + _aesDecoderSpec = new NCrypto::NWzAES::CDecoder; + _aesDecoder = _aesDecoderSpec; + } + cryptoFilter = _aesDecoder; + Byte properties = aesField.Strength; + RINOK(_aesDecoderSpec->SetDecoderProperties2(&properties, 1)); + } + else + { + if (!_zipCryptoDecoder) + { + _zipCryptoDecoderSpec = new NCrypto::NZip::CDecoder; + _zipCryptoDecoder = _zipCryptoDecoderSpec; + } + cryptoFilter = _zipCryptoDecoder; + } + CMyComPtr cryptoSetPassword; + RINOK(cryptoFilter.QueryInterface(IID_ICryptoSetPassword, &cryptoSetPassword)); + + if (!getTextPassword) + extractCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getTextPassword); + + if (getTextPassword) + { + CMyComBSTR password; + RINOK(getTextPassword->CryptoGetTextPassword(&password)); + AString charPassword; + if (aesMode) + { + charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_ACP); + /* + for (int i = 0;; i++) + { + wchar_t c = password[i]; + if (c == 0) + break; + if (c >= 0x80) + { + res = NArchive::NExtract::NOperationResult::kDataError; + return S_OK; + } + charPassword += (char)c; + } + */ + } + else + { + // we use OEM. WinZip/Windows probably use ANSI for some files + charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP); + } + HRESULT res = cryptoSetPassword->CryptoSetPassword( + (const Byte *)(const char *)charPassword, charPassword.Length()); + if (res != S_OK) + return S_OK; + } + else + { + RINOK(cryptoSetPassword->CryptoSetPassword(0, 0)); + } + } + + int m; + for (m = 0; m < methodItems.Size(); m++) + if (methodItems[m].ZipMethod == methodId) + break; + + if (m == methodItems.Size()) + { + CMethodItem mi; + mi.ZipMethod = methodId; + if (methodId == NFileHeader::NCompressionMethod::kStored) + mi.Coder = new NCompress::CCopyCoder; + else if (methodId == NFileHeader::NCompressionMethod::kShrunk) + mi.Coder = new NCompress::NShrink::CDecoder; + else if (methodId == NFileHeader::NCompressionMethod::kImploded) + mi.Coder = new NCompress::NImplode::NDecoder::CCoder; + else + { + #ifdef EXCLUDE_COM + switch(methodId) + { + case NFileHeader::NCompressionMethod::kDeflated: + mi.Coder = new NCompress::NDeflate::NDecoder::CCOMCoder; + break; + case NFileHeader::NCompressionMethod::kDeflated64: + mi.Coder = new NCompress::NDeflate::NDecoder::CCOMCoder64; + break; + case NFileHeader::NCompressionMethod::kBZip2: + mi.Coder = new NCompress::NBZip2::CDecoder; + break; + default: + res = NArchive::NExtract::NOperationResult::kUnSupportedMethod; + return S_OK; + } + #else + N7z::CMethodID methodID = { { 0x04, 0x01 } , 3 }; + if (methodId > 0xFF) + { + res = NArchive::NExtract::NOperationResult::kUnSupportedMethod; + return S_OK; + } + methodID.ID[2] = (Byte)methodId; + if (methodId == NFileHeader::NCompressionMethod::kStored) + { + methodID.ID[0] = 0; + methodID.IDSize = 1; + } + else if (methodId == NFileHeader::NCompressionMethod::kBZip2) + { + methodID.ID[1] = 0x02; + methodID.ID[2] = 0x02; + } + + N7z::CMethodInfo methodInfo; + if (!N7z::GetMethodInfo(methodID, methodInfo)) + { + res = NArchive::NExtract::NOperationResult::kUnSupportedMethod; + return S_OK; + } + RINOK(libraries.CreateCoder(methodInfo.FilePath, methodInfo.Decoder, &mi.Coder)); + #endif + } + m = methodItems.Add(mi); + } + ICompressCoder *coder = methodItems[m].Coder; + + { + CMyComPtr setDecoderProperties; + coder->QueryInterface(IID_ICompressSetDecoderProperties2, (void **)&setDecoderProperties); + if (setDecoderProperties) + { + Byte properties = (Byte)item.Flags; + RINOK(setDecoderProperties->SetDecoderProperties2(&properties, 1)); + } + } + + #ifdef COMPRESS_MT + { + CMyComPtr setCoderMt; + coder->QueryInterface(IID_ICompressSetCoderMt, (void **)&setCoderMt); + if (setCoderMt) + { + RINOK(setCoderMt->SetNumberOfThreads(numThreads)); + } + } + #endif + + { + HRESULT result; + CMyComPtr inStreamNew; + if (item.IsEncrypted()) + { + if (!filterStream) + { + filterStreamSpec = new CFilterCoder; + filterStream = filterStreamSpec; + } + filterStreamSpec->Filter = cryptoFilter; + if (aesMode) + { + RINOK(_aesDecoderSpec->ReadHeader(inStream)); + } + else + { + RINOK(_zipCryptoDecoderSpec->ReadHeader(inStream)); + } + RINOK(filterStreamSpec->SetInStream(inStream)); + inStreamReleaser.FilterCoder = filterStreamSpec; + inStreamNew = filterStream; + + if (aesMode) + { + if (!_aesDecoderSpec->CheckPasswordVerifyCode()) + return S_OK; + } + } + else + inStreamNew = inStream; + result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress); + if (result == S_FALSE) + return S_OK; + RINOK(result); + } + bool crcOK = true; + bool authOk = true; + if (needCRC) + crcOK = (outStreamSpec->GetCRC() == item.FileCRC); + if (aesMode) + { + inStream.Attach(archive.CreateLimitedStream(authenticationPos, NCrypto::NWzAES::kMacSize)); + if (_aesDecoderSpec->CheckMac(inStream, authOk) != S_OK) + authOk = false; + } + + res = ((crcOK && authOk) ? + NArchive::NExtract::NOperationResult::kOK : + NArchive::NExtract::NOperationResult::kCRCError); + return S_OK; +} + + STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, - Int32 _aTestMode, IArchiveExtractCallback *_anExtractCallback) + Int32 _aTestMode, IArchiveExtractCallback *extractCallback) { COM_TRY_BEGIN - CMyComPtr getTextPassword; + CZipDecoder myDecoder; bool testMode = (_aTestMode != 0); - CMyComPtr extractCallback = _anExtractCallback; UInt64 totalUnPacked = 0, totalPacked = 0; bool allFilesMode = (numItems == UInt32(-1)); if (allFilesMode) @@ -363,37 +691,14 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, UInt64 currentTotalUnPacked = 0, currentTotalPacked = 0; UInt64 currentItemUnPacked, currentItemPacked; - - #ifndef EXCLUDE_COM - N7z::LoadMethodMap(); - CCoderLibraries libraries; - #endif - CObjectVector methodItems; - /* - CCoderLibraries _libraries; - #ifndef COMPRESS_IMPLODE - CCoderLibrary implodeLib; - #endif - + CLocalProgress *localProgressSpec = new CLocalProgress; + CMyComPtr progress = localProgressSpec; + CLocalCompressProgressInfo *localCompressProgressSpec = new CLocalCompressProgressInfo; + CMyComPtr compressProgress = localCompressProgressSpec; - CMyComPtr implodeDecoder; - CMyComPtr deflateDecoder; - CMyComPtr deflate64Decoder; - CMyComPtr bzip2Decoder; + CZipDecoder::Init(); - #ifndef CRYPTO_ZIP - CCoderLibrary cryptoLib; - #endif - */ - - NCrypto::NZip::CDecoder *cryptoDecoderSpec; - CMyComPtr cryptoDecoder; - CFilterCoder *filterStreamSpec; - CMyComPtr filterStream; - - // UInt16 mixerCoderMethod; - - for(i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked, + for (i = 0; i < numItems; i++, currentTotalUnPacked += currentItemUnPacked, currentTotalPacked += currentItemPacked) { currentItemUnPacked = 0; @@ -401,222 +706,58 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(extractCallback->SetCompleted(¤tTotalUnPacked)); CMyComPtr realOutStream; - Int32 askMode; - askMode = testMode ? NArchive::NExtract::NAskMode::kTest : + Int32 askMode = testMode ? + NArchive::NExtract::NAskMode::kTest : NArchive::NExtract::NAskMode::kExtract; Int32 index = allFilesMode ? i : indices[i]; - const CItemEx &item = m_Items[index]; + RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); - if(item.IsDirectory() || item.IgnoreItem()) + CItemEx item = m_Items[index]; + if (!item.FromLocal) + { + HRESULT res = m_Archive.ReadLocalItemAfterCdItem(item); + if (res == S_FALSE) + { + if (item.IsDirectory() || realOutStream || testMode) + { + RINOK(extractCallback->PrepareOperation(askMode)); + realOutStream.Release(); + RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kUnSupportedMethod)); + } + continue; + } + RINOK(res); + } + + if (item.IsDirectory() || item.IgnoreItem()) { // if (!testMode) { RINOK(extractCallback->PrepareOperation(askMode)); + realOutStream.Release(); RINOK(extractCallback->SetOperationResult(NArchive::NExtract::NOperationResult::kOK)); } continue; } - if (!testMode && (!realOutStream)) - continue; - - RINOK(extractCallback->PrepareOperation(askMode)); currentItemUnPacked = item.UnPackSize; currentItemPacked = item.PackSize; - CInStreamReleaser inStreamReleaser; - { - COutStreamWithCRC *outStreamSpec = new COutStreamWithCRC; - CMyComPtr outStream(outStreamSpec); - outStreamSpec->Init(realOutStream); - realOutStream.Release(); - - CMyComPtr inStream; - inStream.Attach(m_Archive.CreateLimitedStream(item.GetDataPosition(), - item.PackSize)); - - CLocalProgress *localProgressSpec = new CLocalProgress; - CMyComPtr progress = localProgressSpec; - localProgressSpec->Init(extractCallback, false); - - CLocalCompressProgressInfo *localCompressProgressSpec = - new CLocalCompressProgressInfo; - CMyComPtr compressProgress = localCompressProgressSpec; - localCompressProgressSpec->Init(progress, - ¤tTotalPacked, - ¤tTotalUnPacked); - - if (item.IsEncrypted()) - { - if (!cryptoDecoder) - { - cryptoDecoderSpec = new NCrypto::NZip::CDecoder; - cryptoDecoder = cryptoDecoderSpec; - } - CMyComPtr cryptoSetPassword; - RINOK(cryptoDecoder.QueryInterface( - IID_ICryptoSetPassword, &cryptoSetPassword)); - - if (!getTextPassword) - extractCallback.QueryInterface( - IID_ICryptoGetTextPassword, &getTextPassword); - - if (getTextPassword) - { - CMyComBSTR password; - RINOK(getTextPassword->CryptoGetTextPassword(&password)); - AString anOemPassword = UnicodeStringToMultiByte( - (const wchar_t *)password, CP_OEMCP); - RINOK(cryptoSetPassword->CryptoSetPassword( - (const Byte *)(const char *)anOemPassword, anOemPassword.Length())); - } - else - { - RINOK(cryptoSetPassword->CryptoSetPassword(0, 0)); - } - } - - int m; - for (m = 0; m < methodItems.Size(); m++) - if (methodItems[m].ZipMethod == item.CompressionMethod) - break; - if (m == methodItems.Size()) - { - CMethodItem mi; - mi.ZipMethod = (Byte)item.CompressionMethod; - if (item.CompressionMethod == NFileHeader::NCompressionMethod::kStored) - mi.Coder = new NCompress::CCopyCoder; - else if (item.CompressionMethod == NFileHeader::NCompressionMethod::kShrunk) - mi.Coder = new NCompress::NShrink::CDecoder; - else if (item.CompressionMethod == NFileHeader::NCompressionMethod::kImploded) - mi.Coder = new NCompress::NImplode::NDecoder::CCoder; - else - { - #ifdef EXCLUDE_COM - switch(item.CompressionMethod) - { - case NFileHeader::NCompressionMethod::kDeflated: - mi.Coder = new NCompress::NDeflate::NDecoder::CCOMCoder; - break; - case NFileHeader::NCompressionMethod::kDeflated64: - mi.Coder = new NCompress::NDeflate::NDecoder::CCOMCoder64; - break; - case NFileHeader::NCompressionMethod::kBZip2: - mi.Coder = new NCompress::NBZip2::CDecoder; - break; - default: - RINOK(extractCallback->SetOperationResult( - NArchive::NExtract::NOperationResult::kUnSupportedMethod)); - continue; - } - #else - N7z::CMethodID methodID = { { 0x04, 0x01 } , 3 }; - methodID.ID[2] = mi.ZipMethod; - if (item.CompressionMethod == NFileHeader::NCompressionMethod::kStored) - { - methodID.ID[0] = 0; - methodID.IDSize = 1; - } - else if (item.CompressionMethod == NFileHeader::NCompressionMethod::kBZip2) - { - methodID.ID[1] = 0x02; - methodID.ID[2] = 0x02; - } - - N7z::CMethodInfo methodInfo; - if (!N7z::GetMethodInfo(methodID, methodInfo)) - { - RINOK(extractCallback->SetOperationResult( - NArchive::NExtract::NOperationResult::kUnSupportedMethod)); - continue; - } - RINOK(libraries.CreateCoder(methodInfo.FilePath, - methodInfo.Decoder, &mi.Coder)); - #endif - } - m = methodItems.Add(mi); - } - ICompressCoder *coder = methodItems[m].Coder; - - { - CMyComPtr setDecoderProperties; - coder->QueryInterface(IID_ICompressSetDecoderProperties2, (void **)&setDecoderProperties); - if (setDecoderProperties) - { - Byte properties = (Byte)item.Flags; - RINOK(setDecoderProperties->SetDecoderProperties2(&properties, 1)); - } - } - - #ifdef COMPRESS_MT - { - CMyComPtr setCoderMt; - coder->QueryInterface(IID_ICompressSetCoderMt, (void **)&setCoderMt); - if (setCoderMt) - { - RINOK(setCoderMt->SetNumberOfThreads(_numThreads)); - } - } - #endif + if (!testMode && (!realOutStream)) + continue; - // case NFileHeader::NCompressionMethod::kImploded: - // switch(item.CompressionMethod) - try - { - HRESULT result; - CMyComPtr inStreamNew; - if (item.IsEncrypted()) - { - if (!filterStream) - { - filterStreamSpec = new CFilterCoder; - filterStream = filterStreamSpec; - filterStreamSpec->Filter = cryptoDecoder; - } - RINOK(cryptoDecoderSpec->ReadHeader(inStream)); - RINOK(filterStreamSpec->SetInStream(inStream)); - inStreamReleaser.FilterCoder = filterStreamSpec; + RINOK(extractCallback->PrepareOperation(askMode)); - /* - switch(item.CompressionMethod) - { - case NFileHeader::NCompressionMethod::kStored: - mixerCoderSpec->SetCoderInfo(0, ¤tItemPacked, - ¤tItemUnPacked); - mixerCoderSpec->SetCoderInfo(1, NULL, NULL); - break; - default: - mixerCoderSpec->SetCoderInfo(0, ¤tItemPacked, NULL); - mixerCoderSpec->SetCoderInfo(1, NULL, ¤tItemUnPacked); - break; - } - */ - inStreamNew = filterStream; - } - else - { - inStreamNew = inStream; - } - result = coder->Code(inStreamNew, outStream, - NULL, ¤tItemUnPacked, compressProgress); - if (result == S_FALSE) - throw "data error"; - if (result != S_OK) - return result; - } - catch(...) - { - outStream.Release(); - RINOK(extractCallback->SetOperationResult( - NArchive::NExtract::NOperationResult::kDataError)); - continue; - } - bool crcOK = outStreamSpec->GetCRC() == item.FileCRC; - outStream.Release(); - RINOK(extractCallback->SetOperationResult(crcOK ? NArchive::NExtract::NOperationResult::kOK : - NArchive::NExtract::NOperationResult::kCRCError)) - } + localProgressSpec->Init(extractCallback, false); + localCompressProgressSpec->Init(progress, ¤tTotalPacked, ¤tTotalUnPacked); + + Int32 res; + RINOK(myDecoder.Decode(m_Archive, item, realOutStream, extractCallback, + compressProgress, _numThreads, res)); + realOutStream.Release(); + + RINOK(extractCallback->SetOperationResult(res)) } return S_OK; COM_TRY_END diff --git a/7zip/Archive/Zip/ZipHandler.h b/7zip/Archive/Zip/ZipHandler.h index 94aae211..ea6becd0 100755 --- a/7zip/Archive/Zip/ZipHandler.h +++ b/7zip/Archive/Zip/ZipHandler.h @@ -71,6 +71,9 @@ private: UInt32 m_NumMatchFinderCycles; bool m_NumMatchFinderCyclesDefined; + bool m_IsAesMode; + Byte m_AesKeyMode; + #ifdef COMPRESS_MT UInt32 _numThreads; #endif @@ -84,6 +87,8 @@ private: m_NumFastBytes = m_NumMatchFinderCycles = 0xFFFFFFFF; m_NumMatchFinderCyclesDefined = false; + m_IsAesMode = false; + m_AesKeyMode = 3; // aes-256 #ifdef COMPRESS_MT _numThreads = NWindows::NSystem::GetNumberOfProcessors();; #endif diff --git a/7zip/Archive/Zip/ZipHandlerOut.cpp b/7zip/Archive/Zip/ZipHandlerOut.cpp index 86d61527..e2394172 100755 --- a/7zip/Archive/Zip/ZipHandlerOut.cpp +++ b/7zip/Archive/Zip/ZipHandlerOut.cpp @@ -15,6 +15,7 @@ #include "../../IPassword.h" #include "../Common/ItemNameUtils.h" #include "../Common/ParseProperties.h" +#include "../../Crypto/WzAES/WzAES.h" using namespace NWindows; using namespace NCOM; @@ -45,6 +46,17 @@ STDMETHODIMP CHandler::GetFileTimeType(UInt32 *timeType) return S_OK; } +static bool IsAsciiString(const UString &s) +{ + for (int i = 0; i < s.Length(); i++) + { + wchar_t c = s[i]; + if (c < 0x20 || c > 0x7F) + return false; + } + return true; +} + STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) { @@ -138,6 +150,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt if (needSlash) name += kSlash; updateItem.Name = UnicodeStringToMultiByte(name, CP_OEMCP); + if (updateItem.Name.Length() > 0xFFFF) + return E_INVALIDARG; updateItem.IndexInClient = i; /* @@ -183,10 +197,21 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt { CMyComBSTR password; Int32 passwordIsDefined; - RINOK(getTextPassword->CryptoGetTextPassword2( - &passwordIsDefined, &password)); - if (options.PasswordIsDefined = IntToBool(passwordIsDefined)) + RINOK(getTextPassword->CryptoGetTextPassword2(&passwordIsDefined, &password)); + options.PasswordIsDefined = IntToBool(passwordIsDefined); + if (options.PasswordIsDefined) + { + if (!IsAsciiString((const wchar_t *)password)) + return E_INVALIDARG; + if (m_IsAesMode) + { + if (options.Password.Length() > NCrypto::NWzAES::kPasswordSizeMax) + return E_INVALIDARG; + } options.Password = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP); + options.IsAesMode = m_IsAesMode; + options.AesKeyMode = m_AesKeyMode; + } } else options.PasswordIsDefined = false; @@ -197,9 +222,9 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt Byte mainMethod; if (m_MainMethod < 0) - mainMethod = ((level == 0) ? + mainMethod = (Byte)(((level == 0) ? NFileHeader::NCompressionMethod::kStored : - NFileHeader::NCompressionMethod::kDeflated); + NFileHeader::NCompressionMethod::kDeflated)); else mainMethod = (Byte)m_MainMethod; options.MethodSequence.Add(mainMethod); @@ -301,6 +326,33 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v else return E_INVALIDARG; } + else if (name.Left(2) == L"EM") + { + if (prop.vt == VT_BSTR) + { + UString valueString = prop.bstrVal; + valueString.MakeUpper(); + if (valueString.Left(3) == L"AES") + { + valueString = valueString.Mid(3); + if (valueString == L"128") + m_AesKeyMode = 1; + else if (valueString == L"192") + m_AesKeyMode = 2; + else if (valueString == L"256" || valueString.IsEmpty()) + m_AesKeyMode = 3; + else + return E_INVALIDARG; + m_IsAesMode = true; + } + else if (valueString == L"ZIPCRYPTO") + m_IsAesMode = false; + else + return E_INVALIDARG; + } + else + return E_INVALIDARG; + } else if (name[0] == L'D') { UInt32 dicSize = kBZip2DicSizeX5; diff --git a/7zip/Archive/Zip/ZipHeader.h b/7zip/Archive/Zip/ZipHeader.h index 7d023715..ac98ea76 100755 --- a/7zip/Archive/Zip/ZipHeader.h +++ b/7zip/Archive/Zip/ZipHeader.h @@ -20,8 +20,9 @@ namespace NSignature static const UInt32 kMarkerSize = 4; } -const UInt32 kZip64EndOfCentralDirRecordSize = 44; - +const UInt32 kEcdSize = 22; +const UInt32 kZip64EcdSize = 44; +const UInt32 kZip64EcdLocatorSize = 20; /* struct CEndOfCentralDirectoryRecord { @@ -68,7 +69,8 @@ namespace NFileHeader kPKImploding = 10, kBZip2 = 12, - kWinZipPPMd = 0x62 + kWzPPMd = 0x62, + kWzAES = 0x63 }; const int kNumCompressionMethods = 11; const Byte kMadeByProgramVersion = 20; @@ -79,6 +81,15 @@ namespace NFileHeader const Byte kSupportedVersion = 20; } + namespace NExtraID + { + enum + { + kZip64 = 0x01, + kWzAES = 0x9901 + }; + } + const UInt32 kLocalBlockSize = 26; /* struct CLocalBlock diff --git a/7zip/Archive/Zip/ZipIn.cpp b/7zip/Archive/Zip/ZipIn.cpp index 59f1e0ae..c9e3a7d1 100755 --- a/7zip/Archive/Zip/ZipIn.cpp +++ b/7zip/Archive/Zip/ZipIn.cpp @@ -28,6 +28,11 @@ void CInArchive::Close() m_Stream.Release(); } +HRESULT CInArchive::Seek(UInt64 offset) +{ + return m_Stream->Seek(offset, STREAM_SEEK_SET, NULL); +} + ////////////////////////////////////// // Markers @@ -41,9 +46,8 @@ static inline bool TestMarkerCandidate(const Byte *p, UInt32 &value) bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit) { m_ArchiveInfo.Clear(); - m_ArchiveInfo.StartPosition = 0; m_Position = m_StreamStartPosition; - if(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL) != S_OK) + if(Seek(m_StreamStartPosition) != S_OK) return false; Byte marker[NSignature::kMarkerSize]; @@ -61,24 +65,26 @@ bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit) UInt32 numBytesPrev = NSignature::kMarkerSize - 1; memmove(buffer, marker + 1, numBytesPrev); UInt64 curTestPos = m_StreamStartPosition + 1; - while(true) + for (;;) { if (searchHeaderSizeLimit != NULL) if (curTestPos - m_StreamStartPosition > *searchHeaderSizeLimit) - return false; + break; UInt32 numReadBytes = kSearchMarkerBufferSize - numBytesPrev; ReadBytes(buffer + numBytesPrev, numReadBytes, &processedSize); UInt32 numBytesInBuffer = numBytesPrev + processedSize; if (numBytesInBuffer < NSignature::kMarkerSize) - return false; + break; UInt32 numTests = numBytesInBuffer - NSignature::kMarkerSize + 1; for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++) { if (TestMarkerCandidate(buffer + pos, m_Signature)) { m_ArchiveInfo.StartPosition = curTestPos; + // m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition; + // m_ArchiveInfo.Base = 0; m_Position = curTestPos + NSignature::kMarkerSize; - if(m_Stream->Seek(m_Position, STREAM_SEEK_SET, NULL) != S_OK) + if(Seek(m_Position) != S_OK) return false; return true; } @@ -86,6 +92,7 @@ bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit) numBytesPrev = numBytesInBuffer - numTests; memmove(buffer, buffer + numTests, numBytesPrev); } + return false; } HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize) @@ -184,10 +191,12 @@ void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const archiveInfo = m_ArchiveInfo; } +/* void CInArchive::ThrowIncorrectArchiveException() { throw CInArchiveException(CInArchiveException::kIncorrectArchive); } +*/ static UInt32 GetUInt32(const Byte *data) { @@ -198,6 +207,21 @@ static UInt32 GetUInt32(const Byte *data) (((UInt32)(Byte)data[3]) << 24); } +/* +static UInt16 GetUInt16(const Byte *data) +{ + return + ((UInt16)(Byte)data[0]) | + (((UInt16)(Byte)data[1]) << 8); +} +*/ + +static UInt64 GetUInt64(const Byte *data) +{ + return GetUInt32(data) | ((UInt64)GetUInt32(data + 4) << 32); +} + + void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock, UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber) @@ -212,7 +236,7 @@ void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock, remain -= 4; if (dataSize > remain) // it's bug dataSize = remain; - if (subBlock.ID == 0x1) + if (subBlock.ID == NFileHeader::NExtraID::kZip64) { if (unpackSize == 0xFFFFFFFF) { @@ -259,108 +283,298 @@ void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock, IncreaseRealPosition(remain); } -HRESULT CInArchive::ReadHeaders(CObjectVector &items, CProgressVirt *progress) +HRESULT CInArchive::ReadLocalItem(CItemEx &item) { - // m_Signature must be kLocalFileHeaderSignature or - // kEndOfCentralDirSignature - // m_Position points to next byte after signature - - items.Clear(); + item.ExtractVersion.Version = ReadByte(); + item.ExtractVersion.HostOS = ReadByte(); + item.Flags = ReadUInt16(); // & NFileHeader::NFlags::kUsedBitsMask; + item.CompressionMethod = ReadUInt16(); + item.Time = ReadUInt32(); + item.FileCRC = ReadUInt32(); + item.PackSize = ReadUInt32(); + item.UnPackSize = ReadUInt32(); + UInt32 fileNameSize = ReadUInt16(); + item.LocalExtraSize = ReadUInt16(); + item.Name = ReadFileName(fileNameSize); + item.FileHeaderWithNameSize = 4 + NFileHeader::kLocalBlockSize + fileNameSize; + if (item.LocalExtraSize > 0) + { + UInt64 localHeaderOffset = 0; + UInt32 diskStartNumber = 0; + ReadExtra(item.LocalExtraSize, item.LocalExtra, item.UnPackSize, item.PackSize, + localHeaderOffset, diskStartNumber); + } + /* + if (item.IsDirectory()) + item.UnPackSize = 0; // check It + */ + return S_OK; +} - if (progress != 0) +HRESULT CInArchive::ReadLocalItemAfterCdItem(CItemEx &item) +{ + if (item.FromLocal) + return S_OK; + try { - UInt64 numItems = items.Size(); - RINOK(progress->SetCompleted(&numItems)); + RINOK(Seek(m_ArchiveInfo.Base + item.LocalHeaderPosition)); + CItemEx localItem; + if (ReadUInt32() != NSignature::kLocalFileHeader) + return S_FALSE; + RINOK(ReadLocalItem(localItem)); + if (item.Flags != localItem.Flags) + { + if (item.CompressionMethod != NFileHeader::NCompressionMethod::kDeflated || + (item.Flags & 0xFFFC) != (localItem.Flags & 0xFFFC)) + return S_FALSE; + } + + if (item.CompressionMethod != localItem.CompressionMethod || + // item.Time != localItem.Time || + (!localItem.HasDescriptor() && + ( + item.FileCRC != localItem.FileCRC || + item.PackSize != localItem.PackSize || + item.UnPackSize != localItem.UnPackSize + ) + ) || + item.Name.Length() != localItem.Name.Length() + ) + return S_FALSE; + item.FileHeaderWithNameSize = localItem.FileHeaderWithNameSize; + item.LocalExtraSize = localItem.LocalExtraSize; + item.LocalExtra = localItem.LocalExtra; + item.FromLocal = true; } + catch(...) { return S_FALSE; } + return S_OK; +} - while(m_Signature == NSignature::kLocalFileHeader) +HRESULT CInArchive::ReadLocalItemDescriptor(CItemEx &item) +{ + if (item.HasDescriptor()) { - // FSeek points to next byte after signature - // NFileHeader::CLocalBlock localHeader; - CItemEx item; - item.LocalHeaderPosition = m_Position - m_StreamStartPosition - 4; // points to signature; + const int kBufferSize = (1 << 12); + Byte buffer[kBufferSize]; + + UInt32 numBytesInBuffer = 0; + UInt32 packedSize = 0; - // SafeReadBytes(&localHeader, sizeof(localHeader)); - - item.ExtractVersion.Version = ReadByte(); - item.ExtractVersion.HostOS = ReadByte(); - item.Flags = ReadUInt16() & NFileHeader::NFlags::kUsedBitsMask; - item.CompressionMethod = ReadUInt16(); - item.Time = ReadUInt32(); - item.FileCRC = ReadUInt32(); - item.PackSize = ReadUInt32(); - item.UnPackSize = ReadUInt32(); - UInt32 fileNameSize = ReadUInt16(); - item.LocalExtraSize = ReadUInt16(); - item.Name = ReadFileName(fileNameSize); - /* - if (!NItemName::IsNameLegal(item.Name)) - ThrowIncorrectArchiveException(); - */ - - item.FileHeaderWithNameSize = 4 + - NFileHeader::kLocalBlockSize + fileNameSize; - - // IncreaseRealPosition(item.LocalExtraSize); - if (item.LocalExtraSize > 0) + bool descriptorWasFound = false; + for (;;) { - UInt64 localHeaderOffset = 0; - UInt32 diskStartNumber = 0; - CExtraBlock extraBlock; - ReadExtra(item.LocalExtraSize, extraBlock, item.UnPackSize, item.PackSize, - localHeaderOffset, diskStartNumber); + UInt32 processedSize; + RINOK(ReadBytes(buffer + numBytesInBuffer, kBufferSize - numBytesInBuffer, &processedSize)); + numBytesInBuffer += processedSize; + if (numBytesInBuffer < NFileHeader::kDataDescriptorSize) + return S_FALSE; + UInt32 i; + for (i = 0; i <= numBytesInBuffer - NFileHeader::kDataDescriptorSize; i++) + { + // descriptorSignature field is Info-ZIP's extension + // to Zip specification. + UInt32 descriptorSignature = GetUInt32(buffer + i); + + // !!!! It must be fixed for Zip64 archives + UInt32 descriptorPackSize = GetUInt32(buffer + i + 8); + if (descriptorSignature== NSignature::kDataDescriptor && descriptorPackSize == packedSize + i) + { + descriptorWasFound = true; + item.FileCRC = GetUInt32(buffer + i + 4); + item.PackSize = descriptorPackSize; + item.UnPackSize = GetUInt32(buffer + i + 12); + IncreaseRealPosition(Int64(Int32(0 - (numBytesInBuffer - i - NFileHeader::kDataDescriptorSize)))); + break; + } + } + if (descriptorWasFound) + break; + packedSize += i; + int j; + for (j = 0; i < numBytesInBuffer; i++, j++) + buffer[j] = buffer[i]; + numBytesInBuffer = j; } + } + else + IncreaseRealPosition(item.PackSize); + return S_OK; +} +HRESULT CInArchive::ReadLocalItemAfterCdItemFull(CItemEx &item) +{ + if (item.FromLocal) + return S_OK; + try + { + RINOK(ReadLocalItemAfterCdItem(item)); if (item.HasDescriptor()) { - const int kBufferSize = (1 << 12); - Byte buffer[kBufferSize]; + RINOK(Seek(m_ArchiveInfo.Base + item.GetDataPosition() + item.PackSize)); + if (ReadUInt32() != NSignature::kDataDescriptor) + return S_FALSE; + UInt32 crc = ReadUInt32(); + UInt32 packSize = ReadUInt32(); + UInt32 unpackSize = ReadUInt32(); + if (crc != item.FileCRC || item.PackSize != packSize || item.UnPackSize != unpackSize) + return S_FALSE; + } + } + catch(...) { return S_FALSE; } + return S_OK; +} + +HRESULT CInArchive::ReadCdItem(CItemEx &item) +{ + item.FromCentral = true; + item.MadeByVersion.Version = ReadByte(); + item.MadeByVersion.HostOS = ReadByte(); + item.ExtractVersion.Version = ReadByte(); + item.ExtractVersion.HostOS = ReadByte(); + item.Flags = ReadUInt16(); // & NFileHeader::NFlags::kUsedBitsMask; + item.CompressionMethod = ReadUInt16(); + item.Time = ReadUInt32(); + item.FileCRC = ReadUInt32(); + item.PackSize = ReadUInt32(); + item.UnPackSize = ReadUInt32(); + UInt16 headerNameSize = ReadUInt16(); + UInt16 headerExtraSize = ReadUInt16(); + UInt16 headerCommentSize = ReadUInt16(); + UInt32 headerDiskNumberStart = ReadUInt16(); + item.InternalAttributes = ReadUInt16(); + item.ExternalAttributes = ReadUInt32(); + item.LocalHeaderPosition = ReadUInt32(); + item.Name = ReadFileName(headerNameSize); + + if (headerExtraSize > 0) + { + ReadExtra(headerExtraSize, item.CentralExtra, item.UnPackSize, item.PackSize, + item.LocalHeaderPosition, headerDiskNumberStart); + } + + if (headerDiskNumberStart != 0) + throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported); + + // May be these strings must be deleted + /* + if (item.IsDirectory()) + item.UnPackSize = 0; + */ + + ReadBuffer(item.Comment, headerCommentSize); + return S_OK; +} - UInt32 numBytesInBuffer = 0; - UInt32 packedSize = 0; +HRESULT CInArchive::TryEcd64(UInt64 offset, CCdInfo &cdInfo) +{ + RINOK(Seek(offset)); + const UInt32 kEcd64Size = 56; + Byte buf[kEcd64Size]; + if(!ReadBytesAndTestSize(buf, kEcd64Size)) + return S_FALSE; + if (GetUInt32(buf) != NSignature::kZip64EndOfCentralDir) + return S_FALSE; + // cdInfo.NumEntries = GetUInt64(buf + 24); + cdInfo.Size = GetUInt64(buf + 40); + cdInfo.Offset = GetUInt64(buf + 48); + return S_OK; +} - bool descriptorWasFound = false; - while (true) +HRESULT CInArchive::FindCd(CCdInfo &cdInfo) +{ + UInt64 endPosition; + RINOK(m_Stream->Seek(0, STREAM_SEEK_END, &endPosition)); + const UInt32 kBufSizeMax = (1 << 16) + kEcdSize + kZip64EcdLocatorSize; + Byte buf[kBufSizeMax]; + UInt32 bufSize = (endPosition < kBufSizeMax) ? (UInt32)endPosition : kBufSizeMax; + if (bufSize < kEcdSize) + return S_FALSE; + UInt64 startPosition = endPosition - bufSize; + RINOK(m_Stream->Seek(startPosition, STREAM_SEEK_SET, &m_Position)); + if (m_Position != startPosition) + return S_FALSE; + if (!ReadBytesAndTestSize(buf, bufSize)) + return S_FALSE; + for (int i = (int)(bufSize - kEcdSize); i >= 0; i--) + { + if (GetUInt32(buf + i) == NSignature::kEndOfCentralDir) + { + if (i >= kZip64EcdLocatorSize) { - UInt32 processedSize; - RINOK(ReadBytes(buffer + numBytesInBuffer, - kBufferSize - numBytesInBuffer, &processedSize)); - numBytesInBuffer += processedSize; - if (numBytesInBuffer < NFileHeader::kDataDescriptorSize) - ThrowIncorrectArchiveException(); - UInt32 i; - for (i = 0; i <= numBytesInBuffer - NFileHeader::kDataDescriptorSize; i++) + const Byte *locator = buf + i - kZip64EcdLocatorSize; + if (GetUInt32(locator) == NSignature::kZip64EndOfCentralDirLocator) { - // descriptorSignature field is Info-ZIP's extension - // to Zip specification. - UInt32 descriptorSignature = GetUInt32(buffer + i); - - // !!!! It must be fixed for Zip64 archives - UInt32 descriptorPackSize = GetUInt32(buffer + i + 8); - if (descriptorSignature== NSignature::kDataDescriptor && - descriptorPackSize == packedSize + i) + UInt64 ecd64Offset = GetUInt64(locator + 8); + if (TryEcd64(ecd64Offset, cdInfo) == S_OK) + return S_OK; + if (TryEcd64(m_ArchiveInfo.StartPosition + ecd64Offset, cdInfo) == S_OK) { - descriptorWasFound = true; - item.FileCRC = GetUInt32(buffer + i + 4); - item.PackSize = descriptorPackSize; - item.UnPackSize = GetUInt32(buffer + i + 12); - IncreaseRealPosition(Int64(Int32(0 - (numBytesInBuffer - i - - NFileHeader::kDataDescriptorSize)))); - break; - }; + m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition; + return S_OK; + } } - if (descriptorWasFound) - break; - packedSize += i; - int j; - for (j = 0; i < numBytesInBuffer; i++, j++) - buffer[j] = buffer[i]; - numBytesInBuffer = j; + } + if (GetUInt32(buf + i + 4) == 0) + { + // cdInfo.NumEntries = GetUInt16(buf + i + 10); + cdInfo.Size = GetUInt32(buf + i + 12); + cdInfo.Offset = GetUInt32(buf + i + 16); + return S_OK; } } - else - IncreaseRealPosition(item.PackSize); + } + return S_FALSE; +} + +HRESULT CInArchive::TryReadCd(CObjectVector &items, UInt64 cdOffset, UInt64 cdSize) +{ + items.Clear(); + RINOK(m_Stream->Seek(cdOffset, STREAM_SEEK_SET, &m_Position)); + if (m_Position != cdOffset) + return S_FALSE; + while(m_Position - cdOffset < cdSize) + { + if(ReadUInt32() != NSignature::kCentralFileHeader) + return S_FALSE; + CItemEx cdItem; + RINOK(ReadCdItem(cdItem)); + items.Add(cdItem); + } + return (m_Position - cdOffset == cdSize) ? S_OK : S_FALSE; +} +HRESULT CInArchive::ReadCd(CObjectVector &items, UInt64 &cdOffset, UInt64 &cdSize) +{ + m_ArchiveInfo.Base = 0; + CCdInfo cdInfo; + RINOK(FindCd(cdInfo)); + HRESULT res = S_FALSE; + cdSize = cdInfo.Size; + cdOffset = cdInfo.Offset; + res = TryReadCd(items, m_ArchiveInfo.Base + cdOffset, cdSize); + if (res == S_FALSE && m_ArchiveInfo.Base == 0) + { + res = TryReadCd(items, cdInfo.Offset + m_ArchiveInfo.StartPosition, cdSize); + if (res == S_OK) + m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition; + } + if (!ReadUInt32(m_Signature)) + return S_FALSE; + return res; +} + +HRESULT CInArchive::ReadLocalsAndCd(CObjectVector &items, CProgressVirt *progress, UInt64 &cdOffset) +{ + items.Clear(); + while (m_Signature == NSignature::kLocalFileHeader) + { + // FSeek points to next byte after signature + // NFileHeader::CLocalBlock localHeader; + CItemEx item; + item.LocalHeaderPosition = m_Position - m_StreamStartPosition - 4; // points to signature; + RINOK(ReadLocalItem(item)); + item.FromLocal = true; + ReadLocalItemDescriptor(item); items.Add(item); if (progress != 0) { @@ -370,8 +584,7 @@ HRESULT CInArchive::ReadHeaders(CObjectVector &items, CProgressVirt *pr if (!ReadUInt32(m_Signature)) break; } - UInt64 centralDirectorySize = 0; - UInt64 centralDirectoryStartOffset = m_Position - 4; + cdOffset = m_Position - 4; for(int i = 0; i < items.Size(); i++) { if (progress != 0) @@ -379,152 +592,143 @@ HRESULT CInArchive::ReadHeaders(CObjectVector &items, CProgressVirt *pr UInt64 numItems = items.Size(); RINOK(progress->SetCompleted(&numItems)); } - // if(m_Signature == NSignature::kEndOfCentralDir) - // break; if(m_Signature != NSignature::kCentralFileHeader) - ThrowIncorrectArchiveException(); - - // NFileHeader::CBlock header; - // SafeReadBytes(&header, sizeof(header)); - - Byte headerMadeByVersionVersion = ReadByte(); - Byte headerMadeByVersionHostOS = ReadByte(); - Byte centalHeaderExtractVersionVersion = ReadByte(); - Byte centalHeaderExtractVersionHostOS = ReadByte(); - UInt16 headerFlags = ReadUInt16() & NFileHeader::NFlags::kUsedBitsMask; - UInt16 headerCompressionMethod = ReadUInt16(); - UInt32 headerTime = ReadUInt32(); - UInt32 headerFileCRC = ReadUInt32(); - UInt64 headerPackSize = ReadUInt32(); - UInt64 headerUnPackSize = ReadUInt32(); - UInt16 headerNameSize = ReadUInt16(); - UInt16 headerExtraSize = ReadUInt16(); - UInt16 headerCommentSize = ReadUInt16(); - UInt32 headerDiskNumberStart = ReadUInt16(); - UInt16 headerInternalAttributes = ReadUInt16(); - UInt32 headerExternalAttributes = ReadUInt32(); - UInt64 localHeaderOffset = ReadUInt32(); - AString centralName = ReadFileName(headerNameSize); - - // item.Name = ReadFileName(fileNameSize); + return S_FALSE; - CExtraBlock centralExtra; - if (headerExtraSize > 0) + CItemEx cdItem; + RINOK(ReadCdItem(cdItem)); + + if (i == 0) { - ReadExtra(headerExtraSize, centralExtra, headerUnPackSize, headerPackSize, localHeaderOffset, headerDiskNumberStart); + if (cdItem.LocalHeaderPosition == 0) + m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition; } - + int index; int left = 0, right = items.Size(); - while(true) + for (;;) { if (left >= right) - ThrowIncorrectArchiveException(); + return S_FALSE; index = (left + right) / 2; - UInt64 position = items[index].LocalHeaderPosition; - if (localHeaderOffset == position) + UInt64 position = items[index].LocalHeaderPosition - m_ArchiveInfo.Base; + if (cdItem.LocalHeaderPosition == position) break; - if (localHeaderOffset < position) + if (cdItem.LocalHeaderPosition < position) right = index; else left = index + 1; } CItemEx &item = items[index]; - item.MadeByVersion.Version = headerMadeByVersionVersion; - item.MadeByVersion.HostOS = headerMadeByVersionHostOS; - item.CentralExtra = centralExtra; + item.LocalHeaderPosition = cdItem.LocalHeaderPosition; + item.MadeByVersion = cdItem.MadeByVersion; + item.CentralExtra = cdItem.CentralExtra; if ( - // item.ExtractVersion != centalHeaderExtractVersion || - item.Flags != headerFlags || - item.CompressionMethod != headerCompressionMethod || - // item.Time != header.Time || - item.FileCRC != headerFileCRC) - ThrowIncorrectArchiveException(); - - if (item.Name.Length() != centralName.Length()) - ThrowIncorrectArchiveException(); // test it maybe better compare names - item.Name = centralName; - - // item.CentralExtraPosition = m_Position; - // item.CentralExtraSize = headerExtraSize; - // item.CommentSize = headerCommentSize; - if (headerDiskNumberStart != 0) - throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported); - item.InternalAttributes = headerInternalAttributes; - item.ExternalAttributes = headerExternalAttributes; - - // May be these strings must be deleted - if (item.IsDirectory()) - { - // if (item.PackSize != 0 /* || item.UnPackSize != 0 */) - // ThrowIncorrectArchiveException(); - item.UnPackSize = 0; - } + // item.ExtractVersion != cdItem.ExtractVersion || + item.Flags != cdItem.Flags || + item.CompressionMethod != cdItem.CompressionMethod || + // item.Time != cdItem.Time || + item.FileCRC != cdItem.FileCRC) + return S_FALSE; - UInt32 currentRecordSize = 4 + NFileHeader::kCentralBlockSize + - headerNameSize + headerExtraSize + headerCommentSize; + if (item.Name.Length() != cdItem.Name.Length() || + item.PackSize != cdItem.PackSize || + item.UnPackSize != cdItem.UnPackSize + ) + return S_FALSE; + item.Name = cdItem.Name; + item.InternalAttributes = cdItem.InternalAttributes; + item.ExternalAttributes = cdItem.ExternalAttributes; + item.Comment = cdItem.Comment; + item.FromCentral = cdItem.FromCentral; + if (!ReadUInt32(m_Signature)) + return S_FALSE; + } + return S_OK; +} - centralDirectorySize += currentRecordSize; +HRESULT CInArchive::ReadHeaders(CObjectVector &items, CProgressVirt *progress) +{ + // m_Signature must be kLocalFileHeaderSignature or + // kEndOfCentralDirSignature + // m_Position points to next byte after signature - // IncreaseRealPosition(headerExtraSize); + items.Clear(); + if (progress != 0) + { + UInt64 numItems = items.Size(); + RINOK(progress->SetCompleted(&numItems)); + } - if ( - item.PackSize != headerPackSize || - item.UnPackSize != headerUnPackSize - ) - ThrowIncorrectArchiveException(); + UInt64 cdSize, cdStartOffset; + HRESULT res = ReadCd(items, cdStartOffset, cdSize); + if (res != S_FALSE && res != S_OK) + return res; - // IncreaseRealPosition(headerCommentSize); - ReadBuffer(item.Comment, headerCommentSize); + /* + if (res != S_OK) + return res; + res = S_FALSE; + */ + if (res == S_FALSE) + { + m_ArchiveInfo.Base = 0; + RINOK(m_Stream->Seek(m_ArchiveInfo.StartPosition, STREAM_SEEK_SET, &m_Position)); + if (m_Position != m_ArchiveInfo.StartPosition) + return S_FALSE; if (!ReadUInt32(m_Signature)) - break; + return S_FALSE; + RINOK(ReadLocalsAndCd(items, progress, cdStartOffset)); + cdSize = (m_Position - 4) - cdStartOffset; + cdStartOffset -= m_ArchiveInfo.Base; } + UInt32 thisDiskNumber = 0; UInt32 startCDDiskNumber = 0; UInt64 numEntriesInCDOnThisDisk = 0; UInt64 numEntriesInCD = 0; - UInt64 cdSize = 0; + UInt64 cdSizeFromRecord = 0; UInt64 cdStartOffsetFromRecord = 0; bool isZip64 = false; - UInt64 zip64EndOfCDStartOffset = m_Position - 4; + UInt64 zip64EcdStartOffset = m_Position - 4 - m_ArchiveInfo.Base; if(m_Signature == NSignature::kZip64EndOfCentralDir) { isZip64 = true; UInt64 recordSize = ReadUInt64(); - UInt16 versionMade = ReadUInt16(); - UInt16 versionNeedExtract = ReadUInt16(); + /* UInt16 versionMade = */ ReadUInt16(); + /* UInt16 versionNeedExtract = */ ReadUInt16(); thisDiskNumber = ReadUInt32(); startCDDiskNumber = ReadUInt32(); numEntriesInCDOnThisDisk = ReadUInt64(); numEntriesInCD = ReadUInt64(); - cdSize = ReadUInt64(); + cdSizeFromRecord = ReadUInt64(); cdStartOffsetFromRecord = ReadUInt64(); - IncreaseRealPosition(recordSize - kZip64EndOfCentralDirRecordSize); + IncreaseRealPosition(recordSize - kZip64EcdSize); if (!ReadUInt32(m_Signature)) return S_FALSE; if (thisDiskNumber != 0 || startCDDiskNumber != 0) throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported); if (numEntriesInCDOnThisDisk != items.Size() || numEntriesInCD != items.Size() || - cdSize != centralDirectorySize || - (cdStartOffsetFromRecord != centralDirectoryStartOffset && + cdSizeFromRecord != cdSize || + (cdStartOffsetFromRecord != cdStartOffset && (!items.IsEmpty()))) - ThrowIncorrectArchiveException(); + return S_FALSE; } if(m_Signature == NSignature::kZip64EndOfCentralDirLocator) { - UInt32 startEndCDDiskNumber = ReadUInt32(); + /* UInt32 startEndCDDiskNumber = */ ReadUInt32(); UInt64 endCDStartOffset = ReadUInt64(); - UInt32 numberOfDisks = ReadUInt32(); - if (zip64EndOfCDStartOffset != endCDStartOffset) - ThrowIncorrectArchiveException(); + /* UInt32 numberOfDisks = */ ReadUInt32(); + if (zip64EcdStartOffset != endCDStartOffset) + return S_FALSE; if (!ReadUInt32(m_Signature)) return S_FALSE; } if(m_Signature != NSignature::kEndOfCentralDir) - ThrowIncorrectArchiveException(); + return S_FALSE; UInt16 thisDiskNumber16 = ReadUInt16(); if (!isZip64 || thisDiskNumber16) @@ -542,9 +746,9 @@ HRESULT CInArchive::ReadHeaders(CObjectVector &items, CProgressVirt *pr if (!isZip64 || numEntriesInCD16 != 0xFFFF) numEntriesInCD = numEntriesInCD16; - UInt32 cdSize32 = ReadUInt32(); - if (!isZip64 || cdSize32 != 0xFFFFFFFF) - cdSize = cdSize32; + UInt32 cdSizeFromRecord32 = ReadUInt32(); + if (!isZip64 || cdSizeFromRecord32 != 0xFFFFFFFF) + cdSizeFromRecord = cdSizeFromRecord32; UInt32 cdStartOffsetFromRecord32 = ReadUInt32(); if (!isZip64 || cdStartOffsetFromRecord32 != 0xFFFFFFFF) @@ -557,10 +761,10 @@ HRESULT CInArchive::ReadHeaders(CObjectVector &items, CProgressVirt *pr throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported); if ((UInt16)numEntriesInCDOnThisDisk != ((UInt16)items.Size()) || (UInt16)numEntriesInCD != ((UInt16)items.Size()) || - (UInt32)cdSize != (UInt32)centralDirectorySize || - ((UInt32)(cdStartOffsetFromRecord) != (UInt32)centralDirectoryStartOffset && + (UInt32)cdSizeFromRecord != (UInt32)cdSize || + ((UInt32)(cdStartOffsetFromRecord) != (UInt32)cdStartOffset && (!items.IsEmpty()))) - ThrowIncorrectArchiveException(); + return S_FALSE; return S_OK; } @@ -569,8 +773,9 @@ ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 siz { CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream(streamSpec); - SeekInArchive(position); - streamSpec->Init(m_Stream, size); + SeekInArchive(m_ArchiveInfo.Base + position); + streamSpec->SetStream(m_Stream); + streamSpec->Init(size); return inStream.Detach(); } diff --git a/7zip/Archive/Zip/ZipIn.h b/7zip/Archive/Zip/ZipIn.h index 8f873578..80de2272 100755 --- a/7zip/Archive/Zip/ZipIn.h +++ b/7zip/Archive/Zip/ZipIn.h @@ -33,9 +33,16 @@ public: class CInArchiveInfo { public: + UInt64 Base; UInt64 StartPosition; CByteBuffer Comment; - void Clear() { Comment.SetCapacity(0); } + CInArchiveInfo(): Base(0), StartPosition(0) {} + void Clear() + { + Base = 0; + StartPosition = 0; + Comment.SetCapacity(0); + } }; class CProgressVirt @@ -44,6 +51,13 @@ public: STDMETHOD(SetCompleted)(const UInt64 *numFiles) PURE; }; +struct CCdInfo +{ + // UInt64 NumEntries; + UInt64 Size; + UInt64 Offset; +}; + class CInArchive { CMyComPtr m_Stream; @@ -53,6 +67,8 @@ class CInArchive CInArchiveInfo m_ArchiveInfo; AString m_NameBuffer; + HRESULT Seek(UInt64 offset); + bool FindAndReadMarker(const UInt64 *searchHeaderSizeLimit); bool ReadUInt32(UInt32 &signature); AString ReadFileName(UInt32 nameSize); @@ -67,16 +83,24 @@ class CInArchive UInt64 ReadUInt64(); void IncreaseRealPosition(UInt64 addValue); - void ThrowIncorrectArchiveException(); void ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock, UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber); + HRESULT ReadLocalItem(CItemEx &item); + HRESULT ReadLocalItemDescriptor(CItemEx &item); + HRESULT ReadCdItem(CItemEx &item); + HRESULT TryEcd64(UInt64 offset, CCdInfo &cdInfo); + HRESULT FindCd(CCdInfo &cdInfo); + HRESULT TryReadCd(CObjectVector &items, UInt64 cdOffset, UInt64 cdSize); + HRESULT ReadCd(CObjectVector &items, UInt64 &cdOffset, UInt64 &cdSize); + HRESULT ReadLocalsAndCd(CObjectVector &items, CProgressVirt *progress, UInt64 &cdOffset); public: HRESULT ReadHeaders(CObjectVector &items, CProgressVirt *progress); + HRESULT ReadLocalItemAfterCdItem(CItemEx &item); + HRESULT ReadLocalItemAfterCdItemFull(CItemEx &item); bool Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit); void Close(); void GetArchiveInfo(CInArchiveInfo &archiveInfo) const; - void DirectGetBytes(void *data, UInt32 num); bool SeekInArchive(UInt64 position); ISequentialInStream *CreateLimitedStream(UInt64 position, UInt64 size); IInStream* CreateStream(); diff --git a/7zip/Archive/Zip/ZipItem.cpp b/7zip/Archive/Zip/ZipItem.cpp index 8a7fe75d..1934c357 100755 --- a/7zip/Archive/Zip/ZipItem.cpp +++ b/7zip/Archive/Zip/ZipItem.cpp @@ -19,31 +19,38 @@ bool operator!=(const CVersion &v1, const CVersion &v2) return !(v1 == v2); } -bool CItem::IsEncrypted() const +bool CLocalItem::IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncryptedMask) != 0; } -bool CItem::HasDescriptor() const +bool CLocalItem::HasDescriptor() const { return (Flags & NFileHeader::NFlags::kDescriptorUsedMask) != 0; } -bool CItem::IsImplodeBigDictionary() const +bool CLocalItem::IsImplodeBigDictionary() const { if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded) throw 12312212; return (Flags & NFileHeader::NFlags::kImplodeDictionarySizeMask) != 0; } -bool CItem::IsImplodeLiteralsOn() const +bool CLocalItem::IsImplodeLiteralsOn() const { -if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded) + if (CompressionMethod != NFileHeader::NCompressionMethod::kImploded) throw 12312213; return (Flags & NFileHeader::NFlags::kImplodeLiteralsOnMask) != 0; } static const char *kUnknownAttributes = "Unknown file attributes"; +bool CLocalItem::IsDirectory() const +{ + return NItemName::HasTailSlash(Name, GetCodePage()); +} + bool CItem::IsDirectory() const { if (NItemName::HasTailSlash(Name, GetCodePage())) return true; + if (!FromCentral) + return false; WORD highAttributes = WORD((ExternalAttributes >> 16 ) & 0xFFFF); switch(MadeByVersion.HostOS) { @@ -83,34 +90,40 @@ bool CItem::IsDirectory() const } } +UInt32 CLocalItem::GetWinAttributes() const +{ + DWORD winAttributes = 0; + if (IsDirectory()) + winAttributes |= FILE_ATTRIBUTE_DIRECTORY; + return winAttributes; +} + UInt32 CItem::GetWinAttributes() const { - DWORD winAttributes; + DWORD winAttributes = 0; switch(MadeByVersion.HostOS) { case NFileHeader::NHostOS::kFAT: case NFileHeader::NHostOS::kNTFS: - winAttributes = ExternalAttributes; + if (FromCentral) + winAttributes = ExternalAttributes; break; default: - winAttributes = 0; // must be converted from unix value;; + winAttributes = 0; // must be converted from unix value; } if (IsDirectory()) // test it; winAttributes |= FILE_ATTRIBUTE_DIRECTORY; return winAttributes; } -void CItem::ClearFlags() - { Flags = 0; } - -void CItem::SetFlagBits(int startBitNumber, int numBits, int value) +void CLocalItem::SetFlagBits(int startBitNumber, int numBits, int value) { - WORD mask = ((1 << numBits) - 1) << startBitNumber; + UInt16 mask = (UInt16)(((1 << numBits) - 1) << startBitNumber); Flags &= ~mask; Flags |= value << startBitNumber; } -void CItem::SetBitMask(int bitMask, bool enable) +void CLocalItem::SetBitMask(int bitMask, bool enable) { if(enable) Flags |= bitMask; @@ -118,7 +131,7 @@ void CItem::SetBitMask(int bitMask, bool enable) Flags &= ~bitMask; } -void CItem::SetEncrypted(bool encrypted) +void CLocalItem::SetEncrypted(bool encrypted) { SetBitMask(NFileHeader::NFlags::kEncryptedMask, encrypted); } }} diff --git a/7zip/Archive/Zip/ZipItem.h b/7zip/Archive/Zip/ZipItem.h index 92d670ce..765bfd85 100755 --- a/7zip/Archive/Zip/ZipItem.h +++ b/7zip/Archive/Zip/ZipItem.h @@ -27,6 +27,46 @@ struct CExtraSubBlock CByteBuffer Data; }; +struct CWzAesExtraField +{ + UInt16 VendorVersion; // 0x0001 - AE-1, 0x0002 - AE-2, + // UInt16 VendorId; // "AE" + Byte Strength; // 1 - 128-bit , 2 - 192-bit , 3 - 256-bit + UInt16 Method; + + CWzAesExtraField(): VendorVersion(2), Strength(3), Method(0) {} + + bool NeedCrc() const { return (VendorVersion == 1); } + + bool ParseFromSubBlock(const CExtraSubBlock &sb) + { + if (sb.ID != NFileHeader::NExtraID::kWzAES) + return false; + if (sb.Data.GetCapacity() < 7) + return false; + const Byte *p = (const Byte *)sb.Data; + VendorVersion = (((UInt16)p[1]) << 8) | p[0]; + if (p[2] != 'A' || p[3] != 'E') + return false; + Strength = p[4]; + Method = (((UInt16)p[6]) << 16) | p[5]; + return true; + } + void SetSubBlock(CExtraSubBlock &sb) const + { + sb.Data.SetCapacity(7); + sb.ID = NFileHeader::NExtraID::kWzAES; + Byte *p = (Byte *)sb.Data; + p[0] = (Byte)VendorVersion; + p[1] = (Byte)(VendorVersion >> 8); + p[2] = 'A'; + p[3] = 'E'; + p[4] = Strength; + p[5] = (Byte)Method; + p[6] = (Byte)(Method >> 8); + } +}; + struct CExtraBlock { CObjectVector SubBlocks; @@ -38,13 +78,38 @@ struct CExtraBlock res += SubBlocks[i].Data.GetCapacity() + 2 + 2; return res; } + bool GetWzAesField(CWzAesExtraField &aesField) const + { + // size_t res = 0; + for (int i = 0; i < SubBlocks.Size(); i++) + if (aesField.ParseFromSubBlock(SubBlocks[i])) + return true; + return false; + } + + bool HasWzAesField() const + { + CWzAesExtraField aesField; + return GetWzAesField(aesField); + } + + void RemoveUnknownSubBlocks() + { + for (int i = SubBlocks.Size() - 1; i >= 0;) + { + const CExtraSubBlock &subBlock = SubBlocks[i]; + if (subBlock.ID != NFileHeader::NExtraID::kWzAES) + SubBlocks.Delete(i); + else + i--; + } + } }; -class CItem +class CLocalItem { public: - CVersion MadeByVersion; CVersion ExtractVersion; UInt16 Flags; UInt16 CompressionMethod; @@ -52,16 +117,10 @@ public: UInt32 FileCRC; UInt64 PackSize; UInt64 UnPackSize; - UInt16 InternalAttributes; - UInt32 ExternalAttributes; AString Name; - - UInt64 LocalHeaderPosition; - UInt16 LocalExtraSize; - - CExtraBlock CentralExtra; - CByteBuffer Comment; + + CExtraBlock LocalExtra; bool IsEncrypted() const; @@ -74,19 +133,55 @@ public: bool HasDescriptor() const; - WORD GetCodePage() const - { - return (MadeByVersion.HostOS == NFileHeader::NHostOS::kFAT - || MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS - ) ? CP_OEMCP : CP_ACP; - } - private: void SetFlagBits(int startBitNumber, int numBits, int value); void SetBitMask(int bitMask, bool enable); public: - void ClearFlags(); + void ClearFlags() { Flags = 0; } void SetEncrypted(bool encrypted); + + WORD GetCodePage() const + { + return CP_OEMCP; + } +}; + +class CItem: public CLocalItem +{ +public: + CVersion MadeByVersion; + UInt16 InternalAttributes; + UInt32 ExternalAttributes; + + UInt64 LocalHeaderPosition; + + CExtraBlock CentralExtra; + CByteBuffer Comment; + + bool FromLocal; + bool FromCentral; + + bool IsDirectory() const; + UInt32 GetWinAttributes() const; + + bool IsThereCrc() const + { + if (CompressionMethod == NFileHeader::NCompressionMethod::kWzAES) + { + CWzAesExtraField aesField; + if (CentralExtra.GetWzAesField(aesField)) + return aesField.NeedCrc(); + } + return true; + } + + WORD GetCodePage() const + { + return (WORD)((MadeByVersion.HostOS == NFileHeader::NHostOS::kFAT + || MadeByVersion.HostOS == NFileHeader::NHostOS::kNTFS + ) ? CP_OEMCP : CP_ACP); + } + CItem() : FromLocal(false), FromCentral(false) {} }; }} diff --git a/7zip/Archive/Zip/ZipItemEx.h b/7zip/Archive/Zip/ZipItemEx.h index 3666926d..3cacc0e7 100755 --- a/7zip/Archive/Zip/ZipItemEx.h +++ b/7zip/Archive/Zip/ZipItemEx.h @@ -13,6 +13,7 @@ class CItemEx: public CItem { public: UInt32 FileHeaderWithNameSize; + UInt16 LocalExtraSize; UInt64 GetLocalFullSize() const { return FileHeaderWithNameSize + LocalExtraSize + PackSize + diff --git a/7zip/Archive/Zip/ZipOut.cpp b/7zip/Archive/Zip/ZipOut.cpp index 6e4e7335..7575d320 100755 --- a/7zip/Archive/Zip/ZipOut.cpp +++ b/7zip/Archive/Zip/ZipOut.cpp @@ -22,26 +22,28 @@ void COutArchive::MoveBasePosition(UInt64 distanceToMove) m_BasePosition += distanceToMove; // test overflow } -void COutArchive::PrepareWriteCompressedDataZip64(UInt16 fileNameLength, bool isZip64) +void COutArchive::PrepareWriteCompressedDataZip64(UInt16 fileNameLength, bool isZip64, bool aesEncryption) { m_IsZip64 = isZip64; m_ExtraSize = isZip64 ? (4 + 8 + 8) : 0; + if (aesEncryption) + m_ExtraSize += 4 + 7; m_LocalFileHeaderSize = 4 + NFileHeader::kLocalBlockSize + fileNameLength + m_ExtraSize; } -void COutArchive::PrepareWriteCompressedData(UInt16 fileNameLength, UInt64 unPackSize) +void COutArchive::PrepareWriteCompressedData(UInt16 fileNameLength, UInt64 unPackSize, bool aesEncryption) { // We test it to 0xF8000000 to support case when compressed size // can be larger than uncompressed size. - PrepareWriteCompressedDataZip64(fileNameLength, unPackSize >= 0xF8000000); + PrepareWriteCompressedDataZip64(fileNameLength, unPackSize >= 0xF8000000, aesEncryption); } -void COutArchive::PrepareWriteCompressedData2(UInt16 fileNameLength, UInt64 unPackSize, UInt64 packSize) +void COutArchive::PrepareWriteCompressedData2(UInt16 fileNameLength, UInt64 unPackSize, UInt64 packSize, bool aesEncryption) { bool isUnPack64 = unPackSize >= 0xFFFFFFFF; bool isPack64 = packSize >= 0xFFFFFFFF; bool isZip64 = isPack64 || isUnPack64; - PrepareWriteCompressedDataZip64(fileNameLength, isZip64); + PrepareWriteCompressedDataZip64(fileNameLength, isZip64, aesEncryption); } void COutArchive::WriteBytes(const void *buffer, UInt32 size) @@ -86,7 +88,21 @@ void COutArchive::WriteUInt64(UInt64 value) } } -HRESULT COutArchive::WriteLocalHeader(const CItem &item) +void COutArchive::WriteExtra(const CExtraBlock &extra) +{ + if (extra.SubBlocks.Size() != 0) + { + for (int i = 0; i < extra.SubBlocks.Size(); i++) + { + const CExtraSubBlock &subBlock = extra.SubBlocks[i]; + WriteUInt16(subBlock.ID); + WriteUInt16((UInt16)subBlock.Data.GetCapacity()); + WriteBytes(subBlock.Data, (UInt32)subBlock.Data.GetCapacity()); + } + } +} + +HRESULT COutArchive::WriteLocalHeader(const CLocalItem &item) { m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); @@ -101,29 +117,32 @@ HRESULT COutArchive::WriteLocalHeader(const CItem &item) WriteUInt32(item.FileCRC); WriteUInt32(isZip64 ? 0xFFFFFFFF: (UInt32)item.PackSize); WriteUInt32(isZip64 ? 0xFFFFFFFF: (UInt32)item.UnPackSize); - WriteUInt16(item.Name.Length()); - UInt16 localExtraSize = isZip64 ? (4 + 16): 0; - if (localExtraSize > m_ExtraSize) - return E_FAIL; - WriteUInt16(m_ExtraSize); // test it; + WriteUInt16((UInt16)item.Name.Length()); + { + UInt16 localExtraSize = (UInt16)((isZip64 ? (4 + 16): 0) + item.LocalExtra.GetSize()); + if (localExtraSize > m_ExtraSize) + return E_FAIL; + } + WriteUInt16((UInt16)m_ExtraSize); // test it; WriteBytes((const char *)item.Name, item.Name.Length()); - if (m_ExtraSize > 0) + + UInt32 extraPos = 0; + if (isZip64) { - UInt16 remain = m_ExtraSize - 4; - WriteUInt16(0x1); // Zip64 Tag; - WriteUInt16(remain); - if (isZip64) - { - WriteUInt64(item.UnPackSize); - WriteUInt64(item.PackSize); - remain -= 16; - } - for (int i = 0; i < remain; i++) - WriteByte(0); + extraPos += 4 + 16; + WriteUInt16(NFileHeader::NExtraID::kZip64); + WriteUInt16(16); + WriteUInt64(item.UnPackSize); + WriteUInt64(item.PackSize); } + + WriteExtra(item.LocalExtra); + extraPos += (UInt32)item.LocalExtra.GetSize(); + for (; extraPos < m_ExtraSize; extraPos++) + WriteByte(0); + MoveBasePosition(item.PackSize); - m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); - return S_OK; + return m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); } void COutArchive::WriteCentralHeader(const CItem &item) @@ -146,10 +165,10 @@ void COutArchive::WriteCentralHeader(const CItem &item) WriteUInt32(item.FileCRC); WriteUInt32(isPack64 ? 0xFFFFFFFF: (UInt32)item.PackSize); WriteUInt32(isUnPack64 ? 0xFFFFFFFF: (UInt32)item.UnPackSize); - WriteUInt16(item.Name.Length()); - UInt16 zip64ExtraSize = (isUnPack64 ? 8: 0) + (isPack64 ? 8: 0) + (isPosition64 ? 8: 0); - UInt16 centralExtraSize = isZip64 ? (4 + zip64ExtraSize) : 0; - centralExtraSize += (UInt16)item.CentralExtra.GetSize(); + WriteUInt16((UInt16)item.Name.Length()); + UInt16 zip64ExtraSize = (UInt16)((isUnPack64 ? 8: 0) + (isPack64 ? 8: 0) + (isPosition64 ? 8: 0)); + UInt16 centralExtraSize = (UInt16)(isZip64 ? (4 + zip64ExtraSize) : 0); + centralExtraSize = (UInt16)(centralExtraSize + item.CentralExtra.GetSize()); WriteUInt16(centralExtraSize); // test it; WriteUInt16((UInt16)item.Comment.GetCapacity()); WriteUInt16(0); // DiskNumberStart; @@ -159,7 +178,7 @@ void COutArchive::WriteCentralHeader(const CItem &item) WriteBytes((const char *)item.Name, item.Name.Length()); if (isZip64) { - WriteUInt16(0x1); // Zip64 Tag; + WriteUInt16(NFileHeader::NExtraID::kZip64); WriteUInt16(zip64ExtraSize); if(isUnPack64) WriteUInt64(item.UnPackSize); @@ -168,16 +187,7 @@ void COutArchive::WriteCentralHeader(const CItem &item) if(isPosition64) WriteUInt64(item.LocalHeaderPosition); } - if (item.CentralExtra.SubBlocks.Size() != 0) - { - for (int i = 0; i < item.CentralExtra.SubBlocks.Size(); i++) - { - CExtraSubBlock subBlock = item.CentralExtra.SubBlocks[i]; - WriteUInt16(subBlock.ID); - WriteUInt16((UInt16)subBlock.Data.GetCapacity()); - WriteBytes(subBlock.Data, (UInt32)subBlock.Data.GetCapacity()); - } - } + WriteExtra(item.CentralExtra); if (item.Comment.GetCapacity() > 0) WriteBytes(item.Comment, (UInt32)item.Comment.GetCapacity()); } @@ -199,7 +209,7 @@ void COutArchive::WriteCentralDir(const CObjectVector &items, const CByte if (isZip64) { WriteUInt32(NSignature::kZip64EndOfCentralDir); - WriteUInt64(kZip64EndOfCentralDirRecordSize); // ThisDiskNumber = 0; + WriteUInt64(kZip64EcdSize); // ThisDiskNumber = 0; WriteUInt16(45); // version WriteUInt16(45); // version WriteUInt32(0); // ThisDiskNumber = 0; @@ -217,8 +227,8 @@ void COutArchive::WriteCentralDir(const CObjectVector &items, const CByte WriteUInt32(NSignature::kEndOfCentralDir); WriteUInt16(0); // ThisDiskNumber = 0; WriteUInt16(0); // StartCentralDirectoryDiskNumber; - WriteUInt16(items64 ? 0xFFFF: (UInt16)items.Size()); - WriteUInt16(items64 ? 0xFFFF: (UInt16)items.Size()); + WriteUInt16((UInt16)(items64 ? 0xFFFF: items.Size())); + WriteUInt16((UInt16)(items64 ? 0xFFFF: items.Size())); WriteUInt32(cdSize64 ? 0xFFFFFFFF: (UInt32)cdSize); WriteUInt32(cdOffset64 ? 0xFFFFFFFF: (UInt32)cdOffset); UInt16 commentSize = (UInt16)comment.GetCapacity(); diff --git a/7zip/Archive/Zip/ZipOut.h b/7zip/Archive/Zip/ZipOut.h index 79401243..e08c306e 100755 --- a/7zip/Archive/Zip/ZipOut.h +++ b/7zip/Archive/Zip/ZipOut.h @@ -29,14 +29,15 @@ class COutArchive void WriteExtraHeader(const CItem &item); void WriteCentralHeader(const CItem &item); + void WriteExtra(const CExtraBlock &extra); public: void Create(IOutStream *outStream); void MoveBasePosition(UInt64 distanceToMove); UInt64 GetCurrentPosition() const { return m_BasePosition; }; - void PrepareWriteCompressedDataZip64(UInt16 fileNameLength, bool isZip64); - void PrepareWriteCompressedData(UInt16 fileNameLength, UInt64 unPackSize); - void PrepareWriteCompressedData2(UInt16 fileNameLength, UInt64 unPackSize, UInt64 packSize); - HRESULT WriteLocalHeader(const CItem &item); + void PrepareWriteCompressedDataZip64(UInt16 fileNameLength, bool isZip64, bool aesEncryption); + void PrepareWriteCompressedData(UInt16 fileNameLength, UInt64 unPackSize, bool aesEncryption); + void PrepareWriteCompressedData2(UInt16 fileNameLength, UInt64 unPackSize, UInt64 packSize, bool aesEncryption); + HRESULT WriteLocalHeader(const CLocalItem &item); void WriteCentralDir(const CObjectVector &items, const CByteBuffer &comment); diff --git a/7zip/Archive/Zip/ZipUpdate.cpp b/7zip/Archive/Zip/ZipUpdate.cpp index 68ed571b..349e780a 100755 --- a/7zip/Archive/Zip/ZipUpdate.cpp +++ b/7zip/Archive/Zip/ZipUpdate.cpp @@ -2,6 +2,8 @@ #include "StdAfx.h" +#include + #include "ZipUpdate.h" #include "ZipAddCommon.h" #include "ZipOut.h" @@ -10,180 +12,246 @@ #include "Common/AutoPtr.h" #include "Common/StringConvert.h" #include "Windows/Defs.h" +#include "Windows/Thread.h" #include "../../Common/ProgressUtils.h" +#ifdef COMPRESS_MT +#include "../../Common/ProgressMt.h" +#endif #include "../../Common/LimitedStreams.h" -#include "../../Compress/Copy/CopyCoder.h" +#include "../../Common/OutMemStream.h" -#include "../Common/InStreamWithCRC.h" +#include "../../Compress/Copy/CopyCoder.h" +using namespace NWindows; +using namespace NSynchronization; namespace NArchive { namespace NZip { +class CCriticalSectionLock2 +{ + CCriticalSection *_object; + void Unlock() { if (_object != 0) _object->Leave(); } +public: + CCriticalSectionLock2(): _object(0) {} + void Set(CCriticalSection &object) { _object = &object; _object->Enter(); } + ~CCriticalSectionLock2() { Unlock(); } +}; + static const Byte kMadeByHostOS = NFileHeader::NHostOS::kFAT; static const Byte kExtractHostOS = NFileHeader::NHostOS::kFAT; static const Byte kMethodForDirectory = NFileHeader::NCompressionMethod::kStored; static const Byte kExtractVersionForDirectory = NFileHeader::NCompressionMethod::kStoreExtractVersion; -static HRESULT CopyBlock(ISequentialInStream *inStream, - ISequentialOutStream *outStream, ICompressProgressInfo *progress) -{ - CMyComPtr copyCoder = new NCompress::CCopyCoder; - return copyCoder->Code(inStream, outStream, NULL, NULL, progress); -} - -HRESULT CopyBlockToArchive(ISequentialInStream *inStream, +static HRESULT CopyBlockToArchive(ISequentialInStream *inStream, COutArchive &outArchive, ICompressProgressInfo *progress) { CMyComPtr outStream; outArchive.CreateStreamForCopying(&outStream); - return CopyBlock(inStream, outStream, progress); + CMyComPtr copyCoder = new NCompress::CCopyCoder; + return copyCoder->Code(inStream, outStream, NULL, NULL, progress); } -static HRESULT WriteRange(IInStream *inStream, - COutArchive &outArchive, - const CUpdateRange &range, - IProgress *progress, - UInt64 ¤tComplexity) +static HRESULT WriteRange(IInStream *inStream, COutArchive &outArchive, + const CUpdateRange &range, ICompressProgressInfo *progress) { UInt64 position; - inStream->Seek(range.Position, STREAM_SEEK_SET, &position); + RINOK(inStream->Seek(range.Position, STREAM_SEEK_SET, &position)); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStreamLimited(streamSpec); - streamSpec->Init(inStream, range.Size); - - CLocalProgress *localProgressSpec = new CLocalProgress; - CMyComPtr localProgress = localProgressSpec; - localProgressSpec->Init(progress, true); - - CLocalCompressProgressInfo *localCompressProgressSpec = new CLocalCompressProgressInfo; - CMyComPtr compressProgress = localCompressProgressSpec; + streamSpec->SetStream(inStream); + streamSpec->Init(range.Size); - localCompressProgressSpec->Init(localProgress, ¤tComplexity, ¤tComplexity); - - HRESULT result = CopyBlockToArchive(inStreamLimited, outArchive, compressProgress); - currentComplexity += range.Size; - return result; + RINOK(CopyBlockToArchive(inStreamLimited, outArchive, progress)); + return progress->SetRatioInfo(&range.Size, &range.Size); } - -static HRESULT UpdateOneFile(IInStream *inStream, +static void SetFileHeader( COutArchive &archive, const CCompressionMethodMode &options, - CAddCommon &compressor, const CUpdateItem &updateItem, - UInt64 ¤tComplexity, - IArchiveUpdateCallback *updateCallback, - CItemEx &fileHeader, - CMyComPtr &fileInStream2) + CItem &item) { - CMyComPtr fileInStream; - if (fileInStream2) - { - RINOK(fileInStream2.QueryInterface(IID_IInStream, &fileInStream)); - } - + item.UnPackSize = updateItem.Size; bool isDirectory; - UInt64 fileSize = updateItem.Size; - fileHeader.UnPackSize = fileSize; if (updateItem.NewProperties) { isDirectory = updateItem.IsDirectory; - fileHeader.Name = updateItem.Name; - fileHeader.ExternalAttributes = updateItem.Attributes; - fileHeader.Time = updateItem.Time; + item.Name = updateItem.Name; + item.ExternalAttributes = updateItem.Attributes; + item.Time = updateItem.Time; } else - isDirectory = fileHeader.IsDirectory(); + isDirectory = item.IsDirectory(); - archive.PrepareWriteCompressedData(fileHeader.Name.Length(), fileSize); - - fileHeader.LocalHeaderPosition = archive.GetCurrentPosition(); - fileHeader.MadeByVersion.HostOS = kMadeByHostOS; - fileHeader.MadeByVersion.Version = NFileHeader::NCompressionMethod::kMadeByProgramVersion; + item.LocalHeaderPosition = archive.GetCurrentPosition(); + item.MadeByVersion.HostOS = kMadeByHostOS; + item.MadeByVersion.Version = NFileHeader::NCompressionMethod::kMadeByProgramVersion; - fileHeader.ExtractVersion.HostOS = kExtractHostOS; + item.ExtractVersion.HostOS = kExtractHostOS; - fileHeader.InternalAttributes = 0; // test it - fileHeader.ClearFlags(); - if(isDirectory) + item.InternalAttributes = 0; // test it + item.ClearFlags(); + item.SetEncrypted(!isDirectory && options.PasswordIsDefined); + if (isDirectory) { - fileHeader.ExtractVersion.Version = kExtractVersionForDirectory; - fileHeader.CompressionMethod = kMethodForDirectory; - - fileHeader.PackSize = 0; - fileHeader.FileCRC = 0; // test it + item.ExtractVersion.Version = kExtractVersionForDirectory; + item.CompressionMethod = kMethodForDirectory; + item.PackSize = 0; + item.FileCRC = 0; // test it } - else +} + +static void SetItemInfoFromCompressingResult(const CCompressingResult &compressingResult, + bool isAesMode, Byte aesKeyMode, CItem &item) +{ + item.ExtractVersion.Version = compressingResult.ExtractVersion; + item.CompressionMethod = compressingResult.Method; + item.FileCRC = compressingResult.CRC; + item.UnPackSize = compressingResult.UnpackSize; + item.PackSize = compressingResult.PackSize; + + item.LocalExtra.Clear(); + item.CentralExtra.Clear(); + + if (isAesMode) { - { - CSequentialInStreamWithCRC *inSecStreamSpec = 0; - CInStreamWithCRC *inStreamSpec = 0; - CMyComPtr fileSecInStream; - if (fileInStream) - { - inStreamSpec = new CInStreamWithCRC; - fileSecInStream = inStreamSpec; - inStreamSpec->Init(fileInStream); - } - else - { - inSecStreamSpec = new CSequentialInStreamWithCRC; - fileSecInStream = inSecStreamSpec; - inSecStreamSpec->Init(fileInStream2); - } + CWzAesExtraField wzAesField; + wzAesField.Strength = aesKeyMode; + wzAesField.Method = compressingResult.Method; + item.CompressionMethod = NFileHeader::NCompressionMethod::kWzAES; + item.FileCRC = 0; + CExtraSubBlock sb; + wzAesField.SetSubBlock(sb); + item.LocalExtra.SubBlocks.Add(sb); + item.CentralExtra.SubBlocks.Add(sb); + } +} - CCompressingResult compressingResult; - CMyComPtr outStream; - archive.CreateStreamForCompressing(&outStream); +#ifdef COMPRESS_MT - CLocalProgress *localProgressSpec = new CLocalProgress; - CMyComPtr localProgress = localProgressSpec; - localProgressSpec->Init(updateCallback, true); +static DWORD WINAPI CoderThread(void *threadCoderInfo); + +struct CThreadInfo +{ + NWindows::CThread Thread; + CAutoResetEvent *CompressEvent; + CAutoResetEvent *CompressionCompletedEvent; + bool ExitThread; + + CMtCompressProgress *ProgressSpec; + CMyComPtr Progress; + + COutMemStream *OutStreamSpec; + CMyComPtr OutStream; + CMyComPtr InStream; + + CAddCommon Coder; + HRESULT Result; + CCompressingResult CompressingResult; + + bool IsFree; + UInt32 UpdateIndex; + + CThreadInfo(const CCompressionMethodMode &options): + CompressEvent(NULL), + CompressionCompletedEvent(NULL), + ExitThread(false), + ProgressSpec(0), + OutStreamSpec(0), + Coder(options) + {} - CLocalCompressProgressInfo *localCompressProgressSpec = new CLocalCompressProgressInfo; - CMyComPtr compressProgress = localCompressProgressSpec; + void CreateEvents() + { + CompressEvent = new CAutoResetEvent(false); + CompressionCompletedEvent = new CAutoResetEvent(false); + } + bool CreateThread() { return Thread.Create(CoderThread, this); } + ~CThreadInfo(); - localCompressProgressSpec->Init(localProgress, ¤tComplexity, NULL); + void WaitAndCode(); + void StopWaitClose() + { + ExitThread = true; + if (OutStreamSpec != 0) + OutStreamSpec->StopWriting(E_ABORT); + if (CompressEvent != NULL) + CompressEvent->Set(); + Thread.Wait(); + Thread.Close(); + } - RINOK(compressor.Compress(fileSecInStream, outStream, fileSize, compressProgress, compressingResult)); +}; - fileHeader.PackSize = compressingResult.PackSize; - fileHeader.CompressionMethod = compressingResult.Method; - fileHeader.ExtractVersion.Version = compressingResult.ExtractVersion; - if (inStreamSpec != 0) - { - fileHeader.FileCRC = inStreamSpec->GetCRC(); - fileHeader.UnPackSize = inStreamSpec->GetSize(); - } - else - { - fileHeader.FileCRC = inSecStreamSpec->GetCRC(); - fileHeader.UnPackSize = inSecStreamSpec->GetSize(); - } - } - } - fileHeader.SetEncrypted(!isDirectory && options.PasswordIsDefined); - /* - fileHeader.CommentSize = (updateItem.Commented) ? - WORD(updateItem.CommentRange.Size) : 0; - */ +CThreadInfo::~CThreadInfo() +{ + if (CompressEvent != NULL) + delete CompressEvent; + if (CompressionCompletedEvent != NULL) + delete CompressionCompletedEvent; +} - fileHeader.LocalExtraSize = 0; - - // fileHeader.CentralExtraSize = 0; +void CThreadInfo::WaitAndCode() +{ + for (;;) + { + CompressEvent->Lock(); + if (ExitThread) + return; + Result = Coder.Compress(InStream, OutStream, Progress, CompressingResult); + if (Result == S_OK && Progress) + Result = Progress->SetRatioInfo(&CompressingResult.UnpackSize, &CompressingResult.PackSize); + CompressionCompletedEvent->Set(); + } +} - RINOK(archive.WriteLocalHeader(fileHeader)); - currentComplexity += fileSize; - return updateCallback->SetOperationResult( - NArchive::NUpdate::NOperationResult::kOK); +static DWORD WINAPI CoderThread(void *threadCoderInfo) +{ + ((CThreadInfo *)threadCoderInfo)->WaitAndCode(); + return 0; } +class CThreads +{ +public: + CObjectVector Threads; + ~CThreads() + { + for (int i = 0; i < Threads.Size(); i++) + Threads[i].StopWaitClose(); + } +}; + +struct CMemBlocks2: public CMemLockBlocks +{ + CCompressingResult CompressingResult; + bool Defined; + bool Skip; + CMemBlocks2(): Defined(false), Skip(false) {} +}; + +class CMemRefs +{ +public: + CMemBlockManagerMt *Manager; + CObjectVector Refs; + CMemRefs(CMemBlockManagerMt *manager): Manager(manager) {} ; + ~CMemRefs() + { + for (int i = 0; i < Refs.Size(); i++) + Refs[i].FreeOpt(Manager); + } +}; + +#endif + static HRESULT Update2(COutArchive &archive, + CInArchive *inArchive, IInStream *inStream, const CObjectVector &inputItems, const CObjectVector &updateItems, @@ -192,6 +260,8 @@ static HRESULT Update2(COutArchive &archive, IArchiveUpdateCallback *updateCallback) { UInt64 complexity = 0; + UInt64 numFilesToCompress = 0; + UInt64 numBytesToCompress = 0; int i; for(i = 0; i < updateItems.Size(); i++) @@ -200,6 +270,8 @@ static HRESULT Update2(COutArchive &archive, if (updateItem.NewData) { complexity += updateItem.Size; + numBytesToCompress += updateItem.Size; + numFilesToCompress++; /* if (updateItem.Commented) complexity += updateItem.CommentRange.Size; @@ -207,7 +279,9 @@ static HRESULT Update2(COutArchive &archive, } else { - const CItemEx &inputItem = inputItems[updateItem.IndexInArchive]; + CItemEx inputItem = inputItems[updateItem.IndexInArchive]; + if (inArchive->ReadLocalItemAfterCdItemFull(inputItem) != S_OK) + return E_NOTIMPL; complexity += inputItem.GetLocalFullSize(); // complexity += inputItem.GetCentralExtraPlusCommentSize(); } @@ -217,51 +291,345 @@ static HRESULT Update2(COutArchive &archive, if (comment != 0) complexity += comment.GetCapacity(); - complexity++; // end of central - updateCallback->SetTotal(complexity); - CMyAutoPtr compressor; + + CAddCommon compressor(*options); complexity = 0; CObjectVector items; - CRecordVector updateIndices; - for(i = 0; i < updateItems.Size(); i++) + CLocalProgress *localProgressSpec = new CLocalProgress; + CMyComPtr localProgress = localProgressSpec; + localProgressSpec->Init(updateCallback, true); + + CLocalCompressProgressInfo *localCompressProgressSpec = new CLocalCompressProgressInfo; + CMyComPtr compressProgress = localCompressProgressSpec; + + + #ifdef COMPRESS_MT + + const size_t kNumMaxThreads = (1 << 10); + UInt32 numThreads = options->NumThreads; + if (numThreads > kNumMaxThreads) + numThreads = kNumMaxThreads; + + const size_t kMemPerThread = (1 << 25); + const size_t kBlockSize = 1 << 16; + + CCompressionMethodMode options2; + if (options != 0) + options2 = *options; + + bool mtMode = ((options != 0) && (numThreads > 1)); + + if (numFilesToCompress <= 1) + mtMode = false; + + if (mtMode) { - const CUpdateItem &updateItem = updateItems[i]; - RINOK(updateCallback->SetCompleted(&complexity)); + Byte method = options->MethodSequence.Front(); + if (method == NFileHeader::NCompressionMethod::kStored && !options->PasswordIsDefined) + mtMode = false; + if (method == NFileHeader::NCompressionMethod::kBZip2) + { + UInt64 averageSize = numBytesToCompress / numFilesToCompress; + UInt32 blockSize = options->DicSize; + if (blockSize == 0) + blockSize = 1; + UInt64 averageNumberOfBlocks = averageSize / blockSize; + UInt32 numBZip2Threads = 32; + if (averageNumberOfBlocks < numBZip2Threads) + numBZip2Threads = (UInt32)averageNumberOfBlocks; + if (numBZip2Threads < 1) + numBZip2Threads = 1; + numThreads = numThreads / numBZip2Threads; + options2.NumThreads = numBZip2Threads; + if (numThreads <= 1) + mtMode = false; + } + } + + + CMtCompressProgressMixer mtCompressProgressMixer; + mtCompressProgressMixer.Init(numThreads + 1, localProgress); + + // we need one item for main stream + CMtCompressProgress *progressMainSpec = new CMtCompressProgress(); + CMyComPtr progressMain = progressMainSpec; + progressMainSpec->Init(&mtCompressProgressMixer, (int)numThreads); + + CMemBlockManagerMt memManager(kBlockSize); + CMemRefs refs(&memManager); + + CThreads threads; + CRecordVector compressingCompletedEvents; + CRecordVector threadIndices; // list threads in order of updateItems + + if (mtMode) + { + if (!memManager.AllocateSpaceAlways((size_t)numThreads * (kMemPerThread / kBlockSize))) + return E_OUTOFMEMORY; + for(i = 0; i < updateItems.Size(); i++) + refs.Refs.Add(CMemBlocks2()); + + UInt32 i; + for (i = 0; i < numThreads; i++) + threads.Threads.Add(CThreadInfo(options2)); + + for (i = 0; i < numThreads; i++) + { + CThreadInfo &threadInfo = threads.Threads[i]; + threadInfo.CreateEvents(); + threadInfo.OutStreamSpec = new COutMemStream(&memManager); + threadInfo.OutStream = threadInfo.OutStreamSpec; + threadInfo.IsFree = true; + threadInfo.ProgressSpec = new CMtCompressProgress(); + threadInfo.Progress = threadInfo.ProgressSpec; + threadInfo.ProgressSpec->Init(&mtCompressProgressMixer, (int)i); + if (!threadInfo.CreateThread()) + return ::GetLastError(); + } + } + int mtItemIndex = 0; + + #endif + + int itemIndex = 0; + int lastRealStreamItemIndex = -1; + + while(itemIndex < updateItems.Size()) + { + #ifdef COMPRESS_MT + if (!mtMode) + #endif + { + RINOK(updateCallback->SetCompleted(&complexity)); + } + + #ifdef COMPRESS_MT + if (mtMode && (UInt32)threadIndices.Size() < numThreads && mtItemIndex < updateItems.Size()) + { + const CUpdateItem &updateItem = updateItems[mtItemIndex++]; + if (!updateItem.NewData) + continue; + CItemEx item; + if (updateItem.NewProperties) + { + if (updateItem.IsDirectory) + continue; + } + else + { + item = inputItems[updateItem.IndexInArchive]; + if (inArchive->ReadLocalItemAfterCdItemFull(item) != S_OK) + return E_NOTIMPL; + if (item.IsDirectory()) + continue; + } + CMyComPtr fileInStream; + { + NWindows::NSynchronization::CCriticalSectionLock lock(mtCompressProgressMixer.CriticalSection); + HRESULT res = updateCallback->GetStream(updateItem.IndexInClient, &fileInStream); + if (res == S_FALSE) + { + complexity += updateItem.Size; + complexity++; + RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); + refs.Refs[mtItemIndex - 1].Skip = true; + continue; + } + RINOK(res); + RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); + } + + for (UInt32 i = 0; i < numThreads; i++) + { + CThreadInfo &threadInfo = threads.Threads[i]; + if (threadInfo.IsFree) + { + threadInfo.IsFree = false; + threadInfo.InStream = fileInStream; + threadInfo.OutStreamSpec->Init(); + threadInfo.ProgressSpec->Reinit(); + threadInfo.CompressEvent->Set(); + threadInfo.UpdateIndex = mtItemIndex - 1; + + compressingCompletedEvents.Add(*threadInfo.CompressionCompletedEvent); + threadIndices.Add(i); + break; + } + } + continue; + } + if (mtMode) + if (refs.Refs[itemIndex].Skip) + { + itemIndex++; + continue; + } + #endif + + const CUpdateItem &updateItem = updateItems[itemIndex]; CItemEx item; if (!updateItem.NewProperties || !updateItem.NewData) + { item = inputItems[updateItem.IndexInArchive]; + if (inArchive->ReadLocalItemAfterCdItemFull(item) != S_OK) + return E_NOTIMPL; + } + + + bool isDirectory; + if (updateItem.NewProperties) + isDirectory = updateItem.IsDirectory; + else + isDirectory = item.IsDirectory(); if (updateItem.NewData) { - if(compressor.get() == NULL) + #ifdef COMPRESS_MT + if (mtMode && !isDirectory) { - CMyAutoPtr tmp(new CAddCommon(*options)); - compressor = tmp; + if (lastRealStreamItemIndex < itemIndex) + { + lastRealStreamItemIndex = itemIndex; + SetFileHeader(archive, *options, updateItem, item); + // file Size can be 64-bit !!! + archive.PrepareWriteCompressedData((UInt16)item.Name.Length(), updateItem.Size, options->IsAesMode); + } + + CMemBlocks2 &memRef = refs.Refs[itemIndex]; + if (memRef.Defined) + { + CMyComPtr outStream; + archive.CreateStreamForCompressing(&outStream); + memRef.WriteToStream(memManager.GetBlockSize(), outStream); + SetItemInfoFromCompressingResult(memRef.CompressingResult, + options->IsAesMode, options->AesKeyMode, item); + SetFileHeader(archive, *options, updateItem, item); + RINOK(archive.WriteLocalHeader(item)); + complexity += item.UnPackSize; + // RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); + memRef.FreeOpt(&memManager); + } + else + { + { + CThreadInfo &thread = threads.Threads[threadIndices.Front()]; + if (!thread.OutStreamSpec->WasUnlockEventSent()) + { + CMyComPtr outStream; + archive.CreateStreamForCompressing(&outStream); + thread.OutStreamSpec->SetOutStream(outStream); + thread.OutStreamSpec->SetRealStreamMode(); + } + } + + DWORD result = ::WaitForMultipleObjects(compressingCompletedEvents.Size(), + &compressingCompletedEvents.Front(), FALSE, INFINITE); + int t = (int)(result - WAIT_OBJECT_0); + CThreadInfo &threadInfo = threads.Threads[threadIndices[t]]; + threadInfo.InStream.Release(); + threadInfo.IsFree = true; + RINOK(threadInfo.Result); + threadIndices.Delete(t); + compressingCompletedEvents.Delete(t); + if (t == 0) + { + RINOK(threadInfo.OutStreamSpec->WriteToRealStream()); + threadInfo.OutStreamSpec->ReleaseOutStream(); + SetItemInfoFromCompressingResult(threadInfo.CompressingResult, + options->IsAesMode, options->AesKeyMode, item); + SetFileHeader(archive, *options, updateItem, item); + RINOK(archive.WriteLocalHeader(item)); + complexity += item.UnPackSize; + } + else + { + CMemBlocks2 &memRef = refs.Refs[threadInfo.UpdateIndex]; + threadInfo.OutStreamSpec->DetachData(memRef); + memRef.CompressingResult = threadInfo.CompressingResult; + memRef.Defined = true; + continue; + } + } } - CMyComPtr fileInStream2; - HRESULT res = updateCallback->GetStream(updateItem.IndexInClient, &fileInStream2); - if (res == S_FALSE) + else + #endif { - complexity += updateItem.Size; - complexity++; - RINOK(updateCallback->SetOperationResult( - NArchive::NUpdate::NOperationResult::kOK)); - continue; + { + CMyComPtr fileInStream; + { + #ifdef COMPRESS_MT + CCriticalSectionLock2 lock; + if (mtMode) + lock.Set(mtCompressProgressMixer.CriticalSection); + #endif + HRESULT res = updateCallback->GetStream(updateItem.IndexInClient, &fileInStream); + if (res == S_FALSE) + { + complexity += updateItem.Size; + complexity++; + RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); + itemIndex++; + continue; + } + RINOK(res); + + #ifdef COMPRESS_MT + if (mtMode) + { + RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); + } + #endif + } + // file Size can be 64-bit !!! + SetFileHeader(archive, *options, updateItem, item); + archive.PrepareWriteCompressedData((UInt16)item.Name.Length(), updateItem.Size, options->IsAesMode); + + if(!isDirectory) + { + CCompressingResult compressingResult; + CMyComPtr outStream; + archive.CreateStreamForCompressing(&outStream); + + localCompressProgressSpec->Init(localProgress, &complexity, NULL); + + RINOK(compressor.Compress(fileInStream, outStream, compressProgress, compressingResult)); + + SetItemInfoFromCompressingResult(compressingResult, + options->IsAesMode, options->AesKeyMode, item); + } + } + RINOK(archive.WriteLocalHeader(item)); + complexity += item.UnPackSize; + #ifdef COMPRESS_MT + if (!mtMode) + #endif + { + RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); + } } - RINOK(res); - RINOK(UpdateOneFile(inStream, archive, *options, - *compressor, updateItem, complexity, updateCallback, item, - fileInStream2)); } else { // item = inputItems[copyIndices[copyIndexIndex++]]; + + #ifdef COMPRESS_MT + if (mtMode) + progressMainSpec->Reinit(); + #endif + + localCompressProgressSpec->Init(localProgress, &complexity, NULL); + ICompressProgressInfo *progress = compressProgress; + #ifdef COMPRESS_MT + if (mtMode) + progress = progressMain; + #endif + if (updateItem.NewProperties) { if (item.HasDescriptor()) @@ -275,13 +643,14 @@ static HRESULT Update2(COutArchive &archive, // Test it item.Name = updateItem.Name; item.Time = updateItem.Time; - item.CentralExtra.Clear(); - item.LocalExtraSize = 0; + item.CentralExtra.RemoveUnknownSubBlocks(); + item.LocalExtra.RemoveUnknownSubBlocks(); - archive.PrepareWriteCompressedData2(item.Name.Length(), item.UnPackSize, item.PackSize); + archive.PrepareWriteCompressedData2((UInt16)item.Name.Length(), item.UnPackSize, item.PackSize, item.LocalExtra.HasWzAesField()); item.LocalHeaderPosition = archive.GetCurrentPosition(); archive.SeekToPackedDataPosition(); - RINOK(WriteRange(inStream, archive, range, updateCallback, complexity)); + RINOK(WriteRange(inStream, archive, range, progress)); + complexity += range.Size; archive.WriteLocalHeader(item); } else @@ -291,15 +660,15 @@ static HRESULT Update2(COutArchive &archive, // set new header position item.LocalHeaderPosition = archive.GetCurrentPosition(); - RINOK(WriteRange(inStream, archive, range, updateCallback, complexity)); + RINOK(WriteRange(inStream, archive, range, progress)); + complexity += range.Size; archive.MoveBasePosition(range.Size); } } items.Add(item); - updateIndices.Add(i); complexity += NFileHeader::kLocalBlockSize; + itemIndex++; } - archive.WriteCentralDir(items, comment); return S_OK; } @@ -319,7 +688,11 @@ HRESULT Update( CInArchiveInfo archiveInfo; if(inArchive != 0) + { inArchive->GetArchiveInfo(archiveInfo); + if (archiveInfo.Base != 0) + return E_NOTIMPL; + } else archiveInfo.StartPosition = 0; @@ -336,7 +709,7 @@ HRESULT Update( if(inArchive != 0) inStream.Attach(inArchive->CreateStream()); - return Update2(outArchive, inStream, + return Update2(outArchive, inArchive, inStream, inputItems, updateItems, compressionMethodMode, archiveInfo.Comment, updateCallback); diff --git a/7zip/Archive/Zip/ZipUpdate.h b/7zip/Archive/Zip/ZipUpdate.h index c8cdfbbf..d846b05f 100755 --- a/7zip/Archive/Zip/ZipUpdate.h +++ b/7zip/Archive/Zip/ZipUpdate.h @@ -36,6 +36,7 @@ struct CUpdateItem AString Name; // bool Commented; // CUpdateRange CommentRange; + CUpdateItem(): Size(0) {} }; HRESULT Update( diff --git a/7zip/Archive/Zip/makefile b/7zip/Archive/Zip/makefile index cb50a884..eaf1031f 100755 --- a/7zip/Archive/Zip/makefile +++ b/7zip/Archive/Zip/makefile @@ -17,7 +17,6 @@ ZIP_OBJS = \ COMMON_OBJS = \ $O\Alloc.obj \ $O\CRC.obj \ - $O\Random.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ $O\String.obj \ @@ -29,13 +28,17 @@ WIN_OBJS = \ $O\DLL.obj \ $O\FileFind.obj \ $O\PropVariant.obj \ + $O\Synchronization.obj \ 7ZIP_COMMON_OBJS = \ $O\InBuffer.obj \ $O\LimitedStreams.obj \ $O\LSBFDecoder.obj \ + $O\MemBlocks.obj \ $O\OffsetStream.obj \ $O\OutBuffer.obj \ + $O\OutMemStream.obj \ + $O\ProgressMt.obj \ $O\ProgressUtils.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ @@ -60,6 +63,15 @@ IMPLODE_OBJS = \ SHRINK_OBJS = \ $O\ShrinkDecoder.obj \ +CRYPTO_HASH_OBJS = \ + $O\HmacSha1.obj \ + $O\Pbkdf2HmacSha1.obj \ + $O\RandGen.obj \ + $O\Sha1.obj \ + +CRYPTO_WZAES_OBJS = \ + $O\WzAES.obj \ + CRYPTO_ZIP_OBJS = \ $O\ZipCipher.obj \ $O\ZipCrypto.obj \ @@ -73,6 +85,8 @@ OBJS = \ $(7ZIP_COMMON_OBJS) \ $(AR_COMMON_OBJS) \ $(7Z_OBJS) \ + $(CRYPTO_HASH_OBJS) \ + $(CRYPTO_WZAES_OBJS) \ $(CRYPTO_ZIP_OBJS) \ $(IMPLODE_OBJS) \ $(SHRINK_OBJS) \ @@ -94,8 +108,12 @@ $(AR_COMMON_OBJS): ../Common/$(*B).cpp $(COMPL) $(7Z_OBJS): ../7z/$(*B).cpp $(COMPL) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL_O2) $(CRYPTO_ZIP_OBJS): ../../Crypto/Zip/$(*B).cpp $(COMPL) +$(CRYPTO_WZAES_OBJS): ../../Crypto/WzAES/$(*B).cpp + $(COMPL_O2) $(IMPLODE_OBJS): ../../Compress/Implode/$(*B).cpp $(COMPL) $(SHRINK_OBJS): ../../Compress/Shrink/$(*B).cpp diff --git a/7zip/Archive/cpio/CpioHandler.cpp b/7zip/Archive/cpio/CpioHandler.cpp index 1787402d..601afbd6 100755 --- a/7zip/Archive/cpio/CpioHandler.cpp +++ b/7zip/Archive/cpio/CpioHandler.cpp @@ -44,7 +44,7 @@ STATPROPSTG kProperties[] = // { L"CheckSum", kpidiChkSum, VT_UI4} }; -STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +STDMETHODIMP CHandler::GetArchiveProperty(PROPID /* propID */, PROPVARIANT *value) { value->vt = VT_EMPTY; return S_OK; @@ -74,18 +74,17 @@ STDMETHODIMP CHandler::GetNumberOfArchiveProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 index, - BSTR *name, PROPID *propID, VARTYPE *varType) +STDMETHODIMP CHandler::GetArchivePropertyInfo(UInt32 /* index */, + BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) { return E_INVALIDARG; } STDMETHODIMP CHandler::Open(IInStream *inStream, - const UInt64 *maxCheckStartPosition, + const UInt64 * /* maxCheckStartPosition */, IArchiveOpenCallback *openArchiveCallback) { COM_TRY_BEGIN - bool mustBeClosed = true; // try { CInArchive archive; @@ -102,7 +101,7 @@ STDMETHODIMP CHandler::Open(IInStream *inStream, RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL)); } - while(true) + for (;;) { CItemEx itemInfo; bool filled; @@ -251,7 +250,8 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems, RINOK(m_InStream->Seek(itemInfo.GetDataPosition(), STREAM_SEEK_SET, NULL)); CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; CMyComPtr inStream(streamSpec); - streamSpec->Init(m_InStream, itemInfo.Size); + streamSpec->SetStream(m_InStream); + streamSpec->Init(itemInfo.Size); CLocalProgress *localProgressSpec = new CLocalProgress; CMyComPtr progress = localProgressSpec; diff --git a/7zip/Archive/cpio/CpioIn.cpp b/7zip/Archive/cpio/CpioIn.cpp index 32b9f77d..91399362 100755 --- a/7zip/Archive/cpio/CpioIn.cpp +++ b/7zip/Archive/cpio/CpioIn.cpp @@ -112,7 +112,7 @@ static unsigned short ConvertValue(unsigned short value, bool convert) { if (!convert) return value; - return (((unsigned short)(value & 0xFF)) << 8) | (value >> 8); + return (unsigned short)((((unsigned short)(value & 0xFF)) << 8) | (value >> 8)); } static UInt32 GetAlignedSize(UInt32 size, UInt32 align) diff --git a/7zip/Archive/cpio/DllExports.cpp b/7zip/Archive/cpio/DllExports.cpp index 32473235..8eb38bfd 100755 --- a/7zip/Archive/cpio/DllExports.cpp +++ b/7zip/Archive/cpio/DllExports.cpp @@ -13,9 +13,9 @@ DEFINE_GUID(CLSID_CCpioHandler, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xED, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject( diff --git a/7zip/Bundles/Alone/Alone.dsp b/7zip/Bundles/Alone/Alone.dsp index 4ad83675..42ce825c 100755 --- a/7zip/Bundles/Alone/Alone.dsp +++ b/7zip/Bundles/Alone/Alone.dsp @@ -597,6 +597,10 @@ SOURCE=..\..\Common\LSBFEncoder.h # End Source File # Begin Source File +SOURCE=..\..\Common\MemBlocks.cpp +# End Source File +# Begin Source File + SOURCE=..\..\Common\MSBFDecoder.h # End Source File # Begin Source File @@ -621,6 +625,22 @@ SOURCE=..\..\Common\OutBuffer.h # End Source File # Begin Source File +SOURCE=..\..\Common\OutMemStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OutMemStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressMt.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressMt.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\ProgressUtils.cpp # End Source File # Begin Source File @@ -2043,13 +2063,25 @@ SOURCE=..\..\Crypto\7zAES\7zAES.cpp SOURCE=..\..\Crypto\7zAES\7zAES.h # End Source File +# End Group +# Begin Group "WzAES" + +# PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\7zAES\MySHA256.h +SOURCE=..\..\Crypto\WzAES\WzAES.cpp # End Source File # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.cpp +SOURCE=..\..\Crypto\WzAES\WzAES.h +# End Source File +# End Group +# Begin Group "Hash" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Crypto\Hash\HmacSha1.cpp !IF "$(CFG)" == "Alone - Win32 Release" @@ -2060,9 +2092,72 @@ SOURCE=..\..\Crypto\7zAES\SHA256.cpp !ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\HmacSha1.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Pbkdf2HmacSha1.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + # ADD CPP /O2 # SUBTRACT CPP /YX /Yc /Yu +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Pbkdf2HmacSha1.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha1.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha1.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha256.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + !ELSEIF "$(CFG)" == "Alone - Win32 DebugU" !ENDIF @@ -2070,7 +2165,7 @@ SOURCE=..\..\Crypto\7zAES\SHA256.cpp # End Source File # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.h +SOURCE=..\..\Crypto\Hash\Sha256.h # End Source File # End Group # End Group diff --git a/7zip/Bundles/Alone/makefile b/7zip/Bundles/Alone/makefile index 72832de1..e14b1104 100755 --- a/7zip/Bundles/Alone/makefile +++ b/7zip/Bundles/Alone/makefile @@ -46,7 +46,6 @@ COMMON_OBJS = \ $O\IntToString.obj \ $O\ListFileUtils.obj \ $O\NewHandler.obj \ - $O\Random.obj \ $O\StdInStream.obj \ $O\StdOutStream.obj \ $O\String.obj \ @@ -77,8 +76,11 @@ WIN_OBJS = \ $O\LockedStream.obj \ $O\LSBFDecoder.obj \ $O\LSBFEncoder.obj \ + $O\MemBlocks.obj \ $O\OffsetStream.obj \ $O\OutBuffer.obj \ + $O\OutMemStream.obj \ + $O\ProgressMt.obj \ $O\ProgressUtils.obj \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ @@ -215,7 +217,6 @@ COMPRESS_Z_OBJS = \ 7ZAES_OPT_OBJS = \ $O\7zAES.obj \ - $O\SHA256.obj \ AES_OPT_OBJS = \ $O\MyAES.obj \ @@ -225,10 +226,21 @@ AES_ORIG_OBJS = \ $O\aeskey.obj \ $O\aestab.obj \ +CRYPTO_HASH_OBJS = \ + $O\HmacSha1.obj \ + $O\Pbkdf2HmacSha1.obj \ + $O\RandGen.obj \ + $O\Sha1.obj \ + $O\Sha256.obj \ + +CRYPTO_WZAES_OBJS = \ + $O\WzAES.obj \ + CRYPTO_ZIP_OBJS = \ $O\ZipCipher.obj \ $O\ZipCrypto.obj \ + OBJS = \ $O\StdAfx.obj \ $(CONSOLE_OBJS) \ @@ -262,7 +274,9 @@ OBJS = \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ $(AES_ORIG_OBJS) \ + $(CRYPTO_HASH_OBJS) \ $(CRYPTO_ZIP_OBJS) \ + $(CRYPTO_WZAES_OBJS) \ $O\resource.res @@ -332,8 +346,12 @@ $O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) $(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2) + $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL_O2) $(CRYPTO_ZIP_OBJS): ../../Crypto/Zip/$(*B).cpp $(COMPL) +$(CRYPTO_WZAES_OBJS): ../../Crypto/WzAES/$(*B).cpp + $(COMPL_O2) diff --git a/7zip/Bundles/Alone7z/Alone.dsp b/7zip/Bundles/Alone7z/Alone.dsp new file mode 100755 index 00000000..758fb198 --- /dev/null +++ b/7zip/Bundles/Alone7z/Alone.dsp @@ -0,0 +1,1366 @@ +# Microsoft Developer Studio Project File - Name="Alone" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Alone - Win32 DebugU +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "Alone.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "Alone.mak" CFG="Alone - Win32 DebugU" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Alone - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Alone - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "Alone - Win32 ReleaseU" (based on "Win32 (x86) Console Application") +!MESSAGE "Alone - Win32 DebugU" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Alone - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /Gz /MT /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMFORMAT_SPLIT" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /Yu"StdAfx.h" /FD /c +# ADD BASE RSC /l 0x419 /d "NDEBUG" +# ADD RSC /l 0x419 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\UTIL\7za.exe" /opt:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /Gz /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMFORMAT_SPLIT" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /Yu"StdAfx.h" /FD /GZ /c +# ADD BASE RSC /l 0x419 /d "_DEBUG" +# ADD RSC /l 0x419 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7za.exe" /pdbtype:sept + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ReleaseU" +# PROP BASE Intermediate_Dir "ReleaseU" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "ReleaseU" +# PROP Intermediate_Dir "ReleaseU" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMAT_BZIP2" /D "FORMAT_ZIP" /D "FORMAT_TAR" /D "FORMAT_GZIP" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_BT" /D "COMPRESS_PPMD" /D "COMPRESS_DEFLATE" /D "COMPRESS_IMPLODE" /D "COMPRESS_BZIP2" /D "CRYPTO_ZIP" /Yu"StdAfx.h" /FD /c +# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMFORMAT_SPLIT" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /Yu"StdAfx.h" /FD /c +# ADD BASE RSC /l 0x419 /d "NDEBUG" +# ADD RSC /l 0x419 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\UTIL\7za.exe" /opt:NOWIN98 +# SUBTRACT BASE LINK32 /pdb:none +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"c:\UTIL\7zan.exe" /opt:NOWIN98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "DebugU" +# PROP BASE Intermediate_Dir "DebugU" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "DebugU" +# PROP Intermediate_Dir "DebugU" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMAT_BZIP2" /D "FORMAT_ZIP" /D "FORMAT_TAR" /D "FORMAT_GZIP" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_BT" /D "COMPRESS_PPMD" /D "COMPRESS_DEFLATE" /D "COMPRESS_IMPLODE" /D "COMPRESS_BZIP2" /D "CRYPTO_ZIP" /D "_MBCS" /Yu"StdAfx.h" /FD /GZ /c +# ADD CPP /nologo /Gz /W4 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMFORMAT_SPLIT" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_MT" /D "COMPRESS_MT" /Yu"StdAfx.h" /FD /GZ /c +# ADD BASE RSC /l 0x419 /d "_DEBUG" +# ADD RSC /l 0x419 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7za.exe" /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7zan.exe" /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "Alone - Win32 Release" +# Name "Alone - Win32 Debug" +# Name "Alone - Win32 ReleaseU" +# Name "Alone - Win32 DebugU" +# Begin Group "Console" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\UI\Console\ArError.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\CompressionMode.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\ConsoleClose.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\ConsoleClose.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\ExtractCallbackConsole.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\ExtractCallbackConsole.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\List.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\List.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\Main.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\MainAr.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\OpenCallbackConsole.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\OpenCallbackConsole.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\PercentPrinter.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\PercentPrinter.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\UpdateCallbackConsole.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\UpdateCallbackConsole.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\UserInputUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Console\UserInputUtils.h +# End Source File +# End Group +# Begin Group "Spec" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\resource.rc +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# ADD CPP /Yc"StdAfx.h" +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# End Group +# Begin Group "Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\Common\AlignedBuffer.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\AlignedBuffer.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Alloc.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Alloc.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\AutoPtr.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Buffer.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\CommandLineParser.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\CommandLineParser.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\ComTry.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\CRC.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\CRC.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Defs.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\DynamicBuffer.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Exception.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\IntToString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\IntToString.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\ListFileUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\ListFileUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyCom.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyGuidDef.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyInitGuid.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyUnknown.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyWindows.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyWindows.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Random.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Random.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdOutStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdOutStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\String.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\String.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringConvert.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringConvert.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringToInt.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringToInt.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Types.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\UTFConvert.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\UTFConvert.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Vector.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Vector.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Wildcard.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Wildcard.h +# End Source File +# End Group +# Begin Group "Windows" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\..\Windows\Defs.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Device.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\DLL.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\DLL.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Error.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Error.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileDir.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileDir.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileFind.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileFind.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileIO.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileIO.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileName.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileName.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Handle.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\MemoryLock.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\MemoryLock.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariant.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariant.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariantConversions.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\PropVariantConversions.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Synchronization.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Synchronization.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Thread.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Time.h +# End Source File +# End Group +# Begin Group "7zip Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Archive\Common\CrossThreadProgress.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\CrossThreadProgress.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FilePathAutoRename.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FilePathAutoRename.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FileStreams.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\FileStreams.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\InBuffer.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\InBuffer.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\InOutTempBuffer.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\InOutTempBuffer.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LimitedStreams.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LimitedStreams.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LockedStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LockedStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LSBFDecoder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LSBFDecoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LSBFEncoder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\LSBFEncoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MSBFDecoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MSBFEncoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OffsetStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OffsetStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OutBuffer.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OutBuffer.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OutMemStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\OutMemStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressMt.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressMt.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\ProgressUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamBinder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamBinder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamObjects.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamObjects.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\StreamUtils.h +# End Source File +# End Group +# Begin Group "Compress" + +# PROP Default_Filter "" +# Begin Group "Branch" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchCoder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchCoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\Coder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\x86.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\x86.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\x86_2.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\x86_2.h +# End Source File +# End Group +# Begin Group "Copy" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\Copy\CopyCoder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Copy\CopyCoder.h +# End Source File +# End Group +# Begin Group "LZ" + +# PROP Default_Filter "" +# Begin Group "MT" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\LZ\MT\MT.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\MT\MT.h +# End Source File +# End Group +# Begin Group "HC" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\LZ\HashChain\HC.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\HashChain\HC2.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\HashChain\HC3.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\HashChain\HC4.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\HashChain\HC4b.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\HashChain\HCMain.h +# End Source File +# End Group +# Begin Source File + +SOURCE=..\..\Compress\LZ\IMatchFinder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\LZInWindow.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O1 + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O1 + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\LZInWindow.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\LZOutWindow.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O1 + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O1 + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZ\LZOutWindow.h +# End Source File +# End Group +# Begin Group "LZMA" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\LZMA\LZMA.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZMA\LZMADecoder.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZMA\LZMADecoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZMA\LZMAEncoder.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O2 +# SUBTRACT CPP /YX /Yc /Yu + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\LZMA\LZMAEncoder.h +# End Source File +# End Group +# Begin Group "RangeCoder" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\RangeCoder\RangeCoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\RangeCoder\RangeCoderBit.cpp + +!IF "$(CFG)" == "Alone - Win32 Release" + +# ADD CPP /O1 + +!ELSEIF "$(CFG)" == "Alone - Win32 Debug" + +!ELSEIF "$(CFG)" == "Alone - Win32 ReleaseU" + +# ADD CPP /O1 + +!ELSEIF "$(CFG)" == "Alone - Win32 DebugU" + +!ENDIF + +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\RangeCoder\RangeCoderBit.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\RangeCoder\RangeCoderBitTree.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\RangeCoder\RangeCoderOpt.h +# End Source File +# End Group +# End Group +# Begin Group "Archive" + +# PROP Default_Filter "" +# Begin Group "7z" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Archive\7z\7zCompressionMode.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zCompressionMode.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zDecode.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zDecode.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zEncode.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zEncode.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zExtract.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zFolderInStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zFolderInStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zFolderOutStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zFolderOutStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zHandler.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zHandler.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zHandlerOut.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zHeader.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zHeader.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zIn.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zIn.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zItem.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zMethodID.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zMethodID.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zOut.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zOut.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zProperties.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zProperties.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zSpecStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zSpecStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zUpdate.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\7z\7zUpdate.h +# End Source File +# End Group +# Begin Group "Archive Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Archive\Common\CoderMixer2.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\CoderMixer2.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\CoderMixer2MT.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\CoderMixer2MT.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\CoderMixer2ST.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\CoderMixer2ST.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\DummyOutStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\DummyOutStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\FilterCoder.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\FilterCoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\InStreamWithCRC.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\InStreamWithCRC.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\ItemNameUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\ItemNameUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\MultiStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\MultiStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\OutStreamWithCRC.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\OutStreamWithCRC.h +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\ParseProperties.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Common\ParseProperties.h +# End Source File +# End Group +# Begin Group "split" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Archive\Split\SplitHandler.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Archive\Split\SplitHandler.h +# End Source File +# End Group +# End Group +# Begin Group "UI Common" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiveCommandLine.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiveCommandLine.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiveExtractCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiveExtractCallback.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiveOpenCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiveOpenCallback.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiverInfo.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ArchiverInfo.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\DefaultName.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\DefaultName.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\EnumDirItems.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\EnumDirItems.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\Extract.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\Extract.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ExtractingFilePath.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\ExtractingFilePath.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\OpenArchive.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\OpenArchive.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\PropIDUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\PropIDUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\SetProperties.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\SetProperties.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\SortUtils.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\SortUtils.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\TempFiles.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\TempFiles.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\Update.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\Update.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdateAction.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdateAction.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdateCallback.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdateCallback.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdatePair.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdatePair.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdateProduce.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\UpdateProduce.h +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\WorkDir.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\UI\Common\WorkDir.h +# End Source File +# End Group +# Begin Group "7-zip" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\ICoder.h +# End Source File +# Begin Source File + +SOURCE=..\..\IMyUnknown.h +# End Source File +# Begin Source File + +SOURCE=..\..\IPassword.h +# End Source File +# Begin Source File + +SOURCE=..\..\IProgress.h +# End Source File +# Begin Source File + +SOURCE=..\..\IStream.h +# End Source File +# Begin Source File + +SOURCE=..\..\PropID.h +# End Source File +# End Group +# End Target +# End Project diff --git a/7zip/Bundles/Alone7z/Alone.dsw b/7zip/Bundles/Alone7z/Alone.dsw new file mode 100755 index 00000000..65eca43f --- /dev/null +++ b/7zip/Bundles/Alone7z/Alone.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "Alone"=.\Alone.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/7zip/Bundles/Format7z/Format7z.dsp b/7zip/Bundles/Format7z/Format7z.dsp index 74b8b25b..05a1b1fb 100755 --- a/7zip/Bundles/Format7z/Format7z.dsp +++ b/7zip/Bundles/Format7z/Format7z.dsp @@ -727,29 +727,17 @@ SOURCE=..\..\Crypto\7zAES\7zAES.cpp SOURCE=..\..\Crypto\7zAES\7zAES.h # End Source File -# Begin Source File +# End Group +# Begin Group "Hash" -SOURCE=..\..\Crypto\7zAES\MySHA256.h -# End Source File +# PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.cpp - -!IF "$(CFG)" == "7z - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7z - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - +SOURCE=..\..\Crypto\Hash\Sha256.cpp # End Source File # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.h +SOURCE=..\..\Crypto\Hash\Sha256.h # End Source File # End Group # End Group diff --git a/7zip/Bundles/Format7z/makefile b/7zip/Bundles/Format7z/makefile index f03a4dbd..90d68362 100755 --- a/7zip/Bundles/Format7z/makefile +++ b/7zip/Bundles/Format7z/makefile @@ -107,7 +107,6 @@ PPMD_OPT_OBJS = \ 7ZAES_OPT_OBJS = \ $O\7zAES.obj \ - $O\SHA256.obj \ AES_OPT_OBJS = \ $O\MyAES.obj \ @@ -117,6 +116,9 @@ AES_ORIG_OBJS = \ $O\aeskey.obj \ $O\aestab.obj \ +CRYPTO_HASH_OBJS = \ + $O\Sha256.obj \ + OBJS = \ $O\StdAfx.obj \ $(CONSOLE_OBJS) \ @@ -138,6 +140,7 @@ OBJS = \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ $(AES_ORIG_OBJS) \ + $(CRYPTO_HASH_OBJS) \ $O\resource.res @@ -180,6 +183,8 @@ $O\RangeCoderBit.obj: ../../Compress/RangeCoder/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) $(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2) + $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL_O2) diff --git a/7zip/Bundles/Format7zExtract/Format7z.dsp b/7zip/Bundles/Format7zExtract/Format7z.dsp index eba80af3..d049d00c 100755 --- a/7zip/Bundles/Format7zExtract/Format7z.dsp +++ b/7zip/Bundles/Format7zExtract/Format7z.dsp @@ -647,29 +647,17 @@ SOURCE=..\..\Crypto\7zAES\7zAES.cpp SOURCE=..\..\Crypto\7zAES\7zAES.h # End Source File -# Begin Source File +# End Group +# Begin Group "Hash" -SOURCE=..\..\Crypto\7zAES\MySHA256.h -# End Source File +# PROP Default_Filter "" # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.cpp - -!IF "$(CFG)" == "7z - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "7z - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - +SOURCE=..\..\Crypto\Hash\Sha256.cpp # End Source File # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.h +SOURCE=..\..\Crypto\Hash\Sha256.h # End Source File # End Group # End Group diff --git a/7zip/Bundles/Format7zExtract/makefile b/7zip/Bundles/Format7zExtract/makefile index 86d4d4d4..9a74f429 100755 --- a/7zip/Bundles/Format7zExtract/makefile +++ b/7zip/Bundles/Format7zExtract/makefile @@ -98,7 +98,6 @@ PPMD_OPT_OBJS = \ 7ZAES_OPT_OBJS = \ $O\7zAES.obj \ - $O\SHA256.obj \ AES_OPT_OBJS = \ $O\MyAES.obj \ @@ -108,6 +107,9 @@ AES_ORIG_OBJS = \ $O\aeskey.obj \ $O\aestab.obj \ +CRYPTO_HASH_OBJS = \ + $O\Sha256.obj \ + OBJS = \ $O\StdAfx.obj \ $(CONSOLE_OBJS) \ @@ -127,6 +129,7 @@ OBJS = \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ $(AES_ORIG_OBJS) \ + $(CRYPTO_HASH_OBJS) \ $O\resource.res @@ -165,6 +168,8 @@ $O\CopyCoder.obj: ../../Compress/Copy/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL_O2) $(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O2) + $(COMPL_O2_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL_O2) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL_O2) diff --git a/7zip/Bundles/SFXCon/Main.cpp b/7zip/Bundles/SFXCon/Main.cpp index 12599e87..65ed8931 100755 --- a/7zip/Bundles/SFXCon/Main.cpp +++ b/7zip/Bundles/SFXCon/Main.cpp @@ -168,19 +168,6 @@ NRecursedType::EEnum CArchiveCommand::DefaultRecursedType() const return kCommandRecursedDefault[CommandType]; } -static NRecursedType::EEnum GetRecursedTypeFromIndex(int index) -{ - switch (index) - { - case NRecursedPostCharIndex::kWildCardRecursionOnly: - return NRecursedType::kWildCardOnlyRecursed; - case NRecursedPostCharIndex::kNoRecursion: - return NRecursedType::kNonRecursed; - default: - return NRecursedType::kRecursed; - } -} - void PrintHelp(void) { g_StdOut << kHelpString; @@ -198,12 +185,6 @@ static void PrintHelpAndExit() // yyy ShowMessageAndThrowException(kUserErrorMessage, NExitCode::kUserError); } -static void PrintProcessTitle(const CSysString &processTitle, const UString &archiveName) -{ - g_StdOut << endl << processTitle << kProcessArchiveMessage << - archiveName << endl << endl; -} - bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command) { UString commandStringUpper = commandString; @@ -228,7 +209,7 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, return false; */ bool isWildCard = DoesNameContainWildCard(name); - bool recursed; + bool recursed = false; switch (type) { @@ -246,67 +227,20 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, return true; } -void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor, +void AddCommandLineWildCardToCensor(NWildcard::CCensor &wildcardCensor, const UString &name, bool include, NRecursedType::EEnum type) { if (!AddNameToCensor(wildcardCensor, name, include, type)) ShowMessageAndThrowException(kIncorrectWildCardInCommandLine, NExitCode::kUserError); } -static bool AreEqualNoCase(wchar_t c1, wchar_t c2) -{ - return ::MyCharUpper(c1) == ::MyCharUpper(c2); -} - void AddToCensorFromNonSwitchesStrings(NWildcard::CCensor &wildcardCensor, - const UStringVector &nonSwitchStrings, NRecursedType::EEnum type, - bool thereAreSwitchIncludeWildCards) + const UStringVector & /* nonSwitchStrings */, NRecursedType::EEnum type, + bool /* thereAreSwitchIncludeWildCards */) { - AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type); + AddCommandLineWildCardToCensor(wildcardCensor, kUniversalWildcard, true, type); } -/* -void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, - const UStringVector &strings, bool include, NRecursedType::EEnum commonRecursedType) -{ - for(int i = 0; i < strings.Size(); i++) - { - const UString &string = strings[i]; - NRecursedType::EEnum recursedType; - int pos = 0; - if (string.Length() < kSomeCludePostStringMinSize) - PrintHelpAndExit(); - if (AreEqualNoCase(string[pos], kRecursedIDChar)) - { - pos++; - int index = UString(kRecursedPostCharSet).Find(string[pos]); - recursedType = GetRecursedTypeFromIndex(index); - if (index >= 0) - pos++; - } - else - recursedType = commonRecursedType; - if (string.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize) - PrintHelpAndExit(); - UString tail = string.Mid(pos + 1); - if (AreEqualNoCase(string[pos], kImmediateNameID)) - AddCommandLineWildCardToCensr(wildcardCensor, - tail, include, recursedType); - else - PrintHelpAndExit(); - } -} -*/ - -// ------------------------------------------------------------------ -/* -static void ThrowPrintFileIsNotArchiveException(const CSysString &fileName) -{ - CSysString message; - message = kFileIsNotArchiveMessageBefore + fileName + kFileIsNotArchiveMessageAfter; - ShowMessageAndThrowException(message, NExitCode::kFileIsNotArchive); -} -*/ #ifndef _WIN32 static void GetArguments(int numArguments, const char *arguments[], UStringVector &parts) @@ -443,10 +377,17 @@ int Main2( eo.OutputDir = outputDir; eo.YesToAll = yesToAll; + UString errorMessage; HRESULT result = DecompressArchives( v1, v2, wildcardCensorHead, - eo, &openCallback, ecs); + eo, &openCallback, ecs, errorMessage); + if (!errorMessage.IsEmpty()) + { + (*g_StdStream) << endl << "Error: " << errorMessage;; + if (result == S_OK) + result = E_FAIL; + } if (ecs->NumArchiveErrors != 0 || ecs->NumFileErrors != 0) { diff --git a/7zip/Bundles/SFXCon/SFXCon.dsp b/7zip/Bundles/SFXCon/SFXCon.dsp index 2cc0dca5..5b61dae3 100755 --- a/7zip/Bundles/SFXCon/SFXCon.dsp +++ b/7zip/Bundles/SFXCon/SFXCon.dsp @@ -350,18 +350,6 @@ SOURCE=..\..\Crypto\7zAES\7zAES.cpp SOURCE=..\..\Crypto\7zAES\7zAES.h # End Source File -# Begin Source File - -SOURCE=..\..\Crypto\7zAES\MySHA256.h -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\7zAES\SHA256.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Crypto\7zAES\SHA256.h -# End Source File # End Group # Begin Group "AES" @@ -406,6 +394,22 @@ SOURCE=..\..\Crypto\AES\MyAES.cpp SOURCE=..\..\Crypto\AES\MyAES.h # End Source File # End Group +# Begin Group "Hash" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Crypto\Hash\RotateDefs.h +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha256.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Crypto\Hash\Sha256.h +# End Source File +# End Group # End Group # Begin Group "SDK" diff --git a/7zip/Bundles/SFXCon/makefile b/7zip/Bundles/SFXCon/makefile index 3164dc39..7501a497 100755 --- a/7zip/Bundles/SFXCon/makefile +++ b/7zip/Bundles/SFXCon/makefile @@ -104,7 +104,6 @@ PPMD_OPT_OBJS = \ 7ZAES_OPT_OBJS = \ $O\7zAES.obj \ - $O\SHA256.obj \ AES_OPT_OBJS = \ $O\MyAES.obj \ @@ -114,6 +113,9 @@ AES_ORIG_OBJS = \ $O\aeskey.obj \ $O\aestab.obj \ +CRYPTO_HASH_OBJS = \ + $O\Sha256.obj \ + OBJS = \ $O\StdAfx.obj \ $(SFX_CONSOLE_OBJS) \ @@ -132,7 +134,7 @@ OBJS = \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ $(AES_ORIG_OBJS) \ - $(CRYPTO_ZIP_OBJS) \ + $(CRYPTO_HASH_OBJS) \ $O\resource.res @@ -171,6 +173,8 @@ $O\CopyCoder.obj: ../../Compress/Copy/$(*B).cpp $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL) $(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O1) + $(COMPL_O1_W3) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL) diff --git a/7zip/Bundles/SFXSetup/ExtractCallback.cpp b/7zip/Bundles/SFXSetup/ExtractCallback.cpp index dfa66e43..6294516c 100755 --- a/7zip/Bundles/SFXSetup/ExtractCallback.cpp +++ b/7zip/Bundles/SFXSetup/ExtractCallback.cpp @@ -54,7 +54,7 @@ STDMETHODIMP CExtractCallbackImp::SetTotal(UInt64 size) STDMETHODIMP CExtractCallbackImp::SetCompleted(const UInt64 *completeValue) { #ifndef _NO_PROGRESS - while(true) + for (;;) { if(ProgressDialog.ProgressSynch.GetStopped()) return E_ABORT; diff --git a/7zip/Bundles/SFXSetup/Main.cpp b/7zip/Bundles/SFXSetup/Main.cpp index abc34506..12de5c01 100755 --- a/7zip/Bundles/SFXSetup/Main.cpp +++ b/7zip/Bundles/SFXSetup/Main.cpp @@ -51,7 +51,7 @@ static bool ReadDataString(LPCWSTR fileName, LPCSTR startID, UInt32 numBytesPrev = 0; bool writeMode = false; UInt64 posTotal = 0; - while(true) + for (;;) { if (posTotal > (1 << 20)) return (stringResult.IsEmpty()); @@ -63,7 +63,7 @@ static bool ReadDataString(LPCWSTR fileName, LPCSTR startID, return true; UInt32 numBytesInBuffer = numBytesPrev + processedSize; UInt32 pos = 0; - while (true) + for (;;) { if (writeMode) { @@ -134,11 +134,7 @@ static inline bool IsItWindowsNT() } #endif -int APIENTRY WinMain( - HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */,int /* nCmdShow */) { g_hInstance = (HINSTANCE)hInstance; #ifndef _UNICODE @@ -217,24 +213,26 @@ int APIENTRY WinMain( COpenCallbackGUI openCallback; UString tempDirPath = GetUnicodeString(tempDir.GetPath()); - bool isCorrupt = false; - UString errorMessage; - HRESULT result = ExtractArchive(fullPath, tempDirPath, &openCallback, showProgress, - isCorrupt, errorMessage); - - if (result != S_OK) { - if (!assumeYes) + bool isCorrupt = false; + UString errorMessage; + HRESULT result = ExtractArchive(fullPath, tempDirPath, &openCallback, showProgress, + isCorrupt, errorMessage); + + if (result != S_OK) { - if (result == S_FALSE || isCorrupt) + if (!assumeYes) { - errorMessage = NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_MESSAGE); - result = E_FAIL; + if (result == S_FALSE || isCorrupt) + { + errorMessage = NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_MESSAGE); + result = E_FAIL; + } + if (result != E_ABORT && !errorMessage.IsEmpty()) + ::MessageBoxW(0, errorMessage, NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR); } - if (result != E_ABORT && !errorMessage.IsEmpty()) - ::MessageBoxW(0, errorMessage, NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR); + return 1; } - return 1; } CCurrentDirRestorer currentDirRestorer; @@ -266,8 +264,8 @@ int APIENTRY WinMain( execInfo.lpDirectory = NULL; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; - bool success = BOOLToBool(::ShellExecuteEx(&execInfo)); - result = (UINT32)execInfo.hInstApp; + /* BOOL success = */ ::ShellExecuteEx(&execInfo); + UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp; if(result <= 32) { if (!assumeYes) diff --git a/7zip/Bundles/SFXWin/Main.cpp b/7zip/Bundles/SFXWin/Main.cpp index 59c2d1dc..166d58cb 100755 --- a/7zip/Bundles/SFXWin/Main.cpp +++ b/7zip/Bundles/SFXWin/Main.cpp @@ -31,11 +31,7 @@ static inline bool IsItWindowsNT() } #endif -int APIENTRY WinMain( - HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */) { g_hInstance = (HINSTANCE)hInstance; #ifndef _UNICODE diff --git a/7zip/Bundles/SFXWin/SFXWin.dsp b/7zip/Bundles/SFXWin/SFXWin.dsp index d3ae57e5..ead66bc6 100755 --- a/7zip/Bundles/SFXWin/SFXWin.dsp +++ b/7zip/Bundles/SFXWin/SFXWin.dsp @@ -385,13 +385,21 @@ SOURCE=..\..\Crypto\7zAES\7zAES.h SOURCE=..\..\Crypto\7zAES\MySHA256.h # End Source File +# End Group +# Begin Group "Hash" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Crypto\Hash\RotateDefs.h +# End Source File # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.cpp +SOURCE=..\..\Crypto\Hash\Sha256.cpp # End Source File # Begin Source File -SOURCE=..\..\Crypto\7zAES\SHA256.h +SOURCE=..\..\Crypto\Hash\Sha256.h # End Source File # End Group # End Group diff --git a/7zip/Bundles/SFXWin/makefile b/7zip/Bundles/SFXWin/makefile index af10c3fe..00d3ecc6 100755 --- a/7zip/Bundles/SFXWin/makefile +++ b/7zip/Bundles/SFXWin/makefile @@ -109,7 +109,6 @@ PPMD_OPT_OBJS = \ 7ZAES_OPT_OBJS = \ $O\7zAES.obj \ - $O\SHA256.obj \ AES_OPT_OBJS = \ $O\MyAES.obj \ @@ -119,6 +118,9 @@ AES_ORIG_OBJS = \ $O\aeskey.obj \ $O\aestab.obj \ +CRYPTO_HASH_OBJS = \ + $O\Sha256.obj \ + OBJS = \ $O\StdAfx.obj \ $(SFX_WIN_OBJS) \ @@ -136,6 +138,7 @@ OBJS = \ $(LZMA_OPT_OBJS) \ $(PPMD_OPT_OBJS) \ $O\CopyCoder.obj \ + $(CRYPTO_HASH_OBJS) \ $(7ZAES_OPT_OBJS) \ $(AES_OPT_OBJS) \ $(AES_ORIG_OBJS) \ @@ -183,12 +186,14 @@ $(PPMD_OPT_OBJS): ../../Compress/PPMD/$(*B).cpp $O\CopyCoder.obj: ../../Compress/Copy/$(*B).cpp $(COMPL) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL) $(7ZAES_OPT_OBJS): ../../Crypto/7zAES/$(*B).cpp $(COMPL) $(AES_OPT_OBJS): ../../Crypto/AES/$(*B).cpp $(COMPL) $(AES_ORIG_OBJS): ../../Crypto/AES/$(*B).c - $(COMPL_O1) + $(COMPL_O1_W3) $O\MyMessages.obj: ../../UI/Explorer/MyMessages.cpp $(COMPL) diff --git a/7zip/Bundles/makefile b/7zip/Bundles/makefile index 9e7b3e0a..108cbd17 100755 --- a/7zip/Bundles/makefile +++ b/7zip/Bundles/makefile @@ -1,5 +1,6 @@ DIRS = \ Alone\~ \ + Alone7z\~ \ Format7z\~ \ Format7zExtract\~ \ SFXCon\~ \ diff --git a/7zip/Common/InMemStream.cpp b/7zip/Common/InMemStream.cpp new file mode 100755 index 00000000..036ef3bd --- /dev/null +++ b/7zip/Common/InMemStream.cpp @@ -0,0 +1,222 @@ +// InMemStream.cpp + +#include "StdAfx.h" + +#include + +#include "Windows/Thread.h" + +#include "InMemStream.h" +#include "../../Common/Defs.h" + +void CStreamInfo::Free(IInMemStreamMtCallback *callback) +{ + for (int i = 0; i < Blocks.Size(); i++) + { + callback->FreeBlock(Blocks[i]); + Blocks[i] = 0; + } +} + +bool CInMemStreamMt::Create(int numSubStreams, UInt64 subStreamSize) +{ + Free(); + _subStreamSize = subStreamSize; + size_t blockSize = Callback->GetBlockSize(); + for (int i = 0; i < numSubStreams; i++) + { + _streams.Add(CStreamInfo()); + CStreamInfo &blocks = _streams.Back(); + blocks.Create(); + for (UInt64 j = 0; (UInt64)j * blockSize < _subStreamSize; j++) + blocks.Blocks.Add(0); + } + if (!_streamIndexAllocator.AllocateList(numSubStreams)) + return false; + return true; +} + +void CInMemStreamMt::Free() +{ + while(_streams.Size() > 0) + { + _streams.Back().Free(Callback); + _streams.DeleteBack(); + } +} + +HRESULT CInMemStreamMt::Read() +{ + for (;;) + { + // printf("\n_streamIndexAllocator.AllocateItem\n"); + int index = _streamIndexAllocator.AllocateItem(); + /* + if (_stopReading) + return E_ABORT; + */ + // printf("\nread Index = %d\n", index); + CStreamInfo &blocks = _streams[index]; + blocks.Init(); + Callback->AddStreamIndexToQueue(index); + + for (;;) + { + const Byte *p = (const Byte *)blocks.Blocks[blocks.LastBlockIndex]; + if (p == 0) + { + void **pp = &blocks.Blocks[blocks.LastBlockIndex]; + HRESULT res = Callback->AllocateBlock(pp); + p = (const Byte *)*pp; + RINOK(res); + if (p == 0) + return E_FAIL; + } + size_t blockSize = Callback->GetBlockSize(); + UInt32 curSize = (UInt32)(blockSize - blocks.LastBlockPos); + UInt32 realProcessedSize; + UInt64 pos64 = (UInt64)blocks.LastBlockIndex * blockSize + blocks.LastBlockPos; + if (curSize > _subStreamSize - pos64) + curSize = (UInt32)(_subStreamSize - pos64); + RINOK(_stream->Read((void *)(p + blocks.LastBlockPos), curSize, &realProcessedSize)); + + blocks.Cs->Enter(); + if (realProcessedSize == 0) + { + blocks.StreamWasFinished = true; + blocks.CanReadEvent->Set(); + blocks.Cs->Leave(); + + Callback->AddStreamIndexToQueue(-1); + return S_OK; + } + + blocks.LastBlockPos += realProcessedSize; + if (blocks.LastBlockPos == blockSize) + { + blocks.LastBlockPos = 0; + blocks.LastBlockIndex++; + } + pos64 += realProcessedSize; + if (pos64 >= _subStreamSize) + blocks.StreamWasFinished = true; + blocks.CanReadEvent->Set(); + blocks.Cs->Leave(); + if (pos64 >= _subStreamSize) + break; + } + } +} + +static DWORD WINAPI CoderThread(void *threadCoderInfo) +{ + ((CInMemStreamMt *)threadCoderInfo)->ReadResult = ((CInMemStreamMt *)threadCoderInfo)->Read(); + return 0; +} + +bool CInMemStreamMt::StartReadThread() +{ + // _stopReading = false; + NWindows::CThread Thread; + return Thread.Create(CoderThread, this); +} + +void CInMemStreamMt::FreeSubStream(int subStreamIndex) +{ + // printf("\nFreeSubStream\n"); + _streams[subStreamIndex].Free(Callback); + _streamIndexAllocator.FreeItem(subStreamIndex); + // printf("\nFreeSubStream end\n"); +} + +HRESULT CInMemStreamMt::ReadSubStream(int subStreamIndex, void *data, UInt32 size, UInt32 *processedSize, bool keepData) +{ + if (processedSize != NULL) + *processedSize = 0; + CStreamInfo &blocks = _streams[subStreamIndex]; + while (size > 0) + { + if (blocks.CurBlockPos == Callback->GetBlockSize()) + { + blocks.CurBlockPos = 0; + blocks.CurBlockIndex++; + } + UInt32 curSize; + UInt32 curPos = blocks.CurBlockPos; + + blocks.Cs->Enter(); + if (blocks.CurBlockIndex == blocks.LastBlockIndex) + { + curSize = blocks.LastBlockPos - curPos; + if (curSize == 0) + { + if (blocks.StreamWasFinished) + { + blocks.Cs->Leave(); + void *p = blocks.Blocks[blocks.CurBlockIndex]; + if (p != 0 && !keepData) + { + Callback->FreeBlock(p); + blocks.Blocks[blocks.CurBlockIndex] = 0; + } + return S_OK; + } + blocks.CanReadEvent->Reset(); + blocks.Cs->Leave(); + // printf("\nBlock Lock\n"); + blocks.CanReadEvent->Lock(); + // printf("\nAfter Lock\n"); + if (blocks.ExitResult != S_OK) + return blocks.ExitResult; + continue; + } + } + else + curSize = Callback->GetBlockSize() - curPos; + blocks.Cs->Leave(); + + if (curSize > size) + curSize = size; + void *p = blocks.Blocks[blocks.CurBlockIndex]; + memmove(data, (const Byte *)p + curPos, curSize); + data = (void *)((Byte *)data + curSize); + size -= curSize; + if (processedSize != NULL) + *processedSize += curSize; + curPos += curSize; + + bool needFree = false; + blocks.CurBlockPos = curPos; + + if (curPos == Callback->GetBlockSize()) + needFree = true; + blocks.Cs->Enter(); + if (blocks.CurBlockIndex == blocks.LastBlockIndex && + blocks.CurBlockPos == blocks.LastBlockPos && + blocks.StreamWasFinished) + needFree = true; + blocks.Cs->Leave(); + + if (needFree && !keepData) + { + Callback->FreeBlock(p); + blocks.Blocks[blocks.CurBlockIndex] = 0; + } + return S_OK; + } + return S_OK; +} + +STDMETHODIMP CInMemStream::Read(void *data, UInt32 size, UInt32 *processedSize) +{ + UInt32 realProcessedSize; + HRESULT result = mtStream->ReadSubStream(Index, data, size, &realProcessedSize, _keepData); + if (processedSize != NULL) + *processedSize = realProcessedSize; + if (realProcessedSize != 0) + { + // printf("\ns = %d\n", Index); + } + _size += realProcessedSize; + return result; +} diff --git a/7zip/Common/InMemStream.h b/7zip/Common/InMemStream.h new file mode 100755 index 00000000..fcd0092d --- /dev/null +++ b/7zip/Common/InMemStream.h @@ -0,0 +1,282 @@ +// InMemStream.h + +#ifndef __INMEMSTREAM_H +#define __INMEMSTREAM_H + +#include + +#include "../../Common/MyCom.h" +#include "MemBlocks.h" + +class CIntListCheck +{ +protected: + int *_data; +public: + CIntListCheck(): _data(0) {} + ~CIntListCheck() { FreeList(); } + + bool AllocateList(int numItems) + { + FreeList(); + if (numItems == 0) + return true; + _data = (int *)::MyAlloc(numItems * sizeof(int)); + return (_data != 0); + } + + void FreeList() + { + ::MyFree(_data); + _data = 0; + } +}; + + +class CResourceList : public CIntListCheck +{ + int _headFree; +public: + CResourceList(): _headFree(-1) {} + + bool AllocateList(int numItems) + { + FreeList(); + if (numItems == 0) + return true; + if (!CIntListCheck::AllocateList(numItems)) + return false; + for (int i = 0; i < numItems; i++) + _data[i] = i + 1; + _data[numItems - 1] = -1; + _headFree = 0; + return true; + } + + void FreeList() + { + CIntListCheck::FreeList(); + _headFree = -1; + } + + int AllocateItem() + { + int res = _headFree; + if (res >= 0) + _headFree = _data[res]; + return res; + } + + void FreeItem(int index) + { + if (index < 0) + return; + _data[index] = _headFree; + _headFree = index; + } +}; + +class CResourceListMt: public CResourceList +{ + NWindows::NSynchronization::CCriticalSection _criticalSection; +public: + NWindows::NSynchronization::CSemaphore Semaphore; + + bool AllocateList(int numItems) + { + if (!CResourceList::AllocateList(numItems)) + return false; + return Semaphore.Create((LONG)numItems, (LONG)numItems); + } + + int AllocateItem() + { + Semaphore.Lock(); + _criticalSection.Enter(); + int res = CResourceList::AllocateItem(); + _criticalSection.Leave(); + return res; + } + + void FreeItem(int index) + { + if (index < 0) + return; + _criticalSection.Enter(); + CResourceList::FreeItem(index); + _criticalSection.Leave(); + Semaphore.Release(); + } +}; + +class CIntQueueMt: public CIntListCheck +{ + int _numItems; + int _head; + int _cur; +public: + CIntQueueMt(): _numItems(0), _head(0), _cur(0) {} + NWindows::NSynchronization::CSemaphore Semaphore; + + bool AllocateList(int numItems) + { + FreeList(); + if (numItems == 0) + return true; + if (!CIntListCheck::AllocateList(numItems)) + return false; + _numItems = numItems; + return Semaphore.Create((LONG)0, (LONG)numItems); + } + + void FreeList() + { + CIntListCheck::FreeList(); + _numItems = 0; + _head = 0; + _cur = 0; + } + + void AddItem(int value) + { + _data[_head++] = value; + if (_head == _numItems) + _head = 0; + LONG previousCount; + Semaphore.Release(1, &previousCount); + // printf("\nRelease prev = %d\n", previousCount); + + } + + int GetItem() + { + // Semaphore.Lock(); + int res = _data[_cur++]; + if (_cur == _numItems) + _cur = 0; + return res; + } +}; + +struct IInMemStreamMtCallback +{ + // must be same for all calls + virtual size_t GetBlockSize() = 0; + + // Out: + // result != S_OK stops Reading + // if *p = 0, result must be != S_OK; + // Locking is allowed + virtual HRESULT AllocateBlock(void **p) = 0; + + virtual void FreeBlock(void *p) = 0; + + // It must allow to add at least numSubStreams + 1 , + // where numSubStreams is value from CInMemStreamMt::Create + // value -1 means End of stream + // Locking is not allowed + virtual void AddStreamIndexToQueue(int index) = 0; +}; + +struct CStreamInfo +{ + CRecordVector Blocks; + + int LastBlockIndex; + size_t LastBlockPos; + bool StreamWasFinished; + + int CurBlockIndex; + size_t CurBlockPos; + + NWindows::NSynchronization::CCriticalSection *Cs; + NWindows::NSynchronization::CManualResetEvent *CanReadEvent; + + HRESULT ExitResult; + + CStreamInfo(): Cs(0), CanReadEvent(0), StreamWasFinished(false) { } + ~CStreamInfo() + { + delete Cs; + delete CanReadEvent; + // Free(); + } + void Create() + { + Cs = new NWindows::NSynchronization::CCriticalSection; + CanReadEvent = new NWindows::NSynchronization::CManualResetEvent; + } + + void Free(IInMemStreamMtCallback *callback); + void Init() + { + LastBlockIndex = CurBlockIndex = 0; + CurBlockPos = LastBlockPos = 0; + StreamWasFinished = false; + ExitResult = S_OK; + } + + // res must be != S_OK + void Exit(HRESULT res) + { + ExitResult = res; + CanReadEvent->Set(); + } +}; + + +class CInMemStreamMt +{ + CMyComPtr _stream; + NWindows::NSynchronization::CCriticalSection CS; + CObjectVector _streams; + int _nextFreeStreamIndex; + int _currentStreamIndex; + UInt64 _subStreamSize; + + CResourceListMt _streamIndexAllocator; + + // bool _stopReading; + +public: + HRESULT Read(); + HRESULT ReadResult; + IInMemStreamMtCallback *Callback; + void FreeSubStream(int subStreamIndex); + HRESULT ReadSubStream(int subStreamIndex, void *data, UInt32 size, UInt32 *processedSize, bool keepData); + + // numSubStreams: min = 1, good min = numThreads + bool Create(int numSubStreams, UInt64 subStreamSize); + ~CInMemStreamMt() { Free(); } + void SetStream(ISequentialInStream *stream) { _stream = stream; } + + // to stop reading you must implement + // returning Error in IInMemStreamMtCallback::AllocateBlock + // and then you must free at least one substream + bool StartReadThread(); + + void Free(); + + // you must free at least one substream after that function to unlock waiting. + // void StopReading() { _stopReading = true; } +}; + +class CInMemStream: + public ISequentialInStream, + public CMyUnknownImp +{ + UInt64 _size; + bool _keepData; +public: + int Index; + CInMemStreamMt *mtStream; + void Init(bool keepData = false) + { + _size = 0; _keepData = keepData ; + } + MY_UNKNOWN_IMP + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); + UInt64 GetSize() const { return _size; } +}; + +#endif diff --git a/7zip/Common/InOutTempBuffer.cpp b/7zip/Common/InOutTempBuffer.cpp index 665fc554..ffaed32c 100755 --- a/7zip/Common/InOutTempBuffer.cpp +++ b/7zip/Common/InOutTempBuffer.cpp @@ -97,7 +97,7 @@ HRESULT CInOutTempBuffer::WriteToStream(ISequentialOutStream *stream) } if (!_tmpFileCreated) return true; - while(true) + for (;;) { UInt32 localProcessedSize; if (!_inFile.ReadPart(_buffer, kTmpBufferMemorySize, localProcessedSize)) diff --git a/7zip/Common/LSBFDecoder.h b/7zip/Common/LSBFDecoder.h index 1f5dcb59..75458452 100755 --- a/7zip/Common/LSBFDecoder.h +++ b/7zip/Common/LSBFDecoder.h @@ -47,7 +47,7 @@ public: { for (;m_BitPos >= 8; m_BitPos -= 8) { - Byte b; + Byte b = 0; if (!m_Stream.ReadByte(b)) { b = 0xFF; // check it @@ -88,9 +88,9 @@ public: void Normalize() { - for (;this->m_BitPos >= 8; this->m_BitPos -= 8) + for (; this->m_BitPos >= 8; this->m_BitPos -= 8) { - Byte b; + Byte b = 0; if (!this->m_Stream.ReadByte(b)) { b = 0xFF; // check it diff --git a/7zip/Common/LimitedStreams.cpp b/7zip/Common/LimitedStreams.cpp index c048d49d..af721146 100755 --- a/7zip/Common/LimitedStreams.cpp +++ b/7zip/Common/LimitedStreams.cpp @@ -5,20 +5,20 @@ #include "LimitedStreams.h" #include "../../Common/Defs.h" -void CLimitedSequentialInStream::Init(ISequentialInStream *stream, UInt64 streamSize) -{ - _stream = stream; - _size = streamSize; -} - STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize) { - UInt32 processedSizeReal; - UInt32 sizeToRead = UInt32(MyMin(_size, UInt64(size))); - HRESULT result = _stream->Read(data, sizeToRead, &processedSizeReal); - _size -= processedSizeReal; + UInt32 realProcessedSize = 0; + UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size); + HRESULT result = S_OK; + if (sizeToRead > 0) + { + result = _stream->Read(data, sizeToRead, &realProcessedSize); + _pos += realProcessedSize; + if (realProcessedSize == 0) + _wasFinished = true; + } if(processedSize != NULL) - *processedSize = processedSizeReal; + *processedSize = realProcessedSize; return result; } diff --git a/7zip/Common/LimitedStreams.h b/7zip/Common/LimitedStreams.h index d40be974..ec4a3a70 100755 --- a/7zip/Common/LimitedStreams.h +++ b/7zip/Common/LimitedStreams.h @@ -10,14 +10,24 @@ class CLimitedSequentialInStream: public ISequentialInStream, public CMyUnknownImp { - UInt64 _size; CMyComPtr _stream; + UInt64 _size; + UInt64 _pos; + bool _wasFinished; public: - void Init(ISequentialInStream *stream, UInt64 streamSize); + void SetStream(ISequentialInStream *stream) { _stream = stream; } + void Init(UInt64 streamSize) + { + _size = streamSize; + _pos = 0; + _wasFinished = false; + } MY_UNKNOWN_IMP STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); + UInt64 GetSize() const { return _pos; } + bool WasFinished() const { return _wasFinished; } }; #endif diff --git a/7zip/Common/MSBFEncoder.h b/7zip/Common/MSBFEncoder.h index 0d1812a3..767a0e57 100755 --- a/7zip/Common/MSBFEncoder.h +++ b/7zip/Common/MSBFEncoder.h @@ -45,7 +45,7 @@ public: numBits -= m_BitPos; UInt32 newBits = (value >> numBits); value -= (newBits << numBits); - m_Stream.WriteByte(m_CurByte | (Byte)newBits); + m_Stream.WriteByte((Byte)(m_CurByte | newBits)); m_BitPos = 8; m_CurByte = 0; } diff --git a/7zip/Common/MemBlocks.cpp b/7zip/Common/MemBlocks.cpp new file mode 100755 index 00000000..d2b79a70 --- /dev/null +++ b/7zip/Common/MemBlocks.cpp @@ -0,0 +1,184 @@ +// MemBlocks.cpp + +#include "StdAfx.h" + +#include "Common/MyCom.h" + +#include "StreamUtils.h" +#include "MemBlocks.h" + +bool CMemBlockManager::AllocateSpace(size_t numBlocks) +{ + FreeSpace(); + if (_blockSize < sizeof(void *) || numBlocks < 1) + return false; + size_t totalSize = numBlocks * _blockSize; + if (totalSize / _blockSize != numBlocks) + return false; + _data = ::MidAlloc(totalSize); + if (_data == 0) + return false; + Byte *p = (Byte *)_data; + for (size_t i = 0; i + 1 < numBlocks; i++, p += _blockSize) + *(Byte **)p = (p + _blockSize); + *(Byte **)p = 0; + _headFree = _data; + return true; +} + +void CMemBlockManager::FreeSpace() +{ + ::MidFree(_data); + _data = 0; + _headFree= 0; +} + +void *CMemBlockManager::AllocateBlock() +{ + if (_headFree == 0) + return 0; + void *p = _headFree; + _headFree = *(void **)_headFree; + return p; +} + +void CMemBlockManager::FreeBlock(void *p) +{ + if (p == 0) + return; + *(void **)p = _headFree; + _headFree = p; +} + + +bool CMemBlockManagerMt::AllocateSpace(size_t numBlocks, size_t numNoLockBlocks) +{ + if (numNoLockBlocks > numBlocks) + return false; + if (!CMemBlockManager::AllocateSpace(numBlocks)) + return false; + size_t numLockBlocks = numBlocks - numNoLockBlocks; + return Semaphore.Create((LONG)numLockBlocks, (LONG)numLockBlocks); +} + +bool CMemBlockManagerMt::AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks) +{ + if (numNoLockBlocks > desiredNumberOfBlocks) + return false; + for (;;) + { + if (AllocateSpace(desiredNumberOfBlocks, numNoLockBlocks)) + return true; + if (desiredNumberOfBlocks == numNoLockBlocks) + return false; + desiredNumberOfBlocks = numNoLockBlocks + ((desiredNumberOfBlocks - numNoLockBlocks) >> 1); + } +} + +void CMemBlockManagerMt::FreeSpace() +{ + Semaphore.Close(); + CMemBlockManager::FreeSpace(); +} + +void *CMemBlockManagerMt::AllocateBlock() +{ + // Semaphore.Lock(); + NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); + return CMemBlockManager::AllocateBlock(); +} + +void CMemBlockManagerMt::FreeBlock(void *p, bool lockMode) +{ + if (p == 0) + return; + { + NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); + CMemBlockManager::FreeBlock(p); + } + if (lockMode) + Semaphore.Release(); +} + +void CMemBlocks::Free(CMemBlockManagerMt *manager) +{ + while(Blocks.Size() > 0) + { + manager->FreeBlock(Blocks.Back()); + Blocks.DeleteBack(); + } + TotalSize = 0; +} + +void CMemBlocks::FreeOpt(CMemBlockManagerMt *manager) +{ + Free(manager); + Blocks.Free(); // to reduce memory usage +} + +HRESULT CMemBlocks::WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const +{ + UInt64 totalSize = TotalSize; + for (int blockIndex = 0; totalSize > 0; blockIndex++) + { + UInt32 curSize = (UInt32)blockSize; + if (totalSize < curSize) + curSize = (UInt32)totalSize; + UInt32 processedSize; + if (blockIndex >= Blocks.Size()) + return E_FAIL; + RINOK(WriteStream(outStream, Blocks[blockIndex], curSize, &processedSize)); + if (processedSize != curSize) + return E_FAIL; + totalSize -= processedSize; + } + return S_OK; +} + + +void CMemLockBlocks::FreeBlock(int index, CMemBlockManagerMt *memManager) +{ + memManager->FreeBlock(Blocks[index], LockMode); + Blocks[index] = 0; +} + +void CMemLockBlocks::Free(CMemBlockManagerMt *memManager) +{ + while (Blocks.Size() > 0) + { + FreeBlock(Blocks.Size() - 1, memManager); + Blocks.DeleteBack(); + } + TotalSize = 0; +} + +bool CMemLockBlocks::SwitchToNoLockMode(CMemBlockManagerMt *memManager) +{ + if (LockMode) + { + if (Blocks.Size() > 0) + if (!memManager->ReleaseLockedBlocks(Blocks.Size())) + return false; + LockMode = false; + } + return true; +} + +void CMemLockBlocks::Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager) +{ + blocks.Free(memManager); + blocks.LockMode = LockMode; + UInt64 totalSize = 0; + size_t blockSize = memManager->GetBlockSize(); + for (int i = 0; i < Blocks.Size(); i++) + { + if (totalSize < TotalSize) + blocks.Blocks.Add(Blocks[i]); + else + FreeBlock(i, memManager); + Blocks[i] = 0; + totalSize += blockSize; + } + blocks.TotalSize = TotalSize; + Free(memManager); +} diff --git a/7zip/Common/MemBlocks.h b/7zip/Common/MemBlocks.h new file mode 100755 index 00000000..31cd3546 --- /dev/null +++ b/7zip/Common/MemBlocks.h @@ -0,0 +1,73 @@ +// MemBlocks.h + +#ifndef __MEMBLOCKS_H +#define __MEMBLOCKS_H + +#include "Common/Alloc.h" +#include "Common/Types.h" +#include "Common/Vector.h" + +#include "Windows/Synchronization.h" + +#include "../IStream.h" + +class CMemBlockManager +{ + void *_data; + size_t _blockSize; + void *_headFree; +public: + CMemBlockManager(size_t blockSize = (1 << 20)): _data(0), _blockSize(blockSize), _headFree(0) {} + ~CMemBlockManager() { FreeSpace(); } + + bool AllocateSpace(size_t numBlocks); + void FreeSpace(); + size_t GetBlockSize() const { return _blockSize; } + void *AllocateBlock(); + void FreeBlock(void *p); +}; + + +class CMemBlockManagerMt: public CMemBlockManager +{ + NWindows::NSynchronization::CCriticalSection _criticalSection; +public: + NWindows::NSynchronization::CSemaphore Semaphore; + + CMemBlockManagerMt(size_t blockSize = (1 << 20)): CMemBlockManager(blockSize) {} + ~CMemBlockManagerMt() { FreeSpace(); } + + bool AllocateSpace(size_t numBlocks, size_t numNoLockBlocks = 0); + bool AllocateSpaceAlways(size_t desiredNumberOfBlocks, size_t numNoLockBlocks = 0); + void FreeSpace(); + void *AllocateBlock(); + void FreeBlock(void *p, bool lockMode = true); + bool ReleaseLockedBlocks(int number) { return Semaphore.Release(number); } +}; + + +class CMemBlocks +{ + void Free(CMemBlockManagerMt *manager); +public: + CRecordVector Blocks; + UInt64 TotalSize; + + CMemBlocks(): TotalSize(0) {} + + void FreeOpt(CMemBlockManagerMt *manager); + HRESULT WriteToStream(size_t blockSize, ISequentialOutStream *outStream) const; +}; + +struct CMemLockBlocks: public CMemBlocks +{ + bool LockMode; + + CMemLockBlocks(): LockMode(true) {}; + void Free(CMemBlockManagerMt *memManager); + void FreeBlock(int index, CMemBlockManagerMt *memManager); + bool SwitchToNoLockMode(CMemBlockManagerMt *memManager); + void Detach(CMemLockBlocks &blocks, CMemBlockManagerMt *memManager); +}; + +#endif diff --git a/7zip/Common/OutMemStream.cpp b/7zip/Common/OutMemStream.cpp new file mode 100755 index 00000000..2953afd8 --- /dev/null +++ b/7zip/Common/OutMemStream.cpp @@ -0,0 +1,137 @@ +// OutMemStream.cpp + +#include "StdAfx.h" + +#include "OutMemStream.h" + +void COutMemStream::Free() +{ + Blocks.Free(_memManager); + Blocks.LockMode = true; +} + +void COutMemStream::Init() +{ + WriteToRealStreamEvent.Reset(); + _unlockEventWasSent = false; + _realStreamMode = false; + Free(); + _curBlockPos = 0; + _curBlockIndex = 0; +} + +void COutMemStream::DetachData(CMemLockBlocks &blocks) +{ + Blocks.Detach(blocks, _memManager); + Free(); +} + + +HRESULT COutMemStream::WriteToRealStream() +{ + RINOK(Blocks.WriteToStream(_memManager->GetBlockSize(), OutSeqStream)); + Blocks.Free(_memManager); + return S_OK; +} + +STDMETHODIMP COutMemStream::Write(const void *data, UInt32 size, UInt32 *processedSize) +{ + if (_realStreamMode) + return OutSeqStream->Write(data, size, processedSize); + if (processedSize != 0) + *processedSize = 0; + while(size != 0) + { + if ((int)_curBlockIndex < Blocks.Blocks.Size()) + { + Byte *p = (Byte *)Blocks.Blocks[(int)_curBlockIndex] + _curBlockPos; + size_t curSize = _memManager->GetBlockSize() - _curBlockPos; + if (size < curSize) + curSize = size; + memmove(p, data, curSize); + if (processedSize != 0) + *processedSize += (UInt32)curSize; + data = (const void *)((const Byte *)data + curSize); + size -= (UInt32)curSize; + _curBlockPos += curSize; + + UInt64 pos64 = GetPos(); + if (pos64 > Blocks.TotalSize) + Blocks.TotalSize = pos64; + if (_curBlockPos == _memManager->GetBlockSize()) + { + _curBlockIndex++; + _curBlockPos = 0; + } + continue; + } + HANDLE events[4] = { StopWritingEvent, WriteToRealStreamEvent, NoLockEvent, _memManager->Semaphore }; + DWORD waitResult = ::WaitForMultipleObjects((Blocks.LockMode ? 4 : 2), events, FALSE, INFINITE); + switch (waitResult) + { + case (WAIT_OBJECT_0 + 0): + return StopWriteResult; + case (WAIT_OBJECT_0 + 1): + { + _realStreamMode = true; + RINOK(WriteToRealStream()); + UInt32 processedSize2; + HRESULT res = OutSeqStream->Write(data, size, &processedSize2); + if (processedSize != 0) + *processedSize += processedSize2; + return res; + } + case (WAIT_OBJECT_0 + 2): + { + if (!Blocks.SwitchToNoLockMode(_memManager)) + return E_FAIL; + break; + } + case (WAIT_OBJECT_0 + 3): + break; + default: + return E_FAIL; + } + Blocks.Blocks.Add(_memManager->AllocateBlock()); + } + return S_OK; +} + +STDMETHODIMP COutMemStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) +{ + if (_realStreamMode) + { + if (!OutStream) + return E_FAIL; + return OutStream->Seek(offset, seekOrigin, newPosition); + } + if (seekOrigin == STREAM_SEEK_CUR) + { + if (offset != 0) + return E_NOTIMPL; + } + else if (seekOrigin == STREAM_SEEK_SET) + { + if (offset != 0) + return E_NOTIMPL; + _curBlockIndex = 0; + _curBlockPos = 0; + } + else + return E_NOTIMPL; + if (newPosition != 0) + *newPosition = GetPos(); + return S_OK; +} + +STDMETHODIMP COutMemStream::SetSize(Int64 newSize) +{ + if (_realStreamMode) + { + if (!OutStream) + return E_FAIL; + return OutStream->SetSize(newSize); + } + Blocks.TotalSize = newSize; + return S_OK; +} diff --git a/7zip/Common/OutMemStream.h b/7zip/Common/OutMemStream.h new file mode 100755 index 00000000..ea98de17 --- /dev/null +++ b/7zip/Common/OutMemStream.h @@ -0,0 +1,88 @@ +// OutMemStream.h + +#ifndef __OUTMEMSTREAM_H +#define __OUTMEMSTREAM_H + +#include "Common/MyCom.h" +#include "MemBlocks.h" + +class COutMemStream: + public IOutStream, + public CMyUnknownImp +{ + CMemBlockManagerMt *_memManager; + size_t _curBlockIndex; + size_t _curBlockPos; + bool _realStreamMode; + + bool _unlockEventWasSent; + NWindows::NSynchronization::CAutoResetEvent StopWritingEvent; + NWindows::NSynchronization::CAutoResetEvent WriteToRealStreamEvent; + NWindows::NSynchronization::CAutoResetEvent NoLockEvent; + + HRESULT StopWriteResult; + CMemLockBlocks Blocks; + + UInt64 GetPos() const { return (UInt64)_curBlockIndex * _memManager->GetBlockSize() + _curBlockPos; } + + CMyComPtr OutSeqStream; + CMyComPtr OutStream; + +public: + + void SetOutStream(IOutStream *outStream) + { + OutStream = outStream; + OutSeqStream = outStream; + } + + void SetSeqOutStream(ISequentialOutStream *outStream) + { + OutStream = NULL; + OutSeqStream = outStream; + } + + void ReleaseOutStream() + { + OutStream.Release(); + OutSeqStream.Release(); + } + + COutMemStream(CMemBlockManagerMt *memManager): _memManager(memManager) { } + + ~COutMemStream() { Free(); } + void Free(); + + void Init(); + HRESULT WriteToRealStream(); + + void DetachData(CMemLockBlocks &blocks); + + bool WasUnlockEventSent() const { return _unlockEventWasSent; } + + void SetRealStreamMode() + { + _unlockEventWasSent = true; + WriteToRealStreamEvent.Set(); + } + + void SetNoLockMode() + { + _unlockEventWasSent = true; + NoLockEvent.Set(); + } + + void StopWriting(HRESULT res) + { + StopWriteResult = res; + StopWritingEvent.Set(); + } + + MY_UNKNOWN_IMP + + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); + STDMETHOD(SetSize)(Int64 newSize); +}; + +#endif diff --git a/7zip/Common/ProgressMt.cpp b/7zip/Common/ProgressMt.cpp new file mode 100755 index 00000000..319bd241 --- /dev/null +++ b/7zip/Common/ProgressMt.cpp @@ -0,0 +1,53 @@ +// ProgressMt.h + +#include "StdAfx.h" + +#include "ProgressMt.h" + +void CMtCompressProgressMixer::Init(int numItems, ICompressProgressInfo *progress) +{ + NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); + InSizes.Clear(); + OutSizes.Clear(); + for (int i = 0; i < numItems; i++) + { + InSizes.Add(0); + OutSizes.Add(0); + } + TotalInSize = 0; + TotalOutSize = 0; + _progress = progress; +} + +void CMtCompressProgressMixer::Reinit(int index) +{ + NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); + InSizes[index] = 0; + OutSizes[index] = 0; +} + +HRESULT CMtCompressProgressMixer::SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize) +{ + NWindows::NSynchronization::CCriticalSectionLock lock(CriticalSection); + if (inSize != 0) + { + UInt64 diff = *inSize - InSizes[index]; + InSizes[index] = *inSize; + TotalInSize += diff; + } + if (outSize != 0) + { + UInt64 diff = *outSize - OutSizes[index]; + OutSizes[index] = *outSize; + TotalOutSize += diff; + } + if (_progress) + return _progress->SetRatioInfo(&TotalInSize, &TotalOutSize); + return S_OK; +} + + +STDMETHODIMP CMtCompressProgress::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) +{ + return _progress->SetRatioInfo(_index, inSize, outSize); +} diff --git a/7zip/Common/ProgressMt.h b/7zip/Common/ProgressMt.h new file mode 100755 index 00000000..c0776944 --- /dev/null +++ b/7zip/Common/ProgressMt.h @@ -0,0 +1,47 @@ +// ProgressMt.h + +#ifndef __PROGRESSMT_H +#define __PROGRESSMT_H + +#include "../../Common/MyCom.h" + +#include "../ICoder.h" +#include "../IProgress.h" + +#include "Windows/Synchronization.h" +#include "../../Common/Vector.h" + +class CMtCompressProgressMixer +{ + CMyComPtr _progress; + CRecordVector InSizes; + CRecordVector OutSizes; + UInt64 TotalInSize; + UInt64 TotalOutSize; +public: + NWindows::NSynchronization::CCriticalSection CriticalSection; + void Init(int numItems, ICompressProgressInfo *progress); + void Reinit(int index); + HRESULT SetRatioInfo(int index, const UInt64 *inSize, const UInt64 *outSize); +}; + +class CMtCompressProgress: + public ICompressProgressInfo, + public CMyUnknownImp +{ + CMtCompressProgressMixer *_progress; + int _index; +public: + void Init(CMtCompressProgressMixer *progress, int index) + { + _progress = progress; + _index = index; + } + void Reinit() { _progress->Reinit(_index); } + + MY_UNKNOWN_IMP + + STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); +}; + +#endif diff --git a/7zip/Common/ProgressUtils.cpp b/7zip/Common/ProgressUtils.cpp index 382e7980..40e13877 100755 --- a/7zip/Common/ProgressUtils.cpp +++ b/7zip/Common/ProgressUtils.cpp @@ -40,9 +40,7 @@ STDMETHODIMP CLocalCompressProgressInfo::SetRatioInfo( return _progress->SetRatioInfo(inSizeNewPointer, outSizeNewPointer); } - /////////////////////////////////// -// void CLocalProgress::Init(IProgress *progress, bool inSizeIsMain) { @@ -55,4 +53,3 @@ STDMETHODIMP CLocalProgress::SetRatioInfo( { return _progress->SetCompleted(_inSizeIsMain ? inSize : outSize); } - diff --git a/7zip/Common/StreamObjects.cpp b/7zip/Common/StreamObjects.cpp index c89f64e1..32f8f306 100755 --- a/7zip/Common/StreamObjects.cpp +++ b/7zip/Common/StreamObjects.cpp @@ -57,40 +57,6 @@ STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 return result; } -STDMETHODIMP CSequentialInStreamRollback::Read(void *data, UInt32 size, UInt32 *processedSize) -{ - if (_currentPos != _currentSize) - { - size_t curSize = _currentSize - _currentPos; - if (size > curSize) - size = (UInt32)curSize; - memmove(data, _buffer + _currentPos, size); - _currentPos += size; - if (processedSize != 0) - *processedSize = size; - return S_OK; - } - UInt32 realProcessedSize; - if (size > _bufferSize) - size = (UInt32)_bufferSize; - HRESULT result = _stream->Read(_buffer, size, &realProcessedSize); - memmove(data, _buffer, realProcessedSize); - _size += realProcessedSize; - _currentSize = realProcessedSize; - _currentPos = realProcessedSize; - if (processedSize != 0) - *processedSize = realProcessedSize; - return result; -} - -HRESULT CSequentialInStreamRollback::Rollback(size_t rollbackSize) -{ - if (rollbackSize > _currentPos) - return E_INVALIDARG; - _currentPos -= rollbackSize; - return S_OK; -} - STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize) { UInt32 realProcessedSize; diff --git a/7zip/Common/StreamObjects.h b/7zip/Common/StreamObjects.h index 4dd01e47..6f670f59 100755 --- a/7zip/Common/StreamObjects.h +++ b/7zip/Common/StreamObjects.h @@ -61,9 +61,9 @@ class CSequentialOutStreamImp2: public CMyUnknownImp { Byte *_buffer; -public: size_t _size; size_t _pos; +public: void Init(Byte *buffer, size_t size) { @@ -72,6 +72,8 @@ public: _size = size; } + size_t GetPos() const { return _pos; } + MY_UNKNOWN_IMP STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); @@ -96,44 +98,6 @@ public: STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); }; -class CSequentialInStreamRollback: - public ISequentialInStream, - public CMyUnknownImp -{ - CMyComPtr _stream; - Byte *_buffer; - size_t _bufferSize; - UInt64 _size; - - size_t _currentSize; - size_t _currentPos; -public: - CSequentialInStreamRollback(size_t bufferSize): - _bufferSize(bufferSize), - _buffer(0) - { - _buffer = new Byte[bufferSize]; - } - ~CSequentialInStreamRollback() - { - delete _buffer; - } - - void Init(ISequentialInStream *stream) - { - _stream = stream; - _size = 0; - _currentSize = 0; - _currentPos = 0; - } - UInt64 GetSize() const { return _size; } - - MY_UNKNOWN_IMP - - STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); - HRESULT Rollback(size_t rollbackSize); -}; - class CSequentialOutStreamSizeCount: public ISequentialOutStream, public CMyUnknownImp @@ -141,11 +105,8 @@ class CSequentialOutStreamSizeCount: CMyComPtr _stream; UInt64 _size; public: - void Init(ISequentialOutStream *stream) - { - _stream = stream; - _size = 0; - } + void SetStream(ISequentialOutStream *stream) { _stream = stream; } + void Init() { _size = 0; } UInt64 GetSize() const { return _size; } MY_UNKNOWN_IMP diff --git a/7zip/Compress/Arj/ArjDecoder1.cpp b/7zip/Compress/Arj/ArjDecoder1.cpp index a560f443..7f720807 100755 --- a/7zip/Compress/Arj/ArjDecoder1.cpp +++ b/7zip/Compress/Arj/ArjDecoder1.cpp @@ -238,7 +238,7 @@ UInt32 CCoder::decode_p() STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { if (outSize == NULL) @@ -288,7 +288,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, UInt32 number = decode_c(); if (number < 256) { - m_OutWindowStream.PutByte(number); + m_OutWindowStream.PutByte((Byte)number); pos++; continue; } diff --git a/7zip/Compress/Arj/ArjDecoder2.cpp b/7zip/Compress/Arj/ArjDecoder2.cpp index 1fb20649..a734d1b4 100755 --- a/7zip/Compress/Arj/ArjDecoder2.cpp +++ b/7zip/Compress/Arj/ArjDecoder2.cpp @@ -13,8 +13,8 @@ static const UInt32 kMatchMaxLen = 256; static const UInt32 kMatchMinLen = 3; STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, - ICompressProgressInfo *progress) + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, + ICompressProgressInfo * /* progress */) { if (outSize == NULL) return E_INVALIDARG; @@ -49,7 +49,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, len += m_InBitStream.ReadBits(width); if (len == 0) { - m_OutWindowStream.PutByte(m_InBitStream.ReadBits(8)); + m_OutWindowStream.PutByte((Byte)m_InBitStream.ReadBits(8)); pos++; continue; } diff --git a/7zip/Compress/BWT/BlockSort.cpp b/7zip/Compress/BWT/BlockSort.cpp index 2729004a..ffe7dd9d 100755 --- a/7zip/Compress/BWT/BlockSort.cpp +++ b/7zip/Compress/BWT/BlockSort.cpp @@ -140,7 +140,7 @@ UInt32 CBlockSorter::SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask for (j = 0; j < groupSize; j++) { UInt32 group = groupOffset + j; - while (true) + for (;;) { Groups[ind2[j]] = group; if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0) @@ -154,7 +154,7 @@ UInt32 CBlockSorter::SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask // Radix-Range Sort UInt32 i; - do + for (;;) { if (maskSize == 0) return 1; @@ -193,7 +193,6 @@ UInt32 CBlockSorter::SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask else break; } - while(true); UInt32 t = (groupOffset + i - 1); Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); @@ -251,7 +250,7 @@ UInt32 CBlockSorter::Sort(const Byte *data, UInt32 blockSize) UInt32 mask; for (mask = 2; mask < blockSize; mask <<= 1); mask >>= 1; - for (NumSortedBytes = kNumHashBytes; true; NumSortedBytes <<= 1) + for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1) { UInt32 newLimit = 0; for (i = 0; i < blockSize;) diff --git a/7zip/Compress/BWT/Mtf8.h b/7zip/Compress/BWT/Mtf8.h index 4c0fb9cf..d6c1c41a 100755 --- a/7zip/Compress/BWT/Mtf8.h +++ b/7zip/Compress/BWT/Mtf8.h @@ -38,7 +38,7 @@ class CMtf8Decoder { public: Byte Buffer[256]; - void Init(int size) {}; + void Init(int /* size */) {}; Byte GetHead() const { return Buffer[0]; } Byte GetAndMove(int pos) { diff --git a/7zip/Compress/BZip2/BZip2Decoder.cpp b/7zip/Compress/BZip2/BZip2Decoder.cpp index 5ff5f530..3f45e665 100755 --- a/7zip/Compress/BZip2/BZip2Decoder.cpp +++ b/7zip/Compress/BZip2/BZip2Decoder.cpp @@ -97,7 +97,7 @@ void CState::FinishStream(bool needLeave) DWORD CState::ThreadFunc() { - while (true) + for (;;) { Decoder->CS.Enter(); if (Decoder->CloseThreads) @@ -262,7 +262,7 @@ HRESULT CDecoder::ReadBlock(UInt32 blockSizeMax, CState &state) int i; for (i = 0; i < alphaSize; i++) { - while (true) + for (;;) { if (len < 1 || len > kMaxHuffmanLen) return S_FALSE; @@ -295,7 +295,7 @@ HRESULT CDecoder::ReadBlock(UInt32 blockSizeMax, CState &state) int runPower = 0; UInt32 runCounter = 0; - while (true) + for (;;) { if (groupSize == 0) { @@ -572,7 +572,7 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress) #endif { CState &state = m_States[0]; - while (true) + for (;;) { if (progress) { @@ -596,7 +596,7 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress) } HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress) { if (!m_InStream.Create(kBufferSize)) diff --git a/7zip/Compress/BZip2/BZip2Encoder.cpp b/7zip/Compress/BZip2/BZip2Encoder.cpp index d827d4f3..97009041 100755 --- a/7zip/Compress/BZip2/BZip2Encoder.cpp +++ b/7zip/Compress/BZip2/BZip2Encoder.cpp @@ -58,7 +58,7 @@ void CThreadInfo::FinishStream(bool needLeave) DWORD CThreadInfo::ThreadFunc() { - while (true) + for (;;) { Encoder->CS.Enter(); if (Encoder->CloseThreads) @@ -190,7 +190,7 @@ UInt32 CEncoder::ReadRleBlock(Byte *buffer) if (b != prevByte) { if (numReps >= kRleModeRepSize) - buffer[i++] = numReps - kRleModeRepSize; + buffer[i++] = (Byte)(numReps - kRleModeRepSize); buffer[i++] = b; numReps = 1; prevByte = b; @@ -201,13 +201,13 @@ UInt32 CEncoder::ReadRleBlock(Byte *buffer) buffer[i++] = b; else if (numReps == kRleModeRepSize + 255) { - buffer[i++] = numReps - kRleModeRepSize; + buffer[i++] = (Byte)(numReps - kRleModeRepSize); numReps = 0; } } // it's to support original BZip2 decoder if (numReps >= kRleModeRepSize) - buffer[i++] = numReps - kRleModeRepSize; + buffer[i++] = (Byte)(numReps - kRleModeRepSize); } return i; } @@ -295,17 +295,17 @@ void CThreadInfo::EncodeBlock(Byte *block, UInt32 blockSize) while (rleSize != 0) { rleSize--; - mtfs[mtfArraySize++] = (rleSize & 1); + mtfs[mtfArraySize++] = (Byte)(rleSize & 1); symbolCounts[rleSize & 1]++; rleSize >>= 1; } if (pos >= 0xFE) { mtfs[mtfArraySize++] = 0xFF; - mtfs[mtfArraySize++] = pos - 0xFE; + mtfs[mtfArraySize++] = (Byte)(pos - 0xFE); } else - mtfs[mtfArraySize++] = pos + 1; + mtfs[mtfArraySize++] = (Byte)(pos + 1); symbolCounts[pos + 1]++; } } @@ -314,7 +314,7 @@ void CThreadInfo::EncodeBlock(Byte *block, UInt32 blockSize) while (rleSize != 0) { rleSize--; - mtfs[mtfArraySize++] = (rleSize & 1); + mtfs[mtfArraySize++] = (Byte)(rleSize & 1); symbolCounts[rleSize & 1]++; rleSize >>= 1; } @@ -338,7 +338,7 @@ void CThreadInfo::EncodeBlock(Byte *block, UInt32 blockSize) int bestNumTables = kNumTablesMin; UInt32 bestPrice = 0xFFFFFFFF; UInt32 startPos = m_OutStreamCurrent->GetPos(); - UInt32 startCurByte = m_OutStreamCurrent->GetCurByte(); + Byte startCurByte = m_OutStreamCurrent->GetCurByte(); for (int nt = kNumTablesMin; nt <= kNumTablesMax + 1; nt++) { int numTables; @@ -596,9 +596,9 @@ void CThreadInfo::EncodeBlock2(Byte *block, UInt32 blockSize, UInt32 numPasses) UInt32 startBytePos = m_OutStreamCurrent->GetBytePos(); UInt32 startPos = m_OutStreamCurrent->GetPos(); - UInt32 startCurByte = m_OutStreamCurrent->GetCurByte(); - UInt32 endCurByte; - UInt32 endPos; + Byte startCurByte = m_OutStreamCurrent->GetCurByte(); + Byte endCurByte = 0; + UInt32 endPos = 0; if (numPasses > 1 && blockSize >= (1 << 10)) { UInt32 blockSize0 = blockSize / 2; @@ -697,7 +697,7 @@ void CEncoder::WriteBytes(const Byte *data, UInt32 sizeInBits, Byte lastByte) HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress) { #ifdef COMPRESS_BZIP2_MT @@ -771,7 +771,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, else #endif { - while (true) + for (;;) { CThreadInfo &ti = #ifdef COMPRESS_BZIP2_MT diff --git a/7zip/Compress/BZip2/DllExports.cpp b/7zip/Compress/BZip2/DllExports.cpp index d0b8b99e..c528e98c 100755 --- a/7zip/Compress/BZip2/DllExports.cpp +++ b/7zip/Compress/BZip2/DllExports.cpp @@ -20,7 +20,7 @@ DEFINE_GUID(CLSID_CCompressBZip2Encoder, 0x23170F69, 0x40C1, 0x278B, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD dwReason, LPVOID /*lpReserved*/) { #ifdef _WIN32 if (dwReason == DLL_PROCESS_ATTACH) diff --git a/7zip/Compress/BZip2Original/BZip2Decoder.cpp b/7zip/Compress/BZip2Original/BZip2Decoder.cpp index 2f691f09..5fb77d01 100755 --- a/7zip/Compress/BZip2Original/BZip2Decoder.cpp +++ b/7zip/Compress/BZip2Original/BZip2Decoder.cpp @@ -65,7 +65,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, } CBZip2DecompressorReleaser releaser(&bzStream); bzStream.avail_in = 0; - while (true) + for (;;) { if (bzStream.avail_in == 0) { diff --git a/7zip/Compress/BZip2Original/BZip2Encoder.cpp b/7zip/Compress/BZip2Original/BZip2Encoder.cpp index 4580347d..bcd7dec0 100755 --- a/7zip/Compress/BZip2Original/BZip2Encoder.cpp +++ b/7zip/Compress/BZip2Original/BZip2Encoder.cpp @@ -66,7 +66,7 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, } CBZip2CompressorReleaser releaser(&bzStream); bzStream.avail_in = 0; - while (true) + for (;;) { if (bzStream.avail_in == 0) { diff --git a/7zip/Compress/Branch/BranchARM.c b/7zip/Compress/Branch/BranchARM.c index 7e0bbf8b..6d4e3672 100755 --- a/7zip/Compress/Branch/BranchARM.c +++ b/7zip/Compress/Branch/BranchARM.c @@ -1,4 +1,4 @@ -// BranchARM.c +/* BranchARM.c */ #include "BranchARM.h" @@ -17,9 +17,9 @@ UInt32 ARM_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) else dest = src - (nowPos + i + 8); dest >>= 2; - data[i + 2] = (dest >> 16); - data[i + 1] = (dest >> 8); - data[i + 0] = dest; + data[i + 2] = (Byte)(dest >> 16); + data[i + 1] = (Byte)(dest >> 8); + data[i + 0] = (Byte)dest; } } return i; diff --git a/7zip/Compress/Branch/BranchARMThumb.c b/7zip/Compress/Branch/BranchARMThumb.c index d30b75c1..aab9c7a1 100755 --- a/7zip/Compress/Branch/BranchARMThumb.c +++ b/7zip/Compress/Branch/BranchARMThumb.c @@ -1,4 +1,4 @@ -// BranchARMThumb.c +/* BranchARMThumb.c */ #include "BranchARMThumb.h" @@ -24,10 +24,10 @@ UInt32 ARMThumb_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) dest = src - (nowPos + i + 4); dest >>= 1; - data[i + 1] = 0xF0 | ((dest >> 19) & 0x7); - data[i + 0] = (dest >> 11); - data[i + 3] = 0xF8 | ((dest >> 8) & 0x7); - data[i + 2] = (dest); + data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); + data[i + 0] = (Byte)(dest >> 11); + data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); + data[i + 2] = (Byte)dest; i += 2; } } diff --git a/7zip/Compress/Branch/BranchIA64.c b/7zip/Compress/Branch/BranchIA64.c index 55c03fa4..e7775564 100755 --- a/7zip/Compress/Branch/BranchIA64.c +++ b/7zip/Compress/Branch/BranchIA64.c @@ -1,4 +1,4 @@ -// BranchIA64.c +/* BranchIA64.c */ #include "BranchIA64.h" @@ -24,7 +24,6 @@ UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) continue; UInt32 bytePos = (bitPos >> 3); UInt32 bitRes = bitPos & 0x7; - // UInt64 instruction = *(UInt64 *)(data + i + bytePos); UInt64 instruction = 0; int j; for (j = 0; j < 6; j++) @@ -33,7 +32,7 @@ UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) UInt64 instNorm = instruction >> bitRes; if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0 - // && (instNorm & 0x3F)== 0 + /* && (instNorm & 0x3F)== 0 */ ) { UInt32 src = UInt32((instNorm >> 13) & 0xFFFFF); @@ -55,7 +54,6 @@ UInt32 IA64_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) instruction &= (1 << bitRes) - 1; instruction |= (instNorm << bitRes); - // *(UInt64 *)(data + i + bytePos) = instruction; for (j = 0; j < 6; j++) data[i + j + bytePos] = Byte(instruction >> (8 * j)); } diff --git a/7zip/Compress/Branch/BranchPPC.c b/7zip/Compress/Branch/BranchPPC.c index eb3aafb4..b3e5703f 100755 --- a/7zip/Compress/Branch/BranchPPC.c +++ b/7zip/Compress/Branch/BranchPPC.c @@ -1,4 +1,4 @@ -// BranchPPC.c +/* BranchPPC.c */ #include "BranchPPC.h" @@ -7,11 +7,11 @@ UInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) UInt32 i; for (i = 0; i + 4 <= size; i += 4) { - // PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) + /* PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link) */ if ((data[i] >> 2) == 0x12 && ( (data[i + 3] & 3) == 1 - // || (data[i+3] & 3) == 3 + /* || (data[i+3] & 3) == 3 */ ) ) { @@ -25,9 +25,9 @@ UInt32 PPC_B_Convert(Byte *data, UInt32 size, UInt32 nowPos, int encoding) dest = nowPos + i + src; else dest = src - (nowPos + i); - data[i + 0] = 0x48 | ((dest >> 24) & 0x3); - data[i + 1] = (dest >> 16); - data[i + 2] = (dest >> 8); + data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); + data[i + 1] = (Byte)(dest >> 16); + data[i + 2] = (Byte)(dest >> 8); data[i + 3] &= 0x3; data[i + 3] |= dest; } diff --git a/7zip/Compress/Branch/BranchSPARC.c b/7zip/Compress/Branch/BranchSPARC.c index a8d3f4dc..c175875b 100755 --- a/7zip/Compress/Branch/BranchSPARC.c +++ b/7zip/Compress/Branch/BranchSPARC.c @@ -1,4 +1,4 @@ -// BranchSPARC.c +/* BranchSPARC.c */ #include "BranchSPARC.h" diff --git a/7zip/Compress/Branch/BranchTypes.h b/7zip/Compress/Branch/BranchTypes.h index 6472ef6b..f7ad3abc 100755 --- a/7zip/Compress/Branch/BranchTypes.h +++ b/7zip/Compress/Branch/BranchTypes.h @@ -3,13 +3,23 @@ #ifndef __BRANCHTYPES_H #define __BRANCHTYPES_H +#ifndef _7ZIP_BYTE_DEFINED +#define _7ZIP_BYTE_DEFINED typedef unsigned char Byte; +#endif + +#ifndef _7ZIP_UINT16_DEFINED +#define _7ZIP_UINT16_DEFINED typedef unsigned short UInt16; +#endif +#ifndef _7ZIP_UINT32_DEFINED +#define _7ZIP_UINT32_DEFINED #ifdef _LZMA_UINT32_IS_ULONG typedef unsigned long UInt32; #else typedef unsigned int UInt32; #endif +#endif #endif diff --git a/7zip/Compress/Branch/BranchX86.c b/7zip/Compress/Branch/BranchX86.c index 2c6f69a5..c3f455b8 100755 --- a/7zip/Compress/Branch/BranchX86.c +++ b/7zip/Compress/Branch/BranchX86.c @@ -67,7 +67,7 @@ UInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, (buffer[bufferPos + 1]); UInt32 dest; - while(1) + for (;;) { UInt32 index; if (encoding) diff --git a/7zip/Compress/Branch/DllExports.cpp b/7zip/Compress/Branch/DllExports.cpp index 55f399e4..e7928f75 100755 --- a/7zip/Compress/Branch/DllExports.cpp +++ b/7zip/Compress/Branch/DllExports.cpp @@ -25,9 +25,9 @@ if (*clsid == CLSID_CCompressConvert ## n ## _Encoder) { \ } extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject( diff --git a/7zip/Compress/Branch/x86_2.cpp b/7zip/Compress/Branch/x86_2.cpp index 8f7bff21..ca37ab83 100755 --- a/7zip/Compress/Branch/x86_2.cpp +++ b/7zip/Compress/Branch/x86_2.cpp @@ -58,7 +58,7 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams, ISequentialOutStream **outStreams, - const UInt64 **outSizes, + const UInt64 ** /* outSizes */, UInt32 numOutStreams, ICompressProgressInfo *progress) { @@ -69,7 +69,7 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, return E_OUTOFMEMORY; bool sizeIsDefined = false; - UInt64 inSize; + UInt64 inSize = 0; if (inSizes != NULL) if (inSizes[0] != NULL) { @@ -109,10 +109,10 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, UInt64 subStreamStartPos = 0; UInt64 subStreamEndPos = 0; - while(true) + for (;;) { UInt32 processedSize = 0; - while(true) + for (;;) { UInt32 size = kBufferSize - (bufferPos + processedSize); UInt32 processedSizeLoc; @@ -279,10 +279,10 @@ STDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams, #endif HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, - const UInt64 **inSizes, + const UInt64 ** /* inSizes */, UInt32 numInStreams, ISequentialOutStream **outStreams, - const UInt64 **outSizes, + const UInt64 ** /* outSizes */, UInt32 numOutStreams, ICompressProgressInfo *progress) { @@ -321,7 +321,7 @@ HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, Byte prevByte = 0; UInt32 processedBytes = 0; - while(true) + for (;;) { if (processedBytes > (1 << 20) && progress != NULL) { @@ -386,7 +386,7 @@ HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, _outStream.WriteByte((Byte)(dest >> 8)); _outStream.WriteByte((Byte)(dest >> 16)); _outStream.WriteByte((Byte)(dest >> 24)); - prevByte = (dest >> 24); + prevByte = (Byte)(dest >> 24); processedBytes += 4; } else diff --git a/7zip/Compress/ByteSwap/DllExports.cpp b/7zip/Compress/ByteSwap/DllExports.cpp index 61a02c8d..cc737590 100755 --- a/7zip/Compress/ByteSwap/DllExports.cpp +++ b/7zip/Compress/ByteSwap/DllExports.cpp @@ -8,9 +8,9 @@ #include "../../ICoder.h" extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject) diff --git a/7zip/Compress/Copy/CopyCoder.cpp b/7zip/Compress/Copy/CopyCoder.cpp index ab81ba29..ce1bde03 100755 --- a/7zip/Compress/Copy/CopyCoder.cpp +++ b/7zip/Compress/Copy/CopyCoder.cpp @@ -17,7 +17,7 @@ CCopyCoder::~CCopyCoder() STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, - const UInt64 *inSize, const UInt64 *outSize, + const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { if (_buffer == 0) @@ -28,7 +28,7 @@ STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, } TotalSize = 0; - while(true) + for (;;) { UInt32 realProcessedSize; UInt32 size = kBufferSize; diff --git a/7zip/Compress/Copy/DllExports.cpp b/7zip/Compress/Copy/DllExports.cpp index 01d52dbf..756dcc9c 100755 --- a/7zip/Compress/Copy/DllExports.cpp +++ b/7zip/Compress/Copy/DllExports.cpp @@ -12,9 +12,9 @@ DEFINE_GUID(CLSID_CCompressCopyCoder, 0x23170F69, 0x40C1, 0x278B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject) diff --git a/7zip/Compress/Copy/StdAfx.h b/7zip/Compress/Copy/StdAfx.h index 8531cc9c..92239aeb 100755 --- a/7zip/Compress/Copy/StdAfx.h +++ b/7zip/Compress/Copy/StdAfx.h @@ -4,6 +4,5 @@ #define __STDAFX_H #include "../../../Common/MyWindows.h" -#include "../../../Common/NewHandler.h" #endif diff --git a/7zip/Compress/Deflate/DeflateDecoder.cpp b/7zip/Compress/Deflate/DeflateDecoder.cpp index 78a4e47f..0de5534b 100755 --- a/7zip/Compress/Deflate/DeflateDecoder.cpp +++ b/7zip/Compress/Deflate/DeflateDecoder.cpp @@ -241,7 +241,7 @@ HRESULT CCoder::CodeReal(ISequentialInStream *inStream, CCoderReleaser flusher(this); const UInt64 start = m_OutWindowStream.GetProcessedSize(); - while(true) + for (;;) { UInt32 curSize = 1 << 18; if (outSize != 0) @@ -311,7 +311,7 @@ STDMETHODIMP CCoder::ReleaseInStream() return S_OK; } -STDMETHODIMP CCoder::SetOutStreamSize(const UInt64 *outSize) +STDMETHODIMP CCoder::SetOutStreamSize(const UInt64 * /* outSize */) { _remainLen = kLenIdNeedInit; m_OutWindowStream.Init(_keepHistory); diff --git a/7zip/Compress/Deflate/DeflateEncoder.cpp b/7zip/Compress/Deflate/DeflateEncoder.cpp index a3e9f4aa..8a0f4746 100755 --- a/7zip/Compress/Deflate/DeflateEncoder.cpp +++ b/7zip/Compress/Deflate/DeflateEncoder.cpp @@ -335,7 +335,7 @@ UInt32 CCoder::GetOptimal(UInt32 &backRes) { UInt32 distance = matchDistances[offs + 1]; m_Optimum[i].PosPrev = 0; - m_Optimum[i].BackPrev = distance; + m_Optimum[i].BackPrev = (UInt16)distance; m_Optimum[i].Price = m_LenPrices[i - kMatchMinLen] + m_PosPrices[GetPosSlot(distance)]; if (i == matchDistances[offs]) offs += 2; @@ -343,7 +343,7 @@ UInt32 CCoder::GetOptimal(UInt32 &backRes) UInt32 cur = 0; UInt32 lenEnd = lenMain; - while(true) + for (;;) { ++cur; if(cur == lenEnd || cur == kNumOptsBase || m_Pos >= kMatchArrayLimit) @@ -360,7 +360,8 @@ UInt32 CCoder::GetOptimal(UInt32 &backRes) { UInt32 len = Backward(backRes, cur); m_Optimum[cur].BackPrev = matchDistances[numDistancePairs - 1]; - m_Optimum[cur].PosPrev = m_OptimumEndIndex = cur + newLen; + m_OptimumEndIndex = cur + newLen; + m_Optimum[cur].PosPrev = (UInt16)m_OptimumEndIndex; MovePos(newLen - 1); return len; } @@ -388,7 +389,7 @@ UInt32 CCoder::GetOptimal(UInt32 &backRes) { optimum.Price = curAndLenPrice; optimum.PosPrev = (UInt16)cur; - optimum.BackPrev = distance; + optimum.BackPrev = (UInt16)distance; } if (lenTest == matchDistances[offs]) { @@ -545,7 +546,7 @@ void CCoder::TryBlock(bool staticMode) m_ValueIndex = 0; UInt32 blockSize = BlockSizeRes; BlockSizeRes = 0; - while(true) + for (;;) { if (m_OptimumCurrentIndex == m_OptimumEndIndex) { @@ -597,13 +598,13 @@ void CCoder::SetPrices(const CLevels &levels) { UInt32 slot = g_LenSlots[i]; Byte price = levels.litLenLevels[kSymbolMatch + slot]; - m_LenPrices[i] = ((price != 0) ? price : kNoLenStatPrice) + m_LenDirectBits[slot]; + m_LenPrices[i] = (Byte)(((price != 0) ? price : kNoLenStatPrice) + m_LenDirectBits[slot]); } for(i = 0; i < kDistTableSize64; i++) { Byte price = levels.distLevels[i]; - m_PosPrices[i] = ((price != 0) ? price: kNoPosStatPrice) + kDistDirectBits[i]; + m_PosPrices[i] = (Byte)(((price != 0) ? price: kNoPosStatPrice) + kDistDirectBits[i]); } } @@ -741,12 +742,14 @@ UInt32 CCoder::GetBlockPrice(int tableIndex, int numDivPasses) if (m_CheckStatic && m_ValueIndex <= kFixedHuffmanCodeBlockSizeMax) { const UInt32 fixedPrice = TryFixedBlock(tableIndex); - if (t.StaticMode = (fixedPrice < price)) + t.StaticMode = (fixedPrice < price); + if (t.StaticMode) price = fixedPrice; } const UInt32 storePrice = GetStorePrice(BlockSizeRes, 0); // bitPosition - if (t.StoreMode = (storePrice <= price)) + t.StoreMode = (storePrice <= price); + if (t.StoreMode) price = storePrice; t.UseSubBlocks = false; @@ -768,7 +771,8 @@ UInt32 CCoder::GetBlockPrice(int tableIndex, int numDivPasses) t1.m_Pos = m_Pos; m_AdditionalOffset -= t0.BlockSizeRes; subPrice += GetBlockPrice((tableIndex << 1) + 1, numDivPasses - 1); - if (t.UseSubBlocks = (subPrice < price)) + t.UseSubBlocks = (subPrice < price); + if (t.UseSubBlocks) price = subPrice; } } @@ -806,7 +810,7 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock) } HRESULT CCoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */ , const UInt64 * /* outSize */ , ICompressProgressInfo *progress) { m_CheckStatic = (m_NumPasses != 1 || m_NumDivPasses != 1); diff --git a/7zip/Compress/Deflate/DllExports.cpp b/7zip/Compress/Deflate/DllExports.cpp index cbfc8f44..acc431ff 100755 --- a/7zip/Compress/Deflate/DllExports.cpp +++ b/7zip/Compress/Deflate/DllExports.cpp @@ -31,9 +31,9 @@ DEFINE_GUID(CLSID_CCompressDeflateNsisDecoder, 0x23170F69, 0x40C1, 0x278B, 0x04, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject) diff --git a/7zip/Compress/Implode/ImplodeDecoder.cpp b/7zip/Compress/Implode/ImplodeDecoder.cpp index b7689f62..19634c5c 100755 --- a/7zip/Compress/Implode/ImplodeDecoder.cpp +++ b/7zip/Compress/Implode/ImplodeDecoder.cpp @@ -89,7 +89,7 @@ bool CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder, if (currentIndex + rep > numLevelItems) throw CException(CException::kData); for(int j = 0; j < rep; j++) - levels[currentIndex++] = level; + levels[currentIndex++] = (Byte)level; } if (currentIndex != numLevelItems) return false; @@ -123,7 +123,7 @@ public: }; STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { if (!m_InBitStream.Create(1 << 20)) diff --git a/7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp b/7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp index 2fbb77fd..ad2061c3 100755 --- a/7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp +++ b/7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp @@ -65,7 +65,7 @@ bool CDecoder::SetCodeLengths(const Byte *codeLengths) UInt32 CDecoder::DecodeSymbol(CInBit *inStream) { - UInt32 numBits; + UInt32 numBits = 0; UInt32 value = inStream->GetValue(kNumBitsInLongestCode); int i; for(i = kNumBitsInLongestCode; i > 0; i--) diff --git a/7zip/Compress/LZ/BinTree/BinTreeMain.h b/7zip/Compress/LZ/BinTree/BinTreeMain.h index 7a6f621a..ef9f6ce2 100755 --- a/7zip/Compress/LZ/BinTree/BinTreeMain.h +++ b/7zip/Compress/LZ/BinTree/BinTreeMain.h @@ -285,7 +285,7 @@ STDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances) } #endif UInt32 count = _cutValue; - while(true) + for (;;) { if(curMatch <= matchMinPos || count-- == 0) { @@ -418,7 +418,7 @@ STDMETHODIMP CMatchFinder::Skip(UInt32 num) UInt32 len0, len1; len0 = len1 = kNumHashDirectBytes; UInt32 count = _cutValue; - while(true) + for (;;) { if(curMatch <= matchMinPos || count-- == 0) { diff --git a/7zip/Compress/LZ/LZInWindow.cpp b/7zip/Compress/LZ/LZInWindow.cpp index 0e65c425..aacaea9d 100755 --- a/7zip/Compress/LZ/LZInWindow.cpp +++ b/7zip/Compress/LZ/LZInWindow.cpp @@ -68,7 +68,7 @@ HRESULT CLZInWindow::ReadBlock() { if(_streamEndWasReached) return S_OK; - while(true) + for (;;) { UInt32 size = (UInt32)(_bufferBase - _buffer) + _blockSize - _streamPos; if(size == 0) diff --git a/7zip/Compress/LZ/LZInWindow.h b/7zip/Compress/LZ/LZInWindow.h index 54f2cb7b..20e0331b 100755 --- a/7zip/Compress/LZ/LZInWindow.h +++ b/7zip/Compress/LZ/LZInWindow.h @@ -79,7 +79,7 @@ public: bool NeedMove(UInt32 numCheckBytes) { - UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos); + size_t reserv = (size_t)(_pointerToLastSafePosition - (_buffer + _pos)); return (reserv <= numCheckBytes); } }; diff --git a/7zip/Compress/LZ/MT/MT.cpp b/7zip/Compress/LZ/MT/MT.cpp index a96e924f..b0ac456d 100755 --- a/7zip/Compress/LZ/MT/MT.cpp +++ b/7zip/Compress/LZ/MT/MT.cpp @@ -141,7 +141,7 @@ void CMatchFinderMT::GetNextBlock() m_MtWasStarted.Lock(); m_Result = S_OK; } - while (true) + for (;;) { UInt32 nextIndex = (m_BlockIndex == kNumMTBlocks - 1) ? 0 : m_BlockIndex + 1; m_CS[nextIndex].Enter(); @@ -206,7 +206,7 @@ STDMETHODIMP CMatchFinderMT::Skip(UInt32 num) return S_OK; } -STDMETHODIMP_(Int32) CMatchFinderMT::NeedChangeBufferPos(UInt32 numCheckBytes) +STDMETHODIMP_(Int32) CMatchFinderMT::NeedChangeBufferPos(UInt32 /* numCheckBytes */) { throw 1; } @@ -219,13 +219,13 @@ STDMETHODIMP_(void) CMatchFinderMT::ChangeBufferPos() DWORD CMatchFinderMT::ThreadFunc() { - while(true) + for (;;) { bool needStartEvent = true; m_MtCanStart.Lock(); HRESULT result = S_OK; UInt32 blockIndex = 0; - while (true) + for (;;) { m_CS[blockIndex].Enter(); if (needStartEvent) diff --git a/7zip/Compress/LZMA/DllExports.cpp b/7zip/Compress/LZMA/DllExports.cpp index efd28a46..92260f9b 100755 --- a/7zip/Compress/LZMA/DllExports.cpp +++ b/7zip/Compress/LZMA/DllExports.cpp @@ -21,7 +21,7 @@ DEFINE_GUID(CLSID_CLZMAEncoder, 0x23170F69, 0x40C1, 0x278B, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD dwReason, LPVOID /*lpReserved*/) { if (dwReason == DLL_PROCESS_ATTACH) { @@ -31,7 +31,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) SetLargePageSize(); #endif } - return TRUE; + return TRUE; } STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject) diff --git a/7zip/Compress/LZMA/LZMADecoder.cpp b/7zip/Compress/LZMA/LZMADecoder.cpp index 9640d7bc..75de2245 100755 --- a/7zip/Compress/LZMA/LZMADecoder.cpp +++ b/7zip/Compress/LZMA/LZMADecoder.cpp @@ -220,7 +220,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, SetOutStreamSize(outSize); CDecoderFlusher flusher(this); - while (true) + for (;;) { UInt32 curSize = 1 << 18; RINOK(CodeSpec(curSize)); @@ -309,7 +309,8 @@ STDMETHODIMP CDecoder::ReleaseInStream() STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize) { - if (_outSizeDefined = (outSize != NULL)) + _outSizeDefined = (outSize != NULL); + if (_outSizeDefined) _outSize = *outSize; _remainLen = kLenIdNeedInit; _outWindowStream.Init(); diff --git a/7zip/Compress/LZMA/LZMAEncoder.cpp b/7zip/Compress/LZMA/LZMAEncoder.cpp index bafdb875..4f0bcf0f 100755 --- a/7zip/Compress/LZMA/LZMAEncoder.cpp +++ b/7zip/Compress/LZMA/LZMAEncoder.cpp @@ -220,7 +220,6 @@ void CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) con } CEncoder::CEncoder(): _numFastBytes(kNumFastBytesDefault), - _matchFinderCycles(0), _distTableSize(kDefaultDictionaryLogSize * 2), _posStateBits(2), _posStateMask(4 - 1), @@ -229,12 +228,13 @@ CEncoder::CEncoder(): _dictionarySize(1 << kDefaultDictionaryLogSize), _dictionarySizePrev(UInt32(-1)), _numFastBytesPrev(UInt32(-1)), + _matchFinderCycles(0), _matchFinderIndex(kBT4), - setMfPasses(0), #ifdef COMPRESS_MF_MT _multiThread(false), #endif - _writeEndMark(false) + _writeEndMark(false), + setMfPasses(0) { // _maxMode = false; _fastMode = false; @@ -320,7 +320,7 @@ HRESULT CEncoder::Create() static bool AreStringsEqual(const wchar_t *base, const wchar_t *testString) { - while (true) + for (;;) { wchar_t c = *testString; if (c >= 'a' && c <= 'z') @@ -486,7 +486,7 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) { const UInt32 kPropSize = 5; Byte properties[kPropSize]; - properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits; + properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits); for (int i = 0; i < 4; i++) properties[1 + i] = Byte(_dictionarySize >> (8 * i)); return WriteStream(outStream, properties, kPropSize, NULL); @@ -764,7 +764,7 @@ HRESULT CEncoder::GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes) UInt32 cur = 0; - while(true) + for (;;) { cur++; if(cur == lenEnd) @@ -1129,7 +1129,7 @@ HRESULT CEncoder::ReadMatchDistances(UInt32 &lenRes, UInt32 &numDistancePairs) return S_OK; } -HRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes) +HRESULT CEncoder::GetOptimumFast(UInt32 &backRes, UInt32 &lenRes) { UInt32 lenMain, numDistancePairs; if (!_longestMatchWasFound) @@ -1185,7 +1185,7 @@ HRESULT CEncoder::GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRe return MovePos(lenMain - 1); } - UInt32 backMain; + UInt32 backMain = 0; // for GCC if (lenMain >= 2) { backMain = matchDistances[numDistancePairs - 1]; @@ -1296,24 +1296,25 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, _needReleaseMFStream = false; CCoderReleaser coderReleaser(this); RINOK(SetStreams(inStream, outStream, inSize, outSize)); - while(true) + for (;;) { UInt64 processedInSize; UInt64 processedOutSize; Int32 finished; RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished)); if (finished != 0) - return S_OK; + break; if (progress != 0) { RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize)); } } + return S_OK; } HRESULT CEncoder::SetStreams(ISequentialInStream *inStream, ISequentialOutStream *outStream, - const UInt64 *inSize, const UInt64 *outSize) + const UInt64 * /* inSize */, const UInt64 * /* outSize */) { _inStream = inStream; _finished = false; @@ -1381,7 +1382,7 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished) if (_matchFinder->GetNumAvailableBytes() == 0) return Flush(nowPos32); - while(true) + for (;;) { #ifdef _NO_EXCEPTIONS if (_rangeEncoder.Stream.ErrorCode != S_OK) @@ -1390,7 +1391,7 @@ HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished) UInt32 pos, len; HRESULT result; if (_fastMode) - result = GetOptimumFast(nowPos32, pos, len); + result = GetOptimumFast(pos, len); else result = GetOptimum(nowPos32, pos, len); RINOK(result); diff --git a/7zip/Compress/LZMA/LZMAEncoder.h b/7zip/Compress/LZMA/LZMAEncoder.h index f4c2c151..26d2033d 100755 --- a/7zip/Compress/LZMA/LZMAEncoder.h +++ b/7zip/Compress/LZMA/LZMAEncoder.h @@ -326,7 +326,7 @@ class CEncoder : UInt32 Backward(UInt32 &backRes, UInt32 cur); HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes); - HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes); + HRESULT GetOptimumFast(UInt32 &backRes, UInt32 &lenRes); void FillDistancesPrices(); void FillAlignPrices(); diff --git a/7zip/Compress/LZMA_Alone/LzmaAlone.cpp b/7zip/Compress/LZMA_Alone/LzmaAlone.cpp index 39f679cf..16f80414 100755 --- a/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +++ b/7zip/Compress/LZMA_Alone/LzmaAlone.cpp @@ -10,7 +10,7 @@ #if defined(_WIN32) || defined(OS2) || defined(MSDOS) #include #include -#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY) +#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY) #else #define MY_SET_BINARY_MODE(file) #endif @@ -152,7 +152,7 @@ int main2(int n, const char *args[]) g_IsNT = IsItWindowsNT(); #endif - fprintf(stderr, "\nLZMA 4.40 Copyright (c) 1999-2006 Igor Pavlov 2006-05-01\n"); + fprintf(stderr, "\nLZMA 4.43 Copyright (c) 1999-2006 Igor Pavlov 2006-08-08\n"); if (n == 1) { @@ -160,7 +160,8 @@ int main2(int n, const char *args[]) return 0; } - if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4) + bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4); + if (unsupportedTypes) { fprintf(stderr, "Unsupported base types. Edit Common/Types.h and recompile"); return 1; @@ -368,7 +369,8 @@ int main2(int n, const char *args[]) if(parser[NKey::kFastBytes].ThereIs) if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes)) IncorrectCommand(); - if (matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs) + matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs; + if (matchFinderCyclesDefined) if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles)) IncorrectCommand(); if(parser[NKey::kLitContext].ThereIs) diff --git a/7zip/Compress/LZMA_Alone/LzmaBench.cpp b/7zip/Compress/LZMA_Alone/LzmaBench.cpp index 7b54b26c..f9924165 100755 --- a/7zip/Compress/LZMA_Alone/LzmaBench.cpp +++ b/7zip/Compress/LZMA_Alone/LzmaBench.cpp @@ -270,7 +270,7 @@ struct CProgressInfo: STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); }; -STDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) +STDMETHODIMP CProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 * /* outSize */) { if (*inSize >= ApprovedStart && InSize == 0) { @@ -459,7 +459,7 @@ int LzmaBenchmark(FILE *f, UInt32 numIterations, UInt32 dictionarySize) CCrcOutStream *crcOutStreamSpec = new CCrcOutStream; CMyComPtr crcOutStream = crcOutStreamSpec; - UInt64 decodeTime; + UInt64 decodeTime = 0; for (int j = 0; j < 2; j++) { inStreamSpec->Init(outStreamSpec->Buffer, compressedSize); diff --git a/7zip/Compress/LZMA_Alone/LzmaRam.cpp b/7zip/Compress/LZMA_Alone/LzmaRam.cpp index 090d73d8..eb66211a 100755 --- a/7zip/Compress/LZMA_Alone/LzmaRam.cpp +++ b/7zip/Compress/LZMA_Alone/LzmaRam.cpp @@ -31,9 +31,8 @@ public: STDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize) { - UInt32 remain = Size - Pos; - if (size > remain) - size = remain; + if (size > (Size - Pos)) + size = (UInt32)(Size - Pos); for (UInt32 i = 0; i < size; i++) ((Byte *)data)[i] = Data[Pos + i]; Pos += size; @@ -176,7 +175,7 @@ int LzmaRamEncode( x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 1); } - UInt32 minSize = 0; + size_t minSize = 0; int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1; bool bestIsFiltered = false; int mainResult = 0; diff --git a/7zip/Compress/LZMA_Alone/makefile b/7zip/Compress/LZMA_Alone/makefile index 63a63ae4..135c54b0 100755 --- a/7zip/Compress/LZMA_Alone/makefile +++ b/7zip/Compress/LZMA_Alone/makefile @@ -2,6 +2,11 @@ PROG = lzma.exe CFLAGS = $(CFLAGS) -I ../../../ LIBS = $(LIBS) oleaut32.lib user32.lib +!IFDEF CPU +LIBS = $(LIBS) bufferoverflowU.lib +CFLAGS = $(CFLAGS) -GS- -Zc:forScope -W4 -Wp64 -DUNICODE -D_UNICODE +!ENDIF + !IFNDEF O !IFDEF CPU O=$(CPU) @@ -10,7 +15,16 @@ O=O !ENDIF !ENDIF -CFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -GS- +!IFDEF MY_STATIC_LINK +!IFNDEF MY_SINGLE_THREAD +CFLAGS = $(CFLAGS) -MT +!ENDIF +!ELSE +CFLAGS = $(CFLAGS) -MD +!ENDIF + + +CFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -WX CFLAGS_O1 = $(CFLAGS) -O1 CFLAGS_O2 = $(CFLAGS) -O2 diff --git a/7zip/Compress/LZMA_C/LzmaTypes.h b/7zip/Compress/LZMA_C/LzmaTypes.h index 1bb43189..288c5e45 100755 --- a/7zip/Compress/LZMA_C/LzmaTypes.h +++ b/7zip/Compress/LZMA_C/LzmaTypes.h @@ -10,23 +10,36 @@ This file is part of LZMA SDK 4.40 (2006-05-01) #ifndef __LZMATYPES_H #define __LZMATYPES_H +#ifndef _7ZIP_BYTE_DEFINED +#define _7ZIP_BYTE_DEFINED typedef unsigned char Byte; +#endif + +#ifndef _7ZIP_UINT16_DEFINED +#define _7ZIP_UINT16_DEFINED typedef unsigned short UInt16; +#endif +#ifndef _7ZIP_UINT32_DEFINED +#define _7ZIP_UINT32_DEFINED #ifdef _LZMA_UINT32_IS_ULONG typedef unsigned long UInt32; #else typedef unsigned int UInt32; #endif +#endif /* #define _LZMA_SYSTEM_SIZE_T */ /* Use system's size_t. You can use it to enable 64-bit sizes supporting */ +#ifndef _7ZIP_SIZET_DEFINED +#define _7ZIP_SIZET_DEFINED #ifdef _LZMA_SYSTEM_SIZE_T #include typedef size_t SizeT; #else typedef UInt32 SizeT; #endif +#endif #endif diff --git a/7zip/Compress/Lzh/LzhDecoder.cpp b/7zip/Compress/Lzh/LzhDecoder.cpp index e3988a75..846a4163 100755 --- a/7zip/Compress/Lzh/LzhDecoder.cpp +++ b/7zip/Compress/Lzh/LzhDecoder.cpp @@ -126,7 +126,7 @@ HRESULT CCoder::ReadCTable() } } else - lens[i++] = c - 2; + lens[i++] = (Byte)(c - 2); } while (i < kNumCSymbols) lens[i++] = 0; @@ -136,7 +136,7 @@ HRESULT CCoder::ReadCTable() } STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { if (outSize == NULL) diff --git a/7zip/Compress/Lzx/LzxDecoder.cpp b/7zip/Compress/Lzx/LzxDecoder.cpp index a3bdf5b0..e854af32 100755 --- a/7zip/Compress/Lzx/LzxDecoder.cpp +++ b/7zip/Compress/Lzx/LzxDecoder.cpp @@ -95,7 +95,8 @@ bool CDecoder::ReadTables(void) return false; m_UnCompressedBlockSize = m_InBitStream.ReadBitsBig(kUncompressedBlockSizeNumBits); - if (m_IsUncompressedBlock = (blockType == kBlockTypeUncompressed)) + m_IsUncompressedBlock = (blockType == kBlockTypeUncompressed); + if (m_IsUncompressedBlock) { m_InBitStream.ReadBits(16 - m_InBitStream.GetBitPosition()); if (!m_InBitStream.ReadUInt32(m_RepDistances[0])) @@ -110,10 +111,11 @@ bool CDecoder::ReadTables(void) } return true; } - if (m_AlignIsUsed = (blockType == kBlockTypeAligned)) + m_AlignIsUsed = (blockType == kBlockTypeAligned); + if (m_AlignIsUsed) { for(int i = 0; i < kAlignTableSize; i++) - newLevels[i] = ReadBits(kNumBitsForAlignLevel); + newLevels[i] = (Byte)ReadBits(kNumBitsForAlignLevel); RIF(m_AlignDecoder.SetCodeLengths(newLevels)); } } @@ -195,7 +197,6 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize) if (m_UnCompressedBlockSize == 0) if (!ReadTables()) return S_FALSE; - UInt32 nowPos = 0; UInt32 next = (Int32)MyMin(m_UnCompressedBlockSize, curSize); curSize -= next; m_UnCompressedBlockSize -= next; @@ -300,7 +301,6 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, if (outSize == NULL) return E_INVALIDARG; UInt64 size = *outSize; - const UInt64 startSize = size; RINOK(SetInStream(inStream)); m_x86ConvertOutStreamSpec->SetStream(outStream); @@ -310,7 +310,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, CDecoderFlusher flusher(this); const UInt64 start = m_OutWindowStream.GetProcessedSize(); - while(true) + for (;;) { UInt32 curSize = 1 << 18; UInt64 rem = size - (m_OutWindowStream.GetProcessedSize() - start); diff --git a/7zip/Compress/PPMD/DllExports.cpp b/7zip/Compress/PPMD/DllExports.cpp index f8eb1310..c4a4fc61 100755 --- a/7zip/Compress/PPMD/DllExports.cpp +++ b/7zip/Compress/PPMD/DllExports.cpp @@ -20,7 +20,7 @@ DEFINE_GUID(CLSID_CCompressPPMDEncoder, 0x23170F69, 0x40C1, 0x278B, 0x03, 0x04, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD dwReason, LPVOID /*lpReserved*/) { #ifdef _WIN32 if (dwReason == DLL_PROCESS_ATTACH) diff --git a/7zip/Compress/PPMD/PPMDContext.h b/7zip/Compress/PPMD/PPMDContext.h index 6f154fc4..a6a8dd60 100755 --- a/7zip/Compress/PPMD/PPMDContext.h +++ b/7zip/Compress/PPMD/PPMDContext.h @@ -20,19 +20,19 @@ struct SEE2_CONTEXT // SEE-contexts for PPM-contexts with masked symbols UInt16 Summ; Byte Shift, Count; - void init(int InitVal) { Summ=InitVal << (Shift=PERIOD_BITS-4); Count=4; } + void init(int InitVal) { Summ = (UInt16)(InitVal << (Shift=PERIOD_BITS-4)); Count=4; } unsigned int getMean() { unsigned int RetVal=(Summ >> Shift); - Summ -= RetVal; + Summ = (UInt16)(Summ - RetVal); return RetVal+(RetVal == 0); } void update() { if (Shift < PERIOD_BITS && --Count == 0) { - Summ += Summ; - Count = 3 << Shift++; + Summ <<= 1; + Count = (Byte)(3 << Shift++); } } }; @@ -115,20 +115,21 @@ struct CInfo MinContext = MaxContext = (PPM_CONTEXT*) SubAllocator.AllocContext(); MinContext->Suffix = 0; OrderFall = MaxOrder; - MinContext->SummFreq = (MinContext->NumStats = 256) + 1; + MinContext->SummFreq = (UInt16)((MinContext->NumStats = 256) + 1); FoundState = (PPM_CONTEXT::STATE*)SubAllocator.AllocUnits(256 / 2); MinContext->Stats = SubAllocator.GetOffsetNoCheck(FoundState); - for (RunLength = InitRL, PrevSuccess = i = 0; i < 256; i++) + PrevSuccess = 0; + for (RunLength = InitRL, i = 0; i < 256; i++) { PPM_CONTEXT::STATE &state = FoundState[i]; - state.Symbol = i; + state.Symbol = (Byte)i; state.Freq = 1; state.SetSuccessor(0); } for (i = 0; i < 128; i++) for (k = 0; k < 8; k++) for ( m=0; m < 64; m += 8) - BinSumm[i][k + m] = BIN_SCALE - InitBinEsc[k] / (i + 2); + BinSumm[i][k + m] = (UInt16)(BIN_SCALE - InitBinEsc[k] / (i + 2)); for (i = 0; i < 25; i++) for (k = 0; k < 16; k++) SEE2Cont[i][k].init(5*i+10); @@ -160,10 +161,10 @@ struct CInfo memset(NS2BSIndx + 2, 2 * 2, 9); memset(NS2BSIndx + 11, 2 * 3, 256 - 11); for (i = 0; i < 3; i++) - NS2Indx[i] = i; + NS2Indx[i] = (Byte)i; for (m = i, k = Step = 1; i < 256; i++) { - NS2Indx[i] =m; + NS2Indx[i] = (Byte)m; if ( !--k ) { k = ++Step; @@ -227,8 +228,8 @@ NO_LOOP: do { p++; } while (p->Symbol != UpState.Symbol); unsigned int cf = p->Freq-1; unsigned int s0 = pc->SummFreq - pc->NumStats - cf; - UpState.Freq = 1 + ((2 * cf <= s0) ? (5 * cf > s0) : - ((2 * cf + 3 * s0 - 1) / (2 * s0))); + UpState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : + ((2 * cf + 3 * s0 - 1) / (2 * s0)))); } else UpState.Freq = pc->oneState().Freq; @@ -271,7 +272,7 @@ NO_LOOP: else { p = &(pc->oneState()); - p->Freq += (p->Freq < 32); + p->Freq = (Byte)(p->Freq + ((p->Freq < 32) ? 1 : 0)); } } if ( !OrderFall ) @@ -318,8 +319,8 @@ NO_LOOP: if (!ppp) goto RESTART_MODEL; } - pc->SummFreq += (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & - (pc->SummFreq <= 8 * ns1)); + pc->SummFreq = (UInt16)(pc->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & + (pc->SummFreq <= 8 * ns1))); } else { @@ -329,10 +330,10 @@ NO_LOOP: *p = pc->oneState(); pc->Stats = SubAllocator.GetOffsetNoCheck(p); if (p->Freq < MAX_FREQ / 4 - 1) - p->Freq += p->Freq; + p->Freq <<= 1; else p->Freq = MAX_FREQ - 4; - pc->SummFreq = p->Freq + InitEsc + (ns > 3); + pc->SummFreq = (UInt16)(p->Freq + InitEsc + (ns > 3)); } cf = 2 * fs.Freq * (pc->SummFreq+6); sf = s0 + pc->SummFreq; @@ -344,13 +345,13 @@ NO_LOOP: else { cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf); - pc->SummFreq += cf; + pc->SummFreq = (UInt16)(pc->SummFreq + cf); } p = GetState(pc->Stats) + ns1; p->SetSuccessor(SubAllocator.GetOffset(Successor)); p->Symbol = fs.Symbol; - p->Freq = cf; - pc->NumStats = ++ns1; + p->Freq = (Byte)cf; + pc->NumStats = (UInt16)++ns1; } MaxContext = MinContext = GetContext(fs.GetSuccessor()); return; @@ -425,11 +426,13 @@ RESTART_MODEL: MinContext->SummFreq += 4; EscFreq = MinContext->SummFreq - p->Freq; Adder = (OrderFall != 0); - MinContext->SummFreq = (p->Freq = (p->Freq + Adder) >> 1); + p->Freq = (Byte)((p->Freq + Adder) >> 1); + MinContext->SummFreq = p->Freq; do { EscFreq -= (++p)->Freq; - MinContext->SummFreq += (p->Freq = (p->Freq + Adder) >> 1); + p->Freq = (Byte)((p->Freq + Adder) >> 1); + MinContext->SummFreq = (UInt16)(MinContext->SummFreq + p->Freq); if (p[0].Freq > p[-1].Freq) { PPM_CONTEXT::STATE tmp = *(p1 = p); @@ -446,15 +449,17 @@ RESTART_MODEL: { do { i++; } while ((--p)->Freq == 0); EscFreq += i; - if ((MinContext->NumStats -= i) == 1) + MinContext->NumStats = (UInt16)(MinContext->NumStats - i); + if (MinContext->NumStats == 1) { PPM_CONTEXT::STATE tmp = *stats; - do { tmp.Freq -= (tmp.Freq >> 1); EscFreq >>= 1; } while (EscFreq > 1); + do { tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1)); EscFreq >>= 1; } while (EscFreq > 1); SubAllocator.FreeUnits(stats, (OldNS+1) >> 1); *(FoundState = &MinContext->oneState()) = tmp; return; } } - MinContext->SummFreq += (EscFreq -= (EscFreq >> 1)); + EscFreq -= (EscFreq >> 1); + MinContext->SummFreq = (UInt16)(MinContext->SummFreq + EscFreq); int n0 = (OldNS+1) >> 1, n1 = (MinContext->NumStats + 1) >> 1; if (n0 != n1) MinContext->Stats = SubAllocator.GetOffset(SubAllocator.ShrinkUnits(stats, n0, n1)); diff --git a/7zip/Compress/PPMD/PPMDDecode.h b/7zip/Compress/PPMD/PPMDDecode.h index 56afbe66..5eddcdf4 100755 --- a/7zip/Compress/PPMD/PPMDDecode.h +++ b/7zip/Compress/PPMD/PPMDDecode.h @@ -18,14 +18,14 @@ struct CDecodeInfo: public CInfo if (rangeDecoder->DecodeBit(bs, TOT_BITS) == 0) { FoundState = &rs; - rs.Freq += (rs.Freq < 128); - bs += UInt16(INTERVAL-GET_MEAN(bs,PERIOD_BITS,2)); + rs.Freq = (Byte)(rs.Freq + (rs.Freq < 128 ? 1: 0)); + bs = (UInt16)(bs + INTERVAL - GET_MEAN(bs, PERIOD_BITS, 2)); PrevSuccess = 1; RunLength++; } else { - bs -= UInt16(GET_MEAN(bs,PERIOD_BITS,2)); + bs = (UInt16)(bs - GET_MEAN(bs, PERIOD_BITS, 2)); InitEsc = ExpEscape[bs >> 10]; NumMasked = 1; CharMask[rs.Symbol] = EscCount; @@ -43,7 +43,7 @@ struct CDecodeInfo: public CInfo PrevSuccess = (2 * hiCnt > MinContext->SummFreq); RunLength += PrevSuccess; rangeDecoder->Decode(0, p->Freq); // MinContext->SummFreq); - (FoundState = p)->Freq=(hiCnt += 4); + (FoundState = p)->Freq = (Byte)(hiCnt += 4); MinContext->SummFreq += 4; if (hiCnt > MAX_FREQ) rescale(); @@ -103,7 +103,7 @@ struct CDecodeInfo: public CInfo i = MinContext->NumStats - NumMasked; pps--; do { CharMask[(*++pps)->Symbol] = EscCount; } while ( --i ); - psee2c->Summ += freqSum; + psee2c->Summ = (UInt16)(psee2c->Summ + freqSum); NumMasked = MinContext->NumStats; } } diff --git a/7zip/Compress/PPMD/PPMDDecoder.cpp b/7zip/Compress/PPMD/PPMDDecoder.cpp index 492fbede..f5f9b06c 100755 --- a/7zip/Compress/PPMD/PPMDDecoder.cpp +++ b/7zip/Compress/PPMD/PPMDDecoder.cpp @@ -75,7 +75,7 @@ HRESULT CDecoder::CodeSpec(UInt32 size, Byte *memStream) break; } if (memStream != 0) - *memStream++ = symbol; + *memStream++ = (Byte)symbol; else _outStream.WriteByte((Byte)symbol); size--; @@ -85,7 +85,7 @@ HRESULT CDecoder::CodeSpec(UInt32 size, Byte *memStream) } STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { if (!_outStream.Create(1 << 20)) @@ -96,7 +96,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, SetOutStreamSize(outSize); CDecoderFlusher flusher(this); - while(true) + for (;;) { _processedSize = _outStream.GetProcessedSize(); UInt32 curSize = (1 << 18); @@ -155,7 +155,8 @@ STDMETHODIMP CDecoder::ReleaseInStream() STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize) { - if (_outSizeDefined = (outSize != NULL)) + _outSizeDefined = (outSize != NULL); + if (_outSizeDefined) _outSize = *outSize; _remainLen = kLenIdNeedInit; _outStream.Init(); diff --git a/7zip/Compress/PPMD/PPMDEncode.h b/7zip/Compress/PPMD/PPMDEncode.h index 860310a2..6a720cac 100755 --- a/7zip/Compress/PPMD/PPMDEncode.h +++ b/7zip/Compress/PPMD/PPMDEncode.h @@ -19,16 +19,16 @@ struct CEncodeInfo: public CInfo if (rs.Symbol == symbol) { FoundState = &rs; - rs.Freq += (rs.Freq < 128); + rs.Freq = (Byte)(rs.Freq + (rs.Freq < 128 ? 1: 0)); rangeEncoder->EncodeBit(bs, TOT_BITS, 0); - bs += UInt16(INTERVAL-GET_MEAN(bs,PERIOD_BITS, 2)); + bs = (UInt16)(bs + INTERVAL - GET_MEAN(bs, PERIOD_BITS, 2)); PrevSuccess = 1; RunLength++; } else { rangeEncoder->EncodeBit(bs, TOT_BITS, 1); - bs -= UInt16(GET_MEAN(bs,PERIOD_BITS, 2)); + bs = (UInt16)(bs - GET_MEAN(bs, PERIOD_BITS, 2)); InitEsc = ExpEscape[bs >> 10]; NumMasked = 1; CharMask[rs.Symbol] = EscCount; @@ -91,7 +91,7 @@ struct CEncodeInfo: public CInfo rangeEncoder->Encode(hiCnt, scale, hiCnt + scale); scale += hiCnt; - psee2c->Summ += scale; + psee2c->Summ = (UInt16)(psee2c->Summ + scale); NumMasked = MinContext->NumStats; return; SYMBOL_FOUND: diff --git a/7zip/Compress/PPMD/PPMDEncoder.cpp b/7zip/Compress/PPMD/PPMDEncoder.cpp index b661f018..fe99ea5a 100755 --- a/7zip/Compress/PPMD/PPMDEncoder.cpp +++ b/7zip/Compress/PPMD/PPMDEncoder.cpp @@ -96,7 +96,7 @@ CEncoder::CEncoder(): HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, - const UInt64 *inSize, const UInt64 *outSize, + const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress) { if (!_inStream.Create(1 << 20)) @@ -117,7 +117,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, _info.MaxOrder = 0; _info.StartModelRare(_order); - while(true) + for (;;) { UInt32 size = (1 << 18); do diff --git a/7zip/Compress/PPMD/PPMDSubAlloc.h b/7zip/Compress/PPMD/PPMDSubAlloc.h index fd64d577..9b13f933 100755 --- a/7zip/Compress/PPMD/PPMDSubAlloc.h +++ b/7zip/Compress/PPMD/PPMDSubAlloc.h @@ -25,7 +25,7 @@ struct MEM_BLK Prev = p; MEM_BLK *pp = (MEM_BLK *)(Base + p); Next = pp->Next; - pp->Next = ((MEM_BLK *)(Base + Next))->Prev = (Byte *)this - Base; + pp->Next = ((MEM_BLK *)(Base + Next))->Prev = (UInt32)((Byte *)this - Base); } void Remove(Byte *Base) { @@ -140,14 +140,15 @@ public: HiUnit = (pText = HeapStart) + SubAllocatorSize; UINT Diff = UNIT_SIZE * (SubAllocatorSize / 8 / UNIT_SIZE * 7); LoUnit = UnitsStart = HiUnit - Diff; - for (i = 0, k=1; i < N1 ; i++, k += 1) Indx2Units[i]=k; - for (k++; i < N1 + N2 ;i++, k += 2) Indx2Units[i]=k; - for (k++; i < N1 + N2 + N3 ;i++,k += 3) Indx2Units[i]=k; - for (k++; i < N1 + N2 + N3 + N4; i++, k += 4) Indx2Units[i]=k; - for (GlueCount = k = i = 0; k < 128; k++) + for (i = 0, k=1; i < N1 ; i++, k += 1) Indx2Units[i] = (Byte)k; + for (k++; i < N1 + N2 ;i++, k += 2) Indx2Units[i] = (Byte)k; + for (k++; i < N1 + N2 + N3 ;i++,k += 3) Indx2Units[i] = (Byte)k; + for (k++; i < N1 + N2 + N3 + N4; i++, k += 4) Indx2Units[i] = (Byte)k; + GlueCount = 0; + for (k = i = 0; k < 128; k++) { i += (Indx2Units[i] < k+1); - Units2Indx[k]=i; + Units2Indx[k] = (Byte)i; } } @@ -176,14 +177,14 @@ public: } for (p = ps0->Next; p != s0; p = GetBlk(p)->Next) { - while (true) + for (;;) { MEM_BLK *pp = GetBlk(p); MEM_BLK *pp1 = GetBlk(p + pp->NU * UNIT_SIZE); if (pp1->Stamp != 0xFFFF || int(pp->NU) + pp1->NU >= 0x10000) break; pp1->Remove(Base); - pp->NU += pp1->NU; + pp->NU = (UInt16)(pp->NU + pp1->NU); } } while ((p = ps0->Next) != s0) diff --git a/7zip/Compress/Quantum/QuantumDecoder.cpp b/7zip/Compress/Quantum/QuantumDecoder.cpp index 8dcd736a..5cf863bb 100755 --- a/7zip/Compress/Quantum/QuantumDecoder.cpp +++ b/7zip/Compress/Quantum/QuantumDecoder.cpp @@ -112,7 +112,6 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, if (outSize == NULL) return E_INVALIDARG; UInt64 size = *outSize; - const UInt64 startSize = size; SetInStream(inStream); _outWindowStream.SetStream(outStream); @@ -120,7 +119,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, CDecoderFlusher flusher(this); const UInt64 start = _outWindowStream.GetProcessedSize(); - while(true) + for (;;) { UInt32 curSize = 1 << 18; UInt64 rem = size - (_outWindowStream.GetProcessedSize() - start); diff --git a/7zip/Compress/Quantum/QuantumDecoder.h b/7zip/Compress/Quantum/QuantumDecoder.h index 2574368f..8b5aaaba 100755 --- a/7zip/Compress/Quantum/QuantumDecoder.h +++ b/7zip/Compress/Quantum/QuantumDecoder.h @@ -109,7 +109,7 @@ public: UInt32 offset = start * Range / total; Code -= offset; Low += offset; - while (true) + for (;;) { if ((Low & 0x8000) != (high & 0x8000)) { @@ -167,7 +167,7 @@ public: { ReorderCount = kReorderCount; for(i = 0; i < NumItems; i++) - Freqs[i] = ((Freqs[i] - Freqs[i + 1]) + 1) >> 1; + Freqs[i] = (UInt16)(((Freqs[i] - Freqs[i + 1]) + 1) >> 1); for(i = 0; i < NumItems - 1; i++) for(unsigned int j = i + 1; j < NumItems; j++) if (Freqs[i] < Freqs[j]) @@ -180,7 +180,7 @@ public: Values[j] = tmpVal; } do - Freqs[i] += Freqs[i + 1]; + Freqs[i] = (UInt16)(Freqs[i] + Freqs[i + 1]); while(i-- != 0); } else @@ -190,7 +190,7 @@ public: { Freqs[i] >>= 1; if (Freqs[i] <= Freqs[i + 1]) - Freqs[i] = Freqs[i + 1] + 1; + Freqs[i] = (UInt16)(Freqs[i + 1] + 1); } while(i-- != 0); } diff --git a/7zip/Compress/Rar20/Rar20Decoder.cpp b/7zip/Compress/Rar20/Rar20Decoder.cpp index fd013a43..f990811f 100755 --- a/7zip/Compress/Rar20/Rar20Decoder.cpp +++ b/7zip/Compress/Rar20/Rar20Decoder.cpp @@ -208,7 +208,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, if (symbol >= kMMTableSize) return S_FALSE; Byte byPredict = m_Predictor.Predict(); - Byte byReal = byPredict - Byte(symbol); + Byte byReal = (Byte)(byPredict - (Byte)symbol); m_Predictor.Update(byReal, byPredict); m_OutWindowStream.PutByte(byReal); if (++m_Predictor.CurrentChannel == m_NumChannels) diff --git a/7zip/Compress/Rar29/DllExports.cpp b/7zip/Compress/Rar29/DllExports.cpp index ed5197f8..d0053055 100755 --- a/7zip/Compress/Rar29/DllExports.cpp +++ b/7zip/Compress/Rar29/DllExports.cpp @@ -21,9 +21,9 @@ DEFINE_GUID(CLSID_CCompressRar29Decoder, 0x23170F69, 0x40C1, 0x278B, 0x04, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00); extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/) { - return TRUE; + return TRUE; } STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject) diff --git a/7zip/Compress/Rar29/makefile b/7zip/Compress/Rar29/makefile index 12fc22b1..0a0f45f8 100755 --- a/7zip/Compress/Rar29/makefile +++ b/7zip/Compress/Rar29/makefile @@ -46,10 +46,10 @@ OBJS = \ !include "../../../Build.mak" -COMPL_SPEC = $(CPP) $(CFLAGS_O2) $** +COMPL_SPEC = $(CPP) $(CFLAGS_O2_W3) -w $** $(RAR29_OBJS): $(*B).cpp - $(COMPL) + $(COMPL_SPEC) $(RAR29_OPT_OBJS): Original/$(*B).cpp $(COMPL_SPEC) $(RAR20_OPT_OBJS): ../Rar20/$(*B).cpp diff --git a/7zip/Compress/Shrink/ShrinkDecoder.cpp b/7zip/Compress/Shrink/ShrinkDecoder.cpp index 47628164..12d1b8d0 100755 --- a/7zip/Compress/Shrink/ShrinkDecoder.cpp +++ b/7zip/Compress/Shrink/ShrinkDecoder.cpp @@ -17,7 +17,7 @@ static const UInt32 kBufferSize = (1 << 20); static const int kNumMinBits = 9; STDMETHODIMP CDecoder ::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress) { NStream::NLSBF::CBaseDecoder inBuffer; @@ -49,7 +49,7 @@ STDMETHODIMP CDecoder ::CodeReal(ISequentialInStream *inStream, _isFree[i] = true; UInt32 lastSymbol = 0; - while (true) + for (;;) { outBuffer.Flush(); UInt32 symbol = inBuffer.ReadBits(numBits); diff --git a/7zip/Compress/Z/ZDecoder.cpp b/7zip/Compress/Z/ZDecoder.cpp index b896bf08..f63fbbf6 100755 --- a/7zip/Compress/Z/ZDecoder.cpp +++ b/7zip/Compress/Z/ZDecoder.cpp @@ -47,7 +47,7 @@ CDecoder::~CDecoder() } STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress) { NStream::NLSBF::CBaseDecoder inBuffer; @@ -89,7 +89,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, _parents[256] = 0; // virus protection _suffixes[256] = 0; - while (true) + for (;;) { if (keepBits < numBits) keepBits = numBits * 8; diff --git a/7zip/Crypto/7zAES/7zAES.cpp b/7zip/Crypto/7zAES/7zAES.cpp index a0d0882b..843d9027 100755 --- a/7zip/Crypto/7zAES/7zAES.cpp +++ b/7zip/Crypto/7zAES/7zAES.cpp @@ -14,7 +14,7 @@ #include "../AES/MyAES.h" #endif -#include "SHA256.h" +#include "../Hash/Sha256.h" using namespace NWindows; @@ -49,7 +49,7 @@ void CKeyInfo::CalculateDigest() } else { - NCrypto::NSHA256::SHA256 sha; + NCrypto::NSha256::CContext sha; const UInt64 numRounds = UInt64(1) << (NumCyclesPower); Byte temp[8] = { 0,0,0,0,0,0,0,0 }; for (UInt64 round = 0; round < numRounds; round++) @@ -158,15 +158,15 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) // _key.NumCyclesPower = 0x3F; _key.NumCyclesPower = 18; - Byte firstByte = _key.NumCyclesPower | + Byte firstByte = (Byte)(_key.NumCyclesPower | (((_key.SaltSize == 0) ? 0 : 1) << 7) | - (((ivSize == 0) ? 0 : 1) << 6); + (((ivSize == 0) ? 0 : 1) << 6)); RINOK(outStream->Write(&firstByte, 1, NULL)); if (_key.SaltSize == 0 && ivSize == 0) return S_OK; - Byte saltSizeSpec = (_key.SaltSize == 0) ? 0 : (_key.SaltSize - 1); - Byte ivSizeSpec = (ivSize == 0) ? 0 : (ivSize - 1); - Byte secondByte = ((saltSizeSpec) << 4) | ivSizeSpec; + Byte saltSizeSpec = (Byte)((_key.SaltSize == 0) ? 0 : (_key.SaltSize - 1)); + Byte ivSizeSpec = (Byte)((ivSize == 0) ? 0 : (ivSize - 1)); + Byte secondByte = (Byte)(((saltSizeSpec) << 4) | ivSizeSpec); RINOK(outStream->Write(&secondByte, 1, NULL)); if (_key.SaltSize > 0) { @@ -285,20 +285,20 @@ HRESULT CBaseCoder::CreateFilterFromDLL(REFCLSID clsID) HRESULT CEncoder::CreateFilter() { #ifdef CRYPTO_AES - _aesFilter = new CAES256_CBC_Encoder; + _aesFilter = new CAES_CBC_Encoder; return S_OK; #else - return CreateFilterFromDLL(CLSID_CCrypto_AES256_Encoder); + return CreateFilterFromDLL(CLSID_CCrypto_AES_CBC_Encoder); #endif } HRESULT CDecoder::CreateFilter() { #ifdef CRYPTO_AES - _aesFilter = new CAES256_CBC_Decoder; + _aesFilter = new CAES_CBC_Decoder; return S_OK; #else - return CreateFilterFromDLL(CLSID_CCrypto_AES256_Decoder); + return CreateFilterFromDLL(CLSID_CCrypto_AES_CBC_Decoder); #endif } diff --git a/7zip/Crypto/7zAES/7zAES.dsp b/7zip/Crypto/7zAES/7zAES.dsp index 1c177670..37cd7792 100755 --- a/7zip/Crypto/7zAES/7zAES.dsp +++ b/7zip/Crypto/7zAES/7zAES.dsp @@ -197,9 +197,16 @@ SOURCE=..\..\..\Windows\Synchronization.h SOURCE=..\..\Archive\Common\CoderLoader.h # End Source File # End Group +# Begin Group "Hash" + +# PROP Default_Filter "" # Begin Source File -SOURCE=.\7zAES.cpp +SOURCE=..\Hash\RotateDefs.h +# End Source File +# Begin Source File + +SOURCE=..\Hash\Sha256.cpp !IF "$(CFG)" == "7zAES - Win32 Release" @@ -213,11 +220,12 @@ SOURCE=.\7zAES.cpp # End Source File # Begin Source File -SOURCE=.\7zAES.h +SOURCE=..\Hash\Sha256.h # End Source File +# End Group # Begin Source File -SOURCE=.\SHA256.cpp +SOURCE=.\7zAES.cpp !IF "$(CFG)" == "7zAES - Win32 Release" @@ -231,7 +239,7 @@ SOURCE=.\SHA256.cpp # End Source File # Begin Source File -SOURCE=.\SHA256.h +SOURCE=.\7zAES.h # End Source File # End Target # End Project diff --git a/7zip/Crypto/7zAES/7zAES.h b/7zip/Crypto/7zAES/7zAES.h index e455b6c8..f312f7e6 100755 --- a/7zip/Crypto/7zAES/7zAES.h +++ b/7zip/Crypto/7zAES/7zAES.h @@ -15,13 +15,11 @@ #include "../../Archive/Common/CoderLoader.h" #endif -// {23170F69-40C1-278B-0601-810000000100} -DEFINE_GUID(CLSID_CCrypto_AES256_Encoder, -0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0x81, 0x00, 0x00, 0x00, 0x01, 0x00); +DEFINE_GUID(CLSID_CCrypto_AES_CBC_Encoder, +0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0xC1, 0x00, 0x00, 0x00, 0x01, 0x00); -// {23170F69-40C1-278B-0601-810000000000} -DEFINE_GUID(CLSID_CCrypto_AES256_Decoder, -0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00); +DEFINE_GUID(CLSID_CCrypto_AES_CBC_Decoder, +0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00); namespace NCrypto { namespace NSevenZ { diff --git a/7zip/Crypto/7zAES/DllExports.cpp b/7zip/Crypto/7zAES/DllExports.cpp index 3de7078e..8766ded4 100755 --- a/7zip/Crypto/7zAES/DllExports.cpp +++ b/7zip/Crypto/7zAES/DllExports.cpp @@ -86,7 +86,7 @@ STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value) { case NMethodPropID::kID: { - const char id[] = { 0x06, (char)0xF1, 0x07, 0x01 }; + const char id[] = { 0x06, (char)(unsigned char)0xF1, 0x07, 0x01 }; if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0) value->vt = VT_BSTR; return S_OK; diff --git a/7zip/Crypto/7zAES/SHA256.cpp b/7zip/Crypto/7zAES/SHA256.cpp deleted file mode 100755 index cd80110f..00000000 --- a/7zip/Crypto/7zAES/SHA256.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// Crypto/SHA256.cpp -// This code is based on code from Wei Dai's Crypto++ library. - -#include "StdAfx.h" - -#include "SHA256.h" -#include "Windows/Defs.h" - -const int kBufferSize = 1 << 17; - -namespace NCrypto { -namespace NSHA256 { - - -template static inline T rotrFixed(T x, unsigned int y) -{ - // assert(y < sizeof(T)*8); - return (x>>y) | (x<<(sizeof(T)*8-y)); -} - -#define blk0(i) (W[i] = data[i]) - - -void SHA256::Init() -{ - m_digest[0] = 0x6a09e667; - m_digest[1] = 0xbb67ae85; - m_digest[2] = 0x3c6ef372; - m_digest[3] = 0xa54ff53a; - m_digest[4] = 0x510e527f; - m_digest[5] = 0x9b05688c; - m_digest[6] = 0x1f83d9ab; - m_digest[7] = 0x5be0cd19; - - m_count = 0; -} - -#define blk2(i) (W[i&15]+=s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15])) - -#define Ch(x,y,z) (z^(x&(y^z))) -#define Maj(x,y,z) ((x&y)|(z&(x|y))) - -#define a(i) T[(0-i)&7] -#define b(i) T[(1-i)&7] -#define c(i) T[(2-i)&7] -#define d(i) T[(3-i)&7] -#define e(i) T[(4-i)&7] -#define f(i) T[(5-i)&7] -#define g(i) T[(6-i)&7] -#define h(i) T[(7-i)&7] - -#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+K[i+j]+(j?blk2(i):blk0(i));\ - d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i)) - -// for SHA256 -#define S0(x) (rotrFixed(x,2)^rotrFixed(x,13)^rotrFixed(x,22)) -#define S1(x) (rotrFixed(x,6)^rotrFixed(x,11)^rotrFixed(x,25)) -#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3)) -#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10)) - -void SHA256::Transform(UInt32 *state, const UInt32 *data) -{ - UInt32 W[16]; - UInt32 T[8]; - /* Copy context->state[] to working vars */ - // memcpy(T, state, sizeof(T)); - for (int s = 0; s < 8; s++) - T[s] = state[s]; - - - /* 64 operations, partially loop unrolled */ - for (unsigned int j = 0; j < 64; j += 16) - { - for (unsigned int i = 0; i < 16; i++) - { - R(i); - } - /* - R( 0); R( 1); R( 2); R( 3); - R( 4); R( 5); R( 6); R( 7); - R( 8); R( 9); R(10); R(11); - R(12); R(13); R(14); R(15); - */ - } - /* Add the working vars back into context.state[] */ - /* - state[0] += a(0); - state[1] += b(0); - state[2] += c(0); - state[3] += d(0); - state[4] += e(0); - state[5] += f(0); - state[6] += g(0); - state[7] += h(0); - */ - for (int i = 0; i < 8; i++) - state[i] += T[i]; - - /* Wipe variables */ - // memset(W, 0, sizeof(W)); - // memset(T, 0, sizeof(T)); -} - -const UInt32 SHA256::K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -#undef S0 -#undef S1 -#undef s0 -#undef s1 - -void SHA256::WriteByteBlock() -{ - UInt32 data32[16]; - for (int i = 0; i < 16; i++) - { - data32[i] = (UInt32(_buffer[i * 4]) << 24) + - (UInt32(_buffer[i * 4 + 1]) << 16) + - (UInt32(_buffer[i * 4 + 2]) << 8) + - UInt32(_buffer[i * 4 + 3]); - } - Transform(m_digest, data32); -} - -void SHA256::Update(const Byte *data, size_t size) -{ - UInt32 curBufferPos = UInt32(m_count) & 0x3F; - while (size > 0) - { - while(curBufferPos < 64 && size > 0) - { - _buffer[curBufferPos++] = *data++; - m_count++; - size--; - } - if (curBufferPos == 64) - { - curBufferPos = 0; - WriteByteBlock(); - } - } -} - -void SHA256::Final(Byte *digest) -{ - UInt64 lenInBits = (m_count << 3); - UInt32 curBufferPos = UInt32(m_count) & 0x3F; - _buffer[curBufferPos++] = 0x80; - while (curBufferPos != (64 - 8)) - { - curBufferPos &= 0x3F; - if (curBufferPos == 0) - WriteByteBlock(); - _buffer[curBufferPos++] = 0; - } - for (int i = 0; i < 8; i++) - { - _buffer[curBufferPos++] = Byte(lenInBits >> 56); - lenInBits <<= 8; - } - WriteByteBlock(); - - for (int j = 0; j < 8; j++) - { - *digest++ = m_digest[j] >> 24; - *digest++ = m_digest[j] >> 16; - *digest++ = m_digest[j] >> 8; - *digest++ = m_digest[j]; - } - Init(); -} - -}} diff --git a/7zip/Crypto/7zAES/SHA256.h b/7zip/Crypto/7zAES/SHA256.h deleted file mode 100755 index 503b144e..00000000 --- a/7zip/Crypto/7zAES/SHA256.h +++ /dev/null @@ -1,30 +0,0 @@ -// Crypto/SHA256.h - -#ifndef __CRYPTO_SHA256_H -#define __CRYPTO_SHA256_H - -#include "Common/Types.h" - -namespace NCrypto { -namespace NSHA256 { - -class SHA256 -{ - static const UInt32 K[64]; - - UInt32 m_digest[8]; - UInt64 m_count; - Byte _buffer[64]; - static void Transform(UInt32 *digest, const UInt32 *data); - void WriteByteBlock(); -public: - enum {DIGESTSIZE = 32}; - SHA256() { Init(); } ; - void Init(); - void Update(const Byte *data, size_t size); - void Final(Byte *digest); -}; - -}} - -#endif diff --git a/7zip/Crypto/7zAES/makefile b/7zip/Crypto/7zAES/makefile index d8daaf69..c3d9a51d 100755 --- a/7zip/Crypto/7zAES/makefile +++ b/7zip/Crypto/7zAES/makefile @@ -8,7 +8,9 @@ LIBS = $(LIBS) oleaut32.lib user32.lib 7ZAES_OPT_OBJS = \ $O\7zAES.obj \ - $O\SHA256.obj \ + +CRYPTO_HASH_OBJS = \ + $O\Sha256.obj \ COMMON_OBJS = \ $O\Alloc.obj \ @@ -28,6 +30,7 @@ OBJS = \ $O\StdAfx.obj \ $(7ZAES_OBJS) \ $(7ZAES_OPT_OBJS) \ + $(CRYPTO_HASH_OBJS) \ $(COMMON_OBJS) \ $(WIN_OBJS) \ $(7ZIP_COMMON_OBJS) \ @@ -39,6 +42,8 @@ $(7ZAES_OBJS): $(*B).cpp $(COMPL) $(7ZAES_OPT_OBJS): $(*B).cpp $(COMPL) +$(CRYPTO_HASH_OBJS): ../../Crypto/Hash/$(*B).cpp + $(COMPL_O2) $(COMMON_OBJS): ../../../Common/$(*B).cpp $(COMPL) $(WIN_OBJS): ../../../Windows/$(*B).cpp diff --git a/7zip/Crypto/AES/DllExports.cpp b/7zip/Crypto/AES/DllExports.cpp index 29d5fac1..7c21ac5c 100755 --- a/7zip/Crypto/AES/DllExports.cpp +++ b/7zip/Crypto/AES/DllExports.cpp @@ -7,9 +7,9 @@ #include "MyAES.h" extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) +BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /* lpReserved */) { - return TRUE; + return TRUE; } #define MY_CreateClass(n) \ @@ -31,9 +31,9 @@ STDAPI CreateObject( int correctInterface = (*interfaceID == IID_ICompressFilter); CMyComPtr filter; - MY_CreateClass(AES128_CBC) + MY_CreateClass(AES_CBC) else - MY_CreateClass(AES256_CBC) + MY_CreateClass(AES_ECB) else return CLASS_E_CLASSNOTAVAILABLE; *outObject = filter.Detach(); @@ -57,8 +57,8 @@ struct CAESMethodItem static CAESMethodItem g_Methods[] = { - METHOD_ITEM(AES128_CBC, 0x01, L"AES128"), - METHOD_ITEM(AES256_CBC, char(0x81), L"AES256") + METHOD_ITEM(AES_ECB, (char)(unsigned char)0xC0, L"AES-ECB"), + METHOD_ITEM(AES_CBC, (char)(unsigned char)0xC1, L"AES") }; STDAPI GetNumberOfMethods(UINT32 *numMethods) diff --git a/7zip/Crypto/AES/MyAES.cpp b/7zip/Crypto/AES/MyAES.cpp index d52ab36b..359caa25 100755 --- a/7zip/Crypto/AES/MyAES.cpp +++ b/7zip/Crypto/AES/MyAES.cpp @@ -22,10 +22,7 @@ public: CTabInit() { gen_tabs();} } g_TabInit; -STDMETHODIMP CAESFilter::Init() -{ - return S_OK; -} +STDMETHODIMP CAESFilter::Init() { return S_OK; } STDMETHODIMP_(UInt32) CAESFilter::Filter(Byte *data, UInt32 size) { @@ -51,25 +48,47 @@ STDMETHODIMP CAESFilter::SetInitVector(const Byte *data, UInt32 size) } STDMETHODIMP CAESEncoder::SetKey(const Byte *data, UInt32 size) -{ - if (AES.enc_key(data, size) != aes_good) - return E_FAIL; - return S_OK; -} + { return (AES.enc_key(data, size) == aes_good) ? S_OK: E_FAIL; } void CAESEncoder::SubFilter(const Byte *inBlock, Byte *outBlock) -{ - AES.Encode(inBlock, outBlock); -} + { AES.Encode(inBlock, outBlock); } STDMETHODIMP CAESDecoder::SetKey(const Byte *data, UInt32 size) -{ - if (AES.dec_key(data, size) != aes_good) - return E_FAIL; - return S_OK; -} + { return (AES.dec_key(data, size) == aes_good) ? S_OK: E_FAIL; } void CAESDecoder::SubFilter(const Byte *inBlock, Byte *outBlock) + { AES.Decode(inBlock, outBlock); } + +//////////////////////////// +// ECB mode + +STDMETHODIMP CAesEcbFilter::Init() { return S_OK; } +STDMETHODIMP CAesEcbFilter::SetInitVector(const Byte * /* data */, UInt32 size) + { return (size == 0) ? S_OK: E_INVALIDARG; } + +STDMETHODIMP_(UInt32) CAesEcbFilter::Filter(Byte *data, UInt32 size) { - AES.Decode(inBlock, outBlock); + if (size > 0 && size < kAESBlockSize) + return kAESBlockSize; + UInt32 i; + for (i = 0; i + kAESBlockSize <= size; i += kAESBlockSize) + { + Byte outBlock[kAESBlockSize]; + SubFilter(data + i, outBlock); + for (int j = 0; j < kAESBlockSize; j++) + data[i + j] = outBlock[j]; + } + return i; } + +STDMETHODIMP CAesEcbEncoder::SetKey(const Byte *data, UInt32 size) + { return (AES.enc_key(data, size) == aes_good) ? S_OK: E_FAIL; } + +void CAesEcbEncoder::SubFilter(const Byte *inBlock, Byte *outBlock) + { AES.enc_blk(inBlock, outBlock); } + +STDMETHODIMP CAesEcbDecoder::SetKey(const Byte *data, UInt32 size) + { return (AES.dec_key(data, size) == aes_good) ? S_OK: E_FAIL; } + +void CAesEcbDecoder::SubFilter(const Byte *inBlock, Byte *outBlock) + { AES.dec_blk(inBlock, outBlock); } diff --git a/7zip/Crypto/AES/MyAES.h b/7zip/Crypto/AES/MyAES.h index 75747147..f58913ae 100755 --- a/7zip/Crypto/AES/MyAES.h +++ b/7zip/Crypto/AES/MyAES.h @@ -55,7 +55,52 @@ MyClassCrypto3E(Name ## _Encoder) \ MyClassCrypto2(Name ## _Decoder, id, 0x00) \ MyClassCrypto3D(Name ## _Decoder) \ -MyClassCrypto(AES128_CBC, 0x01) -MyClassCrypto(AES256_CBC, 0x81) +MyClassCrypto(AES_CBC, 0xC1) + +class CAesEcbFilter: + public ICompressFilter, + public ICryptoProperties, + public CMyUnknownImp +{ +protected: + AESclass AES; +public: + MY_UNKNOWN_IMP1(ICryptoProperties) + STDMETHOD(Init)(); + STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); + STDMETHOD(SetKey)(const Byte *data, UInt32 size) = 0; + STDMETHOD(SetInitVector)(const Byte *data, UInt32 size); + virtual void SubFilter(const Byte *inBlock, Byte *outBlock) = 0; +}; + +class CAesEcbEncoder: public CAesEcbFilter +{ +public: + STDMETHOD(SetKey)(const Byte *data, UInt32 size); + virtual void SubFilter(const Byte *inBlock, Byte *outBlock); +}; + +class CAesEcbDecoder: public CAesEcbFilter +{ +public: + STDMETHOD(SetKey)(const Byte *data, UInt32 size); + virtual void SubFilter(const Byte *inBlock, Byte *outBlock); +}; + +#define MyClassCrypto3E_Ecb(Name) class C ## Name: public CAesEcbEncoder { }; +#define MyClassCrypto3D_Ecb(Name) class C ## Name: public CAesEcbDecoder { }; + +// {23170F69-40C1-278B-0601-000000000000} +#define MyClassCrypto2_Ecb(Name, id, encodingId) \ +DEFINE_GUID(CLSID_CCrypto_ ## Name, \ +0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, id, 0x00, 0x00, 0x00, encodingId, 0x00); + +#define MyClassCrypto_Ecb(Name, id) \ +MyClassCrypto2_Ecb(Name ## _Encoder, id, 0x01) \ +MyClassCrypto3E_Ecb(Name ## _Encoder) \ +MyClassCrypto2_Ecb(Name ## _Decoder, id, 0x00) \ +MyClassCrypto3D_Ecb(Name ## _Decoder) \ + +MyClassCrypto_Ecb(AES_ECB, 0xC0) #endif diff --git a/7zip/Crypto/AES/makefile b/7zip/Crypto/AES/makefile index a6b61c41..28f99965 100755 --- a/7zip/Crypto/AES/makefile +++ b/7zip/Crypto/AES/makefile @@ -28,4 +28,4 @@ $(AES_OBJS): $(*B).cpp $(AES_OPT_OBJS): $(*B).cpp $(COMPL_O2) $(AES_ORIG_OBJS): $(*B).c - $(COMPL_O2) + $(COMPL_O2_W3) diff --git a/7zip/Crypto/Hash/HmacSha1.cpp b/7zip/Crypto/Hash/HmacSha1.cpp new file mode 100755 index 00000000..a5c20a75 --- /dev/null +++ b/7zip/Crypto/Hash/HmacSha1.cpp @@ -0,0 +1,109 @@ +// HmacSha1.cpp + +#include "StdAfx.h" + +#include "HmacSha1.h" + +namespace NCrypto { +namespace NSha1 { + +void CHmac::SetKey(const Byte *key, size_t keySize) +{ + Byte keyTemp[kBlockSize]; + size_t i; + for (i = 0; i < kBlockSize; i++) + keyTemp[i] = 0; + if(keySize > kBlockSize) + { + _sha.Init(); + _sha.Update(key, keySize); + _sha.Final(keyTemp); + keySize = kDigestSize; + } + else + for (i = 0; i < keySize; i++) + keyTemp[i] = key[i]; + for (i = 0; i < kBlockSize; i++) + keyTemp[i] ^= 0x36; + _sha.Init(); + _sha.Update(keyTemp, kBlockSize); + for (i = 0; i < kBlockSize; i++) + keyTemp[i] ^= 0x36 ^ 0x5C; + _sha2.Init(); + _sha2.Update(keyTemp, kBlockSize); +} + +void CHmac::Final(Byte *mac, size_t macSize) +{ + Byte digest[kDigestSize]; + _sha.Final(digest); + _sha2.Update(digest, kDigestSize); + _sha2.Final(digest); + for(size_t i = 0; i < macSize; i++) + mac[i] = digest[i]; +} + + +void CHmac32::SetKey(const Byte *key, size_t keySize) +{ + UInt32 keyTemp[kBlockSizeInWords]; + size_t i; + for (i = 0; i < kBlockSizeInWords; i++) + keyTemp[i] = 0; + if(keySize > kBlockSize) + { + CContext sha; + sha.Init(); + sha.Update(key, keySize); + Byte digest[kDigestSize]; + sha.Final(digest); + + for (int i = 0 ; i < kDigestSizeInWords; i++) + keyTemp[i] = + ((UInt32)(digest[i * 4 + 0]) << 24) | + ((UInt32)(digest[i * 4 + 1]) << 16) | + ((UInt32)(digest[i * 4 + 2]) << 8) | + ((UInt32)(digest[i * 4 + 3])); + keySize = kDigestSizeInWords; + } + else + for (size_t i = 0; i < keySize; i++) + keyTemp[i / 4] |= (key[i] << (24 - 8 * (i & 3))); + for (i = 0; i < kBlockSizeInWords; i++) + keyTemp[i] ^= 0x36363636; + _sha.Init(); + _sha.Update(keyTemp, kBlockSizeInWords); + for (i = 0; i < kBlockSizeInWords; i++) + keyTemp[i] ^= 0x36363636 ^ 0x5C5C5C5C; + _sha2.Init(); + _sha2.Update(keyTemp, kBlockSizeInWords); +} + +void CHmac32::Final(UInt32 *mac, size_t macSize) +{ + UInt32 digest[kDigestSizeInWords]; + _sha.Final(digest); + _sha2.Update(digest, kDigestSizeInWords); + _sha2.Final(digest); + for(size_t i = 0; i < macSize; i++) + mac[i] = digest[i]; +} + +void CHmac32::GetLoopXorDigest(UInt32 *mac, UInt32 numIteration) +{ + UInt32 block[kBlockSizeInWords]; + UInt32 block2[kBlockSizeInWords]; + _sha.PrepareBlock(block, kDigestSizeInWords); + _sha2.PrepareBlock(block2, kDigestSizeInWords); + for(unsigned int s = 0; s < kDigestSizeInWords; s++) + block[s] = mac[s]; + for(UInt32 i = 0; i < numIteration; i++) + { + _sha.GetBlockDigest(block, block2); + _sha2.GetBlockDigest(block2, block); + for (unsigned int s = 0; s < kDigestSizeInWords; s++) + mac[s] ^= block[s]; + } +} + +}} diff --git a/7zip/Crypto/Hash/HmacSha1.h b/7zip/Crypto/Hash/HmacSha1.h new file mode 100755 index 00000000..bca5bcf8 --- /dev/null +++ b/7zip/Crypto/Hash/HmacSha1.h @@ -0,0 +1,39 @@ +// HmacSha1.h +// Implements HMAC-SHA-1 (RFC2104, FIPS-198) + +#ifndef _HMAC_H +#define _HMAC_H + +#include "Sha1.h" + +namespace NCrypto { +namespace NSha1 { + +// Use: SetKey(key, keySize); for () Update(data, size); Final(mac, macSize); + +class CHmac +{ + CContext _sha; + CContext _sha2; +public: + void SetKey(const Byte *key, size_t keySize); + void Update(const Byte *data, size_t dataSize) { _sha.Update(data, dataSize); } + void Final(Byte *mac, size_t macSize = kDigestSize); +}; + +class CHmac32 +{ + CContext32 _sha; + CContext32 _sha2; +public: + void SetKey(const Byte *key, size_t keySize); + void Update(const UInt32 *data, size_t dataSize) { _sha.Update(data, dataSize); } + void Final(UInt32 *mac, size_t macSize = kDigestSizeInWords); + + // It'sa for hmac function. in,out: mac[kDigestSizeInWords]. + void GetLoopXorDigest(UInt32 *mac, UInt32 numIteration); +}; + +}} + +#endif diff --git a/7zip/Crypto/Hash/Pbkdf2HmacSha1.cpp b/7zip/Crypto/Hash/Pbkdf2HmacSha1.cpp new file mode 100755 index 00000000..b11881b7 --- /dev/null +++ b/7zip/Crypto/Hash/Pbkdf2HmacSha1.cpp @@ -0,0 +1,83 @@ +// Pbkdf2HmacSha1.cpp + +#include "StdAfx.h" + +#include "HmacSha1.h" + +namespace NCrypto { +namespace NSha1 { + +void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize, + UInt32 numIterations, Byte *key, size_t keySize) +{ + CHmac baseCtx; + baseCtx.SetKey(pwd, pwdSize); + for (UInt32 i = 1; keySize > 0; i++) + { + CHmac ctx = baseCtx; + ctx.Update(salt, saltSize); + Byte u[kDigestSize] = { (Byte)(i >> 24), (Byte)(i >> 16), (Byte)(i >> 8), (Byte)(i) }; + const unsigned int curSize = (keySize < kDigestSize) ? (unsigned int)keySize : kDigestSize; + ctx.Update(u, 4); + ctx.Final(u, kDigestSize); + + unsigned int s; + for (s = 0; s < curSize; s++) + key[s] = u[s]; + + for (UInt32 j = numIterations; j > 1; j--) + { + ctx = baseCtx; + ctx.Update(u, kDigestSize); + ctx.Final(u, kDigestSize); + for (s = 0; s < curSize; s++) + key[s] ^= u[s]; + } + + key += curSize; + keySize -= curSize; + } +} + +void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize, + UInt32 numIterations, UInt32 *key, size_t keySize) +{ + CHmac32 baseCtx; + baseCtx.SetKey(pwd, pwdSize); + for (UInt32 i = 1; keySize > 0; i++) + { + CHmac32 ctx = baseCtx; + ctx.Update(salt, saltSize); + UInt32 u[kDigestSizeInWords] = { i }; + const unsigned int curSize = (keySize < kDigestSizeInWords) ? (unsigned int)keySize : kDigestSizeInWords; + ctx.Update(u, 1); + ctx.Final(u, kDigestSizeInWords); + + // Speed-optimized code start + ctx = baseCtx; + ctx.GetLoopXorDigest(u, numIterations - 1); + // Speed-optimized code end + + unsigned int s; + for (s = 0; s < curSize; s++) + key[s] = u[s]; + + /* + // Default code start + for (UInt32 j = numIterations; j > 1; j--) + { + ctx = baseCtx; + ctx.Update(u, kDigestSizeInWords); + ctx.Final(u, kDigestSizeInWords); + for (s = 0; s < curSize; s++) + key[s] ^= u[s]; + } + // Default code end + */ + + key += curSize; + keySize -= curSize; + } +} + +}} diff --git a/7zip/Crypto/Hash/Pbkdf2HmacSha1.h b/7zip/Crypto/Hash/Pbkdf2HmacSha1.h new file mode 100755 index 00000000..00a5e009 --- /dev/null +++ b/7zip/Crypto/Hash/Pbkdf2HmacSha1.h @@ -0,0 +1,21 @@ +// Pbkdf2HmacSha1.h +// Password-Based Key Derivation Function (RFC 2898, PKCS #5) based on HMAC-SHA-1 + +#ifndef __PBKDF2HMACSHA1_H +#define __PBKDF2HMACSHA1_H + +#include +#include "../../../Common/Types.h" + +namespace NCrypto { +namespace NSha1 { + +void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize, + UInt32 numIterations, Byte *key, size_t keySize); + +void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize, + UInt32 numIterations, UInt32 *key, size_t keySize); + +}} + +#endif diff --git a/7zip/Crypto/Hash/RandGen.cpp b/7zip/Crypto/Hash/RandGen.cpp new file mode 100755 index 00000000..480e04ca --- /dev/null +++ b/7zip/Crypto/Hash/RandGen.cpp @@ -0,0 +1,78 @@ +// RandGen.cpp + +#include "StdAfx.h" + +#include + +#include "Windows/Synchronization.h" + +#include "RandGen.h" + +// This is not very good random number generator. +// Please use it only for salt. +// First genrated data block depends from timer. +// Other genrated data blocks depend from previous state +// Maybe it's possible to restore original timer vaue from generated value. + +void CRandomGenerator::Init() +{ + NCrypto::NSha1::CContext hash; + hash.Init(); + + #ifdef _WIN32 + DWORD w = ::GetCurrentProcessId(); + hash.Update((const Byte *)&w, sizeof(w)); + w = ::GetCurrentThreadId(); + hash.Update((const Byte *)&w, sizeof(w)); + #endif + + for (int i = 0; i < 1000; i++) + { + #ifdef _WIN32 + LARGE_INTEGER v; + if (::QueryPerformanceCounter(&v)) + hash.Update((const Byte *)&v.QuadPart, sizeof(v.QuadPart)); + #endif + + DWORD tickCount = ::GetTickCount(); + hash.Update((const Byte *)&tickCount, sizeof(tickCount)); + + for (int j = 0; j < 100; j++) + { + hash.Final(_buff); + hash.Init(); + hash.Update(_buff, NCrypto::NSha1::kDigestSize); + } + } + hash.Final(_buff); + _needInit = false; +} + +static NWindows::NSynchronization::CCriticalSection g_CriticalSection; + +void CRandomGenerator::Generate(Byte *data, unsigned int size) +{ + g_CriticalSection.Enter(); + if (_needInit) + Init(); + while (size > 0) + { + NCrypto::NSha1::CContext hash; + + hash.Init(); + hash.Update(_buff, NCrypto::NSha1::kDigestSize); + hash.Final(_buff); + + hash.Init(); + UInt32 salt = 0xF672ABD1; + hash.Update((const Byte *)&salt, sizeof(salt)); + hash.Update(_buff, NCrypto::NSha1::kDigestSize); + Byte buff[NCrypto::NSha1::kDigestSize]; + hash.Final(buff); + for (unsigned int i = 0; i < NCrypto::NSha1::kDigestSize && size > 0; i++, size--) + *data++ = buff[i]; + } + g_CriticalSection.Leave(); +} + +CRandomGenerator g_RandomGenerator; diff --git a/7zip/Crypto/Hash/RandGen.h b/7zip/Crypto/Hash/RandGen.h new file mode 100755 index 00000000..3b58a032 --- /dev/null +++ b/7zip/Crypto/Hash/RandGen.h @@ -0,0 +1,21 @@ +// RandGen.h + +#ifndef __RANDGEN_H +#define __RANDGEN_H + +#include "Sha1.h" + +class CRandomGenerator +{ + Byte _buff[NCrypto::NSha1::kDigestSize]; + bool _needInit; + + void Init(); +public: + CRandomGenerator(): _needInit(true) {}; + void Generate(Byte *data, unsigned int size); +}; + +extern CRandomGenerator g_RandomGenerator; + +#endif diff --git a/7zip/Crypto/Hash/RotateDefs.h b/7zip/Crypto/Hash/RotateDefs.h new file mode 100755 index 00000000..832e7357 --- /dev/null +++ b/7zip/Crypto/Hash/RotateDefs.h @@ -0,0 +1,19 @@ +// RotateDefs.h + +#ifndef __ROTATEDEFS_H +#define __ROTATEDEFS_H + +#ifdef _MSC_VER + +#include +#define rotlFixed(x, n) _rotl((x), (n)) +#define rotrFixed(x, n) _rotr((x), (n)) + +#else + +#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) +#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) + +#endif + +#endif diff --git a/7zip/Crypto/Hash/Sha1.cpp b/7zip/Crypto/Hash/Sha1.cpp new file mode 100755 index 00000000..0e1d2ecf --- /dev/null +++ b/7zip/Crypto/Hash/Sha1.cpp @@ -0,0 +1,210 @@ +// Sha1.cpp +// This file is based on public domain +// Steve Reid and Wei Dai's code from Crypto++ + +#include "StdAfx.h" + +#include "Sha1.h" +#include "RotateDefs.h" + +namespace NCrypto { +namespace NSha1 { + +// define it for speed optimization +// #define _SHA1_UNROLL + +static const unsigned int kNumW = + #ifdef _SHA1_UNROLL + 16; + #else + 80; + #endif + + +#define w0(i) (W[(i)] = data[(i)]) + +#ifdef _SHA1_UNROLL +#define w1(i) (W[(i)&15] = rotlFixed(W[((i)-3)&15] ^ W[((i)-8)&15] ^ W[((i)-14)&15] ^ W[((i)-16)&15], 1)) +#else +#define w1(i) (W[(i)] = rotlFixed(W[(i)-3] ^ W[(i)-8] ^ W[(i)-14] ^ W[(i)-16], 1)) +#endif + +#define f1(x,y,z) (z^(x&(y^z))) +#define f2(x,y,z) (x^y^z) +#define f3(x,y,z) ((x&y)|(z&(x|y))) +#define f4(x,y,z) (x^y^z) + +#define RK1(a,b,c,d,e,i, f, w, k) e += f(b,c,d) + w(i) + k + rotlFixed(a,5); b = rotlFixed(b,30); + +#define R0(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f1, w0, 0x5A827999) +#define R1(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f1, w1, 0x5A827999) +#define R2(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f2, w1, 0x6ED9EBA1) +#define R3(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f3, w1, 0x8F1BBCDC) +#define R4(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f4, w1, 0xCA62C1D6) + +#define RX_1_4(rx1, rx4, i) rx1(a,b,c,d,e,i); rx4(e,a,b,c,d,i+1); rx4(d,e,a,b,c,i+2); rx4(c,d,e,a,b,i+3); rx4(b,c,d,e,a,i+4); +#define RX_5(rx, i) RX_1_4(rx, rx, i); + +void CContextBase::Init() +{ + _state[0] = 0x67452301; + _state[1] = 0xEFCDAB89; + _state[2] = 0x98BADCFE; + _state[3] = 0x10325476; + _state[4] = 0xC3D2E1F0; + _count = 0; +} + +void CContextBase::GetBlockDigest(UInt32 *data, UInt32 *destDigest, bool returnRes) +{ + UInt32 a, b, c, d, e; + UInt32 W[kNumW]; + + a = _state[0]; + b = _state[1]; + c = _state[2]; + d = _state[3]; + e = _state[4]; + #ifdef _SHA1_UNROLL + RX_5(R0, 0); RX_5(R0, 5); RX_5(R0, 10); + #else + int i; + for (i = 0; i < 15; i += 5) { RX_5(R0, i); } + #endif + + RX_1_4(R0, R1, 15); + + + #ifdef _SHA1_UNROLL + RX_5(R2, 20); RX_5(R2, 25); RX_5(R2, 30); RX_5(R2, 35); + RX_5(R3, 40); RX_5(R3, 45); RX_5(R3, 50); RX_5(R3, 55); + RX_5(R4, 60); RX_5(R4, 65); RX_5(R4, 70); RX_5(R4, 75); + #else + i = 20; + for (; i < 40; i += 5) { RX_5(R2, i); } + for (; i < 60; i += 5) { RX_5(R3, i); } + for (; i < 80; i += 5) { RX_5(R4, i); } + #endif + + destDigest[0] = _state[0] + a; + destDigest[1] = _state[1] + b; + destDigest[2] = _state[2] + c; + destDigest[3] = _state[3] + d; + destDigest[4] = _state[4] + e; + + if (returnRes) + for (int i = 0 ; i < 16; i++) + data[i] = W[kNumW - 16 + i]; + + // Wipe variables + // a = b = c = d = e = 0; +} + +void CContextBase::PrepareBlock(UInt32 *block, unsigned int size) const +{ + unsigned int curBufferPos = size & 0xF; + block[curBufferPos++] = 0x80000000; + while (curBufferPos != (16 - 2)) + block[curBufferPos++] = 0; + const UInt64 lenInBits = (_count << 9) + ((UInt64)size << 5); + block[curBufferPos++] = (UInt32)(lenInBits >> 32); + block[curBufferPos++] = (UInt32)(lenInBits); +} + +void CContext::Update(Byte *data, size_t size, bool rar350Mode) +{ + bool returnRes = false; + unsigned int curBufferPos = _count2; + while (size-- > 0) + { + int pos = (int)(curBufferPos & 3); + if (pos == 0) + _buffer[curBufferPos >> 2] = 0; + _buffer[curBufferPos >> 2] |= ((UInt32)*data++) << (8 * (3 - pos)); + if (++curBufferPos == kBlockSize) + { + curBufferPos = 0; + CContextBase::UpdateBlock(_buffer, returnRes); + if (returnRes) + for (int i = 0; i < kBlockSizeInWords; i++) + { + UInt32 d = _buffer[i]; + data[i * 4 + 0 - kBlockSize] = (Byte)(d); + data[i * 4 + 1 - kBlockSize] = (Byte)(d >> 8); + data[i * 4 + 2 - kBlockSize] = (Byte)(d >> 16); + data[i * 4 + 3 - kBlockSize] = (Byte)(d >> 24); + } + returnRes = rar350Mode; + } + } + _count2 = curBufferPos; +} + +void CContext::Final(Byte *digest) +{ + const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 3); + unsigned int curBufferPos = _count2; + int pos = (int)(curBufferPos & 3); + curBufferPos >>= 2; + if (pos == 0) + _buffer[curBufferPos] = 0; + _buffer[curBufferPos++] |= ((UInt32)0x80) << (8 * (3 - pos)); + + while (curBufferPos != (16 - 2)) + { + curBufferPos &= 0xF; + if (curBufferPos == 0) + UpdateBlock(); + _buffer[curBufferPos++] = 0; + } + _buffer[curBufferPos++] = (UInt32)(lenInBits >> 32); + _buffer[curBufferPos++] = (UInt32)(lenInBits); + UpdateBlock(); + + int i; + for (i = 0; i < kDigestSizeInWords; i++) + { + UInt32 state = _state[i] & 0xFFFFFFFF; + *digest++ = (Byte)(state >> 24); + *digest++ = (Byte)(state >> 16); + *digest++ = (Byte)(state >> 8); + *digest++ = (Byte)(state); + } + Init(); +} + +/////////////////////////// +// Words version + +void CContext32::Update(const UInt32 *data, size_t size) +{ + while (size-- > 0) + { + _buffer[_count2++] = *data++; + if (_count2 == kBlockSizeInWords) + { + _count2 = 0; + UpdateBlock(); + } + } +} + +void CContext32::Final(UInt32 *digest) +{ + const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 5); + unsigned int curBufferPos = _count2; + _buffer[curBufferPos++] = 0x80000000; + while (curBufferPos != (16 - 2)) + { + curBufferPos &= 0xF; + if (curBufferPos == 0) + UpdateBlock(); + _buffer[curBufferPos++] = 0; + } + _buffer[curBufferPos++] = (UInt32)(lenInBits >> 32); + _buffer[curBufferPos++] = (UInt32)(lenInBits); + GetBlockDigest(_buffer, digest); + Init(); +} + +}} diff --git a/7zip/Crypto/Hash/Sha1.h b/7zip/Crypto/Hash/Sha1.h new file mode 100755 index 00000000..ebb11142 --- /dev/null +++ b/7zip/Crypto/Hash/Sha1.h @@ -0,0 +1,68 @@ +// Sha1.h +// This file is based on public domain +// Steve Reid and Wei Dai's code from Crypto++ + +#ifndef __SHA1_H +#define __SHA1_H + +#include +#include "../../../Common/Types.h" + +// Sha1 implementation in RAR before version 3.60 has bug: +// it changes data bytes in some cases. +// So this class supports both versions: normal_SHA and rar3Mode + +namespace NCrypto { +namespace NSha1 { + +const unsigned int kBlockSize = 64; +const unsigned int kDigestSize = 20; + +const unsigned int kBlockSizeInWords = (kBlockSize >> 2); +const unsigned int kDigestSizeInWords = (kDigestSize >> 2); + +class CContextBase +{ +protected: + UInt32 _state[5]; + UInt64 _count; + void UpdateBlock(UInt32 *data, bool returnRes = false) + { + GetBlockDigest(data, _state, returnRes); + _count++; + } +public: + void Init(); + void GetBlockDigest(UInt32 *blockData, UInt32 *destDigest, bool returnRes = false); + // PrepareBlock can be used only when size <= 13. size in Words + void PrepareBlock(UInt32 *block, unsigned int size) const; +}; + +class CContextBase2: public CContextBase +{ +protected: + unsigned int _count2; + UInt32 _buffer[kBlockSizeInWords]; + void UpdateBlock() { CContextBase::UpdateBlock(_buffer); } +public: + void Init() { CContextBase::Init(); _count2 = 0; } +}; + +class CContext: public CContextBase2 +{ +public: + void Update(Byte *data, size_t size, bool rar350Mode = false); + void Update(const Byte *data, size_t size) { Update((Byte *)data, size, false); } + void Final(Byte *digest); +}; + +class CContext32: public CContextBase2 +{ +public: + void Update(const UInt32 *data, size_t size); + void Final(UInt32 *digest); +}; + +}} + +#endif diff --git a/7zip/Crypto/Hash/Sha256.cpp b/7zip/Crypto/Hash/Sha256.cpp new file mode 100755 index 00000000..db236058 --- /dev/null +++ b/7zip/Crypto/Hash/Sha256.cpp @@ -0,0 +1,210 @@ +// Crypto/Sha256.cpp +// This code is based on code from Wei Dai's Crypto++ library. + +#include "StdAfx.h" + +#include "Sha256.h" +#include "RotateDefs.h" + +namespace NCrypto { +namespace NSha256 { + +// define it for speed optimization +// #define _SHA256_UNROLL +// #define _SHA256_UNROLL2 + +void CContext::Init() +{ + _state[0] = 0x6a09e667; + _state[1] = 0xbb67ae85; + _state[2] = 0x3c6ef372; + _state[3] = 0xa54ff53a; + _state[4] = 0x510e527f; + _state[5] = 0x9b05688c; + _state[6] = 0x1f83d9ab; + _state[7] = 0x5be0cd19; + + _count = 0; +} + +#define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22)) +#define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25)) +#define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3)) +#define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10)) + +#define blk0(i) (W[i] = data[i]) +#define blk2(i) (W[i&15] += s1(W[(i-2)&15]) + W[(i-7)&15] + s0(W[(i-15)&15])) + +#define Ch(x,y,z) (z^(x&(y^z))) +#define Maj(x,y,z) ((x&y)|(z&(x|y))) + +#define a(i) T[(0-(i))&7] +#define b(i) T[(1-(i))&7] +#define c(i) T[(2-(i))&7] +#define d(i) T[(3-(i))&7] +#define e(i) T[(4-(i))&7] +#define f(i) T[(5-(i))&7] +#define g(i) T[(6-(i))&7] +#define h(i) T[(7-(i))&7] + + +#ifdef _SHA256_UNROLL2 + +#define R(a,b,c,d,e,f,g,h, i) h += S1(e) + Ch(e,f,g) + K[i+j] + (j?blk2(i):blk0(i));\ + d += h; h += S0(a) + Maj(a, b, c) + +#define RX_8(i) \ + R(a,b,c,d,e,f,g,h, i); \ + R(h,a,b,c,d,e,f,g, i+1); \ + R(g,h,a,b,c,d,e,f, i+2); \ + R(f,g,h,a,b,c,d,e, i+3); \ + R(e,f,g,h,a,b,c,d, i+4); \ + R(d,e,f,g,h,a,b,c, i+5); \ + R(c,d,e,f,g,h,a,b, i+6); \ + R(b,c,d,e,f,g,h,a, i+7) + +#else + +#define R(i) h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j?blk2(i):blk0(i));\ + d(i) += h(i); h(i) += S0(a(i)) + Maj(a(i), b(i), c(i)) + +#ifdef _SHA256_UNROLL + +#define RX_8(i) R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7); + +#endif + +#endif + + +void CContext::Transform(UInt32 *state, const UInt32 *data) +{ + UInt32 W[16]; + + #ifdef _SHA256_UNROLL2 + UInt32 a,b,c,d,e,f,g,h; + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + f = state[5]; + g = state[6]; + h = state[7]; + #else + UInt32 T[8]; + for (int s = 0; s < 8; s++) + T[s] = state[s]; + #endif + + for (unsigned int j = 0; j < 64; j += 16) + { + #if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2) + RX_8(0); RX_8(8); + #else + for (unsigned int i = 0; i < 16; i++) { R(i); } + #endif + } + + #ifdef _SHA256_UNROLL2 + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + state[5] += f; + state[6] += g; + state[7] += h; + #else + for (int i = 0; i < 8; i++) + state[i] += T[i]; + #endif + + // Wipe variables + // memset(W, 0, sizeof(W)); + // memset(T, 0, sizeof(T)); +} + +const UInt32 CContext::K[64] = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 +}; + +#undef S0 +#undef S1 +#undef s0 +#undef s1 + +void CContext::WriteByteBlock() +{ + UInt32 data32[16]; + for (int i = 0; i < 16; i++) + { + data32[i] = (UInt32(_buffer[i * 4]) << 24) + + (UInt32(_buffer[i * 4 + 1]) << 16) + + (UInt32(_buffer[i * 4 + 2]) << 8) + + UInt32(_buffer[i * 4 + 3]); + } + Transform(_state, data32); +} + +void CContext::Update(const Byte *data, size_t size) +{ + UInt32 curBufferPos = (UInt32)_count & 0x3F; + while (size > 0) + { + _buffer[curBufferPos++] = *data++; + _count++; + size--; + if (curBufferPos == 64) + { + curBufferPos = 0; + WriteByteBlock(); + } + } +} + +void CContext::Final(Byte *digest) +{ + UInt64 lenInBits = (_count << 3); + UInt32 curBufferPos = (UInt32)_count & 0x3F; + _buffer[curBufferPos++] = 0x80; + while (curBufferPos != (64 - 8)) + { + curBufferPos &= 0x3F; + if (curBufferPos == 0) + WriteByteBlock(); + _buffer[curBufferPos++] = 0; + } + for (int i = 0; i < 8; i++) + { + _buffer[curBufferPos++] = (Byte)(lenInBits >> 56); + lenInBits <<= 8; + } + WriteByteBlock(); + + for (int j = 0; j < 8; j++) + { + *digest++ = (Byte)(_state[j] >> 24); + *digest++ = (Byte)(_state[j] >> 16); + *digest++ = (Byte)(_state[j] >> 8); + *digest++ = (Byte)(_state[j]); + } + Init(); +} + +}} diff --git a/7zip/Crypto/Hash/Sha256.h b/7zip/Crypto/Hash/Sha256.h new file mode 100755 index 00000000..e4788f41 --- /dev/null +++ b/7zip/Crypto/Hash/Sha256.h @@ -0,0 +1,30 @@ +// Crypto/Sha256.h + +#ifndef __CRYPTO_SHA256_H +#define __CRYPTO_SHA256_H + +#include "Common/Types.h" + +namespace NCrypto { +namespace NSha256 { + +class CContext +{ + static const UInt32 K[64]; + + UInt32 _state[8]; + UInt64 _count; + Byte _buffer[64]; + static void Transform(UInt32 *digest, const UInt32 *data); + void WriteByteBlock(); +public: + enum {DIGESTSIZE = 32}; + CContext() { Init(); } ; + void Init(); + void Update(const Byte *data, size_t size); + void Final(Byte *digest); +}; + +}} + +#endif diff --git a/7zip/Crypto/Hash/StdAfx.h b/7zip/Crypto/Hash/StdAfx.h new file mode 100755 index 00000000..e7fb6986 --- /dev/null +++ b/7zip/Crypto/Hash/StdAfx.h @@ -0,0 +1,8 @@ +// StdAfx.h + +#ifndef __STDAFX_H +#define __STDAFX_H + +#include "../../../Common/MyWindows.h" + +#endif diff --git a/7zip/Crypto/Rar20/Rar20Cipher.cpp b/7zip/Crypto/Rar20/Rar20Cipher.cpp index 322c6ff6..27ccc493 100755 --- a/7zip/Crypto/Rar20/Rar20Cipher.cpp +++ b/7zip/Crypto/Rar20/Rar20Cipher.cpp @@ -42,7 +42,7 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, UInt64 nowPos = 0; UInt32 bufferPos = 0; UInt32 processedSize; - while(true) + for (;;) { UInt32 size = kBufferSize - bufferPos; RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize)); diff --git a/7zip/Crypto/RarAES/RarAES.cpp b/7zip/Crypto/RarAES/RarAES.cpp index 00699158..ae22bb2a 100755 --- a/7zip/Crypto/RarAES/RarAES.cpp +++ b/7zip/Crypto/RarAES/RarAES.cpp @@ -4,14 +4,10 @@ #include "StdAfx.h" #include "RarAES.h" -#include "sha1.h" +#include "../Hash/Sha1.h" extern void GetCryptoFolderPrefix(TCHAR *path); -// {23170F69-40C1-278B-0601-010000000000} -DEFINE_GUID(CLSID_CCrypto_AES128_Decoder, -0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00); - namespace NCrypto { namespace NRar29 { @@ -81,7 +77,7 @@ STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size) STDMETHODIMP CDecoder::Init() { Calculate(); - CreateFilter(); + RINOK(CreateFilter()); CMyComPtr cp; RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp)); RINOK(cp->SetKey(aesKey, 16)); @@ -97,7 +93,7 @@ HRESULT CDecoder::CreateFilter() TCHAR aesLibPath[MAX_PATH + 64]; GetCryptoFolderPrefix(aesLibPath); lstrcat(aesLibPath, TEXT("AES.dll")); - return _aesLib.LoadAndCreateFilter(aesLibPath, CLSID_CCrypto_AES128_Decoder, &_aesFilter); + return _aesLib.LoadAndCreateFilter(aesLibPath, CLSID_CCrypto_AES_CBC_Decoder, &_aesFilter); } STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) @@ -115,7 +111,7 @@ void CDecoder::Calculate() memcpy(rawPassword, buffer, buffer.GetCapacity()); - int rawLength = buffer.GetCapacity(); + size_t rawLength = buffer.GetCapacity(); if (_thereIsSalt) { @@ -123,7 +119,7 @@ void CDecoder::Calculate() rawLength += kSaltSize; } - CSHA1 sha; + NSha1::CContext sha; sha.Init(); // seems rar reverts hash for sha. @@ -132,15 +128,12 @@ void CDecoder::Calculate() for (i = 0; i < hashRounds; i++) { sha.Update(rawPassword, rawLength, _rar350Mode); - Byte pswNum[3]; - pswNum[0] = (Byte)i; - pswNum[1] = (Byte)(i >> 8); - pswNum[2] = (Byte)(i >> 16); + Byte pswNum[3] = { (Byte)i, (Byte)(i >> 8), (Byte)(i >> 16) }; sha.Update(pswNum, 3, _rar350Mode); if (i % (hashRounds / 16) == 0) { - CSHA1 shaTemp = sha; - Byte digest[20]; + NSha1::CContext shaTemp = sha; + Byte digest[NSha1::kDigestSize]; shaTemp.Final(digest); aesInit[i / (hashRounds / 16)] = (Byte)digest[4 * 4 + 3]; } diff --git a/7zip/Crypto/RarAES/RarAES.h b/7zip/Crypto/RarAES/RarAES.h index 086a82f2..4b435b5e 100755 --- a/7zip/Crypto/RarAES/RarAES.h +++ b/7zip/Crypto/RarAES/RarAES.h @@ -11,6 +11,9 @@ #include "Common/Types.h" #include "Common/Buffer.h" +DEFINE_GUID(CLSID_CCrypto_AES_CBC_Decoder, +0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00); + namespace NCrypto { namespace NRar29 { diff --git a/7zip/Crypto/RarAES/sha1.cpp b/7zip/Crypto/RarAES/sha1.cpp deleted file mode 100755 index 4e76de9f..00000000 --- a/7zip/Crypto/RarAES/sha1.cpp +++ /dev/null @@ -1,169 +0,0 @@ -// sha1.cpp -// This file is based on public domain -// Steve Reid and Wei Dai's code from Crypto++ - -#include "StdAfx.h" - -#include "sha1.h" - -static inline UInt32 rotlFixed(UInt32 x, int n) -{ - return (x << n) | (x >> (32 - n)); -} - -#define blk0(i) (W[i] = data[i]) -#define blk1(i) (W[i&15] = rotlFixed(W[(i+13)&15]^W[(i+8)&15]^W[(i+2)&15]^W[i&15],1)) - -#define f1(x,y,z) (z^(x&(y^z))) -#define f2(x,y,z) (x^y^z) -#define f3(x,y,z) ((x&y)|(z&(x|y))) -#define f4(x,y,z) (x^y^z) - -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); -#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); -#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rotlFixed(v,5);w=rotlFixed(w,30); -#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rotlFixed(v,5);w=rotlFixed(w,30); -#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rotlFixed(v,5);w=rotlFixed(w,30); - - -/* Hash a single 512-bit block. This is the core of the algorithm. */ - -void CSHA1::Transform(UInt32 data[16], bool returnRes) -{ - UInt32 a, b, c, d, e; - UInt32 W[16]; - - /* Copy context->m_State[] to working vars */ - a = m_State[0]; - b = m_State[1]; - c = m_State[2]; - d = m_State[3]; - e = m_State[4]; - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); - R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); - R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); - R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); - R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); - R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); - R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); - R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); - R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); - R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); - R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); - R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); - R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); - R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); - R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); - R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); - R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); - R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); - R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); - R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); - /* Add the working vars back into context.m_State[] */ - m_State[0] += a; - m_State[1] += b; - m_State[2] += c; - m_State[3] += d; - m_State[4] += e; - if (returnRes) - for (int i = 0 ; i < 16; i++) - data[i] = W[i]; - - /* Wipe variables */ - a = b = c = d = e = 0; -} - - -void CSHA1::Init() -{ - m_State[0] = 0x67452301; - m_State[1] = 0xEFCDAB89; - m_State[2] = 0x98BADCFE; - m_State[3] = 0x10325476; - m_State[4] = 0xC3D2E1F0; - m_Count = 0; -} - - -void CSHA1::WriteByteBlock(bool returnRes) -{ - UInt32 data32[16]; - int i; - for (i = 0; i < 16; i++) - { - data32[i] = - (UInt32(_buffer[i * 4 + 0]) << 24) + - (UInt32(_buffer[i * 4 + 1]) << 16) + - (UInt32(_buffer[i * 4 + 2]) << 8) + - UInt32(_buffer[i * 4 + 3]); - } - Transform(data32, returnRes); - if (returnRes) - for (i = 0; i < 16; i++) - { - UInt32 d = data32[i]; - _buffer[i * 4 + 0] = (Byte)(d >> 0); - _buffer[i * 4 + 1] = (Byte)(d >> 8); - _buffer[i * 4 + 2] = (Byte)(d >> 16); - _buffer[i * 4 + 3] = (Byte)(d >> 24); - } -} - -void CSHA1::Update(Byte *data, size_t size, bool rar350Mode) -{ - bool returnRes = false; - UInt32 curBufferPos = UInt32(m_Count) & 0x3F; - while (size > 0) - { - while(curBufferPos < 64 && size > 0) - { - _buffer[curBufferPos++] = *data++; - m_Count++; - size--; - } - if (curBufferPos == 64) - { - curBufferPos = 0; - WriteByteBlock(returnRes); - if (returnRes) - for (int i = 0; i < 64; i++) - data[i - 64] = _buffer[i]; - returnRes = rar350Mode; - } - } -} - -void CSHA1::Final(Byte *digest) -{ - UInt64 lenInBits = (m_Count << 3); - UInt32 curBufferPos = UInt32(m_Count) & 0x3F; - _buffer[curBufferPos++] = 0x80; - while (curBufferPos != (64 - 8)) - { - curBufferPos &= 0x3F; - if (curBufferPos == 0) - WriteByteBlock(); - _buffer[curBufferPos++] = 0; - } - int i; - for (i = 0; i < 8; i++) - { - _buffer[curBufferPos++] = Byte(lenInBits >> 56); - lenInBits <<= 8; - } - WriteByteBlock(); - - for (i = 0; i < 5; i++) - { - UInt32 state = m_State[i] & 0xffffffff; - *digest++ = state >> 24; - *digest++ = state >> 16; - *digest++ = state >> 8; - *digest++ = state; - } - Init(); -} - - diff --git a/7zip/Crypto/RarAES/sha1.h b/7zip/Crypto/RarAES/sha1.h deleted file mode 100755 index a7cf9a16..00000000 --- a/7zip/Crypto/RarAES/sha1.h +++ /dev/null @@ -1,32 +0,0 @@ -// sha1.h -// This file is based on public domain -// Steve Reid and Wei Dai's code from Crypto++ - -#ifndef __RAR_SHA1 -#define __RAR_SHA1 - -#include -#include "../../../Common/Types.h" - -#define HW 5 - -// Sha1 implementation in RAR before version 3.60 has bug: -// it changes data bytes in some cases. -// So this class supports both versions: normal_SHA and rar3Mode - -struct CSHA1 -{ - UInt32 m_State[5]; - UInt64 m_Count; - unsigned char _buffer[64]; - - void Transform(UInt32 data[16], bool returnRes = false); - void WriteByteBlock(bool returnRes = false); - -public: - void Init(); - void Update(Byte *data, size_t size, bool rar350Mode = false); - void Final(Byte *digest); -}; - -#endif diff --git a/7zip/Crypto/WzAES/StdAfx.cpp b/7zip/Crypto/WzAES/StdAfx.cpp new file mode 100755 index 00000000..d0feea85 --- /dev/null +++ b/7zip/Crypto/WzAES/StdAfx.cpp @@ -0,0 +1,3 @@ +// StdAfx.cpp + +#include "StdAfx.h" diff --git a/7zip/Crypto/WzAES/StdAfx.h b/7zip/Crypto/WzAES/StdAfx.h new file mode 100755 index 00000000..e7fb6986 --- /dev/null +++ b/7zip/Crypto/WzAES/StdAfx.h @@ -0,0 +1,8 @@ +// StdAfx.h + +#ifndef __STDAFX_H +#define __STDAFX_H + +#include "../../../Common/MyWindows.h" + +#endif diff --git a/7zip/Crypto/WzAES/WzAES.cpp b/7zip/Crypto/WzAES/WzAES.cpp new file mode 100755 index 00000000..8bf53b43 --- /dev/null +++ b/7zip/Crypto/WzAES/WzAES.cpp @@ -0,0 +1,246 @@ +// WzAES.cpp +/* +This code implements Brian Gladman's scheme +specified in password Based File Encryption Utility. +*/ + +#include "StdAfx.h" + +#include "Windows/Defs.h" +#include "../../Common/StreamObjects.h" +#include "../../Common/StreamUtils.h" +#include "../Hash/Pbkdf2HmacSha1.h" +#include "../Hash/RandGen.h" + +#include "WzAES.h" + +#ifdef CRYPTO_AES +#include "../AES/MyAES.h" +#else +extern void GetCryptoFolderPrefix(TCHAR *path); +#endif + +// define it if you don't want to use speed-optimized version of Pbkdf2HmacSha1 +// #define _NO_WZAES_OPTIMIZATIONS + +namespace NCrypto { +namespace NWzAES { + +const unsigned int kAesKeySizeMax = 32; + +static const UInt32 kNumKeyGenIterations = 1000; + +STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size) +{ + if(size > kPasswordSizeMax) + return E_INVALIDARG; + _key.Password.SetCapacity(size); + memcpy(_key.Password, data, size); + return S_OK; +} + +void CBaseCoder::EncryptData(Byte *data, UInt32 size) +{ + unsigned int pos = _blockPos; + for (; size > 0; size--) + { + if (pos == kAesBlockSize) + { + int j; + for (j = 0; j < 8 && ++_counter[j] == 0; j++); + for (j = 0; j < 8; j++) + _buffer[j] = _counter[j]; + for (; j < kAesBlockSize; j++) + _buffer[j] = 0; + _aesFilter->Filter(_buffer, kAesBlockSize); + pos = 0; + } + *data++ ^= _buffer[pos++]; + } + _blockPos = pos; +} + +#ifndef _NO_WZAES_OPTIMIZATIONS + +static void BytesToBeUInt32s(const Byte *src, UInt32 *dest, int destSize) +{ + for (int i = 0 ; i < destSize; i++) + dest[i] = + ((UInt32)(src[i * 4 + 0]) << 24) | + ((UInt32)(src[i * 4 + 1]) << 16) | + ((UInt32)(src[i * 4 + 2]) << 8) | + ((UInt32)(src[i * 4 + 3])); +} + +#endif + +STDMETHODIMP CBaseCoder::Init() +{ + UInt32 keySize = _key.GetKeySize(); + UInt32 keysTotalSize = 2 * keySize + kPwdVerifCodeSize; + Byte buf[2 * kAesKeySizeMax + kPwdVerifCodeSize]; + + // for (int ii = 0; ii < 1000; ii++) + { + #ifdef _NO_WZAES_OPTIMIZATIONS + + NSha1::Pbkdf2Hmac( + _key.Password, _key.Password.GetCapacity(), + _key.Salt, _key.GetSaltSize(), + kNumKeyGenIterations, + buf, keysTotalSize); + + #else + + UInt32 buf32[(2 * kAesKeySizeMax + kPwdVerifCodeSize + 3) / 4]; + UInt32 key32SizeTotal = (keysTotalSize + 3) / 4; + UInt32 salt[kSaltSizeMax * 4]; + UInt32 saltSizeInWords = _key.GetSaltSize() / 4; + BytesToBeUInt32s(_key.Salt, salt, saltSizeInWords); + NSha1::Pbkdf2Hmac32( + _key.Password, _key.Password.GetCapacity(), + salt, saltSizeInWords, + kNumKeyGenIterations, + buf32, key32SizeTotal); + for (UInt32 j = 0; j < keysTotalSize; j++) + buf[j] = (Byte)(buf32[j / 4] >> (24 - 8 * (j & 3))); + + #endif + } + + _hmac.SetKey(buf + keySize, keySize); + memcpy(_key.PwdVerifComputed, buf + 2 * keySize, kPwdVerifCodeSize); + + _blockPos = kAesBlockSize; + for (int i = 0; i < 8; i++) + _counter[i] = 0; + + RINOK(CreateFilters()); + CMyComPtr cp; + RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp)); + return cp->SetKey(buf, keySize); +} + +static HRESULT SafeWrite(ISequentialOutStream *outStream, const Byte *data, UInt32 size) +{ + UInt32 processedSize; + RINOK(WriteStream(outStream, data, size, &processedSize)); + return ((processedSize == size) ? S_OK : E_FAIL); +} + +/* +STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) +{ + Byte keySizeMode = 3; + return outStream->Write(&keySizeMode, 1, NULL); +} +*/ + +HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream) +{ + UInt32 saltSize = _key.GetSaltSize(); + g_RandomGenerator.Generate(_key.Salt, saltSize); + Init(); + RINOK(SafeWrite(outStream, _key.Salt, saltSize)); + return SafeWrite(outStream, _key.PwdVerifComputed, kPwdVerifCodeSize); +} + +HRESULT CEncoder::WriteFooter(ISequentialOutStream *outStream) +{ + Byte mac[kMacSize]; + _hmac.Final(mac, kMacSize); + return SafeWrite(outStream, mac, kMacSize); +} + +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size) +{ + if (size != 1) + return E_INVALIDARG; + _key.Init(); + Byte keySizeMode = data[0]; + if (keySizeMode < 1 || keySizeMode > 3) + return E_INVALIDARG; + _key.KeySizeMode = keySizeMode; + return S_OK; +} + +HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream) +{ + UInt32 saltSize = _key.GetSaltSize(); + UInt32 extraSize = saltSize + kPwdVerifCodeSize; + Byte temp[kSaltSizeMax + kPwdVerifCodeSize]; + UInt32 processedSize; + RINOK(ReadStream(inStream, temp, extraSize, &processedSize)); + if (processedSize != extraSize) + return E_FAIL; + UInt32 i; + for (i = 0; i < saltSize; i++) + _key.Salt[i] = temp[i]; + for (i = 0; i < kPwdVerifCodeSize; i++) + _pwdVerifFromArchive[i] = temp[saltSize + i]; + return S_OK; +} + +static bool CompareArrays(const Byte *p1, const Byte *p2, UInt32 size) +{ + for (UInt32 i = 0; i < size; i++) + if (p1[i] != p2[i]) + return false; + return true; +} + +bool CDecoder::CheckPasswordVerifyCode() +{ + return CompareArrays(_key.PwdVerifComputed, _pwdVerifFromArchive, kPwdVerifCodeSize); +} + +HRESULT CDecoder::CheckMac(ISequentialInStream *inStream, bool &isOK) +{ + isOK = false; + UInt32 processedSize; + Byte mac1[kMacSize]; + RINOK(ReadStream(inStream, mac1, kMacSize, &processedSize)); + if (processedSize != kMacSize) + return E_FAIL; + Byte mac2[kMacSize]; + _hmac.Final(mac2, kMacSize); + isOK = CompareArrays(mac1, mac2, kMacSize); + return S_OK; +} + +STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size) +{ + EncryptData(data, size); + _hmac.Update(data, size); + return size; +} + +STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size) +{ + _hmac.Update(data, size); + EncryptData(data, size); + return size; +} + + +HRESULT CBaseCoder::CreateFilters() +{ + if (!_aesFilter) + { + #ifdef CRYPTO_AES + + _aesFilter = new CAES_ECB_Encoder; + + #else + + TCHAR aesLibPath[MAX_PATH + 64]; + GetCryptoFolderPrefix(aesLibPath); + lstrcat(aesLibPath, TEXT("AES.dll")); + RINOK(_aesLibrary.LoadAndCreateFilter(aesLibPath, CLSID_CCrypto_AES_ECB_Encoder, &_aesFilter)); + + #endif + } + return S_OK; +} + +}} diff --git a/7zip/Crypto/WzAES/WzAES.h b/7zip/Crypto/WzAES/WzAES.h new file mode 100755 index 00000000..c27bd326 --- /dev/null +++ b/7zip/Crypto/WzAES/WzAES.h @@ -0,0 +1,126 @@ +// WzAES.h +/* +This code implements Brian Gladman's scheme +specified in password Based File Encryption Utility: + - AES encryption (128,192,256-bit) in Counter (CTR) mode. + - HMAC-SHA1 authentication for encrypted data (10 bytes) + - Keys are derived by PPKDF2(RFC2898)-HMAC-SHA1 from ASCII password and + Salt (saltSize = aesKeySize / 2). + - 2 bytes contain Password Verifier's Code +*/ + +#ifndef __CRYPTO_WZ_AES_H +#define __CRYPTO_WZ_AES_H + +#include "../Hash/HmacSha1.h" + +#include "Common/MyCom.h" +#include "Common/Buffer.h" +#include "Common/Vector.h" + +#include "../../ICoder.h" +#include "../../IPassword.h" + +#ifndef CRYPTO_AES +#include "../../Archive/Common/CoderLoader.h" +#endif + +DEFINE_GUID(CLSID_CCrypto_AES_ECB_Encoder, +0x23170F69, 0x40C1, 0x278B, 0x06, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x00); + +namespace NCrypto { +namespace NWzAES { + +const unsigned int kAesBlockSize = 16; +const unsigned int kSaltSizeMax = 16; +const unsigned int kMacSize = 10; + +const UInt32 kPasswordSizeMax = 99; // 128; + +// Password Verification Code Size +const unsigned int kPwdVerifCodeSize = 2; + +class CKeyInfo +{ +public: + Byte KeySizeMode; // 1 - 128-bit , 2 - 192-bit , 3 - 256-bit + Byte Salt[kSaltSizeMax]; + Byte PwdVerifComputed[kPwdVerifCodeSize]; + + CByteBuffer Password; + + UInt32 GetKeySize() const { return (8 * (KeySizeMode & 3) + 8); } + UInt32 GetSaltSize() const { return (4 * (KeySizeMode & 3) + 4); } + + CKeyInfo() { Init(); } + void Init() { KeySizeMode = 3; } +}; + +class CBaseCoder: + public ICompressFilter, + public ICryptoSetPassword, + public CMyUnknownImp +{ +protected: + CKeyInfo _key; + Byte _counter[8]; + Byte _buffer[kAesBlockSize]; + NSha1::CHmac _hmac; + unsigned int _blockPos; + Byte _pwdVerifFromArchive[kPwdVerifCodeSize]; + + void EncryptData(Byte *data, UInt32 size); + + #ifndef CRYPTO_AES + CCoderLibrary _aesLibrary; + #endif + CMyComPtr _aesFilter; + + HRESULT CreateFilters(); +public: + STDMETHOD(Init)(); + STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) = 0; + + STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); + + UInt32 GetHeaderSize() const { return _key.GetSaltSize() + kPwdVerifCodeSize; } +}; + +class CEncoder: + public CBaseCoder + // public ICompressWriteCoderProperties +{ +public: + MY_UNKNOWN_IMP1(ICryptoSetPassword) + // ICompressWriteCoderProperties + // STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); + STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); + HRESULT WriteHeader(ISequentialOutStream *outStream); + HRESULT WriteFooter(ISequentialOutStream *outStream); + bool SetKeyMode(Byte mode) + { + if (mode < 1 || mode > 3) + return false; + _key.KeySizeMode = mode; + return true; + } +}; + +class CDecoder: + public CBaseCoder, + public ICompressSetDecoderProperties2 +{ +public: + MY_UNKNOWN_IMP2( + ICryptoSetPassword, + ICompressSetDecoderProperties2) + STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); + STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); + HRESULT ReadHeader(ISequentialInStream *inStream); + bool CheckPasswordVerifyCode(); + HRESULT CheckMac(ISequentialInStream *inStream, bool &isOK); +}; + +}} + +#endif diff --git a/7zip/Crypto/Zip/ZipCipher.cpp b/7zip/Crypto/Zip/ZipCipher.cpp index ec1d9554..639776ce 100755 --- a/7zip/Crypto/Zip/ZipCipher.cpp +++ b/7zip/Crypto/Zip/ZipCipher.cpp @@ -6,25 +6,11 @@ #include "Windows/Defs.h" #include "../../Common/StreamUtils.h" +#include "../Hash/RandGen.h" namespace NCrypto { namespace NZip { -/* -const int kBufferSize = 1 << 17; - -CBuffer2::CBuffer2(): - _buffer(0) -{ - _buffer = new Byte[kBufferSize]; -} - -CBuffer2::~CBuffer2() -{ - delete []_buffer; -} -*/ - STDMETHODIMP CEncoder::CryptoSetPassword(const Byte *data, UInt32 size) { _cipher.SetPassword(data, size); @@ -44,14 +30,9 @@ STDMETHODIMP CEncoder::Init() HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream) { - CRandom random; - random.Init(::GetTickCount()); - Byte header[kHeaderSize]; - for (int i = 0; i < kHeaderSize - 2; i++) - { - header[i] = Byte(random.Generate()); - } + g_RandomGenerator.Generate(header, kHeaderSize - 2); + header[kHeaderSize - 1] = Byte(_crc >> 24); header[kHeaderSize - 2] = Byte(_crc >> 16); diff --git a/7zip/Crypto/Zip/ZipCipher.h b/7zip/Crypto/Zip/ZipCipher.h index bad1eb0e..d750336c 100755 --- a/7zip/Crypto/Zip/ZipCipher.h +++ b/7zip/Crypto/Zip/ZipCipher.h @@ -4,7 +4,6 @@ #define __CRYPTO_ZIPCIPHER_H #include "Common/MyCom.h" -#include "Common/Random.h" #include "Common/Types.h" #include "../../ICoder.h" @@ -15,22 +14,11 @@ namespace NCrypto { namespace NZip { -/* -class CBuffer2 -{ -protected: - Byte *_buffer; -public: - CBuffer2(); - ~CBuffer2(); -}; -*/ class CEncoder : public ICompressFilter, public ICryptoSetPassword, public ICryptoSetCRC, public CMyUnknownImp - // public CBuffer2 { CCipher _cipher; UInt32 _crc; @@ -39,7 +27,6 @@ public: ICryptoSetPassword, ICryptoSetCRC ) - STDMETHOD(Init)(); STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size); diff --git a/7zip/Crypto/Zip/ZipCrypto.cpp b/7zip/Crypto/Zip/ZipCrypto.cpp index 97dcd67b..79f0953c 100755 --- a/7zip/Crypto/Zip/ZipCrypto.cpp +++ b/7zip/Crypto/Zip/ZipCrypto.cpp @@ -18,7 +18,7 @@ void CCipher::UpdateKeys(Byte b) Keys[0] = ZipCRC32(Keys[0], b); Keys[1] += Keys[0] & 0xff; Keys[1] = Keys[1] * 134775813L + 1; - Keys[2] = ZipCRC32(Keys[2], Keys[1] >> 24); + Keys[2] = ZipCRC32(Keys[2], (Byte)(Keys[1] >> 24)); } void CCipher::SetPassword(const Byte *password, UInt32 passwordLength) @@ -33,19 +33,19 @@ void CCipher::SetPassword(const Byte *password, UInt32 passwordLength) Byte CCipher::DecryptByteSpec() { UInt32 temp = Keys[2] | 2; - return (temp * (temp ^ 1)) >> 8; + return (Byte)((temp * (temp ^ 1)) >> 8); } Byte CCipher::DecryptByte(Byte encryptedByte) { - Byte c = encryptedByte ^ DecryptByteSpec(); + Byte c = (Byte)(encryptedByte ^ DecryptByteSpec()); UpdateKeys(c); return c; } Byte CCipher::EncryptByte(Byte b) { - Byte c = b ^ DecryptByteSpec(); + Byte c = (Byte)(b ^ DecryptByteSpec()); UpdateKeys(b); return c; } diff --git a/7zip/FileManager/App.cpp b/7zip/FileManager/App.cpp index 5f5ca09c..25842849 100755 --- a/7zip/FileManager/App.cpp +++ b/7zip/FileManager/App.cpp @@ -91,7 +91,7 @@ void CApp::SetListSettings() panel._showRealFileIcons = showRealFileIcons; panel._exStyle = extendedStyle; - DWORD style = panel._listView.GetStyle(); + DWORD style = (DWORD)panel._listView.GetStyle(); if (mySelectionMode) style |= LVS_SINGLESEL; else @@ -227,9 +227,9 @@ static void AddButton( but.iBitmap = imageList.GetImageCount(); HBITMAP b = ::LoadBitmap(g_hInstance, - large ? - (LPCTSTR)butInfo.BitmapResID: - (LPCTSTR)butInfo.Bitmap2ResID); + large ? + MAKEINTRESOURCE(butInfo.BitmapResID): + MAKEINTRESOURCE(butInfo.Bitmap2ResID)); if (b != 0) { imageList.AddMasked(b, RGB(255, 0, 255)); @@ -692,7 +692,7 @@ int CApp::GetFocusedPanelIndex() const { return LastFocusedPanel; HWND hwnd = ::GetFocus(); - while(true) + for (;;) { if (hwnd == 0) return 0; @@ -710,7 +710,7 @@ int CApp::GetFocusedPanelIndex() const static UString g_ToolTipBuffer; static CSysString g_ToolTipBufferSys; -void CApp::OnNotify(int ctrlID, LPNMHDR pnmh) +void CApp::OnNotify(int /* ctrlID */, LPNMHDR pnmh) { if (pnmh->hwndFrom == _rebar) { @@ -731,7 +731,7 @@ void CApp::OnNotify(int ctrlID, LPNMHDR pnmh) LPNMTTDISPINFO info = (LPNMTTDISPINFO)pnmh; info->hinst = 0; g_ToolTipBuffer.Empty(); - SetButtonText(info->hdr.idFrom, g_ToolTipBuffer); + SetButtonText((UINT32)info->hdr.idFrom, g_ToolTipBuffer); g_ToolTipBufferSys = GetSystemString(g_ToolTipBuffer); info->lpszText = (LPTSTR)(LPCTSTR)g_ToolTipBufferSys; return; @@ -742,7 +742,7 @@ void CApp::OnNotify(int ctrlID, LPNMHDR pnmh) LPNMTTDISPINFOW info = (LPNMTTDISPINFOW)pnmh; info->hinst = 0; g_ToolTipBuffer.Empty(); - SetButtonText(info->hdr.idFrom, g_ToolTipBuffer); + SetButtonText((UINT32)info->hdr.idFrom, g_ToolTipBuffer); info->lpszText = (LPWSTR)(LPCWSTR)g_ToolTipBuffer; return; } diff --git a/7zip/FileManager/ExtractCallback.cpp b/7zip/FileManager/ExtractCallback.cpp index 8e825861..3fd94c00 100755 --- a/7zip/FileManager/ExtractCallback.cpp +++ b/7zip/FileManager/ExtractCallback.cpp @@ -55,7 +55,7 @@ STDMETHODIMP CExtractCallbackImp::SetTotal(UInt64 total) STDMETHODIMP CExtractCallbackImp::SetCompleted(const UInt64 *completeValue) { - while(true) + for (;;) { if(ProgressDialog.ProgressSynch.GetStopped()) return E_ABORT; @@ -76,7 +76,8 @@ STDMETHODIMP CExtractCallbackImp::AskOverwrite( COverwriteDialog dialog; dialog.OldFileInfo.Time = *existTime; - if (dialog.OldFileInfo.SizeIsDefined = (existSize != NULL)) + dialog.OldFileInfo.SizeIsDefined = (existSize != NULL); + if (dialog.OldFileInfo.SizeIsDefined) dialog.OldFileInfo.Size = *existSize; dialog.OldFileInfo.Name = existName; @@ -88,7 +89,8 @@ STDMETHODIMP CExtractCallbackImp::AskOverwrite( dialog.NewFileInfo.Time = *newTime; } - if (dialog.NewFileInfo.SizeIsDefined = (newSize != NULL)) + dialog.NewFileInfo.SizeIsDefined = (newSize != NULL); + if (dialog.NewFileInfo.SizeIsDefined) dialog.NewFileInfo.Size = *newSize; dialog.NewFileInfo.Name = newName; @@ -96,7 +98,7 @@ STDMETHODIMP CExtractCallbackImp::AskOverwrite( NOverwriteDialog::NResult::EEnum writeAnswer = NOverwriteDialog::Execute(oldFileInfo, newFileInfo); */ - int writeAnswer = dialog.Create(NULL); // ParentWindow doesn't work with 7z + INT_PTR writeAnswer = dialog.Create(NULL); // ParentWindow doesn't work with 7z switch(writeAnswer) { @@ -126,7 +128,7 @@ STDMETHODIMP CExtractCallbackImp::AskOverwrite( } -STDMETHODIMP CExtractCallbackImp::PrepareOperation(const wchar_t *name, Int32 askExtractMode, const UInt64 *position) +STDMETHODIMP CExtractCallbackImp::PrepareOperation(const wchar_t *name, Int32 /* askExtractMode */, const UInt64 * /* position */) { return SetCurrentFilePath(name); } @@ -143,7 +145,7 @@ STDMETHODIMP CExtractCallbackImp::ShowMessage(const wchar_t *message) return S_OK; } -STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 operationResult) +STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 operationResult, bool encrypted) { switch(operationResult) { @@ -160,12 +162,16 @@ STDMETHODIMP CExtractCallbackImp::SetOperationResult(Int32 operationResult) langID = 0x02000A91; break; case NArchive::NExtract::NOperationResult::kDataError: - messageID = IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR; - langID = 0x02000A92; + messageID = encrypted ? + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR_ENCRYPTED: + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR; + langID = encrypted ? 0x02000A94 : 0x02000A92; break; case NArchive::NExtract::NOperationResult::kCRCError: - messageID = IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC; - langID = 0x02000A93; + messageID = encrypted ? + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC_ENCRYPTED: + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC; + langID = encrypted ? 0x02000A95 : 0x02000A93; break; default: return E_FAIL; diff --git a/7zip/FileManager/ExtractCallback.h b/7zip/FileManager/ExtractCallback.h index 9159e4f8..ee4aa0a0 100755 --- a/7zip/FileManager/ExtractCallback.h +++ b/7zip/FileManager/ExtractCallback.h @@ -51,7 +51,7 @@ public: STDMETHOD (PrepareOperation)(const wchar_t *name, Int32 askExtractMode, const UInt64 *position); STDMETHOD(MessageError)(const wchar_t *message); - STDMETHOD(SetOperationResult)(Int32 operationResult); + STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted); // IExtractCallbackUI diff --git a/7zip/FileManager/FM.cpp b/7zip/FileManager/FM.cpp index 3ff56736..95272d2a 100755 --- a/7zip/FileManager/FM.cpp +++ b/7zip/FileManager/FM.cpp @@ -7,6 +7,7 @@ #include "Common/Defs.h" #include "Common/StringConvert.h" +#include "Common/Alloc.h" #include "Windows/Control/Toolbar.h" #include "Windows/Error.h" @@ -126,6 +127,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); const wchar_t *kWindowClass = L"FM"; +#ifndef _UNICODE static bool IsItWindowsNT() { OSVERSIONINFO versionInfo; @@ -134,6 +136,7 @@ static bool IsItWindowsNT() return false; return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); } +#endif // FUNCTION: InitInstance(HANDLE, int) BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) @@ -359,14 +362,16 @@ static void SetMemoryLock() NSecurity::EnableLockMemoryPrivilege(); } -int WINAPI WinMain( HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int nCmdShow) { #ifndef _UNICODE g_IsNT = IsItWindowsNT(); #endif + + #ifdef _WIN32 + SetLargePageSize(); + #endif + InitCommonControls(); g_ComCtl32Version = ::GetDllVersion(TEXT("comctl32.dll")); @@ -430,7 +435,7 @@ int WINAPI WinMain( HINSTANCE hInstance, g_HWND = 0; OleUninitialize(); - return msg.wParam; + return (int)msg.wParam; } static void SaveWindowInfo(HWND aWnd) @@ -650,7 +655,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) */ case WM_NOTIFY: { - g_App.OnNotify(wParam, (LPNMHDR)lParam); + g_App.OnNotify((int)wParam, (LPNMHDR)lParam); break; } /* @@ -672,6 +677,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) void OnSize(HWND hWnd) { + /* if (g_App._rebar) { RECT rect; @@ -682,6 +688,7 @@ void OnSize(HWND hWnd) // g_App._rebar.SizeToRect(&rect); // g_App._rebar.Move(0, 0, xSize, ySize); } + */ MoveSubWindows(hWnd); } diff --git a/7zip/FileManager/FSDrives.cpp b/7zip/FileManager/FSDrives.cpp index cfc1c24c..447ff4dc 100755 --- a/7zip/FileManager/FSDrives.cpp +++ b/7zip/FileManager/FSDrives.cpp @@ -187,7 +187,7 @@ STDMETHODIMP CFSDrives::BindToParentFolder(IFolderFolder **resultFolder) return S_OK; } -STDMETHODIMP CFSDrives::GetName(BSTR *name) +STDMETHODIMP CFSDrives::GetName(BSTR * /* name */) { return E_NOTIMPL; } diff --git a/7zip/FileManager/FSFolder.cpp b/7zip/FileManager/FSFolder.cpp index f0eb49dc..40f04d1b 100755 --- a/7zip/FileManager/FSFolder.cpp +++ b/7zip/FileManager/FSFolder.cpp @@ -172,7 +172,7 @@ bool CFSFolder::LoadComments() if (length >= (1 << 28)) return false; AString s; - char *p = s.GetBuffer((size_t)length + 1); + char *p = s.GetBuffer((int)((size_t)length + 1)); UInt32 processedSize; file.Read(p, (UInt32)length, processedSize); p[length] = 0; @@ -380,7 +380,7 @@ STDMETHODIMP CFSFolder::BindToParentFolder(IFolderFolder **resultFolder) return S_OK; } -STDMETHODIMP CFSFolder::GetName(BSTR *name) +STDMETHODIMP CFSFolder::GetName(BSTR * /* name */) { return E_NOTIMPL; /* @@ -429,7 +429,7 @@ STDMETHODIMP CFSFolder::GetPath(BSTR *path) STDMETHODIMP CFSFolder::WasChanged(INT32 *wasChanged) { bool wasChangedMain = false; - while (true) + for (;;) { if (!_findChangeNotificationDefined) { @@ -518,7 +518,7 @@ HRESULT CFSFolder::GetComplexName(const wchar_t *name, UString &resultPath) return S_OK; } -STDMETHODIMP CFSFolder::CreateFolder(const wchar_t *name, IProgress *progress) +STDMETHODIMP CFSFolder::CreateFolder(const wchar_t *name, IProgress * /* progress */) { UString processedName; RINOK(GetComplexName(name, processedName)); @@ -531,7 +531,7 @@ STDMETHODIMP CFSFolder::CreateFolder(const wchar_t *name, IProgress *progress) return S_OK; } -STDMETHODIMP CFSFolder::CreateFile(const wchar_t *name, IProgress *progress) +STDMETHODIMP CFSFolder::CreateFile(const wchar_t *name, IProgress * /* progress */) { UString processedName; RINOK(GetComplexName(name, processedName)); @@ -541,7 +541,7 @@ STDMETHODIMP CFSFolder::CreateFile(const wchar_t *name, IProgress *progress) return S_OK; } -STDMETHODIMP CFSFolder::Rename(UInt32 index, const wchar_t *newName, IProgress *progress) +STDMETHODIMP CFSFolder::Rename(UInt32 index, const wchar_t *newName, IProgress * /* progress */) { const CDirItem &fileInfo = *_refs[index]; const UString fullPrefix = _path + GetPrefix(fileInfo); @@ -550,13 +550,11 @@ STDMETHODIMP CFSFolder::Rename(UInt32 index, const wchar_t *newName, IProgress * return S_OK; } -STDMETHODIMP CFSFolder::Delete(const UInt32 *indices, UInt32 numItems, - IProgress *progress) +STDMETHODIMP CFSFolder::Delete(const UInt32 *indices, UInt32 numItems,IProgress *progress) { RINOK(progress->SetTotal(numItems)); for (UInt32 i = 0; i < numItems; i++) { - int index = indices[i]; const CDirItem &fileInfo = *_refs[indices[i]]; const UString fullPath = _path + GetRelPath(fileInfo); bool result; @@ -573,7 +571,7 @@ STDMETHODIMP CFSFolder::Delete(const UInt32 *indices, UInt32 numItems, } STDMETHODIMP CFSFolder::SetProperty(UInt32 index, PROPID propID, - const PROPVARIANT *value, IProgress *progress) + const PROPVARIANT *value, IProgress * /* progress */) { if (index >= (UInt32)_refs.Size()) return E_INVALIDARG; diff --git a/7zip/FileManager/FSFolderCopy.cpp b/7zip/FileManager/FSFolderCopy.cpp index bba8b3f3..bcc4cf97 100755 --- a/7zip/FileManager/FSFolderCopy.cpp +++ b/7zip/FileManager/FSFolderCopy.cpp @@ -20,6 +20,7 @@ using namespace NFind; extern bool g_IsNT; #endif +/* static bool IsItWindows2000orHigher() { OSVERSIONINFO versionInfo; @@ -29,6 +30,7 @@ static bool IsItWindows2000orHigher() return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && (versionInfo.dwMajorVersion >= 5); } +*/ struct CProgressInfo { @@ -37,14 +39,14 @@ struct CProgressInfo }; static DWORD CALLBACK CopyProgressRoutine( - LARGE_INTEGER TotalFileSize, // file size + LARGE_INTEGER /* TotalFileSize */, // file size LARGE_INTEGER TotalBytesTransferred, // bytes transferred - LARGE_INTEGER StreamSize, // bytes in stream - LARGE_INTEGER StreamBytesTransferred, // bytes transferred for stream - DWORD dwStreamNumber, // current stream - DWORD dwCallbackReason, // callback reason - HANDLE hSourceFile, // handle to source file - HANDLE hDestinationFile, // handle to destination file + LARGE_INTEGER /* StreamSize */, // bytes in stream + LARGE_INTEGER /* StreamBytesTransferred */, // bytes transferred for stream + DWORD /* dwStreamNumber */, // current stream + DWORD /* dwCallbackReason */, // callback reason + HANDLE /* hSourceFile */, // handle to source file + HANDLE /* hDestinationFile */, // handle to destination file LPVOID lpData // from CopyFileEx ) { @@ -133,7 +135,6 @@ static bool MyMoveFile(LPCWSTR existingFile, LPCWSTR newFile, CProgressInfo progressInfo; progressInfo.Progress = progress; progressInfo.StartPos = completedSize; - BOOL CancelFlag = FALSE; MoveFileWithProgressPointer moveFunction = (MoveFileWithProgressPointer) ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), @@ -462,9 +463,8 @@ STDMETHODIMP CFSFolder::MoveTo( return S_OK; } -STDMETHODIMP CFSFolder::CopyFrom( - const wchar_t *fromFolderPath, - const wchar_t **itemsPaths, UInt32 numItems, IProgress *progress) +STDMETHODIMP CFSFolder::CopyFrom(const wchar_t * /* fromFolderPath */, + const wchar_t ** /* itemsPaths */, UInt32 /* numItems */, IProgress * /* progress */) { return E_NOTIMPL; } diff --git a/7zip/FileManager/LangUtils.cpp b/7zip/FileManager/LangUtils.cpp index 1f28c52c..decff306 100755 --- a/7zip/FileManager/LangUtils.cpp +++ b/7zip/FileManager/LangUtils.cpp @@ -103,7 +103,7 @@ void LoadLangs(CObjectVector &langs) continue; CLangEx lang; UString filePath = folderPath + fileInfo.Name; - const kExtSize = 4; + const int kExtSize = 4; if (fileInfo.Name.Right(kExtSize) != L".txt") continue; lang.ShortName = fileInfo.Name.Left(fileInfo.Name.Length() - kExtSize); @@ -138,8 +138,8 @@ void FindMatchLang(UString &shortName) { shortName.Empty(); LANGID langID = GetUserDefaultLangID(); - WORD primLang = PRIMARYLANGID(langID); - WORD subLang = SUBLANGID(langID); + WORD primLang = (WORD)(PRIMARYLANGID(langID)); + WORD subLang = (WORD)(SUBLANGID(langID)); CObjectVector langs; LoadLangs(langs); for (int i = 0; i < langs.Size(); i++) diff --git a/7zip/FileManager/MyLoadMenu.cpp b/7zip/FileManager/MyLoadMenu.cpp index 740b2520..e464f7f3 100755 --- a/7zip/FileManager/MyLoadMenu.cpp +++ b/7zip/FileManager/MyLoadMenu.cpp @@ -301,7 +301,7 @@ static void CopyMenu(HMENU srcMenuSpec, HMENU destMenuSpec) } } -void OnMenuActivating(HWND hWnd, HMENU hMenu, int position) +void OnMenuActivating(HWND /* hWnd */, HMENU hMenu, int position) { if (::GetSubMenu(::GetMenu(g_HWND), position) != hMenu) return; @@ -357,7 +357,7 @@ void OnMenuActivating(HWND hWnd, HMENU hMenu, int position) { UString s = LangString(IDS_BOOKMARK, 0x03000720); s += L" "; - wchar_t c = L'0' + i; + wchar_t c = (wchar_t)(L'0' + i); s += c; s += L"\tAlt+Shift+"; s += c; @@ -381,7 +381,7 @@ void OnMenuActivating(HWND hWnd, HMENU hMenu, int position) if (s.IsEmpty()) s = L"-"; s += L"\tAlt+"; - s += (L'0' + i); + s += (wchar_t)(L'0' + i); menu.AppendItem(MF_STRING, kOpenBookmarkMenuID + i, s); } } @@ -402,8 +402,7 @@ void OnMenuUnActivating(HWND hWnd) */ -void LoadFileMenu(HMENU hMenu, int startPos, bool forFileMode, - bool programMenu) +void LoadFileMenu(HMENU hMenu, int startPos, bool /* forFileMode */, bool programMenu) { { CMenu srcMenu; diff --git a/7zip/FileManager/NetFolder.cpp b/7zip/FileManager/NetFolder.cpp index 51ee5372..a5cd379a 100755 --- a/7zip/FileManager/NetFolder.cpp +++ b/7zip/FileManager/NetFolder.cpp @@ -85,7 +85,7 @@ STDMETHODIMP CNetFolder::LoadItems() _items.Clear(); CEnum enumerator; - while(true) + for (;;) { DWORD result = enumerator.Open( RESOURCE_GLOBALNET, @@ -104,7 +104,7 @@ STDMETHODIMP CNetFolder::LoadItems() return result; } - while(true) + for (;;) { CResourceEx resource; DWORD result = enumerator.Next(resource); @@ -212,7 +212,7 @@ STDMETHODIMP CNetFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder return S_OK; } -STDMETHODIMP CNetFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder) +STDMETHODIMP CNetFolder::BindToFolder(const wchar_t * /* name */, IFolderFolder ** /* resultFolder */) { return E_NOTIMPL; } diff --git a/7zip/FileManager/OpenCallback.cpp b/7zip/FileManager/OpenCallback.cpp index 9c9f842e..9ba2da05 100755 --- a/7zip/FileManager/OpenCallback.cpp +++ b/7zip/FileManager/OpenCallback.cpp @@ -9,22 +9,22 @@ #include "Windows/PropVariant.h" #include "../Common/FileStreams.h" -STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 *numFiles, const UINT64 *numBytes) +STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 * /* numFiles */, const UINT64 * /* numBytes */) { return S_OK; } -STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *numFiles, const UINT64 *numBytes) +STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 * /* numFiles */, const UINT64 * /* numBytes */) { return S_OK; } -STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 total) +STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 /* total */) { return S_OK; } -STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *completed) +STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 * /* completed */) { return S_OK; } diff --git a/7zip/FileManager/OptionsDialog.cpp b/7zip/FileManager/OptionsDialog.cpp index b6c07275..7413bafc 100755 --- a/7zip/FileManager/OptionsDialog.cpp +++ b/7zip/FileManager/OptionsDialog.cpp @@ -26,7 +26,7 @@ using namespace NWindows; -void OptionsDialog(HWND hwndOwner, HINSTANCE hInstance) +void OptionsDialog(HWND hwndOwner, HINSTANCE /* hInstance */) { CSystemPage systemPage; CPluginsPage pluginsPage; @@ -48,7 +48,7 @@ void OptionsDialog(HWND hwndOwner, HINSTANCE hInstance) pages.Add(page); } - int res = NControl::MyPropertySheet(pages, hwndOwner, LangString(IDS_OPTIONS, 0x03010000)); + INT_PTR res = NControl::MyPropertySheet(pages, hwndOwner, LangString(IDS_OPTIONS, 0x03010000)); if (res != -1 && res != 0) { if (langPage._langWasChanged) diff --git a/7zip/FileManager/Panel.cpp b/7zip/FileManager/Panel.cpp index f58b3d9f..da695053 100755 --- a/7zip/FileManager/Panel.cpp +++ b/7zip/FileManager/Panel.cpp @@ -80,7 +80,7 @@ LRESULT CPanel::Create(HWND mainWindow, HWND parentWindow, UINT id, if (!CreateEx(0, kClassName, 0, WS_CHILD | WS_VISIBLE, 0, 0, _xSize, 260, - parentWindow, (HMENU)id, g_hInstance)) + parentWindow, (HMENU)(UINT_PTR)id, g_hInstance)) return E_FAIL; return S_OK; } @@ -132,7 +132,7 @@ LRESULT CMyListView::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_CHAR) { - UINT scanCode = (lParam >> 16) & 0xFF; + UINT scanCode = (UINT)((lParam >> 16) & 0xFF); bool extended = ((lParam & 0x1000000) != 0); UINT virtualKey = MapVirtualKey(scanCode, 1); if (virtualKey == VK_MULTIPLY || virtualKey == VK_ADD || @@ -148,7 +148,7 @@ LRESULT CMyListView::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) else if (message == WM_SYSCHAR) { // For Alt+Enter Beep disabling - UINT scanCode = (lParam >> 16) & 0xFF; + UINT scanCode = (UINT)(lParam >> 16) & 0xFF; UINT virtualKey = MapVirtualKey(scanCode, 1); if (virtualKey == VK_RETURN || virtualKey == VK_MULTIPLY || virtualKey == VK_ADD || virtualKey == VK_SUBTRACT) @@ -164,8 +164,8 @@ LRESULT CMyListView::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) { bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0; bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; - bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0; - bool RightCtrl = (::GetKeyState(VK_RCONTROL) & 0x8000) != 0; + // bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0; + // bool RightCtrl = (::GetKeyState(VK_RCONTROL) & 0x8000) != 0; bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; switch(wParam) { @@ -295,7 +295,7 @@ LRESULT CMyComboBoxEdit::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) return CallWindowProc(_origWindowProc, *this, message, wParam, lParam); } -bool CPanel::OnCreate(CREATESTRUCT *createStruct) +bool CPanel::OnCreate(CREATESTRUCT * /* createStruct */) { // _virtualMode = false; // _sortIndex = 0; @@ -329,7 +329,7 @@ bool CPanel::OnCreate(CREATESTRUCT *createStruct) exStyle = WS_EX_CLIENTEDGE; if (!_listView.CreateEx(exStyle, style, 0, 0, 116, 260, - HWND(*this), (HMENU)_baseID + 1, g_hInstance, NULL)) + HWND(*this), (HMENU)(UINT_PTR)(_baseID + 1), g_hInstance, NULL)) return false; _listView.SetUnicodeFormat(true); @@ -438,7 +438,7 @@ bool CPanel::OnCreate(CREATESTRUCT *createStruct) WS_BORDER | WS_VISIBLE |WS_CHILD | CBS_DROPDOWN | CBS_AUTOHSCROLL, 0, 0, 100, 20, ((_headerReBar == 0) ? HWND(*this) : _headerToolBar), - (HMENU)(_comboBoxID), + (HMENU)(UINT_PTR)(_comboBoxID), g_hInstance, NULL); // _headerComboBox.SendMessage(CBEM_SETUNICODEFORMAT, (WPARAM)(BOOL)TRUE, 0); @@ -569,7 +569,7 @@ void CPanel::ChangeWindowSize(int xSize, int ySize) // _statusBar2.MoveWindow(0, 200, xSize, kStatusBar2Size); } -bool CPanel::OnSize(WPARAM wParam, int xSize, int ySize) +bool CPanel::OnSize(WPARAM /* wParam */, int xSize, int ySize) { if (_headerReBar) _headerReBar.Move(0, 0, xSize, 0); @@ -577,7 +577,7 @@ bool CPanel::OnSize(WPARAM wParam, int xSize, int ySize) return true; } -bool CPanel::OnNotifyReBar(LPNMHDR header, LRESULT &result) +bool CPanel::OnNotifyReBar(LPNMHDR header, LRESULT & /* result */) { switch(header->code) { @@ -592,7 +592,7 @@ bool CPanel::OnNotifyReBar(LPNMHDR header, LRESULT &result) return false; } -bool CPanel::OnNotify(UINT controlID, LPNMHDR header, LRESULT &result) +bool CPanel::OnNotify(UINT /* controlID */, LPNMHDR header, LRESULT &result) { if (!_processNotify) return false; @@ -729,7 +729,7 @@ void CPanel::SetListViewMode(UINT32 index) if (index >= 4) return; _ListViewMode = index; - DWORD oldStyle = _listView.GetStyle(); + DWORD oldStyle = (DWORD)_listView.GetStyle(); DWORD newStyle = kStyles[index]; if ((oldStyle & LVS_TYPEMASK) != newStyle) _listView.SetStyle((oldStyle & ~LVS_TYPEMASK) | newStyle); @@ -770,8 +770,7 @@ void CPanel::AddToArchive() } const UString archiveName = CreateArchiveName( names.Front(), (names.Size() > 1), false); - CompressFiles(_currentFolderPrefix, archiveName, - names, false, true, false); + CompressFiles(_currentFolderPrefix, archiveName, L"", names, false, true, false); // KillSelection(); } diff --git a/7zip/FileManager/Panel.h b/7zip/FileManager/Panel.h index a94cb868..e4e48d73 100755 --- a/7zip/FileManager/Panel.h +++ b/7zip/FileManager/Panel.h @@ -240,7 +240,7 @@ public: if (_virtualMode) return _realIndices[item.iItem]; */ - return item.lParam; + return (UInt32)item.lParam; } int GetRealItemIndex(int indexInListView) const { @@ -251,7 +251,7 @@ public: LPARAM param; if (!_listView.GetItemParam(indexInListView, param)) throw 1; - return param; + return (int)param; } UInt32 _ListViewMode; @@ -415,26 +415,28 @@ public: CPanel &_panel; public: - CDisableTimerProcessing(CPanel &panel): _panel(panel) - { - Disable(); - } - void Disable() - { - _processTimerMem = _panel._processTimer; - _processNotifyMem = _panel._processNotify; - _panel._processTimer = false; - _panel._processNotify = false; - } - void Restore() - { - _panel._processTimer = _processTimerMem; - _panel._processNotify = _processNotifyMem; - } - ~CDisableTimerProcessing() - { - Restore(); - } + + CDisableTimerProcessing(CPanel &panel): _panel(panel) + { + Disable(); + } + void Disable() + { + _processTimerMem = _panel._processTimer; + _processNotifyMem = _panel._processNotify; + _panel._processTimer = false; + _panel._processNotify = false; + } + void Restore() + { + _panel._processTimer = _processTimerMem; + _panel._processNotify = _processNotifyMem; + } + ~CDisableTimerProcessing() + { + Restore(); + } + CDisableTimerProcessing& operator=(const CDisableTimerProcessing &) {; } }; // bool _passwordIsDefined; @@ -466,7 +468,7 @@ public: HRESULT OpenItemAsArchive(int index); void OpenItemInArchive(int index, bool tryInternal, bool tryExternal, bool editMode); - LRESULT OnOpenItemChanged(const UString &folderPath, const UString &itemName); + HRESULT OnOpenItemChanged(const UString &folderPath, const UString &itemName); LRESULT OnOpenItemChanged(LPARAM lParam); void OpenItem(int index, bool tryInternal, bool tryExternal); diff --git a/7zip/FileManager/PanelCrc.cpp b/7zip/FileManager/PanelCrc.cpp index cc5d1eb2..12dcee55 100755 --- a/7zip/FileManager/PanelCrc.cpp +++ b/7zip/FileManager/PanelCrc.cpp @@ -53,7 +53,7 @@ void CDirEnumerator::Init() bool CDirEnumerator::GetNextFile(NFind::CFileInfoW &fileInfo, bool &filled, UString &resPath, DWORD &errorCode) { filled = false; - while(true) + for (;;) { if (Enumerators.IsEmpty()) { @@ -154,7 +154,7 @@ struct CThreadCrc UString scanningStr = LangString(IDS_SCANNING, 0x03020800); scanningStr += L" "; - while (true) + for (;;) { NFile::NFind::CFileInfoW fileInfo; bool filled; @@ -180,7 +180,7 @@ struct CThreadCrc DirEnumerator.Init(); - while(true) + for (;;) { NFile::NFind::CFileInfoW fileInfo; bool filled; @@ -209,7 +209,7 @@ struct CThreadCrc } NumFiles++; ProgressDialog->ProgressSynch.SetCurrentFileName(resPath); - while(true) + for (;;) { UInt32 processedSize; if (!inFile.Read(buffer, kBufSize, processedSize)) @@ -232,8 +232,8 @@ struct CThreadCrc for (int i = 0; i < resPath.Length(); i++) { wchar_t c = resPath[i]; - crc.UpdateByte(c & 0xFF); - crc.UpdateByte((c >> 8) & 0xFF); + crc.UpdateByte((Byte)(c & 0xFF)); + crc.UpdateByte((Byte)((c >> 8) & 0xFF)); } DataNameCrcSum += crc.GetDigest(); Result = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(DataSize); diff --git a/7zip/FileManager/PanelDrag.cpp b/7zip/FileManager/PanelDrag.cpp index 494bca79..95273102 100755 --- a/7zip/FileManager/PanelDrag.cpp +++ b/7zip/FileManager/PanelDrag.cpp @@ -42,16 +42,16 @@ public: STDMETHODIMP GetDataHere(LPFORMATETC pformatetc, LPSTGMEDIUM medium); STDMETHODIMP QueryGetData(LPFORMATETC pformatetc ); - STDMETHODIMP GetCanonicalFormatEtc ( LPFORMATETC pformatetc, LPFORMATETC pformatetcOut) + STDMETHODIMP GetCanonicalFormatEtc ( LPFORMATETC /* pformatetc */, LPFORMATETC pformatetcOut) { pformatetcOut->ptd = NULL; return ResultFromScode(E_NOTIMPL); } STDMETHODIMP SetData(LPFORMATETC etc, STGMEDIUM *medium, BOOL release); STDMETHODIMP EnumFormatEtc(DWORD drection, LPENUMFORMATETC *enumFormatEtc); - STDMETHODIMP DAdvise(FORMATETC *etc, DWORD advf, LPADVISESINK pAdvSink, DWORD *pdwConnection) + STDMETHODIMP DAdvise(FORMATETC * /* etc */, DWORD /* advf */, LPADVISESINK /* pAdvSink */, DWORD * /* pdwConnection */) { return OLE_E_ADVISENOTSUPPORTED; } - STDMETHODIMP DUnadvise(DWORD dwConnection) { return OLE_E_ADVISENOTSUPPORTED; } - STDMETHODIMP EnumDAdvise( LPENUMSTATDATA *ppenumAdvise) { return OLE_E_ADVISENOTSUPPORTED; } + STDMETHODIMP DUnadvise(DWORD /* dwConnection */) { return OLE_E_ADVISENOTSUPPORTED; } + STDMETHODIMP EnumDAdvise( LPENUMSTATDATA * /* ppenumAdvise */) { return OLE_E_ADVISENOTSUPPORTED; } CDataObject(); @@ -69,7 +69,7 @@ CDataObject::CDataObject() m_Etc.tymed = TYMED_HGLOBAL; } -STDMETHODIMP CDataObject::SetData(LPFORMATETC etc, STGMEDIUM *medium, BOOL release) +STDMETHODIMP CDataObject::SetData(LPFORMATETC etc, STGMEDIUM *medium, BOOL /* release */) { if (etc->cfFormat == m_SetFolderFormat && etc->tymed == TYMED_HGLOBAL && etc->dwAspect == DVASPECT_CONTENT && medium->tymed == TYMED_HGLOBAL) @@ -131,7 +131,7 @@ STDMETHODIMP CDataObject::GetData(LPFORMATETC etc, LPSTGMEDIUM medium) return S_OK; } -STDMETHODIMP CDataObject::GetDataHere(LPFORMATETC etc, LPSTGMEDIUM medium) +STDMETHODIMP CDataObject::GetDataHere(LPFORMATETC /* etc */, LPSTGMEDIUM /* medium */) { // Seems Windows doesn't call it, so we will not implement it. return E_UNEXPECTED; @@ -248,7 +248,7 @@ static bool CopyNamesToHGlobal(NMemory::CGlobal &hgDrop, const UStringVector &na { const AString &s = namesA[i]; int fullLength = s.Length() + 1; - strcpy(p, s); + MyStringCopy(p, (const char *)s); p += fullLength; totalLength -= fullLength; } @@ -278,7 +278,7 @@ static bool CopyNamesToHGlobal(NMemory::CGlobal &hgDrop, const UStringVector &na { const UString &s = names[i]; int fullLength = s.Length() + 1; - wcscpy(p, s); + MyStringCopy(p, (const WCHAR *)s); p += fullLength; totalLength -= fullLength; } @@ -287,7 +287,7 @@ static bool CopyNamesToHGlobal(NMemory::CGlobal &hgDrop, const UStringVector &na return true; } -void CPanel::OnDrag(LPNMLISTVIEW nmListView) +void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */) { CPanel::CDisableTimerProcessing disableTimerProcessing2(*this); if (!DoesItSupportOperations()) @@ -586,7 +586,7 @@ bool CDropTarget::IsItSameDrive() const } -DWORD CDropTarget::GetEffect(DWORD keyState, POINTL pt, DWORD allowedEffect) +DWORD CDropTarget::GetEffect(DWORD keyState, POINTL /* pt */, DWORD allowedEffect) { if (!m_DropIsAllowed || !m_PanelDropIsAllowed) return DROPEFFECT_NONE; @@ -636,7 +636,7 @@ bool CDropTarget::SetPath(bool enablePath) const { UINT setFolderFormat = RegisterClipboardFormat(kSvenZipSetFolderFormat); - FORMATETC etc = { setFolderFormat, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; + FORMATETC etc = { (CLIPFORMAT)setFolderFormat, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM medium; medium.tymed = etc.tymed; medium.pUnkForRelease = 0; @@ -653,7 +653,7 @@ bool CDropTarget::SetPath(bool enablePath) const GlobalUnlock(medium.hGlobal); return false; } - wcscpy(dest, path); + MyStringCopy(dest, (const wchar_t *)path); GlobalUnlock(medium.hGlobal); bool res = m_DataObject->SetData(&etc, &medium, FALSE) == S_OK; GlobalFree(medium.hGlobal); @@ -785,7 +785,7 @@ void CPanel::CompressDropFiles(const UStringVector &fileNames, const UString &fo if (IsFolderInTemp(folderPath2)) folderPath2 = L"C:\\"; // fix it } - CompressFiles(folderPath2, archiveName, fileNames, + CompressFiles(folderPath2, archiveName, L"", fileNames, false, // email true, // showDialog AreThereNamesFromTemp(fileNames) // waitFinish diff --git a/7zip/FileManager/PanelFolderChange.cpp b/7zip/FileManager/PanelFolderChange.cpp index d8ae7d1b..1db8196c 100755 --- a/7zip/FileManager/PanelFolderChange.cpp +++ b/7zip/FileManager/PanelFolderChange.cpp @@ -216,7 +216,7 @@ bool CPanel::OnNotifyComboBoxEndEdit(PNMCBEENDEDIT info, LRESULT &result) } #endif -void CPanel::OnComboBoxCommand(UINT code, LPARAM ¶m) +void CPanel::OnComboBoxCommand(UINT /* code */, LPARAM & /* param */) { /* if (code == CBN_SELENDOK) diff --git a/7zip/FileManager/PanelItemOpen.cpp b/7zip/FileManager/PanelItemOpen.cpp index c08581a8..9baaeebb 100755 --- a/7zip/FileManager/PanelItemOpen.cpp +++ b/7zip/FileManager/PanelItemOpen.cpp @@ -51,15 +51,15 @@ struct CTmpProcessInfo: public CTempFileInfo class CTmpProcessInfoRelease { - CTmpProcessInfo &_tmpProcessInfo; + CTmpProcessInfo *_tmpProcessInfo; public: bool _needDelete; CTmpProcessInfoRelease(CTmpProcessInfo &tmpProcessInfo): - _tmpProcessInfo(tmpProcessInfo), _needDelete(true) {} + _tmpProcessInfo(&tmpProcessInfo), _needDelete(true) {} ~CTmpProcessInfoRelease() { if (_needDelete) - _tmpProcessInfo.DeleteDirAndFile(); + _tmpProcessInfo->DeleteDirAndFile(); } }; @@ -139,6 +139,17 @@ HRESULT CPanel::OpenParentArchiveFolder() return S_OK; } +static const wchar_t *kStartExtensions[] = +{ + L"exe", + L"bat", + L"com", + L"chm", + L"doc", + L"pdf", + L"xls" +}; + static bool DoItemAlwaysStart(const UString &name) { int extPos = name.ReverseFind('.'); @@ -146,10 +157,10 @@ static bool DoItemAlwaysStart(const UString &name) return false; UString ext = name.Mid(extPos + 1); ext.MakeLower(); - return (ext == UString(L"exe") || - ext == UString(L"bat") || - ext == UString(L"com") || - ext == UString(L"chm")); + for (int i = 0; i < sizeof(kStartExtensions) / sizeof(kStartExtensions[0]); i++) + if (ext.Compare(kStartExtensions[i]) == 0) + return true; + return false; } static HANDLE StartEditApplication(const UString &path, HWND window) @@ -237,7 +248,7 @@ static HANDLE StartApplication(const UString &path, HWND window) if (shellExecuteExW == 0) return 0; shellExecuteExW(&execInfo); - result = (UINT32)execInfo.hInstApp; + result = (UINT32)(UINT_PTR)execInfo.hInstApp; hProcess = execInfo.hProcess; } else @@ -255,7 +266,7 @@ static HANDLE StartApplication(const UString &path, HWND window) execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; ::ShellExecuteEx(&execInfo); - result = (UINT32)execInfo.hInstApp; + result = (UINT32)(UINT_PTR)execInfo.hInstApp; hProcess = execInfo.hProcess; } if(result <= 32) @@ -319,7 +330,7 @@ void CPanel::OpenItem(int index, bool tryInternal, bool tryExternal) } } -LRESULT CPanel::OnOpenItemChanged(const UString &folderPath, const UString &itemName) +HRESULT CPanel::OnOpenItemChanged(const UString &folderPath, const UString &itemName) { CMyComPtr folderOperations; if (_folder.QueryInterface(IID_IFolderOperations, &folderOperations) != S_OK) diff --git a/7zip/FileManager/PanelItems.cpp b/7zip/FileManager/PanelItems.cpp index 12ade3cf..c7483eb5 100755 --- a/7zip/FileManager/PanelItems.cpp +++ b/7zip/FileManager/PanelItems.cpp @@ -131,7 +131,7 @@ void CPanel::InitColumns() } // InitColumns2(sortID); - while(true) + for (;;) if (!_listView.DeleteColumn(0)) break; @@ -331,7 +331,6 @@ void CPanel::RefreshListCtrl(const UString &focusedName, int focusedPos, bool se SetToRootFolder(); } - bool isRoot = IsRootFolder(); _headerToolBar.EnableButton(kParentFolderID, !IsRootFolder()); CMyComPtr folderSetFlatMode; @@ -411,7 +410,7 @@ void CPanel::RefreshListCtrl(const UString &focusedName, int focusedPos, bool se if (itemName.Find(L" ") >= 0) { int pos = 0; - while (true) + for (;;) { int posNew = itemName.Find(L" ", pos); if (posNew < 0) @@ -653,7 +652,7 @@ bool CPanel::IsItemFolder(int itemIndex) const return VARIANT_BOOLToBool(propVariant.boolVal); if (propVariant.vt == VT_EMPTY) return false; - throw 21632; + return false; } UINT64 CPanel::GetItemSize(int itemIndex) const diff --git a/7zip/FileManager/PanelKey.cpp b/7zip/FileManager/PanelKey.cpp index 493bcb1e..9c6ddac1 100755 --- a/7zip/FileManager/PanelKey.cpp +++ b/7zip/FileManager/PanelKey.cpp @@ -43,7 +43,7 @@ bool CPanel::OnKeyDown(LPNMLVKEYDOWN keyDownInfo, LRESULT &result) } bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0; bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; - bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0; + // bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0; bool rightCtrl = (::GetKeyState(VK_RCONTROL) & 0x8000) != 0; bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; result = 0; diff --git a/7zip/FileManager/PanelListNotify.cpp b/7zip/FileManager/PanelListNotify.cpp index abc86029..44bb3e8b 100755 --- a/7zip/FileManager/PanelListNotify.cpp +++ b/7zip/FileManager/PanelListNotify.cpp @@ -141,7 +141,7 @@ LRESULT CPanel::SetItemText(LVITEMW &item) { if(s.Length() + 1 > size) s = s.Left(size - 1); - wcscpy(item.pszText, s); + MyStringCopy(item.pszText, (const wchar_t *)s); } return 0; } @@ -150,7 +150,7 @@ extern DWORD g_ComCtl32Version; void CPanel::OnItemChanged(NMLISTVIEW *item) { - int index = item->lParam; + int index = (int)item->lParam; if (index == kParentIndex) return; bool oldSelected = (item->uOldState & LVIS_SELECTED) != 0; @@ -162,9 +162,9 @@ void CPanel::OnItemChanged(NMLISTVIEW *item) bool CPanel::OnNotifyList(LPNMHDR header, LRESULT &result) { - bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0; - bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; - bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; + // bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0; + // bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; + // bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; switch(header->code) { case LVN_ITEMCHANGED: @@ -222,8 +222,8 @@ bool CPanel::OnNotifyList(LPNMHDR header, LRESULT &result) { bool alt = (::GetKeyState(VK_MENU) & 0x8000) != 0; bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0; - bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0; - bool RightCtrl = (::GetKeyState(VK_RCONTROL) & 0x8000) != 0; + // bool leftCtrl = (::GetKeyState(VK_LCONTROL) & 0x8000) != 0; + // bool RightCtrl = (::GetKeyState(VK_RCONTROL) & 0x8000) != 0; bool shift = (::GetKeyState(VK_SHIFT) & 0x8000) != 0; if (!shift && alt && !ctrl) { @@ -310,7 +310,7 @@ bool CPanel::OnCustomDraw(LPNMLVCUSTOMDRAW lplvcd, LRESULT &result) lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec, lplvcd->nmcd.lItemlParam); */ - int realIndex = lplvcd->nmcd.lItemlParam; + int realIndex = (int)lplvcd->nmcd.lItemlParam; bool selected = false; if (realIndex != kParentIndex) selected = _selectedStatusVector[realIndex]; diff --git a/7zip/FileManager/PanelMenu.cpp b/7zip/FileManager/PanelMenu.cpp index 878478c0..64db53ee 100755 --- a/7zip/FileManager/PanelMenu.cpp +++ b/7zip/FileManager/PanelMenu.cpp @@ -326,13 +326,13 @@ bool CPanel::InvokePluginCommand(int id, commandInfo.cbSize = sizeof(commandInfo); commandInfo.fMask = CMIC_MASK_UNICODE; commandInfo.hwnd = GetParent(); - commandInfo.lpVerb = LPCSTR(offset); + commandInfo.lpVerb = (LPCSTR)(MAKEINTRESOURCE(offset)); commandInfo.lpParameters = NULL; CSysString currentFolderSys = GetSystemString(_currentFolderPrefix); commandInfo.lpDirectory = (LPCSTR)(LPCTSTR)(currentFolderSys); commandInfo.nShow = SW_SHOW; commandInfo.lpTitle = ""; - commandInfo.lpVerbW = LPCWSTR(offset); + commandInfo.lpVerbW = (LPCWSTR)(MAKEINTRESOURCEW(offset)); commandInfo.lpParameters = NULL; UString currentFolderUnicode = _currentFolderPrefix; commandInfo.lpDirectoryW = currentFolderUnicode; diff --git a/7zip/FileManager/PanelOperations.cpp b/7zip/FileManager/PanelOperations.cpp index 8f1f28e4..9616dca7 100755 --- a/7zip/FileManager/PanelOperations.cpp +++ b/7zip/FileManager/PanelOperations.cpp @@ -95,7 +95,7 @@ void CPanel::DeleteItems(bool toRecycleBin) fo.fAnyOperationsAborted = FALSE; fo.hNameMappings = 0; fo.lpszProgressTitle = 0; - int res = ::SHFileOperationA(&fo); + /* int res = */ ::SHFileOperationA(&fo); } else #endif diff --git a/7zip/FileManager/PanelSort.cpp b/7zip/FileManager/PanelSort.cpp index 79a36ceb..fd9027b9 100755 --- a/7zip/FileManager/PanelSort.cpp +++ b/7zip/FileManager/PanelSort.cpp @@ -29,14 +29,14 @@ int CALLBACK CompareItems2(LPARAM lParam1, LPARAM lParam2, LPARAM lpData) // if (panel->_sortIndex == 0) case kpidName: { - const UString &name1 = panel->GetItemName(lParam1); - const UString &name2 = panel->GetItemName(lParam2); + const UString name1 = panel->GetItemName((int)lParam1); + const UString name2 = panel->GetItemName((int)lParam2); int res = name1.CompareNoCase(name2); /* if (res != 0 || !panel->_flatMode) return res; - const UString &prefix1 = panel->GetItemPrefix(lParam1); - const UString &prefix2 = panel->GetItemPrefix(lParam2); + const UString prefix1 = panel->GetItemPrefix(lParam1); + const UString prefix2 = panel->GetItemPrefix(lParam2); return res = prefix1.CompareNoCase(prefix2); */ return res; @@ -47,8 +47,8 @@ int CALLBACK CompareItems2(LPARAM lParam1, LPARAM lParam2, LPARAM lpData) } case kpidExtension: { - const UString &ext1 = GetExtension(panel->GetItemName(lParam1)); - const UString &ext2 = GetExtension(panel->GetItemName(lParam2)); + const UString ext1 = GetExtension(panel->GetItemName((int)lParam1)); + const UString ext2 = GetExtension(panel->GetItemName((int)lParam2)); return ext1.CompareNoCase(ext2); } } @@ -63,13 +63,13 @@ int CALLBACK CompareItems2(LPARAM lParam1, LPARAM lParam2, LPARAM lpData) NCOM::CPropVariant propVariant1, propVariant2; // Name must be first property - panel->_folder->GetProperty(lParam1, propID, &propVariant1); - panel->_folder->GetProperty(lParam2, propID, &propVariant2); + panel->_folder->GetProperty((UINT32)lParam1, propID, &propVariant1); + panel->_folder->GetProperty((UINT32)lParam2, propID, &propVariant2); if(propVariant1.vt != propVariant2.vt) return 0; // It means some BUG if (propVariant1.vt == VT_BSTR) { - return wcsicmp(propVariant1.bstrVal, propVariant2.bstrVal); + return _wcsicmp(propVariant1.bstrVal, propVariant2.bstrVal); } return propVariant1.Compare(propVariant2); // return 0; @@ -86,8 +86,8 @@ int CALLBACK CompareItems(LPARAM lParam1, LPARAM lParam2, LPARAM lpData) CPanel *panel = (CPanel*)lpData; - bool isDirectory1 = panel->IsItemFolder(lParam1); - bool isDirectory2 = panel->IsItemFolder(lParam2); + bool isDirectory1 = panel->IsItemFolder((int)lParam1); + bool isDirectory2 = panel->IsItemFolder((int)lParam2); if(isDirectory1 && (!isDirectory2)) return -1; @@ -95,8 +95,6 @@ int CALLBACK CompareItems(LPARAM lParam1, LPARAM lParam2, LPARAM lpData) return 1; int result = CompareItems2(lParam1, lParam2, lpData); - if(lpData == NULL) - return 0; return panel->_ascending ? result: (-result); } diff --git a/7zip/FileManager/PanelSplitFile.cpp b/7zip/FileManager/PanelSplitFile.cpp index d1d9f408..2449f45f 100755 --- a/7zip/FileManager/PanelSplitFile.cpp +++ b/7zip/FileManager/PanelSplitFile.cpp @@ -122,7 +122,7 @@ struct CThreadSplit int volIndex = 0; - while(true) + for (;;) { UInt64 volSize; if (volIndex < VolumeSizes.Size()) @@ -298,7 +298,7 @@ struct CThreadCombine UString nextName = InputDirPrefix + FirstVolumeName; UInt64 totalSize = 0; - while (true) + for (;;) { NFile::NFind::CFileInfoW fileInfo; if (!NFile::NFind::FindFile(nextName, fileInfo)) @@ -337,7 +337,7 @@ struct CThreadCombine UInt64 pos = 0; nextName = InputDirPrefix + FirstVolumeName; bool needOpen = true; - while(true) + for (;;) { if (needOpen) { diff --git a/7zip/FileManager/PhysDriveFolder.cpp b/7zip/FileManager/PhysDriveFolder.cpp index 35e829f7..b69d3cb3 100755 --- a/7zip/FileManager/PhysDriveFolder.cpp +++ b/7zip/FileManager/PhysDriveFolder.cpp @@ -79,10 +79,10 @@ STDMETHODIMP CPhysDriveFolder::GetProperty(UInt32 itemIndex, PROPID propID, PROP return S_OK; } -STDMETHODIMP CPhysDriveFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder) +STDMETHODIMP CPhysDriveFolder::BindToFolder(UInt32 /* index */, IFolderFolder ** /* resultFolder */) { return E_NOTIMPL; } -STDMETHODIMP CPhysDriveFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder) +STDMETHODIMP CPhysDriveFolder::BindToFolder(const wchar_t * /* name */, IFolderFolder ** /* resultFolder */) { return E_NOTIMPL; } STDMETHODIMP CPhysDriveFolder::BindToParentFolder(IFolderFolder **resultFolder) @@ -91,7 +91,7 @@ STDMETHODIMP CPhysDriveFolder::BindToParentFolder(IFolderFolder **resultFolder) return S_OK; } -STDMETHODIMP CPhysDriveFolder::GetName(BSTR *name) +STDMETHODIMP CPhysDriveFolder::GetName(BSTR * /* name */) { return E_NOTIMPL; } STDMETHODIMP CPhysDriveFolder::GetNumberOfProperties(UInt32 *numProperties) @@ -144,7 +144,7 @@ STDMETHODIMP CPhysDriveFolder::Clone(IFolderFolder **resultFolder) return S_OK; } -STDMETHODIMP CPhysDriveFolder::GetItemFullSize(UInt32 index, PROPVARIANT *value, IProgress *progress) +STDMETHODIMP CPhysDriveFolder::GetItemFullSize(UInt32 index, PROPVARIANT *value, IProgress * /* progress */) { NCOM::CPropVariant propVariant; if (index >= 1) @@ -156,20 +156,20 @@ STDMETHODIMP CPhysDriveFolder::GetItemFullSize(UInt32 index, PROPVARIANT *value, return result; } -STDMETHODIMP CPhysDriveFolder::CreateFolder(const wchar_t *name, IProgress *progress) +STDMETHODIMP CPhysDriveFolder::CreateFolder(const wchar_t * /* name */, IProgress * /* progress */) { return E_NOTIMPL; } -STDMETHODIMP CPhysDriveFolder::CreateFile(const wchar_t *name, IProgress *progress) +STDMETHODIMP CPhysDriveFolder::CreateFile(const wchar_t * /* name */, IProgress * /* progress */) { return E_NOTIMPL; } -STDMETHODIMP CPhysDriveFolder::Rename(UInt32 index, const wchar_t *newName, IProgress *progress) +STDMETHODIMP CPhysDriveFolder::Rename(UInt32 /* index */, const wchar_t * /* newName */, IProgress * /* progress */) { return E_NOTIMPL; } -STDMETHODIMP CPhysDriveFolder::Delete(const UInt32 *indices, UInt32 numItems, IProgress *progress) +STDMETHODIMP CPhysDriveFolder::Delete(const UInt32 * /* indices */, UInt32 /* numItems */, IProgress * /* progress */) { return E_NOTIMPL; } -STDMETHODIMP CPhysDriveFolder::SetProperty(UInt32 index, PROPID propID, - const PROPVARIANT *value, IProgress *progress) +STDMETHODIMP CPhysDriveFolder::SetProperty(UInt32 index, PROPID /* propID */, + const PROPVARIANT * /* value */, IProgress * /* progress */) { if (index >= 1) return E_INVALIDARG; @@ -186,7 +186,7 @@ HRESULT CPhysDriveFolder::GetLength(UInt64 &length) const return S_OK; } -STDMETHODIMP CPhysDriveFolder::CopyTo(const UInt32 *indices, UInt32 numItems, +STDMETHODIMP CPhysDriveFolder::CopyTo(const UInt32 * /* indices */, UInt32 numItems, const wchar_t *path, IFolderOperationsExtractCallback *callback) { if (numItems == 0) @@ -258,17 +258,17 @@ STDMETHODIMP CPhysDriveFolder::CopyTo(const UInt32 *indices, UInt32 numItems, // Move Operations STDMETHODIMP CPhysDriveFolder::MoveTo( - const UInt32 *indices, - UInt32 numItems, - const wchar_t *path, - IFolderOperationsExtractCallback *callback) + const UInt32 * /* indices */, + UInt32 /* numItems */, + const wchar_t * /* path */, + IFolderOperationsExtractCallback * /* callback */) { return E_NOTIMPL; } STDMETHODIMP CPhysDriveFolder::CopyFrom( - const wchar_t *fromFolderPath, - const wchar_t **itemsPaths, UInt32 numItems, IProgress *progress) + const wchar_t * /* fromFolderPath */, + const wchar_t ** /* itemsPaths */, UInt32 /* numItems */, IProgress * /* progress */) { return E_NOTIMPL; } diff --git a/7zip/FileManager/RegistryUtils.cpp b/7zip/FileManager/RegistryUtils.cpp index ea92aa73..22869c46 100755 --- a/7zip/FileManager/RegistryUtils.cpp +++ b/7zip/FileManager/RegistryUtils.cpp @@ -94,6 +94,7 @@ static bool ReadOption(const TCHAR *value, bool defaultValue) return defaultValue; } +/* static void SaveLmOption(const TCHAR *value, bool enabled) { CKey key; @@ -112,6 +113,7 @@ static bool ReadLmOption(const TCHAR *value, bool defaultValue) } return defaultValue; } +*/ void SaveShowDots(bool showDots) { SaveOption(kShowDots, showDots); } bool ReadShowDots() { return ReadOption(kShowDots, false); } diff --git a/7zip/FileManager/Resource/BenchmarkDialog/BenchmarkDialog.cpp b/7zip/FileManager/Resource/BenchmarkDialog/BenchmarkDialog.cpp index bac3d9cb..fd627d30 100755 --- a/7zip/FileManager/Resource/BenchmarkDialog/BenchmarkDialog.cpp +++ b/7zip/FileManager/Resource/BenchmarkDialog/BenchmarkDialog.cpp @@ -235,7 +235,7 @@ bool CBenchmarkDialog::OnInit() TCHAR s[40]; ConvertUInt64ToString((dictionary >> 20), s); lstrcat(s, kMB); - int index = m_Dictionary.AddString(s); + int index = (int)m_Dictionary.AddString(s); m_Dictionary.SetItemData(index, dictionary); } m_Dictionary.SetCurSel(0); @@ -413,7 +413,7 @@ void CBenchmarkDialog::PrintResults( PrintRating(rating, ratingID); } -bool CBenchmarkDialog::OnTimer(WPARAM timerID, LPARAM callback) +bool CBenchmarkDialog::OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { PrintTime(); NWindows::NSynchronization::CCriticalSectionLock lock(_syncInfo.CS); @@ -629,7 +629,7 @@ struct CDecoderProgressInfo: }; STDMETHODIMP CDecoderProgressInfo::SetRatioInfo( - const UInt64 *inSize, const UInt64 *outSize) + const UInt64 * /* inSize */, const UInt64 * /* outSize */) { NSynchronization::CCriticalSectionLock lock(SyncInfo->CS); if (SyncInfo->Changed) @@ -647,16 +647,18 @@ struct CThreadBenchmark: NDLL::CLibrary Library; CMyComPtr Encoder; CMyComPtr Decoder; - DWORD Process(); + HRESULT Process(); + HRESULT Result; static DWORD WINAPI MyThreadFunction(void *param) { - return ((CThreadBenchmark *)param)->Process(); + ((CThreadBenchmark *)param)->Result = ((CThreadBenchmark *)param)->Process(); + return 0; } MY_UNKNOWN_IMP STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize); }; -DWORD CThreadBenchmark::Process() +HRESULT CThreadBenchmark::Process() { try { @@ -685,7 +687,7 @@ DWORD CThreadBenchmark::Process() CMyComPtr decoderProgress = decoderProgressInfoSpec; decoderProgressInfoSpec->SyncInfo = SyncInfo; - while(true) + for (;;) { if (SyncInfo->WasStopped()) return 0; @@ -760,7 +762,7 @@ DWORD CThreadBenchmark::Process() // this code is for reducing time of memory allocationg inStreamSpec->Init(randomGenerator.Buffer, MyMin((UInt32)1, randomGenerator.BufferSize)); outStreamSpec->Init(); - HRESULT result = Encoder->Code(inStream, outStream, 0, 0, NULL); + /* HRESULT result = */ Encoder->Code(inStream, outStream, 0, 0, NULL); } inStreamSpec->Init(randomGenerator.Buffer, randomGenerator.BufferSize); @@ -815,7 +817,7 @@ DWORD CThreadBenchmark::Process() if (compressSetDecoderProperties) { RINOK(compressSetDecoderProperties->SetDecoderProperties2( - propStreamSpec->GetBuffer(), propStreamSpec->GetSize())); + propStreamSpec->GetBuffer(), (UInt32)propStreamSpec->GetSize())); } UInt64 outSize = kBufferSize; diff --git a/7zip/FileManager/Resource/LangPage/LangPage.cpp b/7zip/FileManager/Resource/LangPage/LangPage.cpp index f3d9c1d4..9974759a 100755 --- a/7zip/FileManager/Resource/LangPage/LangPage.cpp +++ b/7zip/FileManager/Resource/LangPage/LangPage.cpp @@ -30,7 +30,7 @@ bool CLangPage::OnInit() s += L" ("; s += NWindows::MyLoadStringW(IDS_LANG_NATIVE); s += L")"; - int index = _langCombo.AddString(s); + int index = (int)_langCombo.AddString(s); _langCombo.SetItemData(index, _paths.Size()); _paths.Add(L"-"); _langCombo.SetCurSel(0); @@ -55,7 +55,7 @@ bool CLangPage::OnInit() name += L")"; } } - index = _langCombo.AddString(name); + index = (int)_langCombo.AddString(name); _langCombo.SetItemData(index, _paths.Size()); _paths.Add(lang.ShortName); if (g_LangID.CompareNoCase(lang.ShortName) == 0) @@ -67,7 +67,7 @@ bool CLangPage::OnInit() LONG CLangPage::OnApply() { int selectedIndex = _langCombo.GetCurSel(); - int pathIndex = _langCombo.GetItemData(selectedIndex); + int pathIndex = (int)_langCombo.GetItemData(selectedIndex); SaveRegLang(_paths[pathIndex]); ReloadLang(); _langWasChanged = true; diff --git a/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp b/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp index 750a4085..ca7b7935 100755 --- a/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp +++ b/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp @@ -45,7 +45,7 @@ bool CListViewDialog::OnInit() return CModalDialog::OnInit(); } -bool CListViewDialog::OnNotify(UINT controlID, LPNMHDR header) +bool CListViewDialog::OnNotify(UINT /* controlID */, LPNMHDR header) { if (header->hwndFrom != _listView) return false; @@ -63,7 +63,7 @@ bool CListViewDialog::OnNotify(UINT controlID, LPNMHDR header) int focusedIndex = _listView.GetFocusedItem(); if (focusedIndex < 0) focusedIndex = 0; - while(true) + for (;;) { int index = _listView.GetNextSelectedItem(-1); if (index < 0) diff --git a/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.cpp b/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.cpp index 85fcd806..40453ccb 100755 --- a/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.cpp +++ b/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.cpp @@ -82,7 +82,7 @@ void CProgressDialog::SetPos(UINT64 pos) } } -bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback) +bool CProgressDialog::OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { if (ProgressSynch.GetPaused()) return true; diff --git a/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.cpp b/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.cpp index 49961874..128081aa 100755 --- a/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.cpp +++ b/7zip/FileManager/Resource/ProgressDialog2/ProgressDialog.cpp @@ -31,7 +31,7 @@ static CIDLangPair kIDLangPairs[] = HRESULT CProgressSynch::SetPosAndCheckPaused(UInt64 completed) { - while(true) + for (;;) { if(GetStopped()) return E_ABORT; @@ -114,7 +114,7 @@ void CProgressDialog::OnCancel() static void ConvertSizeToString(UInt64 value, wchar_t *s) { const wchar_t *kModif = L" KMGTP"; - for (int i = 0; true; i++) + for (int i = 0; ; i++) if (i == 5 || value < (UInt64(10000) << (i * 10))) { ConvertUInt64ToString(value >> (i * 10), s); @@ -163,7 +163,7 @@ static void GetTimeString(UInt64 timeValue, TCHAR *s) UInt32(timeValue % 60)); } -bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback) +bool CProgressDialog::OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { if (ProgressSynch.GetPaused()) return true; diff --git a/7zip/FileManager/Resource/SystemPage/SystemPage.cpp b/7zip/FileManager/Resource/SystemPage/SystemPage.cpp index 4c561b18..ca3b7432 100755 --- a/7zip/FileManager/Resource/SystemPage/SystemPage.cpp +++ b/7zip/FileManager/Resource/SystemPage/SystemPage.cpp @@ -351,7 +351,7 @@ void CSystemPage::UpdateDatabase() LPARAM param; if (!_listViewExt.GetItemParam(i, param)) return; - CExtInfoBig &extInfo = _extDatabase.ExtBigItems[param]; + CExtInfoBig &extInfo = _extDatabase.ExtBigItems[(int)param]; extInfo.Associated = _listViewExt.GetCheckState(i); } @@ -376,7 +376,7 @@ int CSystemPage::GetSelectedExtIndex() LPARAM param; if (!_listViewExt.GetItemParam(selectedIndex, param)) return -1; - return param; + return (int)param; } diff --git a/7zip/FileManager/RootFolder.cpp b/7zip/FileManager/RootFolder.cpp index 6eed3d1f..4ff0660b 100755 --- a/7zip/FileManager/RootFolder.cpp +++ b/7zip/FileManager/RootFolder.cpp @@ -151,7 +151,7 @@ STDMETHODIMP CRootFolder::BindToParentFolder(IFolderFolder **resultFolder) return S_OK; } -STDMETHODIMP CRootFolder::GetName(BSTR *name) +STDMETHODIMP CRootFolder::GetName(BSTR * /* name */) { return E_NOTIMPL; } diff --git a/7zip/FileManager/SplitUtils.cpp b/7zip/FileManager/SplitUtils.cpp index b8fb5948..0264c06d 100755 --- a/7zip/FileManager/SplitUtils.cpp +++ b/7zip/FileManager/SplitUtils.cpp @@ -50,7 +50,7 @@ bool ParseVolumeSizes(const UString &s, CRecordVector &values) return false; values.Add(value); prevIsNumber = true; - UString rem = subString.Mid(end - start); + UString rem = subString.Mid((int)(end - start)); if (!rem.IsEmpty()) destStrings.Insert(i + 1, rem); } diff --git a/7zip/FileManager/TextPairs.cpp b/7zip/FileManager/TextPairs.cpp index ce5a4c3f..76c97b8c 100755 --- a/7zip/FileManager/TextPairs.cpp +++ b/7zip/FileManager/TextPairs.cpp @@ -123,7 +123,7 @@ static int ComparePairItems(const CTextPair &p1, const CTextPair &p2) // typedef void* MY_PVOID; // static int ComparePairItems(const MY_PVOID *a1, const MY_PVOID *a2, void *param) -static int ComparePairItems(void *const *a1, void *const *a2, void *param) +static int ComparePairItems(void *const *a1, void *const *a2, void * /* param */) { return ComparePairItems(**(const CTextPair **)a1, **(const CTextPair **)a2); } void CPairsStorage::Sort() diff --git a/7zip/FileManager/UpdateCallback100.cpp b/7zip/FileManager/UpdateCallback100.cpp index c9931922..ddd2e55d 100755 --- a/7zip/FileManager/UpdateCallback100.cpp +++ b/7zip/FileManager/UpdateCallback100.cpp @@ -36,7 +36,7 @@ STDMETHODIMP CUpdateCallback100Imp::SetTotal(UINT64 size) STDMETHODIMP CUpdateCallback100Imp::SetCompleted(const UINT64 *completeValue) { - while(true) + for (;;) { if(ProgressDialog.ProgressSynch.GetStopped()) return E_ABORT; @@ -55,12 +55,12 @@ STDMETHODIMP CUpdateCallback100Imp::CompressOperation(const wchar_t *name) return S_OK; } -STDMETHODIMP CUpdateCallback100Imp::DeleteOperation(const wchar_t *name) +STDMETHODIMP CUpdateCallback100Imp::DeleteOperation(const wchar_t * /* name */) { return S_OK; } -STDMETHODIMP CUpdateCallback100Imp::OperationResult(INT32 operationResult) +STDMETHODIMP CUpdateCallback100Imp::OperationResult(INT32 /* operationResult */) { return S_OK; } diff --git a/7zip/FileManager/ViewSettings.cpp b/7zip/FileManager/ViewSettings.cpp index 61d422cc..9102cc4e 100755 --- a/7zip/FileManager/ViewSettings.cpp +++ b/7zip/FileManager/ViewSettings.cpp @@ -286,7 +286,7 @@ void SaveToolbarsMask(UInt32 toolbarMask) key.SetValue(kToolbars, toolbarMask); } -static const kDefaultToolbarMask = 8 | 4 | 1; +static const UInt32 kDefaultToolbarMask = 8 | 4 | 1; UInt32 ReadToolbarsMask() { @@ -360,11 +360,11 @@ void SaveStringList(LPCTSTR valueName, const UStringVector &folders) sizeInChars += folders[i].Length() + 1; CBuffer buffer; buffer.SetCapacity(sizeInChars); - int aPos = 0; + int pos = 0; for (i = 0; i < folders.Size(); i++) { - wcscpy(buffer + aPos, folders[i]); - aPos += folders[i].Length() + 1; + MyStringCopy((wchar_t *)buffer + pos, (const wchar_t *)folders[i]); + pos += folders[i].Length() + 1; } CKey key; NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); diff --git a/7zip/MyVersion.h b/7zip/MyVersion.h index 39bcb475..dd539afb 100755 --- a/7zip/MyVersion.h +++ b/7zip/MyVersion.h @@ -1,8 +1,8 @@ #define MY_VER_MAJOR 4 -#define MY_VER_MINOR 42 -#define MY_VER_BUILD 0 -#define MY_VERSION "4.42" -#define MY_7ZIP_VERSION "7-Zip 4.42" -#define MY_DATE "2006-05-14" +#define MY_VER_MINOR 43 +#define MY_VER_BUILD 7 +#define MY_VERSION "4.43 beta" +#define MY_7ZIP_VERSION "7-Zip 4.43" +#define MY_DATE "2006-09-15" #define MY_COPYRIGHT "Copyright (c) 1999-2006 Igor Pavlov" #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE diff --git a/7zip/UI/Agent/Agent.cpp b/7zip/UI/Agent/Agent.cpp index eb37b84f..b47e7ec5 100755 --- a/7zip/UI/Agent/Agent.cpp +++ b/7zip/UI/Agent/Agent.cpp @@ -301,7 +301,7 @@ STDMETHODIMP CAgentFolder::GetPath(BSTR *path) UStringVector pathParts; pathParts.Clear(); CMyComPtr currentFolder = this; - while (true) + for (;;) { CMyComPtr newFolder; currentFolder->BindToParentFolder(&newFolder); @@ -445,7 +445,7 @@ STDMETHODIMP CAgent::Open( STDMETHODIMP CAgent::ReOpen( // const wchar_t *filePath, - IArchiveOpenCallback *openArchiveCallback) + IArchiveOpenCallback * /* openArchiveCallback */) { COM_TRY_BEGIN if (_proxyArchive != NULL) @@ -525,7 +525,7 @@ STDMETHODIMP CAgent::Extract( DefaultAttributes // ,_srcDirectoryPrefix ); - return GetArchive()->Extract(0, -1, testMode, extractCallback); + return GetArchive()->Extract(0, (UInt32)(Int32)-1, testMode, extractCallback); COM_TRY_END } diff --git a/7zip/UI/Agent/AgentOut.cpp b/7zip/UI/Agent/AgentOut.cpp index 3ce22077..25d65bb2 100755 --- a/7zip/UI/Agent/AgentOut.cpp +++ b/7zip/UI/Agent/AgentOut.cpp @@ -51,7 +51,7 @@ STDMETHODIMP CAgent::SetFolder(IFolderFolder *folder) pathParts.Clear(); CMyComPtr folderItem = folder; if (folderItem != NULL) - while (true) + for (;;) { CMyComPtr newFolder; folderItem->BindToParentFolder(&newFolder); @@ -111,7 +111,8 @@ static HRESULT EnumerateArchiveItems(CAgent *agent, CPropVariant property; agent->GetArchive()->GetProperty(fileItem.Index, kpidSize, &property); - if (archiveItem.SizeIsDefined = (property.vt != VT_EMPTY)) + archiveItem.SizeIsDefined = (property.vt != VT_EMPTY); + if (archiveItem.SizeIsDefined) archiveItem.Size = ConvertPropVariantToUInt64(property); archiveItem.IsDirectory = false; archiveItem.Name = prefix + fileItem.Name; @@ -207,8 +208,7 @@ STDMETHODIMP CAgent::DoOperation( GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs); CObjectVector updatePairs2; - UpdateProduce(dirItems, archiveItems, updatePairs, actionSet, - updatePairs2); + UpdateProduce(updatePairs, actionSet, updatePairs2); CUpdateCallbackAgent updateCallbackAgent; updateCallbackAgent.Callback = updateCallback100; diff --git a/7zip/UI/Agent/AgentProxy.cpp b/7zip/UI/Agent/AgentProxy.cpp index ce5737ee..757231c6 100755 --- a/7zip/UI/Agent/AgentProxy.cpp +++ b/7zip/UI/Agent/AgentProxy.cpp @@ -14,7 +14,7 @@ using namespace NWindows; int CProxyFolder::FindDirSubItemIndex(const UString &name, int &insertPos) const { int left = 0, right = Folders.Size(); - while(true) + for (;;) { if (left == right) { @@ -177,7 +177,7 @@ HRESULT CProxyArchive::ReadObjects(IInArchive *archiveHandler, IProgress *progre wchar_t c = filePath[i]; if (c == '\\' || c == '/') { - currentItem = currentItem->AddDirSubItem(-1, false, fileName); + currentItem = currentItem->AddDirSubItem((UInt32)(Int32)-1, false, fileName); fileName.Empty(); } else diff --git a/7zip/UI/Agent/ArchiveFolder.cpp b/7zip/UI/Agent/ArchiveFolder.cpp index 2cecbde5..0ce553dc 100755 --- a/7zip/UI/Agent/ArchiveFolder.cpp +++ b/7zip/UI/Agent/ArchiveFolder.cpp @@ -64,8 +64,8 @@ STDMETHODIMP CAgentFolder::CopyTo(const UINT32 *indices, UINT32 numItems, COM_TRY_END } -STDMETHODIMP CAgentFolder::MoveTo(const UINT32 *indices, UINT32 numItems, - const wchar_t *path, IFolderOperationsExtractCallback *callback) +STDMETHODIMP CAgentFolder::MoveTo(const UINT32 * /* indices */, UINT32 /* numItems */, + const wchar_t * /* path */, IFolderOperationsExtractCallback * /* callback */) { return E_NOTIMPL; } diff --git a/7zip/UI/Agent/ArchiveFolderOpen.cpp b/7zip/UI/Agent/ArchiveFolderOpen.cpp index 258e3b77..ce423941 100755 --- a/7zip/UI/Agent/ArchiveFolderOpen.cpp +++ b/7zip/UI/Agent/ArchiveFolderOpen.cpp @@ -91,7 +91,8 @@ STDMETHODIMP CArchiveFolderManager::GetIconPath(const wchar_t *type, BSTR *iconP return S_OK; } -STDMETHODIMP CArchiveFolderManager::CreateFolderFile(const wchar_t *type, const wchar_t *filePath, IProgress *progress) +STDMETHODIMP CArchiveFolderManager::CreateFolderFile(const wchar_t * /* type */, + const wchar_t * /* filePath */, IProgress * /* progress */) { return E_NOTIMPL; } diff --git a/7zip/UI/Agent/ArchiveFolderOut.cpp b/7zip/UI/Agent/ArchiveFolderOut.cpp index 9e2d3c55..4d66d86d 100755 --- a/7zip/UI/Agent/ArchiveFolderOut.cpp +++ b/7zip/UI/Agent/ArchiveFolderOut.cpp @@ -22,7 +22,7 @@ void CAgentFolder::GetPathParts(UStringVector &pathParts) { pathParts.Clear(); CMyComPtr folder = this; - while (true) + for (;;) { CMyComPtr newFolder; folder->BindToParentFolder(&newFolder); @@ -87,7 +87,7 @@ HRESULT CAgentFolder::CommonUpdateOperation( { Byte actionSetByte[NUpdateArchive::NPairState::kNumValues]; for (int i = 0; i < NUpdateArchive::NPairState::kNumValues; i++) - actionSetByte[i] = actionSet->StateActions[i]; + actionSetByte[i] = (Byte)actionSet->StateActions[i]; result = _agentSpec->DoOperation(NULL, NULL, tempFileName, actionSetByte, NULL, updateCallback100); } @@ -203,13 +203,13 @@ STDMETHODIMP CAgentFolder::Rename(UINT32 index, const wchar_t *newName, IProgres COM_TRY_END } -STDMETHODIMP CAgentFolder::CreateFile(const wchar_t *name, IProgress *progress) +STDMETHODIMP CAgentFolder::CreateFile(const wchar_t * /* name */, IProgress * /* progress */) { return E_NOTIMPL; } -STDMETHODIMP CAgentFolder::SetProperty(UINT32 index, PROPID propID, - const PROPVARIANT *value, IProgress *progress) +STDMETHODIMP CAgentFolder::SetProperty(UINT32 /* index */, PROPID /* propID */, + const PROPVARIANT * /* value */, IProgress * /* progress */) { return E_NOTIMPL; } diff --git a/7zip/UI/Agent/UpdateCallbackAgent.cpp b/7zip/UI/Agent/UpdateCallbackAgent.cpp index b12280d5..0d57307c 100755 --- a/7zip/UI/Agent/UpdateCallbackAgent.cpp +++ b/7zip/UI/Agent/UpdateCallbackAgent.cpp @@ -50,7 +50,7 @@ HRESULT CUpdateCallbackAgent::OpenFileError(const wchar_t *name, DWORD systemErr return systemError; } -HRESULT CUpdateCallbackAgent::GetStream(const wchar_t *name, bool isAnti) +HRESULT CUpdateCallbackAgent::GetStream(const wchar_t *name, bool /* isAnti */) { if (Callback) return Callback->CompressOperation(name); diff --git a/7zip/UI/Client7z/Client7z.cpp b/7zip/UI/Client7z/Client7z.cpp index 90d6cfd3..46bdb727 100755 --- a/7zip/UI/Client7z/Client7z.cpp +++ b/7zip/UI/Client7z/Client7z.cpp @@ -5,68 +5,846 @@ #include #include "Common/StringConvert.h" +#include "Common/IntToString.h" #include "../../Common/FileStreams.h" #include "../../Archive/IArchive.h" +#include "../../IPassword.h" + #include "Windows/PropVariant.h" #include "Windows/PropVariantConversions.h" #include "Windows/DLL.h" +#include "Windows/FileDir.h" +#include "Windows/FileName.h" +#include "Windows/FileFind.h" // {23170F69-40C1-278A-1000-000110070000} DEFINE_GUID(CLSID_CFormat7z, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00); +using namespace NWindows; + +static const char *kCopyrightString = "7-Zip 4.43 (7za.DLL client example) (c) 1999-2006 Igor Pavlov 2006-08-10\n"; +static const char *kHelpString = +"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\n" +"Examples:\n" +" Client7z.exe a archive.7z f1.txt f2.txt : compress two files to archive.7z\n" +" Client7z.exe l archive.7z : List contents of archive.7z\n" +" Client7z.exe x archive.7z : eXtract files from archive.7z\n"; + + typedef UINT32 (WINAPI * CreateObjectFunc)( const GUID *clsID, const GUID *interfaceID, void **outObject); -int main(int argc, char* argv[]) +#ifndef _UNICODE +bool g_IsNT = false; +static inline bool IsItWindowsNT() +{ + OSVERSIONINFO versionInfo; + versionInfo.dwOSVersionInfoSize = sizeof(versionInfo); + if (!::GetVersionEx(&versionInfo)) + return false; + return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); +} +#endif + +void PrintString(const UString &s) +{ + printf("%s", (LPCSTR)GetOemString(s)); +} + +void PrintString(const AString &s) +{ + printf("%s", s); +} + +void PrintNewLine() +{ + PrintString("\n"); +} + +void PrintStringLn(const AString &s) +{ + PrintString(s); + PrintNewLine(); +} + +static HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result) +{ + NCOM::CPropVariant prop; + RINOK(archive->GetProperty(index, propID, &prop)); + if(prop.vt == VT_BOOL) + result = VARIANT_BOOLToBool(prop.boolVal); + else if (prop.vt == VT_EMPTY) + result = false; + else + return E_FAIL; + return S_OK; +} + +static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result) +{ + return IsArchiveItemProp(archive, index, kpidIsFolder, result); +} + + +static const wchar_t *kEmptyFileAlias = L"[Content]"; + + +////////////////////////////////////////////////////////////// +// Archive Open callback class + + +class CArchiveOpenCallback: + public IArchiveOpenCallback, + public ICryptoGetTextPassword, + public CMyUnknownImp +{ +public: + MY_UNKNOWN_IMP1(ICryptoGetTextPassword) + + STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes); + STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes); + + STDMETHOD(CryptoGetTextPassword)(BSTR *password); + + bool PasswordIsDefined; + UString Password; + + CArchiveOpenCallback() : PasswordIsDefined(false) {} +}; + +STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 *files, const UInt64 *bytes) +{ + return S_OK; +} + +STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 *files, const UInt64 *bytes) +{ + return S_OK; +} + +STDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password) +{ + if (!PasswordIsDefined) + { + // You can ask real password here from user + // Password = GetPassword(OutStream); + // PasswordIsDefined = true; + PrintStringLn("Password is not defined"); + return E_ABORT; + } + CMyComBSTR tempName(Password); + *password = tempName.Detach(); + return S_OK; +} + + +////////////////////////////////////////////////////////////// +// Archive Extracting callback class + +static const wchar_t *kCantDeleteOutputFile = L"ERROR: Can not delete output file "; + +static const char *kTestingString = "Testing "; +static const char *kExtractingString = "Extracting "; +static const char *kSkippingString = "Skipping "; + +static const char *kUnsupportedMethod = "Unsupported Method"; +static const char *kCRCFailed = "CRC Failed"; +static const char *kDataError = "Data Error"; +static const char *kUnknownError = "Unknown Error"; + +class CArchiveExtractCallback: + public IArchiveExtractCallback, + public ICryptoGetTextPassword, + public CMyUnknownImp +{ +public: + MY_UNKNOWN_IMP1(ICryptoGetTextPassword) + + // IProgress + STDMETHOD(SetTotal)(UInt64 size); + STDMETHOD(SetCompleted)(const UInt64 *completeValue); + + // IArchiveExtractCallback + STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode); + STDMETHOD(PrepareOperation)(Int32 askExtractMode); + STDMETHOD(SetOperationResult)(Int32 resultEOperationResult); + + // ICryptoGetTextPassword + STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword); + +private: + CMyComPtr _archiveHandler; + UString _directoryPath; // Output directory + UString _filePath; // name inside arcvhive + UString _diskFilePath; // full path to file on disk + bool _extractMode; + struct CProcessedFileInfo + { + FILETIME UTCLastWriteTime; + UInt32 Attributes; + bool IsDirectory; + bool AttributesAreDefined; + bool UTCLastWriteTimeIsDefined; + } _processedFileInfo; + + COutFileStream *_outFileStreamSpec; + CMyComPtr _outFileStream; + +public: + void Init(IInArchive *archiveHandler, const UString &directoryPath); + + UInt64 NumErrors; + bool PasswordIsDefined; + UString Password; + + CArchiveExtractCallback() : PasswordIsDefined(false) {} +}; + +void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath) +{ + NumErrors = 0; + _archiveHandler = archiveHandler; + _directoryPath = directoryPath; + NFile::NName::NormalizeDirPathPrefix(_directoryPath); +} + +STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size) +{ + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue) +{ + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, + ISequentialOutStream **outStream, Int32 askExtractMode) +{ + *outStream = 0; + _outFileStream.Release(); + + { + // Get Name + NCOM::CPropVariant propVariant; + RINOK(_archiveHandler->GetProperty(index, kpidPath, &propVariant)); + + UString fullPath; + if(propVariant.vt == VT_EMPTY) + fullPath = kEmptyFileAlias; + else + { + if(propVariant.vt != VT_BSTR) + return E_FAIL; + fullPath = propVariant.bstrVal; + } + _filePath = fullPath; + } + + { + // Get Attributes + NCOM::CPropVariant propVariant; + RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &propVariant)); + if (propVariant.vt == VT_EMPTY) + { + _processedFileInfo.Attributes = 0; + _processedFileInfo.AttributesAreDefined = false; + } + else + { + if (propVariant.vt != VT_UI4) + throw "incorrect item"; + _processedFileInfo.Attributes = propVariant.ulVal; + _processedFileInfo.AttributesAreDefined = true; + } + } + + RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory)); + + { + // Get Modified Time + NCOM::CPropVariant propVariant; + RINOK(_archiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant)); + _processedFileInfo.UTCLastWriteTimeIsDefined = false; + switch(propVariant.vt) + { + case VT_EMPTY: + // _processedFileInfo.UTCLastWriteTime = _utcLastWriteTimeDefault; + break; + case VT_FILETIME: + _processedFileInfo.UTCLastWriteTime = propVariant.filetime; + _processedFileInfo.UTCLastWriteTimeIsDefined = true; + break; + default: + return E_FAIL; + } + + } + { + // Get Size + NCOM::CPropVariant propVariant; + RINOK(_archiveHandler->GetProperty(index, kpidSize, &propVariant)); + bool newFileSizeDefined = (propVariant.vt != VT_EMPTY); + UInt64 newFileSize; + if (newFileSizeDefined) + newFileSize = ConvertPropVariantToUInt64(propVariant); + } + + + { + // Create folders for file + int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR); + if (slashPos >= 0) + NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos)); + } + + UString fullProcessedPath = _directoryPath + _filePath; + _diskFilePath = fullProcessedPath; + + if (_processedFileInfo.IsDirectory) + { + NFile::NDirectory::CreateComplexDirectory(fullProcessedPath); + } + else + { + NFile::NFind::CFileInfoW fileInfo; + if(NFile::NFind::FindFile(fullProcessedPath, fileInfo)) + { + if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath)) + { + PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath); + return E_ABORT; + } + } + + _outFileStreamSpec = new COutFileStream; + CMyComPtr outStreamLoc(_outFileStreamSpec); + if (!_outFileStreamSpec->File.Open(fullProcessedPath, CREATE_ALWAYS)) + { + PrintString((UString)L"can not open output file " + fullProcessedPath); + return E_ABORT; + } + _outFileStream = outStreamLoc; + *outStream = outStreamLoc.Detach(); + } + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode) +{ + _extractMode = false; + switch (askExtractMode) + { + case NArchive::NExtract::NAskMode::kExtract: + _extractMode = true; + }; + switch (askExtractMode) + { + case NArchive::NExtract::NAskMode::kExtract: + PrintString(kExtractingString); + break; + case NArchive::NExtract::NAskMode::kTest: + PrintString(kTestingString); + break; + case NArchive::NExtract::NAskMode::kSkip: + PrintString(kSkippingString); + break; + }; + PrintString(_filePath); + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult) +{ + switch(operationResult) + { + case NArchive::NExtract::NOperationResult::kOK: + break; + default: + { + NumErrors++; + PrintString(" "); + switch(operationResult) + { + case NArchive::NExtract::NOperationResult::kUnSupportedMethod: + PrintString(kUnsupportedMethod); + break; + case NArchive::NExtract::NOperationResult::kCRCError: + PrintString(kCRCFailed); + break; + case NArchive::NExtract::NOperationResult::kDataError: + PrintString(kDataError); + break; + default: + PrintString(kUnknownError); + } + } + } + + if(_outFileStream != NULL && _processedFileInfo.UTCLastWriteTimeIsDefined) + _outFileStreamSpec->File.SetLastWriteTime(&_processedFileInfo.UTCLastWriteTime); + _outFileStream.Release(); + if (_extractMode && _processedFileInfo.AttributesAreDefined) + NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes); + PrintNewLine(); + return S_OK; +} + + +STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password) +{ + if (!PasswordIsDefined) + { + // You can ask real password here from user + // Password = GetPassword(OutStream); + // PasswordIsDefined = true; + PrintStringLn("Password is not defined"); + return E_ABORT; + } + CMyComBSTR tempName(Password); + *password = tempName.Detach(); + return S_OK; +} + + + +////////////////////////////////////////////////////////////// +// Archive Creating callback class + +struct CDirItem +{ + UInt32 Attributes; + FILETIME CreationTime; + FILETIME LastAccessTime; + FILETIME LastWriteTime; + UInt64 Size; + UString Name; + UString FullPath; + bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 ; } +}; + +class CArchiveUpdateCallback: + public IArchiveUpdateCallback2, + public ICryptoGetTextPassword2, + public CMyUnknownImp +{ +public: + MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2) + + // IProgress + STDMETHOD(SetTotal)(UInt64 size); + STDMETHOD(SetCompleted)(const UInt64 *completeValue); + + // IUpdateCallback2 + STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator); + STDMETHOD(GetUpdateItemInfo)(UInt32 index, + Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive); + STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value); + STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream); + STDMETHOD(SetOperationResult)(Int32 operationResult); + STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size); + STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream); + + STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password); + +public: + CRecordVector VolumesSizes; + UString VolName; + UString VolExt; + + UString DirPrefix; + const CObjectVector *DirItems; + + bool PasswordIsDefined; + UString Password; + bool AskPassword; + + bool m_NeedBeClosed; + + UStringVector FailedFiles; + CRecordVector FailedCodes; + + CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {}; + + ~CArchiveUpdateCallback() { Finilize(); } + HRESULT Finilize(); + + void Init(const CObjectVector *dirItems) + { + DirItems = dirItems; + m_NeedBeClosed = false; + FailedFiles.Clear(); + FailedCodes.Clear(); + } +}; + +STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size) +{ + return S_OK; +} + +STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue) +{ + return S_OK; +} + + +STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **enumerator) +{ + return E_NOTIMPL; +} + +STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, + Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive) +{ + if(newData != NULL) + *newData = BoolToInt(true); + if(newProperties != NULL) + *newProperties = BoolToInt(true); + if(indexInArchive != NULL) + *indexInArchive = UInt32(-1); + return S_OK; +} + +STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) +{ + NWindows::NCOM::CPropVariant propVariant; + + if (propID == kpidIsAnti) + { + propVariant = false; + propVariant.Detach(value); + return S_OK; + } + + { + const CDirItem &dirItem = (*DirItems)[index]; + switch(propID) + { + case kpidPath: + propVariant = dirItem.Name; + break; + case kpidIsFolder: + propVariant = dirItem.IsDirectory(); + break; + case kpidSize: + propVariant = dirItem.Size; + break; + case kpidAttributes: + propVariant = dirItem.Attributes; + break; + case kpidLastAccessTime: + propVariant = dirItem.LastAccessTime; + break; + case kpidCreationTime: + propVariant = dirItem.CreationTime; + break; + case kpidLastWriteTime: + propVariant = dirItem.LastWriteTime; + break; + } + } + propVariant.Detach(value); + return S_OK; +} + +HRESULT CArchiveUpdateCallback::Finilize() { - if (argc != 2) + if (m_NeedBeClosed) { - printf("Use Client7z.exe file.7z"); + PrintNewLine(); + m_NeedBeClosed = false; + } + return S_OK; +} + +static void GetStream2(const wchar_t *name) +{ + PrintString("Compressing "); + if (name[0] == 0) + name = kEmptyFileAlias; + PrintString(name); +} + +STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream) +{ + RINOK(Finilize()); + + const CDirItem &dirItem = (*DirItems)[index]; + GetStream2(dirItem.Name); + + if(dirItem.IsDirectory()) + return S_OK; + + { + CInFileStream *inStreamSpec = new CInFileStream; + CMyComPtr inStreamLoc(inStreamSpec); + UString path = DirPrefix + dirItem.FullPath; + if(!inStreamSpec->Open(path)) + { + DWORD sysError = ::GetLastError(); + FailedCodes.Add(sysError); + FailedFiles.Add(path); + // if (systemError == ERROR_SHARING_VIOLATION) + { + PrintNewLine(); + PrintStringLn("WARNING: can't open file"); + // PrintString(NError::MyFormatMessageW(systemError)); + return S_FALSE; + } + // return sysError; + } + *inStream = inStreamLoc.Detach(); + } + return S_OK; +} + +STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult) +{ + m_NeedBeClosed = true; + return S_OK; +} + +STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size) +{ + if (VolumesSizes.Size() == 0) + return S_FALSE; + if (index >= (UInt32)VolumesSizes.Size()) + index = VolumesSizes.Size() - 1; + *size = VolumesSizes[index]; + return S_OK; +} + +STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream) +{ + wchar_t temp[32]; + ConvertUInt64ToString(index + 1, temp); + UString res = temp; + while (res.Length() < 2) + res = UString(L'0') + res; + UString fileName = VolName; + fileName += L'.'; + fileName += res; + fileName += VolExt; + COutFileStream *streamSpec = new COutFileStream; + CMyComPtr streamLoc(streamSpec); + if(!streamSpec->Create(fileName, false)) + return ::GetLastError(); + *volumeStream = streamLoc.Detach(); + return S_OK; +} + +STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) +{ + if (!PasswordIsDefined) + { + if (AskPassword) + { + // You can ask real password here from user + // Password = GetPassword(OutStream); + // PasswordIsDefined = true; + PrintStringLn("Password is not defined"); + return E_ABORT; + } + } + *passwordIsDefined = BoolToInt(PasswordIsDefined); + CMyComBSTR tempName(Password); + *password = tempName.Detach(); + return S_OK; +} + + + +////////////////////////////////////////////////////////////////////////// +// Main function + +int +#ifdef _MSC_VER +__cdecl +#endif +main(int argc, char* argv[]) +{ + #ifndef _UNICODE + g_IsNT = IsItWindowsNT(); + #endif + + PrintStringLn(kCopyrightString); + + if (argc < 3) + { + PrintStringLn(kHelpString); return 1; } NWindows::NDLL::CLibrary library; - if (!library.Load("7za.dll")) + if (!library.Load(TEXT("7za.dll"))) { - printf("Can not load library"); + PrintStringLn("Can not load library"); return 1; } - CreateObjectFunc - createObjectFunc = - (CreateObjectFunc)library.GetProcAddress("CreateObject"); + CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress("CreateObject"); if (createObjectFunc == 0) { - printf("Can not get CreateObject"); + PrintStringLn("Can not get CreateObject"); return 1; } - CMyComPtr archive; - if (createObjectFunc(&CLSID_CFormat7z, - &IID_IInArchive, (void **)&archive) != S_OK) + + AString command = argv[1]; + UString archiveName = GetUnicodeString(argv[2], CP_OEMCP); + if (command.CompareNoCase("a") == 0) { - printf("Can not get class object"); - return 1; - } + // create archive command + if (argc < 4) + { + PrintStringLn(kHelpString); + return 1; + } + CObjectVector dirItems; + int i; + for (i = 3; i < argc; i++) + { + CDirItem item; + UString name = GetUnicodeString(argv[i], CP_OEMCP); + + NFile::NFind::CFileInfoW fileInfo; + if (!NFile::NFind::FindFile(name, fileInfo)) + { + PrintString(UString(L"Can't find file") + name); + return 1; + } - CInFileStream *fileSpec = new CInFileStream; - CMyComPtr file = fileSpec; + item.Attributes = fileInfo.Attributes; + item.Size = fileInfo.Size; + item.CreationTime = fileInfo.CreationTime; + item.LastAccessTime = fileInfo.LastAccessTime; + item.LastWriteTime = fileInfo.LastWriteTime; + item.Name = name; + item.FullPath = name; + dirItems.Add(item); + } + COutFileStream *outFileStreamSpec = new COutFileStream; + CMyComPtr outFileStream = outFileStreamSpec; + if (!outFileStreamSpec->Create(archiveName, false)) + { + PrintStringLn("can't create archive file"); + return 1; + } - if (!fileSpec->Open(argv[1])) - { - printf("Can not open"); - return 1; + CMyComPtr outArchive; + if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK) + { + PrintStringLn("Can not get class object"); + return 1; + } + + CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; + CMyComPtr updateCallback(updateCallbackSpec); + updateCallbackSpec->Init(&dirItems); + // updateCallbackSpec->PasswordIsDefined = true; + // updateCallbackSpec->Password = L"1"; + + HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback); + updateCallbackSpec->Finilize(); + if (result != S_OK) + { + PrintStringLn("Update Error"); + return 1; + } + for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++) + { + PrintNewLine(); + PrintString((UString)L"Error for file: " + updateCallbackSpec->FailedFiles[i]); + } + if (updateCallbackSpec->FailedFiles.Size() != 0) + return 1; } - if (archive->Open(file, 0, 0) != S_OK) - return 0; - UInt32 numItems = 0; - archive->GetNumberOfItems(&numItems); - for (UInt32 i = 0; i < numItems; i++) + else { - NWindows::NCOM::CPropVariant propVariant; - archive->GetProperty(i, kpidPath, &propVariant); - UString s = ConvertPropVariantToString(propVariant); - printf("%s\n", (LPCSTR)GetOemString(s)); + if (argc != 3) + { + PrintStringLn(kHelpString); + return 1; + } + + bool listCommand; + if (command.CompareNoCase("l") == 0) + listCommand = true; + else if (command.CompareNoCase("x") == 0) + listCommand = false; + else + { + PrintStringLn("incorrect command"); + return 1; + } + + CMyComPtr archive; + if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK) + { + PrintStringLn("Can not get class object"); + return 1; + } + + CInFileStream *fileSpec = new CInFileStream; + CMyComPtr file = fileSpec; + + if (!fileSpec->Open(archiveName)) + { + PrintStringLn("Can not open archive file"); + return 1; + } + + { + CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback; + CMyComPtr openCallback(openCallbackSpec); + openCallbackSpec->PasswordIsDefined = false; + // openCallbackSpec->PasswordIsDefined = true; + // openCallbackSpec->Password = L"1"; + + if (archive->Open(file, 0, openCallback) != S_OK) + { + PrintStringLn("Can not open archive"); + return 1; + } + } + + if (listCommand) + { + // List command + UInt32 numItems = 0; + archive->GetNumberOfItems(&numItems); + for (UInt32 i = 0; i < numItems; i++) + { + { + // Get uncompressed size of file + NWindows::NCOM::CPropVariant propVariant; + archive->GetProperty(i, kpidSize, &propVariant); + UString s = ConvertPropVariantToString(propVariant); + PrintString(s); + PrintString(" "); + } + { + // Get name of file + NWindows::NCOM::CPropVariant propVariant; + archive->GetProperty(i, kpidPath, &propVariant); + UString s = ConvertPropVariantToString(propVariant); + PrintString(s); + } + PrintString("\n"); + } + } + else + { + // Extract command + CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback; + CMyComPtr extractCallback(extractCallbackSpec); + extractCallbackSpec->Init(archive, L""); // second parameter is output folder path + extractCallbackSpec->PasswordIsDefined = false; + // extractCallbackSpec->PasswordIsDefined = true; + // extractCallbackSpec->Password = L"1"; + archive->Extract(0, (UInt32)(Int32)(-1), false, extractCallback); + } } return 0; } diff --git a/7zip/UI/Client7z/Client7z.dsp b/7zip/UI/Client7z/Client7z.dsp index fb957bf8..b574bdb7 100755 --- a/7zip/UI/Client7z/Client7z.dsp +++ b/7zip/UI/Client7z/Client7z.dsp @@ -107,6 +107,22 @@ SOURCE=..\..\..\Windows\DLL.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\FileDir.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileDir.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileFind.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileFind.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\FileIO.cpp # End Source File # Begin Source File @@ -115,6 +131,14 @@ SOURCE=..\..\..\Windows\FileIO.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\FileName.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\FileName.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\PropVariant.cpp # End Source File # Begin Source File @@ -143,6 +167,14 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\NewHandler.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\String.cpp # End Source File # Begin Source File @@ -157,6 +189,22 @@ SOURCE=..\..\..\Common\StringConvert.cpp SOURCE=..\..\..\Common\StringConvert.h # End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Vector.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Vector.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Wildcard.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Wildcard.h +# End Source File # End Group # Begin Group "7zip Common" diff --git a/7zip/UI/Client7z/makefile b/7zip/UI/Client7z/makefile new file mode 100755 index 00000000..c4ae0aaf --- /dev/null +++ b/7zip/UI/Client7z/makefile @@ -0,0 +1,45 @@ +PROG = 7z.exe +LIBS = $(LIBS) user32.lib oleaut32.lib advapi32.lib +CFLAGS = $(CFLAGS) -I ../../../ -DCOMPRESS_MT + +CONSOLE_OBJS = \ + $O\Client7z.obj \ + +COMMON_OBJS = \ + $O\IntToString.obj \ + $O\NewHandler.obj \ + $O\String.obj \ + $O\StringConvert.obj \ + $O\StringToInt.obj \ + $O\Vector.obj \ + $O\Wildcard.obj \ + +WIN_OBJS = \ + $O\DLL.obj \ + $O\FileDir.obj \ + $O\FileFind.obj \ + $O\FileIO.obj \ + $O\FileName.obj \ + $O\PropVariant.obj \ + $O\PropVariantConversions.obj \ + +7ZIP_COMMON_OBJS = \ + $O\FileStreams.obj \ + +OBJS = \ + $O\StdAfx.obj \ + $(CONSOLE_OBJS) \ + $(COMMON_OBJS) \ + $(WIN_OBJS) \ + $(7ZIP_COMMON_OBJS) \ + +!include "../../../Build.mak" + +$(CONSOLE_OBJS): $(*B).cpp + $(COMPL_O1_W3) +$(COMMON_OBJS): ../../../Common/$(*B).cpp + $(COMPL) +$(WIN_OBJS): ../../../Windows/$(*B).cpp + $(COMPL) +$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp + $(COMPL) diff --git a/7zip/UI/Common/ArchiveCommandLine.cpp b/7zip/UI/Common/ArchiveCommandLine.cpp index d8aa90ca..f56f982c 100755 --- a/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/7zip/UI/Common/ArchiveCommandLine.cpp @@ -160,6 +160,16 @@ static const char *kIncorrectWildCardInListFile = "Incorrect wildcard in listfil static const char *kIncorrectWildCardInCommandLine = "Incorrect wildcard in command line"; static const char *kTerminalOutError = "I won't write compressed data to a terminal"; +static void ThrowException(const char *errorMessage) +{ + throw CArchiveCommandLineException(errorMessage); +}; + +static void ThrowUserErrorException() +{ + ThrowException(kUserErrorMessage); +}; + // --------------------------- bool CArchiveCommand::IsFromExtractGroup() const @@ -227,7 +237,7 @@ static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor, const UString &name, bool include, NRecursedType::EEnum type) { bool isWildCard = DoesNameContainWildCard(name); - bool recursed; + bool recursed = false; switch (type) { @@ -290,13 +300,13 @@ static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, { int splitPos = switchParam.Find(L':'); if (splitPos < 0) - throw kUserErrorMessage; + ThrowUserErrorException(); UString mappingName = switchParam.Left(splitPos); UString switchParam2 = switchParam.Mid(splitPos + 1); splitPos = switchParam2.Find(L':'); if (splitPos < 0) - throw kUserErrorMessage; + ThrowUserErrorException(); UString mappingSize = switchParam2.Left(splitPos); UString eventName = switchParam2.Mid(splitPos + 1); @@ -306,15 +316,15 @@ static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, { CFileMapping fileMapping; if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName))) - throw L"Can not open mapping"; + ThrowException("Can not open mapping"); LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize); if (data == NULL) - throw L"MapViewOfFile error"; + ThrowException("MapViewOfFile error"); try { const wchar_t *curData = (const wchar_t *)data; if (*curData != 0) - throw L"Incorrect mapping data"; + ThrowException("Incorrect mapping data"); UInt32 numChars = dataSize / sizeof(wchar_t); UString name; for (UInt32 i = 1; i < numChars; i++) @@ -330,7 +340,7 @@ static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor, name += c; } if (!name.IsEmpty()) - throw L"data error"; + ThrowException("data error"); } catch(...) { @@ -358,7 +368,7 @@ static void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, NRecursedType::EEnum recursedType; int pos = 0; if (name.Length() < kSomeCludePostStringMinSize) - throw kUserErrorMessage; + ThrowUserErrorException(); if (::MyCharUpper(name[pos]) == kRecursedIDChar) { pos++; @@ -370,7 +380,7 @@ static void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, else recursedType = commonRecursedType; if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize) - throw kUserErrorMessage; + ThrowUserErrorException(); UString tail = name.Mid(pos + 1); if (name[pos] == kImmediateNameID) AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType); @@ -381,7 +391,7 @@ static void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor, ParseMapWithPaths(wildcardCensor, tail, include, recursedType); #endif else - throw kUserErrorMessage; + ThrowUserErrorException(); } } @@ -520,7 +530,7 @@ static void ParseUpdateCommandString(CUpdateOptions &options, UString postString; if (!ParseUpdateCommandString2(updateString, actionSet, postString)) - throw kUserErrorMessage; + ThrowUserErrorException(); if(postString.IsEmpty()) { if(options.UpdateArchiveItself) @@ -529,11 +539,11 @@ static void ParseUpdateCommandString(CUpdateOptions &options, else { if(MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID) - throw kUserErrorMessage; + ThrowUserErrorException(); CUpdateArchiveCommand uc; UString archivePath = postString.Mid(1); if (archivePath.IsEmpty()) - throw kUserErrorMessage; + ThrowUserErrorException(); uc.ArchivePath.BaseExtension = options.ArchivePath.BaseExtension; uc.ArchivePath.VolExtension = options.ArchivePath.VolExtension; uc.ArchivePath.ParseFromPath(archivePath); @@ -624,7 +634,8 @@ static void SetAddCommandOptions( else options.WorkingDir = postString; } - if(options.SfxMode = parser[NKey::kSfx].ThereIs) + options.SfxMode = parser[NKey::kSfx].ThereIs; + if (options.SfxMode) options.SfxModule = parser[NKey::kSfx].PostStrings[0]; if (parser[NKey::kVolume].ThereIs) @@ -634,7 +645,7 @@ static void SetAddCommandOptions( { UInt64 size; if (!ParseComplexSize(sv[i], size)) - throw "incorrect volume size"; + ThrowException("Incorrect volume size"); options.VolumesSizes.Add(size); } } @@ -674,9 +685,9 @@ static void SetArchiveType(const UString &archiveType, CObjectVector archiverInfoVector; ReadArchiverInfoList(archiverInfoVector); if (archiverInfoVector.Size() == 0) - throw "There are no installed archive handlers"; + ThrowException("There are no installed archive handlers"); if (archiveType.IsEmpty()) - throw "Incorrect archive type was assigned"; + ThrowException("Incorrect archive type was assigned"); for (int i = 0; i < archiverInfoVector.Size(); i++) { const CArchiverInfo &archiverInfo = archiverInfoVector[i]; @@ -694,7 +705,7 @@ static void SetArchiveType(const UString &archiveType, return; } } - throw "Incorrect archive type was assigned"; + ThrowException("Incorrect archive type was assigned"); } @@ -709,12 +720,12 @@ void CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings, } catch(...) { - throw kUserErrorMessage; + ThrowUserErrorException(); } - options.IsInTerminal = (isatty(fileno(stdin)) != 0); - options.IsStdOutTerminal = (isatty(fileno(stdout)) != 0); - options.IsStdErrTerminal = (isatty(fileno(stderr)) != 0); + options.IsInTerminal = (_isatty(_fileno(stdin)) != 0); + options.IsStdOutTerminal = (_isatty(_fileno(stdout)) != 0); + options.IsStdErrTerminal = (_isatty(_fileno(stderr)) != 0); options.StdOutMode = parser[NKey::kStdOut].ThereIs; options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs; options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs || parser[NKey::kHelp3].ThereIs; @@ -750,10 +761,10 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) const UStringVector &nonSwitchStrings = parser.NonSwitchStrings; int numNonSwitchStrings = nonSwitchStrings.Size(); if(numNonSwitchStrings < kMinNonSwitchWords) - throw kUserErrorMessage; + ThrowUserErrorException(); if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command)) - throw kUserErrorMessage; + ThrowUserErrorException(); options.TechMode = parser[NKey::kTechMode].ThereIs; @@ -779,7 +790,7 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) } } if (i >= kNumCodePages) - throw kUserErrorMessage; + ThrowUserErrorException(); } bool thereAreSwitchIncludes = false; @@ -798,7 +809,7 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) if (thereIsArchiveName) { if(curCommandIndex >= numNonSwitchStrings) - throw kUserErrorMessage; + ThrowUserErrorException(); options.ArchiveName = nonSwitchStrings[curCommandIndex++]; } @@ -821,9 +832,9 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) if(isExtractGroupCommand || options.Command.CommandType == NCommandType::kList) { if (options.StdInMode) - throw "reading archives from stdin is not implemented"; + ThrowException("Reading archives from stdin is not implemented"); if (!options.WildcardCensor.AllAreRelative()) - throw "cannot use absolute pathnames for this command"; + ThrowException("Cannot use absolute pathnames for this command"); NWildcard::CCensor archiveWildcardCensor; @@ -941,7 +952,8 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) options.EnablePercents = false; } - if (updateOptions.EMailMode = parser[NKey::kEmail].ThereIs) + updateOptions.EMailMode = parser[NKey::kEmail].ThereIs; + if (updateOptions.EMailMode) { updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front(); if (updateOptions.EMailAddress.Length() > 0) @@ -967,6 +979,6 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options) #endif } else - throw kUserErrorMessage; + ThrowUserErrorException(); options.WildcardCensor.ExtendExclude(); } diff --git a/7zip/UI/Common/ArchiveCommandLine.h b/7zip/UI/Common/ArchiveCommandLine.h index 5392218e..daa66fb6 100755 --- a/7zip/UI/Common/ArchiveCommandLine.h +++ b/7zip/UI/Common/ArchiveCommandLine.h @@ -9,6 +9,11 @@ #include "Extract.h" #include "Update.h" +struct CArchiveCommandLineException: public AString +{ + CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {} +}; + namespace NCommandType { enum EEnum { kAdd = 0, diff --git a/7zip/UI/Common/ArchiveExtractCallback.cpp b/7zip/UI/Common/ArchiveExtractCallback.cpp index 739a03b5..48f7bb67 100755 --- a/7zip/UI/Common/ArchiveExtractCallback.cpp +++ b/7zip/UI/Common/ArchiveExtractCallback.cpp @@ -6,6 +6,7 @@ #include "Common/Wildcard.h" #include "Common/StringConvert.h" +#include "Common/ComTry.h" #include "Windows/FileDir.h" #include "Windows/FileFind.h" @@ -55,22 +56,27 @@ void CArchiveExtractCallback::Init( STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size) { + COM_TRY_BEGIN return _extractCallback2->SetTotal(size); + COM_TRY_END } STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue) { + COM_TRY_BEGIN return _extractCallback2->SetCompleted(completeValue); + COM_TRY_END } -void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts) +void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath) { - UString fullPath = _directoryPath; + fullPath = _directoryPath; for(int i = 0; i < dirPathParts.Size(); i++) { + if (i > 0) + fullPath += wchar_t(NFile::NName::kDirDelimiter); fullPath += dirPathParts[i]; NFile::NDirectory::MyCreateDirectory(fullPath); - fullPath += wchar_t(NFile::NName::kDirDelimiter); } } @@ -87,35 +93,67 @@ static UString MakePathNameFromParts(const UStringVector &parts) } -STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, - ISequentialOutStream **outStream, Int32 askExtractMode) +HRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined) { + filetimeIsDefined = false; + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, propID, &prop)); + if (prop.vt == VT_FILETIME) + { + filetime = prop.filetime; + filetimeIsDefined = true; + } + else if (prop.vt != VT_EMPTY) + return E_FAIL; + return S_OK; +} + +STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) +{ + COM_TRY_BEGIN *outStream = 0; _outFileStream.Release(); - NCOM::CPropVariant propVariant; - RINOK(_archiveHandler->GetProperty(index, kpidPath, &propVariant)); - + + _encrypted = false; + _isSplit = false; + UString fullPath; - if(propVariant.vt == VT_EMPTY) - fullPath = _itemDefaultName; - else { - if(propVariant.vt != VT_BSTR) - return E_FAIL; - fullPath = propVariant.bstrVal; + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop)); + + if(prop.vt == VT_EMPTY) + fullPath = _itemDefaultName; + else + { + if(prop.vt != VT_BSTR) + return E_FAIL; + fullPath = prop.bstrVal; + } } // UString fullPathCorrect = GetCorrectPath(fullPath); _filePath = fullPath; - _isSplit = false; - RINOK(_archiveHandler->GetProperty(index, kpidPosition, &propVariant)); - if (propVariant.vt != VT_EMPTY) { - if (propVariant.vt != VT_UI8) + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidPosition, &prop)); + if (prop.vt != VT_EMPTY) + { + if (prop.vt != VT_UI8) + return E_FAIL; + _position = prop.uhVal.QuadPart; + _isSplit = true; + } + } + + { + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidEncrypted, &prop)); + if (prop.vt == VT_BOOL) + _encrypted = VARIANT_BOOLToBool(prop.boolVal); + else if (prop.vt != VT_EMPTY) return E_FAIL; - _position = propVariant.uhVal.QuadPart; - _isSplit = true; } if(askExtractMode == NArchive::NExtract::NAskMode::kExtract) @@ -127,48 +165,48 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, return S_OK; } - RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &propVariant)); - if (propVariant.vt == VT_EMPTY) - { - _processedFileInfo.Attributes = _attributesDefault; - _processedFileInfo.AttributesAreDefined = false; - } - else { - if (propVariant.vt != VT_UI4) - throw "incorrect item"; - _processedFileInfo.Attributes = propVariant.ulVal; - _processedFileInfo.AttributesAreDefined = true; + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidAttributes, &prop)); + if (prop.vt == VT_EMPTY) + { + _processedFileInfo.Attributes = _attributesDefault; + _processedFileInfo.AttributesAreDefined = false; + } + else + { + if (prop.vt != VT_UI4) + throw "incorrect item"; + _processedFileInfo.Attributes = prop.ulVal; + _processedFileInfo.AttributesAreDefined = true; + } } RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.IsDirectory)); - RINOK(_archiveHandler->GetProperty(index, kpidLastWriteTime, &propVariant)); - switch(propVariant.vt) - { - case VT_EMPTY: - _processedFileInfo.UTCLastWriteTime = _utcLastWriteTimeDefault; - break; - case VT_FILETIME: - _processedFileInfo.UTCLastWriteTime = propVariant.filetime; - break; - default: - return E_FAIL; - } + RINOK(GetTime(index, kpidCreationTime, _processedFileInfo.CreationTime, + _processedFileInfo.IsCreationTimeDefined)); + RINOK(GetTime(index, kpidLastWriteTime, _processedFileInfo.LastWriteTime, + _processedFileInfo.IsLastWriteTimeDefined)); + RINOK(GetTime(index, kpidLastAccessTime, _processedFileInfo.LastAccessTime, + _processedFileInfo.IsLastAccessTimeDefined)); - RINOK(_archiveHandler->GetProperty(index, kpidSize, &propVariant)); - bool newFileSizeDefined = (propVariant.vt != VT_EMPTY); + bool newFileSizeDefined; UInt64 newFileSize; - if (newFileSizeDefined) - newFileSize = ConvertPropVariantToUInt64(propVariant); + { + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop)); + newFileSizeDefined = (prop.vt != VT_EMPTY); + if (newFileSizeDefined) + newFileSize = ConvertPropVariantToUInt64(prop); + } bool isAnti = false; { - NCOM::CPropVariant propVariantTemp; - RINOK(_archiveHandler->GetProperty(index, kpidIsAnti, - &propVariantTemp)); - if (propVariantTemp.vt == VT_BOOL) - isAnti = VARIANT_BOOLToBool(propVariantTemp.boolVal); + NCOM::CPropVariant prop; + RINOK(_archiveHandler->GetProperty(index, kpidIsAnti, &prop)); + if (prop.vt == VT_BOOL) + isAnti = VARIANT_BOOLToBool(prop.boolVal); } UStringVector pathParts; @@ -211,8 +249,19 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, MakeCorrectPath(pathParts); if (!isAnti) + { if (!pathParts.IsEmpty()) - CreateComplexDirectory(pathParts); + { + UString fullPathNew; + CreateComplexDirectory(pathParts, fullPathNew); + if (_processedFileInfo.IsDirectory) + NFile::NDirectory::SetDirTime(fullPathNew, + (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, + (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, + (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault); + } + } + UString fullProcessedPath = _directoryPath + processedPath; @@ -237,9 +286,10 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, { Int32 overwiteResult; RINOK(_extractCallback2->AskOverwrite( - fullProcessedPath, &fileInfo.LastWriteTime, &fileInfo.Size, - fullPath, &_processedFileInfo.UTCLastWriteTime, newFileSizeDefined? - &newFileSize : NULL, &overwiteResult)) + fullProcessedPath, &fileInfo.LastWriteTime, &fileInfo.Size, fullPath, + _processedFileInfo.IsLastWriteTimeDefined ? &_processedFileInfo.LastWriteTime : NULL, + newFileSizeDefined ? &newFileSize : NULL, + &overwiteResult)) switch(overwiteResult) { @@ -327,10 +377,12 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, *outStream = NULL; } return S_OK; + COM_TRY_END } STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode) { + COM_TRY_BEGIN _extractMode = false; switch (askExtractMode) { @@ -338,10 +390,12 @@ STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode) _extractMode = true; }; return _extractCallback2->PrepareOperation(_filePath, askExtractMode, _isSplit ? &_position: 0); + COM_TRY_END } STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult) { + COM_TRY_BEGIN switch(operationResult) { case NArchive::NExtract::NOperationResult::kOK: @@ -354,34 +408,42 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult) return E_FAIL; } if(_outFileStream != NULL) - _outFileStreamSpec->File.SetLastWriteTime(&_processedFileInfo.UTCLastWriteTime); + _outFileStreamSpec->File.SetTime( + (WriteCreated && _processedFileInfo.IsCreationTimeDefined) ? &_processedFileInfo.CreationTime : NULL, + (WriteAccessed && _processedFileInfo.IsLastAccessTimeDefined) ? &_processedFileInfo.LastAccessTime : NULL, + (WriteModified && _processedFileInfo.IsLastWriteTimeDefined) ? &_processedFileInfo.LastWriteTime : &_utcLastWriteTimeDefault); _outFileStream.Release(); if (_extractMode && _processedFileInfo.AttributesAreDefined) NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attributes); - RINOK(_extractCallback2->SetOperationResult(operationResult)); + RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted)); return S_OK; + COM_TRY_END } /* STDMETHODIMP CArchiveExtractCallback::GetInStream( const wchar_t *name, ISequentialInStream **inStream) { + COM_TRY_BEGIN CInFileStream *inFile = new CInFileStream; CMyComPtr inStreamTemp = inFile; if (!inFile->Open(_srcDirectoryPrefix + name)) return ::GetLastError(); *inStream = inStreamTemp.Detach(); return S_OK; + COM_TRY_END } */ STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password) { + COM_TRY_BEGIN if (!_cryptoGetTextPassword) { RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword, &_cryptoGetTextPassword)); } return _cryptoGetTextPassword->CryptoGetTextPassword(password); + COM_TRY_END } diff --git a/7zip/UI/Common/ArchiveExtractCallback.h b/7zip/UI/Common/ArchiveExtractCallback.h index c0de2cc4..4fd63a53 100755 --- a/7zip/UI/Common/ArchiveExtractCallback.h +++ b/7zip/UI/Common/ArchiveExtractCallback.h @@ -25,12 +25,11 @@ public: // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback) // IProgress - STDMETHOD(SetTotal)(UInt64 aize); + STDMETHOD(SetTotal)(UInt64 size); STDMETHOD(SetCompleted)(const UInt64 *completeValue); // IExtractCallBack - STDMETHOD(GetStream)(UInt32 anIndex, ISequentialOutStream **outStream, - Int32 askExtractMode); + STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode); STDMETHOD(PrepareOperation)(Int32 askExtractMode); STDMETHOD(SetOperationResult)(Int32 resultEOperationResult); @@ -55,12 +54,26 @@ private: UString _diskFilePath; bool _extractMode; + + bool WriteModified; + bool WriteCreated; + bool WriteAccessed; + + bool _encrypted; + struct CProcessedFileInfo { - FILETIME UTCLastWriteTime; + FILETIME CreationTime; + FILETIME LastWriteTime; + FILETIME LastAccessTime; + UInt32 Attributes; + + bool IsCreationTimeDefined; + bool IsLastWriteTimeDefined; + bool IsLastAccessTimeDefined; + bool IsDirectory; bool AttributesAreDefined; - UInt32 Attributes; } _processedFileInfo; COutFileStream *_outFileStreamSpec; @@ -72,8 +85,14 @@ private: UInt32 _attributesDefault; bool _stdOutMode; - void CreateComplexDirectory(const UStringVector &dirPathParts); + void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath); + HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined); public: + CArchiveExtractCallback(): + WriteModified(true), + WriteCreated(false), + WriteAccessed(false) + {} void Init( IInArchive *archiveHandler, IFolderArchiveExtractCallback *extractCallback2, diff --git a/7zip/UI/Common/ArchiveOpenCallback.cpp b/7zip/UI/Common/ArchiveOpenCallback.cpp index bd7ec157..1d2944d8 100755 --- a/7zip/UI/Common/ArchiveOpenCallback.cpp +++ b/7zip/UI/Common/ArchiveOpenCallback.cpp @@ -5,6 +5,7 @@ #include "ArchiveOpenCallback.h" #include "Common/StringConvert.h" +#include "Common/ComTry.h" #include "Windows/PropVariant.h" #include "../../Common/FileStreams.h" @@ -13,16 +14,21 @@ using namespace NWindows; STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes) { + COM_TRY_BEGIN return Callback->SetTotal(files, bytes); + COM_TRY_END } STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes) { + COM_TRY_BEGIN return Callback->SetTotal(files, bytes); + COM_TRY_END } STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value) { + COM_TRY_BEGIN NCOM::CPropVariant propVariant; if (_subArchiveMode) { @@ -61,6 +67,7 @@ STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value) } propVariant.Detach(value); return S_OK; + COM_TRY_END } int COpenCallbackImp::FindName(const UString &name) @@ -84,9 +91,9 @@ struct CInFileStreamVol: public CInFileStream } }; -STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, - IInStream **inStream) +STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream) { + COM_TRY_BEGIN if (_subArchiveMode) return S_FALSE; RINOK(Callback->CheckBreak()); @@ -106,12 +113,15 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, inFile->OpenCallbackRef = this; FileNames.Add(name); return S_OK; + COM_TRY_END } #ifndef _NO_CRYPTO STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password) { + COM_TRY_BEGIN return Callback->CryptoGetTextPassword(password); + COM_TRY_END } #endif diff --git a/7zip/UI/Common/ArchiverInfo.cpp b/7zip/UI/Common/ArchiverInfo.cpp index ac3c8351..115c5d91 100755 --- a/7zip/UI/Common/ArchiverInfo.cpp +++ b/7zip/UI/Common/ArchiverInfo.cpp @@ -104,7 +104,7 @@ typedef UInt32 (WINAPI *CreateObjectPointer)( #endif #ifndef _SFX -static void SetBuffer(CByteBuffer &bb, const Byte *data, int size) +static inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size) { bb.SetCapacity(size); memmove((Byte *)bb, data, size); diff --git a/7zip/UI/Common/CompressCall.cpp b/7zip/UI/Common/CompressCall.cpp index 419a1843..86bdd297 100755 --- a/7zip/UI/Common/CompressCall.cpp +++ b/7zip/UI/Common/CompressCall.cpp @@ -26,6 +26,7 @@ static LPCWSTR kShowDialogSwitch = L" -ad"; static LPCWSTR kEmailSwitch = L" -seml."; static LPCWSTR kMapSwitch = L" -i#"; static LPCWSTR kArchiveNoNameSwitch = L" -an"; +static LPCWSTR kArchiveTypeSwitch = L" -t"; static LPCWSTR kArchiveMapSwitch = L" -ai#"; static LPCWSTR kStopSwitchParsing = L" --"; static LPCWSTR kLargePagesDisable = L" -slp-"; @@ -129,7 +130,7 @@ static HRESULT CreateMap(const UStringVector &names, CRandom random; random.Init(GetTickCount()); - while(true) + for (;;) { int number = random.Generate(); wchar_t temp[32]; @@ -145,7 +146,7 @@ static HRESULT CreateMap(const UStringVector &names, fileMapping.Close(); } - while(true) + for (;;) { int number = random.Generate(); wchar_t temp[32]; @@ -172,7 +173,6 @@ static HRESULT CreateMap(const UStringVector &names, LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize); if (data == NULL) return E_FAIL; - try { wchar_t *curData = (wchar_t *)data; *curData = 0; @@ -185,18 +185,13 @@ static HRESULT CreateMap(const UStringVector &names, *curData++ = L'\0'; } } - catch(...) - { - UnmapViewOfFile(data); - throw; - } - // UnmapViewOfFile(data); return S_OK; } HRESULT CompressFiles( const UString &curDir, const UString &archiveName, + const UString &archiveType, const UStringVector &names, // const UString &outFolder, bool email, @@ -228,7 +223,7 @@ HRESULT CompressFiles( CFileMapping fileMapping; CRandom random; random.Init(GetTickCount()); - while(true) + for (;;) { int number = random.Generate(); wchar_t temp[32]; @@ -247,7 +242,7 @@ HRESULT CompressFiles( } NSynchronization::CEvent event; - while(true) + for (;;) { int number = random.Generate(); wchar_t temp[32]; @@ -273,6 +268,12 @@ HRESULT CompressFiles( params += L":"; params += eventName; + if (!archiveType.IsEmpty()) + { + params += kArchiveTypeSwitch; + params += archiveType; + } + if (email) params += kEmailSwitch; diff --git a/7zip/UI/Common/CompressCall.h b/7zip/UI/Common/CompressCall.h index 815a50ea..95be95c3 100755 --- a/7zip/UI/Common/CompressCall.h +++ b/7zip/UI/Common/CompressCall.h @@ -13,6 +13,7 @@ HRESULT MyCreateProcess(const UString ¶ms, HRESULT CompressFiles( const UString &curDir, const UString &archiveName, + const UString &archiveType, const UStringVector &names, // const UString &outFolder, bool email, bool showDialog, bool waitFinish); diff --git a/7zip/UI/Common/EnumDirItems.cpp b/7zip/UI/Common/EnumDirItems.cpp index dddc05a9..454092ec 100755 --- a/7zip/UI/Common/EnumDirItems.cpp +++ b/7zip/UI/Common/EnumDirItems.cpp @@ -38,7 +38,7 @@ static void EnumerateDirectory( CRecordVector &errorCodes) { NFind::CEnumeratorW enumerator(baseFolderPrefix + directory + wchar_t(kAnyStringWildcard)); - while (true) + for (;;) { NFind::CFileInfoW fileInfo; bool found; @@ -138,7 +138,7 @@ static HRESULT EnumerateDirItems( bool isDir = fileInfo.IsDirectory(); if (isDir && !item.ForDir || !isDir && !item.ForFile) { - errorCodes.Add(E_FAIL); + errorCodes.Add((DWORD)E_FAIL); errorPaths.Add(fullPath); continue; } @@ -192,7 +192,7 @@ static HRESULT EnumerateDirItems( } if (!fileInfo.IsDirectory()) { - errorCodes.Add(E_FAIL); + errorCodes.Add((DWORD)E_FAIL); errorPaths.Add(fullPath); continue; } @@ -207,7 +207,7 @@ static HRESULT EnumerateDirItems( NFind::CEnumeratorW enumerator(diskPrefix + wchar_t(kAnyStringWildcard)); - while (true) + for (;;) { NFind::CFileInfoW fileInfo; bool found; diff --git a/7zip/UI/Common/Extract.cpp b/7zip/UI/Common/Extract.cpp index 2879feaa..300521ad 100755 --- a/7zip/UI/Common/Extract.cpp +++ b/7zip/UI/Common/Extract.cpp @@ -21,7 +21,8 @@ HRESULT DecompressArchive( const UString &defaultName, const NWildcard::CCensorNode &wildcardCensor, const CExtractOptions &options, - IExtractCallbackUI *callback) + IExtractCallbackUI *callback, + UString &errorMessage) { CRecordVector realIndices; UInt32 numItems; @@ -53,7 +54,11 @@ HRESULT DecompressArchive( if(!outDir.IsEmpty()) if(!NFile::NDirectory::CreateComplexDirectory(outDir)) { - throw UString(L"Can not create output directory ") + outDir; + HRESULT res = ::GetLastError(); + if (res == S_OK) + res = E_FAIL; + errorMessage = ((UString)L"Can not create output directory ") + outDir; + return res; } extractCallbackSpec->Init( @@ -84,7 +89,8 @@ HRESULT DecompressArchives( const NWildcard::CCensorNode &wildcardCensor, const CExtractOptions &optionsSpec, IOpenCallbackUI *openCallback, - IExtractCallbackUI *extractCallback) + IExtractCallbackUI *extractCallback, + UString &errorMessage) { CExtractOptions options = optionsSpec; for (int i = 0; i < archivePaths.Size(); i++) @@ -128,7 +134,9 @@ HRESULT DecompressArchives( options.DefaultItemName = archiveLink.GetDefaultItemName(); RINOK(DecompressArchive( archiveLink.GetArchive(), archiveLink.GetDefaultItemName(), - wildcardCensor, options, extractCallback)); + wildcardCensor, options, extractCallback, errorMessage)); + if (!errorMessage.IsEmpty()) + return E_FAIL; } return S_OK; } diff --git a/7zip/UI/Common/Extract.h b/7zip/UI/Common/Extract.h index 58636f70..c7b47c84 100755 --- a/7zip/UI/Common/Extract.h +++ b/7zip/UI/Common/Extract.h @@ -53,6 +53,7 @@ HRESULT DecompressArchives( const NWildcard::CCensorNode &wildcardCensor, const CExtractOptions &options, IOpenCallbackUI *openCallback, - IExtractCallbackUI *extractCallback); + IExtractCallbackUI *extractCallback, + UString &errorMessage); #endif diff --git a/7zip/UI/Common/IFileExtractCallback.h b/7zip/UI/Common/IFileExtractCallback.h index ac2c6543..7db0af1f 100755 --- a/7zip/UI/Common/IFileExtractCallback.h +++ b/7zip/UI/Common/IFileExtractCallback.h @@ -31,7 +31,7 @@ public: Int32 *answer) PURE; STDMETHOD(PrepareOperation)(const wchar_t *name, Int32 askExtractMode, const UInt64 *position) PURE; STDMETHOD(MessageError)(const wchar_t *message) PURE; - STDMETHOD(SetOperationResult)(Int32 operationResult) PURE; + STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE; }; struct IExtractCallbackUI: IFolderArchiveExtractCallback diff --git a/7zip/UI/Common/OpenArchive.cpp b/7zip/UI/Common/OpenArchive.cpp index d00a1f54..89deb434 100755 --- a/7zip/UI/Common/OpenArchive.cpp +++ b/7zip/UI/Common/OpenArchive.cpp @@ -110,14 +110,8 @@ HRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result) return IsArchiveItemProp(archive, index, kpidIsAnti, result); } -// Static-SFX (for Linux) can be big -const UInt64 kMaxCheckStartPosition = -#ifdef _WIN32 -1 << 20; -#else -1 << 22; -#endif - +// Static-SFX (for Linux) can be big. +const UInt64 kMaxCheckStartPosition = 1 << 22; HRESULT ReOpenArchive(IInArchive *archive, const UString &fileName) { diff --git a/7zip/UI/Common/Update.cpp b/7zip/UI/Common/Update.cpp index 9bebb34a..cd7975d0 100755 --- a/7zip/UI/Common/Update.cpp +++ b/7zip/UI/Common/Update.cpp @@ -263,7 +263,7 @@ static HRESULT Compress( CArchivePath &archivePath, const CObjectVector &archiveItems, bool stdInMode, - const UString &stdInFileName, + /* const UString & stdInFileName, */ bool stdOutMode, const CObjectVector &dirItems, bool sfxMode, @@ -342,7 +342,7 @@ static HRESULT Compress( GetUpdatePairInfoList(dirItems, archiveItems, fileTimeType, updatePairs); // must be done only once!!! CObjectVector updatePairs2; - UpdateProduce(dirItems, archiveItems, updatePairs, actionSet, updatePairs2); + UpdateProduce(updatePairs, actionSet, updatePairs2); CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; CMyComPtr updateCallback(updateCallbackSpec ); @@ -490,7 +490,8 @@ HRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor, CPropVariant propertySize; RINOK(archive->GetProperty(i, kpidSize, &propertySize)); - if (ai.SizeIsDefined = (propertySize.vt != VT_EMPTY)) + ai.SizeIsDefined = (propertySize.vt != VT_EMPTY); + if (ai.SizeIsDefined) ai.Size = ConvertPropVariantToUInt64(propertySize); ai.IndexInServer = i; @@ -526,7 +527,8 @@ static HRESULT UpdateWithItemLists( options.MethodMode, command.ArchivePath, archiveItems, - options.StdInMode, options.StdInFileName, + options.StdInMode, + /* options.StdInFileName, */ options.StdOutMode, dirItems, options.SfxMode, options.SfxModule, @@ -608,7 +610,7 @@ HRESULT UpdateArchive(const NWildcard::CCensor &censor, RINOK(result); if (archiveLink.VolumePaths.Size() > 1) { - errorInfo.SystemError = E_NOTIMPL; + errorInfo.SystemError = (DWORD)E_NOTIMPL; errorInfo.Message = L"Updating for multivolume archives is not implemented"; return E_NOTIMPL; } diff --git a/7zip/UI/Common/Update.h b/7zip/UI/Common/Update.h index d94ffcc9..465acc24 100755 --- a/7zip/UI/Common/Update.h +++ b/7zip/UI/Common/Update.h @@ -40,7 +40,10 @@ struct CArchivePath return; } if (BaseExtension.CompareNoCase(Name.Mid(dotPos + 1)) == 0) + { + BaseExtension = Name.Mid(dotPos + 1); Name = Name.Left(dotPos); + } else BaseExtension.Empty(); } diff --git a/7zip/UI/Common/UpdateCallback.cpp b/7zip/UI/Common/UpdateCallback.cpp index cc3d20ae..db3bf805 100755 --- a/7zip/UI/Common/UpdateCallback.cpp +++ b/7zip/UI/Common/UpdateCallback.cpp @@ -7,6 +7,7 @@ #include "Common/StringConvert.h" #include "Common/IntToString.h" #include "Common/Defs.h" +#include "Common/ComTry.h" #include "Windows/PropVariant.h" @@ -25,12 +26,16 @@ CArchiveUpdateCallback::CArchiveUpdateCallback(): STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size) { + COM_TRY_BEGIN return Callback->SetTotal(size); + COM_TRY_END } STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue) { + COM_TRY_BEGIN return Callback->SetCompleted(completeValue); + COM_TRY_END } /* @@ -47,7 +52,7 @@ STATPROPSTG kProperties[] = }; */ -STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **enumerator) +STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **) { return E_NOTIMPL; /* @@ -59,6 +64,7 @@ STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **enumerato STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive) { + COM_TRY_BEGIN RINOK(Callback->CheckBreak()); const CUpdatePair2 &updatePair = (*UpdatePairs)[index]; if(newData != NULL) @@ -78,10 +84,12 @@ STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index, *indexInArchive = UInt32(-1); } return S_OK; + COM_TRY_END } STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) { + COM_TRY_BEGIN const CUpdatePair2 &updatePair = (*UpdatePairs)[index]; NWindows::NCOM::CPropVariant propVariant; @@ -160,11 +168,12 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR } propVariant.Detach(value); return S_OK; + COM_TRY_END } -STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, - ISequentialInStream **inStream) +STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream) { + COM_TRY_BEGIN const CUpdatePair2 &updatePair = (*UpdatePairs)[index]; if(!updatePair.NewData) return E_FAIL; @@ -200,11 +209,14 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, *inStream = inStreamLoc.Detach(); } return S_OK; + COM_TRY_END } STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 operationResult) { + COM_TRY_BEGIN return Callback->SetOperationResult(operationResult); + COM_TRY_END } STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size) @@ -219,6 +231,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size) STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream) { + COM_TRY_BEGIN wchar_t temp[32]; ConvertUInt64ToString(index + 1, temp); UString res = temp; @@ -234,9 +247,12 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOu return ::GetLastError(); *volumeStream = streamLoc.Detach(); return S_OK; + COM_TRY_END } STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) { + COM_TRY_BEGIN return Callback->CryptoGetTextPassword2(passwordIsDefined, password); + COM_TRY_END } diff --git a/7zip/UI/Common/UpdateProduce.cpp b/7zip/UI/Common/UpdateProduce.cpp index 0d50a8ce..992bbeec 100755 --- a/7zip/UI/Common/UpdateProduce.cpp +++ b/7zip/UI/Common/UpdateProduce.cpp @@ -10,8 +10,6 @@ static const char *kUpdateActionSetCollision = "Internal collision in update action set"; void UpdateProduce( - const CObjectVector &dirItems, - const CObjectVector &archiveItems, const CObjectVector &updatePairs, const NUpdateArchive::CActionSet &actionSet, CObjectVector &operationChain) diff --git a/7zip/UI/Common/UpdateProduce.h b/7zip/UI/Common/UpdateProduce.h index 9c1e1e44..8f58dab9 100755 --- a/7zip/UI/Common/UpdateProduce.h +++ b/7zip/UI/Common/UpdateProduce.h @@ -24,8 +24,6 @@ struct CUpdatePair2 }; void UpdateProduce( - const CObjectVector &dirItems, - const CObjectVector &archiveItems, const CObjectVector &updatePairs, const NUpdateArchive::CActionSet &actionSet, CObjectVector &operationChain); diff --git a/7zip/UI/Common/ZipRegistry.cpp b/7zip/UI/Common/ZipRegistry.cpp index 5a324dae..e449d6b4 100755 --- a/7zip/UI/Common/ZipRegistry.cpp +++ b/7zip/UI/Common/ZipRegistry.cpp @@ -74,7 +74,7 @@ void ReadExtractionInfo(NExtract::CInfo &info) if(pathHistoryKey.Open(extractionKey, kExtractionPathHistoryKeyName, KEY_READ) == ERROR_SUCCESS) { - while(true) + for (;;) { wchar_t numberString[16]; ConvertUInt64ToString(info.Paths.Size(), numberString); @@ -135,9 +135,39 @@ static const TCHAR *kMultiThread = TEXT("Multithread"); static const WCHAR *kCompressionOptions = L"Options"; static const TCHAR *kCompressionLevel = TEXT("Level"); static const WCHAR *kCompressionMethod = L"Method"; +static const WCHAR *kEncryptionMethod = L"EncryptionMethod"; static const TCHAR *kCompressionDictionary = TEXT("Dictionary"); static const TCHAR *kCompressionOrder = TEXT("Order"); + +static void SetRegString(CKey &key, const WCHAR *name, const UString &value) +{ + if (value.IsEmpty()) + key.DeleteValue(name); + else + key.SetValue(name, value); +} + +static void SetRegUInt32(CKey &key, const TCHAR *name, UInt32 value) +{ + if (value == (UInt32)-1) + key.DeleteValue(name); + else + key.SetValue(name, value); +} + +static void GetRegString(CKey &key, const WCHAR *name, UString &value) +{ + if (key.QueryValue(name, value) != ERROR_SUCCESS) + value.Empty(); +} + +static void GetRegUInt32(CKey &key, const TCHAR *name, UInt32 &value) +{ + if (key.QueryValue(name, value) != ERROR_SUCCESS) + value = UInt32(-1); +} + void SaveCompressionInfo(const NCompression::CInfo &info) { NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection); @@ -167,26 +197,14 @@ void SaveCompressionInfo(const NCompression::CInfo &info) const NCompression::CFormatOptions &fo = info.FormatOptionsVector[i]; CKey formatKey; formatKey.Create(optionsKey, fo.FormatID); - if (fo.Options.IsEmpty()) - formatKey.DeleteValue(kCompressionOptions); - else - formatKey.SetValue(kCompressionOptions, fo.Options); - if (fo.Level == UInt32(-1)) - formatKey.DeleteValue(kCompressionLevel); - else - formatKey.SetValue(kCompressionLevel, fo.Level); - if (fo.Method.IsEmpty()) - formatKey.DeleteValue(kCompressionMethod); - else - formatKey.SetValue(kCompressionMethod, fo.Method); - if (fo.Dictionary == UInt32(-1)) - formatKey.DeleteValue(kCompressionDictionary); - else - formatKey.SetValue(kCompressionDictionary, fo.Dictionary); - if (fo.Order == UInt32(-1)) - formatKey.DeleteValue(kCompressionOrder); - else - formatKey.SetValue(kCompressionOrder, fo.Order); + + SetRegString(formatKey, kCompressionOptions, fo.Options); + SetRegString(formatKey, kCompressionMethod, fo.Method); + SetRegString(formatKey, kEncryptionMethod, fo.EncryptionMethod); + + SetRegUInt32(formatKey, kCompressionLevel, fo.Level); + SetRegUInt32(formatKey, kCompressionDictionary, fo.Dictionary); + SetRegUInt32(formatKey, kCompressionOrder, fo.Order); } } @@ -232,7 +250,7 @@ void ReadCompressionInfo(NCompression::CInfo &info) if(historyArchivesKey.Open(compressionKey, kCompressionHistoryArchivesKeyName, KEY_READ) == ERROR_SUCCESS) { - while(true) + for (;;) { wchar_t numberString[16]; ConvertUInt64ToString(info.HistoryArchives.Size(), numberString); @@ -266,16 +284,14 @@ void ReadCompressionInfo(NCompression::CInfo &info) fo.FormatID = formatIDs[i]; if(formatKey.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS) { - if (formatKey.QueryValue(kCompressionOptions, fo.Options) != ERROR_SUCCESS) - fo.Options.Empty(); - if (formatKey.QueryValue(kCompressionLevel, fo.Level) != ERROR_SUCCESS) - fo.Level = UInt32(-1); - if (formatKey.QueryValue(kCompressionMethod, fo.Method) != ERROR_SUCCESS) - fo.Method.Empty();; - if (formatKey.QueryValue(kCompressionDictionary, fo.Dictionary) != ERROR_SUCCESS) - fo.Dictionary = UInt32(-1); - if (formatKey.QueryValue(kCompressionOrder, fo.Order) != ERROR_SUCCESS) - fo.Order = UInt32(-1); + GetRegString(formatKey, kCompressionOptions, fo.Options); + GetRegString(formatKey, kCompressionMethod, fo.Method); + GetRegString(formatKey, kEncryptionMethod, fo.EncryptionMethod); + + GetRegUInt32(formatKey, kCompressionLevel, fo.Level); + GetRegUInt32(formatKey, kCompressionDictionary, fo.Dictionary); + GetRegUInt32(formatKey, kCompressionOrder, fo.Order); + info.FormatOptionsVector.Add(fo); } diff --git a/7zip/UI/Common/ZipRegistry.h b/7zip/UI/Common/ZipRegistry.h index cda96f7b..30e7ee44 100755 --- a/7zip/UI/Common/ZipRegistry.h +++ b/7zip/UI/Common/ZipRegistry.h @@ -24,17 +24,19 @@ namespace NCompression { { CSysString FormatID; UString Options; - UInt32 Level; UString Method; + UString EncryptionMethod; + UInt32 Level; UInt32 Dictionary; UInt32 Order; - void Init() + void ResetForLevelChange() { Level = Dictionary = Order = UInt32(-1); Method.Empty(); + // EncryptionMethod.Empty(); // Options.Empty(); } - CFormatOptions() { Init(); } + CFormatOptions() { ResetForLevelChange(); } }; struct CInfo diff --git a/7zip/UI/Console/ConsoleClose.cpp b/7zip/UI/Console/ConsoleClose.cpp index 5527ef6b..a514c12a 100755 --- a/7zip/UI/Console/ConsoleClose.cpp +++ b/7zip/UI/Console/ConsoleClose.cpp @@ -2,6 +2,8 @@ #include "StdAfx.h" +#include + #include "ConsoleClose.h" static int g_BreakCounter = 0; @@ -9,14 +11,20 @@ static const int kBreakAbortThreshold = 2; namespace NConsoleClose { -static BOOL WINAPI HandlerRoutine(DWORD aCtrlType) +static BOOL WINAPI HandlerRoutine(DWORD ctrlType) { + if (ctrlType == CTRL_LOGOFF_EVENT) + { + // printf("\nCTRL_LOGOFF_EVENT\n"); + return TRUE; + } + g_BreakCounter++; if (g_BreakCounter < kBreakAbortThreshold) return TRUE; return FALSE; /* - switch(aCtrlType) + switch(ctrlType) { case CTRL_C_EVENT: case CTRL_BREAK_EVENT: diff --git a/7zip/UI/Console/ExtractCallbackConsole.cpp b/7zip/UI/Console/ExtractCallbackConsole.cpp index 284f7b9a..13aee7c8 100755 --- a/7zip/UI/Console/ExtractCallbackConsole.cpp +++ b/7zip/UI/Console/ExtractCallbackConsole.cpp @@ -39,18 +39,20 @@ static const char *kEverythingIsOk = "Everything is Ok"; static const char *kNoFiles = "No files to process"; static const char *kUnsupportedMethod = "Unsupported Method"; -static const char *kCRCFailed = "CRC Failed"; +static const char *kCrcFailed = "CRC Failed"; +static const char *kCrcFailedEncrypted = "CRC Failed in encrypted file. Wrong password?"; static const char *kDataError = "Data Error"; +static const char *kDataErrorEncrypted = "Data Error in encrypted file. Wrong password?"; static const char *kUnknownError = "Unknown Error"; -STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64 size) +STDMETHODIMP CExtractCallbackConsole::SetTotal(UInt64) { if (NConsoleClose::TestBreakSignal()) return E_ABORT; return S_OK; } -STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue) +STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *) { if (NConsoleClose::TestBreakSignal()) return E_ABORT; @@ -58,8 +60,8 @@ STDMETHODIMP CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue) } STDMETHODIMP CExtractCallbackConsole::AskOverwrite( - const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize, - const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize, + const wchar_t *existName, const FILETIME *, const UInt64 *, + const wchar_t *newName, const FILETIME *, const UInt64 *, Int32 *answer) { (*OutStream) << "file " << existName << @@ -119,7 +121,7 @@ STDMETHODIMP CExtractCallbackConsole::MessageError(const wchar_t *message) return S_OK; } -STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult) +STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult, bool encrypted) { switch(operationResult) { @@ -136,10 +138,10 @@ STDMETHODIMP CExtractCallbackConsole::SetOperationResult(Int32 operationResult) (*OutStream) << kUnsupportedMethod; break; case NArchive::NExtract::NOperationResult::kCRCError: - (*OutStream) << kCRCFailed; + (*OutStream) << (encrypted ? kCrcFailedEncrypted: kCrcFailed); break; case NArchive::NExtract::NOperationResult::kDataError: - (*OutStream) << kDataError; + (*OutStream) << (encrypted ? kDataErrorEncrypted : kDataError); break; default: (*OutStream) << kUnknownError; diff --git a/7zip/UI/Console/ExtractCallbackConsole.h b/7zip/UI/Console/ExtractCallbackConsole.h index 3fa9044a..fdcdfbd9 100755 --- a/7zip/UI/Console/ExtractCallbackConsole.h +++ b/7zip/UI/Console/ExtractCallbackConsole.h @@ -29,7 +29,7 @@ public: STDMETHOD (PrepareOperation)(const wchar_t *name, Int32 askExtractMode, const UInt64 *position); STDMETHOD(MessageError)(const wchar_t *message); - STDMETHOD(SetOperationResult)(Int32 operationResult); + STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted); // ICryptoGetTextPassword STDMETHOD(CryptoGetTextPassword)(BSTR *password); diff --git a/7zip/UI/Console/List.cpp b/7zip/UI/Console/List.cpp index 6744fb82..6001e114 100755 --- a/7zip/UI/Console/List.cpp +++ b/7zip/UI/Console/List.cpp @@ -130,7 +130,7 @@ void PrintSpaces(int numSpaces) void PrintString(EAdjustment adjustment, int width, const UString &textString) { const int numSpaces = width - textString.Length(); - int numLeftSpaces; + int numLeftSpaces = 0; switch (adjustment) { case kLeft: diff --git a/7zip/UI/Console/Main.cpp b/7zip/UI/Console/Main.cpp index f51c1ccd..f844be5a 100755 --- a/7zip/UI/Console/Main.cpp +++ b/7zip/UI/Console/Main.cpp @@ -126,11 +126,6 @@ static void PrintHelpAndExit(CStdOutStream &s) // yyy ShowMessageAndThrowException(s, kUserErrorMessage, NExitCode::kUserError); } -static void PrintProcessTitle(CStdOutStream &s, const AString &processTitle, const UString &archiveName) -{ - s << endl << processTitle << kProcessArchiveMessage << archiveName << endl << endl; -} - #ifndef _WIN32 static void GetArguments(int numArguments, const char *arguments[], UStringVector &parts) { @@ -235,11 +230,18 @@ int Main2( #ifdef COMPRESS_MT eo.Properties = options.ExtractProperties; #endif + UString errorMessage; HRESULT result = DecompressArchives( options.ArchivePathsSorted, options.ArchivePathsFullSorted, options.WildcardCensor.Pairs.Front().Head, - eo, &openCallback, ecs); + eo, &openCallback, ecs, errorMessage); + if (!errorMessage.IsEmpty()) + { + stdStream << endl << "Error: " << errorMessage; + if (result == S_OK) + result = E_FAIL; + } if (ecs->NumArchives > 1) { diff --git a/7zip/UI/Console/MainAr.cpp b/7zip/UI/Console/MainAr.cpp index a30298c1..35272a35 100755 --- a/7zip/UI/Console/MainAr.cpp +++ b/7zip/UI/Console/MainAr.cpp @@ -15,6 +15,7 @@ #endif #include "../Common/ExitCode.h" +#include "../Common/ArchiveCommandLine.h" #include "ConsoleClose.h" using namespace NWindows; @@ -75,9 +76,10 @@ int numArguments, const char *arguments[] // setlocale(LC_COLLATE, ".OCP"); NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; + int res = 0; try { - return Main2( + res = Main2( #ifndef _WIN32 numArguments, arguments #endif @@ -93,6 +95,11 @@ int numArguments, const char *arguments[] (*g_StdStream) << endl << kUserBreak; return (NExitCode::kUserBreak); } + catch(const CArchiveCommandLineException &e) + { + (*g_StdStream) << kExceptionErrorMessage << e << endl; + return (NExitCode::kUserError); + } catch(const CSystemException &systemError) { if (systemError.ErrorCode == E_OUTOFMEMORY) @@ -148,4 +155,5 @@ int numArguments, const char *arguments[] (*g_StdStream) << kUnknownExceptionMessage; return (NExitCode::kFatalError); } + return res; } diff --git a/7zip/UI/Console/OpenCallbackConsole.cpp b/7zip/UI/Console/OpenCallbackConsole.cpp index f4833a2a..21c5391c 100755 --- a/7zip/UI/Console/OpenCallbackConsole.cpp +++ b/7zip/UI/Console/OpenCallbackConsole.cpp @@ -14,12 +14,12 @@ HRESULT COpenCallbackConsole::CheckBreak() return S_OK; } -HRESULT COpenCallbackConsole::SetTotal(const UInt64 *files, const UInt64 *bytes) +HRESULT COpenCallbackConsole::SetTotal(const UInt64 *, const UInt64 *) { return CheckBreak(); } -HRESULT COpenCallbackConsole::SetCompleted(const UInt64 *files, const UInt64 *bytes) +HRESULT COpenCallbackConsole::SetCompleted(const UInt64 *, const UInt64 *) { return CheckBreak(); } diff --git a/7zip/UI/Console/PercentPrinter.cpp b/7zip/UI/Console/PercentPrinter.cpp index 81d24222..34e48143 100755 --- a/7zip/UI/Console/PercentPrinter.cpp +++ b/7zip/UI/Console/PercentPrinter.cpp @@ -15,6 +15,9 @@ static const int kNumDigits = 3; CPercentPrinter::CPercentPrinter(UInt64 minStepSize): m_MinStepSize(minStepSize), + m_PrevValue(0), + m_CurValue(0), + m_Total(1), m_ScreenPos(0), m_StringIsPrinted(false) { @@ -67,10 +70,12 @@ void CPercentPrinter::RePrintRatio() char temp[32 + kNumDigits] = " "; // for 4 digits; ConvertUInt64ToString(ratio, temp + kNumDigits); int len = (int)strlen(temp + kNumDigits); - strcat(temp, "%"); + temp[kNumDigits + len] = '%'; + temp[kNumDigits + len + 1] = '\0'; int pos = (len > kNumDigits)? kNumDigits : len; (*OutStream) << kPercentFormatString1; (*OutStream) << (temp + pos); + OutStream->Flush(); m_PrevValue = m_CurValue; m_StringIsPrinted = true; } diff --git a/7zip/UI/Console/UpdateCallbackConsole.cpp b/7zip/UI/Console/UpdateCallbackConsole.cpp index 4abeecbe..51b96524 100755 --- a/7zip/UI/Console/UpdateCallbackConsole.cpp +++ b/7zip/UI/Console/UpdateCallbackConsole.cpp @@ -5,6 +5,7 @@ #include "UpdateCallbackConsole.h" #include "Windows/Error.h" +// #include "Windows/Synchronization.h" #include "ConsoleClose.h" #include "UserInputUtils.h" @@ -19,6 +20,8 @@ static const char *kScanningMessage = "Scanning"; static const char *kNoFilesScannedMessage = "No files scanned"; static const char *kTotalFilesAddedMessage = "Total files added to archive: "; +// static NSynchronization::CCriticalSection g_CriticalSection; + HRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result) { (*OutStream) << endl; @@ -86,6 +89,7 @@ HRESULT CUpdateCallbackConsole::CheckBreak() HRESULT CUpdateCallbackConsole::Finilize() { + // NSynchronization::CCriticalSectionLock lock(g_CriticalSection); if (m_NeedBeClosed) { if (EnablePercents) @@ -102,6 +106,7 @@ HRESULT CUpdateCallbackConsole::Finilize() HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size) { + // NSynchronization::CCriticalSectionLock lock(g_CriticalSection); if (EnablePercents) m_PercentPrinter.SetTotal(size); return S_OK; @@ -109,6 +114,7 @@ HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size) HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue) { + // NSynchronization::CCriticalSectionLock lock(g_CriticalSection); if (completeValue != NULL) { if (EnablePercents) @@ -125,6 +131,7 @@ HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue) HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti) { + // NSynchronization::CCriticalSectionLock lock(g_CriticalSection); if (StdOutMode) return S_OK; if(isAnti) @@ -145,6 +152,7 @@ HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti) HRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError) { + // NSynchronization::CCriticalSectionLock lock(g_CriticalSection); FailedCodes.Add(systemError); FailedFiles.Add(name); // if (systemError == ERROR_SHARING_VIOLATION) @@ -155,10 +163,10 @@ HRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemE m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError)); return S_FALSE; } - return systemError; + // return systemError; } -HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 operationResult) +HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 ) { m_NeedBeClosed = true; return S_OK; diff --git a/7zip/UI/Console/UserInputUtils.cpp b/7zip/UI/Console/UserInputUtils.cpp index 1ec64dd1..164af99c 100755 --- a/7zip/UI/Console/UserInputUtils.cpp +++ b/7zip/UI/Console/UserInputUtils.cpp @@ -25,7 +25,7 @@ static const char *kHelpQuestionMessage = NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream) { (*outStream) << kFirstQuestionMessage; - do + for(;;) { (*outStream) << kHelpQuestionMessage; AString scannedString = g_StdIn.ScanStringUntilNewLine(); @@ -47,7 +47,6 @@ NUserAnswerMode::EEnum ScanUserYesNoAllQuit(CStdOutStream *outStream) return NUserAnswerMode::kQuit; } } - while(true); } UString GetPassword(CStdOutStream *outStream) diff --git a/7zip/UI/Explorer/ContextMenu.cpp b/7zip/UI/Explorer/ContextMenu.cpp index fdb62212..fd40add5 100755 --- a/7zip/UI/Explorer/ContextMenu.cpp +++ b/7zip/UI/Explorer/ContextMenu.cpp @@ -73,7 +73,7 @@ HRESULT CZipContextMenu::GetFileNames(LPDATAOBJECT dataObject, UStringVector &fi } STDMETHODIMP CZipContextMenu::Initialize(LPCITEMIDLIST pidlFolder, - LPDATAOBJECT dataObject, HKEY hkeyProgID) + LPDATAOBJECT dataObject, HKEY /* hkeyProgID */) { // OutputDebugString(TEXT("::Initialize\r\n")); _dropMode = false; @@ -99,7 +99,7 @@ STDMETHODIMP CZipContextMenu::Initialize(LPCITEMIDLIST pidlFolder, return GetFileNames(dataObject, _fileNames); } -STDMETHODIMP CZipContextMenu::InitContextMenu(const wchar_t *folder, +STDMETHODIMP CZipContextMenu::InitContextMenu(const wchar_t * /* folder */, const wchar_t **names, UINT32 numFiles) { _fileNames.Clear(); @@ -187,14 +187,6 @@ static CContextMenuCommand g_Commands[] = IDS_CONTEXT_COMPRESS_HELP, 0x02000107, }, - { - NContextMenuFlags::kCompressTo, - CZipContextMenu::kCompressTo, - L"CompressTo", - IDS_CONTEXT_COMPRESS_TO, - IDS_CONTEXT_COMPRESS_TO_HELP, - 0x0200010F - }, { NContextMenuFlags::kCompressEmail, CZipContextMenu::kCompressEmail, @@ -204,9 +196,33 @@ static CContextMenuCommand g_Commands[] = 0x02000111 }, { - NContextMenuFlags::kCompressToEmail, - CZipContextMenu::kCompressToEmail, - L"CompressToEmail", + NContextMenuFlags::kCompressTo7z, + CZipContextMenu::kCompressTo7z, + L"CompressTo7z", + IDS_CONTEXT_COMPRESS_TO, + IDS_CONTEXT_COMPRESS_TO_HELP, + 0x0200010F + }, + { + NContextMenuFlags::kCompressTo7zEmail, + CZipContextMenu::kCompressTo7zEmail, + L"CompressTo7zEmail", + IDS_CONTEXT_COMPRESS_TO_EMAIL, + IDS_CONTEXT_COMPRESS_TO_EMAIL_HELP, + 0x02000113 + }, + { + NContextMenuFlags::kCompressToZip, + CZipContextMenu::kCompressToZip, + L"CompressToZip", + IDS_CONTEXT_COMPRESS_TO, + IDS_CONTEXT_COMPRESS_TO_HELP, + 0x0200010F + }, + { + NContextMenuFlags::kCompressToZipEmail, + CZipContextMenu::kCompressToZipEmail, + L"CompressToZipEmail", IDS_CONTEXT_COMPRESS_TO_EMAIL, IDS_CONTEXT_COMPRESS_TO_EMAIL_HELP, 0x02000113 @@ -306,7 +322,6 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, if (!ReadContextMenuStatus(contextMenuFlags)) contextMenuFlags = NContextMenuFlags::GetDefaultFlags(); - int subMenuIndex = 0; UString mainString; if(_fileNames.Size() == 1 && currentCommandID + 6 <= commandIDLast) { @@ -407,6 +422,7 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, } UString archiveName = CreateArchiveName(fileName, _fileNames.Size() > 1, false); UString archiveName7z = archiveName + L".7z"; + UString archiveNameZip = archiveName + L".zip"; UString archivePathPrefix; NFile::NDirectory::GetOnlyDirPrefix(fileName, archivePathPrefix); @@ -425,41 +441,75 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, } - // CompressTo - if (contextMenuFlags & NContextMenuFlags::kCompressTo) + // CompressEmail + if ((contextMenuFlags & NContextMenuFlags::kCompressEmail) != 0 && !_dropMode) + { + CCommandMapItem commandMapItem; + commandMapItem.Archive = archiveName; + FillCommand(kCompressEmail, mainString, commandMapItem); + MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString); + _commandMap.Add(commandMapItem); + } + + // CompressTo7z + if (contextMenuFlags & NContextMenuFlags::kCompressTo7z) { CCommandMapItem commandMapItem; UString s; - FillCommand(kCompressTo, s, commandMapItem); + FillCommand(kCompressTo7z, s, commandMapItem); if (_dropMode) commandMapItem.Folder = _dropPath; else commandMapItem.Folder = archivePathPrefix; commandMapItem.Archive = archiveName7z; + commandMapItem.ArchiveType = L"7z"; UString t = UString(L"\"") + GetReducedString(archiveName7z) + UString(L"\""); s = MyFormatNew(s, t); MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s); _commandMap.Add(commandMapItem); } - // CompressEmail - if ((contextMenuFlags & NContextMenuFlags::kCompressEmail) != 0 && !_dropMode) + // CompressTo7zEmail + if ((contextMenuFlags & NContextMenuFlags::kCompressTo7zEmail) != 0 && !_dropMode) { CCommandMapItem commandMapItem; - commandMapItem.Archive = archiveName; - FillCommand(kCompressEmail, mainString, commandMapItem); - MyInsertMenu(popupMenu, subIndex++, currentCommandID++, mainString); + UString s; + FillCommand(kCompressTo7zEmail, s, commandMapItem); + commandMapItem.Archive = archiveName7z; + commandMapItem.ArchiveType = L"7z"; + UString t = UString(L"\"") + GetReducedString(archiveName7z) + UString(L"\""); + s = MyFormatNew(s, t); + MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s); _commandMap.Add(commandMapItem); } - // CompressToEmail - if ((contextMenuFlags & NContextMenuFlags::kCompressToEmail) != 0 && !_dropMode) + // CompressToZip + if (contextMenuFlags & NContextMenuFlags::kCompressToZip) { CCommandMapItem commandMapItem; UString s; - FillCommand(kCompressToEmail, s, commandMapItem); - commandMapItem.Archive = archiveName7z; - UString t = UString(L"\"") + GetReducedString(archiveName7z) + UString(L"\""); + FillCommand(kCompressToZip, s, commandMapItem); + if (_dropMode) + commandMapItem.Folder = _dropPath; + else + commandMapItem.Folder = archivePathPrefix; + commandMapItem.Archive = archiveNameZip; + commandMapItem.ArchiveType = L"zip"; + UString t = UString(L"\"") + GetReducedString(archiveNameZip) + UString(L"\""); + s = MyFormatNew(s, t); + MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s); + _commandMap.Add(commandMapItem); + } + + // CompressToZipEmail + if ((contextMenuFlags & NContextMenuFlags::kCompressToZipEmail) != 0 && !_dropMode) + { + CCommandMapItem commandMapItem; + UString s; + FillCommand(kCompressToZipEmail, s, commandMapItem); + commandMapItem.Archive = archiveNameZip; + commandMapItem.ArchiveType = L"zip"; + UString t = UString(L"\"") + GetReducedString(archiveNameZip) + UString(L"\""); s = MyFormatNew(s, t); MyInsertMenu(popupMenu, subIndex++, currentCommandID++, s); _commandMap.Add(commandMapItem); @@ -489,7 +539,7 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, } -UINT CZipContextMenu::FindVerb(const UString &verb) +int CZipContextMenu::FindVerb(const UString &verb) { for(int i = 0; i < _commandMap.Size(); i++) if(_commandMap[i].Verb.Compare(verb) == 0) @@ -537,7 +587,6 @@ STDMETHODIMP CZipContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO commandInfo) const CCommandMapItem commandMapItem = _commandMap[commandOffset]; ECommandInternalID commandInternalID = commandMapItem.CommandInternalID; - HWND aHWND = commandInfo->hwnd; try { @@ -567,15 +616,21 @@ STDMETHODIMP CZipContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO commandInfo) break; } case kCompress: - case kCompressTo: case kCompressEmail: - case kCompressToEmail: + case kCompressTo7z: + case kCompressTo7zEmail: + case kCompressToZip: + case kCompressToZipEmail: { - bool email = (commandInternalID == kCompressEmail) || - (commandInternalID == kCompressToEmail); - bool showDialog = (commandInternalID == kCompress) || - (commandInternalID == kCompressEmail); - CompressFiles(commandMapItem.Folder, commandMapItem.Archive, + bool email = + (commandInternalID == kCompressEmail) || + (commandInternalID == kCompressTo7zEmail) || + (commandInternalID == kCompressToZipEmail); + bool showDialog = + (commandInternalID == kCompress) || + (commandInternalID == kCompressEmail); + CompressFiles(commandMapItem.Folder, + commandMapItem.Archive, commandMapItem.ArchiveType, _fileNames, email, showDialog, false); break; } @@ -592,35 +647,35 @@ static void MyCopyString(void *dest, const wchar_t *src, bool writeInUnicode) { if(writeInUnicode) { - wcscpy((wchar_t *)dest, src); + MyStringCopy((wchar_t *)dest, src); } else lstrcpyA((char *)dest, GetAnsiString(src)); } STDMETHODIMP CZipContextMenu::GetCommandString(UINT_PTR commandOffset, UINT uType, - UINT *pwReserved, LPSTR pszName, UINT cchMax) + UINT * /* pwReserved */ , LPSTR pszName, UINT /* cchMax */) { + int cmdOffset = (int)commandOffset; switch(uType) { case GCS_VALIDATEA: case GCS_VALIDATEW: - if(commandOffset < 0 || commandOffset >= (UINT)_commandMap.Size()) + if(cmdOffset < 0 || cmdOffset >= _commandMap.Size()) return S_FALSE; else return S_OK; } - if(commandOffset < 0 || commandOffset >= (UINT)_commandMap.Size()) + if(cmdOffset < 0 || cmdOffset >= _commandMap.Size()) return E_FAIL; if(uType == GCS_HELPTEXTA || uType == GCS_HELPTEXTW) { - MyCopyString(pszName, _commandMap[commandOffset].HelpString, - uType == GCS_HELPTEXTW); + MyCopyString(pszName, _commandMap[cmdOffset].HelpString, uType == GCS_HELPTEXTW); return NO_ERROR; } if(uType == GCS_VERBA || uType == GCS_VERBW) { - MyCopyString(pszName, _commandMap[commandOffset].Verb, uType == GCS_VERBW); + MyCopyString(pszName, _commandMap[cmdOffset].Verb, uType == GCS_VERBW); return NO_ERROR; } return E_FAIL; diff --git a/7zip/UI/Explorer/ContextMenu.h b/7zip/UI/Explorer/ContextMenu.h index f3693ca2..60970a22 100755 --- a/7zip/UI/Explorer/ContextMenu.h +++ b/7zip/UI/Explorer/ContextMenu.h @@ -31,9 +31,11 @@ public: kExtractTo, kTest, kCompress, - kCompressTo, kCompressEmail, - kCompressToEmail + kCompressTo7z, + kCompressTo7zEmail, + kCompressToZip, + kCompressToZipEmail }; struct CCommandMapItem @@ -43,6 +45,7 @@ public: UString HelpString; UString Folder; UString Archive; + UString ArchiveType; }; MY_UNKNOWN_IMP3_MT(IContextMenu, IShellExtInit, IInitContextMenu) @@ -71,7 +74,7 @@ private: UString _dropPath; CObjectVector _commandMap; HRESULT GetFileNames(LPDATAOBJECT dataObject, UStringVector &fileNames); - UINT FindVerb(const UString &verb); + int FindVerb(const UString &verb); void FillCommand(ECommandInternalID id, UString &mainString, CCommandMapItem &commandMapItem); diff --git a/7zip/UI/Explorer/ContextMenuFlags.h b/7zip/UI/Explorer/ContextMenuFlags.h index b2f4a3a6..d138baf9 100755 --- a/7zip/UI/Explorer/ContextMenuFlags.h +++ b/7zip/UI/Explorer/ContextMenuFlags.h @@ -15,12 +15,20 @@ namespace NContextMenuFlags const UINT32 kOpen = 1 << 5; const UINT32 kCompress = 1 << 8; - const UINT32 kCompressTo = 1 << 9; + const UINT32 kCompressTo7z = 1 << 9; const UINT32 kCompressEmail = 1 << 10; - const UINT32 kCompressToEmail = 1 << 11; + const UINT32 kCompressTo7zEmail = 1 << 11; + + const UINT32 kCompressToZip = 1 << 12; + const UINT32 kCompressToZipEmail = 1 << 13; inline UINT32 GetDefaultFlags() { - return kOpen | kExtract | kExtractHere | kCompress | kTest; } + return + kOpen | kTest | + kExtract | kExtractHere | kExtractTo | + kCompress | kCompressEmail | + kCompressTo7z | kCompressTo7zEmail | + kCompressToZip | kCompressToZipEmail; } } #endif diff --git a/7zip/UI/Explorer/DllExports.cpp b/7zip/UI/Explorer/DllExports.cpp index 8c5f21c1..fb7daf04 100755 --- a/7zip/UI/Explorer/DllExports.cpp +++ b/7zip/UI/Explorer/DllExports.cpp @@ -82,7 +82,7 @@ STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, } -STDMETHODIMP CShellExtClassFactory::LockServer(BOOL fLock) +STDMETHODIMP CShellExtClassFactory::LockServer(BOOL /* fLock */) { return S_OK; // Check it } diff --git a/7zip/UI/Explorer/Explorer.dsp b/7zip/UI/Explorer/Explorer.dsp index c8ffe168..7689cd83 100755 --- a/7zip/UI/Explorer/Explorer.dsp +++ b/7zip/UI/Explorer/Explorer.dsp @@ -673,6 +673,10 @@ SOURCE=..\..\..\Windows\Memory.cpp # End Source File # Begin Source File +SOURCE=..\..\..\Windows\Memory.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Menu.cpp # End Source File # Begin Source File diff --git a/7zip/UI/Explorer/MyMessages.cpp b/7zip/UI/Explorer/MyMessages.cpp index 3ec59f99..61d2429d 100755 --- a/7zip/UI/Explorer/MyMessages.cpp +++ b/7zip/UI/Explorer/MyMessages.cpp @@ -20,17 +20,30 @@ void MyMessageBox(HWND window, LPCWSTR message) ::MessageBoxW(window, message, L"7-Zip", 0); } -void MyMessageBox(UINT32 id +void MyMessageBoxResource(HWND window, UINT32 id #ifdef LANG ,UINT32 langID #endif ) { #ifdef LANG - MyMessageBox(LangString(id, langID)); + MyMessageBox(window, LangString(id, langID)); #else - MyMessageBox(MyLoadStringW(id)); + MyMessageBox(window, MyLoadStringW(id)); + #endif +} + +void MyMessageBox(UINT32 id + #ifdef LANG + ,UINT32 langID + #endif + ) +{ + MyMessageBoxResource(0, id + #ifdef LANG + , langID #endif + ); } void ShowErrorMessage(HWND window, DWORD message) diff --git a/7zip/UI/Explorer/MyMessages.h b/7zip/UI/Explorer/MyMessages.h index b3c02d74..1a96f569 100755 --- a/7zip/UI/Explorer/MyMessages.h +++ b/7zip/UI/Explorer/MyMessages.h @@ -10,6 +10,12 @@ void MyMessageBox(HWND window, LPCWSTR message); inline void MyMessageBox(LPCWSTR message) { MyMessageBox(0, message); } +void MyMessageBoxResource(HWND window, UINT32 id + #ifdef LANG + ,UINT32 langID + #endif + ); + void MyMessageBox(UINT32 id #ifdef LANG ,UINT32 langID diff --git a/7zip/UI/Explorer/OptionsDialog.cpp b/7zip/UI/Explorer/OptionsDialog.cpp index 1a2c91d1..b7831afd 100755 --- a/7zip/UI/Explorer/OptionsDialog.cpp +++ b/7zip/UI/Explorer/OptionsDialog.cpp @@ -17,7 +17,7 @@ using namespace NWindows; -int OptionsDialog(HWND hwndOwner) +static INT_PTR OptionsDialog(HWND hwndOwner) { CSystemPage systemPage; CFoldersPage foldersPage; @@ -39,7 +39,7 @@ int OptionsDialog(HWND hwndOwner) } STDMETHODIMP CSevenZipOptions::PluginOptions(HWND hWnd, - IPluginOptionsCallback *callback) + IPluginOptionsCallback * /* callback */) { /* CComBSTR programPath; @@ -49,7 +49,7 @@ STDMETHODIMP CSevenZipOptions::PluginOptions(HWND hWnd, return S_OK; } -STDMETHODIMP CSevenZipOptions::GetFileExtensions(BSTR *extensions) +STDMETHODIMP CSevenZipOptions::GetFileExtensions(BSTR * /* extensions */) { /* UString extStrings; diff --git a/7zip/UI/Explorer/SystemPage/SystemPage.cpp b/7zip/UI/Explorer/SystemPage/SystemPage.cpp index 8f656559..cc2f974d 100755 --- a/7zip/UI/Explorer/SystemPage/SystemPage.cpp +++ b/7zip/UI/Explorer/SystemPage/SystemPage.cpp @@ -46,9 +46,11 @@ static CContextMenuItem kMenuItems[] = { IDS_CONTEXT_TEST, 0x02000109, kTest}, { IDS_CONTEXT_COMPRESS, 0x02000107, kCompress }, - { IDS_CONTEXT_COMPRESS_TO, 0x0200010F, kCompressTo }, { IDS_CONTEXT_COMPRESS_EMAIL, 0x02000111, kCompressEmail }, - { IDS_CONTEXT_COMPRESS_TO_EMAIL, 0x02000113, kCompressToEmail}, + { IDS_CONTEXT_COMPRESS_TO, 0x0200010F, kCompressTo7z }, + { IDS_CONTEXT_COMPRESS_TO_EMAIL, 0x02000113, kCompressTo7zEmail}, + { IDS_CONTEXT_COMPRESS_TO, 0x0200010F, kCompressToZip }, + { IDS_CONTEXT_COMPRESS_TO_EMAIL, 0x02000113, kCompressToZipEmail}, }; const int kNumMenuItems = sizeof(kMenuItems) / sizeof(kMenuItems[0]); @@ -99,12 +101,28 @@ bool CSystemPage::OnInit() switch(menuItem.ControlID) { case IDS_CONTEXT_EXTRACT_TO: + { s = MyFormatNew(s, LangString(IDS_CONTEXT_FOLDER, 0x02000140)); break; + } case IDS_CONTEXT_COMPRESS_TO: case IDS_CONTEXT_COMPRESS_TO_EMAIL: - s = MyFormatNew(s, LangString(IDS_CONTEXT_ARCHIVE, 0x02000141)); + { + UString s2 = LangString(IDS_CONTEXT_ARCHIVE, 0x02000141); + switch(menuItem.Flag) + { + case kCompressTo7z: + case kCompressTo7zEmail: + s2 += L".7z"; + break; + case kCompressToZip: + case kCompressToZipEmail: + s2 += L".zip"; + break; + } + s = MyFormatNew(s, s2); break; + } } // UString MyFormatNew(const UString &format, const UString &argument); diff --git a/7zip/UI/Far/ExtractEngine.cpp b/7zip/UI/Far/ExtractEngine.cpp index 6140a242..e85df5e1 100755 --- a/7zip/UI/Far/ExtractEngine.cpp +++ b/7zip/UI/Far/ExtractEngine.cpp @@ -62,16 +62,18 @@ STDMETHODIMP CExtractCallBackImp::AskOverwrite( { NOverwriteDialog::CFileInfo oldFileInfo, newFileInfo; oldFileInfo.Time = *existTime; - if (oldFileInfo.SizeIsDefined = (existSize != NULL)) + oldFileInfo.SizeIsDefined = (existSize != NULL); + if (oldFileInfo.SizeIsDefined) oldFileInfo.Size = *existSize; - oldFileInfo.Name = UnicodeStringToMultiByte(existName, m_CodePage); + oldFileInfo.Name = GetSystemString(existName, m_CodePage); newFileInfo.Time = *aNewTime; - if (newFileInfo.SizeIsDefined = (newSize != NULL)) + newFileInfo.SizeIsDefined = (newSize != NULL); + if (newFileInfo.SizeIsDefined) newFileInfo.Size = *newSize; - newFileInfo.Name = UnicodeStringToMultiByte(newName, m_CodePage); + newFileInfo.Name = GetSystemString(newName, m_CodePage); NOverwriteDialog::NResult::EEnum result = NOverwriteDialog::Execute(oldFileInfo, newFileInfo); @@ -103,7 +105,7 @@ STDMETHODIMP CExtractCallBackImp::AskOverwrite( return S_OK; } -STDMETHODIMP CExtractCallBackImp::PrepareOperation(const wchar_t *name, INT32 askExtractMode, const UINT64 *position) +STDMETHODIMP CExtractCallBackImp::PrepareOperation(const wchar_t *name, INT32 /* askExtractMode */, const UINT64 * /* position */) { m_CurrentFilePath = name; return S_OK; @@ -111,13 +113,13 @@ STDMETHODIMP CExtractCallBackImp::PrepareOperation(const wchar_t *name, INT32 as STDMETHODIMP CExtractCallBackImp::MessageError(const wchar_t *message) { - CSysString s = UnicodeStringToMultiByte(message, CP_OEMCP); - if (g_StartupInfo.ShowMessage(s) == -1) + AString s = UnicodeStringToMultiByte(message, CP_OEMCP); + if (g_StartupInfo.ShowMessage((const char *)s) == -1) return E_ABORT; return S_OK; } -STDMETHODIMP CExtractCallBackImp::SetOperationResult(INT32 operationResult) +STDMETHODIMP CExtractCallBackImp::SetOperationResult(INT32 operationResult, bool encrypted) { switch(operationResult) { diff --git a/7zip/UI/Far/ExtractEngine.h b/7zip/UI/Far/ExtractEngine.h index b95b6ae8..57c04f76 100755 --- a/7zip/UI/Far/ExtractEngine.h +++ b/7zip/UI/Far/ExtractEngine.h @@ -31,7 +31,7 @@ public: STDMETHOD (PrepareOperation)(const wchar_t *name, INT32 askExtractMode, const UINT64 *position); STDMETHOD(MessageError)(const wchar_t *message); - STDMETHOD(SetOperationResult)(INT32 resultEOperationResult); + STDMETHOD(SetOperationResult)(INT32 resultEOperationResult, bool encrypted); // ICryptoGetTextPassword STDMETHOD(CryptoGetTextPassword)(BSTR *password); diff --git a/7zip/UI/Far/FarPlugin.h b/7zip/UI/Far/FarPlugin.h index 9f1fbe24..f61bbcb4 100755 --- a/7zip/UI/Far/FarPlugin.h +++ b/7zip/UI/Far/FarPlugin.h @@ -139,7 +139,15 @@ struct FarDialogItem int Type; int X1,Y1,X2,Y2; int Focus; - int Selected; + union + { + int Selected; + const char *History; + const char *Mask; + struct FarList *ListItems; + int ListPos; + CHAR_INFO *VBuf; + }; unsigned int Flags; int DefaultButton; char Data[512]; diff --git a/7zip/UI/Far/FarUtils.cpp b/7zip/UI/Far/FarUtils.cpp index 11fb422c..abbb6817 100755 --- a/7zip/UI/Far/FarUtils.cpp +++ b/7zip/UI/Far/FarUtils.cpp @@ -90,22 +90,22 @@ void CStartupInfo::InitDialogItems(const CInitDialogItem *srcItems, destItem.Y2 = srcItem.Y2; destItem.Focus = GetBOOLValue(srcItem.Focus); if(srcItem.HistoryName != NULL) - destItem.Selected = int(srcItem.HistoryName); + destItem.History = srcItem.HistoryName; else destItem.Selected = GetBOOLValue(srcItem.Selected); destItem.Flags = srcItem.Flags; destItem.DefaultButton = GetBOOLValue(srcItem.DefaultButton); if(srcItem.DataMessageId < 0) - strcpy(destItem.Data, srcItem.DataString); + MyStringCopy(destItem.Data, srcItem.DataString); else - strcpy(destItem.Data, GetMsgString(srcItem.DataMessageId)); + MyStringCopy(destItem.Data, GetMsgString(srcItem.DataMessageId)); /* if ((unsigned int)Init[i].Data < 0xFFF) - strcpy(destItem.Data, GetMsg((unsigned int)srcItem.Data)); + MyStringCopy(destItem.Data, GetMsg((unsigned int)srcItem.Data)); else - strcpy(destItem.Data,srcItem.Data); + MyStringCopy(destItem.Data,srcItem.Data); */ } } @@ -318,9 +318,8 @@ int CStartupInfo::Menu( item.Checked = 0; item.Separator = 0; item.Selected = (i == selectedItem); - CSysString reducedString = - items[i].Left(sizeof(item.Text) / sizeof(item.Text[0]) - 1); - strcpy(item.Text, reducedString); + AString reducedString = items[i].Left(sizeof(item.Text) / sizeof(item.Text[0]) - 1); + MyStringCopy(item.Text, (const char *)reducedString); farMenuItems.Add(item); } return Menu(flags, title, helpTopic, &farMenuItems.Front(), farMenuItems.Size()); @@ -351,7 +350,7 @@ void CScreenRestorer::Restore() } }; -static CSysString DWORDToString(DWORD number) +static AString DWORDToString(DWORD number) { char buffer[32]; ultoa(number, buffer, 10); @@ -381,7 +380,7 @@ bool WasEscPressed() if(handle == INVALID_HANDLE_VALUE) return true; inConsole.Attach(handle); - while (true) + for (;;) { DWORD numEvents; if(!inConsole.GetNumberOfEvents(numEvents)) @@ -401,8 +400,10 @@ bool WasEscPressed() void ShowErrorMessage(DWORD errorCode) { - CSysString message; + AString message; NError::MyFormatMessage(errorCode, message); + message.Replace("\x0D", ""); + message.Replace("\x0A", " "); g_StartupInfo.ShowMessage(SystemStringToOemString(message)); } diff --git a/7zip/UI/Far/Main.cpp b/7zip/UI/Far/Main.cpp index d9e7d696..a7994b6d 100755 --- a/7zip/UI/Far/Main.cpp +++ b/7zip/UI/Far/Main.cpp @@ -218,7 +218,7 @@ STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 *numFiles, const UINT64 return S_OK; } -STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *numFiles, const UINT64 *numBytes) +STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *numFiles, const UINT64 * /* numBytes */) { if (WasEscPressed()) return E_ABORT; @@ -232,7 +232,7 @@ STDMETHODIMP COpenArchiveCallback::SetCompleted(const UINT64 *numFiles, const UI } -STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 total) +STDMETHODIMP COpenArchiveCallback::SetTotal(const UINT64 /* total */) { if (WasEscPressed()) return E_ABORT; @@ -434,7 +434,7 @@ static HANDLE MyOpenFilePlugin(const char *name) } HANDLE WINAPI OpenFilePlugin(char *name, - const unsigned char *data, unsigned int dataSize) + const unsigned char * /* data */, unsigned int /* dataSize */) { MY_TRY_BEGIN; if (name == NULL || (!g_Options.Enabled)) diff --git a/7zip/UI/Far/Plugin.cpp b/7zip/UI/Far/Plugin.cpp index e16c6cf8..0d4b150e 100755 --- a/7zip/UI/Far/Plugin.cpp +++ b/7zip/UI/Far/Plugin.cpp @@ -243,7 +243,7 @@ void CPlugin::GetPathParts(UStringVector &pathParts) { pathParts.Clear(); CMyComPtr folderItem = _folder; - while (true) + for (;;) { CMyComPtr newFolder; folderItem->BindToParentFolder(&newFolder); diff --git a/7zip/UI/Far/PluginRead.cpp b/7zip/UI/Far/PluginRead.cpp index 79409142..503ff639 100755 --- a/7zip/UI/Far/PluginRead.cpp +++ b/7zip/UI/Far/PluginRead.cpp @@ -177,7 +177,7 @@ NFileOperationReturnCode::EEnum CPlugin::GetFilesReal(struct PluginPanelItem *pa FarDialogItem dialogItems[kNumDialogItems]; g_StartupInfo.InitDialogItems(initItems, dialogItems, kNumDialogItems); - while(true) + for (;;) { int askCode = g_StartupInfo.ShowDialog(kXSize, kYSize, kHelpTopicExtrFromSevenZip, dialogItems, kNumDialogItems); diff --git a/7zip/UI/Far/PluginWrite.cpp b/7zip/UI/Far/PluginWrite.cpp index 58d77ec9..d6730985 100755 --- a/7zip/UI/Far/PluginWrite.cpp +++ b/7zip/UI/Far/PluginWrite.cpp @@ -407,7 +407,7 @@ HRESULT CompressFiles(const CObjectVector &pluginPanelItems) const CActionSet *actionSet = &kAddActionSet; - while(true) + for (;;) { AString archiveNameA = UnicodeStringToMultiByte(archiveName, CP_OEMCP); const int kYSize = 16; diff --git a/7zip/UI/GUI/CompressDialog.cpp b/7zip/UI/GUI/CompressDialog.cpp index 211e8cf6..edaee789 100755 --- a/7zip/UI/GUI/CompressDialog.cpp +++ b/7zip/UI/GUI/CompressDialog.cpp @@ -14,6 +14,7 @@ #include "../../FileManager/HelpUtils.h" #include "../../FileManager/SplitUtils.h" +#include "../Explorer/MyMessages.h" #include "../Common/ZipRegistry.h" @@ -46,12 +47,18 @@ static CIDLangPair kIDLangPairs[] = { IDC_COMPRESS_MULTI_THREAD, 0x02000D09 }, { IDC_STATIC_COMPRESS_VOLUME, 0x02000D40 }, { IDC_STATIC_COMPRESS_PARAMETERS, 0x02000D06 }, + { IDC_STATIC_COMPRESS_UPDATE_MODE, 0x02000D02 }, { IDC_STATIC_COMPRESS_OPTIONS, 0x02000D07 }, { IDC_COMPRESS_SFX, 0x02000D08 }, - { IDC_COMPRESS_PASSWORD, 0x02000802 }, + + { IDC_COMPRESS_ENCRYPTION, 0x02000D10 }, + { IDC_STATIC_COMPRESS_PASSWORD1, 0x02000B01 }, + { IDC_STATIC_COMPRESS_PASSWORD2, 0x02000B03 }, { IDC_COMPRESS_CHECK_SHOW_PASSWORD, 0x02000B02 }, + { IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, 0x02000D11 }, { IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, 0x02000D0A }, + { IDOK, 0x02000702 }, { IDCANCEL, 0x02000710 }, { IDHELP, 0x02000720 } @@ -261,8 +268,11 @@ bool CCompressDialog::OnInit() LangSetWindowText(HWND(*this), 0x02000D00); LangSetDlgItemsText(HWND(*this), kIDLangPairs, MY_SIZE_OF_ARRAY(kIDLangPairs) ); #endif - _passwordControl.Attach(GetItem(IDC_COMPRESS_EDIT_PASSWORD)); - _passwordControl.SetText(Info.Password); + _password1Control.Attach(GetItem(IDC_COMPRESS_EDIT_PASSWORD1)); + _password2Control.Attach(GetItem(IDC_COMPRESS_EDIT_PASSWORD2)); + _password1Control.SetText(Info.Password); + _password2Control.SetText(Info.Password); + _encryptionMethod.Attach(GetItem(IDC_COMPRESS_COMBO_ENCRYPTION_METHOD)); m_ArchivePath.Attach(GetItem(IDC_COMPRESS_COMBO_ARCHIVE)); m_Format.Attach(GetItem(IDC_COMPRESS_COMBO_FORMAT)); @@ -319,6 +329,7 @@ bool CCompressDialog::OnInit() OnButtonSFX(); + SetEncryptionMethod(); return CModalDialog::OnInit(); } @@ -333,11 +344,19 @@ namespace NCompressDialog void CCompressDialog::UpdatePasswordControl() { - _passwordControl.SetPasswordChar((IsButtonChecked( - IDC_COMPRESS_CHECK_SHOW_PASSWORD) == BST_CHECKED) ? 0: TEXT('*')); + bool showPassword = IsShowPasswordChecked(); + TCHAR c = showPassword ? 0: TEXT('*'); + _password1Control.SetPasswordChar(c); + _password2Control.SetPasswordChar(c); UString password; - _passwordControl.GetText(password); - _passwordControl.SetText(password); + _password1Control.GetText(password); + _password1Control.SetText(password); + _password2Control.GetText(password); + _password2Control.SetText(password); + + int cmdShow = showPassword ? SW_HIDE : SW_SHOW; + ShowItem(IDC_STATIC_COMPRESS_PASSWORD2, cmdShow); + _password2Control.Show(cmdShow); } bool CCompressDialog::OnButtonClicked(int buttonID, HWND buttonHWND) @@ -408,14 +427,17 @@ void CCompressDialog::CheckControlsEnable() CheckSFXControlsEnable(); CheckVolumeEnable(); - // EnableItem(IDC_STATIC_COMPRESS_VOLUME, enable); - // EnableItem(IDC_COMPRESS_COMBO_VOLUME, enable); - - EnableItem(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, fi.EncryptFileNames); - EnableItem(IDC_COMPRESS_PASSWORD, fi.Encrypt); - EnableItem(IDC_COMPRESS_EDIT_PASSWORD, fi.Encrypt); + EnableItem(IDC_COMPRESS_ENCRYPTION, fi.Encrypt); + + EnableItem(IDC_STATIC_COMPRESS_PASSWORD1, fi.Encrypt); + EnableItem(IDC_STATIC_COMPRESS_PASSWORD2, fi.Encrypt); + EnableItem(IDC_COMPRESS_EDIT_PASSWORD1, fi.Encrypt); + EnableItem(IDC_COMPRESS_EDIT_PASSWORD2, fi.Encrypt); EnableItem(IDC_COMPRESS_CHECK_SHOW_PASSWORD, fi.Encrypt); + EnableItem(IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, fi.Encrypt); + EnableItem(IDC_COMPRESS_COMBO_ENCRYPTION_METHOD, fi.Encrypt); + EnableItem(IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, fi.EncryptFileNames); } bool CCompressDialog::IsSFX() @@ -483,10 +505,48 @@ void CCompressDialog::OnButtonSetArchive() // in ExtractDialog.cpp extern void AddUniqueString(UStringVector &strings, const UString &srcString); +static bool IsAsciiString(const UString &s) +{ + for (int i = 0; i < s.Length(); i++) + { + wchar_t c = s[i]; + if (c < 0x20 || c > 0x7F) + return false; + } + return true; +} void CCompressDialog::OnOK() { - _passwordControl.GetText(Info.Password); + _password1Control.GetText(Info.Password); + if (IsZipFormat()) + { + if (!IsAsciiString(Info.Password)) + { + MyMessageBoxResource(*this, IDS_PASSWORD_USE_ASCII, 0x02000B11); + return; + } + UString method = GetEncryptionMethodSpec(); + method.MakeUpper(); + if (method.Find(L"AES") == 0) + { + if (Info.Password.Length() > 99) + { + MyMessageBoxResource(*this, IDS_PASSWORD_IS_TOO_LONG, 0x02000B12); + return; + } + } + } + if (!IsShowPasswordChecked()) + { + UString password2; + _password2Control.GetText(password2); + if (password2 != Info.Password) + { + MyMessageBoxResource(*this, IDS_PASSWORD_PASSWORDS_DO_NOT_MATCH, 0x02000B10); + return; + } + } SaveOptionsInMem(); UString s; @@ -502,6 +562,7 @@ void CCompressDialog::OnOK() Info.Order = GetOrderSpec(); Info.OrderMode = GetOrderMode(); Info.Method = GetMethodSpec(); + Info.EncryptionMethod = GetEncryptionMethodSpec(); Info.ArchiverInfoIndex = m_Format.GetCurSel(); @@ -518,7 +579,7 @@ void CCompressDialog::OnOK() if (!volumeString.IsEmpty()) if (!ParseVolumeSizes(volumeString, Info.VolumeSizes)) { - MessageBox(*this, TEXT("Incorrect volume size"), TEXT("7-Zip"), 0); + MyMessageBoxResource(*this, IDS_COMPRESS_INCORRECT_VOLUME_SIZE, 0x02000D41); return; } @@ -538,8 +599,7 @@ void CCompressDialog::OnOK() m_RegistryInfo.Level = Info.Level; m_RegistryInfo.ArchiveType = m_ArchiverInfoList[Info.ArchiverInfoIndex].Name; - m_RegistryInfo.ShowPassword = (IsButtonChecked( - IDC_COMPRESS_CHECK_SHOW_PASSWORD) == BST_CHECKED); + m_RegistryInfo.ShowPassword = IsShowPasswordChecked(); SaveCompressionInfo(m_RegistryInfo); @@ -569,7 +629,7 @@ bool CCompressDialog::OnCommand(int code, int itemID, LPARAM lParam) const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; int index = FindRegistryFormatAlways(ai.Name); NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; - fo.Init(); + fo.ResetForLevelChange(); SetMethod(); CheckSFXNameChange(); return true; @@ -628,6 +688,7 @@ void CCompressDialog::OnChangeFormat() SetParams(); CheckControlsEnable(); SetArchiveName2(isSFX); + SetEncryptionMethod(); } // if type.KeepName then use OriginalFileName @@ -732,7 +793,7 @@ void CCompressDialog::SetLevel() if ((fi.LevelsMask & (1 << i)) != 0) { const CLevelInfo &levelInfo = g_Levels[i]; - int index = m_Level.AddString(LangString(levelInfo.ResourceID, levelInfo.LangID)); + int index = (int)m_Level.AddString(LangString(levelInfo.ResourceID, levelInfo.LangID)); m_Level.SetItemData(index, i); } } @@ -744,7 +805,7 @@ int CCompressDialog::GetLevel() { if (m_Level.GetCount() <= 0) return -1; - return m_Level.GetItemData(m_Level.GetCurSel()); + return (int)m_Level.GetItemData(m_Level.GetCurSel()); } int CCompressDialog::GetLevelSpec() @@ -789,7 +850,7 @@ void CCompressDialog::SetMethod() if (index >= 0) { const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; - defaultMethod = GetUnicodeString(fo.Method); + defaultMethod = fo.Method; } bool isSfx = IsSFX(); for(int m = 0; m < fi.NumMethods; m++) @@ -799,7 +860,7 @@ void CCompressDialog::SetMethod() if (!IsMethodSupportedBySfx(methodID)) continue; const LPCWSTR method = kMethodsNames[methodID]; - int itemIndex = m_Method.AddString(GetSystemString(method)); + int itemIndex = (int)m_Method.AddString(GetSystemString(method)); if (defaultMethod.CompareNoCase(method) == 0 || m == 0) m_Method.SetCurSel(itemIndex); } @@ -807,6 +868,36 @@ void CCompressDialog::SetMethod() SetOrder(); } +bool CCompressDialog::IsZipFormat() +{ + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + return (ai.Name.CompareNoCase(L"zip") == 0); +} + +void CCompressDialog::SetEncryptionMethod() +{ + _encryptionMethod.ResetContent(); + const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; + if (ai.Name.CompareNoCase(L"7z") == 0) + { + _encryptionMethod.AddString(TEXT("AES-256")); + _encryptionMethod.SetCurSel(0); + } + else if (ai.Name.CompareNoCase(L"zip") == 0) + { + int index = FindRegistryFormat(ai.Name); + UString encryptionMethod; + if (index >= 0) + { + const NCompression::CFormatOptions &fo = m_RegistryInfo.FormatOptionsVector[index]; + encryptionMethod = fo.EncryptionMethod; + } + _encryptionMethod.AddString(TEXT("ZipCrypto")); + _encryptionMethod.AddString(TEXT("AES-256")); + _encryptionMethod.SetCurSel(encryptionMethod.Find(L"AES") == 0 ? 1 : 0); + } +} + int CCompressDialog::GetMethodID() { UString methodName; @@ -826,6 +917,18 @@ UString CCompressDialog::GetMethodSpec() return result; } +UString CCompressDialog::GetEncryptionMethodSpec() +{ + if (m_Method.GetCount() <= 1) + return UString(); + if (_encryptionMethod.GetCurSel() <= 0) + return UString(); + UString result; + _encryptionMethod.GetText(result); + result.Replace(L"-", L""); + return result; +} + int CCompressDialog::AddDictionarySize(UInt32 size, bool kilo, bool maga) { UInt32 sizePrint = size; @@ -842,7 +945,7 @@ int CCompressDialog::AddDictionarySize(UInt32 size, bool kilo, bool maga) else lstrcat(s, TEXT(" ")); lstrcat(s, TEXT("B")); - int index = m_Dictionary.AddString(s); + int index = (int)m_Dictionary.AddString(s); m_Dictionary.SetItemData(index, size); return index; } @@ -862,7 +965,6 @@ int CCompressDialog::AddDictionarySize(UInt32 size) void CCompressDialog::SetDictionary() { m_Dictionary.ResetContent(); - const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; int index = FindRegistryFormat(ai.Name); UInt32 defaultDictionary = UInt32(-1); @@ -884,7 +986,7 @@ void CCompressDialog::SetDictionary() { case kLZMA: { - static const kMinDicSize = (1 << 16); + static const UInt32 kMinDicSize = (1 << 16); if (defaultDictionary == UInt32(-1)) { if (level >= 9) @@ -993,14 +1095,14 @@ void CCompressDialog::SetDictionary() UInt32 CCompressDialog::GetDictionary() { if (m_Dictionary.GetCount() <= 0) - return -1; - return m_Dictionary.GetItemData(m_Dictionary.GetCurSel()); + return (UInt32)-1; + return (UInt32)m_Dictionary.GetItemData(m_Dictionary.GetCurSel()); } UInt32 CCompressDialog::GetDictionarySpec() { if (m_Dictionary.GetCount() <= 1) - return -1; + return (UInt32)-1; return GetDictionary(); } @@ -1008,7 +1110,7 @@ int CCompressDialog::AddOrder(UInt32 size) { TCHAR s[40]; ConvertUInt64ToString(size, s); - int index = m_Order.AddString(s); + int index = (int)m_Order.AddString(s); m_Order.SetItemData(index, size); return index; } @@ -1016,7 +1118,6 @@ int CCompressDialog::AddOrder(UInt32 size) void CCompressDialog::SetOrder() { m_Order.ResetContent(); - const CFormatInfo &fi = g_Formats[GetStaticFormatIndex()]; const CArchiverInfo &ai = m_ArchiverInfoList[m_Format.GetCurSel()]; int index = FindRegistryFormat(ai.Name); UInt32 defaultOrder = UInt32(-1); @@ -1122,14 +1223,14 @@ bool CCompressDialog::GetOrderMode() UInt32 CCompressDialog::GetOrder() { if (m_Order.GetCount() <= 0) - return -1; - return m_Order.GetItemData(m_Order.GetCurSel()); + return (UInt32)-1; + return (UInt32)m_Order.GetItemData(m_Order.GetCurSel()); } UInt32 CCompressDialog::GetOrderSpec() { if (m_Order.GetCount() <= 1) - return -1; + return (UInt32)-1; return GetOrder(); } @@ -1252,4 +1353,5 @@ void CCompressDialog::SaveOptionsInMem() fo.Dictionary = GetDictionarySpec(); fo.Order = GetOrderSpec(); fo.Method = GetMethodSpec(); + fo.EncryptionMethod = GetEncryptionMethodSpec(); } diff --git a/7zip/UI/GUI/CompressDialog.h b/7zip/UI/GUI/CompressDialog.h index 3425ca48..fc73b557 100755 --- a/7zip/UI/GUI/CompressDialog.h +++ b/7zip/UI/GUI/CompressDialog.h @@ -41,6 +41,8 @@ namespace NCompressDialog UInt32 Order; UString Options; + UString EncryptionMethod; + bool SFXMode; UString ArchiveName; // in: Relative for ; out: abs @@ -61,6 +63,7 @@ namespace NCompressDialog OrderMode = false; Method.Empty(); Options.Empty(); + EncryptionMethod.Empty(); } CInfo() { @@ -81,8 +84,9 @@ class CCompressDialog: public NWindows::NControl::CModalDialog NWindows::NControl::CComboBox m_Volume; NWindows::NControl::CDialogChildControl m_Params; - NWindows::NControl::CEdit _passwordControl; - + NWindows::NControl::CEdit _password1Control; + NWindows::NControl::CEdit _password2Control; + NWindows::NControl::CComboBox _encryptionMethod; NCompression::CInfo m_RegistryInfo; @@ -109,6 +113,11 @@ class CCompressDialog: public NWindows::NControl::CModalDialog void SetMethod(); int GetMethodID(); UString GetMethodSpec(); + UString GetEncryptionMethodSpec(); + + bool IsZipFormat(); + + void SetEncryptionMethod(); int AddDictionarySize(UInt32 size, bool kilo, bool maga); int AddDictionarySize(UInt32 size); @@ -131,6 +140,8 @@ class CCompressDialog: public NWindows::NControl::CModalDialog void SaveOptionsInMem(); void UpdatePasswordControl(); + bool IsShowPasswordChecked() const + { return IsButtonChecked(IDC_COMPRESS_CHECK_SHOW_PASSWORD) == BST_CHECKED; } public: CObjectVector m_ArchiverInfoList; diff --git a/7zip/UI/GUI/ExtractGUI.cpp b/7zip/UI/GUI/ExtractGUI.cpp index a076f3d0..395df5a9 100755 --- a/7zip/UI/GUI/ExtractGUI.cpp +++ b/7zip/UI/GUI/ExtractGUI.cpp @@ -46,7 +46,7 @@ struct CThreadExtracting try { Result = DecompressArchives(*ArchivePaths, *ArchivePathsFull, - *WildcardCensor, *Options, OpenCallback, ExtractCallback); + *WildcardCensor, *Options, OpenCallback, ExtractCallback, ErrorMessage); } catch(const UString &s) { diff --git a/7zip/UI/GUI/GUI.cpp b/7zip/UI/GUI/GUI.cpp index cd26f35f..fe956dbd 100755 --- a/7zip/UI/GUI/GUI.cpp +++ b/7zip/UI/GUI/GUI.cpp @@ -17,6 +17,7 @@ #include "Windows/FileName.h" #ifdef _WIN32 #include "Windows/MemoryLock.h" +#include "Common/Alloc.h" #endif #include "../../IStream.h" @@ -168,7 +169,7 @@ static bool inline IsItWindowsNT() return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); } -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */) { g_hInstance = hInstance; #ifdef _UNICODE @@ -181,6 +182,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi g_IsNT = IsItWindowsNT(); #endif + #ifdef _WIN32 + SetLargePageSize(); + #endif + InitCommonControls(); ReloadLang(); @@ -195,6 +200,11 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi MyMessageBox(kMemoryExceptionMessage); return (NExitCode::kMemoryError); } + catch(const CArchiveCommandLineException &e) + { + MyMessageBox(GetUnicodeString(e)); + return (NExitCode::kUserError); + } catch(const CSystemException &systemError) { if (systemError.ErrorCode == E_OUTOFMEMORY) @@ -224,6 +234,11 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi MyMessageBox(s); return (NExitCode::kFatalError); } + catch(const AString &s) + { + MyMessageBox(GetUnicodeString(s)); + return (NExitCode::kFatalError); + } catch(const char *s) { MyMessageBox(GetUnicodeString(s)); diff --git a/7zip/UI/GUI/GUI.dsp b/7zip/UI/GUI/GUI.dsp index 0483b53a..ef9aba16 100755 --- a/7zip/UI/GUI/GUI.dsp +++ b/7zip/UI/GUI/GUI.dsp @@ -329,6 +329,10 @@ SOURCE=..\..\..\Windows\Control\ListView.cpp SOURCE=..\..\..\Windows\Control\ListView.h # End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\Control\ProgressBar.h +# End Source File # End Group # Begin Source File diff --git a/7zip/UI/GUI/OpenCallbackGUI.cpp b/7zip/UI/GUI/OpenCallbackGUI.cpp index a3a6caf0..6634c0b3 100755 --- a/7zip/UI/GUI/OpenCallbackGUI.cpp +++ b/7zip/UI/GUI/OpenCallbackGUI.cpp @@ -17,12 +17,12 @@ HRESULT COpenCallbackGUI::CheckBreak() return S_OK; } -HRESULT COpenCallbackGUI::SetTotal(const UInt64 *files, const UInt64 *bytes) +HRESULT COpenCallbackGUI::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */) { return S_OK; } -HRESULT COpenCallbackGUI::SetCompleted(const UInt64 *files, const UInt64 *bytes) +HRESULT COpenCallbackGUI::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */) { return S_OK; } diff --git a/7zip/UI/GUI/UpdateCallbackGUI.cpp b/7zip/UI/GUI/UpdateCallbackGUI.cpp index 61f27d61..eff29953 100755 --- a/7zip/UI/GUI/UpdateCallbackGUI.cpp +++ b/7zip/UI/GUI/UpdateCallbackGUI.cpp @@ -73,7 +73,7 @@ HRESULT CUpdateCallbackGUI::FinishScanning() return S_OK; } -HRESULT CUpdateCallbackGUI::StartArchive(const wchar_t *name, bool updating) +HRESULT CUpdateCallbackGUI::StartArchive(const wchar_t *name, bool /* updating */) { ProgressDialog.ProgressSynch.SetTitleFileName(name); return S_OK; @@ -86,7 +86,7 @@ HRESULT CUpdateCallbackGUI::FinishArchive() HRESULT CUpdateCallbackGUI::CheckBreak() { - while(true) + for (;;) { if(ProgressDialog.ProgressSynch.GetStopped()) return E_ABORT; @@ -116,7 +116,7 @@ HRESULT CUpdateCallbackGUI::SetCompleted(const UInt64 *completeValue) return S_OK; } -HRESULT CUpdateCallbackGUI::GetStream(const wchar_t *name, bool isAnti) +HRESULT CUpdateCallbackGUI::GetStream(const wchar_t *name, bool /* isAnti */) { ProgressDialog.ProgressSynch.SetCurrentFileName(name); return S_OK; @@ -130,10 +130,10 @@ HRESULT CUpdateCallbackGUI::OpenFileError(const wchar_t *name, DWORD systemError AddErrorMessage(name, systemError); return S_FALSE; } - return systemError; + // return systemError; } -HRESULT CUpdateCallbackGUI::SetOperationResult(Int32 operationResult) +HRESULT CUpdateCallbackGUI::SetOperationResult(Int32 /* operationResult */) { return S_OK; } diff --git a/7zip/UI/GUI/UpdateGUI.cpp b/7zip/UI/GUI/UpdateGUI.cpp index a3f6b449..e39e7faf 100755 --- a/7zip/UI/GUI/UpdateGUI.cpp +++ b/7zip/UI/GUI/UpdateGUI.cpp @@ -7,6 +7,7 @@ #include "resource.h" #include "Common/StringConvert.h" #include "Common/IntToString.h" +#include "Common/StringToInt.h" #include "Windows/FileDir.h" #include "Windows/Error.h" @@ -103,6 +104,30 @@ static void AddProp(CObjectVector &properties, AddProp(properties, name, value ? UString(L"on"): UString(L"off")); } +static bool IsThereMethodOverride(bool is7z, const UString &propertiesString) +{ + UStringVector strings; + SplitString(propertiesString, strings); + for (int i = 0; i < strings.Size(); i++) + { + const UString &s = strings[i]; + if (is7z) + { + const wchar_t *end; + UInt64 n = ConvertStringToUInt64(s, &end); + if (n == 0 && *end == L'=') + return true; + } + else + { + if (s.Length() > 0) + if (s[0] == L'm' && s[1] == L'=') + return true; + } + } + return false; +} + static void ParseAndAddPropertires(CObjectVector &properties, const UString &propertiesString) { @@ -128,45 +153,55 @@ static void SetOutProperties( CObjectVector &properties, bool is7z, UInt32 level, + bool setMethod, const UString &method, UInt32 dictionary, bool orderMode, UInt32 order, bool solidModeIsAllowed, bool solidMode, bool multiThreadIsAllowed, bool multiThread, + const UString &encryptionMethod, bool encryptHeadersIsAllowed, bool encryptHeaders, - bool sfxMode) + bool /* sfxMode */) { if (level != (UInt32)(Int32)-1) AddProp(properties, L"x", (UInt32)level); - if (!method.IsEmpty()) - AddProp(properties, is7z ? L"0": L"m", method); - if (dictionary != (UInt32)(Int32)-1) + if (setMethod) { - UString name; - if (is7z) - name = L"0"; - if (orderMode) - name += L"mem"; - else - name += L"d"; - wchar_t s[32]; - ConvertUInt64ToString(dictionary, s); - wcscat(s, L"B"); - AddProp(properties, name, UString(s)); - } - if (order != (UInt32)(Int32)-1) - { - UString name; - if (is7z) - name = L"0"; - if (orderMode) - name += L"o"; - else - name += L"fb"; - AddProp(properties, name, (UInt32)order); + if (!method.IsEmpty()) + AddProp(properties, is7z ? L"0": L"m", method); + if (dictionary != (UInt32)(Int32)-1) + { + UString name; + if (is7z) + name = L"0"; + if (orderMode) + name += L"mem"; + else + name += L"d"; + wchar_t s[32]; + ConvertUInt64ToString(dictionary, s); + size_t len = wcslen(s); + s[len++] = L'B'; + s[len] = L'\0'; + AddProp(properties, name, UString(s)); + } + if (order != (UInt32)(Int32)-1) + { + UString name; + if (is7z) + name = L"0"; + if (orderMode) + name += L"o"; + else + name += L"fb"; + AddProp(properties, name, (UInt32)order); + } } - + + if (!encryptionMethod.IsEmpty()) + AddProp(properties, L"em", encryptionMethod); + if (encryptHeadersIsAllowed) AddProp(properties, L"he", encryptHeaders); if (solidModeIsAllowed) @@ -277,25 +312,30 @@ static HRESULT ShowDialog(const NWildcard::CCensor &censor, throw 1091756; } archiverInfo = dialog.m_ArchiverInfoList[di.ArchiverInfoIndex]; - if (callback->PasswordIsDefined = (!di.Password.IsEmpty())) + callback->PasswordIsDefined = (!di.Password.IsEmpty()); + if (callback->PasswordIsDefined) callback->Password = di.Password; options.MethodMode.Properties.Clear(); + bool is7z = archiverInfo.Name.CompareNoCase(L"7z") == 0; + bool methodOverride = IsThereMethodOverride(is7z, di.Options); + SetOutProperties( options.MethodMode.Properties, - archiverInfo.Name.CompareNoCase(L"7z") == 0, + is7z, di.Level, + !methodOverride, di.Method, di.Dictionary, di.OrderMode, di.Order, di.SolidIsAllowed, di.Solid, di.MultiThreadIsAllowed, di.MultiThread, + di.EncryptionMethod, di.EncryptHeadersIsAllowed, di.EncryptHeaders, di.SFXMode); - ParseAndAddPropertires(options.MethodMode.Properties, - di.Options); + ParseAndAddPropertires(options.MethodMode.Properties, di.Options); if (di.SFXMode) options.SfxMode = true; diff --git a/7zip/UI/GUI/resource.h b/7zip/UI/GUI/resource.h index b999873d..af4fdc0b 100755 --- a/7zip/UI/GUI/resource.h +++ b/7zip/UI/GUI/resource.h @@ -22,6 +22,8 @@ #define IDS_COMPRESS_UPDATE_MODE_FRESH 92 #define IDS_COMPRESS_UPDATE_MODE_SYNCHRONIZE 93 +#define IDS_COMPRESS_INCORRECT_VOLUME_SIZE 95 + #define IDS_COMPRESS_SET_ARCHIVE_DIALOG_TITLE 96 #define IDS_CANT_UPDATE_ARCHIVE 97 @@ -31,6 +33,9 @@ #define IDS_MESSAGE_NO_ERRORS 101 #define IDS_CONFIG_DIALOG_CAPTION 102 +#define IDS_PASSWORD_USE_ASCII 110 +#define IDS_PASSWORD_PASSWORDS_DO_NOT_MATCH 111 +#define IDS_PASSWORD_IS_TOO_LONG 112 #define IDD_DIALOG_EXTRACT 137 #define IDB_DELETE 149 diff --git a/7zip/UI/GUI/resource.rc b/7zip/UI/GUI/resource.rc index c8590711..ace71177 100755 --- a/7zip/UI/GUI/resource.rc +++ b/7zip/UI/GUI/resource.rc @@ -32,6 +32,12 @@ BEGIN IDS_COMPRESS_UPDATE_MODE_FRESH "Freshen existing files" IDS_COMPRESS_UPDATE_MODE_SYNCHRONIZE "Synchronize files" IDS_COMPRESS_SET_ARCHIVE_DIALOG_TITLE "Browse" + IDS_COMPRESS_INCORRECT_VOLUME_SIZE "Incorrect volume size" + + IDS_PASSWORD_USE_ASCII "Use only English letters, numbers and special characters (!, #, $, ...) for password." + IDS_PASSWORD_PASSWORDS_DO_NOT_MATCH "Passwords do not match" + IDS_PASSWORD_IS_TOO_LONG "Password is too long" + IDS_CANT_UPDATE_ARCHIVE "Can not update archive '{0}'" IDS_PROGRESS_COMPRESSING "Compressing" IDS_PROGRESS_TESTING "Testing" diff --git a/7zip/UI/Resource/CompressDialog/resource.h b/7zip/UI/Resource/CompressDialog/resource.h index 93837032..847bb3f9 100755 --- a/7zip/UI/Resource/CompressDialog/resource.h +++ b/7zip/UI/Resource/CompressDialog/resource.h @@ -26,7 +26,15 @@ #define IDC_STATIC_COMPRESS_METHOD 1104 #define IDC_STATIC_COMPRESS_DICTIONARY 1105 #define IDC_STATIC_COMPRESS_ORDER 1106 -#define IDC_COMPRESS_PASSWORD 1107 -#define IDC_COMPRESS_EDIT_PASSWORD 1108 -#define IDC_COMPRESS_CHECK_SHOW_PASSWORD 1109 -#define IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES 1110 + +#define IDC_COMPRESS_ENCRYPTION 1110 +#define IDC_STATIC_COMPRESS_PASSWORD1 1111 +#define IDC_COMPRESS_EDIT_PASSWORD1 1112 +#define IDC_STATIC_COMPRESS_PASSWORD2 1113 +#define IDC_COMPRESS_EDIT_PASSWORD2 1114 +#define IDC_COMPRESS_CHECK_SHOW_PASSWORD 1115 + +#define IDC_STATIC_COMPRESS_ENCRYPTION_METHOD 1120 +#define IDC_COMPRESS_COMBO_ENCRYPTION_METHOD 1121 + +#define IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES 1122 diff --git a/7zip/UI/Resource/CompressDialog/resource.rc b/7zip/UI/Resource/CompressDialog/resource.rc index 33779409..9019a1af 100755 --- a/7zip/UI/Resource/CompressDialog/resource.rc +++ b/7zip/UI/Resource/CompressDialog/resource.rc @@ -2,7 +2,7 @@ #include "../../../GuiCommon.rc" #define xSize2 344 -#define ySize2 260 +#define ySize2 295 #define xSize (xSize2 + marg + marg) #define ySize (ySize2 + marg + marg) @@ -82,11 +82,11 @@ BEGIN CONTROL "Multi-threading", IDC_COMPRESS_MULTI_THREAD, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, marg, 195, gSize, 10 - LTEXT "Split to &volumes, bytes:", IDC_STATIC_COMPRESS_VOLUME, g4XPos, 184, g4XSize, 8 - COMBOBOX IDC_COMPRESS_COMBO_VOLUME, g4XPos, 196, g4XSize, 73, CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP + LTEXT "Split to &volumes, bytes:", IDC_STATIC_COMPRESS_VOLUME, marg, 215, gSize, 8 + COMBOBOX IDC_COMPRESS_COMBO_VOLUME, marg, 227, gSize, 73, CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP - LTEXT "&Parameters:",IDC_STATIC_COMPRESS_PARAMETERS, marg, 214, xSize2, 8 - EDITTEXT IDC_COMPRESS_EDIT_PARAMETERS, marg, 225, xSize2, 14, ES_AUTOHSCROLL + LTEXT "&Parameters:",IDC_STATIC_COMPRESS_PARAMETERS, marg, 250, xSize2, 8 + EDITTEXT IDC_COMPRESS_EDIT_PARAMETERS, marg, 262, xSize2, 14, ES_AUTOHSCROLL LTEXT "&Update mode:",IDC_STATIC_COMPRESS_UPDATE_MODE, g4XPos, 39, g4XSize, 8 COMBOBOX IDC_COMPRESS_COMBO_UPDATE_MODE, g4XPos, 51, g4XSize, 80, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP @@ -95,12 +95,21 @@ BEGIN CONTROL "Create SF&X archive",IDC_COMPRESS_SFX, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, g4XPos2, 87, g4XSize2, 10 - GROUPBOX "Password",IDC_COMPRESS_PASSWORD, g4XPos, 113, g4XSize, 63 - EDITTEXT IDC_COMPRESS_EDIT_PASSWORD, g4XPos2, 127, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL + GROUPBOX "Encryption",IDC_COMPRESS_ENCRYPTION, g4XPos, 113, g4XSize, 127 + + LTEXT "Enter password:",IDC_STATIC_COMPRESS_PASSWORD1, g4XPos2, 127, g4XSize2, 8 + EDITTEXT IDC_COMPRESS_EDIT_PASSWORD1, g4XPos2, 139, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL + LTEXT "Reenter password:",IDC_STATIC_COMPRESS_PASSWORD2, g4XPos2, 159, g4XSize2, 8 + EDITTEXT IDC_COMPRESS_EDIT_PASSWORD2, g4XPos2, 171, g4XSize2, 14, ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Show Password",IDC_COMPRESS_CHECK_SHOW_PASSWORD,"Button", BS_AUTOCHECKBOX | WS_TABSTOP, - g4XPos2, 145, g4XSize2, 10 + g4XPos2, 192, g4XSize2, 10 + + LTEXT "&Encryption method:",IDC_STATIC_COMPRESS_ENCRYPTION_METHOD, g4XPos2, 208, 80, 8 + COMBOBOX IDC_COMPRESS_COMBO_ENCRYPTION_METHOD, g4XPos2 + 90, 206, g4XSize2 - 90, 198, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Encrypt file &names", IDC_COMPRESS_CHECK_ENCRYPT_FILE_NAMES, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, - g4XPos2, 159, g4XSize2, 10 + g4XPos2, 224, g4XSize2, 10 DEFPUSHBUTTON "OK", IDOK, bXPos3, bYPos, bXSize, bYSize, WS_GROUP PUSHBUTTON "Cancel", IDCANCEL, bXPos2, bYPos, bXSize, bYSize diff --git a/7zip/UI/Resource/Extract/resource.h b/7zip/UI/Resource/Extract/resource.h index 4038e986..4cee4183 100755 --- a/7zip/UI/Resource/Extract/resource.h +++ b/7zip/UI/Resource/Extract/resource.h @@ -4,7 +4,9 @@ #define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC 202 #define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR 203 #define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_UNSUPPORTED_METHOD 204 +#define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC_ENCRYPTED 205 +#define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR_ENCRYPTED 206 -#define IDS_EXTRACT_SET_FOLDER 205 -#define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CANNOT_OPEN_FILE 206 -#define IDS_PROGRESS_EXTRACTING 207 +#define IDS_EXTRACT_SET_FOLDER 207 +#define IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CANNOT_OPEN_FILE 208 +#define IDS_PROGRESS_EXTRACTING 209 diff --git a/7zip/UI/Resource/Extract/resource.rc b/7zip/UI/Resource/Extract/resource.rc index 66e0b4d4..f4cf5a1f 100755 --- a/7zip/UI/Resource/Extract/resource.rc +++ b/7zip/UI/Resource/Extract/resource.rc @@ -7,7 +7,9 @@ BEGIN IDS_CANNOT_CREATE_FOLDER "Cannot create folder '{0}'" IDS_OPEN_IS_NOT_SUPORTED_ARCHIVE "File is not supported archive." IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC "CRC failed in '{0}'. File is broken." - IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR "Data error in '{0}'. File is broken." + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR "Data error in '{0}'. File is broken" + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CRC_ENCRYPTED "CRC failed in encrypted file '{0}'. Wrong password?" + IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_DATA_ERROR_ENCRYPTED "Data error in encrypted file '{0}'. Wrong password?" IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_UNSUPPORTED_METHOD "Unsupported compression method for '{0}'." IDS_EXTRACT_SET_FOLDER "Specify a location for extracted files." IDS_MESSAGES_DIALOG_EXTRACT_MESSAGE_CANNOT_OPEN_FILE "Can not open output file '{0}'." diff --git a/7zip/UI/makefile b/7zip/UI/makefile index f9ff7200..942beaa0 100755 --- a/7zip/UI/makefile +++ b/7zip/UI/makefile @@ -1,4 +1,5 @@ DIRS = \ + Client7z\~ \ Console\~ \ Explorer\~ \ GUI\~ \ diff --git a/Build.mak b/Build.mak index d4f08684..4f25c853 100755 --- a/Build.mak +++ b/Build.mak @@ -19,8 +19,17 @@ CFLAGS = $(CFLAGS) -MT !ELSE CFLAGS = $(CFLAGS) -MD !ENDIF -CFLAGS_O1 = $(CFLAGS) -O1 -CFLAGS_O2 = $(CFLAGS) -O2 + +!IFDEF NEW_COMPILER +CFLAGS_O1 = $(CFLAGS) -O1 -W4 -Wp64 +CFLAGS_O2 = $(CFLAGS) -O2 -W4 -Wp64 +!ELSE +CFLAGS_O1 = $(CFLAGS) -O1 -W3 +CFLAGS_O2 = $(CFLAGS) -O2 -W3 +!ENDIF + +CFLAGS_O1_W3 = $(CFLAGS) -O1 -W3 +CFLAGS_O2_W3 = $(CFLAGS) -O2 -W3 LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 @@ -32,6 +41,8 @@ PROGPATH = $O\$(PROG) COMPL_O1 = $(CPP) $(CFLAGS_O1) $** COMPL_O2 = $(CPP) $(CFLAGS_O2) $** +COMPL_O1_W3 = $(CPP) $(CFLAGS_O1_W3) $** +COMPL_O2_W3 = $(CPP) $(CFLAGS_O2_W3) $** COMPL_PCH = $(CPP) $(CFLAGS_O1) -Yc"StdAfx.h" -Fp$O/a.pch $** COMPL = $(CPP) $(CFLAGS_O1) -Yu"StdAfx.h" -Fp$O/a.pch $** diff --git a/Common/Alloc.cpp b/Common/Alloc.cpp index e2b8c3d2..e4fc6a81 100755 --- a/Common/Alloc.cpp +++ b/Common/Alloc.cpp @@ -62,6 +62,16 @@ void MidFree(void *address) throw() ::VirtualFree(address, 0, MEM_RELEASE); } + +#ifndef MEM_LARGE_PAGES +#define _7ZIP_NO_LARGE_PAGES +#endif + +// define _7ZIP_NO_LARGE_PAGES if you don't need LARGE_PAGES support +// #define _7ZIP_NO_LARGE_PAGES + + +#ifndef _7ZIP_NO_LARGE_PAGES static SIZE_T g_LargePageSize = #ifdef _WIN64 (1 << 21); @@ -70,9 +80,11 @@ static SIZE_T g_LargePageSize = #endif typedef SIZE_T (WINAPI *GetLargePageMinimumP)(); +#endif bool SetLargePageSize() { + #ifndef _7ZIP_NO_LARGE_PAGES GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP) ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); if (largePageMinimum == 0) @@ -81,6 +93,7 @@ bool SetLargePageSize() if (size == 0 || (size & (size - 1)) != 0) return false; g_LargePageSize = size; + #endif return true; } @@ -93,6 +106,7 @@ void *BigAlloc(size_t size) throw() fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); #endif + #ifndef _7ZIP_NO_LARGE_PAGES if (size >= (1 << 18)) { void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), @@ -100,6 +114,7 @@ void *BigAlloc(size_t size) throw() if (res != 0) return res; } + #endif return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); } diff --git a/Common/CommandLineParser.cpp b/Common/CommandLineParser.cpp index 69c41841..67f72675 100755 --- a/Common/CommandLineParser.cpp +++ b/Common/CommandLineParser.cpp @@ -33,7 +33,7 @@ void SplitCommandLine(const UString &s, UStringVector &parts) UString sTemp = s; sTemp.Trim(); parts.Clear(); - while (true) + for (;;) { UString s1, s2; SplitCommandLine(sTemp, s1, s2); @@ -42,7 +42,7 @@ void SplitCommandLine(const UString &s, UStringVector &parts) if (!s1.IsEmpty()) parts.Add(s1); if (s2.IsEmpty()) - return; + break; sTemp = s2; } } diff --git a/Common/CommandLineParser.h b/Common/CommandLineParser.h index af698db8..f59d8e4c 100755 --- a/Common/CommandLineParser.h +++ b/Common/CommandLineParser.h @@ -3,7 +3,7 @@ #ifndef __COMMON_COMMANDLINEPARSER_H #define __COMMON_COMMANDLINEPARSER_H -#include "Common/String.h" +#include "String.h" namespace NCommandLineParser { diff --git a/Common/IntToString.cpp b/Common/IntToString.cpp index d841635d..7d81d966 100755 --- a/Common/IntToString.cpp +++ b/Common/IntToString.cpp @@ -16,7 +16,7 @@ void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base) do { int delta = (int)(value % base); - temp[pos++] = (delta < 10) ? ('0' + delta) : ('a' + (delta - 10)); + temp[pos++] = (char)((delta < 10) ? ('0' + delta) : ('a' + (delta - 10))); value /= base; } while (value != 0); @@ -32,7 +32,7 @@ void ConvertUInt64ToString(UInt64 value, wchar_t *s) int pos = 0; do { - temp[pos++] = L'0' + (int)(value % 10); + temp[pos++] = (wchar_t)(L'0' + (int)(value % 10)); value /= 10; } while (value != 0); diff --git a/Common/StdInStream.cpp b/Common/StdInStream.cpp index 8da30738..923f366e 100755 --- a/Common/StdInStream.cpp +++ b/Common/StdInStream.cpp @@ -5,6 +5,11 @@ #include #include "StdInStream.h" +#ifdef _MSC_VER +// "was declared deprecated" disabling +#pragma warning(disable : 4996 ) +#endif + static const char kIllegalChar = '\0'; static const char kNewLineChar = '\n'; @@ -40,7 +45,7 @@ CStdInStream::~CStdInStream() AString CStdInStream::ScanStringUntilNewLine() { AString s; - while(true) + for (;;) { int intChar = GetChar(); if(intChar == EOF) @@ -49,9 +54,10 @@ AString CStdInStream::ScanStringUntilNewLine() if (c == kIllegalChar) throw kIllegalCharMessage; if(c == kNewLineChar) - return s; + break; s += c; } + return s; } void CStdInStream::ReadToString(AString &resultString) diff --git a/Common/StdOutStream.cpp b/Common/StdOutStream.cpp index 5ab0f10b..5f1ef0fc 100755 --- a/Common/StdOutStream.cpp +++ b/Common/StdOutStream.cpp @@ -8,6 +8,11 @@ #include "Common/IntToString.h" #include "Common/StringConvert.h" +#ifdef _MSC_VER +// "was declared deprecated" disabling +#pragma warning(disable : 4996 ) +#endif + static const char kNewLineChar = '\n'; static const char *kFileOpenMode = "wt"; @@ -27,14 +32,15 @@ bool CStdOutStream::Close() { if(!_streamIsOpen) return true; - _streamIsOpen = (fclose(_stream) != 0); - return !_streamIsOpen; + if (fclose(_stream) != 0) + return false; + _stream = 0; + _streamIsOpen = false; + return true; } bool CStdOutStream::Flush() { - if(!_streamIsOpen) - return false; return (fflush(_stream) == 0); } diff --git a/Common/StdOutStream.h b/Common/StdOutStream.h index e8aba74a..a3b11979 100755 --- a/Common/StdOutStream.h +++ b/Common/StdOutStream.h @@ -12,7 +12,7 @@ class CStdOutStream bool _streamIsOpen; FILE *_stream; public: - CStdOutStream (): _streamIsOpen(false) {}; + CStdOutStream (): _streamIsOpen(false), _stream(0) {}; CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {}; ~CStdOutStream (); bool Open(const char *fileName); diff --git a/Common/String.cpp b/Common/String.cpp index 7921fe41..34da1487 100755 --- a/Common/String.cpp +++ b/Common/String.cpp @@ -8,7 +8,7 @@ #include #endif -#include "Common/String.h" +#include "String.h" #ifdef _WIN32 @@ -19,9 +19,9 @@ wchar_t MyCharUpper(wchar_t c) { if (c == 0) return 0; - wchar_t *res = CharUpperW((LPWSTR)(unsigned int)c); + wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return (wchar_t)(unsigned int)res; + return (wchar_t)(unsigned int)(UINT_PTR)res; const int kBufferSize = 4; char s[kBufferSize + 1]; int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0); @@ -37,9 +37,9 @@ wchar_t MyCharLower(wchar_t c) { if (c == 0) return 0; - wchar_t *res = CharLowerW((LPWSTR)(unsigned int)c); + wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return (wchar_t)(unsigned int)res; + return (wchar_t)(unsigned int)(UINT_PTR)res; const int kBufferSize = 4; char s[kBufferSize + 1]; int numChars = ::WideCharToMultiByte(CP_ACP, 0, &c, 1, s, kBufferSize, 0, 0); @@ -133,7 +133,7 @@ wchar_t MyCharUpper(wchar_t c) /* int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2) { - while (true) + for (;;) { wchar_t c1 = *s1++; wchar_t c2 = *s2++; @@ -151,7 +151,7 @@ int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2) int MyStringCompare(const char *s1, const char *s2) { - while (true) + for (;;) { unsigned char c1 = (unsigned char)*s1++; unsigned char c2 = (unsigned char)*s2++; @@ -163,7 +163,7 @@ int MyStringCompare(const char *s1, const char *s2) int MyStringCompare(const wchar_t *s1, const wchar_t *s2) { - while (true) + for (;;) { wchar_t c1 = *s1++; wchar_t c2 = *s2++; @@ -175,7 +175,7 @@ int MyStringCompare(const wchar_t *s1, const wchar_t *s2) int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) { - while (true) + for (;;) { wchar_t c1 = *s1++; wchar_t c2 = *s2++; diff --git a/Common/String.h b/Common/String.h index c4277c1c..d38cc462 100755 --- a/Common/String.h +++ b/Common/String.h @@ -52,7 +52,7 @@ inline const char* MyStringGetPrevCharPointer(const char *base, const char *p) { return CharPrevA(base, p); } inline char MyCharUpper(char c) - { return (char)(unsigned int)CharUpperA((LPSTR)(unsigned int)(unsigned char)c); } + { return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); } #ifdef _UNICODE inline wchar_t MyCharUpper(wchar_t c) { return (wchar_t)CharUpperW((LPWSTR)c); } @@ -61,7 +61,7 @@ wchar_t MyCharUpper(wchar_t c); #endif inline char MyCharLower(char c) - { return (char)(unsigned int)CharLowerA((LPSTR)(unsigned int)(unsigned char)c); } + { return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); } #ifdef _UNICODE inline wchar_t MyCharLower(wchar_t c) { return (wchar_t)CharLowerW((LPWSTR)c); } @@ -373,7 +373,7 @@ public: int Find(T c, int startIndex) const { T *p = _chars + startIndex; - while (true) + for (;;) { if (*p == c) return (int)(p - _chars); @@ -403,7 +403,7 @@ public: if (_length == 0) return -1; T *p = _chars + _length - 1; - while (true) + for (;;) { if (*p == c) return (int)(p - _chars); diff --git a/Common/StringConvert.h b/Common/StringConvert.h index 648ca028..84eaed9a 100755 --- a/Common/StringConvert.h +++ b/Common/StringConvert.h @@ -4,7 +4,7 @@ #define __COMMON_STRINGCONVERT_H #include "MyWindows.h" -#include "Common/String.h" +#include "String.h" #include "Types.h" UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP); @@ -43,9 +43,9 @@ inline AString GetOemString(const UString &unicodeString) { return unicodeString;} inline const UString& GetSystemString(const UString &unicodeString) { return unicodeString;} - inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT codePage) + inline const wchar_t* GetSystemString(const wchar_t* unicodeString, UINT /* codePage */) { return unicodeString;} - inline const UString& GetSystemString(const UString &unicodeString, UINT codePage) + inline const UString& GetSystemString(const UString &unicodeString, UINT /* codePage */) { return unicodeString;} inline UString GetSystemString(const AString &multiByteString, UINT codePage) { return MultiByteToUnicodeString(multiByteString, codePage);} diff --git a/Common/StringToInt.cpp b/Common/StringToInt.cpp index 1fa8ef21..ec6733e3 100755 --- a/Common/StringToInt.cpp +++ b/Common/StringToInt.cpp @@ -7,7 +7,7 @@ UInt64 ConvertStringToUInt64(const char *s, const char **end) { UInt64 result = 0; - while(true) + for (;;) { char c = *s; if (c < '0' || c > '9') @@ -25,7 +25,7 @@ UInt64 ConvertStringToUInt64(const char *s, const char **end) UInt64 ConvertOctStringToUInt64(const char *s, const char **end) { UInt64 result = 0; - while(true) + for (;;) { char c = *s; if (c < '0' || c > '7') @@ -44,7 +44,7 @@ UInt64 ConvertOctStringToUInt64(const char *s, const char **end) UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) { UInt64 result = 0; - while(true) + for (;;) { wchar_t c = *s; if (c < '0' || c > '9') diff --git a/Common/TextConfig.cpp b/Common/TextConfig.cpp index 1d355e8a..4fce320a 100755 --- a/Common/TextConfig.cpp +++ b/Common/TextConfig.cpp @@ -16,13 +16,14 @@ static bool IsDelimitChar(char c) static AString GetIDString(const char *string, int &finishPos) { AString result; - for (finishPos = 0; true; finishPos++) + for (finishPos = 0; ; finishPos++) { char c = string[finishPos]; if (IsDelimitChar(c) || c == '=') - return result; + break; result += c; } + return result; } static bool WaitNextLine(const AString &string, int &pos) @@ -57,7 +58,7 @@ bool GetTextConfig(const AString &string, CObjectVector &pairs) ///////////////////// // read strings - while (true) + for (;;) { if (!SkipSpaces(string, pos)) break; @@ -80,7 +81,7 @@ bool GetTextConfig(const AString &string, CObjectVector &pairs) return false; pos++; AString message; - while(true) + for (;;) { if (pos >= string.Length()) return false; diff --git a/Common/Types.h b/Common/Types.h index 0bf66e08..41d785e9 100755 --- a/Common/Types.h +++ b/Common/Types.h @@ -3,17 +3,55 @@ #ifndef __COMMON_TYPES_H #define __COMMON_TYPES_H +#ifndef _7ZIP_BYTE_DEFINED +#define _7ZIP_BYTE_DEFINED typedef unsigned char Byte; +#endif + +#ifndef _7ZIP_INT16_DEFINED +#define _7ZIP_INT16_DEFINED typedef short Int16; +#endif + +#ifndef _7ZIP_UINT16_DEFINED +#define _7ZIP_UINT16_DEFINED typedef unsigned short UInt16; +#endif + +#ifndef _7ZIP_INT32_DEFINED +#define _7ZIP_INT32_DEFINED typedef int Int32; +#endif + +#ifndef _7ZIP_UINT32_DEFINED +#define _7ZIP_UINT32_DEFINED typedef unsigned int UInt32; +#endif + #ifdef _MSC_VER + +#ifndef _7ZIP_INT64_DEFINED +#define _7ZIP_INT64_DEFINED typedef __int64 Int64; +#endif + +#ifndef _7ZIP_UINT64_DEFINED +#define _7ZIP_UINT64_DEFINED typedef unsigned __int64 UInt64; +#endif + #else + +#ifndef _7ZIP_INT64_DEFINED +#define _7ZIP_INT64_DEFINED typedef long long int Int64; +#endif + +#ifndef _7ZIP_UINT64_DEFINED +#define _7ZIP_UINT64_DEFINED typedef unsigned long long int UInt64; +#endif + #endif #endif diff --git a/Common/Vector.cpp b/Common/Vector.cpp index cb3d8752..b3dd70a5 100755 --- a/Common/Vector.cpp +++ b/Common/Vector.cpp @@ -7,7 +7,16 @@ #include "Vector.h" CBaseRecordVector::~CBaseRecordVector() - { delete []((unsigned char *)_items); } + { Free(); } + +void CBaseRecordVector::Free() +{ + delete []((unsigned char *)_items); + _capacity = 0; + _size = 0; + _items = 0; +} + void CBaseRecordVector::Clear() { DeleteFrom(0); } void CBaseRecordVector::DeleteBack() diff --git a/Common/Vector.h b/Common/Vector.h index 210c385e..ee374cf3 100755 --- a/Common/Vector.h +++ b/Common/Vector.h @@ -22,11 +22,12 @@ public: CBaseRecordVector(size_t itemSize): _capacity(0), _size(0), _items(0), _itemSize(itemSize) {} virtual ~CBaseRecordVector(); + void Free(); int Size() const { return _size; } - bool IsEmpty() const { return (_size == 0); } - void Reserve(int newCapacity); - virtual void Delete(int index, int num = 1); - void Clear(); + bool IsEmpty() const { return (_size == 0); } + void Reserve(int newCapacity); + virtual void Delete(int index, int num = 1); + void Clear(); void DeleteFrom(int index); void DeleteBack(); }; @@ -38,7 +39,7 @@ public: CRecordVector():CBaseRecordVector(sizeof(T)){}; CRecordVector(const CRecordVector &v): CBaseRecordVector(sizeof(T)) { *this = v;} - CRecordVector& operator=(const CRecordVector &v) + CRecordVector& operator=(const CRecordVector &v) { Clear(); return (*this += v); @@ -220,7 +221,7 @@ public: void Sort(int (*compare)(void *const *, void *const *, void *), void *param) { CPointerVector::Sort(compare, param); } - static int CompareObjectItems(void *const *a1, void *const *a2, void *param) + static int CompareObjectItems(void *const *a1, void *const *a2, void * /* param */) { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); } void Sort() { CPointerVector::Sort(CompareObjectItems, 0); } }; diff --git a/DOC/7zC.txt b/DOC/7zC.txt index 4b2dda0a..88f039c5 100755 --- a/DOC/7zC.txt +++ b/DOC/7zC.txt @@ -1,7 +1,7 @@ -7z ANSI-C Decoder 4.23 +7z ANSI-C Decoder 4.43 ---------------------- -7z ANSI-C Decoder 4.23 Copyright (C) 1999-2005 Igor Pavlov +7z ANSI-C Decoder 4.43 Copyright (C) 1999-2006 Igor Pavlov 7z ANSI-C provides 7z/LZMA decoding. 7z ANSI-C version is simplified version ported from C++ code. diff --git a/DOC/7zFormat.txt b/DOC/7zFormat.txt index 56ff817c..e1cf7380 100755 --- a/DOC/7zFormat.txt +++ b/DOC/7zFormat.txt @@ -191,7 +191,7 @@ SignatureHeader ArchiveProperties ~~~~~~~~~~~~~~~~~ BYTE NID::kArchiveProperties (0x02) -while(true) +for (;;) { BYTE PropertyType; if (aType == 0) @@ -365,7 +365,7 @@ FilesInfo BYTE NID::kFilesInfo; (0x05) UINT64 NumFiles - while(true) + for (;;) { BYTE PropertyType; if (aType == 0) diff --git a/DOC/7zip.nsi b/DOC/7zip.nsi index 4d41dee2..572ef197 100755 --- a/DOC/7zip.nsi +++ b/DOC/7zip.nsi @@ -2,8 +2,8 @@ ;Defines !define VERSION_MAJOR 4 -!define VERSION_MINOR 42 -!define VERSION_POSTFIX_FULL "" +!define VERSION_MINOR 43 +!define VERSION_POSTFIX_FULL " beta" !ifdef WIN64 !ifdef IA64 !define VERSION_SYS_POSTFIX_FULL " for Windows IA-64" @@ -206,6 +206,7 @@ Section File he.txt File hr.txt File hu.txt + File hy.txt File id.txt File io.txt File it.txt @@ -217,6 +218,7 @@ Section File lv.txt File mk.txt File mn.txt + File mr.txt File ms.txt File nl.txt File no.txt @@ -415,6 +417,7 @@ Section "Uninstall" Delete $INSTDIR\Lang\he.txt Delete $INSTDIR\Lang\hr.txt Delete $INSTDIR\Lang\hu.txt + Delete $INSTDIR\Lang\hy.txt Delete $INSTDIR\Lang\id.txt Delete $INSTDIR\Lang\io.txt Delete $INSTDIR\Lang\it.txt @@ -426,6 +429,7 @@ Section "Uninstall" Delete $INSTDIR\Lang\lv.txt Delete $INSTDIR\Lang\mk.txt Delete $INSTDIR\Lang\mn.txt + Delete $INSTDIR\Lang\mr.txt Delete $INSTDIR\Lang\ms.txt Delete $INSTDIR\Lang\nl.txt Delete $INSTDIR\Lang\no.txt diff --git a/DOC/7zip.wxs b/DOC/7zip.wxs index 2da0d57d..6bf7f903 100755 --- a/DOC/7zip.wxs +++ b/DOC/7zip.wxs @@ -1,8 +1,8 @@ - - + + @@ -293,6 +293,7 @@ + @@ -304,6 +305,7 @@ + diff --git a/DOC/Methods.txt b/DOC/Methods.txt index 393e1b0c..ab750599 100755 --- a/DOC/Methods.txt +++ b/DOC/Methods.txt @@ -1,4 +1,4 @@ -Compression method IDs (4.38) +Compression method IDs (4.43) ----------------------------- Each compression method in 7z has unique binary value (ID). @@ -95,6 +95,7 @@ List of defined IDs 0x - AES-128 4x - AES-192 8x - AES-256 + Cx - AES x0 - ECB x1 - CBC diff --git a/DOC/lzma.txt b/DOC/lzma.txt index 6326814f..a65fc1e6 100755 --- a/DOC/lzma.txt +++ b/DOC/lzma.txt @@ -1,4 +1,4 @@ -LZMA SDK 4.40 +LZMA SDK 4.43 ------------- LZMA SDK Copyright (C) 1999-2006 Igor Pavlov diff --git a/DOC/lzma_format.txt b/DOC/lzma_format.txt deleted file mode 100755 index 3dacfe7d..00000000 --- a/DOC/lzma_format.txt +++ /dev/null @@ -1,28 +0,0 @@ -6 Signature 0xFF 'L' 'Z' 'M' 'A' 0x00 -1 Flags - 0 Has CRC16 of the header - 1 Has CRC32 of the data - 2 Has filter - 3 Need initial dictionary - 4-7 Reserved, *must* be zero for now. -1 CompressionMethod - 0 No compression - 1 Lzma -1 Filter ID - 0 none - 1 BCJ -2 LZMA properties - 1 (uint8_t)((pb * 5 + lp) * 9 + lc) (like in LZMA_Alone) - 1 Dictionary size. - eppnnnnn - e: 1 - there is end marker - Dictionary size = (1 << nnnnn) + (pp) << (nnnnn - 2); -2 CRC16 of the header - -Compressed data -... ... -(-16) 4 CRC32 of the uncompressed data as big endian uint32_t --12 8 Uncompressed size as big endian uint64_t --4 4 Footer magic bytes: 0x0A 'I' 'P' 0x0A -0 (End of file; the last byte of the file is at offset -1.) - diff --git a/DOC/readme.txt b/DOC/readme.txt index 2454d7d7..cd0c8c43 100755 --- a/DOC/readme.txt +++ b/DOC/readme.txt @@ -1,4 +1,4 @@ -7-Zip 4.42 Sources +7-Zip 4.43 Sources ------------------ 7-Zip is a file archiver for Windows 95/98/ME/NT/2000/2003/XP. diff --git a/Windows/CommonDialog.cpp b/Windows/CommonDialog.cpp index 756026d7..d0234c54 100755 --- a/Windows/CommonDialog.cpp +++ b/Windows/CommonDialog.cpp @@ -33,7 +33,7 @@ void CDoubleZeroStringListA::Add(LPCSTR s) void CDoubleZeroStringListA::SetForBuffer(LPSTR buffer) { - strcpy(buffer, m_String); + MyStringCopy(buffer, (const char *)m_String); for (int i = 0; i < m_Indexes.Size(); i++) buffer[m_Indexes[i]] = '\0'; } @@ -57,7 +57,7 @@ void CDoubleZeroStringListW::Add(LPCWSTR s) void CDoubleZeroStringListW::SetForBuffer(LPWSTR buffer) { - wcscpy(buffer, m_String); + MyStringCopy(buffer, (const wchar_t *)m_String); for (int i = 0; i < m_Indexes.Size(); i++) buffer[m_Indexes[i]] = L'\0'; } @@ -69,7 +69,7 @@ bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR fullFileName, LPCWSTR s if (!g_IsNT) { CHAR buffer[kBufferSize]; - strcpy(buffer, GetSystemString(fullFileName)); + MyStringCopy(buffer, (const char *)GetSystemString(fullFileName)); OPENFILENAME info; info.lStructSize = sizeof(info); info.hwndOwner = hwnd; @@ -119,7 +119,7 @@ bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR fullFileName, LPCWSTR s #endif { WCHAR buffer[kBufferSize]; - wcscpy(buffer, fullFileName); + MyStringCopy(buffer, fullFileName); OPENFILENAMEW info; info.lStructSize = sizeof(info); info.hwndOwner = hwnd; diff --git a/Windows/Control/ComboBox.cpp b/Windows/Control/ComboBox.cpp index 58c9b9c5..5b1d2651 100755 --- a/Windows/Control/ComboBox.cpp +++ b/Windows/Control/ComboBox.cpp @@ -51,7 +51,7 @@ LRESULT CComboBox::GetLBText(int index, UString &s) return len; } AString sa; - int len = GetLBText(index, sa); + LRESULT len = GetLBText(index, sa); if (len == CB_ERR) return len; s = GetUnicodeString(sa); diff --git a/Windows/Control/ComboBox.h b/Windows/Control/ComboBox.h index b153e6ad..2fb2302e 100755 --- a/Windows/Control/ComboBox.h +++ b/Windows/Control/ComboBox.h @@ -19,9 +19,9 @@ public: #ifndef _UNICODE LRESULT AddString(LPCWSTR string); #endif - int SetCurSel(int index) { return SendMessage(CB_SETCURSEL, index, 0); } - int GetCurSel() { return SendMessage(CB_GETCURSEL, 0, 0); } - int GetCount() { return SendMessage(CB_GETCOUNT, 0, 0); } + LRESULT SetCurSel(int index) { return SendMessage(CB_SETCURSEL, index, 0); } + int GetCurSel() { return (int)SendMessage(CB_GETCURSEL, 0, 0); } + int GetCount() { return (int)SendMessage(CB_GETCOUNT, 0, 0); } LRESULT GetLBTextLen(int index) { return SendMessage(CB_GETLBTEXTLEN, index, 0); } LRESULT GetLBText(int index, LPTSTR string) { return SendMessage(CB_GETLBTEXT, index, (LPARAM)string); } @@ -30,21 +30,21 @@ public: LRESULT GetLBText(int index, UString &s); #endif - int SetItemData(int index, LPARAM lParam) + LRESULT SetItemData(int index, LPARAM lParam) { return SendMessage(CB_SETITEMDATA, index, lParam); } - int GetItemData(int index) + LRESULT GetItemData(int index) { return SendMessage(CB_GETITEMDATA, index, 0); } }; class CComboBoxEx: public CWindow { public: - int DeleteItem(int index) + LRESULT DeleteItem(int index) { return SendMessage(CBEM_DELETEITEM, index, 0); } - int InsertItem(COMBOBOXEXITEM *item) + LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMessage(CBEM_INSERTITEM, 0, (LPARAM)item); } DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) - { return SendMessage(CBEM_SETEXTENDEDSTYLE, exMask, exStyle); } + { return (DWORD)SendMessage(CBEM_SETEXTENDEDSTYLE, exMask, exStyle); } HWND GetEditControl() { return (HWND)SendMessage(CBEM_GETEDITCONTROL, 0, 0); } }; diff --git a/Windows/Control/Dialog.cpp b/Windows/Control/Dialog.cpp index 5025f257..64009b79 100755 --- a/Windows/Control/Dialog.cpp +++ b/Windows/Control/Dialog.cpp @@ -39,7 +39,7 @@ bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) case WM_COMMAND: return OnCommand(wParam, lParam); case WM_NOTIFY: - return OnNotify(wParam, (LPNMHDR) lParam); + return OnNotify((UINT)wParam, (LPNMHDR) lParam); case WM_HELP: { OnHelp((LPHELPINFO)lParam); @@ -66,7 +66,7 @@ bool CDialog::OnCommand(int code, int itemID, LPARAM lParam) return false; } -bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) +bool CDialog::OnButtonClicked(int buttonID, HWND /* buttonHWND */) { switch(buttonID) { diff --git a/Windows/Control/Dialog.h b/Windows/Control/Dialog.h index 4d978790..f6182c4b 100755 --- a/Windows/Control/Dialog.h +++ b/Windows/Control/Dialog.h @@ -21,6 +21,9 @@ public: bool EnableItem(int itemID, bool enable) const { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); } + bool ShowItem(int itemID, int cmdShow) const + { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); } + bool SetItemText(int itemID, LPCTSTR s) { return BOOLToBool(SetDlgItemText(_window, itemID, s)); } @@ -84,13 +87,13 @@ public: virtual bool OnInit() { return true; } virtual bool OnCommand(WPARAM wParam, LPARAM lParam); virtual bool OnCommand(int code, int itemID, LPARAM lParam); - virtual void OnHelp(LPHELPINFO helpInfo) { OnHelp(); }; + virtual void OnHelp(LPHELPINFO /* helpInfo */) { OnHelp(); }; virtual void OnHelp() {}; virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); virtual void OnOK() {}; virtual void OnCancel() {}; - virtual bool OnNotify(UINT controlID, LPNMHDR lParam) { return false; } - virtual bool OnTimer(WPARAM timerID, LPARAM callback) { return false; } + virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; } + virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; } LONG_PTR SetMsgResult(LONG_PTR newLongPtr ) { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); } diff --git a/Windows/Control/ProgressBar.h b/Windows/Control/ProgressBar.h index 89550afa..6ce837cc 100755 --- a/Windows/Control/ProgressBar.h +++ b/Windows/Control/ProgressBar.h @@ -17,23 +17,23 @@ public: LRESULT DeltaPos(int increment) { return SendMessage(PBM_DELTAPOS, increment, 0); } UINT GetPos() - { return SendMessage(PBM_GETPOS, 0, 0); } + { return (UINT)SendMessage(PBM_GETPOS, 0, 0); } LRESULT SetRange(unsigned short minValue, unsigned short maxValue) { return SendMessage(PBM_SETRANGE, 0, MAKELPARAM(minValue, maxValue)); } DWORD SetRange32(int minValue, int maxValue) - { return SendMessage(PBM_SETRANGE32, minValue, maxValue); } - int SetStep(int aStep) - { return SendMessage(PBM_SETSTEP, aStep, 0); } - int StepIt() + { return (DWORD)SendMessage(PBM_SETRANGE32, minValue, maxValue); } + int SetStep(int step) + { return (int)SendMessage(PBM_SETSTEP, step, 0); } + LRESULT StepIt() { return SendMessage(PBM_STEPIT, 0, 0); } - int GetRange(bool minValue, PPBRANGE range) - { return SendMessage(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); } + INT GetRange(bool minValue, PPBRANGE range) + { return (INT)SendMessage(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); } COLORREF SetBarColor(COLORREF color) - { return SendMessage(PBM_SETBARCOLOR, 0, color); } + { return (COLORREF)SendMessage(PBM_SETBARCOLOR, 0, color); } COLORREF SetBackgroundColor(COLORREF color) - { return SendMessage(PBM_SETBKCOLOR, 0, color); } + { return (COLORREF)SendMessage(PBM_SETBKCOLOR, 0, color); } }; }} diff --git a/Windows/Control/PropertyPage.cpp b/Windows/Control/PropertyPage.cpp index 9198131c..f8996be1 100755 --- a/Windows/Control/PropertyPage.cpp +++ b/Windows/Control/PropertyPage.cpp @@ -32,14 +32,14 @@ INT_PTR APIENTRY ProperyPageProcedure(HWND dialogHWND, UINT message, case WM_COMMAND: return dialog->OnCommand(wParam, lParam); case WM_NOTIFY: - return dialog->OnNotify(wParam, (LPNMHDR) lParam); + return dialog->OnNotify((UINT)wParam, (LPNMHDR) lParam); } if (dialog == NULL) return false; return dialog->OnMessage(message, wParam, lParam); } -bool CPropertyPage::OnNotify(UINT controlID, LPNMHDR lParam) +bool CPropertyPage::OnNotify(UINT /* controlID */, LPNMHDR lParam) { switch(lParam->code) { @@ -64,7 +64,7 @@ bool CPropertyPage::OnNotify(UINT controlID, LPNMHDR lParam) return true; } -int MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, const UString &title) +INT_PTR MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, const UString &title) { #ifndef _UNICODE AStringVector titles; @@ -127,7 +127,6 @@ int MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, } } - int res; #ifndef _UNICODE if (!g_IsNT) { @@ -142,7 +141,7 @@ int MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, sheet.nStartPage = 0; sheet.ppsp = &pagesA.Front(); sheet.pfnCallback = NULL; - res = ::PropertySheetA(&sheet); + return ::PropertySheetA(&sheet); } else #endif @@ -157,9 +156,8 @@ int MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, sheet.nStartPage = 0; sheet.ppsp = &pagesW.Front(); sheet.pfnCallback = NULL; - res = ::PropertySheetW(&sheet); + return ::PropertySheetW(&sheet); } - return res; } }} diff --git a/Windows/Control/PropertyPage.h b/Windows/Control/PropertyPage.h index a80d04d0..e041d289 100755 --- a/Windows/Control/PropertyPage.h +++ b/Windows/Control/PropertyPage.h @@ -22,15 +22,15 @@ public: virtual bool OnNotify(UINT controlID, LPNMHDR lParam); virtual bool OnKillActive() { return false; } // false = OK - virtual bool OnKillActive(const PSHNOTIFY *aPSHNOTIFY) { return OnKillActive(); } + virtual bool OnKillActive(const PSHNOTIFY * /* aPSHNOTIFY */) { return OnKillActive(); } virtual LONG OnSetActive() { return false; } // false = OK - virtual LONG OnSetActive(const PSHNOTIFY *aPSHNOTIFY) { return OnKillActive(); } + virtual LONG OnSetActive(const PSHNOTIFY * /* aPSHNOTIFY */) { return OnKillActive(); } virtual LONG OnApply() { return PSNRET_NOERROR; } - virtual LONG OnApply(const PSHNOTIFY *aPSHNOTIFY) { return OnApply(); } + virtual LONG OnApply(const PSHNOTIFY * /* aPSHNOTIFY */) { return OnApply(); } virtual void OnNotifyHelp() { } - virtual void OnNotifyHelp(const PSHNOTIFY *aPSHNOTIFY) { OnNotifyHelp(); } + virtual void OnNotifyHelp(const PSHNOTIFY * /* aPSHNOTIFY */) { OnNotifyHelp(); } virtual void OnReset() { } - virtual void OnReset(const PSHNOTIFY *aPSHNOTIFY) { OnReset(); } + virtual void OnReset(const PSHNOTIFY * /* aPSHNOTIFY */) { OnReset(); } }; struct CPageInfo @@ -40,7 +40,7 @@ struct CPageInfo UINT ID; }; -int MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, const UString &title); +INT_PTR MyPropertySheet(const CObjectVector &pagesInfo, HWND hwndParent, const UString &title); }} diff --git a/Windows/Control/ReBar.h b/Windows/Control/ReBar.h index 9475d5b4..ec27f0ed 100755 --- a/Windows/Control/ReBar.h +++ b/Windows/Control/ReBar.h @@ -13,21 +13,21 @@ class CReBar: public NWindows::CWindow { public: bool SetBarInfo(LPREBARINFO barInfo) - { return BOOLToBool(SendMessage(RB_SETBARINFO, 0, (LPARAM)barInfo)); } + { return LRESULTToBool(SendMessage(RB_SETBARINFO, 0, (LPARAM)barInfo)); } bool InsertBand(int index, LPREBARBANDINFO bandInfo) - { return BOOLToBool(SendMessage(RB_INSERTBAND, index, (LPARAM)bandInfo)); } + { return LRESULTToBool(SendMessage(RB_INSERTBAND, index, (LPARAM)bandInfo)); } bool SetBandInfo(int index, LPREBARBANDINFO bandInfo) - { return BOOLToBool(SendMessage(RB_SETBANDINFO, index, (LPARAM)bandInfo)); } + { return LRESULTToBool(SendMessage(RB_SETBANDINFO, index, (LPARAM)bandInfo)); } void MaximizeBand(int index, bool ideal) { SendMessage(RB_MAXIMIZEBAND, index, BoolToBOOL(ideal)); } bool SizeToRect(LPRECT rect) - { return BOOLToBool(SendMessage(RB_SIZETORECT, 0, (LPARAM)rect)); } + { return LRESULTToBool(SendMessage(RB_SIZETORECT, 0, (LPARAM)rect)); } UINT GetHeight() - { return SendMessage(RB_GETBARHEIGHT); } + { return (UINT)SendMessage(RB_GETBARHEIGHT); } UINT GetBandCount() - { return SendMessage(RB_GETBANDCOUNT); } + { return (UINT)SendMessage(RB_GETBANDCOUNT); } bool DeleteBand(UINT index) - { return BOOLToBool(SendMessage(RB_DELETEBAND, index)); } + { return LRESULTToBool(SendMessage(RB_DELETEBAND, index)); } }; }} diff --git a/Windows/Control/StatusBar.h b/Windows/Control/StatusBar.h index 8adf1c05..e8018a56 100755 --- a/Windows/Control/StatusBar.h +++ b/Windows/Control/StatusBar.h @@ -15,12 +15,12 @@ public: bool Create(LONG style, LPCTSTR text, HWND hwndParent, UINT id) { return (_window = ::CreateStatusWindow(style, text, hwndParent, id)) != 0; } bool SetParts(int numParts, const int *edgePostions) - { return BOOLToBool(SendMessage(SB_SETPARTS, numParts, (LPARAM)edgePostions)); } + { return LRESULTToBool(SendMessage(SB_SETPARTS, numParts, (LPARAM)edgePostions)); } bool SetText(LPCTSTR text) { return CWindow::SetText(text); } bool SetText(int index, LPCTSTR text, UINT type) - { return BOOLToBool(SendMessage(SB_SETTEXT, index | type, (LPARAM)text)); } + { return LRESULTToBool(SendMessage(SB_SETTEXT, index | type, (LPARAM)text)); } bool SetText(int index, LPCTSTR text) { return SetText(index, text, 0); } void Simple(bool simple) @@ -32,7 +32,7 @@ public: bool SetText(LPCWSTR text) { return CWindow::SetText(text); } bool SetText(int index, LPCWSTR text, UINT type) - { return BOOLToBool(SendMessage(SB_SETTEXTW, index | type, (LPARAM)text)); } + { return LRESULTToBool(SendMessage(SB_SETTEXTW, index | type, (LPARAM)text)); } bool SetText(int index, LPCWSTR text) { return SetText(index, text, 0); } #endif diff --git a/Windows/Control/ToolBar.h b/Windows/Control/ToolBar.h index 8c5e95f9..ff5cafd2 100755 --- a/Windows/Control/ToolBar.h +++ b/Windows/Control/ToolBar.h @@ -13,19 +13,19 @@ class CToolBar: public NWindows::CWindow { public: bool GetMaxSize(LPSIZE size) - { return BOOLToBool(SendMessage(TB_GETMAXSIZE, 0, (LPARAM)size)); } + { return LRESULTToBool(SendMessage(TB_GETMAXSIZE, 0, (LPARAM)size)); } bool EnableButton(UINT buttonID, bool enable) - { return BOOLToBool(SendMessage(TB_ENABLEBUTTON, buttonID, + { return LRESULTToBool(SendMessage(TB_ENABLEBUTTON, buttonID, MAKELONG(BoolToBOOL(enable), 0))); } void ButtonStructSize() { SendMessage(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON)); } HIMAGELIST SetImageList(UINT listIndex, HIMAGELIST imageList) { return HIMAGELIST(SendMessage(TB_SETIMAGELIST, listIndex, (LPARAM)imageList)); } bool AddButton(UINT numButtons, LPTBBUTTON buttons) - { return BOOLToBool(SendMessage(TB_ADDBUTTONS, numButtons, (LPARAM)buttons)); } + { return LRESULTToBool(SendMessage(TB_ADDBUTTONS, numButtons, (LPARAM)buttons)); } #ifndef _UNICODE bool AddButtonW(UINT numButtons, LPTBBUTTON buttons) - { return BOOLToBool(SendMessage(TB_ADDBUTTONSW, numButtons, (LPARAM)buttons)); } + { return LRESULTToBool(SendMessage(TB_ADDBUTTONSW, numButtons, (LPARAM)buttons)); } #endif }; diff --git a/Windows/Control/Window2.cpp b/Windows/Control/Window2.cpp index 8da2a0b3..7857d503 100755 --- a/Windows/Control/Window2.cpp +++ b/Windows/Control/Window2.cpp @@ -147,7 +147,7 @@ LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) return result; break; case WM_NOTIFY: - if (OnNotify(wParam, (LPNMHDR) lParam, result)) + if (OnNotify((UINT)wParam, (LPNMHDR) lParam, result)) return result; break; case WM_DESTROY: @@ -168,7 +168,7 @@ bool CWindow2::OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result) return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result); } -bool CWindow2::OnCommand(int code, int itemID, LPARAM lParam, LRESULT &result) +bool CWindow2::OnCommand(int /* code */, int /* itemID */, LPARAM /* lParam */, LRESULT & /* result */) { return false; // return DefProc(message, wParam, lParam); diff --git a/Windows/Control/Window2.h b/Windows/Control/Window2.h index e7df5bb8..2d0e574d 100755 --- a/Windows/Control/Window2.h +++ b/Windows/Control/Window2.h @@ -32,12 +32,12 @@ public: #endif virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); - virtual bool OnCreate(CREATESTRUCT *createStruct) { return true; } + virtual bool OnCreate(CREATESTRUCT * /* createStruct */) { return true; } // virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam); virtual bool OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result); virtual bool OnCommand(int code, int itemID, LPARAM lParam, LRESULT &result); - virtual bool OnSize(WPARAM wParam, int xSize, int ySize) { return false; } - virtual bool OnNotify(UINT controlID, LPNMHDR lParam, LRESULT &result) { return false; } + virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } + virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */, LRESULT & /* result */) { return false; } virtual void OnDestroy() { PostQuitMessage(0); } virtual void OnClose() { Destroy(); } /* diff --git a/Windows/DLL.h b/Windows/DLL.h index 83061958..bad0dd6d 100755 --- a/Windows/DLL.h +++ b/Windows/DLL.h @@ -32,7 +32,7 @@ public: } // operator HMODULE() const { return _module; }; - // bool IsLoaded() const { return (_module != NULL); }; + bool IsLoaded() const { return (_module != NULL); }; bool Free(); bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE); bool Load(LPCTSTR fileName); diff --git a/Windows/Defs.h b/Windows/Defs.h index c0038d61..f8c6daaa 100755 --- a/Windows/Defs.h +++ b/Windows/Defs.h @@ -6,6 +6,9 @@ inline bool BOOLToBool(BOOL value) { return (value != FALSE); } +inline bool LRESULTToBool(LRESULT value) + { return (value != FALSE); } + inline BOOL BoolToBOOL(bool value) { return (value ? TRUE: FALSE); } diff --git a/Windows/FileDevice.h b/Windows/FileDevice.h index 659a9697..d4d71c39 100755 --- a/Windows/FileDevice.h +++ b/Windows/FileDevice.h @@ -66,7 +66,7 @@ public: bool CdRomLock(bool lock) const { PREVENT_MEDIA_REMOVAL rem; - rem.PreventMediaRemoval = BoolToBOOL(lock); + rem.PreventMediaRemoval = (BOOLEAN)(lock ? TRUE : FALSE); return DeviceIoControlIn(IOCTL_CDROM_MEDIA_REMOVAL, &rem, sizeof(rem)); } @@ -81,16 +81,20 @@ public: bool GetLengthSmart(UInt64 &length); + /* bool FormatTracks(const FORMAT_PARAMETERS *formatParams, BAD_TRACK_NUMBER *badTrackNumbers, DWORD numBadTrackNumbers, DWORD &numBadTrackNumbersReturned) { DWORD ret; + // Check params, Probabably error bool res = DeviceIoControl(IOCTL_DISK_FORMAT_TRACKS, badTrackNumbers, sizeof(*formatParams), badTrackNumbers, numBadTrackNumbers * sizeof(*badTrackNumbers), &ret, NULL); numBadTrackNumbersReturned = ret / sizeof(*badTrackNumbers); return res; } + */ + bool Performance(DISK_PERFORMANCE *res) { return DeviceIoControlOut(IOCTL_DISK_PERFORMANCE, LPVOID(res), sizeof(*res)); } diff --git a/Windows/FileDir.cpp b/Windows/FileDir.cpp index 2c8ace90..23174daf 100755 --- a/Windows/FileDir.cpp +++ b/Windows/FileDir.cpp @@ -72,6 +72,29 @@ bool MyGetSystemDirectory(UString &path) } #endif +bool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime) +{ + #ifndef _UNICODE + if (!g_IsNT) + { + ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return false; + } + #endif + HANDLE hDir = CreateFileW(fileName, GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + + bool res = false; + if (hDir != INVALID_HANDLE_VALUE) + { + res = BOOLToBool(::SetFileTime(hDir, creationTime, lastAccessTime, lastWriteTime)); + ::CloseHandle(hDir); + } + return res; +} + + #ifndef _UNICODE bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes) { @@ -147,7 +170,7 @@ bool CreateComplexDirectory(LPCTSTR _aPathName) } CSysString pathName2 = pathName; pos = pathName.Length(); - while(true) + for (;;) { if(MyCreateDirectory(pathName)) break; @@ -193,7 +216,7 @@ bool CreateComplexDirectory(LPCWSTR _aPathName) } UString pathName2 = pathName; pos = pathName.Length(); - while(true) + for (;;) { if(MyCreateDirectory(pathName)) break; @@ -251,8 +274,7 @@ static bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::C { if(fileInfo.IsDirectory()) return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name); - else - return DeleteFileAlways(pathPrefix + fileInfo.Name); + return DeleteFileAlways(pathPrefix + fileInfo.Name); } bool RemoveDirectoryWithSubItems(const CSysString &path) @@ -275,8 +297,7 @@ static bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFil { if(fileInfo.IsDirectory()) return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name); - else - return DeleteFileAlways(pathPrefix + fileInfo.Name); + return DeleteFileAlways(pathPrefix + fileInfo.Name); } bool RemoveDirectoryWithSubItems(const UString &path) { @@ -602,7 +623,7 @@ bool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName) CRandom random; random.Init(); */ - while(true) + for (;;) { CTempFile tempFile; if (!tempFile.Create(prefix, dirName)) @@ -639,7 +660,7 @@ bool CreateTempDirectory(LPCWSTR prefix, UString &dirName) CRandom random; random.Init(); */ - while(true) + for (;;) { CTempFileW tempFile; if (!tempFile.Create(prefix, dirName)) diff --git a/Windows/FileDir.h b/Windows/FileDir.h index 77373a01..64e11a63 100755 --- a/Windows/FileDir.h +++ b/Windows/FileDir.h @@ -17,6 +17,8 @@ bool MyGetWindowsDirectory(UString &path); bool MyGetSystemDirectory(UString &path); #endif +bool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime); + inline bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes) { return BOOLToBool(::SetFileAttributes(fileName, fileAttributes)); } #ifndef _UNICODE diff --git a/Windows/FileFind.cpp b/Windows/FileFind.cpp index ebf494bd..9f36c056 100755 --- a/Windows/FileFind.cpp +++ b/Windows/FileFind.cpp @@ -110,7 +110,8 @@ bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo) Close(); WIN32_FIND_DATA findData; _handle = ::FindFirstFile(wildcard, &findData); - if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE)) + _handleAllocated = (_handle != INVALID_HANDLE_VALUE); + if (_handleAllocated) ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo); return _handleAllocated; } @@ -123,7 +124,8 @@ bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo) { WIN32_FIND_DATAW findData; _handle = ::FindFirstFileW(wildcard, &findData); - if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE)) + _handleAllocated = (_handle != INVALID_HANDLE_VALUE); + if (_handleAllocated) ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo); } else @@ -131,7 +133,8 @@ bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo) WIN32_FIND_DATAA findData; _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard, GetCurrentCodePage()), &findData); - if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE)) + _handleAllocated = (_handle != INVALID_HANDLE_VALUE); + if (_handleAllocated) ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo); } return _handleAllocated; @@ -209,7 +212,7 @@ bool CEnumerator::NextAny(CFileInfo &fileInfo) bool CEnumerator::Next(CFileInfo &fileInfo) { - while(true) + for (;;) { if(!NextAny(fileInfo)) return false; @@ -240,7 +243,7 @@ bool CEnumeratorW::NextAny(CFileInfoW &fileInfo) bool CEnumeratorW::Next(CFileInfoW &fileInfo) { - while(true) + for (;;) { if(!NextAny(fileInfo)) return false; diff --git a/Windows/Memory.h b/Windows/Memory.h index 3da603ee..bd8773b8 100755 --- a/Windows/Memory.h +++ b/Windows/Memory.h @@ -25,7 +25,7 @@ public: class CGlobalLock { - const HGLOBAL m_Global; + HGLOBAL m_Global; LPVOID m_Pointer; public: LPVOID GetPointer() const { return m_Pointer; } diff --git a/Windows/PropVariantConversions.cpp b/Windows/PropVariantConversions.cpp index 073eb069..80ba5ac2 100755 --- a/Windows/PropVariantConversions.cpp +++ b/Windows/PropVariantConversions.cpp @@ -2,7 +2,7 @@ #include "StdAfx.h" -#include +// #include #include "PropVariantConversions.h" @@ -25,20 +25,25 @@ static UString ConvertInt64ToString(Int64 value) return buffer; } -/* -static void UIntToStringSpec(UInt32 value, char *s, int numPos) +static char *UIntToStringSpec(UInt32 value, char *s, int numPos) { - char s2[32]; - ConvertUInt64ToString(value, s2); - int len = strlen(s2); + char temp[16]; + int pos = 0; + do + { + temp[pos++] = (char)('0' + value % 10); + value /= 10; + } + while (value != 0); int i; - for (i = 0; i < numPos - len; i++) - s[i] = '0'; - for (int j = 0; j < len; j++, i++) - s[i] = s2[j]; - s[i] = '\0'; + for (i = 0; i < numPos - pos; i++) + *s++ = '0'; + do + *s++ = temp[--pos]; + while (pos > 0); + *s = '\0'; + return s; } -*/ bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) { @@ -46,25 +51,24 @@ bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool SYSTEMTIME st; if(!BOOLToBool(FileTimeToSystemTime(&ft, &st))) return false; - /* - UIntToStringSpec(st.wYear, s, 4); - strcat(s, "-"); - UIntToStringSpec(st.wMonth, s + strlen(s), 2); - strcat(s, "-"); - UIntToStringSpec(st.wDay, s + strlen(s), 2); + s = UIntToStringSpec(st.wYear, s, 4); + *s++ = '-'; + s = UIntToStringSpec(st.wMonth, s, 2); + *s++ = '-'; + s = UIntToStringSpec(st.wDay, s, 2); if (includeTime) { - strcat(s, " "); - UIntToStringSpec(st.wHour, s + strlen(s), 2); - strcat(s, ":"); - UIntToStringSpec(st.wMinute, s + strlen(s), 2); + *s++ = ' '; + s = UIntToStringSpec(st.wHour, s, 2); + *s++ = ':'; + s = UIntToStringSpec(st.wMinute, s, 2); if (includeSeconds) { - strcat(s, ":"); - UIntToStringSpec(st.wSecond, s + strlen(s), 2); + *s++ = ':'; + UIntToStringSpec(st.wSecond, s, 2); } } - */ + /* sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); if (includeTime) { @@ -72,6 +76,7 @@ bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool if (includeSeconds) sprintf(s + strlen(s), ":%02d", st.wSecond); } + */ return true; } diff --git a/Windows/Registry.cpp b/Windows/Registry.cpp index 9dbaf2bb..2c6b6afc 100755 --- a/Windows/Registry.cpp +++ b/Windows/Registry.cpp @@ -169,7 +169,7 @@ LONG CKey::SetValue(LPCWSTR name, LPCWSTR value) MYASSERT(_object != NULL); if (g_IsNT) return RegSetValueExW(_object, name, NULL, REG_SZ, - (const BYTE * )value, (wcslen(value) + 1) * sizeof(wchar_t)); + (const BYTE * )value, (DWORD)((wcslen(value) + 1) * sizeof(wchar_t))); return SetValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name), value == 0 ? 0 : (LPCSTR)GetSystemString(value)); } @@ -304,7 +304,7 @@ LONG CKey::EnumKeys(CSysStringVector &keyNames) { keyNames.Clear(); CSysString keyName; - for(UInt32 index = 0; true; index++) + for(UInt32 index = 0; ; index++) { const UInt32 kBufferSize = MAX_PATH + 1; // 256 in ATL FILETIME lastWriteTime; diff --git a/Windows/Security.cpp b/Windows/Security.cpp index 3500de46..80cf15be 100755 --- a/Windows/Security.cpp +++ b/Windows/Security.cpp @@ -35,9 +35,9 @@ bool MyLookupAccountSid(LPCTSTR systemName, PSID sid, static void SetLsaString(LPWSTR src, PLSA_UNICODE_STRING dest) { - int len = wcslen(src); - dest->Length = len * sizeof(WCHAR); - dest->MaximumLength = (len + 1) * sizeof(WCHAR); + int len = (int)wcslen(src); + dest->Length = (USHORT)(len * sizeof(WCHAR)); + dest->MaximumLength = (USHORT)((len + 1) * sizeof(WCHAR)); dest->Buffer = src; } diff --git a/Windows/Security.h b/Windows/Security.h index 929986d8..ded31b74 100755 --- a/Windows/Security.h +++ b/Windows/Security.h @@ -158,7 +158,7 @@ public: { return AddAccountRights(accountSid, userRights, 1); } NTSTATUS RemoveAccountRights(PSID accountSid, bool allRights, PLSA_UNICODE_STRING userRights, ULONG countOfRights) - { return LsaRemoveAccountRights(_handle, accountSid, BoolToBOOL(allRights), userRights, countOfRights); } + { return LsaRemoveAccountRights(_handle, accountSid, (BOOLEAN)(allRights ? TRUE : FALSE), userRights, countOfRights); } }; bool AddLockMemoryPrivilege(); diff --git a/Windows/Shell.cpp b/Windows/Shell.cpp index 76868845..2906e2d4 100755 --- a/Windows/Shell.cpp +++ b/Windows/Shell.cpp @@ -143,7 +143,7 @@ bool BrowseForFolder(LPBROWSEINFO browseInfo, CSysString &resultPath) } -int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data) +int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /* lp */, LPARAM data) { switch(uMsg) { @@ -227,7 +227,7 @@ bool BrowseForFolder(LPBROWSEINFOW browseInfo, UString &resultPath) } -int CALLBACK BrowseCallbackProc2(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data) +int CALLBACK BrowseCallbackProc2(HWND hwnd, UINT uMsg, LPARAM /* lp */, LPARAM data) { switch(uMsg) { diff --git a/Windows/Synchronization.h b/Windows/Synchronization.h index c40fa988..89450276 100755 --- a/Windows/Synchronization.h +++ b/Windows/Synchronization.h @@ -81,10 +81,30 @@ public: class CMutexLock { - CMutex &_object; + CMutex *_object; public: - CMutexLock(CMutex &object): _object(object) { _object.Lock(); } - ~CMutexLock() { _object.Release(); } + CMutexLock(CMutex &object): _object(&object) { _object->Lock(); } + ~CMutexLock() { _object->Release(); } +}; + +class CSemaphore: public CObject +{ +public: + bool Create(LONG initiallyCount, LONG maxCount, LPCTSTR name = NULL, + LPSECURITY_ATTRIBUTES securityAttributes = NULL) + { + _handle = ::CreateSemaphore(securityAttributes, initiallyCount, maxCount, name); + return (_handle != 0); + } + bool Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name) + { + _handle = ::OpenSemaphore(desiredAccess, BoolToBOOL(inheritHandle), name); + return (_handle != 0); + } + bool Release(LONG releaseCount = 1, LPLONG previousCount = NULL) + { + return BOOLToBool(::ReleaseSemaphore(_handle, releaseCount, previousCount)); + } }; class CCriticalSection @@ -101,11 +121,10 @@ public: class CCriticalSectionLock { - CCriticalSection &_object; - void Unlock() { _object.Leave(); } + CCriticalSection *_object; + void Unlock() { _object->Leave(); } public: - CCriticalSectionLock(CCriticalSection &object): _object(object) - {_object.Enter(); } + CCriticalSectionLock(CCriticalSection &object): _object(&object) {_object->Enter(); } ~CCriticalSectionLock() { Unlock(); } }; diff --git a/Windows/System.h b/Windows/System.h index 2bd1f858..e1a5abac 100755 --- a/Windows/System.h +++ b/Windows/System.h @@ -8,7 +8,7 @@ namespace NWindows { namespace NSystem { -static UInt32 GetNumberOfProcessors() +inline UInt32 GetNumberOfProcessors() { SYSTEM_INFO systemInfo; GetSystemInfo(&systemInfo); diff --git a/Windows/Window.h b/Windows/Window.h index c2818444..3df80191 100755 --- a/Windows/Window.h +++ b/Windows/Window.h @@ -111,9 +111,9 @@ public: void SetRedraw(bool redraw = true) { SendMessage(WM_SETREDRAW, BoolToBOOL(redraw), 0); } #ifndef _WIN32_WCE - LONG SetStyle(LONG_PTR style) + LONG_PTR SetStyle(LONG_PTR style) { return SetLongPtr(GWL_STYLE, style); } - DWORD GetStyle( ) const + LONG_PTR GetStyle( ) const { return GetLongPtr(GWL_STYLE); } #else LONG SetStyle(LONG_PTR style) @@ -122,21 +122,29 @@ public: { return GetLong(GWL_STYLE); } #endif - LONG_PTR SetLong(int index, LONG_PTR newLongPtr ) + LONG_PTR SetLong(int index, LONG newLongPtr ) { return ::SetWindowLong(_window, index, newLongPtr); } LONG_PTR GetLong(int index) const { return ::GetWindowLong(_window, index ); } - LONG_PTR SetUserDataLong(LONG_PTR newLongPtr ) + LONG_PTR SetUserDataLong(LONG newLongPtr ) { return SetLong(GWLP_USERDATA, newLongPtr); } LONG_PTR GetUserDataLong() const { return GetLong(GWLP_USERDATA); } #ifndef _WIN32_WCE LONG_PTR SetLongPtr(int index, LONG_PTR newLongPtr ) - { return ::SetWindowLongPtr(_window, index, newLongPtr); } + { return ::SetWindowLongPtr(_window, index, + #ifndef _WIN64 + (LONG) + #endif + newLongPtr); } #ifndef _UNICODE LONG_PTR SetLongPtrW(int index, LONG_PTR newLongPtr ) - { return ::SetWindowLongPtrW(_window, index, newLongPtr); } + { return ::SetWindowLongPtrW(_window, index, + #ifndef _WIN64 + (LONG) + #endif + newLongPtr); } #endif LONG_PTR GetLongPtr(int index) const -- cgit v1.2.3