Play-/Source/ISO9660/File.cpp

88 lines
1.7 KiB
C++
Raw Normal View History

#include "File.h"
using namespace ISO9660;
2014-07-12 21:59:58 -04:00
CFile::CFile(CISO9660* iso, uint64 start, uint64 size)
: m_iso(iso)
, m_start(start)
, m_end(start + size)
, m_position(0)
, m_blockPosition(static_cast<uint32>(start / CISO9660::BLOCKSIZE))
{
2014-07-12 21:59:58 -04:00
iso->ReadBlock(m_blockPosition, m_block);
}
CFile::~CFile()
{
}
2014-07-12 21:59:58 -04:00
void CFile::Seek(int64 amount, Framework::STREAM_SEEK_DIRECTION whence)
{
2014-07-12 21:59:58 -04:00
switch(whence)
{
case Framework::STREAM_SEEK_SET:
2014-07-12 21:59:58 -04:00
m_position = amount;
break;
case Framework::STREAM_SEEK_CUR:
2014-07-12 21:59:58 -04:00
m_position += amount;
break;
case Framework::STREAM_SEEK_END:
2014-07-12 21:59:58 -04:00
m_position = m_end + 1;
break;
}
}
uint64 CFile::Tell()
{
if(IsEOF())
{
2014-07-12 21:59:58 -04:00
return m_end - m_start;
}
2014-07-12 21:59:58 -04:00
return m_position;
}
2014-07-12 21:59:58 -04:00
uint64 CFile::Read(void* data, uint64 length)
{
2014-07-12 21:59:58 -04:00
if(length == 0) return 0;
2014-07-12 21:59:58 -04:00
uint64 total = length;
//Read what's remaining of this block
while(1)
{
SyncBlock();
2014-07-12 21:59:58 -04:00
uint64 blockPosition = (m_start + m_position) % CISO9660::BLOCKSIZE;
uint64 blockRemain = CISO9660::BLOCKSIZE - blockPosition;
uint64 toRead = (length > blockRemain) ? (blockRemain) : (length);
2014-07-12 21:59:58 -04:00
memcpy(data, m_block + blockPosition, static_cast<uint32>(toRead));
2014-07-12 21:59:58 -04:00
m_position += toRead;
length -= toRead;
data = reinterpret_cast<uint8*>(data) + toRead;
2014-07-12 21:59:58 -04:00
if(length == 0) break;
}
2014-07-12 21:59:58 -04:00
return total;
}
uint64 CFile::Write(const void* pData, uint64 nLength)
{
return -1;
}
bool CFile::IsEOF()
{
2014-07-12 21:59:58 -04:00
return ((m_start + m_position) > m_end);
}
void CFile::SyncBlock()
{
2014-07-12 21:59:58 -04:00
uint32 position = static_cast<uint32>((m_start + m_position) / CISO9660::BLOCKSIZE);
if(position == m_blockPosition) return;
2014-07-12 21:59:58 -04:00
m_iso->ReadBlock(position, m_block);
m_blockPosition = position;
}