Play-/Source/ISO9660/BlockProvider.h

105 lines
2.3 KiB
C
Raw Permalink Normal View History

#pragma once
2015-07-31 14:06:45 -04:00
#include <memory>
#include <cassert>
#include "Types.h"
#include "Stream.h"
namespace ISO9660
{
class CBlockProvider
{
public:
enum BLOCKSIZE
{
BLOCKSIZE = 0x800ULL
};
2018-10-04 09:15:30 -04:00
virtual ~CBlockProvider() = default;
2018-04-30 21:01:23 +01:00
virtual void ReadBlock(uint32, void*) = 0;
virtual void ReadRawBlock(uint32, void*) = 0;
virtual uint32 GetBlockCount() = 0;
virtual uint32 GetRawBlockSize() const = 0;
};
class CBlockProvider2048 : public CBlockProvider
{
public:
typedef std::shared_ptr<Framework::CStream> StreamPtr;
2018-10-08 00:04:04 -04:00
CBlockProvider2048(const StreamPtr& stream, uint32 offset = 0)
2018-04-30 21:01:23 +01:00
: m_stream(stream)
2018-10-08 00:04:04 -04:00
, m_offset(offset)
{
}
void ReadBlock(uint32 address, void* block) override
{
2018-10-08 00:04:04 -04:00
m_stream->Seek(static_cast<uint64>(address + m_offset) * BLOCKSIZE, Framework::STREAM_SEEK_SET);
m_stream->Read(block, BLOCKSIZE);
}
void ReadRawBlock(uint32 address, void* block) override
{
ReadBlock(address, block);
}
uint32 GetBlockCount() override
{
uint64 imageSize = m_stream->GetLength();
assert((imageSize % BLOCKSIZE) == 0);
return static_cast<uint32>(imageSize / BLOCKSIZE);
}
uint32 GetRawBlockSize() const override
{
return BLOCKSIZE;
}
private:
StreamPtr m_stream;
2018-10-08 00:04:04 -04:00
uint32 m_offset = 0;
};
2021-07-21 11:11:24 -04:00
template <uint64 INTERNAL_BLOCKSIZE, uint64 BLOCKHEADER_SIZE>
class CBlockProviderCustom : public CBlockProvider
{
public:
typedef std::shared_ptr<Framework::CStream> StreamPtr;
CBlockProviderCustom(const StreamPtr& stream)
2018-04-30 21:01:23 +01:00
: m_stream(stream)
{
}
void ReadBlock(uint32 address, void* block) override
{
m_stream->Seek((static_cast<uint64>(address) * INTERNAL_BLOCKSIZE) + BLOCKHEADER_SIZE, Framework::STREAM_SEEK_SET);
m_stream->Read(block, BLOCKSIZE);
}
void ReadRawBlock(uint32 address, void* block) override
{
m_stream->Seek(static_cast<uint64>(address) * INTERNAL_BLOCKSIZE, Framework::STREAM_SEEK_SET);
m_stream->Read(block, INTERNAL_BLOCKSIZE);
}
uint32 GetBlockCount() override
{
uint64 imageSize = m_stream->GetLength();
assert((imageSize % INTERNAL_BLOCKSIZE) == 0);
return static_cast<uint32>(imageSize / INTERNAL_BLOCKSIZE);
}
uint32 GetRawBlockSize() const override
{
return INTERNAL_BLOCKSIZE;
}
private:
StreamPtr m_stream;
};
typedef CBlockProviderCustom<0x930ULL, 0x18ULL> CBlockProviderCDROMXA;
}