async-iso: Some cleanups.

git-svn-id: http://pcsx2.googlecode.com/svn/branches/async-iso@5473 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gigaherz 2012-12-02 18:16:23 +00:00
parent f7a1e04a46
commit cf5d7780ba
7 changed files with 49 additions and 90 deletions

View File

@ -1,41 +1,5 @@
#pragma once
/*
// --------------------------------------------------------------------------------------
// MultiPartIso
// --------------------------------------------------------------------------------------
// An encapsulating class for array boundschecking and easy ScopedPointer behavior.
//
class _IsoPart
{
DeclareNoncopyableObject( _IsoPart );
public:
// starting block index of this part of the iso.
u32 slsn;
// ending bock index of this part of the iso.
u32 elsn;
wxString filename;
ScopedPtr<wxFileInputStream> handle;
public:
_IsoPart() {}
~_IsoPart() throw();
void Read( void* dest, size_t size );
void Seek(wxFileOffset pos, wxSeekMode mode = wxFromStart);
void SeekEnd(wxFileOffset pos=0);
wxFileOffset Tell() const;
uint CalculateBlocks( uint startBlock, uint blocksize );
template< typename T >
void Read( T& dest )
{
Read( &dest, sizeof(dest) );
}
};
*/
#ifdef WIN32
# include <Windows.h>
# undef Yield
@ -63,7 +27,7 @@ public:
virtual void Close(void)=0;
virtual int GetBlockCount(void) const=0;
virtual uint GetBlockCount(void) const=0;
virtual void SetBlockSize(uint bytes) {}
@ -77,6 +41,8 @@ public:
class FlatFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( FlatFileReader );
#ifdef WIN32
HANDLE hOverlappedFile;
@ -102,7 +68,7 @@ public:
virtual void Close(void);
virtual int GetBlockCount(void) const;
virtual uint GetBlockCount(void) const;
void SetBlockSize(uint bytes) { m_blocksize = bytes; }
};
@ -138,7 +104,7 @@ public:
virtual void Close(void);
virtual int GetBlockCount(void) const;
virtual uint GetBlockCount(void) const;
void SetBlockSize(uint bytes);
@ -155,7 +121,7 @@ class BlockdumpFileReader : public AsyncFileReader
u32 m_blocks;
s32 m_blockofs;
// dtable / dtablesize are used when reading blockdumps
// index table
ScopedArray<u32> m_dtable;
int m_dtablesize;
@ -175,7 +141,7 @@ public:
virtual void Close(void);
virtual int GetBlockCount(void) const;
virtual uint GetBlockCount(void) const;
static bool DetectBlockdump(AsyncFileReader* reader);

View File

@ -69,12 +69,14 @@ bool BlockdumpFileReader::Open(const wxString& fileName)
m_dtable = new u32[m_dtablesize];
m_file->SeekI(BlockDumpHeaderSize);
ScopedPtr<u8> buffer;
u32 bs = 1024*1024;
u8* buffer = new u8[bs];
u32 off = 0;
u32 has = 0;
int i = 0;
buffer = new u8[bs];
do {
m_file->Read(buffer, bs);
has = m_file->LastRead();
@ -90,8 +92,6 @@ bool BlockdumpFileReader::Open(const wxString& fileName)
} while(has == bs);
delete[] buffer;
return true;
}
@ -163,7 +163,7 @@ void BlockdumpFileReader::Close(void)
}
}
int BlockdumpFileReader::GetBlockCount(void) const
uint BlockdumpFileReader::GetBlockCount(void) const
{
return m_blocks;
}

View File

@ -388,7 +388,7 @@ bool DoCDVDopen()
blocksize = 2048;
break;
}
blockDumpFile.WriteFormat(blockofs, blocksize, blocks);
blockDumpFile.WriteHeader(blockofs, blocksize, blocks);
}
@ -413,7 +413,7 @@ s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode)
if (ret == 0 && blockDumpFile.IsOpened())
{
blockDumpFile.WriteBlock(buffer, lsn);
blockDumpFile.WriteSector(buffer, lsn);
}
return ret;
@ -452,7 +452,7 @@ s32 DoCDVDgetBuffer(u8* buffer)
if (ret == 0 && blockDumpFile.IsOpened())
{
blockDumpFile.WriteBlock(buffer, lastLSN);
blockDumpFile.WriteSector(buffer, lastLSN);
}
return ret;

View File

