mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 05:15:01 -06:00
4.48 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
0b33f700a6
commit
fd8b1d78b4
@@ -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 {
|
||||
|
||||
@@ -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<CUpdateItem> 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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<CItem> &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<CItem> &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)
|
||||
|
||||
@@ -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<IOutStream> 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<CItem> &items, const CByteBuffer &comment);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user