4.45 beta

This commit is contained in:
Igor Pavlov
2007-04-17 00:00:00 +00:00
committed by Kornel Lesiński
parent d9666cf046
commit a145bfc7cf
458 changed files with 13144 additions and 18608 deletions

View File

@@ -1,34 +0,0 @@
// CodecsPath.cpp
#include "StdAfx.h"
#include "../../../Common/String.h"
extern HINSTANCE g_hInstance;
static CSysString GetLibraryPath()
{
TCHAR fullPath[MAX_PATH + 1];
::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);
return fullPath;
}
static CSysString GetLibraryFolderPrefix()
{
CSysString path = GetLibraryPath();
int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
return path.Left(pos + 1);
}
CSysString GetBaseFolderPrefix()
{
CSysString libPrefix = GetLibraryFolderPrefix();
CSysString temp = libPrefix;
temp.Delete(temp.Length() - 1);
int pos = temp.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
return temp.Left(pos + 1);
}
CSysString GetCodecsFolderPrefix()
{
return GetBaseFolderPrefix() + (CSysString)(TEXT("Codecs")) + (CSysString)(TEXT(STRING_PATH_SEPARATOR));
}

View File

@@ -1,12 +0,0 @@
// CodecsPath.h
#ifndef __CODECSPATH_H
#define __CODECSPATH_H
#include "../../../Common/String.h"
CSysString GetBaseFolderPrefix();
CSysString GetCodecsFolderPrefix();
#endif

View File

@@ -1,31 +0,0 @@
// CoderLoader.cpp
#include "StdAfx.h"
#include "CoderLoader.h"
#include "FilterCoder.h"
HRESULT CCoderLibrary::CreateCoderSpec(REFGUID clsID, ICompressCoder **coder)
{
HRESULT result = CreateObject(clsID, IID_ICompressCoder, (void **)coder);
if (result == S_OK || result != E_NOINTERFACE)
return result;
CMyComPtr<ICompressFilter> filter;
RINOK(CreateObject(clsID, IID_ICompressFilter, (void **)&filter));
CFilterCoder *filterCoderSpec = new CFilterCoder;
CMyComPtr<ICompressCoder> filterCoder = filterCoderSpec;
filterCoderSpec->Filter = filter;
*coder = filterCoder.Detach();
return S_OK;
}
HRESULT CCoderLibrary::LoadAndCreateCoderSpec(LPCTSTR filePath, REFGUID clsID, ICompressCoder **coder)
{
CCoderLibrary libTemp;
if (!libTemp.Load(filePath))
return GetLastError();
RINOK(libTemp.CreateCoderSpec(clsID, coder));
Attach(libTemp.Detach());
return S_OK;
}

View File

