2022-11-12 09:45:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ArchiveHelper.h"
|
|
|
|
|
|
|
|
#ifdef USE_7Z
|
|
|
|
|
|
|
|
class CArchiveIO: public IOutStream, public IInStream, public CMyUnknownImp
|
|
|
|
{
|
2023-09-14 16:51:54 +01:00
|
|
|
Z7_COM_UNKNOWN_IMP_2(IOutStream, IInStream)
|
2022-11-12 09:45:35 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
CArchiveIO(QIODevice* pFile, QIODevice::OpenMode Mode, bool bDelete = true)
|
|
|
|
{
|
|
|
|
Q_ASSERT(pFile);
|
|
|
|
m_pFile = pFile;
|
|
|
|
if(Mode != QIODevice::NotOpen)
|
|
|
|
m_pFile->open(Mode);
|
|
|
|
m_bDelete = bDelete;
|
|
|
|
}
|
|
|
|
~CArchiveIO()
|
|
|
|
{
|
|
|
|
m_pFile->close();
|
|
|
|
if(m_bDelete)
|
|
|
|
delete m_pFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Open(QIODevice::OpenMode Mode) {
|
|
|
|
return m_pFile->open(Mode);
|
|
|
|
}
|
|
|
|
|
2023-09-14 16:51:54 +01:00
|
|
|
Z7_COM7F_IMF(Read(void *data, UInt32 size, UInt32 *processedSize))
|
2022-11-12 09:45:35 +00:00
|
|
|
{
|
|
|
|
quint64 read = m_pFile->read((char*)data, size);
|
|
|
|
if(read == -1)
|
|
|
|
return E_FAIL;
|
|
|
|
if(processedSize)
|
|
|
|
*processedSize = read;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-09-14 16:51:54 +01:00
|
|
|
Z7_COM7F_IMF(Write(const void *data, UInt32 size, UInt32 *processedSize))
|
2022-11-12 09:45:35 +00:00
|
|
|
{
|
2022-12-07 16:32:40 +00:00
|
|
|
quint64 written = m_pFile->write((const char*)data, size);
|
|
|
|
if(written == -1)
|
2022-11-12 09:45:35 +00:00
|
|
|
return E_FAIL;
|
|
|
|
if(processedSize)
|
2022-12-07 16:32:40 +00:00
|
|
|
*processedSize = written;
|
2022-11-12 09:45:35 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-09-14 16:51:54 +01:00
|
|
|
Z7_COM7F_IMF(Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
|
2022-11-12 09:45:35 +00:00
|
|
|
{
|
|
|
|
switch(seekOrigin)
|
|
|
|
{
|
|
|
|
case 0: break; // FILE_BEGIN
|
|
|
|
case 1: offset += m_pFile->pos(); break; // FILE_CURRENT
|
|
|
|
case 2: offset += m_pFile->size(); break; // FILE_END
|
|
|
|
default: Q_ASSERT(0); return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!m_pFile->seek(offset))
|
|
|
|
return E_FAIL;
|
|
|
|
if(newPosition)
|
|
|
|
*newPosition = offset;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-09-14 16:51:54 +01:00
|
|
|
Z7_COM7F_IMF(SetSize(UInt64 newSize))
|
2022-11-12 09:45:35 +00:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-09-14 16:51:54 +01:00
|
|
|
Z7_COM7F_IMF(GetSize(UInt64 *size))
|
2022-11-12 09:45:35 +00:00
|
|
|
{
|
|
|
|
*size = m_pFile->size();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QIODevice* m_pFile;
|
|
|
|
bool m_bDelete;
|
|
|
|
};
|
|
|
|
|
2023-09-14 16:51:54 +01:00
|
|
|
#endif
|