diff --git a/pcsx2/AsyncFileReader.h b/pcsx2/AsyncFileReader.h index d75e67ea41..1d6d0981d9 100644 --- a/pcsx2/AsyncFileReader.h +++ b/pcsx2/AsyncFileReader.h @@ -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 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 # 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 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); diff --git a/pcsx2/CDVD/BlockdumpFileReader.cpp b/pcsx2/CDVD/BlockdumpFileReader.cpp index ea035c3f1a..06b2cbd5bf 100644 --- a/pcsx2/CDVD/BlockdumpFileReader.cpp +++ b/pcsx2/CDVD/BlockdumpFileReader.cpp @@ -69,12 +69,14 @@ bool BlockdumpFileReader::Open(const wxString& fileName) m_dtable = new u32[m_dtablesize]; m_file->SeekI(BlockDumpHeaderSize); - + + ScopedPtr 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; } diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index dc3e8c23fe..cf71955a22 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -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; diff --git a/pcsx2/CDVD/IsoFileFormats.h b/pcsx2/CDVD/IsoFileFormats.h index f026c59fe4..dc1bd03ec9 100644 --- a/pcsx2/CDVD/IsoFileFormats.h +++ b/pcsx2/CDVD/IsoFileFormats.h @@ -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) ); } }; diff --git a/pcsx2/CDVD/OutputIsoFile.cpp b/pcsx2/CDVD/OutputIsoFile.cpp index a2bac83ca2..7168158bfa 100644 --- a/pcsx2/CDVD/OutputIsoFile.cpp +++ b/pcsx2/CDVD/OutputIsoFile.cpp @@ -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( 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( 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) diff --git a/pcsx2/MultipartFileReader.cpp b/pcsx2/MultipartFileReader.cpp index 16acdcf4ac..62a96af4bf 100644 --- a/pcsx2/MultipartFileReader.cpp +++ b/pcsx2/MultipartFileReader.cpp @@ -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; } diff --git a/pcsx2/windows/FlatFileReaderWindows.cpp b/pcsx2/windows/FlatFileReaderWindows.cpp index 00ee4164e2..8e0c908c1b 100644 --- a/pcsx2/windows/FlatFileReaderWindows.cpp +++ b/pcsx2/windows/FlatFileReaderWindows.cpp @@ -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));