@@ -1,147 +0,0 @@
// CoderLoader.h
#ifndef __CODERLOADER_H
#define __CODERLOADER_H
#include "../../../Common/String.h"
#include "../../../Common/MyCom.h"
#include "../../../Windows/DLL.h"
#include "../../ICoder.h"
typedef UInt32 (WINAPI * CreateObjectPointer)(
const GUID *clsID,
const GUID *interfaceID,
void **outObject);
class CCoderLibrary: public NWindows::NDLL::CLibrary
{
public:
HRESULT CreateObject(REFGUID clsID, REFGUID iid, void **obj)
{
CreateObjectPointer createObject = (CreateObjectPointer)
GetProcAddress("CreateObject");
if (createObject == NULL)
return GetLastError();
return createObject(&clsID, &iid, obj);
}
HRESULT CreateFilter(REFGUID clsID, ICompressFilter **filter)
{
return CreateObject(clsID, IID_ICompressFilter, (void **)filter);
}
HRESULT CreateCoder(REFGUID clsID, ICompressCoder **coder)
{
return CreateObject(clsID, IID_ICompressCoder, (void **)coder);
}
HRESULT CreateCoderSpec(REFGUID clsID, ICompressCoder **coder);
HRESULT LoadAndCreateFilter(LPCTSTR filePath, REFGUID clsID, ICompressFilter **filter)
{
CCoderLibrary libTemp;
if (!libTemp.Load(filePath))
return GetLastError();
RINOK(libTemp.CreateFilter(clsID, filter));
Attach(libTemp.Detach());
return S_OK;
}
HRESULT LoadAndCreateCoder(LPCTSTR filePath, REFGUID clsID, ICompressCoder **coder)
{
CCoderLibrary libTemp;
if (!libTemp.Load(filePath))
return GetLastError();
RINOK(libTemp.CreateCoder(clsID, coder));
Attach(libTemp.Detach());
return S_OK;
}
HRESULT LoadAndCreateCoderSpec(LPCTSTR filePath, REFGUID clsID, ICompressCoder **coder);
HRESULT CreateCoder2(REFGUID clsID, ICompressCoder2 **coder)
{
CreateObjectPointer createObject = (CreateObjectPointer)
GetProcAddress("CreateObject");
if (createObject == NULL)
return GetLastError();
return createObject(&clsID, &IID_ICompressCoder2, (void **)coder);
}
HRESULT LoadAndCreateCoder2(LPCTSTR filePath, REFGUID clsID, ICompressCoder2 **coder)
{
CCoderLibrary libTemp;
if (!libTemp.Load(filePath))
return GetLastError();
RINOK(libTemp.CreateCoder2(clsID, coder));
Attach(libTemp.Detach());
return S_OK;
}
};
class CCoderLibraries
{
struct CPathToLibraryPair
{
CSysString Path;
CCoderLibrary Libary;
};
CObjectVector<CPathToLibraryPair> Pairs;
public:
int FindPath(LPCTSTR filePath)
{
for (int i = 0; i < Pairs.Size(); i++)
if (Pairs[i].Path.CompareNoCase(filePath) == 0)
return i;
return -1;
}
HRESULT CreateCoder(LPCTSTR filePath, REFGUID clsID, ICompressCoder **coder)
{
int index = FindPath(filePath);
if (index < 0)
{
CPathToLibraryPair pair;
RINOK(pair.Libary.LoadAndCreateCoder(filePath, clsID, coder));
pair.Path = filePath;
Pairs.Add(pair);
pair.Libary.Detach();
return S_OK;
}
return Pairs[index].Libary.CreateCoder(clsID, coder);
}
HRESULT CreateCoderSpec(LPCTSTR filePath, REFGUID clsID, ICompressCoder **coder)
{
int index = FindPath(filePath);
if (index < 0)
{
CPathToLibraryPair pair;
RINOK(pair.Libary.LoadAndCreateCoderSpec(filePath, clsID, coder));
pair.Path = filePath;
Pairs.Add(pair);
pair.Libary.Detach();
return S_OK;
}
return Pairs[index].Libary.CreateCoderSpec(clsID, coder);
}
HRESULT CreateCoder2(LPCTSTR filePath, REFGUID clsID, ICompressCoder2 **coder)
{
int index = FindPath(filePath);
if (index < 0)
{
CPathToLibraryPair pair;
RINOK(pair.Libary.LoadAndCreateCoder2(filePath, clsID, coder));
pair.Path = filePath;
Pairs.Add(pair);
pair.Libary.Detach();
return S_OK;
}
return Pairs[index].Libary.CreateCoder2(clsID, coder);
}
};
#endif

View File

