From f2902217b38cf2e16e851ae84d61247f8e828180 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 25 Mar 2019 17:53:14 +0100 Subject: Update the 7z installer stub source to 18.05. Tag #1022 --- .../7zstub/src/7zip/Common/StreamBinder.cpp | 162 --------------------- 1 file changed, 162 deletions(-) delete mode 100644 other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp (limited to 'other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp') diff --git a/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp b/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp deleted file mode 100644 index dc11de8e5..000000000 --- a/other-licenses/7zstub/src/7zip/Common/StreamBinder.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// StreamBinder.cpp - -#include "StdAfx.h" - -#include "StreamBinder.h" -#include "../../Common/Defs.h" -#include "../../Common/MyCom.h" - -using namespace NWindows; -using namespace NSynchronization; - -class CSequentialInStreamForBinder: - public ISequentialInStream, - public CMyUnknownImp -{ -public: - MY_UNKNOWN_IMP - - STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); -private: - CStreamBinder *m_StreamBinder; -public: - ~CSequentialInStreamForBinder() { m_StreamBinder->CloseRead(); } - void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; } -}; - -STDMETHODIMP CSequentialInStreamForBinder::Read(void *data, UInt32 size, UInt32 *processedSize) - { return m_StreamBinder->Read(data, size, processedSize); } - -class CSequentialOutStreamForBinder: - public ISequentialOutStream, - public CMyUnknownImp -{ -public: - MY_UNKNOWN_IMP - - STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); - -private: - CStreamBinder *m_StreamBinder; -public: - ~CSequentialOutStreamForBinder() { m_StreamBinder->CloseWrite(); } - void SetBinder(CStreamBinder *streamBinder) { m_StreamBinder = streamBinder; } -}; - -STDMETHODIMP CSequentialOutStreamForBinder::Write(const void *data, UInt32 size, UInt32 *processedSize) - { return m_StreamBinder->Write(data, size, processedSize); } - - -////////////////////////// -// CStreamBinder -// (_thereAreBytesToReadEvent && _bufferSize == 0) means that stream is finished. - -void CStreamBinder::CreateEvents() -{ - _allBytesAreWritenEvent = new CManualResetEvent(true); - _thereAreBytesToReadEvent = new CManualResetEvent(false); - _readStreamIsClosedEvent = new CManualResetEvent(false); -} - -void CStreamBinder::ReInit() -{ - _thereAreBytesToReadEvent->Reset(); - _readStreamIsClosedEvent->Reset(); - ProcessedSize = 0; -} - -CStreamBinder::~CStreamBinder() -{ - if (_allBytesAreWritenEvent != NULL) - delete _allBytesAreWritenEvent; - if (_thereAreBytesToReadEvent != NULL) - delete _thereAreBytesToReadEvent; - if (_readStreamIsClosedEvent != NULL) - delete _readStreamIsClosedEvent; -} - - - - -void CStreamBinder::CreateStreams(ISequentialInStream **inStream, - ISequentialOutStream **outStream) -{ - CSequentialInStreamForBinder *inStreamSpec = new - CSequentialInStreamForBinder; - CMyComPtr inStreamLoc(inStreamSpec); - inStreamSpec->SetBinder(this); - *inStream = inStreamLoc.Detach(); - - CSequentialOutStreamForBinder *outStreamSpec = new - CSequentialOutStreamForBinder; - CMyComPtr outStreamLoc(outStreamSpec); - outStreamSpec->SetBinder(this); - *outStream = outStreamLoc.Detach(); - - _buffer = NULL; - _bufferSize= 0; - ProcessedSize = 0; -} - -HRESULT CStreamBinder::Read(void *data, UInt32 size, UInt32 *processedSize) -{ - UInt32 sizeToRead = size; - if (size > 0) - { - if(!_thereAreBytesToReadEvent->Lock()) - return E_FAIL; - sizeToRead = MyMin(_bufferSize, size); - if (_bufferSize > 0) - { - MoveMemory(data, _buffer, sizeToRead); - _buffer = ((const Byte *)_buffer) + sizeToRead; - _bufferSize -= sizeToRead; - if (_bufferSize == 0) - { - _thereAreBytesToReadEvent->Reset(); - _allBytesAreWritenEvent->Set(); - } - } - } - if (processedSize != NULL) - *processedSize = sizeToRead; - ProcessedSize += sizeToRead; - return S_OK; -} - -void CStreamBinder::CloseRead() -{ - _readStreamIsClosedEvent->Set(); -} - -HRESULT CStreamBinder::Write(const void *data, UInt32 size, UInt32 *processedSize) -{ - if (size > 0) - { - _buffer = data; - _bufferSize = size; - _allBytesAreWritenEvent->Reset(); - _thereAreBytesToReadEvent->Set(); - - HANDLE events[2]; - events[0] = *_allBytesAreWritenEvent; - events[1] = *_readStreamIsClosedEvent; - DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE); - if (waitResult != WAIT_OBJECT_0 + 0) - { - // ReadingWasClosed = true; - return E_FAIL; - } - // if(!_allBytesAreWritenEvent.Lock()) - // return E_FAIL; - } - if (processedSize != NULL) - *processedSize = size; - return S_OK; -} - -void CStreamBinder::CloseWrite() -{ - // _bufferSize must be = 0 - _thereAreBytesToReadEvent->Set(); -} -- cgit v1.2.3