@ -132,21 +132,19 @@ public:
void Create(const wxString& filename, int mode);
void Close();
void WriteFormat(int blockofs, uint blocksize, uint blocks);
void WriteBlock(const u8* src, uint lsn);
void WriteHeader(int blockofs, uint blocksize, uint blocks);
void WriteSector(const u8* src, uint lsn);
protected:
void _init();
void _WriteBlock(const u8* src, uint lsn);
void _WriteBlockD(const u8* src, uint lsn);
void outWrite( const void* src, size_t size );
void WriteBuffer( const void* src, size_t size );
template< typename T >
void outWrite( const T& data )
void WriteValue( const T& data )
{
outWrite( &data, sizeof(data) );
WriteBuffer( &data, sizeof(data) );
}
};

View File

@ -69,7 +69,7 @@ void OutputIsoFile::Create(const wxString& filename, int version)
}
// Generates format header information for blockdumps.
void OutputIsoFile::WriteFormat(int _blockofs, uint _blocksize, uint _blocks)
void OutputIsoFile::WriteHeader(int _blockofs, uint _blocksize, uint _blocks)
{
m_blocksize = _blocksize;
m_blocks = _blocks;
@ -81,40 +81,35 @@ void OutputIsoFile::WriteFormat(int _blockofs, uint _blocksize, uint _blocks)
if (m_version == 2)
{
outWrite("BDV2", 4);
outWrite(m_blocksize);
outWrite(m_blocks);
outWrite(m_blockofs);
WriteBuffer("BDV2", 4);
WriteValue(m_blocksize);
WriteValue(m_blocks);
WriteValue(m_blockofs);
}
}
void OutputIsoFile::_WriteBlock(const u8* src, uint lsn)
{
wxFileOffset ofs = (wxFileOffset)lsn * m_blocksize + m_offset;
m_outstream->SeekO( ofs );
outWrite( src + m_blockofs, m_blocksize );
}
void OutputIsoFile::_WriteBlockD(const u8* src, uint lsn)
{
// Find and ignore blocks that have already been dumped:
for (int i=0; i<m_dtablesize; ++i)
{
if (m_dtable[i] == lsn) return;
}
m_dtable[m_dtablesize++] = lsn;
outWrite<u32>( lsn );
outWrite( src + m_blockofs, m_blocksize );
}
void OutputIsoFile::WriteBlock(const u8* src, uint lsn)
void OutputIsoFile::WriteSector(const u8* src, uint lsn)
{
if (m_version == 2)
_WriteBlockD(src, lsn);
{
// Find and ignore blocks that have already been dumped:
for (int i=0; i<m_dtablesize; ++i)
{
if (m_dtable[i] == lsn) return;
}
m_dtable[m_dtablesize++] = lsn;
WriteValue<u32>( lsn );
}
else
_WriteBlock(src, lsn);
{
wxFileOffset ofs = (wxFileOffset)lsn * m_blocksize + m_offset;
m_outstream->SeekO( ofs );
}
WriteBuffer( src + m_blockofs, m_blocksize );
}
void OutputIsoFile::Close()
@ -124,7 +119,7 @@ void OutputIsoFile::Close()
_init();
}
void OutputIsoFile::outWrite( const void* src, size_t size )
void OutputIsoFile::WriteBuffer( const void* src, size_t size )
{
m_outstream->Write(src, size);
if(m_outstream->GetLastError() == wxSTREAM_WRITE_ERROR)

View File

@ -122,7 +122,7 @@ bool MultipartFileReader::Open(const wxString& fileName)
{
// Cannot open a MultipartFileReader directly,
// use DetectMultipart to convert a FlatFileReader
return -1;
return false;
}
uint MultipartFileReader::GetFirstPart(uint lsn)
@ -208,7 +208,7 @@ void MultipartFileReader::Close(void)
}
}
int MultipartFileReader::GetBlockCount(void) const
uint MultipartFileReader::GetBlockCount(void) const
{
return m_parts[m_numparts-1].end;
}

View File

@ -98,7 +98,7 @@ void FlatFileReader::Close(void)
hEvent = INVALID_HANDLE_VALUE;
}
int FlatFileReader::GetBlockCount(void) const
uint FlatFileReader::GetBlockCount(void) const
{
LARGE_INTEGER fileSize;
fileSize.LowPart = GetFileSize(hOverlappedFile, (DWORD*)&(fileSize.HighPart));