@@ -227,8 +227,10 @@ void CCoderMixer2MT::ReInit()
STDMETHODIMP CCoderMixer2MT::Init(ISequentialInStream **inStreams,
ISequentialOutStream **outStreams)
{
/*
if (_coderInfoVector.Size() != _bindInfo.Coders.Size())
throw 0;
*/
int i;
for(i = 0; i < _coderInfoVector.Size(); i++)
{

View File

@@ -1,243 +0,0 @@
// FilterCoder.cpp
#include "StdAfx.h"
#include "FilterCoder.h"
#include "../../../Common/Alloc.h"
#include "../../../Common/Defs.h"
#include "../../Common/StreamUtils.h"
static const int kBufferSize = 1 << 17;
CFilterCoder::CFilterCoder()
{
_buffer = (Byte *)::MidAlloc(kBufferSize);
}
CFilterCoder::~CFilterCoder()
{
::MidFree(_buffer);
}
HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)
{
if (_outSizeIsDefined)
{
UInt64 remSize = _outSize - _nowPos64;
if (size > remSize)
size = (UInt32)remSize;
}
UInt32 processedSize = 0;
RINOK(WriteStream(outStream, _buffer, size, &processedSize));
if (size != processedSize)
return E_FAIL;
_nowPos64 += processedSize;
return S_OK;
}
STDMETHODIMP CFilterCoder::Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
ICompressProgressInfo *progress)
{
RINOK(Init());
UInt32 bufferPos = 0;
_outSizeIsDefined = (outSize != 0);
if (_outSizeIsDefined)
_outSize = *outSize;
while(NeedMore())
{
UInt32 processedSize;
// Change it: It can be optimized using ReadPart
RINOK(ReadStream(inStream, _buffer + bufferPos, kBufferSize - bufferPos, &processedSize));
UInt32 endPos = bufferPos + processedSize;
bufferPos = Filter->Filter(_buffer, endPos);
if (bufferPos > endPos)
{
for (; endPos< bufferPos; endPos++)
_buffer[endPos] = 0;
bufferPos = Filter->Filter(_buffer, endPos);
}
if (bufferPos == 0)
{
if (endPos > 0)
return WriteWithLimit(outStream, endPos);
return S_OK;
}
RINOK(WriteWithLimit(outStream, bufferPos));
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&_nowPos64, &_nowPos64));
}
UInt32 i = 0;
while(bufferPos < endPos)
_buffer[i++] = _buffer[bufferPos++];
bufferPos = i;
}
return S_OK;
}
// #ifdef _ST_MODE
STDMETHODIMP CFilterCoder::SetOutStream(ISequentialOutStream *outStream)
{
_bufferPos = 0;
_outStream = outStream;
return Init();
}
STDMETHODIMP CFilterCoder::ReleaseOutStream()
{
_outStream.Release();
return S_OK;
};
STDMETHODIMP CFilterCoder::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 processedSizeTotal = 0;
while(size > 0)
{
UInt32 sizeMax = kBufferSize - _bufferPos;
UInt32 sizeTemp = size;
if (sizeTemp > sizeMax)
sizeTemp = sizeMax;
memmove(_buffer + _bufferPos, data, sizeTemp);
size -= sizeTemp;
processedSizeTotal += sizeTemp;
data = (const Byte *)data + sizeTemp;
UInt32 endPos = _bufferPos + sizeTemp;
_bufferPos = Filter->Filter(_buffer, endPos);
if (_bufferPos == 0)
{
_bufferPos = endPos;
break;
}
if (_bufferPos > endPos)
{
if (size != 0)
return E_FAIL;
break;
}
RINOK(WriteWithLimit(_outStream, _bufferPos));
UInt32 i = 0;
while(_bufferPos < endPos)
_buffer[i++] = _buffer[_bufferPos++];
_bufferPos = i;
}
if (processedSize != NULL)
*processedSize = processedSizeTotal;
return S_OK;
}
STDMETHODIMP CFilterCoder::Flush()
{
if (_bufferPos != 0)
{
UInt32 endPos = Filter->Filter(_buffer, _bufferPos);
if (endPos > _bufferPos)
{
for (; _bufferPos < endPos; _bufferPos++)
_buffer[_bufferPos] = 0;
if (Filter->Filter(_buffer, endPos) != endPos)
return E_FAIL;
}
UInt32 processedSize;
RINOK(WriteStream(_outStream, _buffer, _bufferPos, &processedSize));
if (_bufferPos != processedSize)
return E_FAIL;
_bufferPos = 0;
}
CMyComPtr<IOutStreamFlush> flush;
_outStream.QueryInterface(IID_IOutStreamFlush, &flush);
if (flush)
return flush->Flush();
return S_OK;
}
STDMETHODIMP CFilterCoder::SetInStream(ISequentialInStream *inStream)
{
_convertedPosBegin = _convertedPosEnd = _bufferPos = 0;
_inStream = inStream;
return Init();
}
STDMETHODIMP CFilterCoder::ReleaseInStream()
{
_inStream.Release();
return S_OK;
};
STDMETHODIMP CFilterCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
{
UInt32 processedSizeTotal = 0;
while(size > 0)
{
if (_convertedPosBegin != _convertedPosEnd)
{
UInt32 sizeTemp = MyMin(size, _convertedPosEnd - _convertedPosBegin);
memmove(data, _buffer + _convertedPosBegin, sizeTemp);
_convertedPosBegin += sizeTemp;
data = (void *)((Byte *)data + sizeTemp);
size -= sizeTemp;
processedSizeTotal += sizeTemp;
break;
}
int i;
for (i = 0; _convertedPosEnd + i < _bufferPos; i++)
_buffer[i] = _buffer[i + _convertedPosEnd];
_bufferPos = i;
_convertedPosBegin = _convertedPosEnd = 0;
UInt32 processedSizeTemp;
UInt32 size0 = kBufferSize - _bufferPos;
// Optimize it:
RINOK(ReadStream(_inStream, _buffer + _bufferPos, size0, &processedSizeTemp));
_bufferPos = _bufferPos + processedSizeTemp;
_convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
if (_convertedPosEnd == 0)
{
if (_bufferPos == 0)
break;
else
{
_convertedPosEnd = _bufferPos; // check it
continue;
}
}
if (_convertedPosEnd > _bufferPos)
{
for (; _bufferPos < _convertedPosEnd; _bufferPos++)
_buffer[_bufferPos] = 0;
_convertedPosEnd = Filter->Filter(_buffer, _bufferPos);
}
}
if (processedSize != NULL)
*processedSize = processedSizeTotal;
return S_OK;
}
// #endif // _ST_MODE
#ifndef _NO_CRYPTO
STDMETHODIMP CFilterCoder::CryptoSetPassword(const Byte *data, UInt32 size)
{
return _setPassword->CryptoSetPassword(data, size);
}
#endif
#ifndef EXTRACT_ONLY
STDMETHODIMP CFilterCoder::WriteCoderProperties(ISequentialOutStream *outStream)
{
return _writeCoderProperties->WriteCoderProperties(outStream);
}
#endif
STDMETHODIMP CFilterCoder::SetDecoderProperties2(const Byte *data, UInt32 size)
{
return _setDecoderProperties->SetDecoderProperties2(data, size);
}

