From fd8b1d78b496fe38193bf8c5e86af3b43f0b022d Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 26 Jun 2007 00:00:00 +0000 Subject: 4.48 beta --- C/Alloc.c | 1 - C/Archive/7z/7zDecode.c | 367 +++++++++--- C/Archive/7z/7zDecode.h | 5 +- C/Archive/7z/7zExtract.c | 43 +- C/Archive/7z/7zIn.c | 55 +- C/Archive/7z/7zIn.h | 2 +- C/Archive/7z/7zItem.c | 1 + C/Archive/7z/7zItem.h | 9 +- C/Archive/7z/7zMain.c | 74 ++- C/Archive/7z/7zMethodID.c | 10 +- C/Archive/7z/7zMethodID.h | 10 +- C/Archive/7z/7z_C.dsp | 29 +- C/Archive/7z/makefile | 16 +- C/Archive/7z/makefile.gcc | 9 +- C/Compress/Branch/BranchTypes.h | 15 +- C/Compress/Branch/BranchX86.c | 113 ++-- C/Compress/Branch/BranchX86.h | 5 +- C/Compress/Branch/BranchX86_2.c | 135 +++++ C/Compress/Branch/BranchX86_2.h | 28 + C/Compress/Lzma/LzmaStateDecode.c | 2 +- C/Compress/Lzma/LzmaTypes.h | 10 +- C/Types.h | 2 +- CPP/7zip/Archive/7z/7z.dsp | 61 +- CPP/7zip/Archive/7z/7zCompressionMode.h | 14 +- CPP/7zip/Archive/7z/7zDecode.cpp | 14 +- CPP/7zip/Archive/7z/7zDecode.h | 8 +- CPP/7zip/Archive/7z/7zEncode.cpp | 132 ++--- CPP/7zip/Archive/7z/7zEncode.h | 8 +- CPP/7zip/Archive/7z/7zHandler.cpp | 7 +- CPP/7zip/Archive/7z/7zHandler.h | 87 +-- CPP/7zip/Archive/7z/7zHandlerOut.cpp | 612 +------------------- CPP/7zip/Archive/7z/7zHeader.cpp | 10 +- CPP/7zip/Archive/7z/7zIn.cpp | 8 +- CPP/7zip/Archive/7z/7zItem.h | 2 +- CPP/7zip/Archive/7z/7zOut.cpp | 2 +- CPP/7zip/Archive/7z/7zUpdate.cpp | 26 +- CPP/7zip/Archive/7z/makefile | 11 +- CPP/7zip/Archive/Arj/ArjItem.h | 2 +- CPP/7zip/Archive/BZip2/BZip2HandlerOut.cpp | 1 - CPP/7zip/Archive/Cab/CabItem.h | 2 +- CPP/7zip/Archive/Chm/ChmIn.h | 2 +- CPP/7zip/Archive/Common/CoderMixer.cpp | 19 + CPP/7zip/Archive/Common/CoderMixer.h | 32 ++ CPP/7zip/Archive/Common/CoderMixer2.cpp | 6 +- CPP/7zip/Archive/Common/CoderMixer2.h | 20 +- CPP/7zip/Archive/Common/CoderMixer2MT.cpp | 257 +++------ CPP/7zip/Archive/Common/CoderMixer2MT.h | 123 ++-- CPP/7zip/Archive/Common/CoderMixerMT.cpp | 97 ++++ CPP/7zip/Archive/Common/CoderMixerMT.h | 68 +++ CPP/7zip/Archive/Common/HandlerOut.cpp | 609 ++++++++++++++++++++ CPP/7zip/Archive/Common/HandlerOut.h | 84 +++ CPP/7zip/Archive/Common/ItemNameUtils.h | 2 +- CPP/7zip/Archive/Common/MultiStream.h | 2 +- CPP/7zip/Archive/Common/ParseProperties.cpp | 33 +- CPP/7zip/Archive/Common/ParseProperties.h | 3 +- CPP/7zip/Archive/Cpio/CpioItem.h | 2 +- CPP/7zip/Archive/Deb/DebItem.h | 2 +- CPP/7zip/Archive/GZip/GZipItem.h | 2 +- CPP/7zip/Archive/Iso/IsoItem.h | 2 +- CPP/7zip/Archive/Lzh/LzhItem.h | 2 +- CPP/7zip/Archive/Rar/RarIn.h | 1 - CPP/7zip/Archive/Rar/RarItem.h | 2 +- CPP/7zip/Archive/Split/SplitHandler.h | 2 +- CPP/7zip/Archive/Tar/TarHandler.cpp | 18 +- CPP/7zip/Archive/Tar/TarItem.h | 2 +- CPP/7zip/Archive/Tar/TarUpdate.h | 4 - CPP/7zip/Archive/Zip/ZipCompressionMode.h | 3 +- CPP/7zip/Archive/Zip/ZipHandlerOut.cpp | 10 +- CPP/7zip/Archive/Zip/ZipIn.cpp | 13 +- CPP/7zip/Archive/Zip/ZipItem.h | 2 +- CPP/7zip/Archive/Zip/ZipOut.cpp | 33 +- CPP/7zip/Archive/Zip/ZipOut.h | 7 +- CPP/7zip/Archive/Zip/ZipUpdate.cpp | 14 +- CPP/7zip/Archive/Zip/ZipUpdate.h | 3 - CPP/7zip/Bundles/Alone/Alone.dsp | 80 +-- CPP/7zip/Bundles/Alone/makefile | 10 +- CPP/7zip/Bundles/Alone7z/Alone.dsp | 84 +-- CPP/7zip/Bundles/Alone7z/makefile | 10 +- CPP/7zip/Bundles/Format7z/makefile | 12 +- CPP/7zip/Bundles/Format7zExtract/makefile | 8 +- CPP/7zip/Bundles/Format7zExtractR/makefile | 10 +- CPP/7zip/Bundles/Format7zF/Format7z.dsp | 60 +- CPP/7zip/Bundles/Format7zF/makefile | 10 +- CPP/7zip/Bundles/Format7zR/makefile | 10 +- CPP/7zip/Bundles/SFXCon/Main.cpp | 2 +- CPP/7zip/Bundles/SFXCon/SFXCon.dsp | 32 +- CPP/7zip/Bundles/SFXCon/makefile | 5 +- CPP/7zip/Bundles/SFXSetup/ExtractCallback.h | 1 - CPP/7zip/Bundles/SFXSetup/ExtractEngine.h | 1 - CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp | 32 +- CPP/7zip/Bundles/SFXSetup/makefile | 5 +- CPP/7zip/Bundles/SFXWin/SFXWin.dsp | 24 +- CPP/7zip/Bundles/SFXWin/makefile | 5 +- CPP/7zip/Common/CreateCoder.h | 2 +- CPP/7zip/Common/FilePathAutoRename.h | 2 +- CPP/7zip/Common/FilterCoder.cpp | 12 + CPP/7zip/Common/FilterCoder.h | 8 + CPP/7zip/Common/InBuffer.h | 7 +- CPP/7zip/Common/MemBlocks.h | 2 +- CPP/7zip/Common/MethodId.cpp | 2 +- CPP/7zip/Common/MethodProps.cpp | 96 ++++ CPP/7zip/Common/MethodProps.h | 41 ++ CPP/7zip/Common/OutBuffer.h | 10 +- CPP/7zip/Common/ProgressMt.h | 5 +- CPP/7zip/Common/VirtThread.cpp | 45 ++ CPP/7zip/Common/VirtThread.h | 23 + CPP/7zip/Compress/Branch/BCJ2Register.cpp | 4 +- CPP/7zip/Compress/Branch/x86.cpp | 4 +- CPP/7zip/Compress/Branch/x86.h | 3 +- CPP/7zip/Compress/Branch/x86_2.cpp | 151 ++--- CPP/7zip/Compress/Branch/x86_2.h | 38 +- CPP/7zip/Compress/Copy/CopyCoder.cpp | 6 + CPP/7zip/Compress/Copy/CopyCoder.h | 4 +- CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp | 32 +- CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp | 8 +- CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp | 6 +- CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp | 4 +- CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp | 7 +- CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c | 7 +- CPP/7zip/Compress/LZMA_Alone/makefile | 12 +- CPP/7zip/Compress/LZMA_Alone/makefile.gcc | 36 +- CPP/7zip/Compress/Rar/Rar3Vm.h | 2 +- CPP/7zip/Crypto/7zAES/7zAES.cpp | 63 +- CPP/7zip/Crypto/7zAES/7zAES.h | 19 +- CPP/7zip/Crypto/WzAES/WzAES.h | 2 +- CPP/7zip/FileManager/ExtractCallback.h | 2 +- CPP/7zip/FileManager/FM.dsp | 32 +- CPP/7zip/FileManager/FSDrives.h | 2 +- CPP/7zip/FileManager/FSFolder.h | 2 +- CPP/7zip/FileManager/FormatUtils.h | 2 +- CPP/7zip/FileManager/HelpUtils.h | 2 +- CPP/7zip/FileManager/LangUtils.cpp | 24 +- CPP/7zip/FileManager/NetFolder.h | 2 +- CPP/7zip/FileManager/OpenCallback.h | 2 +- CPP/7zip/FileManager/PanelItems.cpp | 1 - CPP/7zip/FileManager/PhysDriveFolder.h | 2 +- CPP/7zip/FileManager/PluginInterface.h | 2 +- CPP/7zip/FileManager/ProgramLocation.h | 2 +- CPP/7zip/FileManager/PropertyName.h | 2 +- CPP/7zip/FileManager/RegistryAssociations.h | 3 +- CPP/7zip/FileManager/RegistryPlugins.h | 3 +- .../Resource/ListViewDialog/ListViewDialog.cpp | 2 - CPP/7zip/FileManager/RootFolder.h | 2 +- CPP/7zip/FileManager/SplitUtils.h | 2 +- CPP/7zip/FileManager/StringUtils.h | 2 +- CPP/7zip/FileManager/SysIconUtils.h | 2 +- CPP/7zip/FileManager/TextPairs.h | 3 +- CPP/7zip/FileManager/UpdateCallback100.h | 2 +- CPP/7zip/FileManager/ViewSettings.h | 3 +- CPP/7zip/FileManager/makefile | 4 +- CPP/7zip/Guid.txt | 2 + CPP/7zip/ICoder.h | 12 + CPP/7zip/MyVersion.h | 8 +- CPP/7zip/UI/Agent/Agent.cpp | 2 + CPP/7zip/UI/Agent/AgentProxy.h | 2 +- CPP/7zip/UI/Client7z/Client7z.dsp | 16 +- CPP/7zip/UI/Client7z/makefile | 4 +- CPP/7zip/UI/Common/ArchiveCommandLine.cpp | 14 +- CPP/7zip/UI/Common/ArchiveExtractCallback.h | 2 +- CPP/7zip/UI/Common/ArchiveName.h | 2 +- CPP/7zip/UI/Common/ArchiveOpenCallback.cpp | 11 +- CPP/7zip/UI/Common/ArchiveOpenCallback.h | 4 +- CPP/7zip/UI/Common/CompressCall.h | 2 +- CPP/7zip/UI/Common/DefaultName.h | 2 +- CPP/7zip/UI/Common/DirItem.h | 2 +- CPP/7zip/UI/Common/ExtractingFilePath.h | 2 +- CPP/7zip/UI/Common/IFileExtractCallback.h | 2 +- CPP/7zip/UI/Common/LoadCodecs.h | 2 +- CPP/7zip/UI/Common/OpenArchive.cpp | 39 +- CPP/7zip/UI/Common/OpenArchive.h | 7 +- CPP/7zip/UI/Common/PropIDUtils.cpp | 3 +- CPP/7zip/UI/Common/PropIDUtils.h | 5 +- CPP/7zip/UI/Common/Property.h | 2 +- CPP/7zip/UI/Common/SetProperties.cpp | 2 +- CPP/7zip/UI/Common/SortUtils.cpp | 2 +- CPP/7zip/UI/Common/SortUtils.h | 2 +- CPP/7zip/UI/Common/TempFiles.h | 2 +- CPP/7zip/UI/Common/UpdateCallback.h | 2 +- CPP/7zip/UI/Common/ZipRegistry.h | 2 +- CPP/7zip/UI/Console/Console.dsp | 40 +- CPP/7zip/UI/Console/ExtractCallbackConsole.h | 2 +- CPP/7zip/UI/Console/Main.cpp | 2 +- CPP/7zip/UI/Console/MainAr.cpp | 2 +- CPP/7zip/UI/Console/PercentPrinter.cpp | 2 +- CPP/7zip/UI/Console/UpdateCallbackConsole.h | 2 +- CPP/7zip/UI/Console/makefile | 5 +- CPP/7zip/UI/Explorer/ContextMenu.h | 2 +- CPP/7zip/UI/Explorer/Explorer.dsp | 32 +- CPP/7zip/UI/Explorer/MyMessages.cpp | 2 - CPP/7zip/UI/Explorer/MyMessages.h | 2 +- CPP/7zip/UI/Explorer/makefile | 4 +- CPP/7zip/UI/Far/ExtractEngine.h | 2 +- CPP/7zip/UI/Far/Far.dsp | 16 +- CPP/7zip/UI/Far/FarUtils.h | 2 - CPP/7zip/UI/Far/OverwriteDialog.cpp | 1 - CPP/7zip/UI/Far/OverwriteDialog.h | 2 +- CPP/7zip/UI/Far/ProgressBox.h | 2 +- CPP/7zip/UI/Far/UpdateCallback100.h | 1 - CPP/7zip/UI/Far/makefile | 4 +- CPP/7zip/UI/GUI/GUI.cpp | 2 +- CPP/7zip/UI/GUI/GUI.dsp | 32 +- .../Resource/BenchmarkDialog/BenchmarkDialog.cpp | 2 +- CPP/7zip/UI/GUI/makefile | 5 +- CPP/Common/AlignedBuffer.cpp | 22 - CPP/Common/AlignedBuffer.h | 18 - CPP/Common/CommandLineParser.h | 2 +- CPP/Common/Exception.h | 13 - CPP/Common/Lang.cpp | 4 +- CPP/Common/Lang.h | 6 +- CPP/Common/ListFileUtils.h | 7 +- CPP/Common/MyException.h | 14 + CPP/Common/MyString.cpp | 198 +++++++ CPP/Common/MyString.h | 636 +++++++++++++++++++++ CPP/Common/MyVector.cpp | 83 +++ CPP/Common/MyVector.h | 237 ++++++++ CPP/Common/Random.cpp | 2 +- CPP/Common/StdInStream.h | 2 +- CPP/Common/StdOutStream.cpp | 4 +- CPP/Common/String.cpp | 198 ------- CPP/Common/String.h | 629 -------------------- CPP/Common/StringConvert.h | 2 +- CPP/Common/TextConfig.cpp | 4 +- CPP/Common/TextConfig.h | 4 +- CPP/Common/UTFConvert.h | 2 +- CPP/Common/Vector.cpp | 83 --- CPP/Common/Vector.h | 237 -------- CPP/Common/Wildcard.h | 2 +- CPP/Windows/COM.h | 2 +- CPP/Windows/CommonDialog.h | 2 +- CPP/Windows/Control/PropertyPage.cpp | 1 - CPP/Windows/DLL.h | 2 +- CPP/Windows/Error.h | 2 +- CPP/Windows/FileDir.h | 2 +- CPP/Windows/FileFind.h | 2 +- CPP/Windows/FileIO.cpp | 2 +- CPP/Windows/FileIO.h | 4 +- CPP/Windows/FileName.h | 2 +- CPP/Windows/FileSystem.h | 2 +- CPP/Windows/Menu.h | 2 +- CPP/Windows/Net.h | 2 +- CPP/Windows/PropVariantConversions.h | 2 +- CPP/Windows/Registry.h | 2 +- CPP/Windows/ResourceString.h | 2 +- CPP/Windows/Security.h | 1 - CPP/Windows/Shell.h | 2 +- CPP/Windows/System.cpp | 64 +++ CPP/Windows/System.h | 38 +- CPP/Windows/Thread.h | 1 + CPP/Windows/Window.h | 2 +- DOC/7zC.txt | 20 +- DOC/7zip.nsi | 2 +- DOC/7zip.wxs | 2 +- DOC/License.txt | 8 +- 253 files changed, 4288 insertions(+), 3221 deletions(-) create mode 100755 C/Compress/Branch/BranchX86_2.c create mode 100755 C/Compress/Branch/BranchX86_2.h create mode 100755 CPP/7zip/Archive/Common/CoderMixer.cpp create mode 100755 CPP/7zip/Archive/Common/CoderMixer.h create mode 100755 CPP/7zip/Archive/Common/CoderMixerMT.cpp create mode 100755 CPP/7zip/Archive/Common/CoderMixerMT.h create mode 100755 CPP/7zip/Archive/Common/HandlerOut.cpp create mode 100755 CPP/7zip/Archive/Common/HandlerOut.h create mode 100755 CPP/7zip/Common/MethodProps.cpp create mode 100755 CPP/7zip/Common/MethodProps.h create mode 100755 CPP/7zip/Common/VirtThread.cpp create mode 100755 CPP/7zip/Common/VirtThread.h delete mode 100755 CPP/Common/AlignedBuffer.cpp delete mode 100755 CPP/Common/AlignedBuffer.h delete mode 100755 CPP/Common/Exception.h create mode 100755 CPP/Common/MyException.h create mode 100755 CPP/Common/MyString.cpp create mode 100755 CPP/Common/MyString.h create mode 100755 CPP/Common/MyVector.cpp create mode 100755 CPP/Common/MyVector.h delete mode 100755 CPP/Common/String.cpp delete mode 100755 CPP/Common/String.h delete mode 100755 CPP/Common/Vector.cpp delete mode 100755 CPP/Common/Vector.h create mode 100755 CPP/Windows/System.cpp diff --git a/C/Alloc.c b/C/Alloc.c index 72e788ac..7b5af420 100755 --- a/C/Alloc.c +++ b/C/Alloc.c @@ -60,7 +60,6 @@ void MidFree(void *address) } #ifndef MEM_LARGE_PAGES -wedeed #undef _7ZIP_LARGE_PAGES #endif diff --git a/C/Archive/7z/7zDecode.c b/C/Archive/7z/7zDecode.c index fe530384..aea893da 100755 --- a/C/Archive/7z/7zDecode.c +++ b/C/Archive/7z/7zDecode.c @@ -1,14 +1,20 @@ /* 7zDecode.c */ +#include + #include "7zDecode.h" #ifdef _SZ_ONE_DIRECTORY #include "LzmaDecode.h" #else #include "../../Compress/Lzma/LzmaDecode.h" +#include "../../Compress/Branch/BranchX86.h" +#include "../../Compress/Branch/BranchX86_2.h" #endif -CMethodID k_Copy = { { 0x0 }, 1 }; -CMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 }; +#define k_Copy 0 +#define k_LZMA 0x30101 +#define k_BCJ 0x03030103 +#define k_BCJ2 0x0303011B #ifdef _LZMA_IN_CB @@ -16,7 +22,7 @@ typedef struct _CLzmaInCallbackImp { ILzmaInCallback InCallback; ISzInStream *InStream; - size_t Size; + CFileSize Size; } CLzmaInCallbackImp; int LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size) @@ -24,10 +30,13 @@ int LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size) CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object; size_t processedSize; SZ_RESULT res; + size_t curSize = (1 << 20); + if (curSize > cb->Size) + curSize = (size_t)cb->Size; *size = 0; - res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, cb->Size, &processedSize); + res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, curSize, &processedSize); *size = (SizeT)processedSize; - if (processedSize > cb->Size) + if (processedSize > curSize) return (int)SZE_FAIL; cb->Size -= processedSize; if (res == SZ_OK) @@ -37,114 +46,296 @@ int LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size) #endif -SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder, +SZ_RESULT SzDecodeLzma(CCoderInfo *coder, CFileSize inSize, #ifdef _LZMA_IN_CB ISzInStream *inStream, #else const Byte *inBuffer, #endif - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain) + Byte *outBuffer, size_t outSize, ISzAlloc *allocMain) { - UInt32 si; - size_t inSize = 0; - CCoderInfo *coder; - if (folder->NumPackStreams != 1) - return SZE_NOTIMPL; - if (folder->NumCoders != 1) - return SZE_NOTIMPL; - coder = folder->Coders; - *outSizeProcessed = 0; - - for (si = 0; si < folder->NumPackStreams; si++) - inSize += (size_t)packSizes[si]; - - if (AreMethodsEqual(&coder->MethodID, &k_Copy)) + #ifdef _LZMA_IN_CB + CLzmaInCallbackImp lzmaCallback; + #else + SizeT inProcessed; + #endif + + CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */ + int result; + SizeT outSizeProcessedLoc; + + #ifdef _LZMA_IN_CB + lzmaCallback.Size = inSize; + lzmaCallback.InStream = inStream; + lzmaCallback.InCallback.Read = LzmaReadImp; + #endif + + if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, + (unsigned)coder->Properties.Capacity) != LZMA_RESULT_OK) + return SZE_FAIL; + + state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); + if (state.Probs == 0) + return SZE_OUTOFMEMORY; + + #ifdef _LZMA_OUT_READ + if (state.Properties.DictionarySize == 0) + state.Dictionary = 0; + else { - size_t i; - if (inSize != outSize) - return SZE_DATA_ERROR; - #ifdef _LZMA_IN_CB - for (i = 0; i < inSize;) + state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize); + if (state.Dictionary == 0) { - size_t j; - void *inBuffer; - size_t bufferSize; - RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, inSize - i, &bufferSize)); - if (bufferSize == 0) - return SZE_DATA_ERROR; - if (bufferSize > inSize - i) - return SZE_FAIL; - *outSizeProcessed += bufferSize; - for (j = 0; j < bufferSize && i < inSize; j++, i++) - outBuffer[i] = ((const Byte *)inBuffer)[j]; + allocMain->Free(state.Probs); + return SZE_OUTOFMEMORY; } - #else - for (i = 0; i < inSize; i++) - outBuffer[i] = inBuffer[i]; - *outSizeProcessed = inSize; - #endif - return SZ_OK; } + LzmaDecoderInit(&state); + #endif + + result = LzmaDecode(&state, + #ifdef _LZMA_IN_CB + &lzmaCallback.InCallback, + #else + inBuffer, (SizeT)inSize, &inProcessed, + #endif + outBuffer, (SizeT)outSize, &outSizeProcessedLoc); + allocMain->Free(state.Probs); + #ifdef _LZMA_OUT_READ + allocMain->Free(state.Dictionary); + #endif + if (result == LZMA_RESULT_DATA_ERROR) + return SZE_DATA_ERROR; + if (result != LZMA_RESULT_OK) + return SZE_FAIL; + return (outSizeProcessedLoc == outSize) ? SZ_OK : SZE_DATA_ERROR; +} - if (AreMethodsEqual(&coder->MethodID, &k_LZMA)) +#ifdef _LZMA_IN_CB +SZ_RESULT SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer) +{ + while (inSize > 0) { - #ifdef _LZMA_IN_CB - CLzmaInCallbackImp lzmaCallback; - #else - SizeT inProcessed; - #endif + void *inBuffer; + size_t processedSize, curSize = (1 << 18); + if (curSize > inSize) + curSize = (size_t)(inSize); + RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, curSize, &processedSize)); + if (processedSize == 0) + return SZE_DATA_ERROR; + if (processedSize > curSize) + return SZE_FAIL; + memcpy(outBuffer, inBuffer, processedSize); + outBuffer += processedSize; + inSize -= processedSize; + } + return SZ_OK; +} +#endif + +#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA) +#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1) +#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1) +#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1) + +SZ_RESULT CheckSupportedFolder(const CFolder *f) +{ + if (f->NumCoders < 1 || f->NumCoders > 4) + return SZE_NOTIMPL; + if (IS_UNSUPPORTED_CODER(f->Coders[0])) + return SZE_NOTIMPL; + if (f->NumCoders == 1) + { + if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0) + return SZE_NOTIMPL; + return SZ_OK; + } + if (f->NumCoders == 2) + { + if (IS_NO_BCJ(f->Coders[1]) || + f->NumPackStreams != 1 || f->PackStreams[0] != 0 || + f->NumBindPairs != 1 || + f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0) + return SZE_NOTIMPL; + return SZ_OK; + } + if (f->NumCoders == 4) + { + if (IS_UNSUPPORTED_CODER(f->Coders[1]) || + IS_UNSUPPORTED_CODER(f->Coders[2]) || + IS_NO_BCJ2(f->Coders[3])) + return SZE_NOTIMPL; + if (f->NumPackStreams != 4 || + f->PackStreams[0] != 2 || + f->PackStreams[1] != 6 || + f->PackStreams[2] != 1 || + f->PackStreams[3] != 0 || + f->NumBindPairs != 3 || + f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 || + f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 || + f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2) + return SZE_NOTIMPL; + return SZ_OK; + } + return SZE_NOTIMPL; +} - CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */ - int result; - SizeT outSizeProcessedLoc; +CFileSize GetSum(const CFileSize *values, UInt32 index) +{ + CFileSize sum = 0; + UInt32 i; + for (i = 0; i < index; i++) + sum += values[i]; + return sum; +} +SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder, #ifdef _LZMA_IN_CB - lzmaCallback.Size = inSize; - lzmaCallback.InStream = inStream; - lzmaCallback.InCallback.Read = LzmaReadImp; + ISzInStream *inStream, CFileSize startPos, + #else + const Byte *inBuffer, #endif + Byte *outBuffer, size_t outSize, ISzAlloc *allocMain, + Byte *tempBuf[]) +{ + UInt32 ci; + size_t tempSizes[3] = { 0, 0, 0}; + size_t tempSize3 = 0; + Byte *tempBuf3 = 0; - if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, - coder->Properties.Capacity) != LZMA_RESULT_OK) - return SZE_FAIL; + RINOK(CheckSupportedFolder(folder)); - state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); - if (state.Probs == 0) - return SZE_OUTOFMEMORY; + for (ci = 0; ci < folder->NumCoders; ci++) + { + CCoderInfo *coder = &folder->Coders[ci]; - #ifdef _LZMA_OUT_READ - if (state.Properties.DictionarySize == 0) - state.Dictionary = 0; - else + if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA) { - state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize); - if (state.Dictionary == 0) + UInt32 si = 0; + CFileSize offset; + CFileSize inSize; + Byte *outBufCur = outBuffer; + size_t outSizeCur = outSize; + if (folder->NumCoders == 4) { - allocMain->Free(state.Probs); - return SZE_OUTOFMEMORY; + UInt32 indices[] = { 3, 2, 0 }; + CFileSize unpackSize = folder->UnPackSizes[ci]; + si = indices[ci]; + if (ci < 2) + { + Byte *temp; + outSizeCur = (size_t)unpackSize; + if (outSizeCur != unpackSize) + return SZE_OUTOFMEMORY; + temp = (Byte *)allocMain->Alloc(outSizeCur); + if (temp == 0 && outSizeCur != 0) + return SZE_OUTOFMEMORY; + outBufCur = tempBuf[1 - ci] = temp; + tempSizes[1 - ci] = outSizeCur; + } + else if (ci == 2) + { + if (unpackSize > outSize) + return SZE_OUTOFMEMORY; + tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize); + tempSize3 = outSizeCur = (size_t)unpackSize; + } + else + return SZE_NOTIMPL; } - } - LzmaDecoderInit(&state); - #endif + offset = GetSum(packSizes, si); + inSize = packSizes[si]; + #ifdef _LZMA_IN_CB + RINOK(inStream->Seek(inStream, startPos + offset)); + #endif - result = LzmaDecode(&state, + if (coder->MethodID == k_Copy) + { + if (inSize != outSizeCur) + return SZE_DATA_ERROR; + #ifdef _LZMA_IN_CB - &lzmaCallback.InCallback, + RINOK(SzDecodeCopy(inSize, inStream, outBufCur)); #else - inBuffer, (SizeT)inSize, &inProcessed, + memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize); #endif - outBuffer, (SizeT)outSize, &outSizeProcessedLoc); - *outSizeProcessed = (size_t)outSizeProcessedLoc; - allocMain->Free(state.Probs); - #ifdef _LZMA_OUT_READ - allocMain->Free(state.Dictionary); - #endif - if (result == LZMA_RESULT_DATA_ERROR) - return SZE_DATA_ERROR; - if (result != LZMA_RESULT_OK) - return SZE_FAIL; - return SZ_OK; + } + else + { + SZ_RESULT res = SzDecodeLzma(coder, inSize, + #ifdef _LZMA_IN_CB + inStream, + #else + inBuffer + (size_t)offset, + #endif + outBufCur, outSizeCur, allocMain); + RINOK(res) + } + } + else if (coder->MethodID == k_BCJ) + { + UInt32 state; + if (ci != 1) + return SZE_NOTIMPL; + x86_Convert_Init(state); + x86_Convert(outBuffer, outSize, 0, &state, 0); + } + else if (coder->MethodID == k_BCJ2) + { + CFileSize offset = GetSum(packSizes, 1); + CFileSize s3Size = packSizes[1]; + SZ_RESULT res; + if (ci != 3) + return SZE_NOTIMPL; + + #ifdef _LZMA_IN_CB + RINOK(inStream->Seek(inStream, startPos + offset)); + tempSizes[2] = (size_t)s3Size; + if (tempSizes[2] != s3Size) + return SZE_OUTOFMEMORY; + tempBuf[2] = (Byte *)allocMain->Alloc(tempSizes[2]); + if (tempBuf[2] == 0 && tempSizes[2] != 0) + return SZE_OUTOFMEMORY; + res = SzDecodeCopy(s3Size, inStream, tempBuf[2]); + RINOK(res) + #endif + + res = x86_2_Decode( + tempBuf3, tempSize3, + tempBuf[0], tempSizes[0], + tempBuf[1], tempSizes[1], + #ifdef _LZMA_IN_CB + tempBuf[2], tempSizes[2], + #else + inBuffer + (size_t)offset, (size_t)s3Size, + #endif + outBuffer, outSize); + RINOK(res) + } + else + return SZE_NOTIMPL; } - return SZE_NOTIMPL; + return SZ_OK; +} + +SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder, + #ifdef _LZMA_IN_CB + ISzInStream *inStream, CFileSize startPos, + #else + const Byte *inBuffer, + #endif + Byte *outBuffer, size_t outSize, ISzAlloc *allocMain) +{ + Byte *tempBuf[3] = { 0, 0, 0}; + int i; + SZ_RESULT res = SzDecode2(packSizes, folder, + #ifdef _LZMA_IN_CB + inStream, startPos, + #else + inBuffer, + #endif + outBuffer, outSize, allocMain, tempBuf); + for (i = 0; i < 3; i++) + allocMain->Free(tempBuf[i]); + return res; } diff --git a/C/Archive/7z/7zDecode.h b/C/Archive/7z/7zDecode.h index 74bb180f..175896ef 100755 --- a/C/Archive/7z/7zDecode.h +++ b/C/Archive/7z/7zDecode.h @@ -11,11 +11,10 @@ SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder, #ifdef _LZMA_IN_CB - ISzInStream *stream, + ISzInStream *stream, CFileSize startPos, #else const Byte *inBuffer, #endif - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain); + Byte *outBuffer, size_t outSize, ISzAlloc *allocMain); #endif diff --git a/C/Archive/7z/7zExtract.c b/C/Archive/7z/7zExtract.c index 75733fd1..1760a3ce 100755 --- a/C/Archive/7z/7zExtract.c +++ b/C/Archive/7z/7zExtract.c @@ -32,63 +32,64 @@ SZ_RESULT SzExtract( if (*outBuffer == 0 || *blockIndex != folderIndex) { CFolder *folder = db->Database.Folders + folderIndex; - CFileSize unPackSize = SzFolderGetUnPackSize(folder); + CFileSize unPackSizeSpec = SzFolderGetUnPackSize(folder); + size_t unPackSize = (size_t)unPackSizeSpec; + CFileSize startOffset = SzArDbGetFolderStreamPos(db, folderIndex, 0); #ifndef _LZMA_IN_CB - CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex); Byte *inBuffer = 0; size_t processedSize; + CFileSize packSizeSpec; + size_t packSize; + RINOK(SzArDbGetFolderFullPackSize(db, folderIndex, &packSizeSpec)); + packSize = (size_t)packSizeSpec; + if (packSize != packSizeSpec) + return SZE_OUTOFMEMORY; #endif - if (unPackSize != (size_t)unPackSize) + if (unPackSize != unPackSizeSpec) return SZE_OUTOFMEMORY; *blockIndex = folderIndex; allocMain->Free(*outBuffer); *outBuffer = 0; - RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0))); + RINOK(inStream->Seek(inStream, startOffset)); #ifndef _LZMA_IN_CB if (packSize != 0) { - inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize); + inBuffer = (Byte *)allocTemp->Alloc(packSize); if (inBuffer == 0) return SZE_OUTOFMEMORY; } - res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize); - if (res == SZ_OK && processedSize != (size_t)packSize) + res = inStream->Read(inStream, inBuffer, packSize, &processedSize); + if (res == SZ_OK && processedSize != packSize) res = SZE_FAIL; #endif if (res == SZ_OK) { - *outBufferSize = (size_t)unPackSize; + *outBufferSize = unPackSize; if (unPackSize != 0) { - *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize); + *outBuffer = (Byte *)allocMain->Alloc(unPackSize); if (*outBuffer == 0) res = SZE_OUTOFMEMORY; } if (res == SZ_OK) { - size_t outRealSize; res = SzDecode(db->Database.PackSizes + db->FolderStartPackStreamIndex[folderIndex], folder, #ifdef _LZMA_IN_CB - inStream, + inStream, startOffset, #else inBuffer, #endif - *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp); + *outBuffer, unPackSize, allocTemp); if (res == SZ_OK) { - if (outRealSize == (size_t)unPackSize) + if (folder->UnPackCRCDefined) { - if (folder->UnPackCRCDefined) - { - if (CrcCalc(*outBuffer, (size_t)unPackSize) != folder->UnPackCRC) - res = SZE_FAIL; - } + if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC) + res = SZE_CRC_ERROR; } - else - res = SZE_FAIL; } } } @@ -110,7 +111,7 @@ SZ_RESULT SzExtract( if (fileItem->IsFileCRCDefined) { if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC) - res = SZE_FAIL; + res = SZE_CRC_ERROR; } } } diff --git a/C/Archive/7z/7zIn.c b/C/Archive/7z/7zIn.c index 04e83a8e..ac25dbc7 100755 --- a/C/Archive/7z/7zIn.c +++ b/C/Archive/7z/7zIn.c @@ -117,15 +117,21 @@ CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, U db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder]; } -CFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex) +int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize) { UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex]; CFolder *folder = db->Database.Folders + folderIndex; CFileSize size = 0; UInt32 i; for (i = 0; i < folder->NumPackStreams; i++) - size += db->Database.PackSizes[packStreamIndex + i]; - return size; + { + CFileSize t = size + db->Database.PackSizes[packStreamIndex + i]; + if (t < size) + return SZE_FAIL; + size = t; + } + *resSize = size; + return SZ_OK; } @@ -500,9 +506,17 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)( Byte mainByte; CCoderInfo *coder = folder->Coders + i; { + unsigned idSize, j; + Byte longID[15]; RINOK(SzReadByte(sd, &mainByte)); - coder->MethodID.IDSize = (Byte)(mainByte & 0xF); - RINOK(SzReadBytes(sd, coder->MethodID.ID, coder->MethodID.IDSize)); + idSize = (unsigned)(mainByte & 0xF); + RINOK(SzReadBytes(sd, longID, idSize)); + if (idSize > sizeof(coder->MethodID)) + return SZE_NOTIMPL; + coder->MethodID = 0; + for (j = 0; j < idSize; j++) + coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j); + if ((mainByte & 0x10) != 0) { RINOK(SzReadNumber32(sd, &coder->NumInStreams)); @@ -926,6 +940,7 @@ SZ_RESULT SzReadHeader2( UInt32 **digests, /* allocTemp */ Byte **emptyStreamVector, /* allocTemp */ Byte **emptyFileVector, /* allocTemp */ + Byte **lwtVector, /* allocTemp */ ISzAlloc *allocMain, ISzAlloc *allocTemp) { @@ -1008,6 +1023,24 @@ SZ_RESULT SzReadHeader2( RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc)); break; } + case k7zIdLastWriteTime: + { + RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp->Alloc)); + RINOK(SzReadSwitch(sd)); + for (i = 0; i < numFiles; i++) + { + CFileItem *f = &files[i]; + Byte defined = (*lwtVector)[i]; + f->IsLastWriteTimeDefined = defined; + f->LastWriteTime.Low = f->LastWriteTime.High = 0; + if (defined) + { + RINOK(SzReadUInt32(sd, &f->LastWriteTime.Low)); + RINOK(SzReadUInt32(sd, &f->LastWriteTime.High)); + } + } + break; + } default: { RINOK(SzSkeepDataSize(sd, size)); @@ -1060,15 +1093,17 @@ SZ_RESULT SzReadHeader( UInt32 *digests = 0; Byte *emptyStreamVector = 0; Byte *emptyFileVector = 0; + Byte *lwtVector = 0; SZ_RESULT res = SzReadHeader2(sd, db, &unPackSizes, &digestsDefined, &digests, - &emptyStreamVector, &emptyFileVector, + &emptyStreamVector, &emptyFileVector, &lwtVector, allocMain, allocTemp); allocTemp->Free(unPackSizes); allocTemp->Free(digestsDefined); allocTemp->Free(digests); allocTemp->Free(emptyStreamVector); allocTemp->Free(emptyFileVector); + allocTemp->Free(lwtVector); return res; } @@ -1095,7 +1130,6 @@ SZ_RESULT SzReadAndDecodePackedStreams2( UInt32 i = 0; #endif CFileSize unPackSize; - size_t outRealSize; SZ_RESULT res; RINOK(SzReadStreamsInfo(sd, &dataStartPos, db, @@ -1125,15 +1159,12 @@ SZ_RESULT SzReadAndDecodePackedStreams2( res = SzDecode(db->PackSizes, folder, #ifdef _LZMA_IN_CB - inStream, + inStream, dataStartPos, #else *inBuffer, #endif - outBuffer->Items, (size_t)unPackSize, - &outRealSize, allocTemp); + outBuffer->Items, (size_t)unPackSize, allocTemp); RINOK(res) - if (outRealSize != (UInt32)unPackSize) - return SZE_FAIL; if (folder->UnPackCRCDefined) if (CrcCalc(outBuffer->Items, (size_t)unPackSize) != folder->UnPackCRC) return SZE_FAIL; diff --git a/C/Archive/7z/7zIn.h b/C/Archive/7z/7zIn.h index 6bfa2a70..0b4ca08d 100755 --- a/C/Archive/7z/7zIn.h +++ b/C/Archive/7z/7zIn.h @@ -26,7 +26,7 @@ typedef struct _CArchiveDatabaseEx void SzArDbExInit(CArchiveDatabaseEx *db); void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *)); CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder); -CFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex); +int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize); typedef struct _ISzInStream { diff --git a/C/Archive/7z/7zItem.c b/C/Archive/7z/7zItem.c index 2a408050..a88afe9a 100755 --- a/C/Archive/7z/7zItem.c +++ b/C/Archive/7z/7zItem.c @@ -96,6 +96,7 @@ void SzFileInit(CFileItem *fileItem) fileItem->HasStream = 1; fileItem->IsDirectory = 0; fileItem->IsAnti = 0; + fileItem->IsLastWriteTimeDefined = 0; fileItem->Name = 0; } diff --git a/C/Archive/7z/7zItem.h b/C/Archive/7z/7zItem.h index 876539a9..05567bff 100755 --- a/C/Archive/7z/7zItem.h +++ b/C/Archive/7z/7zItem.h @@ -45,12 +45,16 @@ int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex); UInt32 SzFolderGetNumOutStreams(CFolder *folder); CFileSize SzFolderGetUnPackSize(CFolder *folder); -/* #define CArchiveFileTime UInt64 */ +typedef struct _CArchiveFileTime +{ + UInt32 Low; + UInt32 High; +} CArchiveFileTime; typedef struct _CFileItem { - /* CArchiveFileTime LastWriteTime; + /* CFileSize StartPos; UInt32 Attributes; */ @@ -62,6 +66,7 @@ typedef struct _CFileItem Byte HasStream; Byte IsDirectory; Byte IsAnti; + Byte IsLastWriteTimeDefined; /* int AreAttributesDefined; int IsLastWriteTimeDefined; diff --git a/C/Archive/7z/7zMain.c b/C/Archive/7z/7zMain.c index 74f0afd5..0deef893 100755 --- a/C/Archive/7z/7zMain.c +++ b/C/Archive/7z/7zMain.c @@ -44,6 +44,61 @@ void ConvertNumberToString(CFileSize value, char *s) *s = '\0'; } +#define PERIOD_4 (4 * 365 + 1) +#define PERIOD_100 (PERIOD_4 * 25 - 1) +#define PERIOD_400 (PERIOD_100 * 4 + 1) + +void ConvertFileTimeToString(CArchiveFileTime *ft, char *s) +{ + unsigned year, mon, day, hour, min, sec; + UInt64 v64 = ft->Low | ((UInt64)ft->High << 32); + Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + unsigned temp; + UInt32 v; + v64 /= 10000000; + sec = (unsigned)(v64 % 60); + v64 /= 60; + min = (unsigned)(v64 % 60); + v64 /= 60; + hour = (unsigned)(v64 % 24); + v64 /= 24; + + v = (UInt32)v64; + + year = (unsigned)(1601 + v / PERIOD_400 * 400); + v %= PERIOD_400; + + temp = (unsigned)(v / PERIOD_100); + if (temp == 4) + temp = 3; + year += temp * 100; + v -= temp * PERIOD_100; + + temp = v / PERIOD_4; + if (temp == 25) + temp = 24; + year += temp * 4; + v -= temp * PERIOD_4; + + temp = v / 365; + if (temp == 4) + temp = 3; + year += temp; + v -= temp * 365; + + if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) + ms[1] = 29; + for (mon = 1; mon <= 12; mon++) + { + unsigned s = ms[mon - 1]; + if (v < s) + break; + v -= s; + } + day = (unsigned)v + 1; + sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec); +} + #ifdef USE_WINDOWS_FUNCTIONS /* @@ -193,7 +248,7 @@ int main(int numargs, char *args[]) ISzAlloc allocImp; ISzAlloc allocTempImp; - printf("\n7z ANSI-C Decoder 4.45 Copyright (c) 1999-2007 Igor Pavlov 2007-03-15\n"); + printf("\n7z ANSI-C Decoder 4.48 Copyright (c) 1999-2007 Igor Pavlov 2007-06-21\n"); if (numargs == 1) { printf( @@ -256,9 +311,14 @@ int main(int numargs, char *args[]) for (i = 0; i < db.Database.NumFiles; i++) { CFileItem *f = db.Database.Files + i; - char s[32]; + char s[32], t[32]; ConvertNumberToString(f->Size, s); - printf("%10s %s\n", s, f->Name); + if (f->IsLastWriteTimeDefined) + ConvertFileTimeToString(&f->LastWriteTime, t); + else + strcpy(t, " "); + + printf("%10s %s %s\n", s, t, f->Name); } } else if (testCommand || extractCommand) @@ -300,7 +360,7 @@ int main(int numargs, char *args[]) if (!testCommand) { MY_FILE_HANDLE outputHandle; - UInt32 processedSize; + size_t processedSize; char *fileName = f->Name; size_t nameLen = strlen(f->Name); for (; nameLen > 0; nameLen--) @@ -356,8 +416,12 @@ int main(int numargs, char *args[]) printf("\nEverything is Ok\n"); return 0; } - if (res == (SZ_RESULT)SZE_OUTOFMEMORY) + if (res == (SZ_RESULT)SZE_NOTIMPL) + PrintError("decoder doesn't support this archive"); + else if (res == (SZ_RESULT)SZE_OUTOFMEMORY) PrintError("can not allocate memory"); + else if (res == (SZ_RESULT)SZE_CRC_ERROR) + PrintError("CRC error"); else printf("\nERROR #%d\n", res); return 1; diff --git a/C/Archive/7z/7zMethodID.c b/C/Archive/7z/7zMethodID.c index 5047359f..a7e825de 100755 --- a/C/Archive/7z/7zMethodID.c +++ b/C/Archive/7z/7zMethodID.c @@ -2,13 +2,9 @@ #include "7zMethodID.h" +/* int AreMethodsEqual(CMethodID *a1, CMethodID *a2) { - int i; - if (a1->IDSize != a2->IDSize) - return 0; - for (i = 0; i < a1->IDSize; i++) - if (a1->ID[i] != a2->ID[i]) - return 0; - return 1; + return (*a1 == *a2) ? 1 : 0; } +*/ diff --git a/C/Archive/7z/7zMethodID.h b/C/Archive/7z/7zMethodID.h index 8eb301da..57f22a50 100755 --- a/C/Archive/7z/7zMethodID.h +++ b/C/Archive/7z/7zMethodID.h @@ -5,14 +5,6 @@ #include "../../Types.h" -#define kMethodIDSize 15 - -typedef struct _CMethodID -{ - Byte ID[kMethodIDSize]; - Byte IDSize; -} CMethodID; - -int AreMethodsEqual(CMethodID *a1, CMethodID *a2); +typedef UInt64 CMethodID; #endif diff --git a/C/Archive/7z/7z_C.dsp b/C/Archive/7z/7z_C.dsp index e53d1d0a..9a040ad1 100755 --- a/C/Archive/7z/7z_C.dsp +++ b/C/Archive/7z/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 /MD /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /c # ADD BASE RSC /l 0x419 /d "NDEBUG" # ADD RSC /l 0x419 /d "NDEBUG" BSC32=bscmake.exe @@ -50,7 +50,8 @@ BSC32=bscmake.exe # 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:"Release/7zDec.exe" +# 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:"Release/7zDec.exe" /opt:NOWIN98 +# SUBTRACT LINK32 /pdb:none !ELSEIF "$(CFG)" == "7z_C - Win32 Debug" @@ -114,6 +115,30 @@ SOURCE=..\..\7zCrc.h SOURCE=..\..\Types.h # End Source File # End Group +# Begin Group "Branch" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchTypes.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchX86.c +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchX86.h +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchX86_2.c +# End Source File +# Begin Source File + +SOURCE=..\..\Compress\Branch\BranchX86_2.h +# End Source File +# End Group # Begin Source File SOURCE=.\7zAlloc.c diff --git a/C/Archive/7z/makefile b/C/Archive/7z/makefile index d6181717..6ea3119a 100755 --- a/C/Archive/7z/makefile +++ b/C/Archive/7z/makefile @@ -1,5 +1,10 @@ PROG = 7zDec.exe +!IFDEF CPU +LIBS = $(LIBS) bufferoverflowU.lib +CFLAGS = $(CFLAGS) -GS- -Zc:forScope -WX -GS- -Gy -W4 +!ENDIF + !IFNDEF O !IFDEF CPU O=$(CPU) @@ -8,7 +13,7 @@ O=O !ENDIF !ENDIF -CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -GS- -WX -Gy +CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -D_LZMA_IN_CB CFLAGS_O1 = $(CFLAGS) -O1 CFLAGS_O2 = $(CFLAGS) -O2 @@ -38,6 +43,8 @@ C_OBJS = \ OBJS = \ $(7Z_OBJS) \ $O\LzmaDecode.obj \ + $O\BranchX86.obj \ + $O\BranchX86_2.obj \ $(C_OBJS) \ all: $(PROGPATH) @@ -56,5 +63,12 @@ $(7Z_OBJS): $(*B).c $(COMPL) $O\LzmaDecode.obj: ../../Compress/Lzma/$(*B).c $(COMPL_O2) + +$O\BranchX86.obj: ../../Compress/Branch/$(*B).c + $(COMPL_O2) + +$O\BranchX86_2.obj: ../../Compress/Branch/$(*B).c + $(COMPL_O2) + $(C_OBJS): ../../$(*B).c $(COMPL_O2) diff --git a/C/Archive/7z/makefile.gcc b/C/Archive/7z/makefile.gcc index 8de50b72..664ac252 100755 --- a/C/Archive/7z/makefile.gcc +++ b/C/Archive/7z/makefile.gcc @@ -2,9 +2,9 @@ PROG = 7zDec CXX = g++ LIB = RM = rm -f -CFLAGS = -c -O2 -Wall +CFLAGS = -c -O2 -Wall -D_LZMA_IN_CB -OBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o +OBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o BranchX86.o BranchX86_2.o all: $(PROG) @@ -44,6 +44,11 @@ $(PROG): $(OBJS) LzmaDecode.o: ../../Compress/Lzma/LzmaDecode.c $(CXX) $(CFLAGS) ../../Compress/Lzma/LzmaDecode.c +BranchX86.o: ../../Compress/Branch/BranchX86.c + $(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86.c + +BranchX86_2.o: ../../Compress/Branch/BranchX86_2.c + $(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86_2.c clean: -$(RM) $(PROG) $(OBJS) diff --git a/C/Compress/Branch/BranchTypes.h b/C/Compress/Branch/BranchTypes.h index bdf75131..1bed56a9 100755 --- a/C/Compress/Branch/BranchTypes.h +++ b/C/Compress/Branch/BranchTypes.h @@ -27,7 +27,7 @@ typedef unsigned int UInt32; #ifdef _SZ_NO_INT_64 typedef unsigned long UInt64; #else -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__BORLANDC__) typedef unsigned __int64 UInt64; #else typedef unsigned long long int UInt64; @@ -35,4 +35,17 @@ typedef unsigned long long int UInt64; #endif #endif +/* #define _LZMA_NO_SYSTEM_SIZE_T */ +/* You can use it, if you don't want */ + +#ifndef _7ZIP_SIZET_DEFINED +#define _7ZIP_SIZET_DEFINED +#ifdef _LZMA_NO_SYSTEM_SIZE_T +typedef UInt32 SizeT; +#else +#include +typedef size_t SizeT; +#endif +#endif + #endif diff --git a/C/Compress/Branch/BranchX86.c b/C/Compress/Branch/BranchX86.c index c3f455b8..fd1d334e 100755 --- a/C/Compress/Branch/BranchX86.c +++ b/C/Compress/Branch/BranchX86.c @@ -2,100 +2,83 @@ #include "BranchX86.h" -/* -static int inline Test86MSByte(Byte b) -{ - return (b == 0 || b == 0xFF); -} -*/ #define Test86MSByte(b) ((b) == 0 || (b) == 0xFF) -const int kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0}; +const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0}; const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3}; -/* -void x86_Convert_Init(UInt32 *prevMask, UInt32 *prevPos) -{ - *prevMask = 0; - *prevPos = (UInt32)(-5); -} -*/ - -UInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, - UInt32 *prevMask, UInt32 *prevPos, int encoding) +SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix, int encoding) { - UInt32 bufferPos = 0; - UInt32 limit; - + SizeT bufferPos = 0, prevPosT; + UInt32 prevMask = *prevMaskMix & 0x7; if (endPos < 5) return 0; - - if (nowPos - *prevPos > 5) - *prevPos = nowPos - 5; - - limit = endPos - 5; - while(bufferPos <= limit) + nowPos += 5; + prevPosT = (SizeT)0 - 1; + + for(;;) { - Byte b = buffer[bufferPos]; - UInt32 offset; - if (b != 0xE8 && b != 0xE9) - { - bufferPos++; - continue; - } - offset = (nowPos + bufferPos - *prevPos); - *prevPos = (nowPos + bufferPos); - if (offset > 5) - *prevMask = 0; + Byte *p = buffer + bufferPos; + Byte *limit = buffer + endPos - 4; + for (; p < limit; p++) + if ((*p & 0xFE) == 0xE8) + break; + bufferPos = (SizeT)(p - buffer); + if (p >= limit) + break; + prevPosT = bufferPos - prevPosT; + if (prevPosT > 3) + prevMask = 0; else { - UInt32 i; - for (i = 0; i < offset; i++) + prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7; + if (prevMask != 0) { - *prevMask &= 0x77; - *prevMask <<= 1; + Byte b = p[4 - kMaskToBitNumber[prevMask]]; + if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b)) + { + prevPosT = bufferPos; + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + continue; + } } } - b = buffer[bufferPos + 4]; - if (Test86MSByte(b) && kMaskToAllowedStatus[(*prevMask >> 1) & 0x7] && - (*prevMask >> 1) < 0x10) + prevPosT = bufferPos; + + if (Test86MSByte(p[4])) { - UInt32 src = - ((UInt32)(b) << 24) | - ((UInt32)(buffer[bufferPos + 3]) << 16) | - ((UInt32)(buffer[bufferPos + 2]) << 8) | - (buffer[bufferPos + 1]); - + UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); UInt32 dest; for (;;) { - UInt32 index; + Byte b; + int index; if (encoding) - dest = (nowPos + bufferPos + 5) + src; + dest = (nowPos + (UInt32)bufferPos) + src; else - dest = src - (nowPos + bufferPos + 5); - if (*prevMask == 0) + dest = src - (nowPos + (UInt32)bufferPos); + if (prevMask == 0) break; - index = kMaskToBitNumber[*prevMask >> 1]; - b = (Byte)(dest >> (24 - index * 8)); + index = kMaskToBitNumber[prevMask] * 8; + b = (Byte)(dest >> (24 - index)); if (!Test86MSByte(b)) break; - src = dest ^ ((1 << (32 - index * 8)) - 1); + src = dest ^ ((1 << (32 - index)) - 1); } - buffer[bufferPos + 4] = (Byte)(~(((dest >> 24) & 1) - 1)); - buffer[bufferPos + 3] = (Byte)(dest >> 16); - buffer[bufferPos + 2] = (Byte)(dest >> 8); - buffer[bufferPos + 1] = (Byte)dest; + p[4] = (Byte)(~(((dest >> 24) & 1) - 1)); + p[3] = (Byte)(dest >> 16); + p[2] = (Byte)(dest >> 8); + p[1] = (Byte)dest; bufferPos += 5; - *prevMask = 0; } else { + prevMask = ((prevMask << 1) & 0x7) | 1; bufferPos++; - *prevMask |= 1; - if (Test86MSByte(b)) - *prevMask |= 0x10; } } + prevPosT = bufferPos - prevPosT; + *prevMaskMix = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7)); return bufferPos; } diff --git a/C/Compress/Branch/BranchX86.h b/C/Compress/Branch/BranchX86.h index 25c1ae51..5dfd02a7 100755 --- a/C/Compress/Branch/BranchX86.h +++ b/C/Compress/Branch/BranchX86.h @@ -5,9 +5,8 @@ #include "BranchTypes.h" -#define x86_Convert_Init(prevMask, prevPos) { prevMask = 0; prevPos = (UInt32)(-5); } +#define x86_Convert_Init(state) { state = 0; } -UInt32 x86_Convert(Byte *buffer, UInt32 endPos, UInt32 nowPos, - UInt32 *prevMask, UInt32 *prevPos, int encoding); +SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *state, int encoding); #endif diff --git a/C/Compress/Branch/BranchX86_2.c b/C/Compress/Branch/BranchX86_2.c new file mode 100755 index 00000000..241789a5 --- /dev/null +++ b/C/Compress/Branch/BranchX86_2.c @@ -0,0 +1,135 @@ +// BranchX86_2.c + +#include "BranchX86_2.h" + +#include "../../Alloc.h" + +#ifdef _LZMA_PROB32 +#define CProb UInt32 +#else +#define CProb UInt16 +#endif + +#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80) +#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)) + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_READ_BYTE (*Buffer++) + +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \ + { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }} + +#define RC_TEST { if (Buffer == BufferLim) return BCJ2_RESULT_DATA_ERROR; } + +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2 + +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } + +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; +// #define UpdateBit0(p) Range = bound; *(p) = (CProb)(*(p) + ((kBitModelTotal - *(p)) >> kNumMoveBits)); +// #define UpdateBit1(p) Range -= bound; Code -= bound; *(p) = (CProb)(*(p) - (*(p) >> kNumMoveBits)); + +int x86_2_Decode( + const Byte *buf0, SizeT size0, + const Byte *buf1, SizeT size1, + const Byte *buf2, SizeT size2, + const Byte *buf3, SizeT size3, + Byte *outBuf, SizeT outSize) +{ + CProb p[256 + 2]; + SizeT inPos = 0, outPos = 0; + + const Byte *Buffer, *BufferLim; + UInt32 Range, Code; + Byte prevByte = 0; + + unsigned int i; + for (i = 0; i < sizeof(p) / sizeof(p[0]); i++) + p[i] = kBitModelTotal >> 1; + RC_INIT(buf3, size3); + + if (outSize == 0) + return BCJ2_RESULT_OK; + + for (;;) + { + Byte b; + CProb *prob; + UInt32 bound; + + SizeT limit = size0 - inPos; + if (outSize - outPos < limit) + limit = outSize - outPos; + while (limit != 0) + { + Byte b = buf0[inPos]; + outBuf[outPos++] = b; + if (IsJ(prevByte, b)) + break; + inPos++; + prevByte = b; + limit--; + } + + if (limit == 0 || outPos == outSize) + break; + + b = buf0[inPos++]; + + if (b == 0xE8) + prob = p + prevByte; + else if (b == 0xE9) + prob = p + 256; + else + prob = p + 257; + + IfBit0(prob) + { + UpdateBit0(prob) + prevByte = b; + } + else + { + UInt32 dest; + const Byte *v; + UpdateBit1(prob) + if (b == 0xE8) + { + v = buf1; + if (size1 < 4) + return BCJ2_RESULT_DATA_ERROR; + buf1 += 4; + size1 -= 4; + } + else + { + v = buf2; + if (size2 < 4) + return BCJ2_RESULT_DATA_ERROR; + buf2 += 4; + size2 -= 4; + } + dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | + ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4); + outBuf[outPos++] = (Byte)dest; + if (outPos == outSize) + break; + outBuf[outPos++] = (Byte)(dest >> 8); + if (outPos == outSize) + break; + outBuf[outPos++] = (Byte)(dest >> 16); + if (outPos == outSize) + break; + outBuf[outPos++] = prevByte = (Byte)(dest >> 24); + } + } + return (outPos == outSize) ? BCJ2_RESULT_OK : BCJ2_RESULT_DATA_ERROR; +} diff --git a/C/Compress/Branch/BranchX86_2.h b/C/Compress/Branch/BranchX86_2.h new file mode 100755 index 00000000..4d861fa3 --- /dev/null +++ b/C/Compress/Branch/BranchX86_2.h @@ -0,0 +1,28 @@ +// BranchX86_2.h + +#ifndef __BRANCHX86_2_H +#define __BRANCHX86_2_H + +#include "BranchTypes.h" + +#define BCJ2_RESULT_OK 0 +#define BCJ2_RESULT_DATA_ERROR 1 + +/* +Conditions: + outSize <= FullOutputSize, + where FullOutputSize is full size of output stream of x86_2 filter. + +If buf0 overlaps outBuf, there are two required conditions: + 1) (buf0 >= outBuf) + 2) (buf0 + size0 >= outBuf + FullOutputSize). +*/ + +int x86_2_Decode( + const Byte *buf0, SizeT size0, + const Byte *buf1, SizeT size1, + const Byte *buf2, SizeT size2, + const Byte *buf3, SizeT size3, + Byte *outBuf, SizeT outSize); + +#endif diff --git a/C/Compress/Lzma/LzmaStateDecode.c b/C/Compress/Lzma/LzmaStateDecode.c index e50f88b5..5dc8f0e2 100755 --- a/C/Compress/Lzma/LzmaStateDecode.c +++ b/C/Compress/Lzma/LzmaStateDecode.c @@ -227,7 +227,7 @@ int LzmaDecode( else previousByte = dictionary[dictionaryPos - 1]; - while(1) + for (;;) { int bufferPos = (int)(Buffer - vs->Buffer); if (BufferSize - bufferPos < kRequiredInBufferSize) diff --git a/C/Compress/Lzma/LzmaTypes.h b/C/Compress/Lzma/LzmaTypes.h index 288c5e45..9c272907 100755 --- a/C/Compress/Lzma/LzmaTypes.h +++ b/C/Compress/Lzma/LzmaTypes.h @@ -29,16 +29,16 @@ 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 */ +/* #define _LZMA_NO_SYSTEM_SIZE_T */ +/* You can use it, if you don't want */ #ifndef _7ZIP_SIZET_DEFINED #define _7ZIP_SIZET_DEFINED -#ifdef _LZMA_SYSTEM_SIZE_T +#ifdef _LZMA_NO_SYSTEM_SIZE_T +typedef UInt32 SizeT; +#else #include typedef size_t SizeT; -#else -typedef UInt32 SizeT; #endif #endif diff --git a/C/Types.h b/C/Types.h index a781f481..368cc314 100755 --- a/C/Types.h +++ b/C/Types.h @@ -39,7 +39,7 @@ typedef int Int32; #ifdef _SZ_NO_INT_64 typedef unsigned long UInt64; #else -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__BORLANDC__) typedef unsigned __int64 UInt64; #else typedef unsigned long long int UInt64; diff --git a/CPP/7zip/Archive/7z/7z.dsp b/CPP/7zip/Archive/7z/7z.dsp index de892631..fc4c3698 100755 --- a/CPP/7zip/Archive/7z/7z.dsp +++ b/CPP/7zip/Archive/7z/7z.dsp @@ -290,43 +290,43 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringToInt.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringToInt.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\StringToInt.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\StringToInt.h # End Source File # End Group # Begin Group "Archive Common" @@ -358,6 +358,14 @@ SOURCE=..\Common\CrossThreadProgress.h # End Source File # Begin Source File +SOURCE=..\Common\HandlerOut.cpp +# End Source File +# Begin Source File + +SOURCE=..\Common\HandlerOut.h +# End Source File +# Begin Source File + SOURCE=..\Common\InStreamWithCRC.cpp # End Source File # Begin Source File @@ -450,6 +458,14 @@ SOURCE=..\..\Common\MethodId.h # End Source File # Begin Source File +SOURCE=..\..\Common\MethodProps.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MethodProps.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\OutBuffer.cpp # End Source File # Begin Source File @@ -496,6 +512,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "Windows" @@ -558,6 +582,14 @@ SOURCE=..\..\..\Windows\Synchronization.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\System.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Thread.h # End Source File # End Group @@ -594,6 +626,15 @@ SOURCE=..\..\..\..\C\Alloc.c SOURCE=..\..\..\..\C\Alloc.h # End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\Threads.h +# End Source File # End Group # Begin Source File diff --git a/CPP/7zip/Archive/7z/7zCompressionMode.h b/CPP/7zip/Archive/7z/7zCompressionMode.h index 65e573d1..5753606f 100755 --- a/CPP/7zip/Archive/7z/7zCompressionMode.h +++ b/CPP/7zip/Archive/7z/7zCompressionMode.h @@ -3,28 +3,20 @@ #ifndef __7Z_COMPRESSION_MODE_H #define __7Z_COMPRESSION_MODE_H -#include "../../../Common/String.h" +#include "../../../Common/MyString.h" #include "../../../Windows/PropVariant.h" -#include "../../Common/MethodId.h" +#include "../../Common/MethodProps.h" namespace NArchive { namespace N7z { -struct CProperty +struct CMethodFull: public CMethod { - PROPID PropID; - NWindows::NCOM::CPropVariant Value; -}; - -struct CMethodFull -{ - CMethodId MethodID; UInt32 NumInStreams; UInt32 NumOutStreams; bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); } - CObjectVector CoderProperties; }; struct CBind diff --git a/CPP/7zip/Archive/7z/7zDecode.cpp b/CPP/7zip/Archive/7z/7zDecode.cpp index 19b08b78..0f81de40 100755 --- a/CPP/7zip/Archive/7z/7zDecode.cpp +++ b/CPP/7zip/Archive/7z/7zDecode.cpp @@ -22,7 +22,7 @@ static void ConvertFolderItemInfoToBindInfo(const CFolder &folder, int i; for (i = 0; i < folder.BindPairs.Size(); i++) { - NCoderMixer2::CBindPair bindPair; + NCoderMixer::CBindPair bindPair; bindPair.InIndex = (UInt32)folder.BindPairs[i].InIndex; bindPair.OutIndex = (UInt32)folder.BindPairs[i].OutIndex; bindInfo.BindPairs.Add(bindPair); @@ -30,7 +30,7 @@ static void ConvertFolderItemInfoToBindInfo(const CFolder &folder, UInt32 outStreamIndex = 0; for (i = 0; i < folder.Coders.Size(); i++) { - NCoderMixer2::CCoderStreamsInfo coderStreamsInfo; + NCoderMixer::CCoderStreamsInfo coderStreamsInfo; const CCoderInfo &coderInfo = folder.Coders[i]; coderStreamsInfo.NumInStreams = (UInt32)coderInfo.NumInStreams; coderStreamsInfo.NumOutStreams = (UInt32)coderInfo.NumOutStreams; @@ -44,14 +44,14 @@ static void ConvertFolderItemInfoToBindInfo(const CFolder &folder, bindInfo.InStreams.Add((UInt32)folder.PackStreams[i]); } -static bool AreCodersEqual(const NCoderMixer2::CCoderStreamsInfo &a1, - const NCoderMixer2::CCoderStreamsInfo &a2) +static bool AreCodersEqual(const NCoderMixer::CCoderStreamsInfo &a1, + const NCoderMixer::CCoderStreamsInfo &a2) { return (a1.NumInStreams == a2.NumInStreams) && (a1.NumOutStreams == a2.NumOutStreams); } -static bool AreBindPairsEqual(const NCoderMixer2::CBindPair &a1, const NCoderMixer2::CBindPair &a2) +static bool AreBindPairsEqual(const NCoderMixer::CBindPair &a1, const NCoderMixer::CBindPair &a2) { return (a1.InIndex == a2.InIndex) && (a1.OutIndex == a2.OutIndex); @@ -145,14 +145,14 @@ HRESULT CDecoder::Decode( if (_multiThread) { - _mixerCoderMTSpec = new NCoderMixer2::CCoderMixer2MT; + _mixerCoderMTSpec = new NCoderMixer::CCoderMixer2MT; _mixerCoder = _mixerCoderMTSpec; _mixerCoderCommon = _mixerCoderMTSpec; } else { #ifdef _ST_MODE - _mixerCoderSTSpec = new NCoderMixer2::CCoderMixer2ST; + _mixerCoderSTSpec = new NCoderMixer::CCoderMixer2ST; _mixerCoder = _mixerCoderSTSpec; _mixerCoderCommon = _mixerCoderSTSpec; #endif diff --git a/CPP/7zip/Archive/7z/7zDecode.h b/CPP/7zip/Archive/7z/7zDecode.h index 2e493c37..7c10dfe2 100755 --- a/CPP/7zip/Archive/7z/7zDecode.h +++ b/CPP/7zip/Archive/7z/7zDecode.h @@ -19,7 +19,7 @@ namespace NArchive { namespace N7z { -struct CBindInfoEx: public NCoderMixer2::CBindInfo +struct CBindInfoEx: public NCoderMixer::CBindInfo { CRecordVector CoderMethodIDs; void Clear() @@ -36,10 +36,10 @@ class CDecoder bool _multiThread; #ifdef _ST_MODE - NCoderMixer2::CCoderMixer2ST *_mixerCoderSTSpec; + NCoderMixer::CCoderMixer2ST *_mixerCoderSTSpec; #endif - NCoderMixer2::CCoderMixer2MT *_mixerCoderMTSpec; - NCoderMixer2::CCoderMixer2 *_mixerCoderCommon; + NCoderMixer::CCoderMixer2MT *_mixerCoderMTSpec; + NCoderMixer::CCoderMixer2 *_mixerCoderCommon; CMyComPtr _mixerCoder; CObjectVector > _decoders; diff --git a/CPP/7zip/Archive/7z/7zEncode.cpp b/CPP/7zip/Archive/7z/7zEncode.cpp index ef74b9bf..8c229362 100755 --- a/CPP/7zip/Archive/7z/7zEncode.cpp +++ b/CPP/7zip/Archive/7z/7zEncode.cpp @@ -13,14 +13,12 @@ #include "../../Common/CreateCoder.h" #include "../../Common/FilterCoder.h" -static UInt64 k_LZMA = 0x030101; -// static UInt64 k_LZMA2 = 0x030102; static UInt64 k_AES = 0x06F10701; namespace NArchive { namespace N7z { -static void ConvertBindInfoToFolderItemInfo(const NCoderMixer2::CBindInfo &bindInfo, +static void ConvertBindInfoToFolderItemInfo(const NCoderMixer::CBindInfo &bindInfo, const CRecordVector decompressionMethods, CFolder &folder) { @@ -40,7 +38,7 @@ static void ConvertBindInfoToFolderItemInfo(const NCoderMixer2::CBindInfo &bindI for (i = 0; i < bindInfo.Coders.Size(); i++) { CCoderInfo coderInfo; - const NCoderMixer2::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i]; + const NCoderMixer::CCoderStreamsInfo &coderStreamsInfo = bindInfo.Coders[i]; coderInfo.NumInStreams = coderStreamsInfo.NumInStreams; coderInfo.NumOutStreams = coderStreamsInfo.NumOutStreams; coderInfo.MethodID = decompressionMethods[i]; @@ -54,49 +52,25 @@ HRESULT CEncoder::CreateMixerCoder( DECL_EXTERNAL_CODECS_LOC_VARS const UInt64 *inSizeForReduce) { - _mixerCoderSpec = new NCoderMixer2::CCoderMixer2MT; + _mixerCoderSpec = new NCoderMixer::CCoderMixer2MT; _mixerCoder = _mixerCoderSpec; RINOK(_mixerCoderSpec->SetBindInfo(_bindInfo)); for (int i = 0; i < _options.Methods.Size(); i++) { const CMethodFull &methodFull = _options.Methods[i]; _codersInfo.Add(CCoderInfo()); - CCoderInfo &encodingInfo = _codersInfo.Back(); + // CCoderInfo &encodingInfo = _codersInfo.Back(); CMyComPtr encoder; CMyComPtr encoder2; RINOK(CreateCoder( EXTERNAL_CODECS_LOC_VARS - methodFull.MethodID, encoder, encoder2, true)); + methodFull.Id, encoder, encoder2, true)); if (!encoder && !encoder2) return E_FAIL; - bool tryReduce = false; - UInt32 reducedDictionarySize = 1 << 10; - if (inSizeForReduce != 0 && (methodFull.MethodID == k_LZMA /* || methodFull.MethodID == k_LZMA2 */)) - { - for (;;) - { - const UInt32 step = (reducedDictionarySize >> 1); - if (reducedDictionarySize >= *inSizeForReduce) - { - tryReduce = true; - break; - } - reducedDictionarySize += step; - if (reducedDictionarySize >= *inSizeForReduce) - { - tryReduce = true; - break; - } - if (reducedDictionarySize >= ((UInt32)11 << 30)) - break; - reducedDictionarySize += step; - } - } - CMyComPtr encoderCommon = encoder ? (IUnknown *)encoder : (IUnknown *)encoder2; #ifdef COMPRESS_MT @@ -110,50 +84,17 @@ HRESULT CEncoder::CreateMixerCoder( } #endif - if (methodFull.CoderProperties.Size() > 0) + + RINOK(SetMethodProperties(methodFull, inSizeForReduce, encoderCommon)); + + /* + CMyComPtr resetSalt; + encoderCommon.QueryInterface(IID_ICryptoResetSalt, (void **)&resetSalt); + if (resetSalt != NULL) { - CRecordVector propIDs; - int numProperties = methodFull.CoderProperties.Size(); - NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties]; - try - { - for (int i = 0; i < numProperties; i++) - { - const CProperty &property = methodFull.CoderProperties[i]; - propIDs.Add(property.PropID); - NWindows::NCOM::CPropVariant value = property.Value; - if (tryReduce && property.PropID == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal) - value.ulVal = reducedDictionarySize; - values[i] = value; - } - CMyComPtr setCoderProperties; - RINOK(encoderCommon.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties)); - RINOK(setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties)); - } - catch(...) - { - delete []values; - throw; - } - delete []values; - } - - CMyComPtr writeCoderProperties; - - encoderCommon.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties); - - if (writeCoderProperties != NULL) - { - CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp; - CMyComPtr outStream(outStreamSpec); - outStreamSpec->Init(); - writeCoderProperties->WriteCoderProperties(outStream); - - size_t size = outStreamSpec->GetSize(); - - encodingInfo.Properties.SetCapacity(size); - memmove(encodingInfo.Properties, outStreamSpec->GetBuffer(), size); + resetSalt->ResetSalt(); } + */ #ifdef EXTERNAL_CODECS CMyComPtr setCompressCodecsInfo; @@ -268,6 +209,31 @@ HRESULT CEncoder::Encode( outStreamPointers.Add(outStreamSizeCount); for (i = 1; i < _bindInfo.OutStreams.Size(); i++) outStreamPointers.Add(tempBuffers[i - 1]); + + for (i = 0; i < _codersInfo.Size(); i++) + { + CCoderInfo &encodingInfo = _codersInfo[i]; + + CMyComPtr resetInitVector; + _mixerCoderSpec->_coders[i].QueryInterface(IID_ICryptoResetInitVector, (void **)&resetInitVector); + if (resetInitVector != NULL) + { + resetInitVector->ResetInitVector(); + } + + CMyComPtr writeCoderProperties; + _mixerCoderSpec->_coders[i].QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties); + if (writeCoderProperties != NULL) + { + CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp; + CMyComPtr outStream(outStreamSpec); + outStreamSpec->Init(); + writeCoderProperties->WriteCoderProperties(outStream); + size_t size = outStreamSpec->GetSize(); + encodingInfo.Properties.SetCapacity(size); + memmove(encodingInfo.Properties, outStreamSpec->GetBuffer(), size); + } + } RINOK(_mixerCoder->Code(&inStreamPointers.Front(), NULL, 1, &outStreamPointers.Front(), NULL, outStreamPointers.Size(), compressProgress)); @@ -325,14 +291,14 @@ HRESULT CEncoder::EncoderConstr() throw 1; if (!_options.Binds.IsEmpty()) throw 1; - NCoderMixer2::CCoderStreamsInfo coderStreamsInfo; + NCoderMixer::CCoderStreamsInfo coderStreamsInfo; CMethodFull method; method.NumInStreams = 1; method.NumOutStreams = 1; coderStreamsInfo.NumInStreams = 1; coderStreamsInfo.NumOutStreams = 1; - method.MethodID = k_AES; + method.Id = k_AES; _options.Methods.Add(method); _bindInfo.Coders.Add(coderStreamsInfo); @@ -348,14 +314,14 @@ HRESULT CEncoder::EncoderConstr() for (i = 0; i < _options.Methods.Size(); i++) { const CMethodFull &methodFull = _options.Methods[i]; - NCoderMixer2::CCoderStreamsInfo coderStreamsInfo; + NCoderMixer::CCoderStreamsInfo coderStreamsInfo; coderStreamsInfo.NumInStreams = methodFull.NumOutStreams; coderStreamsInfo.NumOutStreams = methodFull.NumInStreams; if (_options.Binds.IsEmpty()) { if (i < _options.Methods.Size() - 1) { - NCoderMixer2::CBindPair bindPair; + NCoderMixer::CBindPair bindPair; bindPair.InIndex = numInStreams + coderStreamsInfo.NumInStreams; bindPair.OutIndex = numOutStreams; _bindInfo.BindPairs.Add(bindPair); @@ -376,7 +342,7 @@ HRESULT CEncoder::EncoderConstr() { for (i = 0; i < _options.Binds.Size(); i++) { - NCoderMixer2::CBindPair bindPair; + NCoderMixer::CBindPair bindPair; const CBind &bind = _options.Binds[i]; bindPair.InIndex = _bindInfo.GetCoderInStreamIndex(bind.InCoder) + bind.InStream; bindPair.OutIndex = _bindInfo.GetCoderOutStreamIndex(bind.OutCoder) + bind.OutStream; @@ -423,7 +389,7 @@ HRESULT CEncoder::EncoderConstr() for (i = 0; i < numCryptoStreams; i++) { - NCoderMixer2::CBindPair bindPair; + NCoderMixer::CBindPair bindPair; bindPair.InIndex = numInStreams + i; bindPair.OutIndex = _bindInfo.OutStreams[i]; _bindInfo.BindPairs.Add(bindPair); @@ -437,13 +403,13 @@ HRESULT CEncoder::EncoderConstr() for (i = 0; i < numCryptoStreams; i++) { - NCoderMixer2::CCoderStreamsInfo coderStreamsInfo; + NCoderMixer::CCoderStreamsInfo coderStreamsInfo; CMethodFull method; method.NumInStreams = 1; method.NumOutStreams = 1; coderStreamsInfo.NumInStreams = method.NumOutStreams; coderStreamsInfo.NumOutStreams = method.NumInStreams; - method.MethodID = k_AES; + method.Id = k_AES; _options.Methods.Add(method); _bindInfo.Coders.Add(coderStreamsInfo); @@ -456,10 +422,10 @@ HRESULT CEncoder::EncoderConstr() for (int i = _options.Methods.Size() - 1; i >= 0; i--) { const CMethodFull &methodFull = _options.Methods[i]; - _decompressionMethods.Add(methodFull.MethodID); + _decompressionMethods.Add(methodFull.Id); } - _bindReverseConverter = new NCoderMixer2::CBindReverseConverter(_bindInfo); + _bindReverseConverter = new NCoderMixer::CBindReverseConverter(_bindInfo); _bindReverseConverter->CreateReverseBindInfo(_decompressBindInfo); _constructed = true; return S_OK; diff --git a/CPP/7zip/Archive/7z/7zEncode.h b/CPP/7zip/Archive/7z/7zEncode.h index 588105c3..4909a6e8 100755 --- a/CPP/7zip/Archive/7z/7zEncode.h +++ b/CPP/7zip/Archive/7z/7zEncode.h @@ -21,15 +21,15 @@ namespace N7z { class CEncoder { - NCoderMixer2::CCoderMixer2MT *_mixerCoderSpec; + NCoderMixer::CCoderMixer2MT *_mixerCoderSpec; CMyComPtr _mixerCoder; CObjectVector _codersInfo; CCompressionMethodMode _options; - NCoderMixer2::CBindInfo _bindInfo; - NCoderMixer2::CBindInfo _decompressBindInfo; - NCoderMixer2::CBindReverseConverter *_bindReverseConverter; + NCoderMixer::CBindInfo _bindInfo; + NCoderMixer::CBindInfo _decompressBindInfo; + NCoderMixer::CBindReverseConverter *_bindReverseConverter; CRecordVector _decompressionMethods; HRESULT CreateMixerCoder(DECL_EXTERNAL_CODECS_LOC_VARS diff --git a/CPP/7zip/Archive/7z/7zHandler.cpp b/CPP/7zip/Archive/7z/7zHandler.cpp index dc0a6505..9fc45848 100755 --- a/CPP/7zip/Archive/7z/7zHandler.cpp +++ b/CPP/7zip/Archive/7z/7zHandler.cpp @@ -20,6 +20,10 @@ #endif #endif +#ifdef COMPRESS_MT +#include "../../../Windows/System.h" +#endif + using namespace NWindows; extern UString ConvertMethodIdToString(UInt64 id); @@ -29,10 +33,11 @@ namespace N7z { CHandler::CHandler() { + #ifdef EXTRACT_ONLY #ifdef COMPRESS_MT _numThreads = NWindows::NSystem::GetNumberOfProcessors(); #endif - #ifndef EXTRACT_ONLY + #else Init(); #endif } diff --git a/CPP/7zip/Archive/7z/7zHandler.h b/CPP/7zip/Archive/7z/7zHandler.h index 77e4d25c..95e53340 100755 --- a/CPP/7zip/Archive/7z/7zHandler.h +++ b/CPP/7zip/Archive/7z/7zHandler.h @@ -9,12 +9,12 @@ #include "7zCompressionMode.h" -#ifdef COMPRESS_MT -#include "../../../Windows/System.h" -#endif - #include "../../Common/CreateCoder.h" +#ifndef EXTRACT_ONLY +#include "../Common/HandlerOut.h" +#endif + namespace NArchive { namespace N7z { @@ -44,15 +44,6 @@ struct CVolume }; #endif -#ifndef EXTRACT_ONLY - -struct COneMethodInfo -{ - CObjectVector CoderProperties; - UString MethodName; -}; -#endif - // {23170F69-40C1-278A-1000-000110070000} DEFINE_GUID(CLSID_CFormat7z, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00); @@ -71,6 +62,9 @@ DEFINE_GUID(CLSID_CFormat7z, class CHandler: + #ifndef EXTRACT_ONLY + public NArchive::COutHandler, + #endif public IInArchive, #ifdef _7Z_VOL public IInArchiveGetStream, @@ -137,8 +131,6 @@ public: // ISetProperties - HRESULT SetSolidSettings(const UString &s); - HRESULT SetSolidSettings(const PROPVARIANT &value); #endif DECL_ISetCompressCodecsInfo @@ -154,37 +146,15 @@ private: NArchive::N7z::CArchiveDatabaseEx _database; #endif - + #ifdef EXTRACT_ONLY + #ifdef COMPRESS_MT UInt32 _numThreads; #endif - - #ifndef EXTRACT_ONLY - CObjectVector _methods; + + #else + CRecordVector _binds; - bool _removeSfxBlock; - UInt64 _numSolidFiles; - UInt64 _numSolidBytes; - bool _numSolidBytesDefined; - bool _solidExtension; - - bool _compressHeaders; - bool _encryptHeaders; - - bool WriteModified; - bool WriteCreated; - bool WriteAccessed; - - - bool _autoFilter; - UInt32 _level; - - bool _volumeMode; - - DECL_EXTERNAL_CODECS_VARS - - HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value); - HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString); HRESULT SetPassword(CCompressionMethodMode &methodMode, IArchiveUpdateCallback *updateCallback); @@ -208,39 +178,6 @@ private: void FillPopIDs(); #endif - - #ifndef EXTRACT_ONLY - - void InitSolidFiles() { _numSolidFiles = UInt64(Int64(-1)); } - void InitSolidSize() { _numSolidBytes = UInt64(Int64(-1)); } - void InitSolid() - { - InitSolidFiles(); - InitSolidSize(); - _solidExtension = false; - _numSolidBytesDefined = false; - } - - void Init() - { - _removeSfxBlock = false; - _compressHeaders = true; - _encryptHeaders = false; - - WriteModified = true; - WriteCreated = false; - WriteAccessed = false; - - #ifdef COMPRESS_MT - _numThreads = NWindows::NSystem::GetNumberOfProcessors(); - #endif - - _level = 5; - _autoFilter = true; - _volumeMode = false; - InitSolid(); - } - #endif }; }} diff --git a/CPP/7zip/Archive/7z/7zHandlerOut.cpp b/CPP/7zip/Archive/7z/7zHandlerOut.cpp index 80d63931..af4b9427 100755 --- a/CPP/7zip/Archive/7z/7zHandlerOut.cpp +++ b/CPP/7zip/Archive/7z/7zHandlerOut.cpp @@ -1,4 +1,4 @@ -// 7z/OutHandler.cpp +// 7zHandlerOut.cpp #include "StdAfx.h" @@ -21,90 +21,19 @@ using namespace NWindows; namespace NArchive { namespace N7z { -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"; -const wchar_t *kDeflate64MethodName = L"Deflate64"; +static const wchar_t *kLZMAMethodName = L"LZMA"; +static const wchar_t *kCopyMethod = L"Copy"; +static const wchar_t *kDefaultMethodName = kLZMAMethodName; -static const wchar_t *kLzmaMatchFinderX1 = L"HC4"; -static const wchar_t *kLzmaMatchFinderX5 = L"BT4"; - -static const UInt32 kLzmaAlgorithmX1 = 0; static const UInt32 kLzmaAlgorithmX5 = 1; - -static const UInt32 kLzmaDicSizeX1 = 1 << 16; -static const UInt32 kLzmaDicSizeX3 = 1 << 20; -static const UInt32 kLzmaDicSizeX5 = 1 << 24; -static const UInt32 kLzmaDicSizeX7 = 1 << 25; -static const UInt32 kLzmaDicSizeX9 = 1 << 26; - -static const UInt32 kLzmaFastBytesX1 = 32; -static const UInt32 kLzmaFastBytesX7 = 64; - -static const UInt32 kPpmdMemSizeX1 = (1 << 22); -static const UInt32 kPpmdMemSizeX5 = (1 << 24); -static const UInt32 kPpmdMemSizeX7 = (1 << 26); -static const UInt32 kPpmdMemSizeX9 = (192 << 20); - -static const UInt32 kPpmdOrderX1 = 4; -static const UInt32 kPpmdOrderX5 = 6; -static const UInt32 kPpmdOrderX7 = 16; -static const UInt32 kPpmdOrderX9 = 32; - -static const UInt32 kDeflateAlgoX1 = 0; -static const UInt32 kDeflateAlgoX5 = 1; - -static const UInt32 kDeflateFastBytesX1 = 32; -static const UInt32 kDeflateFastBytesX7 = 64; -static const UInt32 kDeflateFastBytesX9 = 128; - -static const UInt32 kDeflatePassesX1 = 1; -static const UInt32 kDeflatePassesX7 = 3; -static const UInt32 kDeflatePassesX9 = 10; - -static const UInt32 kBZip2NumPassesX1 = 1; -static const UInt32 kBZip2NumPassesX7 = 2; -static const UInt32 kBZip2NumPassesX9 = 7; - -static const UInt32 kBZip2DicSizeX1 = 100000; -static const UInt32 kBZip2DicSizeX3 = 500000; -static const UInt32 kBZip2DicSizeX5 = 900000; - -const wchar_t *kDefaultMethodName = kLZMAMethodName; - static const wchar_t *kLzmaMatchFinderForHeaders = L"BT2"; static const UInt32 kDictionaryForHeaders = 1 << 20; static const UInt32 kNumFastBytesForHeaders = 273; static const UInt32 kAlgorithmForHeaders = kLzmaAlgorithmX5; -static bool IsCopyMethod(const UString &methodName) +static inline bool IsCopyMethod(const UString &methodName) { return (methodName.CompareNoCase(kCopyMethod) == 0); } -static bool IsLZMAMethod(const UString &methodName) -{ - 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); } - -static bool IsPpmdMethod(const UString &methodName) - { return (methodName.CompareNoCase(kPpmdMethodName) == 0); } - -static bool IsDeflateMethod(const UString &methodName) - { return (methodName.CompareNoCase(kDeflateMethodName) == 0) || - (methodName.CompareNoCase(kDeflate64MethodName) == 0); } - STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type) { *type = NFileTimeType::kWindows; @@ -136,60 +65,6 @@ HRESULT CHandler::SetPassword(CCompressionMethodMode &methodMode, return S_OK; } -struct CNameToPropID -{ - PROPID PropID; - VARTYPE VarType; - const wchar_t *Name; -}; - -CNameToPropID g_NameToPropID[] = -{ - { NCoderPropID::kOrder, VT_UI4, L"O" }, - { NCoderPropID::kPosStateBits, VT_UI4, L"PB" }, - { NCoderPropID::kLitContextBits, VT_UI4, L"LC" }, - { NCoderPropID::kLitPosBits, VT_UI4, L"LP" }, - - { NCoderPropID::kNumPasses, VT_UI4, L"Pass" }, - { NCoderPropID::kNumFastBytes, VT_UI4, L"fb" }, - { NCoderPropID::kMatchFinderCycles, VT_UI4, L"mc" }, - { NCoderPropID::kAlgorithm, VT_UI4, L"a" }, - { NCoderPropID::kMatchFinder, VT_BSTR, L"mf" }, - { NCoderPropID::kNumThreads, VT_UI4, L"mt" } -}; - -bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, - NCOM::CPropVariant &destProp) -{ - if (varType == srcProp.vt) - { - destProp = srcProp; - return true; - } - if (varType == VT_UI1) - { - if(srcProp.vt == VT_UI4) - { - UInt32 value = srcProp.ulVal; - if (value > 0xFF) - return false; - destProp = Byte(value); - return true; - } - } - return false; -} - -const int kNumNameToPropIDItems = sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); - -int FindPropIdFromStringName(const UString &name) -{ - for (int i = 0; i < kNumNameToPropIDItems; i++) - if (name.CompareNoCase(g_NameToPropID[i].Name) == 0) - return i; - return -1; -} - HRESULT CHandler::SetCompressionMethod( CCompressionMethodMode &methodMode, CCompressionMethodMode &headerMethod) @@ -210,28 +85,28 @@ HRESULT CHandler::SetCompressionMethod( COneMethodInfo oneMethodInfo; oneMethodInfo.MethodName = kLZMAMethodName; { - CProperty property; - property.PropID = NCoderPropID::kMatchFinder; + CProp property; + property.Id = NCoderPropID::kMatchFinder; property.Value = kLzmaMatchFinderForHeaders; - oneMethodInfo.CoderProperties.Add(property); + oneMethodInfo.Properties.Add(property); } { - CProperty property; - property.PropID = NCoderPropID::kAlgorithm; + CProp property; + property.Id = NCoderPropID::kAlgorithm; property.Value = kAlgorithmForHeaders; - oneMethodInfo.CoderProperties.Add(property); + oneMethodInfo.Properties.Add(property); } { - CProperty property; - property.PropID = NCoderPropID::kNumFastBytes; + CProp property; + property.Id = NCoderPropID::kNumFastBytes; property.Value = UInt32(kNumFastBytesForHeaders); - oneMethodInfo.CoderProperties.Add(property); + oneMethodInfo.Properties.Add(property); } { - CProperty property; - property.PropID = NCoderPropID::kDictionarySize; + CProp property; + property.Id = NCoderPropID::kDictionarySize; property.Value = UInt32(kDictionaryForHeaders); - oneMethodInfo.CoderProperties.Add(property); + oneMethodInfo.Properties.Add(property); } headerMethodInfoVector.Add(oneMethodInfo); HRESULT res = SetCompressionMethod(headerMethod, headerMethodInfoVector @@ -244,21 +119,6 @@ HRESULT CHandler::SetCompressionMethod( return S_OK; } -static void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID, - const NWindows::NCOM::CPropVariant &value) -{ - int j; - for (j = 0; j < oneMethodInfo.CoderProperties.Size(); j++) - if (oneMethodInfo.CoderProperties[j].PropID == propID) - break; - if (j != oneMethodInfo.CoderProperties.Size()) - return; - CProperty property; - property.PropID = propID; - property.Value = value; - oneMethodInfo.CoderProperties.Add(property); -} - HRESULT CHandler::SetCompressionMethod( CCompressionMethodMode &methodMode, CObjectVector &methodsInfo @@ -280,113 +140,31 @@ HRESULT CHandler::SetCompressionMethod( for(int i = 0; i < methodsInfo.Size(); i++) { COneMethodInfo &oneMethodInfo = methodsInfo[i]; - if (oneMethodInfo.MethodName.IsEmpty()) - oneMethodInfo.MethodName = kDefaultMethodName; - - if (!IsCopyMethod(oneMethodInfo.MethodName)) - needSolid = true; - - if (IsLZMAMethod(oneMethodInfo.MethodName)) - { - UInt32 dicSize = - (level >= 9 ? kLzmaDicSizeX9 : - (level >= 7 ? kLzmaDicSizeX7 : - (level >= 5 ? kLzmaDicSizeX5 : - (level >= 3 ? kLzmaDicSizeX3 : - kLzmaDicSizeX1)))); - - UInt32 algorithm = - (level >= 5 ? kLzmaAlgorithmX5 : - kLzmaAlgorithmX1); - - UInt32 fastBytes = - (level >= 7 ? kLzmaFastBytesX7 : - kLzmaFastBytesX1); - - const wchar_t *matchFinder = - (level >= 5 ? kLzmaMatchFinderX5 : - kLzmaMatchFinderX1); - - SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algorithm); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder); - #ifdef COMPRESS_MT - SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads); - #endif - } - else if (IsDeflateMethod(oneMethodInfo.MethodName)) - { - UInt32 fastBytes = - (level >= 9 ? kDeflateFastBytesX9 : - (level >= 7 ? kDeflateFastBytesX7 : - kDeflateFastBytesX1)); - - UInt32 numPasses = - (level >= 9 ? kDeflatePassesX9 : - (level >= 7 ? kDeflatePassesX7 : - kDeflatePassesX1)); - UInt32 algo = - (level >= 5 ? kDeflateAlgoX5 : - kDeflateAlgoX1); - - SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses); - } - else if (IsBZip2Method(oneMethodInfo.MethodName)) - { - UInt32 numPasses = - (level >= 9 ? kBZip2NumPassesX9 : - (level >= 7 ? kBZip2NumPassesX7 : - kBZip2NumPassesX1)); - - UInt32 dicSize = - (level >= 5 ? kBZip2DicSizeX5 : - (level >= 3 ? kBZip2DicSizeX3 : - kBZip2DicSizeX1)); - - SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize); + SetCompressionMethod2(oneMethodInfo #ifdef COMPRESS_MT - SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads); + , numThreads #endif - } - else if (IsPpmdMethod(oneMethodInfo.MethodName)) - { - UInt32 useMemSize = - (level >= 9 ? kPpmdMemSizeX9 : - (level >= 7 ? kPpmdMemSizeX7 : - (level >= 5 ? kPpmdMemSizeX5 : - kPpmdMemSizeX1))); - - UInt32 order = - (level >= 9 ? kPpmdOrderX9 : - (level >= 7 ? kPpmdOrderX7 : - (level >= 5 ? kPpmdOrderX5 : - kPpmdOrderX1))); - - SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize); - SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order); - } + ); + if (!IsCopyMethod(oneMethodInfo.MethodName)) + needSolid = true; CMethodFull methodFull; if (!FindMethod( EXTERNAL_CODECS_VARS - oneMethodInfo.MethodName, methodFull.MethodID, methodFull.NumInStreams, methodFull.NumOutStreams)) + oneMethodInfo.MethodName, methodFull.Id, methodFull.NumInStreams, methodFull.NumOutStreams)) return E_INVALIDARG; - methodFull.CoderProperties = oneMethodInfo.CoderProperties; + methodFull.Properties = oneMethodInfo.Properties; methodMode.Methods.Add(methodFull); if (!_numSolidBytesDefined) { - for (int j = 0; j < methodFull.CoderProperties.Size(); j++) + for (int j = 0; j < methodFull.Properties.Size(); j++) { - const CProperty &prop = methodFull.CoderProperties[j]; - if ((prop.PropID == NCoderPropID::kDictionarySize || - prop.PropID == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4) + const CProp &prop = methodFull.Properties[j]; + if ((prop.Id == NCoderPropID::kDictionarySize || + prop.Id == NCoderPropID::kUsedMemorySize) && prop.Value.vt == VT_UI4) { _numSolidBytes = ((UInt64)prop.Value.ulVal) << 7; const UInt64 kMinSize = (1 << 24); @@ -652,198 +430,11 @@ static HRESULT GetBindInfo(UString &srcString, CBind &bind) return S_OK; } -static void SplitParams(const UString &srcString, UStringVector &subStrings) -{ - subStrings.Clear(); - UString name; - int len = srcString.Length(); - if (len == 0) - return; - for (int i = 0; i < len; i++) - { - wchar_t c = srcString[i]; - if (c == L':') - { - subStrings.Add(name); - name.Empty(); - } - else - name += c; - } - subStrings.Add(name); -} - -static void SplitParam(const UString ¶m, UString &name, UString &value) -{ - int eqPos = param.Find(L'='); - if (eqPos >= 0) - { - name = param.Left(eqPos); - value = param.Mid(eqPos + 1); - return; - } - for(int i = 0; i < param.Length(); i++) - { - wchar_t c = param[i]; - if (c >= L'0' && c <= L'9') - { - name = param.Left(i); - value = param.Mid(i); - return; - } - } - name = param; -} - -HRESULT CHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value) -{ - CProperty property; - if (name.CompareNoCase(L"D") == 0 || name.CompareNoCase(L"MEM") == 0) - { - UInt32 dicSize; - RINOK(ParsePropDictionaryValue(value, dicSize)); - if (name.CompareNoCase(L"D") == 0) - property.PropID = NCoderPropID::kDictionarySize; - else - property.PropID = NCoderPropID::kUsedMemorySize; - property.Value = dicSize; - oneMethodInfo.CoderProperties.Add(property); - } - else - { - int index = FindPropIdFromStringName(name); - if (index < 0) - return E_INVALIDARG; - - const CNameToPropID &nameToPropID = g_NameToPropID[index]; - property.PropID = nameToPropID.PropID; - - NCOM::CPropVariant propValue; - - - if (nameToPropID.VarType == VT_BSTR) - propValue = value; - else - { - UInt32 number; - if (ParseStringToUInt32(value, number) == value.Length()) - propValue = number; - else - propValue = value; - } - - if (!ConvertProperty(propValue, nameToPropID.VarType, property.Value)) - return E_INVALIDARG; - - oneMethodInfo.CoderProperties.Add(property); - } - return S_OK; -} - -HRESULT CHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString) -{ - UStringVector params; - SplitParams(srcString, params); - if (params.Size() > 0) - oneMethodInfo.MethodName = params[0]; - for (int i = 1; i < params.Size(); i++) - { - const UString ¶m = params[i]; - UString name, value; - SplitParam(param, name, value); - RINOK(SetParam(oneMethodInfo, name, value)); - } - return S_OK; -} - -HRESULT CHandler::SetSolidSettings(const UString &s) -{ - UString s2 = s; - s2.MakeUpper(); - if (s2.IsEmpty() || s2.Compare(L"ON") == 0) - { - InitSolid(); - return S_OK; - } - if (s2.Compare(L"OFF") == 0) - { - _numSolidFiles = 1; - return S_OK; - } - for (int i = 0; i < s2.Length();) - { - const wchar_t *start = ((const wchar_t *)s2) + i; - const wchar_t *end; - UInt64 v = ConvertStringToUInt64(start, &end); - if (start == end) - { - if (s2[i++] != 'E') - return E_INVALIDARG; - _solidExtension = true; - continue; - } - i += (int)(end - start); - if (i == s2.Length()) - return E_INVALIDARG; - wchar_t c = s2[i++]; - switch(c) - { - case 'F': - if (v < 1) - v = 1; - _numSolidFiles = v; - break; - case 'B': - _numSolidBytes = v; - _numSolidBytesDefined = true; - break; - case 'K': - _numSolidBytes = (v << 10); - _numSolidBytesDefined = true; - break; - case 'M': - _numSolidBytes = (v << 20); - _numSolidBytesDefined = true; - break; - case 'G': - _numSolidBytes = (v << 30); - _numSolidBytesDefined = true; - break; - default: - return E_INVALIDARG; - } - } - return S_OK; -} - -HRESULT CHandler::SetSolidSettings(const PROPVARIANT &value) -{ - switch(value.vt) - { - case VT_EMPTY: - InitSolid(); - return S_OK; - case VT_BSTR: - return SetSolidSettings(value.bstrVal); - default: - return E_INVALIDARG; - } -} - STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) { COM_TRY_BEGIN - _methods.Clear(); _binds.Clear(); - Init(); - #ifdef COMPRESS_MT - const UInt32 numProcessors = NSystem::GetNumberOfProcessors(); - #endif - - UInt32 mainDicSize = 0xFFFFFFFF; - UInt32 mainDicMethodIndex = 0xFFFFFFFF; - - UInt32 minNumber = 0; + BeforeSetProperty(); for (int i = 0; i < numProperties; i++) { @@ -854,14 +445,6 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v const PROPVARIANT &value = values[i]; - if (name[0] == 'X') - { - name.Delete(0); - _level = 9; - RINOK(ParsePropValue(name, value, _level)); - continue; - } - if (name[0] == 'B') { name.Delete(0); @@ -871,142 +454,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v continue; } - if (name[0] == L'S') - { - name.Delete(0); - if (name.IsEmpty()) - { - RINOK(SetSolidSettings(value)); - } - else - { - RINOK(SetSolidSettings(name)); - } - continue; - } - - - UInt32 number; - int index = ParseStringToUInt32(name, number); - UString realName = name.Mid(index); - if (index == 0) - { - if(name.Left(2).CompareNoCase(L"MT") == 0) - { - #ifdef COMPRESS_MT - RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads)); - #endif - continue; - } - else if (name.CompareNoCase(L"RSFX") == 0) - { - RINOK(SetBoolProperty(_removeSfxBlock, value)); - continue; - } - else if (name.CompareNoCase(L"F") == 0) - { - RINOK(SetBoolProperty(_autoFilter, value)); - continue; - } - else if (name.CompareNoCase(L"HC") == 0) - { - RINOK(SetBoolProperty(_compressHeaders, value)); - continue; - } - else if (name.CompareNoCase(L"HCF") == 0) - { - bool compressHeadersFull = true; - RINOK(SetBoolProperty(compressHeadersFull, value)); - if (!compressHeadersFull) - return E_INVALIDARG; - continue; - } - else if (name.CompareNoCase(L"HE") == 0) - { - 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)); - continue; - } - number = 0; - } - if (number > 10000) - return E_FAIL; - if (number < minNumber) - return E_INVALIDARG; - number -= minNumber; - for(int j = _methods.Size(); j <= (int)number; j++) - { - COneMethodInfo oneMethodInfo; - _methods.Add(oneMethodInfo); - } - - COneMethodInfo &oneMethodInfo = _methods[number]; - - if (realName.Length() == 0) - { - if (value.vt != VT_BSTR) - return E_INVALIDARG; - - // oneMethodInfo.MethodName = UnicodeStringToMultiByte(UString(value.bstrVal)); - RINOK(SetParams(oneMethodInfo, value.bstrVal)); - } - else - { - CProperty property; - if (realName.Left(1).CompareNoCase(L"D") == 0) - { - UInt32 dicSize; - RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize)); - property.PropID = NCoderPropID::kDictionarySize; - property.Value = dicSize; - oneMethodInfo.CoderProperties.Add(property); - if (number <= mainDicMethodIndex) - mainDicSize = dicSize; - } - else if (realName.Left(3).CompareNoCase(L"MEM") == 0) - { - UInt32 dicSize; - RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize)); - property.PropID = NCoderPropID::kUsedMemorySize; - property.Value = dicSize; - oneMethodInfo.CoderProperties.Add(property); - if (number <= mainDicMethodIndex) - mainDicSize = dicSize; - } - else - { - int index = FindPropIdFromStringName(realName); - if (index < 0) - return E_INVALIDARG; - - const CNameToPropID &nameToPropID = g_NameToPropID[index]; - property.PropID = nameToPropID.PropID; - - if (!ConvertProperty(value, nameToPropID.VarType, property.Value)) - return E_INVALIDARG; - - oneMethodInfo.CoderProperties.Add(property); - } - } + RINOK(SetProperty(name, value)); } return S_OK; diff --git a/CPP/7zip/Archive/7z/7zHeader.cpp b/CPP/7zip/Archive/7z/7zHeader.cpp index cff4d121..425231fc 100755 --- a/CPP/7zip/Archive/7z/7zHeader.cpp +++ b/CPP/7zip/Archive/7z/7zHeader.cpp @@ -7,12 +7,20 @@ namespace NArchive { namespace N7z { Byte kSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C}; +#ifdef _7Z_VOL Byte kFinishSignature[kSignatureSize] = {'7' + 1, 'z', 0xBC, 0xAF, 0x27, 0x1C + 1}; +#endif class SignatureInitializer { public: - SignatureInitializer() { kSignature[0]--; kFinishSignature[0]--;}; + SignatureInitializer() + { + kSignature[0]--; + #ifdef _7Z_VOL + kFinishSignature[0]--; + #endif + }; } g_SignatureInitializer; }} diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp index d1ad9da8..c9150898 100755 --- a/CPP/7zip/Archive/7z/7zIn.cpp +++ b/CPP/7zip/Archive/7z/7zIn.cpp @@ -12,7 +12,9 @@ extern "C" } // define FORMAT_7Z_RECOVERY if you want to recover multivolume archives with empty StartHeader -// #define FORMAT_7Z_RECOVERY +#ifndef _SFX +#define FORMAT_7Z_RECOVERY +#endif namespace NArchive { namespace N7z { @@ -1268,13 +1270,13 @@ HRESULT CInArchive::ReadDatabase( return S_FALSE; nextHeaderSize = realProcessedSize - i; nextHeaderOffset = cur2 - cur + i; - nextHeaderCRC = CCRC::CalculateDigest(buf + i, (size_t)nextHeaderSize); + nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize); RINOK(_stream->Seek(cur, STREAM_SEEK_SET, &_position)); } #endif #ifdef FORMAT_7Z_RECOVERY - crcFromArchive = crc.GetDigest(); + crcFromArchive = CRC_GET_DIGEST(crc); #endif #ifdef _7Z_VOL diff --git a/CPP/7zip/Archive/7z/7zItem.h b/CPP/7zip/Archive/7z/7zItem.h index cad88dc1..388f19d3 100755 --- a/CPP/7zip/Archive/7z/7zItem.h +++ b/CPP/7zip/Archive/7z/7zItem.h @@ -4,7 +4,7 @@ #define __7Z_ITEM_H #include "../../../Common/Buffer.h" -#include "../../../Common/String.h" +#include "../../../Common/MyString.h" #include "../../Common/MethodId.h" #include "7zHeader.h" diff --git a/CPP/7zip/Archive/7z/7zOut.cpp b/CPP/7zip/Archive/7z/7zOut.cpp index 2399f652..a00cdf5c 100755 --- a/CPP/7zip/Archive/7z/7zOut.cpp +++ b/CPP/7zip/Archive/7z/7zOut.cpp @@ -151,7 +151,7 @@ HRESULT COutArchive::Create(ISequentialOutStream *stream, bool endMarker) { if (!Stream) return E_FAIL; - WriteSignature(); + RINOK(WriteSignature()); RINOK(Stream->Seek(0, STREAM_SEEK_CUR, &_prefixHeaderPos)); } return S_OK; diff --git a/CPP/7zip/Archive/7z/7zUpdate.cpp b/CPP/7zip/Archive/7z/7zUpdate.cpp index 2b197adb..59e7c4fc 100755 --- a/CPP/7zip/Archive/7z/7zUpdate.cpp +++ b/CPP/7zip/Archive/7z/7zUpdate.cpp @@ -357,7 +357,7 @@ static const UInt64 k_BCJ2 = 0x0303011B; static bool GetMethodFull(UInt64 methodID, UInt32 numInStreams, CMethodFull &methodResult) { - methodResult.MethodID = methodID; + methodResult.Id = methodID; methodResult.NumInStreams = numInStreams; methodResult.NumOutStreams = 1; return true; @@ -376,28 +376,28 @@ static bool MakeExeMethod(const CCompressionMethodMode &method, if (!GetMethodFull(k_LZMA, 1, methodFull)) return false; { - CProperty property; - property.PropID = NCoderPropID::kAlgorithm; + CProp property; + property.Id = NCoderPropID::kAlgorithm; property.Value = kAlgorithmForBCJ2_LZMA; - methodFull.CoderProperties.Add(property); + methodFull.Properties.Add(property); } { - CProperty property; - property.PropID = NCoderPropID::kMatchFinder; + CProp property; + property.Id = NCoderPropID::kMatchFinder; property.Value = kMatchFinderForBCJ2_LZMA; - methodFull.CoderProperties.Add(property); + methodFull.Properties.Add(property); } { - CProperty property; - property.PropID = NCoderPropID::kDictionarySize; + CProp property; + property.Id = NCoderPropID::kDictionarySize; property.Value = kDictionaryForBCJ2_LZMA; - methodFull.CoderProperties.Add(property); + methodFull.Properties.Add(property); } { - CProperty property; - property.PropID = NCoderPropID::kNumFastBytes; + CProp property; + property.Id = NCoderPropID::kNumFastBytes; property.Value = kNumFastBytesForBCJ2_LZMA; - methodFull.CoderProperties.Add(property); + methodFull.Properties.Add(property); } exeMethod.Methods.Add(methodFull); diff --git a/CPP/7zip/Archive/7z/makefile b/CPP/7zip/Archive/7z/makefile index 03ef4e46..1a72da0e 100755 --- a/CPP/7zip/Archive/7z/makefile +++ b/CPP/7zip/Archive/7z/makefile @@ -31,10 +31,10 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ WIN_OBJS = \ $O\DLL.obj \ @@ -42,7 +42,8 @@ WIN_OBJS = \ $O\FileFind.obj \ $O\FileIO.obj \ $O\PropVariant.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -51,16 +52,19 @@ WIN_OBJS = \ $O\LimitedStreams.obj \ $O\LockedStream.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\OutBuffer.obj \ $O\ProgressUtils.obj \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ AR_COMMON_OBJS = \ $O\CoderMixer2.obj \ $O\CoderMixer2MT.obj \ $O\CrossThreadProgress.obj \ + $O\HandlerOut.obj \ $O\InStreamWithCRC.obj \ $O\ItemNameUtils.obj \ $O\MultiStream.obj \ @@ -69,6 +73,7 @@ AR_COMMON_OBJS = \ C_OBJS = \ $O\Alloc.obj \ + $O\Threads.obj \ !include "../../Crc2.mak" diff --git a/CPP/7zip/Archive/Arj/ArjItem.h b/CPP/7zip/Archive/Arj/ArjItem.h index d48fe38d..a0112107 100755 --- a/CPP/7zip/Archive/Arj/ArjItem.h +++ b/CPP/7zip/Archive/Arj/ArjItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_ARJ_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "ArjHeader.h" namespace NArchive { diff --git a/CPP/7zip/Archive/BZip2/BZip2HandlerOut.cpp b/CPP/7zip/Archive/BZip2/BZip2HandlerOut.cpp index 38797c33..134d4124 100755 --- a/CPP/7zip/Archive/BZip2/BZip2HandlerOut.cpp +++ b/CPP/7zip/Archive/BZip2/BZip2HandlerOut.cpp @@ -6,7 +6,6 @@ #include "BZip2Update.h" #include "Common/Defs.h" -#include "Common/String.h" #include "Windows/PropVariant.h" diff --git a/CPP/7zip/Archive/Cab/CabItem.h b/CPP/7zip/Archive/Cab/CabItem.h index 21327eca..8b41fe69 100755 --- a/CPP/7zip/Archive/Cab/CabItem.h +++ b/CPP/7zip/Archive/Cab/CabItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_CAB_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "CabHeader.h" namespace NArchive { diff --git a/CPP/7zip/Archive/Chm/ChmIn.h b/CPP/7zip/Archive/Chm/ChmIn.h index ebf3c4be..e677c618 100755 --- a/CPP/7zip/Archive/Chm/ChmIn.h +++ b/CPP/7zip/Archive/Chm/ChmIn.h @@ -3,7 +3,7 @@ #ifndef __ARCHIVE_CHM_IN_H #define __ARCHIVE_CHM_IN_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Buffer.h" #include "../../IStream.h" #include "../../Common/InBuffer.h" diff --git a/CPP/7zip/Archive/Common/CoderMixer.cpp b/CPP/7zip/Archive/Common/CoderMixer.cpp new file mode 100755 index 00000000..db626fe1 --- /dev/null +++ b/CPP/7zip/Archive/Common/CoderMixer.cpp @@ -0,0 +1,19 @@ +// CoderMixer.cpp + +#include "StdAfx.h" + +#include "CoderMixer.h" + +namespace NCoderMixer { + +void CCoderInfo::SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize) +{ + InSizeAssigned = (inSize != 0); + if (InSizeAssigned) + InSizeValue = *inSize; + OutSizeAssigned = (outSize != 0); + if (OutSizeAssigned) + OutSizeValue = *outSize; +} + +} diff --git a/CPP/7zip/Archive/Common/CoderMixer.h b/CPP/7zip/Archive/Common/CoderMixer.h new file mode 100755 index 00000000..6379dd80 --- /dev/null +++ b/CPP/7zip/Archive/Common/CoderMixer.h @@ -0,0 +1,32 @@ +// CoderMixer.h + +#ifndef __CODER_MIXER_H +#define __CODER_MIXER_H + +#include "../../../Common/MyCom.h" +#include "../../ICoder.h" + +namespace NCoderMixer { + +struct CCoderInfo +{ + CMyComPtr Coder; + CMyComPtr InStream; + CMyComPtr OutStream; + CMyComPtr Progress; + + UInt64 InSizeValue; + UInt64 OutSizeValue; + bool InSizeAssigned; + bool OutSizeAssigned; + + void ReInit() + { + InSizeAssigned = OutSizeAssigned = false; + } + + void SetCoderInfo(const UInt64 *inSize, const UInt64 *outSize); +}; + +} +#endif diff --git a/CPP/7zip/Archive/Common/CoderMixer2.cpp b/CPP/7zip/Archive/Common/CoderMixer2.cpp index 8f46e985..d11e9e60 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2.cpp +++ b/CPP/7zip/Archive/Common/CoderMixer2.cpp @@ -4,7 +4,7 @@ #include "CoderMixer2.h" -namespace NCoderMixer2 { +namespace NCoderMixer { CBindReverseConverter::CBindReverseConverter(const CBindInfo &srcBindInfo): _srcBindInfo(srcBindInfo) @@ -81,7 +81,7 @@ void CBindReverseConverter::CreateReverseBindInfo(CBindInfo &destBindInfo) destBindInfo.InStreams.Add(_srcOutToDestInMap[_srcBindInfo.OutStreams[i]]); } -CCoderInfo::CCoderInfo(UInt32 numInStreams, UInt32 numOutStreams): +CCoderInfo2::CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams): NumInStreams(numInStreams), NumOutStreams(numOutStreams) { @@ -111,7 +111,7 @@ static void SetSizes(const UInt64 **srcSizes, CRecordVector &sizes, } } -void CCoderInfo::SetCoderInfo(const UInt64 **inSizes, +void CCoderInfo2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes) { SetSizes(inSizes, InSizes, InSizePointers, NumInStreams); diff --git a/CPP/7zip/Archive/Common/CoderMixer2.h b/CPP/7zip/Archive/Common/CoderMixer2.h index 597a7b60..be68c680 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2.h +++ b/CPP/7zip/Archive/Common/CoderMixer2.h @@ -3,12 +3,12 @@ #ifndef __CODER_MIXER2_H #define __CODER_MIXER2_H -#include "../../../Common/Vector.h" +#include "../../../Common/MyVector.h" #include "../../../Common/Types.h" #include "../../../Common/MyCom.h" #include "../../ICoder.h" -namespace NCoderMixer2 { +namespace NCoderMixer { struct CBindPair { @@ -127,7 +127,7 @@ struct CBindInfo class CBindReverseConverter { UInt32 _numSrcOutStreams; - NCoderMixer2::CBindInfo _srcBindInfo; + NCoderMixer::CBindInfo _srcBindInfo; CRecordVector _srcInToDestOutMap; CRecordVector _srcOutToDestInMap; CRecordVector _destInToSrcOutMap; @@ -135,11 +135,11 @@ public: UInt32 NumSrcInStreams; CRecordVector DestOutToSrcInMap; - CBindReverseConverter(const NCoderMixer2::CBindInfo &srcBindInfo); - void CreateReverseBindInfo(NCoderMixer2::CBindInfo &destBindInfo); + CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo); + void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo); }; -struct CCoderInfo +struct CCoderInfo2 { CMyComPtr Coder; CMyComPtr Coder2; @@ -151,8 +151,14 @@ struct CCoderInfo CRecordVector InSizePointers; CRecordVector OutSizePointers; - CCoderInfo(UInt32 numInStreams, UInt32 numOutStreams); + CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams); void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes); + + HRESULT QueryInterface(REFGUID iid, void** pp) const + { + IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2; + return p->QueryInterface(iid, pp); + } }; class CCoderMixer2 diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp index 8a37a10d..bff689dd 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +++ b/CPP/7zip/Archive/Common/CoderMixer2MT.cpp @@ -3,16 +3,11 @@ #include "StdAfx.h" #include "CoderMixer2MT.h" -#include "CrossThreadProgress.h" -using namespace NWindows; -using namespace NSynchronization; +namespace NCoderMixer { -namespace NCoderMixer2 { - -CThreadCoderInfo::CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams): - ExitEvent(NULL), - CCoderInfo(numInStreams, numOutStreams) +CCoder2::CCoder2(UInt32 numInStreams, UInt32 numOutStreams): + CCoderInfo2(numInStreams, numOutStreams) { InStreams.Reserve(NumInStreams); InStreamPointers.Reserve(NumInStreams); @@ -20,62 +15,38 @@ CThreadCoderInfo::CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams): OutStreamPointers.Reserve(NumOutStreams); } -class CCoderInfoFlusher2 +void CCoder2::Execute() { Code(NULL); } + +void CCoder2::Code(ICompressProgressInfo *progress) { - CThreadCoderInfo *m_CoderInfo; -public: - CCoderInfoFlusher2(CThreadCoderInfo *coderInfo): m_CoderInfo(coderInfo) {} - ~CCoderInfoFlusher2() + InStreamPointers.Clear(); + OutStreamPointers.Clear(); + UInt32 i; + for (i = 0; i < NumInStreams; i++) { - int i; - for (i = 0; i < m_CoderInfo->InStreams.Size(); i++) - m_CoderInfo->InStreams[i].Release(); - for (i = 0; i < m_CoderInfo->OutStreams.Size(); i++) - m_CoderInfo->OutStreams[i].Release(); - m_CoderInfo->CompressionCompletedEvent.Set(); + if (InSizePointers[i] != NULL) + InSizePointers[i] = &InSizes[i]; + InStreamPointers.Add(InStreams[i]); } -}; - -bool CThreadCoderInfo::WaitAndCode() -{ - HANDLE events[2] = { ExitEvent, CompressEvent }; - DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); - if (waitResult == WAIT_OBJECT_0 + 0) - return false; - + for (i = 0; i < NumOutStreams; i++) { - InStreamPointers.Clear(); - OutStreamPointers.Clear(); - UInt32 i; - for (i = 0; i < NumInStreams; i++) - { - if (InSizePointers[i] != NULL) - InSizePointers[i] = &InSizes[i]; - InStreamPointers.Add(InStreams[i]); - } - for (i = 0; i < NumOutStreams; i++) - { - if (OutSizePointers[i] != NULL) - OutSizePointers[i] = &OutSizes[i]; - OutStreamPointers.Add(OutStreams[i]); - } - CCoderInfoFlusher2 coderInfoFlusher(this); - if (Coder) - Result = Coder->Code(InStreamPointers[0], - OutStreamPointers[0], - InSizePointers[0], - OutSizePointers[0], - Progress); - else - Result = Coder2->Code(&InStreamPointers.Front(), - &InSizePointers.Front(), - NumInStreams, - &OutStreamPointers.Front(), - &OutSizePointers.Front(), - NumOutStreams, - Progress); + if (OutSizePointers[i] != NULL) + OutSizePointers[i] = &OutSizes[i]; + OutStreamPointers.Add(OutStreams[i]); + } + if (Coder) + Result = Coder->Code(InStreamPointers[0], OutStreamPointers[0], + InSizePointers[0], OutSizePointers[0], progress); + else + Result = Coder2->Code(&InStreamPointers.Front(), &InSizePointers.Front(), NumInStreams, + &OutStreamPointers.Front(), &OutSizePointers.Front(), NumOutStreams, progress); + { + int i; + for (i = 0; i < InStreams.Size(); i++) + InStreams[i].Release(); + for (i = 0; i < OutStreams.Size(); i++) + OutStreams[i].Release(); } - return true; } static void SetSizes(const UInt64 **srcSizes, CRecordVector &sizes, @@ -99,54 +70,15 @@ static void SetSizes(const UInt64 **srcSizes, CRecordVector &sizes, } -void CThreadCoderInfo::SetCoderInfo(const UInt64 **inSizes, - const UInt64 **outSizes, ICompressProgressInfo *progress) +void CCoder2::SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes) { - Progress = progress; SetSizes(inSizes, InSizes, InSizePointers, NumInStreams); SetSizes(outSizes, OutSizes, OutSizePointers, NumOutStreams); } -static THREAD_FUNC_DECL CoderThread(void *threadCoderInfo) -{ - for (;;) - { - if (!((CThreadCoderInfo *)threadCoderInfo)->WaitAndCode()) - return 0; - } -} - ////////////////////////////////////// // CCoderMixer2MT -static THREAD_FUNC_DECL MainCoderThread(void *threadCoderInfo) -{ - for (;;) - { - if (!((CCoderMixer2MT *)threadCoderInfo)->MyCode()) - return 0; - } -} - -CCoderMixer2MT::CCoderMixer2MT() -{ - if (CreateEvents() != S_OK) - throw 271824; - if (_mainThread.Create(MainCoderThread, this) != S_OK) - throw 271825; -} - -CCoderMixer2MT::~CCoderMixer2MT() -{ - _exitEvent.Set(); - _mainThread.Wait(); - for(int i = 0; i < _threads.Size(); i++) - { - _threads[i].Wait(); - _threads[i].Close(); - } -} - HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo) { _bindInfo = bindInfo; @@ -161,48 +93,23 @@ HRESULT CCoderMixer2MT::SetBindInfo(const CBindInfo &bindInfo) void CCoderMixer2MT::AddCoderCommon() { - int index = _coderInfoVector.Size(); - const CCoderStreamsInfo &CoderStreamsInfo = _bindInfo.Coders[index]; - - CThreadCoderInfo threadCoderInfo(CoderStreamsInfo.NumInStreams, - CoderStreamsInfo.NumOutStreams); - _coderInfoVector.Add(threadCoderInfo); - CThreadCoderInfo *tci = &_coderInfoVector.Back(); - tci->CreateEvents(); - tci->ExitEvent = _exitEvent; - - NWindows::CThread newThread; - _threads.Add(newThread); - if (_threads.Back().Create(CoderThread, tci) != S_OK) - throw 271824; + const CCoderStreamsInfo &c = _bindInfo.Coders[_coders.Size()]; + CCoder2 threadCoderInfo(c.NumInStreams, c.NumOutStreams); + _coders.Add(threadCoderInfo); } void CCoderMixer2MT::AddCoder(ICompressCoder *coder) { AddCoderCommon(); - _coderInfoVector.Back().Coder = coder; + _coders.Back().Coder = coder; } void CCoderMixer2MT::AddCoder2(ICompressCoder2 *coder) { AddCoderCommon(); - _coderInfoVector.Back().Coder2 = coder; + _coders.Back().Coder2 = coder; } -/* -void CCoderMixer2MT::FinishAddingCoders() -{ - for(int i = 0; i < _coderInfoVector.Size(); i++) - { - DWORD id; - HANDLE newThread = ::CreateThread(NULL, 0, CoderThread, - &_coderInfoVector[i], 0, &id); - if (newThread == 0) - throw 271824; - _threads.Add(newThread); - } -} -*/ void CCoderMixer2MT::ReInit() { @@ -211,17 +118,16 @@ void CCoderMixer2MT::ReInit() } -STDMETHODIMP CCoderMixer2MT::Init(ISequentialInStream **inStreams, - ISequentialOutStream **outStreams) +HRESULT CCoderMixer2MT::Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams) { /* - if (_coderInfoVector.Size() != _bindInfo.Coders.Size()) + if (_coders.Size() != _bindInfo.Coders.Size()) throw 0; */ int i; - for(i = 0; i < _coderInfoVector.Size(); i++) + for(i = 0; i < _coders.Size(); i++) { - CThreadCoderInfo &coderInfo = _coderInfoVector[i]; + CCoder2 &coderInfo = _coders[i]; const CCoderStreamsInfo &coderStreamsInfo = _bindInfo.Coders[i]; coderInfo.InStreams.Clear(); UInt32 j; @@ -241,45 +147,26 @@ STDMETHODIMP CCoderMixer2MT::Init(ISequentialInStream **inStreams, _bindInfo.FindOutStream(bindPair.OutIndex, outCoderIndex, outCoderStreamIndex); _streamBinders[i].CreateStreams( - &_coderInfoVector[inCoderIndex].InStreams[inCoderStreamIndex], - &_coderInfoVector[outCoderIndex].OutStreams[outCoderStreamIndex]); + &_coders[inCoderIndex].InStreams[inCoderStreamIndex], + &_coders[outCoderIndex].OutStreams[outCoderStreamIndex]); } for(i = 0; i < _bindInfo.InStreams.Size(); i++) { UInt32 inCoderIndex, inCoderStreamIndex; _bindInfo.FindInStream(_bindInfo.InStreams[i], inCoderIndex, inCoderStreamIndex); - _coderInfoVector[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i]; + _coders[inCoderIndex].InStreams[inCoderStreamIndex] = inStreams[i]; } for(i = 0; i < _bindInfo.OutStreams.Size(); i++) { UInt32 outCoderIndex, outCoderStreamIndex; _bindInfo.FindOutStream(_bindInfo.OutStreams[i], outCoderIndex, outCoderStreamIndex); - _coderInfoVector[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i]; + _coders[outCoderIndex].OutStreams[outCoderStreamIndex] = outStreams[i]; } return S_OK; } - -bool CCoderMixer2MT::MyCode() -{ - HANDLE events[2] = { _exitEvent, _startCompressingEvent }; - DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); - if (waitResult == WAIT_OBJECT_0 + 0) - return false; - - int i; - for(i = 0; i < _coderInfoVector.Size(); i++) - _coderInfoVector[i].CompressEvent.Set(); - for (i = 0; i < _coderInfoVector.Size(); i++) - _coderInfoVector[i].CompressionCompletedEvent.Lock(); - - _compressingFinishedEvent.Set(); - return true; -} - - STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams, const UInt64 ** /* inSizes */, UInt32 numInStreams, @@ -294,56 +181,48 @@ STDMETHODIMP CCoderMixer2MT::Code(ISequentialInStream **inStreams, Init(inStreams, outStreams); - _compressingFinishedEvent.Reset(); // ? - - CCrossThreadProgress *progressSpec = new CCrossThreadProgress; - CMyComPtr crossProgress = progressSpec; - RINOK(progressSpec->Create()); - progressSpec->Init(); - _coderInfoVector[_progressCoderIndex].Progress = crossProgress; + int i; + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + { + RINOK(_coders[i].Create()); + } + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + _coders[i].Start(); - _startCompressingEvent.Set(); + _coders[_progressCoderIndex].Code(progress); + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + _coders[i].WaitFinish(); - for (;;) + for (i = 0; i < _coders.Size(); i++) { - HANDLE events[2] = {_compressingFinishedEvent, progressSpec->ProgressEvent }; - DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); - if (waitResult == WAIT_OBJECT_0 + 0) - break; - if (progress != NULL) - progressSpec->Result = progress->SetRatioInfo(progressSpec->InSize, - progressSpec->OutSize); - else - progressSpec->Result = S_OK; - progressSpec->WaitEvent.Set(); + HRESULT result = _coders[i].Result; + if (result == E_ABORT) + return result; } - - int i; - for(i = 0; i < _coderInfoVector.Size(); i++) + for (i = 0; i < _coders.Size(); i++) { - HRESULT result = _coderInfoVector[i].Result; + HRESULT result = _coders[i].Result; if (result == S_FALSE) return result; } - for(i = 0; i < _coderInfoVector.Size(); i++) + for (i = 0; i < _coders.Size(); i++) { - HRESULT result = _coderInfoVector[i].Result; + HRESULT result = _coders[i].Result; if (result != S_OK && result != E_FAIL) return result; } - for(i = 0; i < _coderInfoVector.Size(); i++) + for (i = 0; i < _coders.Size(); i++) { - HRESULT result = _coderInfoVector[i].Result; + HRESULT result = _coders[i].Result; if (result != S_OK) return result; } return S_OK; } -UInt64 CCoderMixer2MT::GetWriteProcessedSize(UInt32 binderIndex) const -{ - return _streamBinders[binderIndex].ProcessedSize; -} - } diff --git a/CPP/7zip/Archive/Common/CoderMixer2MT.h b/CPP/7zip/Archive/Common/CoderMixer2MT.h index 67c0c8a5..3cd3282b 100755 --- a/CPP/7zip/Archive/Common/CoderMixer2MT.h +++ b/CPP/7zip/Archive/Common/CoderMixer2MT.h @@ -5,73 +5,55 @@ #include "CoderMixer2.h" #include "../../../Common/MyCom.h" -#include "../../../Windows/Thread.h" #include "../../Common/StreamBinder.h" +#include "../../Common/VirtThread.h" -namespace NCoderMixer2 { +namespace NCoderMixer { -// CreateEvents(); -// { -// SetCoderInfo() -// Init Streams -// set CompressEvent() -// wait CompressionCompletedEvent -// } - -struct CThreadCoderInfo: public CCoderInfo +struct CCoder2: public CCoderInfo2, public CVirtThread { - NWindows::NSynchronization::CAutoResetEvent CompressEvent; - HANDLE ExitEvent; - NWindows::NSynchronization::CAutoResetEvent CompressionCompletedEvent; - + HRESULT Result; CObjectVector< CMyComPtr > InStreams; CObjectVector< CMyComPtr > OutStreams; - CRecordVector InStreamPointers; - CRecordVector OutStreamPointers; - - CMyComPtr Progress; // CMyComPtr - HRESULT Result; + CRecordVector InStreamPointers; + CRecordVector OutStreamPointers; - CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams); - void SetCoderInfo(const UInt64 **inSizes, - const UInt64 **outSizes, ICompressProgressInfo *progress); - bool WaitAndCode(); - HRes CreateEvents() - { - RINOK(CompressEvent.CreateIfNotCreated()); - return CompressionCompletedEvent.CreateIfNotCreated(); - } + CCoder2(UInt32 numInStreams, UInt32 numOutStreams); + void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes); + virtual void Execute(); + void Code(ICompressProgressInfo *progress); }; -// SetBindInfo() -// for each coder -// { -// AddCoder[2]() -// } -// -// for each file -// { -// ReInit() -// for each coder -// { -// SetCoderInfo -// } -// SetProgressIndex(UInt32 coderIndex); -// Code -// } - +/* + SetBindInfo() + for each coder + AddCoder[2]() + SetProgressIndex(UInt32 coderIndex); + + for each file + { + ReInit() + for each coder + SetCoderInfo + Code + } +*/ class CCoderMixer2MT: public ICompressCoder2, public CCoderMixer2, public CMyUnknownImp { - MY_UNKNOWN_IMP + CBindInfo _bindInfo; + CObjectVector _streamBinders; + int _progressCoderIndex; + void AddCoderCommon(); + HRESULT Init(ISequentialInStream **inStreams, ISequentialOutStream **outStreams); public: - STDMETHOD(Init)(ISequentialInStream **inStreams, - ISequentialOutStream **outStreams); + CObjectVector _coders; + MY_UNKNOWN_IMP STDMETHOD(Code)(ISequentialInStream **inStreams, const UInt64 **inSizes, @@ -81,50 +63,17 @@ public: UInt32 numOutStreams, ICompressProgressInfo *progress); - - CCoderMixer2MT(); - ~CCoderMixer2MT(); - void AddCoderCommon(); + HRESULT SetBindInfo(const CBindInfo &bindInfo); void AddCoder(ICompressCoder *coder); void AddCoder2(ICompressCoder2 *coder); + void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; } void ReInit(); void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) - { _coderInfoVector[coderIndex].SetCoderInfo(inSizes, outSizes, NULL); } - void SetProgressCoderIndex(UInt32 coderIndex) - { _progressCoderIndex = coderIndex; } - - - UInt64 GetWriteProcessedSize(UInt32 binderIndex) const; - - - bool MyCode(); - -private: - CBindInfo _bindInfo; - CObjectVector _streamBinders; - CObjectVector _coderInfoVector; - CRecordVector _threads; - NWindows::CThread _mainThread; - - NWindows::NSynchronization::CAutoResetEvent _startCompressingEvent; - NWindows::NSynchronization::CAutoResetEvent _compressingFinishedEvent; - - NWindows::NSynchronization::CManualResetEvent _exitEvent; - UInt32 _progressCoderIndex; - - HRes CreateEvents() - { - RINOK(_startCompressingEvent.CreateIfNotCreated()); - RINOK(_compressingFinishedEvent.CreateIfNotCreated()); - return _exitEvent.CreateIfNotCreated(); - } - -public: - HRESULT SetBindInfo(const CBindInfo &bindInfo); - + { _coders[coderIndex].SetCoderInfo(inSizes, outSizes); } + UInt64 GetWriteProcessedSize(UInt32 binderIndex) const + { return _streamBinders[binderIndex].ProcessedSize; } }; } #endif - diff --git a/CPP/7zip/Archive/Common/CoderMixerMT.cpp b/CPP/7zip/Archive/Common/CoderMixerMT.cpp new file mode 100755 index 00000000..ad6e12d8 --- /dev/null +++ b/CPP/7zip/Archive/Common/CoderMixerMT.cpp @@ -0,0 +1,97 @@ +// CoderMixerMT.cpp + +#include "StdAfx.h" + +#include "CoderMixerMT.h" + +namespace NCoderMixer { + +void CCoder::Execute() { Code(NULL); } + +void CCoder::Code(ICompressProgressInfo *progress) +{ + Result = Coder->Code(InStream, OutStream, + InSizeAssigned ? &InSizeValue : NULL, + OutSizeAssigned ? &OutSizeValue : NULL, + progress); + InStream.Release(); + OutStream.Release(); +} + +void CCoderMixerMT::AddCoder(ICompressCoder *coder) +{ + _coders.Add(CCoder()); + _coders.Back().Coder = coder; +} + +void CCoderMixerMT::ReInit() +{ + for(int i = 0; i < _coders.Size(); i++) + _coders[i].ReInit(); +} + +STDMETHODIMP CCoderMixerMT::Code(ISequentialInStream *inStream, + ISequentialOutStream *outStream, + const UInt64 * /* inSize */, const UInt64 * /* outSize */, + ICompressProgressInfo *progress) +{ + _coders.Front().InStream = inStream; + int i; + _coders.Back().OutStream = outStream; + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + { + RINOK(_coders[i].Create()); + } + + while (_streamBinders.Size() + 1 < _coders.Size()) + { + _streamBinders.Add(CStreamBinder()); + int i = _streamBinders.Size() - 1; + CStreamBinder &sb = _streamBinders.Back(); + RINOK(sb.CreateEvents()); + sb.CreateStreams(&_coders[i + 1].InStream, &_coders[i].OutStream); + } + + for(i = 0; i < _streamBinders.Size(); i++) + _streamBinders[i].ReInit(); + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + _coders[i].Start(); + + _coders[_progressCoderIndex].Code(progress); + + for (i = 0; i < _coders.Size(); i++) + if (i != _progressCoderIndex) + _coders[i].WaitFinish(); + + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result == E_ABORT) + return result; + } + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result == S_FALSE) + return result; + } + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result != S_OK && result != E_FAIL) + return result; + } + for (i = 0; i < _coders.Size(); i++) + { + HRESULT result = _coders[i].Result; + if (result != S_OK) + return result; + } + return S_OK; +} + +} diff --git a/CPP/7zip/Archive/Common/CoderMixerMT.h b/CPP/7zip/Archive/Common/CoderMixerMT.h new file mode 100755 index 00000000..a2250e8a --- /dev/null +++ b/CPP/7zip/Archive/Common/CoderMixerMT.h @@ -0,0 +1,68 @@ +// CoderMixerMT.h + +#ifndef __CODER_MIXER_MT_H +#define __CODER_MIXER_MT_H + +#include "../../../Common/Vector.h" +#include "../../../Common/MyCom.h" +#include "../../ICoder.h" +#include "../../Common/StreamBinder.h" +#include "../../Common/VirtThread.h" +#include "CoderMixer.h" + +namespace NCoderMixer { + +struct CCoder: public CCoderInfo, public CVirtThread +{ + HRESULT Result; + + virtual void Execute(); + void Code(ICompressProgressInfo *progress); +}; + +/* + for each coder + AddCoder() + SetProgressIndex(UInt32 coderIndex); + + for each file + { + ReInit() + for each coder + SetCoderInfo + Code + } +*/ + + +class CCoderMixerMT: + public ICompressCoder, + public CMyUnknownImp +{ + CObjectVector _streamBinders; + int _progressCoderIndex; + +public: + CObjectVector _coders; + MY_UNKNOWN_IMP + + STDMETHOD(Code)(ISequentialInStream *inStream, + ISequentialOutStream *outStream, + const UInt64 *inSize, const UInt64 *outSize, + ICompressProgressInfo *progress); + + void AddCoder(ICompressCoder *coder); + void SetProgressCoderIndex(int coderIndex) { _progressCoderIndex = coderIndex; } + + void ReInit(); + void SetCoderInfo(UInt32 coderIndex, const UInt64 *inSize, const UInt64 *outSize) + { _coders[coderIndex].SetCoderInfo(inSize, outSize); } + + /* + UInt64 GetWriteProcessedSize(UInt32 binderIndex) const + { return _streamBinders[binderIndex].ProcessedSize; } + */ +}; + +} +#endif diff --git a/CPP/7zip/Archive/Common/HandlerOut.cpp b/CPP/7zip/Archive/Common/HandlerOut.cpp new file mode 100755 index 00000000..7c214c3c --- /dev/null +++ b/CPP/7zip/Archive/Common/HandlerOut.cpp @@ -0,0 +1,609 @@ +// HandlerOutCommon.cpp + +#include "StdAfx.h" + +#include "HandlerOut.h" +#include "../../../Windows/PropVariant.h" +#include "../../../Common/StringToInt.h" +#include "../../ICoder.h" +#include "../Common/ParseProperties.h" + +#ifdef COMPRESS_MT +#include "../../../Windows/System.h" +#endif + +using namespace NWindows; + +namespace NArchive { + +static const wchar_t *kCopyMethod = L"Copy"; +static const wchar_t *kLZMAMethodName = L"LZMA"; +static const wchar_t *kLZMA2MethodName = L"LZMA2"; +static const wchar_t *kBZip2MethodName = L"BZip2"; +static const wchar_t *kPpmdMethodName = L"PPMd"; +static const wchar_t *kDeflateMethodName = L"Deflate"; +static const wchar_t *kDeflate64MethodName = L"Deflate64"; + +static const wchar_t *kLzmaMatchFinderX1 = L"HC4"; +static const wchar_t *kLzmaMatchFinderX5 = L"BT4"; + +static const UInt32 kLzmaAlgoX1 = 0; +static const UInt32 kLzmaAlgoX5 = 1; + +static const UInt32 kLzmaDicSizeX1 = 1 << 16; +static const UInt32 kLzmaDicSizeX3 = 1 << 20; +static const UInt32 kLzmaDicSizeX5 = 1 << 24; +static const UInt32 kLzmaDicSizeX7 = 1 << 25; +static const UInt32 kLzmaDicSizeX9 = 1 << 26; + +static const UInt32 kLzmaFastBytesX1 = 32; +static const UInt32 kLzmaFastBytesX7 = 64; + +static const UInt32 kPpmdMemSizeX1 = (1 << 22); +static const UInt32 kPpmdMemSizeX5 = (1 << 24); +static const UInt32 kPpmdMemSizeX7 = (1 << 26); +static const UInt32 kPpmdMemSizeX9 = (192 << 20); + +static const UInt32 kPpmdOrderX1 = 4; +static const UInt32 kPpmdOrderX5 = 6; +static const UInt32 kPpmdOrderX7 = 16; +static const UInt32 kPpmdOrderX9 = 32; + +static const UInt32 kDeflateAlgoX1 = 0; +static const UInt32 kDeflateAlgoX5 = 1; + +static const UInt32 kDeflateFastBytesX1 = 32; +static const UInt32 kDeflateFastBytesX7 = 64; +static const UInt32 kDeflateFastBytesX9 = 128; + +static const UInt32 kDeflatePassesX1 = 1; +static const UInt32 kDeflatePassesX7 = 3; +static const UInt32 kDeflatePassesX9 = 10; + +static const UInt32 kBZip2NumPassesX1 = 1; +static const UInt32 kBZip2NumPassesX7 = 2; +static const UInt32 kBZip2NumPassesX9 = 7; + +static const UInt32 kBZip2DicSizeX1 = 100000; +static const UInt32 kBZip2DicSizeX3 = 500000; +static const UInt32 kBZip2DicSizeX5 = 900000; + +static const wchar_t *kDefaultMethodName = kLZMAMethodName; + +static const wchar_t *kLzmaMatchFinderForHeaders = L"BT2"; +static const UInt32 kDictionaryForHeaders = 1 << 20; +static const UInt32 kNumFastBytesForHeaders = 273; +static const UInt32 kAlgorithmForHeaders = kLzmaAlgoX5; + +static bool AreEqual(const UString &methodName, const wchar_t *s) + { return (methodName.CompareNoCase(s) == 0); } + +static inline bool IsLZMAMethod(const UString &methodName) +{ + return + AreEqual(methodName, kLZMAMethodName) || + AreEqual(methodName, kLZMA2MethodName); +} + +static inline bool IsBZip2Method(const UString &methodName) + { return AreEqual(methodName, kBZip2MethodName); } + +static inline bool IsPpmdMethod(const UString &methodName) + { return AreEqual(methodName, kPpmdMethodName); } + +static inline bool IsDeflateMethod(const UString &methodName) +{ + return + AreEqual(methodName, kDeflateMethodName) || + AreEqual(methodName, kDeflate64MethodName); +} + +struct CNameToPropID +{ + PROPID PropID; + VARTYPE VarType; + const wchar_t *Name; +}; + +CNameToPropID g_NameToPropID[] = +{ + { NCoderPropID::kOrder, VT_UI4, L"O" }, + { NCoderPropID::kPosStateBits, VT_UI4, L"PB" }, + { NCoderPropID::kLitContextBits, VT_UI4, L"LC" }, + { NCoderPropID::kLitPosBits, VT_UI4, L"LP" }, + { NCoderPropID::kEndMarker, VT_BOOL, L"eos" }, + + { NCoderPropID::kNumPasses, VT_UI4, L"Pass" }, + { NCoderPropID::kNumFastBytes, VT_UI4, L"fb" }, + { NCoderPropID::kMatchFinderCycles, VT_UI4, L"mc" }, + { NCoderPropID::kAlgorithm, VT_UI4, L"a" }, + { NCoderPropID::kMatchFinder, VT_BSTR, L"mf" }, + { NCoderPropID::kNumThreads, VT_UI4, L"mt" } +}; + +static bool ConvertProperty(PROPVARIANT srcProp, VARTYPE varType, NCOM::CPropVariant &destProp) +{ + if (varType == srcProp.vt) + { + destProp = srcProp; + return true; + } + if (varType == VT_UI1) + { + if (srcProp.vt == VT_UI4) + { + UInt32 value = srcProp.ulVal; + if (value > 0xFF) + return false; + destProp = (Byte)value; + return true; + } + } + else if (varType == VT_BOOL) + { + bool res; + if (SetBoolProperty(res, srcProp) != S_OK) + return false; + destProp = res; + return true; + } + return false; +} + +static int FindPropIdFromStringName(const UString &name) +{ + for (int i = 0; i < sizeof(g_NameToPropID) / sizeof(g_NameToPropID[0]); i++) + if (name.CompareNoCase(g_NameToPropID[i].Name) == 0) + return i; + return -1; +} + +static void SetOneMethodProp(COneMethodInfo &oneMethodInfo, PROPID propID, + const NWindows::NCOM::CPropVariant &value) +{ + for (int j = 0; j < oneMethodInfo.Properties.Size(); j++) + if (oneMethodInfo.Properties[j].Id == propID) + return; + CProp property; + property.Id = propID; + property.Value = value; + oneMethodInfo.Properties.Add(property); +} + +void COutHandler::SetCompressionMethod2(COneMethodInfo &oneMethodInfo + #ifdef COMPRESS_MT + , UInt32 numThreads + #endif + ) +{ + UInt32 level = _level; + if (oneMethodInfo.MethodName.IsEmpty()) + oneMethodInfo.MethodName = kDefaultMethodName; + + if (IsLZMAMethod(oneMethodInfo.MethodName)) + { + UInt32 dicSize = + (level >= 9 ? kLzmaDicSizeX9 : + (level >= 7 ? kLzmaDicSizeX7 : + (level >= 5 ? kLzmaDicSizeX5 : + (level >= 3 ? kLzmaDicSizeX3 : + kLzmaDicSizeX1)))); + + UInt32 algo = + (level >= 5 ? kLzmaAlgoX5 : + kLzmaAlgoX1); + + UInt32 fastBytes = + (level >= 7 ? kLzmaFastBytesX7 : + kLzmaFastBytesX1); + + const wchar_t *matchFinder = + (level >= 5 ? kLzmaMatchFinderX5 : + kLzmaMatchFinderX1); + + SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kMatchFinder, matchFinder); + #ifdef COMPRESS_MT + SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads); + #endif + } + else if (IsDeflateMethod(oneMethodInfo.MethodName)) + { + UInt32 fastBytes = + (level >= 9 ? kDeflateFastBytesX9 : + (level >= 7 ? kDeflateFastBytesX7 : + kDeflateFastBytesX1)); + + UInt32 numPasses = + (level >= 9 ? kDeflatePassesX9 : + (level >= 7 ? kDeflatePassesX7 : + kDeflatePassesX1)); + + UInt32 algo = + (level >= 5 ? kDeflateAlgoX5 : + kDeflateAlgoX1); + + SetOneMethodProp(oneMethodInfo, NCoderPropID::kAlgorithm, algo); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumFastBytes, fastBytes); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses); + } + else if (IsBZip2Method(oneMethodInfo.MethodName)) + { + UInt32 numPasses = + (level >= 9 ? kBZip2NumPassesX9 : + (level >= 7 ? kBZip2NumPassesX7 : + kBZip2NumPassesX1)); + + UInt32 dicSize = + (level >= 5 ? kBZip2DicSizeX5 : + (level >= 3 ? kBZip2DicSizeX3 : + kBZip2DicSizeX1)); + + SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumPasses, numPasses); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kDictionarySize, dicSize); + #ifdef COMPRESS_MT + SetOneMethodProp(oneMethodInfo, NCoderPropID::kNumThreads, numThreads); + #endif + } + else if (IsPpmdMethod(oneMethodInfo.MethodName)) + { + UInt32 useMemSize = + (level >= 9 ? kPpmdMemSizeX9 : + (level >= 7 ? kPpmdMemSizeX7 : + (level >= 5 ? kPpmdMemSizeX5 : + kPpmdMemSizeX1))); + + UInt32 order = + (level >= 9 ? kPpmdOrderX9 : + (level >= 7 ? kPpmdOrderX7 : + (level >= 5 ? kPpmdOrderX5 : + kPpmdOrderX1))); + + SetOneMethodProp(oneMethodInfo, NCoderPropID::kUsedMemorySize, useMemSize); + SetOneMethodProp(oneMethodInfo, NCoderPropID::kOrder, order); + } +} + +static void SplitParams(const UString &srcString, UStringVector &subStrings) +{ + subStrings.Clear(); + UString name; + int len = srcString.Length(); + if (len == 0) + return; + for (int i = 0; i < len; i++) + { + wchar_t c = srcString[i]; + if (c == L':') + { + subStrings.Add(name); + name.Empty(); + } + else + name += c; + } + subStrings.Add(name); +} + +static void SplitParam(const UString ¶m, UString &name, UString &value) +{ + int eqPos = param.Find(L'='); + if (eqPos >= 0) + { + name = param.Left(eqPos); + value = param.Mid(eqPos + 1); + return; + } + for(int i = 0; i < param.Length(); i++) + { + wchar_t c = param[i]; + if (c >= L'0' && c <= L'9') + { + name = param.Left(i); + value = param.Mid(i); + return; + } + } + name = param; +} + +HRESULT COutHandler::SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value) +{ + CProp property; + if ( + name.CompareNoCase(L"D") == 0 || + name.CompareNoCase(L"MEM") == 0) + { + UInt32 dicSize; + RINOK(ParsePropDictionaryValue(value, dicSize)); + if (name.CompareNoCase(L"D") == 0) + property.Id = NCoderPropID::kDictionarySize; + else + property.Id = NCoderPropID::kUsedMemorySize; + property.Value = dicSize; + oneMethodInfo.Properties.Add(property); + } + else + { + int index = FindPropIdFromStringName(name); + if (index < 0) + return E_INVALIDARG; + + const CNameToPropID &nameToPropID = g_NameToPropID[index]; + property.Id = nameToPropID.PropID; + + NCOM::CPropVariant propValue; + + if (nameToPropID.VarType == VT_BSTR) + propValue = value; + else if (nameToPropID.VarType == VT_BOOL) + { + bool res; + if (!StringToBool(value, res)) + return E_INVALIDARG; + propValue = res; + } + else + { + UInt32 number; + if (ParseStringToUInt32(value, number) == value.Length()) + propValue = number; + else + propValue = value; + } + + if (!ConvertProperty(propValue, nameToPropID.VarType, property.Value)) + return E_INVALIDARG; + + oneMethodInfo.Properties.Add(property); + } + return S_OK; +} + +HRESULT COutHandler::SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString) +{ + UStringVector params; + SplitParams(srcString, params); + if (params.Size() > 0) + oneMethodInfo.MethodName = params[0]; + for (int i = 1; i < params.Size(); i++) + { + const UString ¶m = params[i]; + UString name, value; + SplitParam(param, name, value); + RINOK(SetParam(oneMethodInfo, name, value)); + } + return S_OK; +} + +HRESULT COutHandler::SetSolidSettings(const UString &s) +{ + bool res; + if (StringToBool(s, res)) + { + if (res) + InitSolid(); + else + _numSolidFiles = 1; + return S_OK; + } + UString s2 = s; + s2.MakeUpper(); + for (int i = 0; i < s2.Length();) + { + const wchar_t *start = ((const wchar_t *)s2) + i; + const wchar_t *end; + UInt64 v = ConvertStringToUInt64(start, &end); + if (start == end) + { + if (s2[i++] != 'E') + return E_INVALIDARG; + _solidExtension = true; + continue; + } + i += (int)(end - start); + if (i == s2.Length()) + return E_INVALIDARG; + wchar_t c = s2[i++]; + switch(c) + { + case 'F': + if (v < 1) + v = 1; + _numSolidFiles = v; + break; + case 'B': + _numSolidBytes = v; + _numSolidBytesDefined = true; + break; + case 'K': + _numSolidBytes = (v << 10); + _numSolidBytesDefined = true; + break; + case 'M': + _numSolidBytes = (v << 20); + _numSolidBytesDefined = true; + break; + case 'G': + _numSolidBytes = (v << 30); + _numSolidBytesDefined = true; + break; + default: + return E_INVALIDARG; + } + } + return S_OK; +} + +HRESULT COutHandler::SetSolidSettings(const PROPVARIANT &value) +{ + switch(value.vt) + { + case VT_EMPTY: + InitSolid(); + return S_OK; + case VT_BSTR: + return SetSolidSettings(value.bstrVal); + default: + return E_INVALIDARG; + } +} + +void COutHandler::Init() +{ + _removeSfxBlock = false; + _compressHeaders = true; + _encryptHeaders = false; + + WriteModified = true; + WriteCreated = false; + WriteAccessed = false; + + #ifdef COMPRESS_MT + _numThreads = NWindows::NSystem::GetNumberOfProcessors(); + #endif + + _level = 5; + _autoFilter = true; + _volumeMode = false; + InitSolid(); +} + +void COutHandler::BeforeSetProperty() +{ + Init(); + #ifdef COMPRESS_MT + numProcessors = NSystem::GetNumberOfProcessors(); + #endif + + mainDicSize = 0xFFFFFFFF; + mainDicMethodIndex = 0xFFFFFFFF; + minNumber = 0; +} + +HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &value) +{ + UString name = nameSpec; + name.MakeUpper(); + if (name.IsEmpty()) + return E_INVALIDARG; + + if (name[0] == 'X') + { + name.Delete(0); + _level = 9; + return ParsePropValue(name, value, _level); + } + + if (name[0] == L'S') + { + name.Delete(0); + if (name.IsEmpty()) + return SetSolidSettings(value); + if (value.vt != VT_EMPTY) + return E_INVALIDARG; + return SetSolidSettings(name); + } + + UInt32 number; + int index = ParseStringToUInt32(name, number); + UString realName = name.Mid(index); + if (index == 0) + { + if(name.Left(2).CompareNoCase(L"MT") == 0) + { + #ifdef COMPRESS_MT + RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads)); + #endif + return S_OK; + } + if (name.CompareNoCase(L"RSFX") == 0) + return SetBoolProperty(_removeSfxBlock, value); + if (name.CompareNoCase(L"F") == 0) + return SetBoolProperty(_autoFilter, value); + if (name.CompareNoCase(L"HC") == 0) + return SetBoolProperty(_compressHeaders, value); + if (name.CompareNoCase(L"HCF") == 0) + { + bool compressHeadersFull = true; + RINOK(SetBoolProperty(compressHeadersFull, value)); + if (!compressHeadersFull) + return E_INVALIDARG; + return S_OK; + } + if (name.CompareNoCase(L"HE") == 0) + return SetBoolProperty(_encryptHeaders, value); + if (name.CompareNoCase(L"TM") == 0) + return SetBoolProperty(WriteModified, value); + if (name.CompareNoCase(L"TC") == 0) + return SetBoolProperty(WriteCreated, value); + if (name.CompareNoCase(L"TA") == 0) + return SetBoolProperty(WriteAccessed, value); + if (name.CompareNoCase(L"V") == 0) + return SetBoolProperty(_volumeMode, value); + number = 0; + } + if (number > 10000) + return E_FAIL; + if (number < minNumber) + return E_INVALIDARG; + number -= minNumber; + for(int j = _methods.Size(); j <= (int)number; j++) + { + COneMethodInfo oneMethodInfo; + _methods.Add(oneMethodInfo); + } + + COneMethodInfo &oneMethodInfo = _methods[number]; + + if (realName.Length() == 0) + { + if (value.vt != VT_BSTR) + return E_INVALIDARG; + + RINOK(SetParams(oneMethodInfo, value.bstrVal)); + } + else + { + CProp property; + if (realName.Left(1).CompareNoCase(L"D") == 0) + { + UInt32 dicSize; + RINOK(ParsePropDictionaryValue(realName.Mid(1), value, dicSize)); + property.Id = NCoderPropID::kDictionarySize; + property.Value = dicSize; + oneMethodInfo.Properties.Add(property); + if (number <= mainDicMethodIndex) + mainDicSize = dicSize; + } + else if (realName.Left(3).CompareNoCase(L"MEM") == 0) + { + UInt32 dicSize; + RINOK(ParsePropDictionaryValue(realName.Mid(3), value, dicSize)); + property.Id = NCoderPropID::kUsedMemorySize; + property.Value = dicSize; + oneMethodInfo.Properties.Add(property); + if (number <= mainDicMethodIndex) + mainDicSize = dicSize; + } + else + { + int index = FindPropIdFromStringName(realName); + if (index < 0) + return E_INVALIDARG; + + const CNameToPropID &nameToPropID = g_NameToPropID[index]; + property.Id = nameToPropID.PropID; + + if (!ConvertProperty(value, nameToPropID.VarType, property.Value)) + return E_INVALIDARG; + + oneMethodInfo.Properties.Add(property); + } + } + return S_OK; +} + +} diff --git a/CPP/7zip/Archive/Common/HandlerOut.h b/CPP/7zip/Archive/Common/HandlerOut.h new file mode 100755 index 00000000..eded0786 --- /dev/null +++ b/CPP/7zip/Archive/Common/HandlerOut.h @@ -0,0 +1,84 @@ +// HandlerOut.h + +#ifndef __HANDLER_OUT_H +#define __HANDLER_OUT_H + +#include "../../Common/MethodProps.h" +#include "../../Common/CreateCoder.h" + +namespace NArchive { + +struct COneMethodInfo +{ + CObjectVector Properties; + UString MethodName; +}; + +class COutHandler +{ +public: + HRESULT SetProperty(const wchar_t *name, const PROPVARIANT &value); + + HRESULT SetSolidSettings(const UString &s); + HRESULT SetSolidSettings(const PROPVARIANT &value); + + #ifdef COMPRESS_MT + UInt32 _numThreads; + #endif + + CObjectVector _methods; + bool _removeSfxBlock; + + UInt64 _numSolidFiles; + UInt64 _numSolidBytes; + bool _numSolidBytesDefined; + bool _solidExtension; + + bool _compressHeaders; + bool _encryptHeaders; + + bool WriteModified; + bool WriteCreated; + bool WriteAccessed; + + bool _autoFilter; + UInt32 _level; + + bool _volumeMode; + + HRESULT SetParam(COneMethodInfo &oneMethodInfo, const UString &name, const UString &value); + HRESULT SetParams(COneMethodInfo &oneMethodInfo, const UString &srcString); + + void SetCompressionMethod2(COneMethodInfo &oneMethodInfo + #ifdef COMPRESS_MT + , UInt32 numThreads + #endif + ); + + void InitSolidFiles() { _numSolidFiles = (UInt64)(Int64)(-1); } + void InitSolidSize() { _numSolidBytes = (UInt64)(Int64)(-1); } + void InitSolid() + { + InitSolidFiles(); + InitSolidSize(); + _solidExtension = false; + _numSolidBytesDefined = false; + } + + void Init(); + + COutHandler() { Init(); } + + void BeforeSetProperty(); + + UInt32 minNumber; + UInt32 numProcessors; + UInt32 mainDicSize; + UInt32 mainDicMethodIndex; + + DECL_EXTERNAL_CODECS_VARS +}; + +} + +#endif diff --git a/CPP/7zip/Archive/Common/ItemNameUtils.h b/CPP/7zip/Archive/Common/ItemNameUtils.h index 63a01563..5eafacb1 100755 --- a/CPP/7zip/Archive/Common/ItemNameUtils.h +++ b/CPP/7zip/Archive/Common/ItemNameUtils.h @@ -3,7 +3,7 @@ #ifndef __ARCHIVE_ITEMNAMEUTILS_H #define __ARCHIVE_ITEMNAMEUTILS_H -#include "../../../Common/String.h" +#include "../../../Common/MyString.h" namespace NArchive { namespace NItemName { diff --git a/CPP/7zip/Archive/Common/MultiStream.h b/CPP/7zip/Archive/Common/MultiStream.h index 5a7cc687..b0fe41d6 100755 --- a/CPP/7zip/Archive/Common/MultiStream.h +++ b/CPP/7zip/Archive/Common/MultiStream.h @@ -4,7 +4,7 @@ #define __MULTISTREAM_H #include "../../../Common/MyCom.h" -#include "../../../Common/Vector.h" +#include "../../../Common/MyVector.h" #include "../../Archive/IArchive.h" class CMultiStream: diff --git a/CPP/7zip/Archive/Common/ParseProperties.cpp b/CPP/7zip/Archive/Common/ParseProperties.cpp index 9866d900..f0d4e29c 100755 --- a/CPP/7zip/Archive/Common/ParseProperties.cpp +++ b/CPP/7zip/Archive/Common/ParseProperties.cpp @@ -97,34 +97,37 @@ HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, U return ParsePropDictionaryValue(name, resValue); } +bool StringToBool(const UString &s, bool &res) +{ + if (s.IsEmpty() || s.CompareNoCase(L"ON") == 0) + { + res = true; + return true; + } + if (s.CompareNoCase(L"OFF") == 0) + { + res = false; + return true; + } + return false; +} + HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value) { switch(value.vt) { case VT_EMPTY: dest = true; - break; + return S_OK; /* case VT_UI4: dest = (value.ulVal != 0); break; */ case VT_BSTR: - { - UString valueString = value.bstrVal; - valueString.MakeUpper(); - if (valueString.Compare(L"ON") == 0) - dest = true; - else if (valueString.Compare(L"OFF") == 0) - dest = false; - else - return E_INVALIDARG; - break; - } - default: - return E_INVALIDARG; + return StringToBool(value.bstrVal, dest) ? S_OK : E_INVALIDARG; } - return S_OK; + return E_INVALIDARG; } int ParseStringToUInt32(const UString &srcString, UInt32 &number) diff --git a/CPP/7zip/Archive/Common/ParseProperties.h b/CPP/7zip/Archive/Common/ParseProperties.h index e6db316b..6f80f634 100755 --- a/CPP/7zip/Archive/Common/ParseProperties.h +++ b/CPP/7zip/Archive/Common/ParseProperties.h @@ -3,13 +3,14 @@ #ifndef __PARSEPROPERTIES_H #define __PARSEPROPERTIES_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" HRESULT ParsePropValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue); HRESULT ParsePropDictionaryValue(const UString &srcStringSpec, UInt32 &dicSize); HRESULT ParsePropDictionaryValue(const UString &name, const PROPVARIANT &prop, UInt32 &resValue); +bool StringToBool(const UString &s, bool &res); HRESULT SetBoolProperty(bool &dest, const PROPVARIANT &value); int ParseStringToUInt32(const UString &srcString, UInt32 &number); HRESULT ParseMtProp(const UString &name, const PROPVARIANT &prop, UInt32 defaultNumThreads, UInt32 &numThreads); diff --git a/CPP/7zip/Archive/Cpio/CpioItem.h b/CPP/7zip/Archive/Cpio/CpioItem.h index 0eb2a0b4..cee8b5b3 100755 --- a/CPP/7zip/Archive/Cpio/CpioItem.h +++ b/CPP/7zip/Archive/Cpio/CpioItem.h @@ -6,7 +6,7 @@ #include #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "CpioHeader.h" namespace NArchive { diff --git a/CPP/7zip/Archive/Deb/DebItem.h b/CPP/7zip/Archive/Deb/DebItem.h index f587f3f5..86e6740d 100755 --- a/CPP/7zip/Archive/Deb/DebItem.h +++ b/CPP/7zip/Archive/Deb/DebItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_DEB_ITEMINFO_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "DebHeader.h" namespace NArchive { diff --git a/CPP/7zip/Archive/GZip/GZipItem.h b/CPP/7zip/Archive/GZip/GZipItem.h index 7006dfb3..cd5e59f0 100755 --- a/CPP/7zip/Archive/GZip/GZipItem.h +++ b/CPP/7zip/Archive/GZip/GZipItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_GZIP_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Buffer.h" namespace NArchive { diff --git a/CPP/7zip/Archive/Iso/IsoItem.h b/CPP/7zip/Archive/Iso/IsoItem.h index 14024d8d..e899d616 100755 --- a/CPP/7zip/Archive/Iso/IsoItem.h +++ b/CPP/7zip/Archive/Iso/IsoItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_ISO_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Buffer.h" #include "IsoHeader.h" diff --git a/CPP/7zip/Archive/Lzh/LzhItem.h b/CPP/7zip/Archive/Lzh/LzhItem.h index 66d4ed75..d0ba25e2 100755 --- a/CPP/7zip/Archive/Lzh/LzhItem.h +++ b/CPP/7zip/Archive/Lzh/LzhItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_LZH_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Buffer.h" #include "LzhHeader.h" diff --git a/CPP/7zip/Archive/Rar/RarIn.h b/CPP/7zip/Archive/Rar/RarIn.h index 83a4d193..9cb66512 100755 --- a/CPP/7zip/Archive/Rar/RarIn.h +++ b/CPP/7zip/Archive/Rar/RarIn.h @@ -4,7 +4,6 @@ #define __ARCHIVE_RAR_IN_H #include "Common/DynamicBuffer.h" -#include "Common/Exception.h" #include "Common/MyCom.h" #include "../../IStream.h" #include "../../ICoder.h" diff --git a/CPP/7zip/Archive/Rar/RarItem.h b/CPP/7zip/Archive/Rar/RarItem.h index 85050a42..5ab8a46e 100755 --- a/CPP/7zip/Archive/Rar/RarItem.h +++ b/CPP/7zip/Archive/Rar/RarItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_RAR_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" namespace NArchive{ namespace NRar{ diff --git a/CPP/7zip/Archive/Split/SplitHandler.h b/CPP/7zip/Archive/Split/SplitHandler.h index a98dc0a6..65071cfd 100755 --- a/CPP/7zip/Archive/Split/SplitHandler.h +++ b/CPP/7zip/Archive/Split/SplitHandler.h @@ -4,7 +4,7 @@ #define __SPLIT_HANDLER_H #include "Common/MyCom.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "../IArchive.h" namespace NArchive { diff --git a/CPP/7zip/Archive/Tar/TarHandler.cpp b/CPP/7zip/Archive/Tar/TarHandler.cpp index 9c2cd006..f2c83caf 100755 --- a/CPP/7zip/Archive/Tar/TarHandler.cpp +++ b/CPP/7zip/Archive/Tar/TarHandler.cpp @@ -113,8 +113,22 @@ STDMETHODIMP CHandler::Open(IInStream *stream, } } if (_items.Size() == 0) - return S_FALSE; - + { + CMyComPtr openVolumeCallback; + if (!openArchiveCallback) + return S_FALSE; + openArchiveCallback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback); + if (!openVolumeCallback) + return S_FALSE; + NCOM::CPropVariant propVariant; + RINOK(openVolumeCallback->GetProperty(kpidName, &propVariant)); + if (propVariant.vt != VT_BSTR) + return S_FALSE; + UString baseName = propVariant.bstrVal; + baseName = baseName.Right(4); + if (baseName.CompareNoCase(L".tar") != 0) + return S_FALSE; + } _inStream = stream; } /* diff --git a/CPP/7zip/Archive/Tar/TarItem.h b/CPP/7zip/Archive/Tar/TarItem.h index 71fff7ba..10b57cd0 100755 --- a/CPP/7zip/Archive/Tar/TarItem.h +++ b/CPP/7zip/Archive/Tar/TarItem.h @@ -6,7 +6,7 @@ #include #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "../Common/ItemNameUtils.h" #include "TarHeader.h" diff --git a/CPP/7zip/Archive/Tar/TarUpdate.h b/CPP/7zip/Archive/Tar/TarUpdate.h index 92f5cebb..67d671f5 100755 --- a/CPP/7zip/Archive/Tar/TarUpdate.h +++ b/CPP/7zip/Archive/Tar/TarUpdate.h @@ -3,10 +3,6 @@ #ifndef __TAR_UPDATE_H #define __TAR_UPDATE_H -#include "Common/Vector.h" -#include "Common/Types.h" -#include "Common/String.h" - #include "../IArchive.h" #include "TarItem.h" diff --git a/CPP/7zip/Archive/Zip/ZipCompressionMode.h b/CPP/7zip/Archive/Zip/ZipCompressionMode.h index 650d4f35..37f22f77 100755 --- a/CPP/7zip/Archive/Zip/ZipCompressionMode.h +++ b/CPP/7zip/Archive/Zip/ZipCompressionMode.h @@ -3,8 +3,7 @@ #ifndef __ZIP_COMPRESSIONMETHOD_H #define __ZIP_COMPRESSIONMETHOD_H -#include "Common/Vector.h" -#include "Common/String.h" +#include "Common/MyString.h" namespace NArchive { namespace NZip { diff --git a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp index 0ccd3727..453c37a3 100755 --- a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +++ b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp @@ -16,6 +16,7 @@ #include "../Common/ItemNameUtils.h" #include "../Common/ParseProperties.h" #include "../../Crypto/WzAES/WzAES.h" +#include "../../Common/OutBuffer.h" using namespace NWindows; using namespace NCOM; @@ -60,10 +61,15 @@ static bool IsAsciiString(const UString &s) return true; } +#define COM_TRY_BEGIN2 try { +#define COM_TRY_END2 } \ +catch(const CSystemException &e) { return e.ErrorCode; } \ +catch(...) { return E_OUTOFMEMORY; } + STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems, IArchiveUpdateCallback *updateCallback) { - COM_TRY_BEGIN + COM_TRY_BEGIN2 CObjectVector updateItems; for(UInt32 i = 0; i < numItems; i++) { @@ -276,7 +282,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt EXTERNAL_CODECS_VARS m_Items, updateItems, outStream, m_ArchiveIsOpen ? &m_Archive : NULL, &options, updateCallback); - COM_TRY_END + COM_TRY_END2 } STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) diff --git a/CPP/7zip/Archive/Zip/ZipIn.cpp b/CPP/7zip/Archive/Zip/ZipIn.cpp index 7c5ecbfb..bb45d1d1 100755 --- a/CPP/7zip/Archive/Zip/ZipIn.cpp +++ b/CPP/7zip/Archive/Zip/ZipIn.cpp @@ -341,11 +341,14 @@ HRESULT CInArchive::ReadLocalItemAfterCdItem(CItemEx &item) RINOK(ReadLocalItem(localItem)); if (item.Flags != localItem.Flags) { - if ((item.CompressionMethod != NFileHeader::NCompressionMethod::kDeflated || - (item.Flags & 0x7FFC) != (localItem.Flags & 0x7FFC)) && - ((item.CompressionMethod != NFileHeader::NCompressionMethod::kStored || - (item.Flags & 0x7FFF) != (localItem.Flags & 0x7FFF)) - )) + if ( + (item.CompressionMethod != NFileHeader::NCompressionMethod::kDeflated || + (item.Flags & 0x7FF9) != (localItem.Flags & 0x7FF9)) && + (item.CompressionMethod != NFileHeader::NCompressionMethod::kStored || + (item.Flags & 0x7FFF) != (localItem.Flags & 0x7FFF)) && + (item.CompressionMethod != NFileHeader::NCompressionMethod::kImploded || + (item.Flags & 0x7FFF) != (localItem.Flags & 0x7FFF)) + ) return S_FALSE; } diff --git a/CPP/7zip/Archive/Zip/ZipItem.h b/CPP/7zip/Archive/Zip/ZipItem.h index 765bfd85..4a7a47f1 100755 --- a/CPP/7zip/Archive/Zip/ZipItem.h +++ b/CPP/7zip/Archive/Zip/ZipItem.h @@ -4,7 +4,7 @@ #define __ARCHIVE_ZIP_ITEM_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Buffer.h" #include "ZipHeader.h" diff --git a/CPP/7zip/Archive/Zip/ZipOut.cpp b/CPP/7zip/Archive/Zip/ZipOut.cpp index 1f108235..d5e6895e 100755 --- a/CPP/7zip/Archive/Zip/ZipOut.cpp +++ b/CPP/7zip/Archive/Zip/ZipOut.cpp @@ -12,7 +12,11 @@ namespace NZip { void COutArchive::Create(IOutStream *outStream) { + if (!m_OutBuffer.Create(1 << 16)) + throw CSystemException(E_OUTOFMEMORY); m_Stream = outStream; + m_OutBuffer.SetStream(outStream); + m_OutBuffer.Init(); m_BasePosition = 0; } @@ -47,11 +51,7 @@ void COutArchive::PrepareWriteCompressedData2(UInt16 fileNameLength, UInt64 unPa void COutArchive::WriteBytes(const void *buffer, UInt32 size) { - UInt32 processedSize; - if(WriteStream(m_Stream, buffer, size, &processedSize) != S_OK) - throw 0; - if(processedSize != size) - throw 0; + m_OutBuffer.WriteBytes(buffer, size); m_BasePosition += size; } @@ -101,9 +101,16 @@ void COutArchive::WriteExtra(const CExtraBlock &extra) } } -HRESULT COutArchive::WriteLocalHeader(const CLocalItem &item) +void COutArchive::SeekTo(UInt64 offset) { - m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); + HRESULT res = m_Stream->Seek(offset, STREAM_SEEK_SET, NULL); + if (res != S_OK) + throw CSystemException(res); +} + +void COutArchive::WriteLocalHeader(const CLocalItem &item) +{ + SeekTo(m_BasePosition); bool isZip64 = m_IsZip64 || item.PackSize >= 0xFFFFFFFF || item.UnPackSize >= 0xFFFFFFFF; @@ -120,7 +127,7 @@ HRESULT COutArchive::WriteLocalHeader(const CLocalItem &item) { UInt16 localExtraSize = (UInt16)((isZip64 ? (4 + 16): 0) + item.LocalExtra.GetSize()); if (localExtraSize > m_ExtraSize) - return E_FAIL; + throw CSystemException(E_FAIL); } WriteUInt16((UInt16)m_ExtraSize); // test it; WriteBytes((const char *)item.Name, item.Name.Length()); @@ -140,14 +147,13 @@ HRESULT COutArchive::WriteLocalHeader(const CLocalItem &item) for (; extraPos < m_ExtraSize; extraPos++) WriteByte(0); + m_OutBuffer.FlushWithCheck(); MoveBasePosition(item.PackSize); - return m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); + SeekTo(m_BasePosition); } void COutArchive::WriteCentralHeader(const CItem &item) { - m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); - bool isUnPack64 = item.UnPackSize >= 0xFFFFFFFF; bool isPack64 = item.PackSize >= 0xFFFFFFFF; bool isPosition64 = item.LocalHeaderPosition >= 0xFFFFFFFF; @@ -193,7 +199,7 @@ void COutArchive::WriteCentralHeader(const CItem &item) void COutArchive::WriteCentralDir(const CObjectVector &items, const CByteBuffer &comment) { - m_Stream->Seek(m_BasePosition, STREAM_SEEK_SET, NULL); + SeekTo(m_BasePosition); UInt64 cdOffset = GetCurrentPosition(); for(int i = 0; i < items.Size(); i++) @@ -234,6 +240,7 @@ void COutArchive::WriteCentralDir(const CObjectVector &items, const CByte WriteUInt16(commentSize); if (commentSize > 0) WriteBytes((const Byte *)comment, commentSize); + m_OutBuffer.FlushWithCheck(); } void COutArchive::CreateStreamForCompressing(IOutStream **outStream) @@ -246,7 +253,7 @@ void COutArchive::CreateStreamForCompressing(IOutStream **outStream) void COutArchive::SeekToPackedDataPosition() { - m_Stream->Seek(m_BasePosition + m_LocalFileHeaderSize, STREAM_SEEK_SET, NULL); + SeekTo(m_BasePosition + m_LocalFileHeaderSize); } void COutArchive::CreateStreamForCopying(ISequentialOutStream **outStream) diff --git a/CPP/7zip/Archive/Zip/ZipOut.h b/CPP/7zip/Archive/Zip/ZipOut.h index e08c306e..24bc83a1 100755 --- a/CPP/7zip/Archive/Zip/ZipOut.h +++ b/CPP/7zip/Archive/Zip/ZipOut.h @@ -6,15 +6,19 @@ #include "Common/MyCom.h" #include "../../IStream.h" +#include "../../Common/OutBuffer.h" #include "ZipItem.h" namespace NArchive { namespace NZip { +// can throw CSystemException and COutBufferException + class COutArchive { CMyComPtr m_Stream; + COutBuffer m_OutBuffer; UInt64 m_BasePosition; UInt32 m_LocalFileHeaderSize; @@ -30,6 +34,7 @@ class COutArchive void WriteExtraHeader(const CItem &item); void WriteCentralHeader(const CItem &item); void WriteExtra(const CExtraBlock &extra); + void SeekTo(UInt64 offset); public: void Create(IOutStream *outStream); void MoveBasePosition(UInt64 distanceToMove); @@ -37,7 +42,7 @@ public: 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 WriteLocalHeader(const CLocalItem &item); void WriteCentralDir(const CObjectVector &items, const CByteBuffer &comment); diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp index 8caa1409..27284953 100755 --- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp +++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp @@ -282,12 +282,12 @@ static HRESULT UpdateItemOldData(COutArchive &archive, return S_OK; } -static HRESULT WriteDirHeader(COutArchive &archive, const CCompressionMethodMode *options, +static void WriteDirHeader(COutArchive &archive, const CCompressionMethodMode *options, const CUpdateItem &updateItem, CItemEx &item) { SetFileHeader(archive, *options, updateItem, item); archive.PrepareWriteCompressedData((UInt16)item.Name.Length(), updateItem.Size, options->IsAesMode); - return archive.WriteLocalHeader(item); + archive.WriteLocalHeader(item); } static HRESULT Update2St( @@ -330,7 +330,7 @@ static HRESULT Update2St( bool isDirectory = ((updateItem.NewProperties) ? updateItem.IsDirectory : item.IsDirectory()); if (isDirectory) { - RINOK(WriteDirHeader(archive, options, updateItem, item)); + WriteDirHeader(archive, options, updateItem, item); } else { @@ -355,7 +355,7 @@ static HRESULT Update2St( EXTERNAL_CODECS_LOC_VARS fileInStream, outStream, compressProgress, compressingResult)); SetItemInfoFromCompressingResult(compressingResult, options->IsAesMode, options->AesKeyMode, item); - RINOK(archive.WriteLocalHeader(item)); + archive.WriteLocalHeader(item); RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); complexity += item.UnPackSize; } @@ -611,7 +611,7 @@ static HRESULT Update2( bool isDirectory = ((updateItem.NewProperties) ? updateItem.IsDirectory : item.IsDirectory()); if (isDirectory) { - RINOK(WriteDirHeader(archive, options, updateItem, item)); + WriteDirHeader(archive, options, updateItem, item); } else { @@ -632,7 +632,7 @@ static HRESULT Update2( SetItemInfoFromCompressingResult(memRef.CompressingResult, options->IsAesMode, options->AesKeyMode, item); SetFileHeader(archive, *options, updateItem, item); - RINOK(archive.WriteLocalHeader(item)); + archive.WriteLocalHeader(item); complexity += item.UnPackSize; // RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); memRef.FreeOpt(&memManager); @@ -666,7 +666,7 @@ static HRESULT Update2( SetItemInfoFromCompressingResult(threadInfo.CompressingResult, options->IsAesMode, options->AesKeyMode, item); SetFileHeader(archive, *options, updateItem, item); - RINOK(archive.WriteLocalHeader(item)); + archive.WriteLocalHeader(item); complexity += item.UnPackSize; } else diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.h b/CPP/7zip/Archive/Zip/ZipUpdate.h index 8b03cfa3..168eedd6 100755 --- a/CPP/7zip/Archive/Zip/ZipUpdate.h +++ b/CPP/7zip/Archive/Zip/ZipUpdate.h @@ -3,9 +3,6 @@ #ifndef __ZIP_UPDATE_H #define __ZIP_UPDATE_H -#include "Common/Vector.h" -#include "Common/Types.h" - #include "../../ICoder.h" #include "../IArchive.h" diff --git a/CPP/7zip/Bundles/Alone/Alone.dsp b/CPP/7zip/Bundles/Alone/Alone.dsp index f7ceb6b8..6250c0bd 100755 --- a/CPP/7zip/Bundles/Alone/Alone.dsp +++ b/CPP/7zip/Bundles/Alone/Alone.dsp @@ -237,14 +237,6 @@ SOURCE=.\StdAfx.h # 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\AutoPtr.h # End Source File # Begin Source File @@ -277,10 +269,6 @@ 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 @@ -301,6 +289,10 @@ SOURCE=..\..\..\Common\MyCom.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\MyException.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyGuidDef.h # End Source File # Begin Source File @@ -309,10 +301,26 @@ SOURCE=..\..\..\Common\MyInitGuid.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\MyString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyString.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyUnknown.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\MyVector.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyVector.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyWindows.cpp # End Source File # Begin Source File @@ -353,14 +361,6 @@ 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 @@ -389,14 +389,6 @@ 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 @@ -501,6 +493,14 @@ SOURCE=..\..\..\Windows\Synchronization.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\System.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Thread.h # End Source File # Begin Source File @@ -613,6 +613,14 @@ SOURCE=..\..\Common\MethodId.h # End Source File # Begin Source File +SOURCE=..\..\Common\MethodProps.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MethodProps.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\MSBFDecoder.h # End Source File # Begin Source File @@ -683,6 +691,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "Compress" @@ -1705,19 +1721,19 @@ SOURCE=..\..\Archive\Common\CoderMixer2MT.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CoderMixer2ST.cpp +SOURCE=..\..\Archive\Common\DummyOutStream.cpp # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CoderMixer2ST.h +SOURCE=..\..\Archive\Common\DummyOutStream.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\DummyOutStream.cpp +SOURCE=..\..\Archive\Common\HandlerOut.cpp # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\DummyOutStream.h +SOURCE=..\..\Archive\Common\HandlerOut.h # End Source File # Begin Source File diff --git a/CPP/7zip/Bundles/Alone/makefile b/CPP/7zip/Bundles/Alone/makefile index eeec13a2..ee881a01 100755 --- a/CPP/7zip/Bundles/Alone/makefile +++ b/CPP/7zip/Bundles/Alone/makefile @@ -29,11 +29,11 @@ COMMON_OBJS = \ $O\NewHandler.obj \ $O\StdInStream.obj \ $O\StdOutStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -46,7 +46,8 @@ WIN_OBJS = \ $O\MemoryLock.obj \ $O\PropVariant.obj \ $O\PropVariantConversions.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -61,6 +62,7 @@ WIN_OBJS = \ $O\LSBFEncoder.obj \ $O\MemBlocks.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\OffsetStream.obj \ $O\OutBuffer.obj \ $O\OutMemStream.obj \ @@ -69,6 +71,7 @@ WIN_OBJS = \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ UI_COMMON_OBJS = \ $O\ArchiveCommandLine.obj \ @@ -96,6 +99,7 @@ AR_COMMON_OBJS = \ $O\CoderMixer2MT.obj \ $O\CrossThreadProgress.obj \ $O\DummyOutStream.obj \ + $O\HandlerOut.obj \ $O\InStreamWithCRC.obj \ $O\ItemNameUtils.obj \ $O\MultiStream.obj \ diff --git a/CPP/7zip/Bundles/Alone7z/Alone.dsp b/CPP/7zip/Bundles/Alone7z/Alone.dsp index e0c46273..b9f389bb 100755 --- a/CPP/7zip/Bundles/Alone7z/Alone.dsp +++ b/CPP/7zip/Bundles/Alone7z/Alone.dsp @@ -237,14 +237,6 @@ SOURCE=.\StdAfx.h # 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\AutoPtr.h # End Source File # Begin Source File @@ -277,10 +269,6 @@ 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 @@ -301,6 +289,10 @@ SOURCE=..\..\..\Common\MyCom.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\MyException.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyGuidDef.h # End Source File # Begin Source File @@ -309,10 +301,26 @@ SOURCE=..\..\..\Common\MyInitGuid.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\MyString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyString.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyUnknown.h # End Source File # Begin Source File +SOURCE=..\..\..\Common\MyVector.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\MyVector.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Common\MyWindows.cpp # End Source File # Begin Source File @@ -353,14 +361,6 @@ 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 @@ -389,14 +389,6 @@ 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 @@ -501,6 +493,14 @@ SOURCE=..\..\..\Windows\Synchronization.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\System.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Thread.h # End Source File # Begin Source File @@ -609,6 +609,14 @@ SOURCE=..\..\Common\MethodId.h # End Source File # Begin Source File +SOURCE=..\..\Common\MethodProps.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MethodProps.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\MSBFDecoder.h # End Source File # Begin Source File @@ -679,6 +687,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "Compress" @@ -1054,19 +1070,19 @@ SOURCE=..\..\Archive\Common\CoderMixer2MT.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CoderMixer2ST.cpp +SOURCE=..\..\Archive\Common\DummyOutStream.cpp # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CoderMixer2ST.h +SOURCE=..\..\Archive\Common\DummyOutStream.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\DummyOutStream.cpp +SOURCE=..\..\Archive\Common\HandlerOut.cpp # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\DummyOutStream.h +SOURCE=..\..\Archive\Common\HandlerOut.h # End Source File # Begin Source File @@ -1199,6 +1215,10 @@ SOURCE=..\..\UI\Common\OpenArchive.h # End Source File # Begin Source File +SOURCE=..\..\UI\Common\Property.h +# End Source File +# Begin Source File + SOURCE=..\..\UI\Common\PropIDUtils.cpp # End Source File # Begin Source File diff --git a/CPP/7zip/Bundles/Alone7z/makefile b/CPP/7zip/Bundles/Alone7z/makefile index 4ae28d39..1feb1fbd 100755 --- a/CPP/7zip/Bundles/Alone7z/makefile +++ b/CPP/7zip/Bundles/Alone7z/makefile @@ -30,11 +30,11 @@ COMMON_OBJS = \ $O\NewHandler.obj \ $O\StdInStream.obj \ $O\StdOutStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -47,7 +47,8 @@ WIN_OBJS = \ $O\MemoryLock.obj \ $O\PropVariant.obj \ $O\PropVariantConversions.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -59,12 +60,14 @@ WIN_OBJS = \ $O\LimitedStreams.obj \ $O\LockedStream.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\OffsetStream.obj \ $O\OutBuffer.obj \ $O\ProgressUtils.obj \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ UI_COMMON_OBJS = \ $O\ArchiveCommandLine.obj \ @@ -92,6 +95,7 @@ AR_COMMON_OBJS = \ $O\CoderMixer2MT.obj \ $O\CrossThreadProgress.obj \ $O\DummyOutStream.obj \ + $O\HandlerOut.obj \ $O\InStreamWithCRC.obj \ $O\ItemNameUtils.obj \ $O\MultiStream.obj \ diff --git a/CPP/7zip/Bundles/Format7z/makefile b/CPP/7zip/Bundles/Format7z/makefile index f74602ae..e690dd3a 100755 --- a/CPP/7zip/Bundles/Format7z/makefile +++ b/CPP/7zip/Bundles/Format7z/makefile @@ -12,10 +12,10 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -23,7 +23,8 @@ WIN_OBJS = \ $O\FileFind.obj \ $O\FileIO.obj \ $O\PropVariant.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -34,11 +35,13 @@ WIN_OBJS = \ $O\LockedStream.obj \ $O\LSBFDecoder.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\OutBuffer.obj \ $O\ProgressUtils.obj \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ AR_OBJS = \ $O\ArchiveExports.obj \ @@ -48,6 +51,7 @@ AR_COMMON_OBJS = \ $O\CoderMixer2.obj \ $O\CoderMixer2MT.obj \ $O\CrossThreadProgress.obj \ + $O\HandlerOut.obj \ $O\InStreamWithCRC.obj \ $O\ItemNameUtils.obj \ $O\OutStreamWithCRC.obj \ @@ -134,6 +138,8 @@ AES_ORIG_OBJS = \ $O\aestab.obj \ CRYPTO_HASH_OBJS = \ + $O\RandGen.obj \ + $O\Sha1.obj \ $O\Sha256.obj \ C_OBJS = \ diff --git a/CPP/7zip/Bundles/Format7zExtract/makefile b/CPP/7zip/Bundles/Format7zExtract/makefile index 5926949f..a2362869 100755 --- a/CPP/7zip/Bundles/Format7zExtract/makefile +++ b/CPP/7zip/Bundles/Format7zExtract/makefile @@ -10,10 +10,10 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -21,7 +21,8 @@ WIN_OBJS = \ $O\FileFind.obj \ $O\FileIO.obj \ $O\PropVariant.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -37,6 +38,7 @@ WIN_OBJS = \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ AR_OBJS = \ $O\ArchiveExports.obj \ diff --git a/CPP/7zip/Bundles/Format7zExtractR/makefile b/CPP/7zip/Bundles/Format7zExtractR/makefile index e2c1b838..0632e718 100755 --- a/CPP/7zip/Bundles/Format7zExtractR/makefile +++ b/CPP/7zip/Bundles/Format7zExtractR/makefile @@ -10,10 +10,10 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -21,7 +21,8 @@ WIN_OBJS = \ $O\FileFind.obj \ $O\FileIO.obj \ $O\PropVariant.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -31,11 +32,13 @@ WIN_OBJS = \ $O\LimitedStreams.obj \ $O\LockedStream.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\OutBuffer.obj \ $O\ProgressUtils.obj \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ AR_OBJS = \ $O\ArchiveExports.obj \ @@ -45,6 +48,7 @@ AR_COMMON_OBJS = \ $O\CoderMixer2.obj \ $O\CoderMixer2MT.obj \ $O\CrossThreadProgress.obj \ + $O\HandlerOut.obj \ $O\ItemNameUtils.obj \ $O\OutStreamWithCRC.obj \ $O\ParseProperties.obj \ diff --git a/CPP/7zip/Bundles/Format7zF/Format7z.dsp b/CPP/7zip/Bundles/Format7zF/Format7z.dsp index 7a4bafb2..66ae5d92 100755 --- a/CPP/7zip/Bundles/Format7zF/Format7z.dsp +++ b/CPP/7zip/Bundles/Format7zF/Format7z.dsp @@ -142,47 +142,51 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyException.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringToInt.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringToInt.h +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\UTFConvert.cpp +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\UTFConvert.h +SOURCE=..\..\..\Common\StringToInt.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StringToInt.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\UTFConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\UTFConvert.h # End Source File # Begin Source File @@ -238,6 +242,14 @@ SOURCE=..\..\..\Windows\Synchronization.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\System.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Thread.h # End Source File # End Group @@ -1160,6 +1172,14 @@ SOURCE=..\..\Common\MethodId.h # End Source File # Begin Source File +SOURCE=..\..\Common\MethodProps.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MethodProps.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\OffsetStream.cpp # End Source File # Begin Source File @@ -1230,6 +1250,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "C" @@ -1411,7 +1439,7 @@ SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c !IF "$(CFG)" == "7z - Win32 Release" -# ADD CPP /O2 +# ADD CPP /O2 /FAs # SUBTRACT CPP /YX /Yc /Yu !ELSEIF "$(CFG)" == "7z - Win32 Debug" @@ -1826,19 +1854,19 @@ SOURCE=..\..\Archive\Common\CoderMixer2MT.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CrossThreadProgress.cpp +SOURCE=..\..\Archive\Common\DummyOutStream.cpp # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\CrossThreadProgress.h +SOURCE=..\..\Archive\Common\DummyOutStream.h # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\DummyOutStream.cpp +SOURCE=..\..\Archive\Common\HandlerOut.cpp # End Source File # Begin Source File -SOURCE=..\..\Archive\Common\DummyOutStream.h +SOURCE=..\..\Archive\Common\HandlerOut.h # End Source File # Begin Source File diff --git a/CPP/7zip/Bundles/Format7zF/makefile b/CPP/7zip/Bundles/Format7zF/makefile index 52554f24..d3e9d8c7 100755 --- a/CPP/7zip/Bundles/Format7zF/makefile +++ b/CPP/7zip/Bundles/Format7zF/makefile @@ -12,10 +12,10 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\UTFConvert.obj \ $O\Wildcard.obj \ @@ -24,7 +24,8 @@ WIN_OBJS = \ $O\FileFind.obj \ $O\FileIO.obj \ $O\PropVariant.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\InBuffer.obj \ @@ -36,6 +37,7 @@ WIN_OBJS = \ $O\LSBFDecoder.obj \ $O\LSBFEncoder.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\MemBlocks.obj \ $O\OffsetStream.obj \ $O\OutBuffer.obj \ @@ -45,6 +47,7 @@ WIN_OBJS = \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ AR_OBJS = \ $O\ArchiveExports.obj \ @@ -59,6 +62,7 @@ AR_COMMON_OBJS = \ $O\ItemNameUtils.obj \ $O\MultiStream.obj \ $O\OutStreamWithCRC.obj \ + $O\HandlerOut.obj \ $O\ParseProperties.obj \ diff --git a/CPP/7zip/Bundles/Format7zR/makefile b/CPP/7zip/Bundles/Format7zR/makefile index 3175e7f2..972c6eb1 100755 --- a/CPP/7zip/Bundles/Format7zR/makefile +++ b/CPP/7zip/Bundles/Format7zR/makefile @@ -10,10 +10,10 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -21,7 +21,8 @@ WIN_OBJS = \ $O\FileFind.obj \ $O\FileIO.obj \ $O\PropVariant.obj \ - $O\Synchronization.obj + $O\Synchronization.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\CreateCoder.obj \ @@ -31,11 +32,13 @@ WIN_OBJS = \ $O\LimitedStreams.obj \ $O\LockedStream.obj \ $O\MethodId.obj \ + $O\MethodProps.obj \ $O\OutBuffer.obj \ $O\ProgressUtils.obj \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ AR_OBJS = \ $O\ArchiveExports.obj \ @@ -45,6 +48,7 @@ AR_COMMON_OBJS = \ $O\CoderMixer2.obj \ $O\CoderMixer2MT.obj \ $O\CrossThreadProgress.obj \ + $O\HandlerOut.obj \ $O\InStreamWithCRC.obj \ $O\ItemNameUtils.obj \ $O\OutStreamWithCRC.obj \ diff --git a/CPP/7zip/Bundles/SFXCon/Main.cpp b/CPP/7zip/Bundles/SFXCon/Main.cpp index c3122cd1..9084d9d7 100755 --- a/CPP/7zip/Bundles/SFXCon/Main.cpp +++ b/CPP/7zip/Bundles/SFXCon/Main.cpp @@ -9,7 +9,7 @@ #include "Common/Wildcard.h" #include "Common/StringConvert.h" #include "Common/MyCom.h" -#include "Common/Exception.h" +#include "Common/MyException.h" #include "Windows/FileDir.h" #include "Windows/FileName.h" diff --git a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp index abf7f22c..163b9298 100755 --- a/CPP/7zip/Bundles/SFXCon/SFXCon.dsp +++ b/CPP/7zip/Bundles/SFXCon/SFXCon.dsp @@ -512,51 +512,51 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdOutStream.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdOutStream.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\StdInStream.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\StdInStream.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\StdOutStream.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\StdOutStream.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File @@ -674,6 +674,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "UI" diff --git a/CPP/7zip/Bundles/SFXCon/makefile b/CPP/7zip/Bundles/SFXCon/makefile index 33bd52c4..b6c13088 100755 --- a/CPP/7zip/Bundles/SFXCon/makefile +++ b/CPP/7zip/Bundles/SFXCon/makefile @@ -23,9 +23,9 @@ COMMON_OBJS = \ $O\NewHandler.obj \ $O\StdInStream.obj \ $O\StdOutStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -51,6 +51,7 @@ WIN_OBJS = \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ UI_COMMON_OBJS = \ $O\ArchiveExtractCallback.obj \ diff --git a/CPP/7zip/Bundles/SFXSetup/ExtractCallback.h b/CPP/7zip/Bundles/SFXSetup/ExtractCallback.h index f3880890..b85dce42 100755 --- a/CPP/7zip/Bundles/SFXSetup/ExtractCallback.h +++ b/CPP/7zip/Bundles/SFXSetup/ExtractCallback.h @@ -5,7 +5,6 @@ #include "resource.h" -#include "Common/String.h" #include "Windows/ResourceString.h" #include "../../Archive/IArchive.h" diff --git a/CPP/7zip/Bundles/SFXSetup/ExtractEngine.h b/CPP/7zip/Bundles/SFXSetup/ExtractEngine.h index a042270b..e2f7518b 100755 --- a/CPP/7zip/Bundles/SFXSetup/ExtractEngine.h +++ b/CPP/7zip/Bundles/SFXSetup/ExtractEngine.h @@ -3,7 +3,6 @@ #ifndef __EXTRACTENGINE_H #define __EXTRACTENGINE_H -#include "Common/String.h" #include "../../UI/GUI/OpenCallbackGUI.h" #include "../../UI/Common/LoadCodecs.h" diff --git a/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp b/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp index b09dce22..528275fd 100755 --- a/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp +++ b/CPP/7zip/Bundles/SFXSetup/SFXSetup.dsp @@ -341,51 +341,51 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\TextConfig.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\TextConfig.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\UTFConvert.cpp +SOURCE=..\..\..\Common\TextConfig.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\UTFConvert.h +SOURCE=..\..\..\Common\TextConfig.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\UTFConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\UTFConvert.h # End Source File # Begin Source File @@ -583,6 +583,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "UI" diff --git a/CPP/7zip/Bundles/SFXSetup/makefile b/CPP/7zip/Bundles/SFXSetup/makefile index a93d0379..e773ba41 100755 --- a/CPP/7zip/Bundles/SFXSetup/makefile +++ b/CPP/7zip/Bundles/SFXSetup/makefile @@ -20,11 +20,11 @@ COMMON_OBJS = \ $O\CRC.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\TextConfig.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -54,6 +54,7 @@ WIN_CTRL_OBJS = \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ UI_COMMON_OBJS = \ $O\ArchiveOpenCallback.obj \ diff --git a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp index 06c0020e..23bdf2de 100755 --- a/CPP/7zip/Bundles/SFXWin/SFXWin.dsp +++ b/CPP/7zip/Bundles/SFXWin/SFXWin.dsp @@ -550,6 +550,14 @@ SOURCE=..\..\Common\StreamUtils.cpp SOURCE=..\..\Common\StreamUtils.h # End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\VirtThread.h +# End Source File # End Group # Begin Group "File Manager" @@ -712,35 +720,35 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File diff --git a/CPP/7zip/Bundles/SFXWin/makefile b/CPP/7zip/Bundles/SFXWin/makefile index a7e52be2..aab98921 100755 --- a/CPP/7zip/Bundles/SFXWin/makefile +++ b/CPP/7zip/Bundles/SFXWin/makefile @@ -19,9 +19,9 @@ COMMON_OBJS = \ $O\CommandLineParser.obj \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -54,6 +54,7 @@ WIN_CTRL_OBJS = \ $O\StreamBinder.obj \ $O\StreamObjects.obj \ $O\StreamUtils.obj \ + $O\VirtThread.obj \ UI_COMMON_OBJS = \ $O\ArchiveExtractCallback.obj \ diff --git a/CPP/7zip/Common/CreateCoder.h b/CPP/7zip/Common/CreateCoder.h index 9b2f3869..49f1552a 100755 --- a/CPP/7zip/Common/CreateCoder.h +++ b/CPP/7zip/Common/CreateCoder.h @@ -4,7 +4,7 @@ #define __CREATECODER_H #include "Common/MyCom.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "../ICoder.h" #include "MethodId.h" diff --git a/CPP/7zip/Common/FilePathAutoRename.h b/CPP/7zip/Common/FilePathAutoRename.h index 99323094..3ef87f48 100755 --- a/CPP/7zip/Common/FilePathAutoRename.h +++ b/CPP/7zip/Common/FilePathAutoRename.h @@ -3,7 +3,7 @@ #ifndef __FILEPATHAUTORENAME_H #define __FILEPATHAUTORENAME_H -#include "Common/String.h" +#include "Common/MyString.h" bool AutoRenamePath(UString &fullProcessedPath); diff --git a/CPP/7zip/Common/FilterCoder.cpp b/CPP/7zip/Common/FilterCoder.cpp index 9b019c7d..76d022d2 100755 --- a/CPP/7zip/Common/FilterCoder.cpp +++ b/CPP/7zip/Common/FilterCoder.cpp @@ -238,6 +238,18 @@ STDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream) { return _writeCoderProperties->WriteCoderProperties(outStream); } + +/* +STDMETHODIMP CFilterCoder::ResetSalt() +{ + return _CryptoResetSalt->ResetSalt(); +} +*/ + +STDMETHODIMP CFilterCoder::ResetInitVector() +{ + return _CryptoResetInitVector->ResetInitVector(); +} #endif STDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size) diff --git a/CPP/7zip/Common/FilterCoder.h b/CPP/7zip/Common/FilterCoder.h index 36334364..1b9b29de 100755 --- a/CPP/7zip/Common/FilterCoder.h +++ b/CPP/7zip/Common/FilterCoder.h @@ -26,6 +26,8 @@ class CFilterCoder: #endif #ifndef EXTRACT_ONLY public ICompressWriteCoderProperties, + // public ICryptoResetSalt, + public ICryptoResetInitVector, #endif public ICompressSetDecoderProperties2, public CMyUnknownImp @@ -53,6 +55,8 @@ protected: CMyComPtr _setPassword; #ifndef EXTRACT_ONLY CMyComPtr _writeCoderProperties; + // CMyComPtr _CryptoResetSalt; + CMyComPtr _CryptoResetInitVector; #endif CMyComPtr _setDecoderProperties; public: @@ -82,6 +86,8 @@ public: #ifndef EXTRACT_ONLY MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties) + // MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetSalt, Filter, _CryptoResetSalt) + MY_QUERYINTERFACE_ENTRY_AG(ICryptoResetInitVector, Filter, _CryptoResetInitVector) #endif MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties) @@ -105,6 +111,8 @@ public: #endif #ifndef EXTRACT_ONLY STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); + // STDMETHOD(ResetSalt)(); + STDMETHOD(ResetInitVector)(); #endif STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); }; diff --git a/CPP/7zip/Common/InBuffer.h b/CPP/7zip/Common/InBuffer.h index 057caa16..05fc77e5 100755 --- a/CPP/7zip/Common/InBuffer.h +++ b/CPP/7zip/Common/InBuffer.h @@ -5,13 +5,12 @@ #include "../IStream.h" #include "../../Common/MyCom.h" +#include "../../Common/MyException.h" #ifndef _NO_EXCEPTIONS -class CInBufferException +struct CInBufferException: public CSystemException { -public: - HRESULT ErrorCode; - CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {} + CInBufferException(HRESULT errorCode): CSystemException(errorCode) {} }; #endif diff --git a/CPP/7zip/Common/MemBlocks.h b/CPP/7zip/Common/MemBlocks.h index b93f6398..de7138ed 100755 --- a/CPP/7zip/Common/MemBlocks.h +++ b/CPP/7zip/Common/MemBlocks.h @@ -9,7 +9,7 @@ extern "C" } #include "Common/Types.h" -#include "Common/Vector.h" +#include "Common/MyVector.h" #include "Windows/Synchronization.h" diff --git a/CPP/7zip/Common/MethodId.cpp b/CPP/7zip/Common/MethodId.cpp index 1eed8fc1..b797b685 100755 --- a/CPP/7zip/Common/MethodId.cpp +++ b/CPP/7zip/Common/MethodId.cpp @@ -3,7 +3,7 @@ #include "StdAfx.h" #include "MethodId.h" -#include "../../Common/String.h" +#include "../../Common/MyString.h" static inline wchar_t GetHex(Byte value) { diff --git a/CPP/7zip/Common/MethodProps.cpp b/CPP/7zip/Common/MethodProps.cpp new file mode 100755 index 00000000..52f5511f --- /dev/null +++ b/CPP/7zip/Common/MethodProps.cpp @@ -0,0 +1,96 @@ +// MethodProps.cpp + +#include "StdAfx.h" + +#include "MethodProps.h" +#include "../../Common/MyCom.h" + +static UInt64 k_LZMA = 0x030101; +// static UInt64 k_LZMA2 = 0x030102; + +HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder) +{ + bool tryReduce = false; + UInt32 reducedDictionarySize = 1 << 10; + if (inSizeForReduce != 0 && (method.Id == k_LZMA /* || methodFull.MethodID == k_LZMA2 */)) + { + for (;;) + { + const UInt32 step = (reducedDictionarySize >> 1); + if (reducedDictionarySize >= *inSizeForReduce) + { + tryReduce = true; + break; + } + reducedDictionarySize += step; + if (reducedDictionarySize >= *inSizeForReduce) + { + tryReduce = true; + break; + } + if (reducedDictionarySize >= ((UInt32)3 << 30)) + break; + reducedDictionarySize += step; + } + } + + { + int numProperties = method.Properties.Size(); + CMyComPtr setCoderProperties; + coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); + if (setCoderProperties == NULL) + { + if (numProperties != 0) + return E_INVALIDARG; + } + else + { + CRecordVector propIDs; + NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties]; + HRESULT res = S_OK; + try + { + for (int i = 0; i < numProperties; i++) + { + const CProp &prop = method.Properties[i]; + propIDs.Add(prop.Id); + NWindows::NCOM::CPropVariant &value = values[i]; + value = prop.Value; + // if (tryReduce && prop.Id == NCoderPropID::kDictionarySize && value.vt == VT_UI4 && reducedDictionarySize < value.ulVal) + if (tryReduce) + if (prop.Id == NCoderPropID::kDictionarySize) + if (value.vt == VT_UI4) + if (reducedDictionarySize < value.ulVal) + value.ulVal = reducedDictionarySize; + } + CMyComPtr setCoderProperties; + coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties); + res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties); + } + catch(...) + { + delete []values; + throw; + } + delete []values; + RINOK(res); + } + } + + /* + CMyComPtr writeCoderProperties; + coder->QueryInterface(IID_ICompressWriteCoderProperties, (void **)&writeCoderProperties); + if (writeCoderProperties != NULL) + { + CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp; + CMyComPtr outStream(outStreamSpec); + outStreamSpec->Init(); + RINOK(writeCoderProperties->WriteCoderProperties(outStream)); + size_t size = outStreamSpec->GetSize(); + filterProps.SetCapacity(size); + memmove(filterProps, outStreamSpec->GetBuffer(), size); + } + */ + return S_OK; +} + diff --git a/CPP/7zip/Common/MethodProps.h b/CPP/7zip/Common/MethodProps.h new file mode 100755 index 00000000..7ffa8e4a --- /dev/null +++ b/CPP/7zip/Common/MethodProps.h @@ -0,0 +1,41 @@ +// MethodProps.h + +#ifndef __7Z_METHOD_PROPS_H +#define __7Z_METHOD_PROPS_H + +#include "MethodId.h" + +#include "../../Windows/PropVariant.h" +#include "../../Common/MyVector.h" +#include "../ICoder.h" + +struct CProp +{ + PROPID Id; + NWindows::NCOM::CPropVariant Value; +}; + +struct CMethod +{ + CMethodId Id; + CObjectVector Properties; +}; + +struct CMethodsMode +{ + CObjectVector Methods; + #ifdef COMPRESS_MT + UInt32 NumThreads; + #endif + + CMethodsMode() + #ifdef COMPRESS_MT + : NumThreads(1) + #endif + {} + bool IsEmpty() const { return Methods.IsEmpty() ; } +}; + +HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce, IUnknown *coder); + +#endif diff --git a/CPP/7zip/Common/OutBuffer.h b/CPP/7zip/Common/OutBuffer.h index 0ce54e21..e99dbf2a 100755 --- a/CPP/7zip/Common/OutBuffer.h +++ b/CPP/7zip/Common/OutBuffer.h @@ -5,12 +5,12 @@ #include "../IStream.h" #include "../../Common/MyCom.h" +#include "../../Common/MyException.h" #ifndef _NO_EXCEPTIONS -struct COutBufferException -{ - HRESULT ErrorCode; - COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {} +struct COutBufferException: public CSystemException +{ + COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} }; #endif @@ -28,7 +28,6 @@ protected: bool _overDict; HRESULT FlushPart(); - void FlushWithCheck(); public: #ifdef _NO_EXCEPTIONS HRESULT ErrorCode; @@ -44,6 +43,7 @@ public: void SetStream(ISequentialOutStream *stream); void Init(); HRESULT Flush(); + void FlushWithCheck(); void ReleaseStream() { _stream.Release(); } void WriteByte(Byte b) diff --git a/CPP/7zip/Common/ProgressMt.h b/CPP/7zip/Common/ProgressMt.h index c0776944..e57f1167 100755 --- a/CPP/7zip/Common/ProgressMt.h +++ b/CPP/7zip/Common/ProgressMt.h @@ -4,13 +4,12 @@ #define __PROGRESSMT_H #include "../../Common/MyCom.h" +#include "../../Common/MyVector.h" +#include "../../Windows/Synchronization.h" #include "../ICoder.h" #include "../IProgress.h" -#include "Windows/Synchronization.h" -#include "../../Common/Vector.h" - class CMtCompressProgressMixer { CMyComPtr _progress; diff --git a/CPP/7zip/Common/VirtThread.cpp b/CPP/7zip/Common/VirtThread.cpp new file mode 100755 index 00000000..3567f98e --- /dev/null +++ b/CPP/7zip/Common/VirtThread.cpp @@ -0,0 +1,45 @@ +// VirtThread.cpp + +#include "StdAfx.h" + +#include "VirtThread.h" + +static THREAD_FUNC_DECL CoderThread(void *p) +{ + for (;;) + { + CVirtThread *t = (CVirtThread *)p; + t->StartEvent.Lock(); + if (t->ExitEvent) + return 0; + t->Execute(); + t->FinishedEvent.Set(); + } +} + +HRes CVirtThread::Create() +{ + RINOK(StartEvent.CreateIfNotCreated()); + RINOK(FinishedEvent.CreateIfNotCreated()); + StartEvent.Reset(); + FinishedEvent.Reset(); + ExitEvent = false; + if (Thread.IsCreated()) + return S_OK; + return Thread.Create(CoderThread, this); +} + +void CVirtThread::Start() +{ + ExitEvent = false; + StartEvent.Set(); +} + +CVirtThread::~CVirtThread() +{ + ExitEvent = true; + if (StartEvent.IsCreated()) + StartEvent.Set(); + Thread.Wait(); +} + diff --git a/CPP/7zip/Common/VirtThread.h b/CPP/7zip/Common/VirtThread.h new file mode 100755 index 00000000..62c055b6 --- /dev/null +++ b/CPP/7zip/Common/VirtThread.h @@ -0,0 +1,23 @@ +// VirtThread.h + +#ifndef __VIRTTHREAD_H +#define __VIRTTHREAD_H + +#include "../../Windows/Synchronization.h" +#include "../../Windows/Thread.h" + +struct CVirtThread +{ + NWindows::NSynchronization::CAutoResetEvent StartEvent; + NWindows::NSynchronization::CAutoResetEvent FinishedEvent; + NWindows::CThread Thread; + bool ExitEvent; + + ~CVirtThread(); + HRes Create(); + void Start(); + void WaitFinish() { FinishedEvent.Lock(); } + virtual void Execute() = 0; +}; + +#endif diff --git a/CPP/7zip/Compress/Branch/BCJ2Register.cpp b/CPP/7zip/Compress/Branch/BCJ2Register.cpp index 24855dd7..88ebbac6 100755 --- a/CPP/7zip/Compress/Branch/BCJ2Register.cpp +++ b/CPP/7zip/Compress/Branch/BCJ2Register.cpp @@ -5,9 +5,9 @@ #include "../../Common/RegisterCodec.h" #include "x86_2.h" -static void *CreateCodec() { return (void *)(ICompressCoder2 *)(new CBCJ2_x86_Decoder()); } +static void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); } #ifndef EXTRACT_ONLY -static void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new CBCJ2_x86_Encoder()); } +static void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder()); } #else #define CreateCodecOut 0 #endif diff --git a/CPP/7zip/Compress/Branch/x86.cpp b/CPP/7zip/Compress/Branch/x86.cpp index c4d11a75..79d49657 100755 --- a/CPP/7zip/Compress/Branch/x86.cpp +++ b/CPP/7zip/Compress/Branch/x86.cpp @@ -5,10 +5,10 @@ UInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size) { - return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 1); + return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1); } UInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size) { - return ::x86_Convert(data, size, _bufferPos, &_prevMask, &_prevPos, 0); + return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0); } diff --git a/CPP/7zip/Compress/Branch/x86.h b/CPP/7zip/Compress/Branch/x86.h index 39ba5ae5..58176600 100755 --- a/CPP/7zip/Compress/Branch/x86.h +++ b/CPP/7zip/Compress/Branch/x86.h @@ -12,8 +12,7 @@ extern "C" struct CBranch86 { UInt32 _prevMask; - UInt32 _prevPos; - void x86Init() { x86_Convert_Init(_prevMask, _prevPos); } + void x86Init() { x86_Convert_Init(_prevMask); } }; MyClassB(BCJ_x86, 0x01, 3, CBranch86 , diff --git a/CPP/7zip/Compress/Branch/x86_2.cpp b/CPP/7zip/Compress/Branch/x86_2.cpp index 178587b6..61f0c55a 100755 --- a/CPP/7zip/Compress/Branch/x86_2.cpp +++ b/CPP/7zip/Compress/Branch/x86_2.cpp @@ -8,10 +8,12 @@ extern "C" #include "../../../../C/Alloc.h" } -inline bool IsJcc(Byte b0, Byte b1) -{ - return (b0 == 0x0F && (b1 & 0xF0) == 0x80); -} +namespace NCompress { +namespace NBcj2 { + +inline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); } +inline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); } +inline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); } #ifndef EXTRACT_ONLY @@ -22,7 +24,7 @@ static bool inline Test86MSByte(Byte b) return (b == 0 || b == 0xFF); } -bool CBCJ2_x86_Encoder::Create() +bool CEncoder::Create() { if (!_mainStream.Create(1 << 16)) return false; @@ -41,12 +43,12 @@ bool CBCJ2_x86_Encoder::Create() return true; } -CBCJ2_x86_Encoder::~CBCJ2_x86_Encoder() +CEncoder::~CEncoder() { ::MidFree(_buffer); } -HRESULT CBCJ2_x86_Encoder::Flush() +HRESULT CEncoder::Flush() { RINOK(_mainStream.Flush()); RINOK(_callStream.Flush()); @@ -57,7 +59,7 @@ HRESULT CBCJ2_x86_Encoder::Flush() const UInt32 kDefaultLimit = (1 << 24); -HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, +HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams, ISequentialOutStream **outStreams, @@ -91,10 +93,8 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, _jumpStream.Init(); _rangeEncoder.SetStream(outStreams[3]); _rangeEncoder.Init(); - for (int i = 0; i < 256; i++) - _statusE8Encoder[i].Init(); - _statusE9Encoder.Init(); - _statusJccEncoder.Init(); + for (int i = 0; i < 256 + 2; i++) + _statusEncoder[i].Init(); CCoderReleaser releaser(this); CMyComPtr getSubStreamSize; @@ -135,12 +135,19 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, { Byte b = _buffer[bufferPos]; _mainStream.WriteByte(b); + UInt32 index; if (b == 0xE8) - _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0); + index = prevByte; else if (b == 0xE9) - _statusE9Encoder.Encode(&_rangeEncoder, 0); + index = 256; else if (IsJcc(prevByte, b)) - _statusJccEncoder.Encode(&_rangeEncoder, 0); + index = 257; + else + { + prevByte = b; + continue; + } + _statusEncoder[index].Encode(&_rangeEncoder, 0); prevByte = b; } return Flush(); @@ -153,7 +160,7 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, { Byte b = _buffer[bufferPos]; _mainStream.WriteByte(b); - if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b)) + if (!IsJ(prevByte, b)) { bufferPos++; prevByte = b; @@ -209,40 +216,19 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, convert = (dest < inSize); else convert = Test86MSByte(nextByte); + unsigned index = GetIndex(prevByte, b); if (convert) { - if (b == 0xE8) - _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1); - else if (b == 0xE9) - _statusE9Encoder.Encode(&_rangeEncoder, 1); - else - _statusJccEncoder.Encode(&_rangeEncoder, 1); - + _statusEncoder[index].Encode(&_rangeEncoder, 1); bufferPos += 5; - if (b == 0xE8) - { - _callStream.WriteByte((Byte)(dest >> 24)); - _callStream.WriteByte((Byte)(dest >> 16)); - _callStream.WriteByte((Byte)(dest >> 8)); - _callStream.WriteByte((Byte)(dest)); - } - else - { - _jumpStream.WriteByte((Byte)(dest >> 24)); - _jumpStream.WriteByte((Byte)(dest >> 16)); - _jumpStream.WriteByte((Byte)(dest >> 8)); - _jumpStream.WriteByte((Byte)(dest)); - } + COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream; + for (int i = 24; i >= 0; i -= 8) + s.WriteByte((Byte)(dest >> i)); prevByte = nextByte; } else { - if (b == 0xE8) - _statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0); - else if (b == 0xE9) - _statusE9Encoder.Encode(&_rangeEncoder, 0); - else - _statusJccEncoder.Encode(&_rangeEncoder, 0); + _statusEncoder[index].Encode(&_rangeEncoder, 0); bufferPos++; prevByte = b; } @@ -262,7 +248,7 @@ HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams, } } -STDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams, +STDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams, ISequentialOutStream **outStreams, @@ -281,7 +267,7 @@ STDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams, #endif -HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, +HRESULT CDecoder::CodeReal(ISequentialInStream **inStreams, const UInt64 ** /* inSizes */, UInt32 numInStreams, ISequentialOutStream **outStreams, @@ -315,10 +301,8 @@ HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, _rangeDecoder.Init(); _outStream.Init(); - for (int i = 0; i < 256; i++) - _statusE8Decoder[i].Init(); - _statusE9Decoder.Init(); - _statusJccDecoder.Init(); + for (int i = 0; i < 256 + 2; i++) + _statusDecoder[i].Init(); CCoderReleaser releaser(this); @@ -326,62 +310,38 @@ HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, UInt32 processedBytes = 0; for (;;) { - if (processedBytes > (1 << 20) && progress != NULL) + if (processedBytes >= (1 << 20) && progress != NULL) { UInt64 nowPos64 = _outStream.GetProcessedSize(); RINOK(progress->SetRatioInfo(NULL, &nowPos64)); processedBytes = 0; } - processedBytes++; - Byte b; - if (!_mainInStream.ReadByte(b)) - return Flush(); - _outStream.WriteByte(b); - if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b)) + UInt32 i; + Byte b = 0; + const UInt32 kBurstSize = (1 << 18); + for (i = 0; i < kBurstSize; i++) { + if (!_mainInStream.ReadByte(b)) + return Flush(); + _outStream.WriteByte(b); + if (IsJ(prevByte, b)) + break; prevByte = b; - continue; } - bool status; - if (b == 0xE8) - status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1); - else if (b == 0xE9) - status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1); - else - status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1); - if (status) + processedBytes += i; + if (i == kBurstSize) + continue; + unsigned index = GetIndex(prevByte, b); + if (_statusDecoder[index].Decode(&_rangeDecoder) == 1) { - UInt32 src; - if (b == 0xE8) + UInt32 src = 0; + CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream; + for (int i = 0; i < 4; i++) { Byte b0; - if(!_callStream.ReadByte(b0)) - return S_FALSE; - src = ((UInt32)b0) << 24; - if(!_callStream.ReadByte(b0)) - return S_FALSE; - src |= ((UInt32)b0) << 16; - if(!_callStream.ReadByte(b0)) - return S_FALSE; - src |= ((UInt32)b0) << 8; - if(!_callStream.ReadByte(b0)) - return S_FALSE; - src |= ((UInt32)b0); - } - else - { - Byte b0; - if(!_jumpStream.ReadByte(b0)) - return S_FALSE; - src = ((UInt32)b0) << 24; - if(!_jumpStream.ReadByte(b0)) - return S_FALSE; - src |= ((UInt32)b0) << 16; - if(!_jumpStream.ReadByte(b0)) - return S_FALSE; - src |= ((UInt32)b0) << 8; - if(!_jumpStream.ReadByte(b0)) + if(!s.ReadByte(b0)) return S_FALSE; + src <<= 8; src |= ((UInt32)b0); } UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ; @@ -397,7 +357,7 @@ HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams, } } -STDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams, +STDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams, ISequentialOutStream **outStreams, @@ -410,6 +370,9 @@ STDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams, return CodeReal(inStreams, inSizes, numInStreams, outStreams, outSizes,numOutStreams, progress); } + catch(const CInBufferException &e) { return e.ErrorCode; } catch(const COutBufferException &e) { return e.ErrorCode; } catch(...) { return S_FALSE; } } + +}} diff --git a/CPP/7zip/Compress/Branch/x86_2.h b/CPP/7zip/Compress/Branch/x86_2.h index 3d34eb8d..2e4a5267 100755 --- a/CPP/7zip/Compress/Branch/x86_2.h +++ b/CPP/7zip/Compress/Branch/x86_2.h @@ -7,38 +7,28 @@ #include "../RangeCoder/RangeCoderBit.h" #include "../../ICoder.h" -// {23170F69-40C1-278B-0303-010100000100} -#define MyClass2_a(Name, id, subId, encodingId) \ -DEFINE_GUID(CLSID_CCompressConvert ## Name, \ -0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); - -#define MyClass_a(Name, id, subId) \ -MyClass2_a(Name ## _Encoder, id, subId, 0x01) \ -MyClass2_a(Name ## _Decoder, id, subId, 0x00) - -MyClass_a(BCJ2_x86, 0x01, 0x1B) +namespace NCompress { +namespace NBcj2 { const int kNumMoveBits = 5; #ifndef EXTRACT_ONLY -class CBCJ2_x86_Encoder: +class CEncoder: public ICompressCoder2, public CMyUnknownImp { Byte *_buffer; public: - CBCJ2_x86_Encoder(): _buffer(0) {}; - ~CBCJ2_x86_Encoder(); + CEncoder(): _buffer(0) {}; + ~CEncoder(); bool Create(); COutBuffer _mainStream; COutBuffer _callStream; COutBuffer _jumpStream; NCompress::NRangeCoder::CEncoder _rangeEncoder; - NCompress::NRangeCoder::CBitEncoder _statusE8Encoder[256]; - NCompress::NRangeCoder::CBitEncoder _statusE9Encoder; - NCompress::NRangeCoder::CBitEncoder _statusJccEncoder; + NCompress::NRangeCoder::CBitEncoder _statusEncoder[256 + 2]; HRESULT Flush(); void ReleaseStreams() @@ -51,9 +41,9 @@ public: class CCoderReleaser { - CBCJ2_x86_Encoder *_coder; + CEncoder *_coder; public: - CCoderReleaser(CBCJ2_x86_Encoder *coder): _coder(coder) {} + CCoderReleaser(CEncoder *coder): _coder(coder) {} ~CCoderReleaser() { _coder->ReleaseStreams(); } }; @@ -79,7 +69,7 @@ public: #endif -class CBCJ2_x86_Decoder: +class CDecoder: public ICompressCoder2, public CMyUnknownImp { @@ -88,9 +78,7 @@ public: CInBuffer _callStream; CInBuffer _jumpStream; NCompress::NRangeCoder::CDecoder _rangeDecoder; - NCompress::NRangeCoder::CBitDecoder _statusE8Decoder[256]; - NCompress::NRangeCoder::CBitDecoder _statusE9Decoder; - NCompress::NRangeCoder::CBitDecoder _statusJccDecoder; + NCompress::NRangeCoder::CBitDecoder _statusDecoder[256 + 2]; COutBuffer _outStream; @@ -106,9 +94,9 @@ public: HRESULT Flush() { return _outStream.Flush(); } class CCoderReleaser { - CBCJ2_x86_Decoder *_coder; + CDecoder *_coder; public: - CCoderReleaser(CBCJ2_x86_Decoder *coder): _coder(coder) {} + CCoderReleaser(CDecoder *coder): _coder(coder) {} ~CCoderReleaser() { _coder->ReleaseStreams(); } }; @@ -130,4 +118,6 @@ public: ICompressProgressInfo *progress); }; +}} + #endif diff --git a/CPP/7zip/Compress/Copy/CopyCoder.cpp b/CPP/7zip/Compress/Copy/CopyCoder.cpp index 141bcf3f..b9af74db 100755 --- a/CPP/7zip/Compress/Copy/CopyCoder.cpp +++ b/CPP/7zip/Compress/Copy/CopyCoder.cpp @@ -52,5 +52,11 @@ STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, return S_OK; } +STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value) +{ + *value = TotalSize; + return S_OK; +} + } diff --git a/CPP/7zip/Compress/Copy/CopyCoder.h b/CPP/7zip/Compress/Copy/CopyCoder.h index d2a26a89..d4530697 100755 --- a/CPP/7zip/Compress/Copy/CopyCoder.h +++ b/CPP/7zip/Compress/Copy/CopyCoder.h @@ -10,6 +10,7 @@ namespace NCompress { class CCopyCoder: public ICompressCoder, + public ICompressGetInStreamProcessedSize, public CMyUnknownImp { Byte *_buffer; @@ -18,12 +19,13 @@ public: CCopyCoder(): TotalSize(0) , _buffer(0) {}; ~CCopyCoder(); - MY_UNKNOWN_IMP + MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize) STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); + STDMETHOD(GetInStreamProcessedSize)(UInt64 *value); }; } diff --git a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp index 9cea4cb1..39fee934 100755 --- a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp +++ b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp @@ -237,6 +237,14 @@ SOURCE=..\..\..\Windows\Synchronization.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\System.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Thread.h # End Source File # End Group @@ -277,51 +285,51 @@ SOURCE=..\..\..\Common\MyCom.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\MyWindows.h +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyWindows.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringToInt.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringToInt.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Types.h +SOURCE=..\..\..\Common\StringToInt.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\StringToInt.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\Types.h # End Source File # End Group # Begin Group "7zip Common" diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp index 69a06207..90c122fc 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp @@ -29,7 +29,7 @@ #include "LzmaRam.h" #ifdef COMPRESS_MF_MT -#include "Windows/System.h" +#include "../../../Windows/System.h" #endif extern "C" @@ -92,7 +92,7 @@ static const CSwitchForm kSwitchForms[] = { L"EOS", NSwitchType::kSimple, false }, { L"SI", NSwitchType::kSimple, false }, { L"SO", NSwitchType::kSimple, false }, - { L"F86", NSwitchType::kSimple, false } + { L"F86", NSwitchType::kPostChar, false, 0, 0, L"+" } }; static const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]); @@ -159,7 +159,7 @@ int main2(int n, const char *args[]) g_IsNT = IsItWindowsNT(); #endif - fprintf(stderr, "\nLZMA 4.45 Copyright (c) 1999-2007 Igor Pavlov 2007-04-03\n"); + fprintf(stderr, "\nLZMA 4.48 Copyright (c) 1999-2007 Igor Pavlov 2007-06-24\n"); if (n == 1) { @@ -335,7 +335,7 @@ int main2(int n, const char *args[]) if (!dictionaryIsDefined) dictionary = 1 << 23; int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, - dictionary, SZ_FILTER_AUTO); + dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO); if (res != 0) { fprintf(stderr, "\nEncoder error = %d\n", (int)res); diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp index b0f01099..124f559b 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp @@ -37,12 +37,12 @@ extern "C" #include "../../ICoder.h" #ifdef BENCH_MT -#include "Windows/Thread.h" -#include "Windows/Synchronization.h" +#include "../../../Windows/Thread.h" +#include "../../../Windows/Synchronization.h" #endif #ifdef EXTERNAL_LZMA -#include "Windows/PropVariant.h" +#include "../../../Windows/PropVariant.h" #else #include "../LZMA/LZMADecoder.h" #include "../LZMA/LZMAEncoder.h" diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp index fef5a9ad..e55b4bc7 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp @@ -6,10 +6,10 @@ #include "LzmaBench.h" #include "LzmaBenchCon.h" -#include "Common/IntToString.h" +#include "../../../Common/IntToString.h" #if defined(BENCH_MT) || defined(_WIN32) -#include "Windows/System.h" +#include "../../../Windows/System.h" #endif #ifdef BREAK_HANDLER diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp index 31ca1c74..b86d1ea9 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp @@ -169,10 +169,9 @@ int LzmaRamEncode( return SZ_RAM_E_OUTOFMEMORY; memmove(filteredStream, inBuffer, inSize); } - UInt32 _prevMask; - UInt32 _prevPos; - x86_Convert_Init(_prevMask, _prevPos); - x86_Convert(filteredStream, (UInt32)inSize, 0, &_prevMask, &_prevPos, 1); + UInt32 x86State; + x86_Convert_Init(x86State); + x86_Convert(filteredStream, (SizeT)inSize, 0, &x86State, 1); } size_t minSize = 0; diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c b/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c index 0767ba21..29f798be 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c @@ -70,10 +70,9 @@ int LzmaRamDecompress( *outSizeProcessed = (size_t)outSizeProcessedLoc; if (useFilter == 1) { - UInt32 _prevMask; - UInt32 _prevPos; - x86_Convert_Init(_prevMask, _prevPos); - x86_Convert(outBuffer, (UInt32)outSizeProcessedLoc, 0, &_prevMask, &_prevPos, 0); + UInt32 x86State; + x86_Convert_Init(x86State); + x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0); } return 0; } diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile b/CPP/7zip/Compress/LZMA_Alone/makefile index b7e6ca0e..16e76376 100755 --- a/CPP/7zip/Compress/LZMA_Alone/makefile +++ b/CPP/7zip/Compress/LZMA_Alone/makefile @@ -1,5 +1,5 @@ PROG = lzma.exe -CFLAGS = $(CFLAGS) -I ../../../ \ +CFLAGS = $(CFLAGS) \ -DCOMPRESS_MF_MT \ -DBENCH_MT \ @@ -53,10 +53,13 @@ COMMON_OBJS = \ $O\CommandLineParser.obj \ $O\CRC.obj \ $O\IntToString.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj + $O\MyVector.obj + +WIN_OBJS = \ + $O\System.obj 7ZIP_COMMON_OBJS = \ $O\InBuffer.obj \ @@ -79,6 +82,7 @@ OBJS = \ $(LZMA_OBJS) \ $(LZMA_OPT_OBJS) \ $(COMMON_OBJS) \ + $(WIN_OBJS) \ $(7ZIP_COMMON_OBJS) \ $(LZ_OBJS) \ $(C_OBJS) \ @@ -108,6 +112,8 @@ $(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp $(COMPL_O2) $(COMMON_OBJS): ../../../Common/$(*B).cpp $(COMPL) +$(WIN_OBJS): ../../../Windows/$(*B).cpp + $(COMPL) $(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp $(COMPL) $(LZ_OBJS): ../LZ/$(*B).cpp diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc index 7696021e..4fed05e6 100755 --- a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc +++ b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc @@ -3,7 +3,20 @@ CXX = g++ -O2 -Wall CXX_C = gcc -O2 -Wall LIB = -lm RM = rm -f -CFLAGS = -c -I ../../../ +CFLAGS = -c + +ifdef SystemDrive +IS_MINGW = 1 +endif + +ifdef IS_MINGW +FILE_IO =FileIO +FILE_IO_2 =Windows/$(FILE_IO) +LIB2 = -luuid +else +FILE_IO =C_FileIO +FILE_IO_2 =Common/$(FILE_IO) +endif OBJS = \ LzmaAlone.o \ @@ -18,14 +31,14 @@ OBJS = \ OutBuffer.o \ FileStreams.o \ StreamUtils.o \ - C_FileIO.o \ + $(FILE_IO).o \ CommandLineParser.o \ CRC.o \ IntToString.o \ - String.o \ + MyString.o \ StringConvert.o \ StringToInt.o \ - Vector.o \ + MyVector.o \ 7zCrc.o \ Alloc.o \ BranchX86.o \ @@ -37,7 +50,7 @@ OBJS = \ all: $(PROG) $(PROG): $(OBJS) - $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) + $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2) LzmaAlone.o: LzmaAlone.cpp $(CXX) $(CFLAGS) LzmaAlone.cpp @@ -75,8 +88,9 @@ FileStreams.o: ../../Common/FileStreams.cpp StreamUtils.o: ../../Common/StreamUtils.cpp $(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp -C_FileIO.o: ../../../Common/C_FileIO.cpp - $(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp +$(FILE_IO).o: ../../../$(FILE_IO_2).cpp + $(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp + CommandLineParser.o: ../../../Common/CommandLineParser.cpp $(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp @@ -90,8 +104,8 @@ MyWindows.o: ../../../Common/MyWindows.cpp IntToString.o: ../../../Common/IntToString.cpp $(CXX) $(CFLAGS) ../../../Common/IntToString.cpp -String.o: ../../../Common/String.cpp - $(CXX) $(CFLAGS) ../../../Common/String.cpp +MyString.o: ../../../Common/MyString.cpp + $(CXX) $(CFLAGS) ../../../Common/MyString.cpp StringConvert.o: ../../../Common/StringConvert.cpp $(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp @@ -99,8 +113,8 @@ StringConvert.o: ../../../Common/StringConvert.cpp StringToInt.o: ../../../Common/StringToInt.cpp $(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp -Vector.o: ../../../Common/Vector.cpp - $(CXX) $(CFLAGS) ../../../Common/Vector.cpp +MyVector.o: ../../../Common/MyVector.cpp + $(CXX) $(CFLAGS) ../../../Common/MyVector.cpp 7zCrc.o: ../../../../C/7zCrc.c $(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c diff --git a/CPP/7zip/Compress/Rar/Rar3Vm.h b/CPP/7zip/Compress/Rar/Rar3Vm.h index cc8bbcd7..99a4f624 100755 --- a/CPP/7zip/Compress/Rar/Rar3Vm.h +++ b/CPP/7zip/Compress/Rar/Rar3Vm.h @@ -7,7 +7,7 @@ #define __RAR3VM_H #include "Common/Types.h" -#include "Common/Vector.h" +#include "Common/MyVector.h" #define RARVM_STANDARD_FILTERS #if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__) // || defined(_M_IA64) || defined(__ia64__) diff --git a/CPP/7zip/Crypto/7zAES/7zAES.cpp b/CPP/7zip/Crypto/7zAES/7zAES.cpp index ae9854e4..d8d86fab 100755 --- a/CPP/7zip/Crypto/7zAES/7zAES.cpp +++ b/CPP/7zip/Crypto/7zAES/7zAES.cpp @@ -1,4 +1,4 @@ -// 7z_AES.cpp +// 7zAES.cpp #include "StdAfx.h" @@ -8,9 +8,12 @@ #include "../../Common/StreamUtils.h" #include "../AES/MyAES.h" #include "../Hash/Sha256.h" - #include "7zAES.h" +#ifndef EXTRACT_ONLY +#include "../Hash/RandGen.h" +#endif + using namespace NWindows; namespace NCrypto { @@ -89,7 +92,8 @@ static CKeyInfoCache g_GlobalKeyCache(32); static NSynchronization::CCriticalSection g_GlobalKeyCacheCriticalSection; CBase::CBase(): - _cachedKeys(16) + _cachedKeys(16), + _ivSize(0) { for (int i = 0; i < sizeof(_iv); i++) _iv[i] = 0; @@ -111,40 +115,31 @@ void CBase::CalculateDigest() } } +#ifndef EXTRACT_ONLY /* -static void GetRandomData(Byte *data) +STDMETHODIMP CEncoder::ResetSalt() { - // probably we don't need truly random. - // it's enough to prevent dictionary attack; - // but it gives some info about time when compressing - // was made. - UInt64 tempValue; - SYSTEMTIME systemTime; - FILETIME fileTime; - ::GetSystemTime(&systemTime); - ::SystemTimeToFileTime(&systemTime, &fileTime); - tempValue = *(const UInt64 *)&fileTime; - LARGE_INTEGER counter; - ::QueryPerformanceCounter(&counter); - tempValue += *(const UInt64 *)&counter; - tempValue += (UInt64)(GetTickCount()) << 32; - *(UInt64 *)data = tempValue; + _key.SaltSize = 4; + g_RandomGenerator.Generate(_key.Salt, _key.SaltSize); + return S_OK; } */ +STDMETHODIMP CEncoder::ResetInitVector() +{ + _ivSize = 8; + g_RandomGenerator.Generate(_iv, _ivSize); + return S_OK; +} + STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) { - _key.Init(); - for (UInt32 i = 0; i < sizeof(_iv); i++) + // _key.Init(); + for (UInt32 i = _ivSize; i < sizeof(_iv); i++) _iv[i] = 0; - _key.SaltSize = 0; - - // _key.SaltSize = 8; - // GetRandomData(_key.Salt); - - int ivSize = 0; + UInt32 ivSize = _ivSize; // _key.NumCyclesPower = 0x3F; _key.NumCyclesPower = 18; @@ -170,6 +165,14 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) return S_OK; } +HRESULT CEncoder::CreateFilter() +{ + _aesFilter = new CAES_CBC_Encoder; + return S_OK; +} + +#endif + STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size) { _key.Init(); @@ -229,12 +232,6 @@ STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size) return _aesFilter->Filter(data, size); } -HRESULT CEncoder::CreateFilter() -{ - _aesFilter = new CAES_CBC_Encoder; - return S_OK; -} - HRESULT CDecoder::CreateFilter() { _aesFilter = new CAES_CBC_Decoder; diff --git a/CPP/7zip/Crypto/7zAES/7zAES.h b/CPP/7zip/Crypto/7zAES/7zAES.h index e8cedccf..ce14e2a1 100755 --- a/CPP/7zip/Crypto/7zAES/7zAES.h +++ b/CPP/7zip/Crypto/7zAES/7zAES.h @@ -6,7 +6,7 @@ #include "Common/MyCom.h" #include "Common/Types.h" #include "Common/Buffer.h" -#include "Common/Vector.h" +#include "Common/MyVector.h" #include "../../ICoder.h" #include "../../IPassword.h" @@ -55,7 +55,7 @@ class CBase protected: CKeyInfo _key; Byte _iv[16]; - // int _ivSize; + UInt32 _ivSize; void CalculateDigest(); CBase(); }; @@ -80,17 +80,26 @@ public: STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size); }; +#ifndef EXTRACT_ONLY + class CEncoder: public CBaseCoder, - public ICompressWriteCoderProperties + public ICompressWriteCoderProperties, + // public ICryptoResetSalt, + public ICryptoResetInitVector { virtual HRESULT CreateFilter(); public: - MY_UNKNOWN_IMP2( + MY_UNKNOWN_IMP3( ICryptoSetPassword, - ICompressWriteCoderProperties) + ICompressWriteCoderProperties, + // ICryptoResetSalt, + ICryptoResetInitVector) STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream); + // STDMETHOD(ResetSalt)(); + STDMETHOD(ResetInitVector)(); }; +#endif class CDecoder: public CBaseCoder, diff --git a/CPP/7zip/Crypto/WzAES/WzAES.h b/CPP/7zip/Crypto/WzAES/WzAES.h index 81ca3f4c..10df3045 100755 --- a/CPP/7zip/Crypto/WzAES/WzAES.h +++ b/CPP/7zip/Crypto/WzAES/WzAES.h @@ -16,7 +16,7 @@ specified in password Based File Encryption Utility: #include "Common/MyCom.h" #include "Common/Buffer.h" -#include "Common/Vector.h" +#include "Common/MyVector.h" #include "../../ICoder.h" #include "../../IPassword.h" diff --git a/CPP/7zip/FileManager/ExtractCallback.h b/CPP/7zip/FileManager/ExtractCallback.h index 7bf8864e..5cf8d635 100755 --- a/CPP/7zip/FileManager/ExtractCallback.h +++ b/CPP/7zip/FileManager/ExtractCallback.h @@ -4,7 +4,7 @@ #define __EXTRACTCALLBACK_H #include "../UI/Agent/IFolderArchive.h" -#include "Common/String.h" +#include "Common/MyString.h" #ifdef _SFX #include "Resource/ProgressDialog/ProgressDialog.h" diff --git a/CPP/7zip/FileManager/FM.dsp b/CPP/7zip/FileManager/FM.dsp index 5265a961..e39ce3af 100755 --- a/CPP/7zip/FileManager/FM.dsp +++ b/CPP/7zip/FileManager/FM.dsp @@ -1027,6 +1027,22 @@ SOURCE=..\..\Common\MyCom.h # End Source File # Begin Source File +SOURCE=..\..\Common\MyString.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MyString.h +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MyVector.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Common\MyVector.h +# End Source File +# Begin Source File + SOURCE=..\..\Common\NewHandler.cpp # End Source File # Begin Source File @@ -1059,14 +1075,6 @@ 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 @@ -1103,14 +1111,6 @@ 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 diff --git a/CPP/7zip/FileManager/FSDrives.h b/CPP/7zip/FileManager/FSDrives.h index 496e8fc1..47afa0cf 100755 --- a/CPP/7zip/FileManager/FSDrives.h +++ b/CPP/7zip/FileManager/FSDrives.h @@ -3,7 +3,7 @@ #ifndef __FSDRIVES_H #define __FSDRIVES_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" #include "Common/MyCom.h" #include "Windows/FileFind.h" diff --git a/CPP/7zip/FileManager/FSFolder.h b/CPP/7zip/FileManager/FSFolder.h index 4641c018..898aff2c 100755 --- a/CPP/7zip/FileManager/FSFolder.h +++ b/CPP/7zip/FileManager/FSFolder.h @@ -3,7 +3,7 @@ #ifndef __FSFOLDER_H #define __FSFOLDER_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/MyCom.h" #include "Windows/FileFind.h" #include "Windows/PropVariant.h" diff --git a/CPP/7zip/FileManager/FormatUtils.h b/CPP/7zip/FileManager/FormatUtils.h index f7e9b193..35536871 100755 --- a/CPP/7zip/FileManager/FormatUtils.h +++ b/CPP/7zip/FileManager/FormatUtils.h @@ -4,7 +4,7 @@ #define __FORMATUTILS_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" UString NumberToString(UInt64 number); diff --git a/CPP/7zip/FileManager/HelpUtils.h b/CPP/7zip/FileManager/HelpUtils.h index b993f09b..2a7b85af 100755 --- a/CPP/7zip/FileManager/HelpUtils.h +++ b/CPP/7zip/FileManager/HelpUtils.h @@ -3,7 +3,7 @@ #ifndef __HELPUTILS_H #define __HELPUTILS_H -#include "Common/String.h" +#include "Common/MyString.h" void ShowHelpWindow(HWND hwnd, LPCWSTR topicFile); diff --git a/CPP/7zip/FileManager/LangUtils.cpp b/CPP/7zip/FileManager/LangUtils.cpp index decff306..f41e764e 100755 --- a/CPP/7zip/FileManager/LangUtils.cpp +++ b/CPP/7zip/FileManager/LangUtils.cpp @@ -134,10 +134,32 @@ bool SplidID(const UString &id, WORD &primID, WORD &subID) return (*end == 0); } +typedef LANGID (WINAPI *GetUserDefaultUILanguageP)(); + void FindMatchLang(UString &shortName) { shortName.Empty(); - LANGID langID = GetUserDefaultLangID(); + + LANGID SystemDefaultLangID = GetSystemDefaultLangID(); // Lang for non-Unicode in XP64 + LANGID UserDefaultLangID = GetUserDefaultLangID(); // Standarts and formats in XP64 + + if (SystemDefaultLangID != UserDefaultLangID) + return; + LANGID langID = UserDefaultLangID; + /* + LANGID SystemDefaultUILanguage; // english in XP64 + LANGID UserDefaultUILanguage; // english in XP64 + + GetUserDefaultUILanguageP fn = (GetUserDefaultUILanguageP)GetProcAddress( + GetModuleHandle("kernel32"), "GetUserDefaultUILanguage"); + if (fn != NULL) + UserDefaultUILanguage = fn(); + fn = (GetUserDefaultUILanguageP)GetProcAddress( + GetModuleHandle("kernel32"), "GetSystemDefaultUILanguage"); + if (fn != NULL) + SystemDefaultUILanguage = fn(); + */ + WORD primLang = (WORD)(PRIMARYLANGID(langID)); WORD subLang = (WORD)(SUBLANGID(langID)); CObjectVector langs; diff --git a/CPP/7zip/FileManager/NetFolder.h b/CPP/7zip/FileManager/NetFolder.h index f23c7e4e..acc7cad2 100755 --- a/CPP/7zip/FileManager/NetFolder.h +++ b/CPP/7zip/FileManager/NetFolder.h @@ -3,7 +3,7 @@ #ifndef __NETFOLDER_H #define __NETFOLDER_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Buffer.h" #include "Common/MyCom.h" #include "Windows/PropVariant.h" diff --git a/CPP/7zip/FileManager/OpenCallback.h b/CPP/7zip/FileManager/OpenCallback.h index 853c0e44..d7e9a5ed 100755 --- a/CPP/7zip/FileManager/OpenCallback.h +++ b/CPP/7zip/FileManager/OpenCallback.h @@ -3,7 +3,7 @@ #ifndef __OPENCALLBACK_H #define __OPENCALLBACK_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/MyCom.h" #include "Windows/FileFind.h" diff --git a/CPP/7zip/FileManager/PanelItems.cpp b/CPP/7zip/FileManager/PanelItems.cpp index 16c8d29a..07d10a76 100755 --- a/CPP/7zip/FileManager/PanelItems.cpp +++ b/CPP/7zip/FileManager/PanelItems.cpp @@ -2,7 +2,6 @@ #include "StdAfx.h" -#include "Common/String.h" #include "Common/StringConvert.h" #include "Windows/PropVariant.h" diff --git a/CPP/7zip/FileManager/PhysDriveFolder.h b/CPP/7zip/FileManager/PhysDriveFolder.h index db339af4..550b76b4 100755 --- a/CPP/7zip/FileManager/PhysDriveFolder.h +++ b/CPP/7zip/FileManager/PhysDriveFolder.h @@ -3,7 +3,7 @@ #ifndef __PHYSDRIVEFOLDER_H #define __PHYSDRIVEFOLDER_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/MyCom.h" #include "IFolder.h" diff --git a/CPP/7zip/FileManager/PluginInterface.h b/CPP/7zip/FileManager/PluginInterface.h index 249f5644..7bef6950 100755 --- a/CPP/7zip/FileManager/PluginInterface.h +++ b/CPP/7zip/FileManager/PluginInterface.h @@ -3,7 +3,7 @@ #ifndef __PLUGININTERFACE_H #define __PLUGININTERFACE_H -#include "Common/String.h" +#include "Common/MyString.h" // {23170F69-40C1-278D-0000-000100010000} DEFINE_GUID(IID_IInitContextMenu, diff --git a/CPP/7zip/FileManager/ProgramLocation.h b/CPP/7zip/FileManager/ProgramLocation.h index 8a8dcf7d..38317b45 100755 --- a/CPP/7zip/FileManager/ProgramLocation.h +++ b/CPP/7zip/FileManager/ProgramLocation.h @@ -3,7 +3,7 @@ #ifndef __PROGRAMLOCATION_H #define __PROGRAMLOCATION_H -#include "Common/String.h" +#include "Common/MyString.h" bool GetProgramFolderPath(UString &folder); // normalized diff --git a/CPP/7zip/FileManager/PropertyName.h b/CPP/7zip/FileManager/PropertyName.h index c99fe933..413d2343 100755 --- a/CPP/7zip/FileManager/PropertyName.h +++ b/CPP/7zip/FileManager/PropertyName.h @@ -3,7 +3,7 @@ #ifndef __PROPERTYNAME_H #define __PROPERTYNAME_H -#include "Common/String.h" +#include "Common/MyString.h" UString GetNameOfProperty(PROPID propID); diff --git a/CPP/7zip/FileManager/RegistryAssociations.h b/CPP/7zip/FileManager/RegistryAssociations.h index 91613f79..c1a64c96 100755 --- a/CPP/7zip/FileManager/RegistryAssociations.h +++ b/CPP/7zip/FileManager/RegistryAssociations.h @@ -3,8 +3,7 @@ #ifndef __REGISTRYASSOCIATIONS_H #define __REGISTRYASSOCIATIONS_H -#include "Common/String.h" -#include "Common/Vector.h" +#include "Common/MyString.h" namespace NRegistryAssociations { diff --git a/CPP/7zip/FileManager/RegistryPlugins.h b/CPP/7zip/FileManager/RegistryPlugins.h index 4a30857c..55f9ebbc 100755 --- a/CPP/7zip/FileManager/RegistryPlugins.h +++ b/CPP/7zip/FileManager/RegistryPlugins.h @@ -3,8 +3,7 @@ #ifndef __REGISTRYPLUGINS_H #define __REGISTRYPLUGINS_H -#include "Common/Vector.h" -#include "Common/String.h" +#include "Common/MyString.h" enum EPluginType { diff --git a/CPP/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp b/CPP/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp index ca7b7935..e6a6779e 100755 --- a/CPP/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp +++ b/CPP/7zip/FileManager/Resource/ListViewDialog/ListViewDialog.cpp @@ -3,8 +3,6 @@ #include "StdAfx.h" #include "ListViewDialog.h" -#include "Common/Vector.h" - #ifdef LANG #include "../../LangUtils.h" static CIDLangPair kIDLangPairs[] = diff --git a/CPP/7zip/FileManager/RootFolder.h b/CPP/7zip/FileManager/RootFolder.h index 16bac250..d49f4d12 100755 --- a/CPP/7zip/FileManager/RootFolder.h +++ b/CPP/7zip/FileManager/RootFolder.h @@ -3,7 +3,7 @@ #ifndef __ROOTFOLDER_H #define __ROOTFOLDER_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Windows/PropVariant.h" diff --git a/CPP/7zip/FileManager/SplitUtils.h b/CPP/7zip/FileManager/SplitUtils.h index fe359f04..755c707c 100755 --- a/CPP/7zip/FileManager/SplitUtils.h +++ b/CPP/7zip/FileManager/SplitUtils.h @@ -3,7 +3,7 @@ #ifndef __SPLITUTILS_H #define __SPLITUTILS_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" #include "Windows/Control/ComboBox.h" diff --git a/CPP/7zip/FileManager/StringUtils.h b/CPP/7zip/FileManager/StringUtils.h index 376a3024..7f72b764 100755 --- a/CPP/7zip/FileManager/StringUtils.h +++ b/CPP/7zip/FileManager/StringUtils.h @@ -3,7 +3,7 @@ #ifndef __STRINGUTILS_H #define __STRINGUTILS_H -#include "Common/String.h" +#include "Common/MyString.h" void SplitStringToTwoStrings(const UString &src, UString &dest1, UString &dest2); diff --git a/CPP/7zip/FileManager/SysIconUtils.h b/CPP/7zip/FileManager/SysIconUtils.h index 51294751..3b6c6c2e 100755 --- a/CPP/7zip/FileManager/SysIconUtils.h +++ b/CPP/7zip/FileManager/SysIconUtils.h @@ -3,7 +3,7 @@ #ifndef __SYSICONUTILS_H #define __SYSICONUTILS_H -#include "Common/String.h" +#include "Common/MyString.h" struct CExtIconPair { diff --git a/CPP/7zip/FileManager/TextPairs.h b/CPP/7zip/FileManager/TextPairs.h index 247a92d9..b75d9c72 100755 --- a/CPP/7zip/FileManager/TextPairs.h +++ b/CPP/7zip/FileManager/TextPairs.h @@ -3,8 +3,7 @@ #ifndef __COMMON_TEXTPAIRS_H #define __COMMON_TEXTPAIRS_H -#include "Common/Vector.h" -#include "Common/String.h" +#include "Common/MyString.h" struct CTextPair { diff --git a/CPP/7zip/FileManager/UpdateCallback100.h b/CPP/7zip/FileManager/UpdateCallback100.h index 4cce5b52..0163010b 100755 --- a/CPP/7zip/FileManager/UpdateCallback100.h +++ b/CPP/7zip/FileManager/UpdateCallback100.h @@ -4,7 +4,7 @@ #define __UPDATE_CALLBACK100_H #include "Common/MyCom.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "../UI/Agent/IFolderArchive.h" #include "Resource/ProgressDialog2/ProgressDialog.h" diff --git a/CPP/7zip/FileManager/ViewSettings.h b/CPP/7zip/FileManager/ViewSettings.h index 4894a6f9..4af0b991 100755 --- a/CPP/7zip/FileManager/ViewSettings.h +++ b/CPP/7zip/FileManager/ViewSettings.h @@ -3,8 +3,7 @@ #ifndef __VIEWSETTINGS_H #define __VIEWSETTINGS_H -#include "Common/Vector.h" -#include "Common/String.h" +#include "Common/MyString.h" struct CColumnInfo { diff --git a/CPP/7zip/FileManager/makefile b/CPP/7zip/FileManager/makefile index 3a15cf2e..3a561121 100755 --- a/CPP/7zip/FileManager/makefile +++ b/CPP/7zip/FileManager/makefile @@ -59,12 +59,12 @@ COMMON_OBJS = \ $O\Random.obj \ $O\StdInStream.obj \ $O\StdOutStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ $O\TextConfig.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ diff --git a/CPP/7zip/Guid.txt b/CPP/7zip/Guid.txt index fd91e292..bead1f83 100755 --- a/CPP/7zip/Guid.txt +++ b/CPP/7zip/Guid.txt @@ -35,6 +35,8 @@ 60 ICompressCodecsInfo 61 ISetCompressCodecsInfo 80 ICryptoProperties +88 ICryptoResetSalt +8C ICryptoResetInitVector 90 ICryptoSetPassword A0 ICryptoSetCRC diff --git a/CPP/7zip/ICoder.h b/CPP/7zip/ICoder.h index e7de64b1..0c10068e 100755 --- a/CPP/7zip/ICoder.h +++ b/CPP/7zip/ICoder.h @@ -146,6 +146,18 @@ CODER_INTERFACE(ICryptoProperties, 0x80) STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE; }; +/* +CODER_INTERFACE(ICryptoResetSalt, 0x88) +{ + STDMETHOD(ResetSalt)() PURE; +}; +*/ + +CODER_INTERFACE(ICryptoResetInitVector, 0x8C) +{ + STDMETHOD(ResetInitVector)() PURE; +}; + CODER_INTERFACE(ICryptoSetPassword, 0x90) { STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE; diff --git a/CPP/7zip/MyVersion.h b/CPP/7zip/MyVersion.h index 722a2451..911dfc15 100755 --- a/CPP/7zip/MyVersion.h +++ b/CPP/7zip/MyVersion.h @@ -1,8 +1,8 @@ #define MY_VER_MAJOR 4 -#define MY_VER_MINOR 47 +#define MY_VER_MINOR 48 #define MY_VER_BUILD 0 -#define MY_VERSION "4.47 beta" -#define MY_7ZIP_VERSION "7-Zip 4.47 beta" -#define MY_DATE "2007-05-27" +#define MY_VERSION "4.48 beta" +#define MY_7ZIP_VERSION "7-Zip 4.48 beta" +#define MY_DATE "2007-06-26" #define MY_COPYRIGHT "Copyright (c) 1999-2007 Igor Pavlov" #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE diff --git a/CPP/7zip/UI/Agent/Agent.cpp b/CPP/7zip/UI/Agent/Agent.cpp index 25cc42e4..528abb53 100755 --- a/CPP/7zip/UI/Agent/Agent.cpp +++ b/CPP/7zip/UI/Agent/Agent.cpp @@ -49,6 +49,8 @@ void CAgentFolder::LoadFolder(CProxyFolder *folder) STDMETHODIMP CAgentFolder::LoadItems() { + if (!_agentSpec->_archiveLink.IsOpen) + return E_FAIL; _items.Clear(); if (_flatMode) LoadFolder(_proxyFolderItem); diff --git a/CPP/7zip/UI/Agent/AgentProxy.h b/CPP/7zip/UI/Agent/AgentProxy.h index 9402cfdd..70f47f40 100755 --- a/CPP/7zip/UI/Agent/AgentProxy.h +++ b/CPP/7zip/UI/Agent/AgentProxy.h @@ -3,7 +3,7 @@ #ifndef __AGENT_PROXY_H #define __AGENT_PROXY_H -#include "Common/String.h" +#include "Common/MyString.h" #include "../../Archive/IArchive.h" diff --git a/CPP/7zip/UI/Client7z/Client7z.dsp b/CPP/7zip/UI/Client7z/Client7z.dsp index b574bdb7..542e2852 100755 --- a/CPP/7zip/UI/Client7z/Client7z.dsp +++ b/CPP/7zip/UI/Client7z/Client7z.dsp @@ -167,35 +167,35 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File diff --git a/CPP/7zip/UI/Client7z/makefile b/CPP/7zip/UI/Client7z/makefile index 4650c293..6c806267 100755 --- a/CPP/7zip/UI/Client7z/makefile +++ b/CPP/7zip/UI/Client7z/makefile @@ -8,10 +8,10 @@ CONSOLE_OBJS = \ COMMON_OBJS = \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index 17b04e12..d16d6166 100755 --- a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -24,6 +24,14 @@ #include "SortUtils.h" #include "EnumDirItems.h" +#if _MSC_VER >= 1400 +#define MY_isatty_fileno(x) _isatty(_fileno(x)) +#else +#define MY_isatty_fileno(x) isatty(fileno(x)) +#endif + +#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0); + using namespace NCommandLineParser; using namespace NWindows; using namespace NFile; @@ -681,9 +689,9 @@ void CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings, ThrowUserErrorException(); } - options.IsInTerminal = (isatty(fileno(stdin)) != 0); - options.IsStdOutTerminal = (isatty(fileno(stdout)) != 0); - options.IsStdErrTerminal = (isatty(fileno(stderr)) != 0); + options.IsInTerminal = MY_IS_TERMINAL(stdin); + options.IsStdOutTerminal = MY_IS_TERMINAL(stdout); + options.IsStdErrTerminal = MY_IS_TERMINAL(stderr); 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; diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.h b/CPP/7zip/UI/Common/ArchiveExtractCallback.h index 4fd63a53..489cdcdb 100755 --- a/CPP/7zip/UI/Common/ArchiveExtractCallback.h +++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.h @@ -6,7 +6,7 @@ #include "../../Archive/IArchive.h" #include "IFileExtractCallback.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/MyCom.h" #include "../../Common/FileStreams.h" diff --git a/CPP/7zip/UI/Common/ArchiveName.h b/CPP/7zip/UI/Common/ArchiveName.h index 6b001a5a..9513fb2b 100755 --- a/CPP/7zip/UI/Common/ArchiveName.h +++ b/CPP/7zip/UI/Common/ArchiveName.h @@ -3,7 +3,7 @@ #ifndef __ARCHIVENAME_H #define __ARCHIVENAME_H -#include "Common/String.h" +#include "Common/MyString.h" UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName); diff --git a/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp b/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp index 1d2944d8..e54214be 100755 --- a/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp +++ b/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp @@ -15,6 +15,8 @@ using namespace NWindows; STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes) { COM_TRY_BEGIN + if (!Callback) + return S_OK; return Callback->SetTotal(files, bytes); COM_TRY_END } @@ -22,6 +24,8 @@ STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes) { COM_TRY_BEGIN + if (!Callback) + return S_OK; return Callback->SetTotal(files, bytes); COM_TRY_END } @@ -96,7 +100,10 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre COM_TRY_BEGIN if (_subArchiveMode) return S_FALSE; - RINOK(Callback->CheckBreak()); + if (Callback) + { + RINOK(Callback->CheckBreak()); + } *inStream = NULL; UString fullPath = _folderPrefix + name; if (!NFile::NFind::FindFile(fullPath, _fileInfo)) @@ -120,6 +127,8 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password) { COM_TRY_BEGIN + if (!Callback) + return E_NOTIMPL; return Callback->CryptoGetTextPassword(password); COM_TRY_END } diff --git a/CPP/7zip/UI/Common/ArchiveOpenCallback.h b/CPP/7zip/UI/Common/ArchiveOpenCallback.h index 454873ad..304c2048 100755 --- a/CPP/7zip/UI/Common/ArchiveOpenCallback.h +++ b/CPP/7zip/UI/Common/ArchiveOpenCallback.h @@ -3,7 +3,7 @@ #ifndef __ARCHIVE_OPEN_CALLBACK_H #define __ARCHIVE_OPEN_CALLBACK_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/MyCom.h" #include "Windows/FileFind.h" @@ -75,6 +75,8 @@ private: public: UStringVector FileNames; IOpenCallbackUI *Callback; + + COpenCallbackImp(): Callback(NULL) {} void Init(const UString &folderPrefix, const UString &fileName) { _folderPrefix = folderPrefix; diff --git a/CPP/7zip/UI/Common/CompressCall.h b/CPP/7zip/UI/Common/CompressCall.h index db7e3647..2bb1c7be 100755 --- a/CPP/7zip/UI/Common/CompressCall.h +++ b/CPP/7zip/UI/Common/CompressCall.h @@ -3,7 +3,7 @@ #ifndef __COMPRESSCALL_H #define __COMPRESSCALL_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Windows/Synchronization.h" HRESULT MyCreateProcess(const UString ¶ms, diff --git a/CPP/7zip/UI/Common/DefaultName.h b/CPP/7zip/UI/Common/DefaultName.h index ff6330fa..a702cb0f 100755 --- a/CPP/7zip/UI/Common/DefaultName.h +++ b/CPP/7zip/UI/Common/DefaultName.h @@ -3,7 +3,7 @@ #ifndef __DEFAULTNAME_H #define __DEFAULTNAME_H -#include "Common/String.h" +#include "Common/MyString.h" UString GetDefaultName2(const UString &fileName, const UString &extension, const UString &addSubExtension); diff --git a/CPP/7zip/UI/Common/DirItem.h b/CPP/7zip/UI/Common/DirItem.h index 9537071c..89bd4cd3 100755 --- a/CPP/7zip/UI/Common/DirItem.h +++ b/CPP/7zip/UI/Common/DirItem.h @@ -3,7 +3,7 @@ #ifndef __DIR_ITEM_H #define __DIR_ITEM_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" struct CDirItem diff --git a/CPP/7zip/UI/Common/ExtractingFilePath.h b/CPP/7zip/UI/Common/ExtractingFilePath.h index 0ae9e9b8..efc8a0e4 100755 --- a/CPP/7zip/UI/Common/ExtractingFilePath.h +++ b/CPP/7zip/UI/Common/ExtractingFilePath.h @@ -3,7 +3,7 @@ #ifndef __EXTRACTINGFILEPATH_H #define __EXTRACTINGFILEPATH_H -#include "Common/String.h" +#include "Common/MyString.h" UString GetCorrectFileName(const UString &path); UString GetCorrectPath(const UString &path); diff --git a/CPP/7zip/UI/Common/IFileExtractCallback.h b/CPP/7zip/UI/Common/IFileExtractCallback.h index 6268f758..466b1e62 100755 --- a/CPP/7zip/UI/Common/IFileExtractCallback.h +++ b/CPP/7zip/UI/Common/IFileExtractCallback.h @@ -3,7 +3,7 @@ #ifndef __IFILEEXTRACTCALLBACK_H #define __IFILEEXTRACTCALLBACK_H -#include "Common/String.h" +#include "Common/MyString.h" namespace NOverwriteAnswer { diff --git a/CPP/7zip/UI/Common/LoadCodecs.h b/CPP/7zip/UI/Common/LoadCodecs.h index 28cc7dad..231680b5 100755 --- a/CPP/7zip/UI/Common/LoadCodecs.h +++ b/CPP/7zip/UI/Common/LoadCodecs.h @@ -5,7 +5,7 @@ #include "../../../Common/Types.h" #include "../../../Common/MyCom.h" -#include "../../../Common/String.h" +#include "../../../Common/MyString.h" #include "../../../Common/Buffer.h" #include "../../ICoder.h" diff --git a/CPP/7zip/UI/Common/OpenArchive.cpp b/CPP/7zip/UI/Common/OpenArchive.cpp index 0f73890f..795b86e7 100755 --- a/CPP/7zip/UI/Common/OpenArchive.cpp +++ b/CPP/7zip/UI/Common/OpenArchive.cpp @@ -81,12 +81,12 @@ HRESULT IsArchiveItemAnti(IInArchive *archive, UInt32 index, bool &result) // Static-SFX (for Linux) can be big. const UInt64 kMaxCheckStartPosition = 1 << 22; -HRESULT ReOpenArchive(IInArchive *archive, const UString &fileName) +HRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback) { CInFileStream *inStreamSpec = new CInFileStream; CMyComPtr inStream(inStreamSpec); inStreamSpec->Open(fileName); - return archive->Open(inStream, &kMaxCheckStartPosition, NULL); + return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback); } #ifndef _SFX @@ -305,13 +305,11 @@ HRESULT OpenArchive( return S_OK; } -HRESULT MyOpenArchive( - CCodecs *codecs, - const UString &archiveName, - IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI) +static void SetCallback(const UString &archiveName, + IOpenCallbackUI *openCallbackUI, CMyComPtr &openCallback) { COpenCallbackImp *openCallbackSpec = new COpenCallbackImp; - CMyComPtr openCallback = openCallbackSpec; + openCallback = openCallbackSpec; openCallbackSpec->Callback = openCallbackUI; UString fullName; @@ -320,7 +318,15 @@ HRESULT MyOpenArchive( openCallbackSpec->Init( fullName.Left(fileNamePartStartIndex), fullName.Mid(fileNamePartStartIndex)); +} +HRESULT MyOpenArchive( + CCodecs *codecs, + const UString &archiveName, + IInArchive **archive, UString &defaultItemName, IOpenCallbackUI *openCallbackUI) +{ + CMyComPtr openCallback; + SetCallback(archiveName, openCallbackUI, openCallback); int formatInfo; return OpenArchive(codecs, archiveName, archive, formatInfo, defaultItemName, openCallback); } @@ -367,11 +373,13 @@ HRESULT CArchiveLink::Close() RINOK(Archive1->Close()); if (Archive0 != 0) RINOK(Archive0->Close()); + IsOpen = false; return S_OK; } void CArchiveLink::Release() { + IsOpen = false; Archive1.Release(); Archive0.Release(); } @@ -382,11 +390,13 @@ HRESULT OpenArchive( CArchiveLink &archiveLink, IArchiveOpenCallback *openCallback) { - return OpenArchive(codecs, archiveName, + HRESULT res = OpenArchive(codecs, archiveName, &archiveLink.Archive0, &archiveLink.Archive1, archiveLink.FormatIndex0, archiveLink.FormatIndex1, archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, openCallback); + archiveLink.IsOpen = (res == S_OK); + return res; } HRESULT MyOpenArchive(CCodecs *codecs, @@ -394,18 +404,27 @@ HRESULT MyOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, IOpenCallbackUI *openCallbackUI) { - return MyOpenArchive(codecs, archiveName, + HRESULT res = MyOpenArchive(codecs, archiveName, &archiveLink.Archive0, &archiveLink.Archive1, archiveLink.DefaultItemName0, archiveLink.DefaultItemName1, archiveLink.VolumePaths, openCallbackUI); + archiveLink.IsOpen = (res == S_OK); + return res; } HRESULT ReOpenArchive(CCodecs *codecs, CArchiveLink &archiveLink, const UString &fileName) { if (archiveLink.GetNumLevels() > 1) return E_NOTIMPL; + if (archiveLink.GetNumLevels() == 0) return MyOpenArchive(codecs, fileName, archiveLink, 0); - return ReOpenArchive(archiveLink.GetArchive(), fileName); + + CMyComPtr openCallback; + SetCallback(fileName, NULL, openCallback); + + HRESULT res = ReOpenArchive(archiveLink.GetArchive(), fileName, openCallback); + archiveLink.IsOpen = (res == S_OK); + return res; } diff --git a/CPP/7zip/UI/Common/OpenArchive.h b/CPP/7zip/UI/Common/OpenArchive.h index ebd89ceb..a857b9de 100755 --- a/CPP/7zip/UI/Common/OpenArchive.h +++ b/CPP/7zip/UI/Common/OpenArchive.h @@ -3,7 +3,7 @@ #ifndef __OPENARCHIVE_H #define __OPENARCHIVE_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Windows/FileFind.h" #include "../../Archive/IArchive.h" @@ -51,7 +51,7 @@ HRESULT OpenArchive( IArchiveOpenCallback *openArchiveCallback); -HRESULT ReOpenArchive(IInArchive *archive, const UString &fileName); +HRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback); HRESULT MyOpenArchive( CCodecs *codecs, @@ -94,6 +94,9 @@ struct CArchiveLink return result; } + bool IsOpen; + + CArchiveLink(): IsOpen(false) {}; IInArchive *GetArchive() { return Archive1 != 0 ? Archive1: Archive0; } UString GetDefaultItemName() { return Archive1 != 0 ? DefaultItemName1: DefaultItemName0; } diff --git a/CPP/7zip/UI/Common/PropIDUtils.cpp b/CPP/7zip/UI/Common/PropIDUtils.cpp index 8869e565..76596883 100755 --- a/CPP/7zip/UI/Common/PropIDUtils.cpp +++ b/CPP/7zip/UI/Common/PropIDUtils.cpp @@ -32,8 +32,7 @@ static void ConvertUInt32ToHex(UInt32 value, wchar_t *s) s[8] = L'\0'; } -UString ConvertPropertyToString(const PROPVARIANT &propVariant, - PROPID propID, bool full) +UString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full) { switch(propID) { diff --git a/CPP/7zip/UI/Common/PropIDUtils.h b/CPP/7zip/UI/Common/PropIDUtils.h index aa540885..1d820976 100755 --- a/CPP/7zip/UI/Common/PropIDUtils.h +++ b/CPP/7zip/UI/Common/PropIDUtils.h @@ -3,9 +3,8 @@ #ifndef __PROPIDUTILS_H #define __PROPIDUTILS_H -#include "Common/String.h" +#include "Common/MyString.h" -UString ConvertPropertyToString(const PROPVARIANT &aPropVariant, - PROPID aPropID, bool aFull = true); +UString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true); #endif diff --git a/CPP/7zip/UI/Common/Property.h b/CPP/7zip/UI/Common/Property.h index 57e7b452..9fd340cb 100755 --- a/CPP/7zip/UI/Common/Property.h +++ b/CPP/7zip/UI/Common/Property.h @@ -3,7 +3,7 @@ #ifndef __PROPERTY_H #define __PROPERTY_H -#include "Common/String.h" +#include "Common/MyString.h" struct CProperty { diff --git a/CPP/7zip/UI/Common/SetProperties.cpp b/CPP/7zip/UI/Common/SetProperties.cpp index 6c92a847..b1434ace 100755 --- a/CPP/7zip/UI/Common/SetProperties.cpp +++ b/CPP/7zip/UI/Common/SetProperties.cpp @@ -5,7 +5,7 @@ #include "SetProperties.h" #include "Windows/PropVariant.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/StringToInt.h" #include "Common/MyCom.h" diff --git a/CPP/7zip/UI/Common/SortUtils.cpp b/CPP/7zip/UI/Common/SortUtils.cpp index 54d88adc..616472ff 100755 --- a/CPP/7zip/UI/Common/SortUtils.cpp +++ b/CPP/7zip/UI/Common/SortUtils.cpp @@ -77,4 +77,4 @@ void SortStrings(const UStringVector &src, UStringVector &dest) for (int i = 0; i < indices.Size(); i++) dest.Add(src[indices[i]]); } -*/ \ No newline at end of file +*/ diff --git a/CPP/7zip/UI/Common/SortUtils.h b/CPP/7zip/UI/Common/SortUtils.h index b30bc6ca..2fb8ddef 100755 --- a/CPP/7zip/UI/Common/SortUtils.h +++ b/CPP/7zip/UI/Common/SortUtils.h @@ -3,7 +3,7 @@ #ifndef __SORTUTLS_H #define __SORTUTLS_H -#include "Common/String.h" +#include "Common/MyString.h" void SortStringsToIndices(const UStringVector &strings, CIntVector &indices); // void SortStrings(const UStringVector &src, UStringVector &dest); diff --git a/CPP/7zip/UI/Common/TempFiles.h b/CPP/7zip/UI/Common/TempFiles.h index 173713a0..eb474a76 100755 --- a/CPP/7zip/UI/Common/TempFiles.h +++ b/CPP/7zip/UI/Common/TempFiles.h @@ -3,7 +3,7 @@ #ifndef __TEMPFILES_H #define __TEMPFILES_H -#include "Common/String.h" +#include "Common/MyString.h" class CTempFiles { diff --git a/CPP/7zip/UI/Common/UpdateCallback.h b/CPP/7zip/UI/Common/UpdateCallback.h index cc4e2649..31e42e33 100755 --- a/CPP/7zip/UI/Common/UpdateCallback.h +++ b/CPP/7zip/UI/Common/UpdateCallback.h @@ -4,7 +4,7 @@ #define __UPDATECALLBACK_H #include "Common/MyCom.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "../../IPassword.h" diff --git a/CPP/7zip/UI/Common/ZipRegistry.h b/CPP/7zip/UI/Common/ZipRegistry.h index fcb0cce4..753287d9 100755 --- a/CPP/7zip/UI/Common/ZipRegistry.h +++ b/CPP/7zip/UI/Common/ZipRegistry.h @@ -3,7 +3,7 @@ #ifndef __ZIPREGISTRY_H #define __ZIPREGISTRY_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" #include "ExtractMode.h" diff --git a/CPP/7zip/UI/Console/Console.dsp b/CPP/7zip/UI/Console/Console.dsp index 64cac741..e68c34dc 100755 --- a/CPP/7zip/UI/Console/Console.dsp +++ b/CPP/7zip/UI/Console/Console.dsp @@ -308,6 +308,14 @@ SOURCE=..\..\..\Windows\Registry.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Windows\System.h +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\Time.h # End Source File # End Group @@ -364,35 +372,43 @@ SOURCE=..\..\..\Common\MyCom.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdOutStream.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdOutStream.h +SOURCE=..\..\..\Common\NewHandler.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\StdInStream.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\StdOutStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdOutStream.h # End Source File # Begin Source File @@ -420,14 +436,6 @@ 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 diff --git a/CPP/7zip/UI/Console/ExtractCallbackConsole.h b/CPP/7zip/UI/Console/ExtractCallbackConsole.h index 5b45106a..bf81a803 100755 --- a/CPP/7zip/UI/Console/ExtractCallbackConsole.h +++ b/CPP/7zip/UI/Console/ExtractCallbackConsole.h @@ -3,7 +3,7 @@ #ifndef __EXTRACTCALLBACKCONSOLE_H #define __EXTRACTCALLBACKCONSOLE_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/StdOutStream.h" #include "../../Common/FileStreams.h" #include "../../IPassword.h" diff --git a/CPP/7zip/UI/Console/Main.cpp b/CPP/7zip/UI/Console/Main.cpp index 4f0061b2..97c117ce 100755 --- a/CPP/7zip/UI/Console/Main.cpp +++ b/CPP/7zip/UI/Console/Main.cpp @@ -5,7 +5,7 @@ #include "Common/MyInitGuid.h" #include "Common/CommandLineParser.h" -#include "Common/Exception.h" +#include "Common/MyException.h" #include "Common/IntToString.h" #include "Common/ListFileUtils.h" #include "Common/StdInStream.h" diff --git a/CPP/7zip/UI/Console/MainAr.cpp b/CPP/7zip/UI/Console/MainAr.cpp index 75fae190..fd42e4f6 100755 --- a/CPP/7zip/UI/Console/MainAr.cpp +++ b/CPP/7zip/UI/Console/MainAr.cpp @@ -8,7 +8,7 @@ #include "Common/StdOutStream.h" #include "Common/NewHandler.h" -#include "Common/Exception.h" +#include "Common/MyException.h" #include "Common/StringConvert.h" #include "../Common/ExitCode.h" diff --git a/CPP/7zip/UI/Console/PercentPrinter.cpp b/CPP/7zip/UI/Console/PercentPrinter.cpp index d6324303..47aafd73 100755 --- a/CPP/7zip/UI/Console/PercentPrinter.cpp +++ b/CPP/7zip/UI/Console/PercentPrinter.cpp @@ -3,7 +3,7 @@ #include "StdAfx.h" #include "Common/IntToString.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "PercentPrinter.h" diff --git a/CPP/7zip/UI/Console/UpdateCallbackConsole.h b/CPP/7zip/UI/Console/UpdateCallbackConsole.h index 2fcb891b..ca7cc742 100755 --- a/CPP/7zip/UI/Console/UpdateCallbackConsole.h +++ b/CPP/7zip/UI/Console/UpdateCallbackConsole.h @@ -3,7 +3,7 @@ #ifndef __UPDATECALLBACKCONSOLE_H #define __UPDATECALLBACKCONSOLE_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/StdOutStream.h" #include "PercentPrinter.h" #include "../Common/Update.h" diff --git a/CPP/7zip/UI/Console/makefile b/CPP/7zip/UI/Console/makefile index 02abe851..bd3b7a4e 100755 --- a/CPP/7zip/UI/Console/makefile +++ b/CPP/7zip/UI/Console/makefile @@ -28,11 +28,11 @@ COMMON_OBJS = \ $O\NewHandler.obj \ $O\StdInStream.obj \ $O\StdOutStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -46,6 +46,7 @@ WIN_OBJS = \ $O\PropVariant.obj \ $O\PropVariantConversions.obj \ $O\Registry.obj \ + $O\System.obj \ 7ZIP_COMMON_OBJS = \ $O\FilePathAutoRename.obj \ diff --git a/CPP/7zip/UI/Explorer/ContextMenu.h b/CPP/7zip/UI/Explorer/ContextMenu.h index 60970a22..9ab80dfd 100755 --- a/CPP/7zip/UI/Explorer/ContextMenu.h +++ b/CPP/7zip/UI/Explorer/ContextMenu.h @@ -7,7 +7,7 @@ DEFINE_GUID(CLSID_CZipContextMenu, 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00); -#include "Common/String.h" +#include "Common/MyString.h" #include "../../FileManager/PluginInterface.h" #include "../../FileManager/MyCom2.h" diff --git a/CPP/7zip/UI/Explorer/Explorer.dsp b/CPP/7zip/UI/Explorer/Explorer.dsp index 3fbf3064..586d9aae 100755 --- a/CPP/7zip/UI/Explorer/Explorer.dsp +++ b/CPP/7zip/UI/Explorer/Explorer.dsp @@ -569,35 +569,43 @@ SOURCE=..\..\..\Common\MyCom.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Random.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Random.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.h +SOURCE=..\..\..\Common\NewHandler.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\Random.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\Random.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\StdInStream.h # End Source File # Begin Source File @@ -637,14 +645,6 @@ 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 diff --git a/CPP/7zip/UI/Explorer/MyMessages.cpp b/CPP/7zip/UI/Explorer/MyMessages.cpp index 61d2429d..a29581be 100755 --- a/CPP/7zip/UI/Explorer/MyMessages.cpp +++ b/CPP/7zip/UI/Explorer/MyMessages.cpp @@ -3,8 +3,6 @@ #include "StdAfx.h" #include "MyMessages.h" -#include "Common/String.h" -#include "Common/StringConvert.h" #include "Windows/Error.h" #include "Windows/ResourceString.h" diff --git a/CPP/7zip/UI/Explorer/MyMessages.h b/CPP/7zip/UI/Explorer/MyMessages.h index 1a96f569..5bd63cc4 100755 --- a/CPP/7zip/UI/Explorer/MyMessages.h +++ b/CPP/7zip/UI/Explorer/MyMessages.h @@ -3,7 +3,7 @@ #ifndef __MYMESSAGES_H #define __MYMESSAGES_H -#include "Common/String.h" +#include "Common/MyString.h" void MyMessageBox(HWND window, LPCWSTR message); diff --git a/CPP/7zip/UI/Explorer/makefile b/CPP/7zip/UI/Explorer/makefile index cf6321fa..f208988b 100755 --- a/CPP/7zip/UI/Explorer/makefile +++ b/CPP/7zip/UI/Explorer/makefile @@ -21,12 +21,12 @@ COMMON_OBJS = \ $O\NewHandler.obj \ $O\Random.obj \ $O\StdInStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ $O\TextConfig.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ diff --git a/CPP/7zip/UI/Far/ExtractEngine.h b/CPP/7zip/UI/Far/ExtractEngine.h index 57c04f76..ee17ff55 100755 --- a/CPP/7zip/UI/Far/ExtractEngine.h +++ b/CPP/7zip/UI/Far/ExtractEngine.h @@ -4,7 +4,7 @@ #define __EXTRACTENGINE_H #include "Common/MyCom.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "../../IPassword.h" #include "../Agent/IFolderArchive.h" diff --git a/CPP/7zip/UI/Far/Far.dsp b/CPP/7zip/UI/Far/Far.dsp index 327574dd..2cddd717 100755 --- a/CPP/7zip/UI/Far/Far.dsp +++ b/CPP/7zip/UI/Far/Far.dsp @@ -126,35 +126,35 @@ SOURCE=..\..\..\Common\IntToString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StringConvert.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\StringConvert.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\StringConvert.h # End Source File # Begin Source File diff --git a/CPP/7zip/UI/Far/FarUtils.h b/CPP/7zip/UI/Far/FarUtils.h index 4fba193d..4e2f83cd 100755 --- a/CPP/7zip/UI/Far/FarUtils.h +++ b/CPP/7zip/UI/Far/FarUtils.h @@ -4,8 +4,6 @@ #define __FARUTILS_H #include "FarPlugin.h" -#include "Common/String.h" -#include "Common/Vector.h" #include "Windows/Registry.h" namespace NFar { diff --git a/CPP/7zip/UI/Far/OverwriteDialog.cpp b/CPP/7zip/UI/Far/OverwriteDialog.cpp index 1594a350..4fbcbc9f 100755 --- a/CPP/7zip/UI/Far/OverwriteDialog.cpp +++ b/CPP/7zip/UI/Far/OverwriteDialog.cpp @@ -6,7 +6,6 @@ #include "OverwriteDialog.h" -#include "Common/String.h" #include "Common/StringConvert.h" #include "Windows/FileName.h" diff --git a/CPP/7zip/UI/Far/OverwriteDialog.h b/CPP/7zip/UI/Far/OverwriteDialog.h index ff1a480e..6ff4590a 100755 --- a/CPP/7zip/UI/Far/OverwriteDialog.h +++ b/CPP/7zip/UI/Far/OverwriteDialog.h @@ -3,7 +3,7 @@ #ifndef OVERWRITEDIALOG_H #define OVERWRITEDIALOG_H -#include "Common/String.h" +#include "Common/MyString.h" namespace NOverwriteDialog { diff --git a/CPP/7zip/UI/Far/ProgressBox.h b/CPP/7zip/UI/Far/ProgressBox.h index 8721b456..9e6f671a 100755 --- a/CPP/7zip/UI/Far/ProgressBox.h +++ b/CPP/7zip/UI/Far/ProgressBox.h @@ -3,7 +3,7 @@ #ifndef __PROGRESSBOX_H #define __PROGRESSBOX_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" class CMessageBox diff --git a/CPP/7zip/UI/Far/UpdateCallback100.h b/CPP/7zip/UI/Far/UpdateCallback100.h index d66137cc..87c55dc3 100755 --- a/CPP/7zip/UI/Far/UpdateCallback100.h +++ b/CPP/7zip/UI/Far/UpdateCallback100.h @@ -3,7 +3,6 @@ #ifndef __UPDATECALLBACK100_H #define __UPDATECALLBACK100_H -#include "Common/String.h" #include "Common/MyCom.h" #include "../Agent/IFolderArchive.h" diff --git a/CPP/7zip/UI/Far/makefile b/CPP/7zip/UI/Far/makefile index 142226a4..2e22d862 100755 --- a/CPP/7zip/UI/Far/makefile +++ b/CPP/7zip/UI/Far/makefile @@ -22,10 +22,10 @@ FAR_OBJS = \ COMMON_OBJS = \ $O\IntToString.obj \ $O\NewHandler.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ diff --git a/CPP/7zip/UI/GUI/GUI.cpp b/CPP/7zip/UI/GUI/GUI.cpp index 2d401fc8..4f06ff93 100755 --- a/CPP/7zip/UI/GUI/GUI.cpp +++ b/CPP/7zip/UI/GUI/GUI.cpp @@ -12,7 +12,7 @@ extern "C" #include "Common/NewHandler.h" #include "Common/StringConvert.h" #include "Common/CommandLineParser.h" -#include "Common/Exception.h" +#include "Common/MyException.h" #include "Windows/COM.h" #include "Windows/FileMapping.h" diff --git a/CPP/7zip/UI/GUI/GUI.dsp b/CPP/7zip/UI/GUI/GUI.dsp index 9586eebf..54e70732 100755 --- a/CPP/7zip/UI/GUI/GUI.dsp +++ b/CPP/7zip/UI/GUI/GUI.dsp @@ -735,27 +735,35 @@ SOURCE=..\..\..\Common\ListFileUtils.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyString.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyString.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\StdInStream.h +SOURCE=..\..\..\Common\MyVector.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.cpp +SOURCE=..\..\..\Common\NewHandler.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\String.h +SOURCE=..\..\..\Common\StdInStream.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\Common\StdInStream.h # End Source File # Begin Source File @@ -791,14 +799,6 @@ 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 @@ -959,6 +959,10 @@ SOURCE=..\..\..\Windows\Synchronization.h # End Source File # Begin Source File +SOURCE=..\..\..\Windows\System.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\Windows\System.h # End Source File # Begin Source File diff --git a/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp b/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp index 894faefb..f9a78472 100755 --- a/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp +++ b/CPP/7zip/UI/GUI/Resource/BenchmarkDialog/BenchmarkDialog.cpp @@ -4,7 +4,7 @@ #include "Common/IntToString.h" #include "Common/StringToInt.h" -#include "Common/Exception.h" +#include "Common/MyException.h" #include "Windows/Thread.h" #include "Windows/Error.h" #include "Windows/System.h" diff --git a/CPP/7zip/UI/GUI/makefile b/CPP/7zip/UI/GUI/makefile index cd1536fe..cc672b46 100755 --- a/CPP/7zip/UI/GUI/makefile +++ b/CPP/7zip/UI/GUI/makefile @@ -26,12 +26,12 @@ COMMON_OBJS = \ $O\ListFileUtils.obj \ $O\NewHandler.obj \ $O\StdInStream.obj \ - $O\String.obj \ + $O\MyString.obj \ $O\StringConvert.obj \ $O\StringToInt.obj \ $O\TextConfig.obj \ $O\UTFConvert.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ $O\Wildcard.obj \ WIN_OBJS = \ @@ -49,6 +49,7 @@ WIN_OBJS = \ $O\ResourceString.obj \ $O\Shell.obj \ $O\Synchronization.obj \ + $O\System.obj \ $O\Window.obj \ WIN_CTRL_OBJS = \ diff --git a/CPP/Common/AlignedBuffer.cpp b/CPP/Common/AlignedBuffer.cpp deleted file mode 100755 index ec472ced..00000000 --- a/CPP/Common/AlignedBuffer.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// AlignedBuffer.cpp - -#include "StdAfx.h" - -#include "AlignedBuffer.h" - -void *CAlignedBuffer::Allocate(size_t size, size_t mask) -{ - Free(); - m_Buffer = new unsigned char[size + mask]; - unsigned char *p = m_Buffer; - while(((size_t)p & mask) != 0) - p++; - return (void *)p; -} - -void CAlignedBuffer::Free() -{ - if (m_Buffer != 0) - delete []m_Buffer; - m_Buffer = 0; -} diff --git a/CPP/Common/AlignedBuffer.h b/CPP/Common/AlignedBuffer.h deleted file mode 100755 index d040463e..00000000 --- a/CPP/Common/AlignedBuffer.h +++ /dev/null @@ -1,18 +0,0 @@ -// Common/AlignedBuffer.h - -#ifndef __COMMON_ALIGNEDBUFFER_H -#define __COMMON_ALIGNEDBUFFER_H - -#include - -class CAlignedBuffer -{ - unsigned char *m_Buffer; -public: - CAlignedBuffer(): m_Buffer(0) {}; - ~CAlignedBuffer() { Free(); } - void *Allocate(size_t size, size_t mask); - void Free(); -}; - -#endif diff --git a/CPP/Common/CommandLineParser.h b/CPP/Common/CommandLineParser.h index af698db8..a97f58a5 100755 --- a/CPP/Common/CommandLineParser.h +++ b/CPP/Common/CommandLineParser.h @@ -3,7 +3,7 @@ #ifndef __COMMON_COMMANDLINEPARSER_H #define __COMMON_COMMANDLINEPARSER_H -#include "Common/String.h" +#include "MyString.h" namespace NCommandLineParser { diff --git a/CPP/Common/Exception.h b/CPP/Common/Exception.h deleted file mode 100755 index d7f86a90..00000000 --- a/CPP/Common/Exception.h +++ /dev/null @@ -1,13 +0,0 @@ -// Common/Exception.h - -#ifndef __COMMON_EXCEPTION_H -#define __COMMON_EXCEPTION_H - -struct CSystemException -{ - DWORD ErrorCode; - CSystemException(): ErrorCode(::GetLastError()) {} - CSystemException(DWORD errorCode): ErrorCode(errorCode) {} -}; - -#endif diff --git a/CPP/Common/Lang.cpp b/CPP/Common/Lang.cpp index f1861d6e..803209cf 100755 --- a/CPP/Common/Lang.cpp +++ b/CPP/Common/Lang.cpp @@ -2,8 +2,8 @@ #include "StdAfx.h" -#include "Common/Lang.h" -#include "Common/TextConfig.h" +#include "Lang.h" +#include "TextConfig.h" #include "StdInStream.h" #include "UTFConvert.h" diff --git a/CPP/Common/Lang.h b/CPP/Common/Lang.h index 2b4615d0..acbf8a6b 100755 --- a/CPP/Common/Lang.h +++ b/CPP/Common/Lang.h @@ -3,9 +3,9 @@ #ifndef __COMMON_LANG_H #define __COMMON_LANG_H -#include "Common/Vector.h" -#include "Common/String.h" -#include "Common/Types.h" +#include "MyVector.h" +#include "MyString.h" +#include "Types.h" struct CLangPair { diff --git a/CPP/Common/ListFileUtils.h b/CPP/Common/ListFileUtils.h index 93bb4507..182d32fa 100755 --- a/CPP/Common/ListFileUtils.h +++ b/CPP/Common/ListFileUtils.h @@ -3,10 +3,9 @@ #ifndef __COMMON_LISTFILEUTILS_H #define __COMMON_LISTFILEUTILS_H -#include "Common/String.h" -#include "Common/Types.h" +#include "MyString.h" +#include "Types.h" -bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &strings, - UINT codePage = CP_OEMCP); +bool ReadNamesFromListFile(LPCTSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP); #endif diff --git a/CPP/Common/MyException.h b/CPP/Common/MyException.h new file mode 100755 index 00000000..f0ad1115 --- /dev/null +++ b/CPP/Common/MyException.h @@ -0,0 +1,14 @@ +// Common/Exception.h + +#ifndef __COMMON_EXCEPTION_H +#define __COMMON_EXCEPTION_H + +#include "MyWindows.h" + +struct CSystemException +{ + HRESULT ErrorCode; + CSystemException(HRESULT errorCode): ErrorCode(errorCode) {} +}; + +#endif diff --git a/CPP/Common/MyString.cpp b/CPP/Common/MyString.cpp new file mode 100755 index 00000000..affdcb0b --- /dev/null +++ b/CPP/Common/MyString.cpp @@ -0,0 +1,198 @@ +// Common/MyString.cpp + +#include "StdAfx.h" + +#ifdef _WIN32 +#include "StringConvert.h" +#else +#include +#endif + +#include "MyString.h" + + +#ifdef _WIN32 + +#ifndef _UNICODE + +wchar_t MyCharUpper(wchar_t c) +{ + if (c == 0) + return 0; + wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); + if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + 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); + if (numChars == 0 || numChars > kBufferSize) + return c; + s[numChars] = 0; + ::CharUpperA(s); + ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1); + return c; +} + +wchar_t MyCharLower(wchar_t c) +{ + if (c == 0) + return 0; + wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); + if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + 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); + if (numChars == 0 || numChars > kBufferSize) + return c; + s[numChars] = 0; + ::CharLowerA(s); + ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1); + return c; +} + +wchar_t * MyStringUpper(wchar_t *s) +{ + if (s == 0) + return 0; + wchar_t *res = CharUpperW(s); + if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + return res; + AString a = UnicodeStringToMultiByte(s); + a.MakeUpper(); + return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a)); +} + +wchar_t * MyStringLower(wchar_t *s) +{ + if (s == 0) + return 0; + wchar_t *res = CharLowerW(s); + if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + return res; + AString a = UnicodeStringToMultiByte(s); + a.MakeLower(); + return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a)); +} + +#endif + +/* +inline int ConvertCompareResult(int r) { return r - 2; } + +int MyStringCollate(const wchar_t *s1, const wchar_t *s2) +{ + int res = CompareStringW( + LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); + #ifdef _UNICODE + return ConvertCompareResult(res); + #else + if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + return ConvertCompareResult(res); + return MyStringCollate(UnicodeStringToMultiByte(s1), + UnicodeStringToMultiByte(s2)); + #endif +} + +#ifndef _WIN32_WCE +int MyStringCollate(const char *s1, const char *s2) +{ + return ConvertCompareResult(CompareStringA( + LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); +} + +int MyStringCollateNoCase(const char *s1, const char *s2) +{ + return ConvertCompareResult(CompareStringA( + LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); +} +#endif + +int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2) +{ + int res = CompareStringW( + LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); + #ifdef _UNICODE + return ConvertCompareResult(res); + #else + if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) + return ConvertCompareResult(res); + return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), + UnicodeStringToMultiByte(s2)); + #endif +} +*/ + +#else + +wchar_t MyCharUpper(wchar_t c) +{ + return toupper(c); +} + +/* +int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2) +{ + for (;;) + { + wchar_t c1 = *s1++; + wchar_t c2 = *s2++; + wchar_t u1 = MyCharUpper(c1); + wchar_t u2 = MyCharUpper(c2); + + if (u1 < u2) return -1; + if (u1 > u2) return 1; + if (u1 == 0) return 0; + } +} +*/ + +#endif + +int MyStringCompare(const char *s1, const char *s2) +{ + for (;;) + { + unsigned char c1 = (unsigned char)*s1++; + unsigned char c2 = (unsigned char)*s2++; + if (c1 < c2) return -1; + if (c1 > c2) return 1; + if (c1 == 0) return 0; + } +} + +int MyStringCompare(const wchar_t *s1, const wchar_t *s2) +{ + for (;;) + { + wchar_t c1 = *s1++; + wchar_t c2 = *s2++; + if (c1 < c2) return -1; + if (c1 > c2) return 1; + if (c1 == 0) return 0; + } +} + +int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) +{ + for (;;) + { + wchar_t c1 = *s1++; + wchar_t c2 = *s2++; + if (c1 != c2) + { + wchar_t u1 = MyCharUpper(c1); + wchar_t u2 = MyCharUpper(c2); + if (u1 < u2) return -1; + if (u1 > u2) return 1; + } + if (c1 == 0) return 0; + } +} + +#ifdef _WIN32 +int MyStringCompareNoCase(const char *s1, const char *s2) +{ + return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2)); +} +#endif diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h new file mode 100755 index 00000000..c46ca545 --- /dev/null +++ b/CPP/Common/MyString.h @@ -0,0 +1,636 @@ +// Common/String.h + +#ifndef __COMMON_STRING_H +#define __COMMON_STRING_H + +#include +// #include + +#include "MyVector.h" + +#ifdef _WIN32 +#include "MyWindows.h" +#endif + +template +inline int MyStringLen(const T *s) +{ + int i; + for (i = 0; s[i] != '\0'; i++); + return i; +} + +template +inline T * MyStringCopy(T *dest, const T *src) +{ + T *destStart = dest; + while((*dest++ = *src++) != 0); + return destStart; +} + +inline wchar_t* MyStringGetNextCharPointer(wchar_t *p) + { return (p + 1); } +inline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p) + { return (p + 1); } +inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p) + { return (p - 1); } +inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p) + { return (p - 1); } + +#ifdef _WIN32 + +inline char* MyStringGetNextCharPointer(char *p) + { return CharNextA(p); } +inline const char* MyStringGetNextCharPointer(const char *p) + { return CharNextA(p); } + +inline char* MyStringGetPrevCharPointer(char *base, char *p) + { return CharPrevA(base, p); } +inline const char* MyStringGetPrevCharPointer(const char *base, const char *p) + { return CharPrevA(base, p); } + +inline char MyCharUpper(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)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); } +#else +wchar_t MyCharUpper(wchar_t c); +#endif + +inline char MyCharLower(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)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); } +#else +wchar_t MyCharLower(wchar_t c); +#endif + +inline char * MyStringUpper(char *s) { return CharUpperA(s); } +#ifdef _UNICODE +inline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); } +#else +wchar_t * MyStringUpper(wchar_t *s); +#endif + +inline char * MyStringLower(char *s) { return CharLowerA(s); } +#ifdef _UNICODE +inline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); } +#else +wchar_t * MyStringLower(wchar_t *s); +#endif + +#else // Standard-C +wchar_t MyCharUpper(wchar_t c); +#endif + +////////////////////////////////////// +// Compare + +/* +#ifndef _WIN32_WCE +int MyStringCollate(const char *s1, const char *s2); +int MyStringCollateNoCase(const char *s1, const char *s2); +#endif +int MyStringCollate(const wchar_t *s1, const wchar_t *s2); +int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2); +*/ + +int MyStringCompare(const char *s1, const char *s2); +int MyStringCompare(const wchar_t *s1, const wchar_t *s2); + +#ifdef _WIN32 +int MyStringCompareNoCase(const char *s1, const char *s2); +#endif + +int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2); + +template +class CStringBase +{ + void TrimLeftWithCharSet(const CStringBase &charSet) + { + const T *p = _chars; + while (charSet.Find(*p) >= 0 && (*p != 0)) + p = GetNextCharPointer(p); + Delete(0, (int)(p - _chars)); + } + void TrimRightWithCharSet(const CStringBase &charSet) + { + const T *p = _chars; + const T *pLast = NULL; + while (*p != 0) + { + if (charSet.Find(*p) >= 0) + { + if (pLast == NULL) + pLast = p; + } + else + pLast = NULL; + p = GetNextCharPointer(p); + } + if(pLast != NULL) + { + int i = (int)(pLast - _chars); + Delete(i, _length - i); + } + + } + void MoveItems(int destIndex, int srcIndex) + { + memmove(_chars + destIndex, _chars + srcIndex, + sizeof(T) * (_length - srcIndex + 1)); + } + + void InsertSpace(int &index, int size) + { + CorrectIndex(index); + GrowLength(size); + MoveItems(index + size, index); + } + + static T *GetNextCharPointer(T *p) + { return MyStringGetNextCharPointer(p); } + static const T *GetNextCharPointer(const T *p) + { return MyStringGetNextCharPointer(p); } + static T *GetPrevCharPointer(T *base, T *p) + { return MyStringGetPrevCharPointer(base, p); } + static const T *GetPrevCharPointer(const T *base, const T *p) + { return MyStringGetPrevCharPointer(base, p); } +protected: + T *_chars; + int _length; + int _capacity; + + void SetCapacity(int newCapacity) + { + int realCapacity = newCapacity + 1; + if(realCapacity == _capacity) + return; + /* + const int kMaxStringSize = 0x20000000; + #ifndef _WIN32_WCE + if(newCapacity > kMaxStringSize || newCapacity < _length) + throw 1052337; + #endif + */ + T *newBuffer = new T[realCapacity]; + if(_capacity > 0) + { + for (int i = 0; i < (_length + 1); i++) + newBuffer[i] = _chars[i]; + delete []_chars; + _chars = newBuffer; + } + else + { + _chars = newBuffer; + _chars[0] = 0; + } + _capacity = realCapacity; + } + + void GrowLength(int n) + { + int freeSize = _capacity - _length - 1; + if (n <= freeSize) + return; + int delta; + if (_capacity > 64) + delta = _capacity / 2; + else if (_capacity > 8) + delta = 16; + else + delta = 4; + if (freeSize + delta < n) + delta = n - freeSize; + SetCapacity(_capacity + delta); + } + + void CorrectIndex(int &index) const + { + if (index > _length) + index = _length; + } + +public: + CStringBase(): _chars(0), _length(0), _capacity(0) + { SetCapacity(16 - 1); } + CStringBase(T c): _chars(0), _length(0), _capacity(0) + { + SetCapacity(1); + _chars[0] = c; + _chars[1] = 0; + _length = 1; + } + CStringBase(const T *chars): _chars(0), _length(0), _capacity(0) + { + int length = MyStringLen(chars); + SetCapacity(length); + MyStringCopy(_chars, chars); // can be optimized by memove() + _length = length; + } + CStringBase(const CStringBase &s): _chars(0), _length(0), _capacity(0) + { + SetCapacity(s._length); + MyStringCopy(_chars, s._chars); + _length = s._length; + } + ~CStringBase() { delete []_chars; } + + operator const T*() const { return _chars;} + + // The minimum size of the character buffer in characters. + // This value does not include space for a null terminator. + T* GetBuffer(int minBufLength) + { + if(minBufLength >= _capacity) + SetCapacity(minBufLength + 1); + return _chars; + } + void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); } + void ReleaseBuffer(int newLength) + { + /* + #ifndef _WIN32_WCE + if(newLength >= _capacity) + throw 282217; + #endif + */ + _chars[newLength] = 0; + _length = newLength; + } + + CStringBase& operator=(T c) + { + Empty(); + SetCapacity(1); + _chars[0] = c; + _chars[1] = 0; + _length = 1; + return *this; + } + CStringBase& operator=(const T *chars) + { + Empty(); + int length = MyStringLen(chars); + SetCapacity(length); + MyStringCopy(_chars, chars); + _length = length; + return *this; + } + CStringBase& operator=(const CStringBase& s) + { + if(&s == this) + return *this; + Empty(); + SetCapacity(s._length); + MyStringCopy(_chars, s._chars); + _length = s._length; + return *this; + } + + CStringBase& operator+=(T c) + { + GrowLength(1); + _chars[_length] = c; + _chars[++_length] = 0; + return *this; + } + CStringBase& operator+=(const T *s) + { + int len = MyStringLen(s); + GrowLength(len); + MyStringCopy(_chars + _length, s); + _length += len; + return *this; + } + CStringBase& operator+=(const CStringBase &s) + { + GrowLength(s._length); + MyStringCopy(_chars + _length, s._chars); + _length += s._length; + return *this; + } + void Empty() + { + _length = 0; + _chars[0] = 0; + } + int Length() const { return _length; } + bool IsEmpty() const { return (_length == 0); } + + CStringBase Mid(int startIndex) const + { return Mid(startIndex, _length - startIndex); } + CStringBase Mid(int startIndex, int count ) const + { + if (startIndex + count > _length) + count = _length - startIndex; + + if (startIndex == 0 && startIndex + count == _length) + return *this; + + CStringBase result; + result.SetCapacity(count); + // MyStringNCopy(result._chars, _chars + startIndex, count); + for (int i = 0; i < count; i++) + result._chars[i] = _chars[startIndex + i]; + result._chars[count] = 0; + result._length = count; + return result; + } + CStringBase Left(int count) const + { return Mid(0, count); } + CStringBase Right(int count) const + { + if (count > _length) + count = _length; + return Mid(_length - count, count); + } + + void MakeUpper() + { MyStringUpper(_chars); } + void MakeLower() + { MyStringLower(_chars); } + + int Compare(const CStringBase& s) const + { return MyStringCompare(_chars, s._chars); } + + int Compare(const T *s) const + { return MyStringCompare(_chars, s); } + + int CompareNoCase(const CStringBase& s) const + { return MyStringCompareNoCase(_chars, s._chars); } + + int CompareNoCase(const T *s) const + { return MyStringCompareNoCase(_chars, s); } + + /* + int Collate(const CStringBase& s) const + { return MyStringCollate(_chars, s._chars); } + int CollateNoCase(const CStringBase& s) const + { return MyStringCollateNoCase(_chars, s._chars); } + */ + + int Find(T c) const { return Find(c, 0); } + int Find(T c, int startIndex) const + { + T *p = _chars + startIndex; + for (;;) + { + if (*p == c) + return (int)(p - _chars); + if (*p == 0) + return -1; + p = GetNextCharPointer(p); + } + } + int Find(const CStringBase &s) const { return Find(s, 0); } + int Find(const CStringBase &s, int startIndex) const + { + if (s.IsEmpty()) + return startIndex; + for (; startIndex < _length; startIndex++) + { + int j; + for (j = 0; j < s._length && startIndex + j < _length; j++) + if (_chars[startIndex+j] != s._chars[j]) + break; + if (j == s._length) + return startIndex; + } + return -1; + } + int ReverseFind(T c) const + { + if (_length == 0) + return -1; + T *p = _chars + _length - 1; + for (;;) + { + if (*p == c) + return (int)(p - _chars); + if (p == _chars) + return -1; + p = GetPrevCharPointer(_chars, p); + } + } + int FindOneOf(const CStringBase &s) const + { + for(int i = 0; i < _length; i++) + if (s.Find(_chars[i]) >= 0) + return i; + return -1; + } + + void TrimLeft(T c) + { + const T *p = _chars; + while (c == *p) + p = GetNextCharPointer(p); + Delete(0, p - _chars); + } + private: + CStringBase GetTrimDefaultCharSet() + { + CStringBase charSet; + charSet += (T)' '; + charSet += (T)'\n'; + charSet += (T)'\t'; + return charSet; + } + public: + + void TrimLeft() + { + TrimLeftWithCharSet(GetTrimDefaultCharSet()); + } + void TrimRight() + { + TrimRightWithCharSet(GetTrimDefaultCharSet()); + } + void TrimRight(T c) + { + const T *p = _chars; + const T *pLast = NULL; + while (*p != 0) + { + if (*p == c) + { + if (pLast == NULL) + pLast = p; + } + else + pLast = NULL; + p = GetNextCharPointer(p); + } + if(pLast != NULL) + { + int i = pLast - _chars; + Delete(i, _length - i); + } + } + void Trim() + { + TrimRight(); + TrimLeft(); + } + + int Insert(int index, T c) + { + InsertSpace(index, 1); + _chars[index] = c; + _length++; + return _length; + } + int Insert(int index, const CStringBase &s) + { + CorrectIndex(index); + if (s.IsEmpty()) + return _length; + int numInsertChars = s.Length(); + InsertSpace(index, numInsertChars); + for(int i = 0; i < numInsertChars; i++) + _chars[index + i] = s[i]; + _length += numInsertChars; + return _length; + } + + // !!!!!!!!!!!!!!! test it if newChar = '\0' + int Replace(T oldChar, T newChar) + { + if (oldChar == newChar) + return 0; + int number = 0; + int pos = 0; + while (pos < Length()) + { + pos = Find(oldChar, pos); + if (pos < 0) + break; + _chars[pos] = newChar; + pos++; + number++; + } + return number; + } + int Replace(const CStringBase &oldString, const CStringBase &newString) + { + if (oldString.IsEmpty()) + return 0; + if (oldString == newString) + return 0; + int oldStringLength = oldString.Length(); + int newStringLength = newString.Length(); + int number = 0; + int pos = 0; + while (pos < _length) + { + pos = Find(oldString, pos); + if (pos < 0) + break; + Delete(pos, oldStringLength); + Insert(pos, newString); + pos += newStringLength; + number++; + } + return number; + } + int Delete(int index, int count = 1 ) + { + if (index + count > _length) + count = _length - index; + if (count > 0) + { + MoveItems(index, index + count); + _length -= count; + } + return _length; + } +}; + +template +CStringBase operator+(const CStringBase& s1, const CStringBase& s2) +{ + CStringBase result(s1); + result += s2; + return result; +} + +template +CStringBase operator+(const CStringBase& s, T c) +{ + CStringBase result(s); + result += c; + return result; +} + +template +CStringBase operator+(T c, const CStringBase& s) +{ + CStringBase result(c); + result += s; + return result; +} + +template +CStringBase operator+(const CStringBase& s, const T * chars) +{ + CStringBase result(s); + result += chars; + return result; +} + +template +CStringBase operator+(const T * chars, const CStringBase& s) +{ + CStringBase result(chars); + result += s; + return result; +} + +template +bool operator==(const CStringBase& s1, const CStringBase& s2) + { return (s1.Compare(s2) == 0); } + +template +bool operator<(const CStringBase& s1, const CStringBase& s2) + { return (s1.Compare(s2) < 0); } + +template +bool operator==(const T *s1, const CStringBase& s2) + { return (s2.Compare(s1) == 0); } + +template +bool operator==(const CStringBase& s1, const T *s2) + { return (s1.Compare(s2) == 0); } + +template +bool operator!=(const CStringBase& s1, const CStringBase& s2) + { return (s1.Compare(s2) != 0); } + +template +bool operator!=(const T *s1, const CStringBase& s2) + { return (s2.Compare(s1) != 0); } + +template +bool operator!=(const CStringBase& s1, const T *s2) + { return (s1.Compare(s2) != 0); } + +typedef CStringBase AString; +typedef CStringBase UString; + +typedef CObjectVector AStringVector; +typedef CObjectVector UStringVector; + +#ifdef _UNICODE + typedef UString CSysString; +#else + typedef AString CSysString; +#endif + +typedef CObjectVector CSysStringVector; + +#endif diff --git a/CPP/Common/MyVector.cpp b/CPP/Common/MyVector.cpp new file mode 100755 index 00000000..86e56da0 --- /dev/null +++ b/CPP/Common/MyVector.cpp @@ -0,0 +1,83 @@ +// Common/MyVector.cpp + +#include "StdAfx.h" + +#include + +#include "MyVector.h" + +CBaseRecordVector::~CBaseRecordVector() + { Free(); } + +void CBaseRecordVector::Free() +{ + delete []((unsigned char *)_items); + _capacity = 0; + _size = 0; + _items = 0; +} + +void CBaseRecordVector::Clear() + { DeleteFrom(0); } +void CBaseRecordVector::DeleteBack() + { Delete(_size - 1); } +void CBaseRecordVector::DeleteFrom(int index) + { Delete(index, _size - index); } + +void CBaseRecordVector::ReserveOnePosition() +{ + if(_size != _capacity) + return; + int delta; + if (_capacity > 64) + delta = _capacity / 2; + else if (_capacity > 8) + delta = 8; + else + delta = 4; + Reserve(_capacity + delta); +} + +void CBaseRecordVector::Reserve(int newCapacity) +{ + if(newCapacity <= _capacity) + return; + /* + #ifndef _DEBUG + static const unsigned int kMaxVectorSize = 0xF0000000; + if(newCapacity < _size || + ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) + throw 1052354; + #endif + */ + unsigned char *p = new unsigned char[newCapacity * _itemSize]; + int numRecordsToMove = _capacity; + memmove(p, _items, _itemSize * numRecordsToMove); + delete [](unsigned char *)_items; + _items = p; + _capacity = newCapacity; +} + +void CBaseRecordVector::MoveItems(int destIndex, int srcIndex) +{ + memmove(((unsigned char *)_items) + destIndex * _itemSize, + ((unsigned char *)_items) + srcIndex * _itemSize, + _itemSize * (_size - srcIndex)); +} + +void CBaseRecordVector::InsertOneItem(int index) +{ + ReserveOnePosition(); + MoveItems(index + 1, index); + _size++; +} + +void CBaseRecordVector::Delete(int index, int num) +{ + TestIndexAndCorrectNum(index, num); + if (num > 0) + { + MoveItems(index, index + num); + _size -= num; + } +} diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h new file mode 100755 index 00000000..1bb67a1d --- /dev/null +++ b/CPP/Common/MyVector.h @@ -0,0 +1,237 @@ +// Common/Vector.h + +#ifndef __COMMON_VECTOR_H +#define __COMMON_VECTOR_H + +#include "Defs.h" + +class CBaseRecordVector +{ + void MoveItems(int destIndex, int srcIndex); +protected: + int _capacity; + int _size; + void *_items; + size_t _itemSize; + + void ReserveOnePosition(); + void InsertOneItem(int index); + void TestIndexAndCorrectNum(int index, int &num) const + { if (index + num > _size) num = _size - index; } +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(); + void DeleteFrom(int index); + void DeleteBack(); +}; + +template +class CRecordVector: public CBaseRecordVector +{ +public: + CRecordVector():CBaseRecordVector(sizeof(T)){}; + CRecordVector(const CRecordVector &v): + CBaseRecordVector(sizeof(T)) { *this = v;} + CRecordVector& operator=(const CRecordVector &v) + { + Clear(); + return (*this += v); + } + CRecordVector& operator+=(const CRecordVector &v) + { + int size = v.Size(); + Reserve(Size() + size); + for(int i = 0; i < size; i++) + Add(v[i]); + return *this; + } + int Add(T item) + { + ReserveOnePosition(); + ((T *)_items)[_size] = item; + return _size++; + } + void Insert(int index, T item) + { + InsertOneItem(index); + ((T *)_items)[index] = item; + } + // T* GetPointer() const { return (T*)_items; } + // operator const T *() const { return _items; }; + const T& operator[](int index) const { return ((T *)_items)[index]; } + T& operator[](int index) { return ((T *)_items)[index]; } + const T& Front() const { return operator[](0); } + T& Front() { return operator[](0); } + const T& Back() const { return operator[](_size - 1); } + T& Back() { return operator[](_size - 1); } + + void Swap(int i, int j) + { + T temp = operator[](i); + operator[](i) = operator[](j); + operator[](j) = temp; + } + + int FindInSorted(const T& item) const + { + int left = 0, right = Size(); + while (left != right) + { + int mid = (left + right) / 2; + const T& midValue = (*this)[mid]; + if (item == midValue) + return mid; + if (item < midValue) + right = mid; + else + left = mid + 1; + } + return -1; + } + + + static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param) + { + T temp = p[k]; + for (;;) + { + int s = (k << 1); + if (s > size) + break; + if (s < size && compare(p + s + 1, p + s, param) > 0) + s++; + if (compare(&temp, p + s, param) >= 0) + break; + p[k] = p[s]; + k = s; + } + p[k] = temp; + } + + void Sort(int (*compare)(const T*, const T*, void *), void *param) + { + int size = _size; + if (size <= 1) + return; + T* p = (&Front()) - 1; + { + int i = size / 2; + do + SortRefDown(p, i, size, compare, param); + while(--i != 0); + } + do + { + T temp = p[size]; + p[size--] = p[1]; + p[1] = temp; + SortRefDown(p, 1, size, compare, param); + } + while (size > 1); + } +}; + +typedef CRecordVector CIntVector; +typedef CRecordVector CUIntVector; +typedef CRecordVector CBoolVector; +typedef CRecordVector CByteVector; +typedef CRecordVector CPointerVector; + +template +class CObjectVector: public CPointerVector +{ +public: + CObjectVector(){}; + ~CObjectVector() { Clear(); } + CObjectVector(const CObjectVector &objectVector) + { *this = objectVector; } + CObjectVector& operator=(const CObjectVector &objectVector) + { + Clear(); + return (*this += objectVector); + } + CObjectVector& operator+=(const CObjectVector &objectVector) + { + int size = objectVector.Size(); + Reserve(Size() + size); + for(int i = 0; i < size; i++) + Add(objectVector[i]); + return *this; + } + const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); } + T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); } + T& Front() { return operator[](0); } + const T& Front() const { return operator[](0); } + T& Back() { return operator[](_size - 1); } + const T& Back() const { return operator[](_size - 1); } + int Add(const T& item) + { return CPointerVector::Add(new T(item)); } + void Insert(int index, const T& item) + { CPointerVector::Insert(index, new T(item)); } + virtual void Delete(int index, int num = 1) + { + TestIndexAndCorrectNum(index, num); + for(int i = 0; i < num; i++) + delete (T *)(((void **)_items)[index + i]); + CPointerVector::Delete(index, num); + } + int Find(const T& item) const + { + for(int i = 0; i < Size(); i++) + if (item == (*this)[i]) + return i; + return -1; + } + int FindInSorted(const T& item) const + { + int left = 0, right = Size(); + while (left != right) + { + int mid = (left + right) / 2; + const T& midValue = (*this)[mid]; + if (item == midValue) + return mid; + if (item < midValue) + right = mid; + else + left = mid + 1; + } + return -1; + } + int AddToSorted(const T& item) + { + int left = 0, right = Size(); + while (left != right) + { + int mid = (left + right) / 2; + const T& midValue = (*this)[mid]; + if (item == midValue) + { + right = mid + 1; + break; + } + if (item < midValue) + right = mid; + else + left = mid + 1; + } + Insert(right, item); + return right; + } + + 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 */) + { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); } + void Sort() { CPointerVector::Sort(CompareObjectItems, 0); } +}; + +#endif diff --git a/CPP/Common/Random.cpp b/CPP/Common/Random.cpp index f4a629c2..9519987e 100755 --- a/CPP/Common/Random.cpp +++ b/CPP/Common/Random.cpp @@ -5,7 +5,7 @@ #include #include -#include "Common/Random.h" +#include "Random.h" void CRandom::Init(unsigned int seed) { srand(seed); } diff --git a/CPP/Common/StdInStream.h b/CPP/Common/StdInStream.h index c1a0a222..e0fb3dfa 100755 --- a/CPP/Common/StdInStream.h +++ b/CPP/Common/StdInStream.h @@ -5,7 +5,7 @@ #include -#include "Common/String.h" +#include "MyString.h" #include "Types.h" class CStdInStream diff --git a/CPP/Common/StdOutStream.cpp b/CPP/Common/StdOutStream.cpp index 5f1ef0fc..5498c0cc 100755 --- a/CPP/Common/StdOutStream.cpp +++ b/CPP/Common/StdOutStream.cpp @@ -5,8 +5,8 @@ #include #include "StdOutStream.h" -#include "Common/IntToString.h" -#include "Common/StringConvert.h" +#include "IntToString.h" +#include "StringConvert.h" #ifdef _MSC_VER // "was declared deprecated" disabling diff --git a/CPP/Common/String.cpp b/CPP/Common/String.cpp deleted file mode 100755 index 34da1487..00000000 --- a/CPP/Common/String.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// Common/String.cpp - -#include "StdAfx.h" - -#ifdef _WIN32 -#include "StringConvert.h" -#else -#include -#endif - -#include "String.h" - - -#ifdef _WIN32 - -#ifndef _UNICODE - -wchar_t MyCharUpper(wchar_t c) -{ - if (c == 0) - return 0; - wchar_t *res = CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - 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); - if (numChars == 0 || numChars > kBufferSize) - return c; - s[numChars] = 0; - ::CharUpperA(s); - ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1); - return c; -} - -wchar_t MyCharLower(wchar_t c) -{ - if (c == 0) - return 0; - wchar_t *res = CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - 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); - if (numChars == 0 || numChars > kBufferSize) - return c; - s[numChars] = 0; - ::CharLowerA(s); - ::MultiByteToWideChar(CP_ACP, 0, s, numChars, &c, 1); - return c; -} - -wchar_t * MyStringUpper(wchar_t *s) -{ - if (s == 0) - return 0; - wchar_t *res = CharUpperW(s); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return res; - AString a = UnicodeStringToMultiByte(s); - a.MakeUpper(); - return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a)); -} - -wchar_t * MyStringLower(wchar_t *s) -{ - if (s == 0) - return 0; - wchar_t *res = CharLowerW(s); - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return res; - AString a = UnicodeStringToMultiByte(s); - a.MakeLower(); - return MyStringCopy(s, (const wchar_t *)MultiByteToUnicodeString(a)); -} - -#endif - -/* -inline int ConvertCompareResult(int r) { return r - 2; } - -int MyStringCollate(const wchar_t *s1, const wchar_t *s2) -{ - int res = CompareStringW( - LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1); - #ifdef _UNICODE - return ConvertCompareResult(res); - #else - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return ConvertCompareResult(res); - return MyStringCollate(UnicodeStringToMultiByte(s1), - UnicodeStringToMultiByte(s2)); - #endif -} - -#ifndef _WIN32_WCE -int MyStringCollate(const char *s1, const char *s2) -{ - return ConvertCompareResult(CompareStringA( - LOCALE_USER_DEFAULT, SORT_STRINGSORT, s1, -1, s2, -1)); -} - -int MyStringCollateNoCase(const char *s1, const char *s2) -{ - return ConvertCompareResult(CompareStringA( - LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1)); -} -#endif - -int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2) -{ - int res = CompareStringW( - LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, s1, -1, s2, -1); - #ifdef _UNICODE - return ConvertCompareResult(res); - #else - if (res != 0 || ::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) - return ConvertCompareResult(res); - return MyStringCollateNoCase(UnicodeStringToMultiByte(s1), - UnicodeStringToMultiByte(s2)); - #endif -} -*/ - -#else - -wchar_t MyCharUpper(wchar_t c) -{ - return toupper(c); -} - -/* -int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2) -{ - for (;;) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - wchar_t u1 = MyCharUpper(c1); - wchar_t u2 = MyCharUpper(c2); - - if (u1 < u2) return -1; - if (u1 > u2) return 1; - if (u1 == 0) return 0; - } -} -*/ - -#endif - -int MyStringCompare(const char *s1, const char *s2) -{ - for (;;) - { - unsigned char c1 = (unsigned char)*s1++; - unsigned char c2 = (unsigned char)*s2++; - if (c1 < c2) return -1; - if (c1 > c2) return 1; - if (c1 == 0) return 0; - } -} - -int MyStringCompare(const wchar_t *s1, const wchar_t *s2) -{ - for (;;) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - if (c1 < c2) return -1; - if (c1 > c2) return 1; - if (c1 == 0) return 0; - } -} - -int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) -{ - for (;;) - { - wchar_t c1 = *s1++; - wchar_t c2 = *s2++; - if (c1 != c2) - { - wchar_t u1 = MyCharUpper(c1); - wchar_t u2 = MyCharUpper(c2); - if (u1 < u2) return -1; - if (u1 > u2) return 1; - } - if (c1 == 0) return 0; - } -} - -#ifdef _WIN32 -int MyStringCompareNoCase(const char *s1, const char *s2) -{ - return MyStringCompareNoCase(MultiByteToUnicodeString(s1), MultiByteToUnicodeString(s2)); -} -#endif diff --git a/CPP/Common/String.h b/CPP/Common/String.h deleted file mode 100755 index 6ec5b8f3..00000000 --- a/CPP/Common/String.h +++ /dev/null @@ -1,629 +0,0 @@ -// Common/String.h - -#ifndef __COMMON_STRING_H -#define __COMMON_STRING_H - -#include -// #include - -#include "Vector.h" - -#ifdef _WIN32 -#include "MyWindows.h" -#endif - -template -inline int MyStringLen(const T *s) -{ - int i; - for (i = 0; s[i] != '\0'; i++); - return i; -} - -template -inline T * MyStringCopy(T *dest, const T *src) -{ - T *destStart = dest; - while((*dest++ = *src++) != 0); - return destStart; -} - -inline wchar_t* MyStringGetNextCharPointer(wchar_t *p) - { return (p + 1); } -inline const wchar_t* MyStringGetNextCharPointer(const wchar_t *p) - { return (p + 1); } -inline wchar_t* MyStringGetPrevCharPointer(const wchar_t *, wchar_t *p) - { return (p - 1); } -inline const wchar_t* MyStringGetPrevCharPointer(const wchar_t *, const wchar_t *p) - { return (p - 1); } - -#ifdef _WIN32 - -inline char* MyStringGetNextCharPointer(char *p) - { return CharNextA(p); } -inline const char* MyStringGetNextCharPointer(const char *p) - { return CharNextA(p); } - -inline char* MyStringGetPrevCharPointer(char *base, char *p) - { return CharPrevA(base, p); } -inline const char* MyStringGetPrevCharPointer(const char *base, const char *p) - { return CharPrevA(base, p); } - -inline char MyCharUpper(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)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); } -#else -wchar_t MyCharUpper(wchar_t c); -#endif - -inline char MyCharLower(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)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); } -#else -wchar_t MyCharLower(wchar_t c); -#endif - -inline char * MyStringUpper(char *s) { return CharUpperA(s); } -#ifdef _UNICODE -inline wchar_t * MyStringUpper(wchar_t *s) { return CharUpperW(s); } -#else -wchar_t * MyStringUpper(wchar_t *s); -#endif - -inline char * MyStringLower(char *s) { return CharLowerA(s); } -#ifdef _UNICODE -inline wchar_t * MyStringLower(wchar_t *s) { return CharLowerW(s); } -#else -wchar_t * MyStringLower(wchar_t *s); -#endif - -#else // Standard-C -wchar_t MyCharUpper(wchar_t c); -#endif - -////////////////////////////////////// -// Compare - -/* -#ifndef _WIN32_WCE -int MyStringCollate(const char *s1, const char *s2); -int MyStringCollateNoCase(const char *s1, const char *s2); -#endif -int MyStringCollate(const wchar_t *s1, const wchar_t *s2); -int MyStringCollateNoCase(const wchar_t *s1, const wchar_t *s2); -*/ - -int MyStringCompare(const char *s1, const char *s2); -int MyStringCompare(const wchar_t *s1, const wchar_t *s2); - -#ifdef _WIN32 -int MyStringCompareNoCase(const char *s1, const char *s2); -#endif - -int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2); - -template -class CStringBase -{ - void TrimLeftWithCharSet(const CStringBase &charSet) - { - const T *p = _chars; - while (charSet.Find(*p) >= 0 && (*p != 0)) - p = GetNextCharPointer(p); - Delete(0, (int)(p - _chars)); - } - void TrimRightWithCharSet(const CStringBase &charSet) - { - const T *p = _chars; - const T *pLast = NULL; - while (*p != 0) - { - if (charSet.Find(*p) >= 0) - { - if (pLast == NULL) - pLast = p; - } - else - pLast = NULL; - p = GetNextCharPointer(p); - } - if(pLast != NULL) - { - int i = (int)(pLast - _chars); - Delete(i, _length - i); - } - - } - void MoveItems(int destIndex, int srcIndex) - { - memmove(_chars + destIndex, _chars + srcIndex, - sizeof(T) * (_length - srcIndex + 1)); - } - - void InsertSpace(int &index, int size) - { - CorrectIndex(index); - GrowLength(size); - MoveItems(index + size, index); - } - - static T *GetNextCharPointer(T *p) - { return MyStringGetNextCharPointer(p); } - static const T *GetNextCharPointer(const T *p) - { return MyStringGetNextCharPointer(p); } - static T *GetPrevCharPointer(T *base, T *p) - { return MyStringGetPrevCharPointer(base, p); } - static const T *GetPrevCharPointer(const T *base, const T *p) - { return MyStringGetPrevCharPointer(base, p); } -protected: - T *_chars; - int _length; - int _capacity; - - void SetCapacity(int newCapacity) - { - int realCapacity = newCapacity + 1; - if(realCapacity == _capacity) - return; - /* - const int kMaxStringSize = 0x20000000; - #ifndef _WIN32_WCE - if(newCapacity > kMaxStringSize || newCapacity < _length) - throw 1052337; - #endif - */ - T *newBuffer = new T[realCapacity]; - if(_capacity > 0) - { - for (int i = 0; i < (_length + 1); i++) - newBuffer[i] = _chars[i]; - delete []_chars; - _chars = newBuffer; - } - else - { - _chars = newBuffer; - _chars[0] = 0; - } - _capacity = realCapacity; - } - - void GrowLength(int n) - { - int freeSize = _capacity - _length - 1; - if (n <= freeSize) - return; - int delta; - if (_capacity > 64) - delta = _capacity / 2; - else if (_capacity > 8) - delta = 16; - else - delta = 4; - if (freeSize + delta < n) - delta = n - freeSize; - SetCapacity(_capacity + delta); - } - - void CorrectIndex(int &index) const - { - if (index > _length) - index = _length; - } - -public: - CStringBase(): _chars(0), _length(0), _capacity(0) - { SetCapacity(16 - 1); } - CStringBase(T c): _chars(0), _length(0), _capacity(0) - { - SetCapacity(1); - _chars[0] = c; - _chars[1] = 0; - _length = 1; - } - CStringBase(const T *chars): _chars(0), _length(0), _capacity(0) - { - int length = MyStringLen(chars); - SetCapacity(length); - MyStringCopy(_chars, chars); // can be optimized by memove() - _length = length; - } - CStringBase(const CStringBase &s): _chars(0), _length(0), _capacity(0) - { - SetCapacity(s._length); - MyStringCopy(_chars, s._chars); - _length = s._length; - } - ~CStringBase() { delete []_chars; } - - operator const T*() const { return _chars;} - - // The minimum size of the character buffer in characters. - // This value does not include space for a null terminator. - T* GetBuffer(int minBufLength) - { - if(minBufLength >= _capacity) - SetCapacity(minBufLength + 1); - return _chars; - } - void ReleaseBuffer() { ReleaseBuffer(MyStringLen(_chars)); } - void ReleaseBuffer(int newLength) - { - /* - #ifndef _WIN32_WCE - if(newLength >= _capacity) - throw 282217; - #endif - */ - _chars[newLength] = 0; - _length = newLength; - } - - CStringBase& operator=(T c) - { - Empty(); - SetCapacity(1); - _chars[0] = c; - _chars[1] = 0; - _length = 1; - return *this; - } - CStringBase& operator=(const T *chars) - { - Empty(); - int length = MyStringLen(chars); - SetCapacity(length); - MyStringCopy(_chars, chars); - _length = length; - return *this; - } - CStringBase& operator=(const CStringBase& s) - { - if(&s == this) - return *this; - Empty(); - SetCapacity(s._length); - MyStringCopy(_chars, s._chars); - _length = s._length; - return *this; - } - - CStringBase& operator+=(T c) - { - GrowLength(1); - _chars[_length] = c; - _chars[++_length] = 0; - return *this; - } - CStringBase& operator+=(const T *s) - { - int len = MyStringLen(s); - GrowLength(len); - MyStringCopy(_chars + _length, s); - _length += len; - return *this; - } - CStringBase& operator+=(const CStringBase &s) - { - GrowLength(s._length); - MyStringCopy(_chars + _length, s._chars); - _length += s._length; - return *this; - } - void Empty() - { - _length = 0; - _chars[0] = 0; - } - int Length() const { return _length; } - bool IsEmpty() const { return (_length == 0); } - - CStringBase Mid(int startIndex) const - { return Mid(startIndex, _length - startIndex); } - CStringBase Mid(int startIndex, int count ) const - { - if (startIndex + count > _length) - count = _length - startIndex; - - if (startIndex == 0 && startIndex + count == _length) - return *this; - - CStringBase result; - result.SetCapacity(count); - // MyStringNCopy(result._chars, _chars + startIndex, count); - for (int i = 0; i < count; i++) - result._chars[i] = _chars[startIndex + i]; - result._chars[count] = 0; - result._length = count; - return result; - } - CStringBase Left(int count) const - { return Mid(0, count); } - CStringBase Right(int count) const - { - if (count > _length) - count = _length; - return Mid(_length - count, count); - } - - void MakeUpper() - { MyStringUpper(_chars); } - void MakeLower() - { MyStringLower(_chars); } - - int Compare(const CStringBase& s) const - { return MyStringCompare(_chars, s._chars); } - - int CompareNoCase(const CStringBase& s) const - { return MyStringCompareNoCase(_chars, s._chars); } - /* - int Collate(const CStringBase& s) const - { return MyStringCollate(_chars, s._chars); } - int CollateNoCase(const CStringBase& s) const - { return MyStringCollateNoCase(_chars, s._chars); } - */ - - int Find(T c) const { return Find(c, 0); } - int Find(T c, int startIndex) const - { - T *p = _chars + startIndex; - for (;;) - { - if (*p == c) - return (int)(p - _chars); - if (*p == 0) - return -1; - p = GetNextCharPointer(p); - } - } - int Find(const CStringBase &s) const { return Find(s, 0); } - int Find(const CStringBase &s, int startIndex) const - { - if (s.IsEmpty()) - return startIndex; - for (; startIndex < _length; startIndex++) - { - int j; - for (j = 0; j < s._length && startIndex + j < _length; j++) - if (_chars[startIndex+j] != s._chars[j]) - break; - if (j == s._length) - return startIndex; - } - return -1; - } - int ReverseFind(T c) const - { - if (_length == 0) - return -1; - T *p = _chars + _length - 1; - for (;;) - { - if (*p == c) - return (int)(p - _chars); - if (p == _chars) - return -1; - p = GetPrevCharPointer(_chars, p); - } - } - int FindOneOf(const CStringBase &s) const - { - for(int i = 0; i < _length; i++) - if (s.Find(_chars[i]) >= 0) - return i; - return -1; - } - - void TrimLeft(T c) - { - const T *p = _chars; - while (c == *p) - p = GetNextCharPointer(p); - Delete(0, p - _chars); - } - private: - CStringBase GetTrimDefaultCharSet() - { - CStringBase charSet; - charSet += (T)' '; - charSet += (T)'\n'; - charSet += (T)'\t'; - return charSet; - } - public: - - void TrimLeft() - { - TrimLeftWithCharSet(GetTrimDefaultCharSet()); - } - void TrimRight() - { - TrimRightWithCharSet(GetTrimDefaultCharSet()); - } - void TrimRight(T c) - { - const T *p = _chars; - const T *pLast = NULL; - while (*p != 0) - { - if (*p == c) - { - if (pLast == NULL) - pLast = p; - } - else - pLast = NULL; - p = GetNextCharPointer(p); - } - if(pLast != NULL) - { - int i = pLast - _chars; - Delete(i, _length - i); - } - } - void Trim() - { - TrimRight(); - TrimLeft(); - } - - int Insert(int index, T c) - { - InsertSpace(index, 1); - _chars[index] = c; - _length++; - return _length; - } - int Insert(int index, const CStringBase &s) - { - CorrectIndex(index); - if (s.IsEmpty()) - return _length; - int numInsertChars = s.Length(); - InsertSpace(index, numInsertChars); - for(int i = 0; i < numInsertChars; i++) - _chars[index + i] = s[i]; - _length += numInsertChars; - return _length; - } - - // !!!!!!!!!!!!!!! test it if newChar = '\0' - int Replace(T oldChar, T newChar) - { - if (oldChar == newChar) - return 0; - int number = 0; - int pos = 0; - while (pos < Length()) - { - pos = Find(oldChar, pos); - if (pos < 0) - break; - _chars[pos] = newChar; - pos++; - number++; - } - return number; - } - int Replace(const CStringBase &oldString, const CStringBase &newString) - { - if (oldString.IsEmpty()) - return 0; - if (oldString == newString) - return 0; - int oldStringLength = oldString.Length(); - int newStringLength = newString.Length(); - int number = 0; - int pos = 0; - while (pos < _length) - { - pos = Find(oldString, pos); - if (pos < 0) - break; - Delete(pos, oldStringLength); - Insert(pos, newString); - pos += newStringLength; - number++; - } - return number; - } - int Delete(int index, int count = 1 ) - { - if (index + count > _length) - count = _length - index; - if (count > 0) - { - MoveItems(index, index + count); - _length -= count; - } - return _length; - } -}; - -template -CStringBase operator+(const CStringBase& s1, const CStringBase& s2) -{ - CStringBase result(s1); - result += s2; - return result; -} - -template -CStringBase operator+(const CStringBase& s, T c) -{ - CStringBase result(s); - result += c; - return result; -} - -template -CStringBase operator+(T c, const CStringBase& s) -{ - CStringBase result(c); - result += s; - return result; -} - -template -CStringBase operator+(const CStringBase& s, const T * chars) -{ - CStringBase result(s); - result += chars; - return result; -} - -template -CStringBase operator+(const T * chars, const CStringBase& s) -{ - CStringBase result(chars); - result += s; - return result; -} - -template -bool operator==(const CStringBase& s1, const CStringBase& s2) - { return (s1.Compare(s2) == 0); } - -template -bool operator<(const CStringBase& s1, const CStringBase& s2) - { return (s1.Compare(s2) < 0); } - -template -bool operator==(const T *s1, const CStringBase& s2) - { return (s2.Compare(s1) == 0); } - -template -bool operator==(const CStringBase& s1, const T *s2) - { return (s1.Compare(s2) == 0); } - -template -bool operator!=(const CStringBase& s1, const CStringBase& s2) - { return (s1.Compare(s2) != 0); } - -template -bool operator!=(const T *s1, const CStringBase& s2) - { return (s2.Compare(s1) != 0); } - -template -bool operator!=(const CStringBase& s1, const T *s2) - { return (s1.Compare(s2) != 0); } - -typedef CStringBase AString; -typedef CStringBase UString; - -typedef CObjectVector AStringVector; -typedef CObjectVector UStringVector; - -#ifdef _UNICODE - typedef UString CSysString; -#else - typedef AString CSysString; -#endif - -typedef CObjectVector CSysStringVector; - -#endif diff --git a/CPP/Common/StringConvert.h b/CPP/Common/StringConvert.h index 84eaed9a..32d8a3a1 100755 --- a/CPP/Common/StringConvert.h +++ b/CPP/Common/StringConvert.h @@ -4,7 +4,7 @@ #define __COMMON_STRINGCONVERT_H #include "MyWindows.h" -#include "String.h" +#include "MyString.h" #include "Types.h" UString MultiByteToUnicodeString(const AString &srcString, UINT codePage = CP_ACP); diff --git a/CPP/Common/TextConfig.cpp b/CPP/Common/TextConfig.cpp index 4fce320a..34fedeb8 100755 --- a/CPP/Common/TextConfig.cpp +++ b/CPP/Common/TextConfig.cpp @@ -2,10 +2,10 @@ #include "StdAfx.h" -#include "Common/TextConfig.h" +#include "TextConfig.h" #include "Defs.h" -#include "Common/UTFConvert.h" +#include "UTFConvert.h" static bool IsDelimitChar(char c) { diff --git a/CPP/Common/TextConfig.h b/CPP/Common/TextConfig.h index 1552df65..a25142a7 100755 --- a/CPP/Common/TextConfig.h +++ b/CPP/Common/TextConfig.h @@ -3,8 +3,8 @@ #ifndef __COMMON_TEXTCONFIG_H #define __COMMON_TEXTCONFIG_H -#include "Common/Vector.h" -#include "Common/String.h" +#include "MyVector.h" +#include "MyString.h" struct CTextConfigPair { diff --git a/CPP/Common/UTFConvert.h b/CPP/Common/UTFConvert.h index 47434111..2a14600d 100755 --- a/CPP/Common/UTFConvert.h +++ b/CPP/Common/UTFConvert.h @@ -3,7 +3,7 @@ #ifndef __COMMON_UTFCONVERT_H #define __COMMON_UTFCONVERT_H -#include "Common/String.h" +#include "MyString.h" bool ConvertUTF8ToUnicode(const AString &utfString, UString &resultString); bool ConvertUnicodeToUTF8(const UString &unicodeString, AString &resultString); diff --git a/CPP/Common/Vector.cpp b/CPP/Common/Vector.cpp deleted file mode 100755 index b3dd70a5..00000000 --- a/CPP/Common/Vector.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// Common/Vector.cpp - -#include "StdAfx.h" - -#include - -#include "Vector.h" - -CBaseRecordVector::~CBaseRecordVector() - { Free(); } - -void CBaseRecordVector::Free() -{ - delete []((unsigned char *)_items); - _capacity = 0; - _size = 0; - _items = 0; -} - -void CBaseRecordVector::Clear() - { DeleteFrom(0); } -void CBaseRecordVector::DeleteBack() - { Delete(_size - 1); } -void CBaseRecordVector::DeleteFrom(int index) - { Delete(index, _size - index); } - -void CBaseRecordVector::ReserveOnePosition() -{ - if(_size != _capacity) - return; - int delta; - if (_capacity > 64) - delta = _capacity / 2; - else if (_capacity > 8) - delta = 8; - else - delta = 4; - Reserve(_capacity + delta); -} - -void CBaseRecordVector::Reserve(int newCapacity) -{ - if(newCapacity <= _capacity) - return; - /* - #ifndef _DEBUG - static const unsigned int kMaxVectorSize = 0xF0000000; - if(newCapacity < _size || - ((unsigned int )newCapacity * (unsigned int )_itemSize) > kMaxVectorSize) - throw 1052354; - #endif - */ - unsigned char *p = new unsigned char[newCapacity * _itemSize]; - int numRecordsToMove = _capacity; - memmove(p, _items, _itemSize * numRecordsToMove); - delete [](unsigned char *)_items; - _items = p; - _capacity = newCapacity; -} - -void CBaseRecordVector::MoveItems(int destIndex, int srcIndex) -{ - memmove(((unsigned char *)_items) + destIndex * _itemSize, - ((unsigned char *)_items) + srcIndex * _itemSize, - _itemSize * (_size - srcIndex)); -} - -void CBaseRecordVector::InsertOneItem(int index) -{ - ReserveOnePosition(); - MoveItems(index + 1, index); - _size++; -} - -void CBaseRecordVector::Delete(int index, int num) -{ - TestIndexAndCorrectNum(index, num); - if (num > 0) - { - MoveItems(index, index + num); - _size -= num; - } -} diff --git a/CPP/Common/Vector.h b/CPP/Common/Vector.h deleted file mode 100755 index 1bb67a1d..00000000 --- a/CPP/Common/Vector.h +++ /dev/null @@ -1,237 +0,0 @@ -// Common/Vector.h - -#ifndef __COMMON_VECTOR_H -#define __COMMON_VECTOR_H - -#include "Defs.h" - -class CBaseRecordVector -{ - void MoveItems(int destIndex, int srcIndex); -protected: - int _capacity; - int _size; - void *_items; - size_t _itemSize; - - void ReserveOnePosition(); - void InsertOneItem(int index); - void TestIndexAndCorrectNum(int index, int &num) const - { if (index + num > _size) num = _size - index; } -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(); - void DeleteFrom(int index); - void DeleteBack(); -}; - -template -class CRecordVector: public CBaseRecordVector -{ -public: - CRecordVector():CBaseRecordVector(sizeof(T)){}; - CRecordVector(const CRecordVector &v): - CBaseRecordVector(sizeof(T)) { *this = v;} - CRecordVector& operator=(const CRecordVector &v) - { - Clear(); - return (*this += v); - } - CRecordVector& operator+=(const CRecordVector &v) - { - int size = v.Size(); - Reserve(Size() + size); - for(int i = 0; i < size; i++) - Add(v[i]); - return *this; - } - int Add(T item) - { - ReserveOnePosition(); - ((T *)_items)[_size] = item; - return _size++; - } - void Insert(int index, T item) - { - InsertOneItem(index); - ((T *)_items)[index] = item; - } - // T* GetPointer() const { return (T*)_items; } - // operator const T *() const { return _items; }; - const T& operator[](int index) const { return ((T *)_items)[index]; } - T& operator[](int index) { return ((T *)_items)[index]; } - const T& Front() const { return operator[](0); } - T& Front() { return operator[](0); } - const T& Back() const { return operator[](_size - 1); } - T& Back() { return operator[](_size - 1); } - - void Swap(int i, int j) - { - T temp = operator[](i); - operator[](i) = operator[](j); - operator[](j) = temp; - } - - int FindInSorted(const T& item) const - { - int left = 0, right = Size(); - while (left != right) - { - int mid = (left + right) / 2; - const T& midValue = (*this)[mid]; - if (item == midValue) - return mid; - if (item < midValue) - right = mid; - else - left = mid + 1; - } - return -1; - } - - - static void SortRefDown(T* p, int k, int size, int (*compare)(const T*, const T*, void *), void *param) - { - T temp = p[k]; - for (;;) - { - int s = (k << 1); - if (s > size) - break; - if (s < size && compare(p + s + 1, p + s, param) > 0) - s++; - if (compare(&temp, p + s, param) >= 0) - break; - p[k] = p[s]; - k = s; - } - p[k] = temp; - } - - void Sort(int (*compare)(const T*, const T*, void *), void *param) - { - int size = _size; - if (size <= 1) - return; - T* p = (&Front()) - 1; - { - int i = size / 2; - do - SortRefDown(p, i, size, compare, param); - while(--i != 0); - } - do - { - T temp = p[size]; - p[size--] = p[1]; - p[1] = temp; - SortRefDown(p, 1, size, compare, param); - } - while (size > 1); - } -}; - -typedef CRecordVector CIntVector; -typedef CRecordVector CUIntVector; -typedef CRecordVector CBoolVector; -typedef CRecordVector CByteVector; -typedef CRecordVector CPointerVector; - -template -class CObjectVector: public CPointerVector -{ -public: - CObjectVector(){}; - ~CObjectVector() { Clear(); } - CObjectVector(const CObjectVector &objectVector) - { *this = objectVector; } - CObjectVector& operator=(const CObjectVector &objectVector) - { - Clear(); - return (*this += objectVector); - } - CObjectVector& operator+=(const CObjectVector &objectVector) - { - int size = objectVector.Size(); - Reserve(Size() + size); - for(int i = 0; i < size; i++) - Add(objectVector[i]); - return *this; - } - const T& operator[](int index) const { return *((T *)CPointerVector::operator[](index)); } - T& operator[](int index) { return *((T *)CPointerVector::operator[](index)); } - T& Front() { return operator[](0); } - const T& Front() const { return operator[](0); } - T& Back() { return operator[](_size - 1); } - const T& Back() const { return operator[](_size - 1); } - int Add(const T& item) - { return CPointerVector::Add(new T(item)); } - void Insert(int index, const T& item) - { CPointerVector::Insert(index, new T(item)); } - virtual void Delete(int index, int num = 1) - { - TestIndexAndCorrectNum(index, num); - for(int i = 0; i < num; i++) - delete (T *)(((void **)_items)[index + i]); - CPointerVector::Delete(index, num); - } - int Find(const T& item) const - { - for(int i = 0; i < Size(); i++) - if (item == (*this)[i]) - return i; - return -1; - } - int FindInSorted(const T& item) const - { - int left = 0, right = Size(); - while (left != right) - { - int mid = (left + right) / 2; - const T& midValue = (*this)[mid]; - if (item == midValue) - return mid; - if (item < midValue) - right = mid; - else - left = mid + 1; - } - return -1; - } - int AddToSorted(const T& item) - { - int left = 0, right = Size(); - while (left != right) - { - int mid = (left + right) / 2; - const T& midValue = (*this)[mid]; - if (item == midValue) - { - right = mid + 1; - break; - } - if (item < midValue) - right = mid; - else - left = mid + 1; - } - Insert(right, item); - return right; - } - - 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 */) - { return MyCompare(*(*((const T **)a1)), *(*((const T **)a2))); } - void Sort() { CPointerVector::Sort(CompareObjectItems, 0); } -}; - -#endif diff --git a/CPP/Common/Wildcard.h b/CPP/Common/Wildcard.h index 82d2bbd2..55c9744e 100755 --- a/CPP/Common/Wildcard.h +++ b/CPP/Common/Wildcard.h @@ -3,7 +3,7 @@ #ifndef __COMMON_WILDCARD_H #define __COMMON_WILDCARD_H -#include "Common/String.h" +#include "MyString.h" void SplitPathToParts(const UString &path, UStringVector &pathParts); void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name); diff --git a/CPP/Windows/COM.h b/CPP/Windows/COM.h index 80651406..2f99905a 100755 --- a/CPP/Windows/COM.h +++ b/CPP/Windows/COM.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_COM_H #define __WINDOWS_COM_H -#include "Common/String.h" +#include "Common/MyString.h" namespace NWindows { namespace NCOM { diff --git a/CPP/Windows/CommonDialog.h b/CPP/Windows/CommonDialog.h index d0149aba..250c64f7 100755 --- a/CPP/Windows/CommonDialog.h +++ b/CPP/Windows/CommonDialog.h @@ -5,7 +5,7 @@ #include -#include "Common/String.h" +#include "Common/MyString.h" #include "Windows/Defs.h" namespace NWindows{ diff --git a/CPP/Windows/Control/PropertyPage.cpp b/CPP/Windows/Control/PropertyPage.cpp index f8996be1..1fd99079 100755 --- a/CPP/Windows/Control/PropertyPage.cpp +++ b/CPP/Windows/Control/PropertyPage.cpp @@ -3,7 +3,6 @@ #include "StdAfx.h" #include "Windows/Control/PropertyPage.h" -#include "../../Common/Vector.h" #ifndef _UNICODE #include "../../Common/StringConvert.h" #endif diff --git a/CPP/Windows/DLL.h b/CPP/Windows/DLL.h index bad0dd6d..4c2ffa2b 100755 --- a/CPP/Windows/DLL.h +++ b/CPP/Windows/DLL.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_DLL_H #define __WINDOWS_DLL_H -#include "../Common/String.h" +#include "../Common/MyString.h" namespace NWindows { namespace NDLL { diff --git a/CPP/Windows/Error.h b/CPP/Windows/Error.h index 4d9a9fa6..05b5cd0e 100755 --- a/CPP/Windows/Error.h +++ b/CPP/Windows/Error.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_ERROR_H #define __WINDOWS_ERROR_H -#include "Common/String.h" +#include "Common/MyString.h" namespace NWindows { namespace NError { diff --git a/CPP/Windows/FileDir.h b/CPP/Windows/FileDir.h index 3ebf3e63..b6f81351 100755 --- a/CPP/Windows/FileDir.h +++ b/CPP/Windows/FileDir.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_FILEDIR_H #define __WINDOWS_FILEDIR_H -#include "../Common/String.h" +#include "../Common/MyString.h" #include "Defs.h" namespace NWindows { diff --git a/CPP/Windows/FileFind.h b/CPP/Windows/FileFind.h index 4d2439aa..87846fde 100755 --- a/CPP/Windows/FileFind.h +++ b/CPP/Windows/FileFind.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_FILEFIND_H #define __WINDOWS_FILEFIND_H -#include "../Common/String.h" +#include "../Common/MyString.h" #include "../Common/Types.h" #include "FileName.h" #include "Defs.h" diff --git a/CPP/Windows/FileIO.cpp b/CPP/Windows/FileIO.cpp index b5f7593c..adfbec3d 100755 --- a/CPP/Windows/FileIO.cpp +++ b/CPP/Windows/FileIO.cpp @@ -5,7 +5,7 @@ #include "FileIO.h" #include "Defs.h" #ifdef WIN_LONG_PATH -#include "../Common/String.h" +#include "../Common/MyString.h" #endif #ifndef _UNICODE #include "../Common/StringConvert.h" diff --git a/CPP/Windows/FileIO.h b/CPP/Windows/FileIO.h index 05c8bc16..a7ee8808 100755 --- a/CPP/Windows/FileIO.h +++ b/CPP/Windows/FileIO.h @@ -34,9 +34,9 @@ protected: public: CFileBase(): _handle(INVALID_HANDLE_VALUE){}; - virtual ~CFileBase(); + ~CFileBase(); - virtual bool Close(); + bool Close(); bool GetPosition(UInt64 &position) const; bool GetLength(UInt64 &length) const; diff --git a/CPP/Windows/FileName.h b/CPP/Windows/FileName.h index f8567652..5b912b2d 100755 --- a/CPP/Windows/FileName.h +++ b/CPP/Windows/FileName.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_FILENAME_H #define __WINDOWS_FILENAME_H -#include "../Common/String.h" +#include "../Common/MyString.h" namespace NWindows { namespace NFile { diff --git a/CPP/Windows/FileSystem.h b/CPP/Windows/FileSystem.h index 25488804..727497bb 100755 --- a/CPP/Windows/FileSystem.h +++ b/CPP/Windows/FileSystem.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_FILESYSTEM_H #define __WINDOWS_FILESYSTEM_H -#include "../Common/String.h" +#include "../Common/MyString.h" #include "../Common/Types.h" #ifndef _UNICODE diff --git a/CPP/Windows/Menu.h b/CPP/Windows/Menu.h index 11ba5537..9e0d375c 100755 --- a/CPP/Windows/Menu.h +++ b/CPP/Windows/Menu.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_MENU_H #define __WINDOWS_MENU_H -#include "Common/String.h" +#include "Common/MyString.h" #include "Windows/Defs.h" namespace NWindows { diff --git a/CPP/Windows/Net.h b/CPP/Windows/Net.h index ff501d70..1f0eae97 100755 --- a/CPP/Windows/Net.h +++ b/CPP/Windows/Net.h @@ -4,7 +4,7 @@ #define __WINDOWS_NET_H #include "Common/Buffer.h" -#include "Common/String.h" +#include "Common/MyString.h" namespace NWindows { namespace NNet { diff --git a/CPP/Windows/PropVariantConversions.h b/CPP/Windows/PropVariantConversions.h index a3f3ebbf..68ad9612 100755 --- a/CPP/Windows/PropVariantConversions.h +++ b/CPP/Windows/PropVariantConversions.h @@ -4,7 +4,7 @@ #define __PROPVARIANTCONVERSIONS_H #include "Common/Types.h" -#include "Common/String.h" +#include "Common/MyString.h" bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime = true, bool includeSeconds = true); UString ConvertFileTimeToString(const FILETIME &ft, bool includeTime = true, bool includeSeconds = true); diff --git a/CPP/Windows/Registry.h b/CPP/Windows/Registry.h index 435717bd..a590d8ea 100755 --- a/CPP/Windows/Registry.h +++ b/CPP/Windows/Registry.h @@ -4,7 +4,7 @@ #define __WINDOWS_REGISTRY_H #include "Common/Buffer.h" -#include "Common/String.h" +#include "Common/MyString.h" #include "Common/Types.h" namespace NWindows { diff --git a/CPP/Windows/ResourceString.h b/CPP/Windows/ResourceString.h index 1bfc88ab..ac9c5cd5 100755 --- a/CPP/Windows/ResourceString.h +++ b/CPP/Windows/ResourceString.h @@ -3,7 +3,7 @@ #ifndef __WINDOWS_RESOURCESTRING_H #define __WINDOWS_RESOURCESTRING_H -#include "Common/String.h" +#include "Common/MyString.h" namespace NWindows { diff --git a/CPP/Windows/Security.h b/CPP/Windows/Security.h index ded31b74..73422568 100755 --- a/CPP/Windows/Security.h +++ b/CPP/Windows/Security.h @@ -3,7 +3,6 @@ #ifndef __WINDOWS_SECURITY_H #define __WINDOWS_SECURITY_H -#include "Common/String.h" #include "Windows/Defs.h" #include diff --git a/CPP/Windows/Shell.h b/CPP/Windows/Shell.h index 4770a454..743eb051 100755 --- a/CPP/Windows/Shell.h +++ b/CPP/Windows/Shell.h @@ -6,7 +6,7 @@ #include #include -#include "Common/String.h" +#include "Common/MyString.h" #include "Windows/Defs.h" diff --git a/CPP/Windows/System.cpp b/CPP/Windows/System.cpp new file mode 100755 index 00000000..8e4069c2 --- /dev/null +++ b/CPP/Windows/System.cpp @@ -0,0 +1,64 @@ +// Windows/System.cpp + +#include "StdAfx.h" + +#include "System.h" + +namespace NWindows { +namespace NSystem { + +UInt32 GetNumberOfProcessors() +{ + SYSTEM_INFO systemInfo; + GetSystemInfo(&systemInfo); + return (UInt32)systemInfo.dwNumberOfProcessors; +} + +#if !defined(_WIN64) && defined(__GNUC__) + +typedef struct _MY_MEMORYSTATUSEX { + DWORD dwLength; + DWORD dwMemoryLoad; + DWORDLONG ullTotalPhys; + DWORDLONG ullAvailPhys; + DWORDLONG ullTotalPageFile; + DWORDLONG ullAvailPageFile; + DWORDLONG ullTotalVirtual; + DWORDLONG ullAvailVirtual; + DWORDLONG ullAvailExtendedVirtual; +} MY_MEMORYSTATUSEX, *MY_LPMEMORYSTATUSEX; + +#else + +#define MY_MEMORYSTATUSEX MEMORYSTATUSEX +#define MY_LPMEMORYSTATUSEX LPMEMORYSTATUSEX + +#endif + +typedef BOOL (WINAPI *GlobalMemoryStatusExP)(MY_LPMEMORYSTATUSEX lpBuffer); + +UInt64 GetRamSize() +{ + MY_MEMORYSTATUSEX stat; + stat.dwLength = sizeof(stat); + #ifdef _WIN64 + if (!::GlobalMemoryStatusEx(&stat)) + return 0; + return stat.ullTotalPhys; + #else + GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) + ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), + "GlobalMemoryStatusEx"); + if (globalMemoryStatusEx != 0) + if (globalMemoryStatusEx(&stat)) + return stat.ullTotalPhys; + { + MEMORYSTATUS stat; + stat.dwLength = sizeof(stat); + GlobalMemoryStatus(&stat); + return stat.dwTotalPhys; + } + #endif +} + +}} diff --git a/CPP/Windows/System.h b/CPP/Windows/System.h index a81aba98..e0067158 100755 --- a/CPP/Windows/System.h +++ b/CPP/Windows/System.h @@ -3,45 +3,13 @@ #ifndef __WINDOWS_SYSTEM_H #define __WINDOWS_SYSTEM_H -#include "..\Common\Types.h" +#include "../Common/Types.h" namespace NWindows { namespace NSystem { -inline UInt32 GetNumberOfProcessors() -{ - SYSTEM_INFO systemInfo; - GetSystemInfo(&systemInfo); - return (UInt32)systemInfo.dwNumberOfProcessors; -} - -#ifndef _WIN64 -typedef BOOL (WINAPI *GlobalMemoryStatusExP)(LPMEMORYSTATUSEX lpBuffer); -#endif - -inline UInt64 GetRamSize() -{ - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(stat); - #ifdef _WIN64 - if (!::GlobalMemoryStatusEx(&stat)) - return 0; - return stat.ullTotalPhys; - #else - GlobalMemoryStatusExP globalMemoryStatusEx = (GlobalMemoryStatusExP) - ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), - "GlobalMemoryStatusEx"); - if (globalMemoryStatusEx != 0) - if (globalMemoryStatusEx(&stat)) - return stat.ullTotalPhys; - { - MEMORYSTATUS stat; - stat.dwLength = sizeof(stat); - GlobalMemoryStatus(&stat); - return stat.dwTotalPhys; - } - #endif -} +UInt32 GetNumberOfProcessors(); +UInt64 GetRamSize(); }} diff --git a/CPP/Windows/Thread.h b/CPP/Windows/Thread.h index 044ec9a3..7edc6827 100755 --- a/CPP/Windows/Thread.h +++ b/CPP/Windows/Thread.h @@ -20,6 +20,7 @@ class CThread public: CThread() { Thread_Construct(&thread); } ~CThread() { Close(); } + bool IsCreated() { return Thread_WasCreated(&thread) != 0; } HRes Close() { return Thread_Close(&thread); } HRes Create(THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter) { return Thread_Create(&thread, startAddress, parameter); } diff --git a/CPP/Windows/Window.h b/CPP/Windows/Window.h index 3df80191..c0e68229 100755 --- a/CPP/Windows/Window.h +++ b/CPP/Windows/Window.h @@ -4,7 +4,7 @@ #define __WINDOWS_WINDOW_H #include "Windows/Defs.h" -#include "Common/String.h" +#include "Common/MyString.h" namespace NWindows { diff --git a/DOC/7zC.txt b/DOC/7zC.txt index 88f039c5..84129547 100755 --- a/DOC/7zC.txt +++ b/DOC/7zC.txt @@ -1,7 +1,7 @@ -7z ANSI-C Decoder 4.43 +7z ANSI-C Decoder 4.48 ---------------------- -7z ANSI-C Decoder 4.43 Copyright (C) 1999-2006 Igor Pavlov +7z ANSI-C Decoder 4.48 Copyright (C) 1999-2006 Igor Pavlov 7z ANSI-C provides 7z/LZMA decoding. 7z ANSI-C version is simplified version ported from C++ code. @@ -40,12 +40,12 @@ You must download 7-Zip program from www.7-zip.org. You can create .7z archive with 7z.exe or 7za.exe: - 7za.exe a archive.7z *.htm -r -mx -m0fb=255 -mf=off + 7za.exe a archive.7z *.htm -r -mx -m0fb=255 If you have big number of files in archive, and you need fast extracting, you can use partly-solid archives: - 7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K -mf=off + 7za.exe a archive.7z *.htm -ms=512K -r -mx -m0fb=255 -m0d=512K In that example 7-Zip will use 512KB solid blocks. So it needs to decompress only 512KB for extracting one file from such archive. @@ -54,8 +54,8 @@ In that example 7-Zip will use 512KB solid blocks. So it needs to decompress onl Limitations of current version of 7z ANSI-C Decoder --------------------------------------------------- - - It reads only "FileName", "Size", and "CRC" information for each file in archive. - - It supports only LZMA and Copy (no compression) methods. + - It reads only "FileName", "Size", "LastWriteTime" and "CRC" information for each file in archive. + - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters. - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names. These limitations will be fixed in future versions. @@ -181,6 +181,7 @@ Memory usage for Archive opening: Estimated size of one file structures in solid archive: - Size (4 or 8 Bytes) - CRC32 (4 bytes) + - LastWriteTime (8 bytes) - Some file information (4 bytes) - File Name (variable length) + pointer + allocation structures @@ -190,6 +191,8 @@ Memory usage for archive Decompressing: - Memory for LZMA decompressing structures - Main pool: - Memory for decompressed solid block + - Memory for temprorary buffers, if BCJ2 fileter is used. Usually these + temprorary buffers can be about 15% of solid block size. If _LZMA_IN_CB is defined, 7z Decoder will not allocate memory for @@ -220,12 +223,11 @@ LZMA Defines _LZMA_IN_CB - Use special callback mode for input stream to reduce memory requirements -_SZ_FILE_SIZE_64 - define it if you need support for files larger than 4 GB -_SZ_NO_INT_64 - define it if your compiler doesn't support long long int +_SZ_FILE_SIZE_32 - define it if you need only support for files smaller than 4 GB +_SZ_NO_INT_64 - define it if your compiler doesn't support long long int or __int64. _LZMA_PROB32 - it can increase LZMA decompressing speed on some 32-bit CPUs. -_SZ_ONE_DIRECTORY - define it if you want to locate all source files to one directory _SZ_ALLOC_DEBUG - define it if you want to debug alloc/free operations to stderr. diff --git a/DOC/7zip.nsi b/DOC/7zip.nsi index 3b73c03c..fcba5ab2 100755 --- a/DOC/7zip.nsi +++ b/DOC/7zip.nsi @@ -2,7 +2,7 @@ ;Defines !define VERSION_MAJOR 4 -!define VERSION_MINOR 47 +!define VERSION_MINOR 48 !define VERSION_POSTFIX_FULL " beta" !ifdef WIN64 !ifdef IA64 diff --git a/DOC/7zip.wxs b/DOC/7zip.wxs index b92995b1..44cc5ed1 100755 --- a/DOC/7zip.wxs +++ b/DOC/7zip.wxs @@ -1,7 +1,7 @@ - + diff --git a/DOC/License.txt b/DOC/License.txt index b02c21ee..d6bbf1e4 100755 --- a/DOC/License.txt +++ b/DOC/License.txt @@ -11,16 +11,16 @@ 2) CPP/7zip/Crypto/AES files: GNU LGPL + AES code license 3) All other files: GNU LGPL - GNU LGPL + unRAR restriction means that you must follow both GNU LGPL rules + The GNU LGPL + unRAR restriction means that you must follow both GNU LGPL rules and unRAR restriction rules. - GNU LGPL + AES code license means that you must follow both GNU LGPL rules + The GNU LGPL + AES code license means that you must follow both GNU LGPL rules and AES code license rules. Notes: - You can use 7-Zip on any computers, including computers in commercial - organizations. You don't need to register or pay for 7-Zip. + You can use 7-Zip on any computer, including a computer in a commercial + organization. You don't need to register or pay for 7-Zip. GNU LGPL information -- cgit v1.2.3