View File

@@ -1,130 +0,0 @@
// FilterCoder.h
#ifndef __FILTERCODER_H
#define __FILTERCODER_H
#include "../../../Common/MyCom.h"
#include "../../ICoder.h"
#include "../../IPassword.h"
#define MY_QUERYINTERFACE_ENTRY_AG(i, sub0, sub) if (iid == IID_ ## i) \
{ if (!sub) RINOK(sub0->QueryInterface(IID_ ## i, (void **)&sub)) \
*outObject = (void *)(i *)this; AddRef(); return S_OK; }
class CFilterCoder:
public ICompressCoder,
// #ifdef _ST_MODE
public ICompressSetInStream,
public ISequentialInStream,
public ICompressSetOutStream,
public ISequentialOutStream,
public IOutStreamFlush,
// #endif
#ifndef _NO_CRYPTO
public ICryptoSetPassword,
#endif
#ifndef EXTRACT_ONLY
public ICompressWriteCoderProperties,
#endif
public ICompressSetDecoderProperties2,
public CMyUnknownImp
{
protected:
Byte *_buffer;
// #ifdef _ST_MODE
CMyComPtr<ISequentialInStream> _inStream;
CMyComPtr<ISequentialOutStream> _outStream;
UInt32 _bufferPos;
UInt32 _convertedPosBegin;
UInt32 _convertedPosEnd;
// #endif
bool _outSizeIsDefined;
UInt64 _outSize;
UInt64 _nowPos64;
HRESULT Init()
{
_nowPos64 = 0;
_outSizeIsDefined = false;
return Filter->Init();
}
CMyComPtr<ICryptoSetPassword> _setPassword;
#ifndef EXTRACT_ONLY
CMyComPtr<ICompressWriteCoderProperties> _writeCoderProperties;
#endif
CMyComPtr<ICompressSetDecoderProperties2> _setDecoderProperties;
public:
CMyComPtr<ICompressFilter> Filter;
CFilterCoder();
~CFilterCoder();
HRESULT WriteWithLimit(ISequentialOutStream *outStream, UInt32 size);
bool NeedMore() const
{ return (!_outSizeIsDefined || (_nowPos64 < _outSize)); }
public:
MY_QUERYINTERFACE_BEGIN
MY_QUERYINTERFACE_ENTRY(ICompressCoder)
// #ifdef _ST_MODE
MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
MY_QUERYINTERFACE_ENTRY(ISequentialInStream)
MY_QUERYINTERFACE_ENTRY(ICompressSetOutStream)
MY_QUERYINTERFACE_ENTRY(ISequentialOutStream)
MY_QUERYINTERFACE_ENTRY(IOutStreamFlush)
// #endif
#ifndef _NO_CRYPTO
MY_QUERYINTERFACE_ENTRY_AG(ICryptoSetPassword, Filter, _setPassword)
#endif
#ifndef EXTRACT_ONLY
MY_QUERYINTERFACE_ENTRY_AG(ICompressWriteCoderProperties, Filter, _writeCoderProperties)
#endif
MY_QUERYINTERFACE_ENTRY_AG(ICompressSetDecoderProperties2, Filter, _setDecoderProperties)
MY_QUERYINTERFACE_END
MY_ADDREF_RELEASE
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress);
// #ifdef _ST_MODE
STDMETHOD(ReleaseInStream)();
STDMETHOD(SetInStream)(ISequentialInStream *inStream);
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); \
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
STDMETHOD(ReleaseOutStream)();
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Flush)();
// #endif
#ifndef _NO_CRYPTO
STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
#endif
#ifndef EXTRACT_ONLY
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
#endif
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
};
// #ifdef _ST_MODE
class CInStreamReleaser
{
public:
CFilterCoder *FilterCoder;
CInStreamReleaser(): FilterCoder(0) {}
~CInStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseInStream(); }
};
class COutStreamReleaser
{
public:
CFilterCoder *FilterCoder;
COutStreamReleaser(): FilterCoder(0) {}
~COutStreamReleaser() { if (FilterCoder) FilterCoder->ReleaseOutStream(); }
};
// #endif
#endif

View File

@@ -11,7 +11,7 @@ STDMETHODIMP CSequentialInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *p
_size += realProcessedSize;
if (size > 0 && realProcessedSize == 0)
_wasFinished = true;
_crc.Update(data, realProcessedSize);
_crc = CrcUpdate(_crc, data, realProcessedSize);
if(processedSize != NULL)
*processedSize = realProcessedSize;
return result;
@@ -24,18 +24,17 @@ STDMETHODIMP CInStreamWithCRC::Read(void *data, UInt32 size, UInt32 *processedSi
if (size > 0 && realProcessedSize == 0)
_wasFinished = true;
_size += realProcessedSize;
_crc.Update(data, realProcessedSize);
_crc = CrcUpdate(_crc, data, realProcessedSize);
if(processedSize != NULL)
*processedSize = realProcessedSize;
return result;
}
STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset,
UInt32 seekOrigin, UInt64 *newPosition)
STDMETHODIMP CInStreamWithCRC::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
{
if (seekOrigin != STREAM_SEEK_SET || offset != 0)
return E_FAIL;
_size = 0;
_crc.Init();
_crc = CRC_INIT_VAL;
return _stream->Seek(offset, seekOrigin, newPosition);
}

View File

@@ -3,10 +3,14 @@
#ifndef __INSTREAMWITHCRC_H
#define __INSTREAMWITHCRC_H
#include "../../../Common/CRC.h"
#include "../../../Common/MyCom.h"
#include "../../IStream.h"
extern "C"
{
#include "../../../../C/7zCrc.h"
}
class CSequentialInStreamWithCRC:
public ISequentialInStream,
public CMyUnknownImp
@@ -18,7 +22,7 @@ public:
private:
CMyComPtr<ISequentialInStream> _stream;
UInt64 _size;
CCRC _crc;
UInt32 _crc;
bool _wasFinished;
public:
void SetStream(ISequentialInStream *stream) { _stream = stream; }
@@ -26,10 +30,10 @@ public:
{
_size = 0;
_wasFinished = false;
_crc.Init();
_crc = CRC_INIT_VAL;
}
void ReleaseStream() { _stream.Release(); }
UInt32 GetCRC() const { return _crc.GetDigest(); }
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
UInt64 GetSize() const { return _size; }
bool WasFinished() const { return _wasFinished; }
};
@@ -46,7 +50,7 @@ public:
private:
CMyComPtr<IInStream> _stream;
UInt64 _size;
CCRC _crc;
UInt32 _crc;
bool _wasFinished;
public:
void SetStream(IInStream *stream) { _stream = stream; }
@@ -54,10 +58,10 @@ public:
{
_size = 0;
_wasFinished = false;
_crc.Init();
_crc = CRC_INIT_VAL;
}
void ReleaseStream() { _stream.Release(); }
UInt32 GetCRC() const { return _crc.GetDigest(); }
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
UInt64 GetSize() const { return _size; }
bool WasFinished() const { return _wasFinished; }
};

View File

@@ -16,7 +16,7 @@ STDMETHODIMP COutStreamWithCRC::Write(const void *data, UInt32 size, UInt32 *pr
else
result = _stream->Write(data, size, &realProcessedSize);
if (_calculateCrc)
_crc.Update(data, realProcessedSize);
_crc = CrcUpdate(_crc, data, realProcessedSize);
_size += realProcessedSize;
if(processedSize != NULL)
*processedSize = realProcessedSize;

View File

@@ -3,10 +3,14 @@
#ifndef __OUTSTREAMWITHCRC_H
#define __OUTSTREAMWITHCRC_H
#include "../../../Common/CRC.h"
#include "../../../Common/MyCom.h"
#include "../../IStream.h"
extern "C"
{
#include "../../../../C/7zCrc.h"
}
class COutStreamWithCRC:
public ISequentialOutStream,
public CMyUnknownImp
@@ -18,7 +22,7 @@ public:
private:
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _size;
CCRC _crc;
UInt32 _crc;
bool _calculateCrc;
public:
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
@@ -26,12 +30,12 @@ public:
{
_size = 0;
_calculateCrc = calculateCrc;
_crc.Init();
_crc = CRC_INIT_VAL;
}
void ReleaseStream() { _stream.Release(); }
UInt64 GetSize() const { return _size; }
UInt32 GetCRC() const { return _crc.GetDigest(); }
void InitCRC() { _crc.Init(); }
UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }
void InitCRC() { _crc = CRC_INIT_VAL; }
};
#endif