pcsx2/: remove ^M eol on 3 files

This commit is contained in:
Gregory Hainaut 2014-07-20 22:09:46 +02:00
parent 50868f14f6
commit e7d0a0345e
2 changed files with 341 additions and 341 deletions

View File

@ -13,175 +13,175 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef WIN32
# include <Windows.h>
# undef Yield
#else
# include <libaio.h>
#endif
class AsyncFileReader
{
protected:
AsyncFileReader(void) {m_dataoffset=0;}
wxString m_filename;
uint m_dataoffset;
uint m_blocksize;
public:
virtual ~AsyncFileReader(void) {};
virtual bool Open(const wxString& fileName)=0;
virtual int ReadSync(void* pBuffer, uint sector, uint count)=0;
virtual void BeginRead(void* pBuffer, uint sector, uint count)=0;
virtual int FinishRead(void)=0;
virtual void CancelRead(void)=0;
virtual void Close(void)=0;
virtual uint GetBlockCount(void) const=0;
virtual void SetBlockSize(uint bytes) {}
virtual void SetDataOffset(uint bytes) {}
uint GetBlockSize() const { return m_blocksize; }
const wxString& GetFilename() const
{
return m_filename;
}
};
class FlatFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( FlatFileReader );
#ifdef WIN32
HANDLE hOverlappedFile;
OVERLAPPED asyncOperationContext;
HANDLE hEvent;
bool asyncInProgress;
#else
int m_fd; // FIXME don't know if overlap as an equivalent on linux
io_context_t m_aio_context;
#endif
public:
FlatFileReader(void);
virtual ~FlatFileReader(void);
virtual bool Open(const wxString& fileName);
virtual int ReadSync(void* pBuffer, uint sector, uint count);
virtual void BeginRead(void* pBuffer, uint sector, uint count);
virtual int FinishRead(void);
virtual void CancelRead(void);
virtual void Close(void);
virtual uint GetBlockCount(void) const;
virtual void SetBlockSize(uint bytes) { m_blocksize = bytes; }
virtual void SetDataOffset(uint bytes) { m_dataoffset = bytes; }
};
// Factory - creates an AsyncFileReader derived instance which can read a compressed file
class CompressedFileReader {
public:
// Checks if any of the available compressed file handlers can open this
static bool DetectCompressed(AsyncFileReader* pReader);
// fileName is only used to choose the compressed reader.
// If no matching handler is found then an arbitrary handlers will be returned.
// The returned instance still needs ->Open(filename) before usage.
// Open(filename) may still fail.
static AsyncFileReader* GetNewReader(const wxString& fileName);
private:
virtual ~CompressedFileReader() = 0;
};
class MultipartFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( MultipartFileReader );
static const int MaxParts = 8;
struct Part {
uint start;
uint end; // exclusive
bool isReading;
AsyncFileReader* reader;
} m_parts[MaxParts];
uint m_numparts;
uint GetFirstPart(uint lsn);
void FindParts();
public:
MultipartFileReader(AsyncFileReader* firstPart);
virtual ~MultipartFileReader(void);
virtual bool Open(const wxString& fileName);
virtual int ReadSync(void* pBuffer, uint sector, uint count);
virtual void BeginRead(void* pBuffer, uint sector, uint count);
virtual int FinishRead(void);
virtual void CancelRead(void);
virtual void Close(void);
virtual uint GetBlockCount(void) const;
virtual void SetBlockSize(uint bytes);
static AsyncFileReader* DetectMultipart(AsyncFileReader* reader);
};
class BlockdumpFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( BlockdumpFileReader );
wxFileInputStream* m_file;
// total number of blocks in the ISO image (including all parts)
u32 m_blocks;
s32 m_blockofs;
// index table
ScopedArray<u32> m_dtable;
int m_dtablesize;
int m_lresult;
public:
BlockdumpFileReader(void);
virtual ~BlockdumpFileReader(void);
virtual bool Open(const wxString& fileName);
virtual int ReadSync(void* pBuffer, uint sector, uint count);
virtual void BeginRead(void* pBuffer, uint sector, uint count);
virtual int FinishRead(void);
virtual void CancelRead(void);
virtual void Close(void);
virtual uint GetBlockCount(void) const;
static bool DetectBlockdump(AsyncFileReader* reader);
int GetBlockOffset() { return m_blockofs; }
};
#pragma once
#ifdef WIN32
# include <Windows.h>
# undef Yield
#else
# include <libaio.h>
#endif
class AsyncFileReader
{
protected:
AsyncFileReader(void) {m_dataoffset=0;}
wxString m_filename;
uint m_dataoffset;
uint m_blocksize;
public:
virtual ~AsyncFileReader(void) {};
virtual bool Open(const wxString& fileName)=0;
virtual int ReadSync(void* pBuffer, uint sector, uint count)=0;
virtual void BeginRead(void* pBuffer, uint sector, uint count)=0;
virtual int FinishRead(void)=0;
virtual void CancelRead(void)=0;
virtual void Close(void)=0;
virtual uint GetBlockCount(void) const=0;
virtual void SetBlockSize(uint bytes) {}
virtual void SetDataOffset(uint bytes) {}
uint GetBlockSize() const { return m_blocksize; }
const wxString& GetFilename() const
{
return m_filename;
}
};
class FlatFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( FlatFileReader );
#ifdef WIN32
HANDLE hOverlappedFile;
OVERLAPPED asyncOperationContext;
HANDLE hEvent;
bool asyncInProgress;
#else
int m_fd; // FIXME don't know if overlap as an equivalent on linux
io_context_t m_aio_context;
#endif
public:
FlatFileReader(void);
virtual ~FlatFileReader(void);
virtual bool Open(const wxString& fileName);
virtual int ReadSync(void* pBuffer, uint sector, uint count);
virtual void BeginRead(void* pBuffer, uint sector, uint count);
virtual int FinishRead(void);
virtual void CancelRead(void);
virtual void Close(void);
virtual uint GetBlockCount(void) const;
virtual void SetBlockSize(uint bytes) { m_blocksize = bytes; }
virtual void SetDataOffset(uint bytes) { m_dataoffset = bytes; }
};
// Factory - creates an AsyncFileReader derived instance which can read a compressed file
class CompressedFileReader {
public:
// Checks if any of the available compressed file handlers can open this
static bool DetectCompressed(AsyncFileReader* pReader);
// fileName is only used to choose the compressed reader.
// If no matching handler is found then an arbitrary handlers will be returned.
// The returned instance still needs ->Open(filename) before usage.
// Open(filename) may still fail.
static AsyncFileReader* GetNewReader(const wxString& fileName);
private:
virtual ~CompressedFileReader() = 0;
};
class MultipartFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( MultipartFileReader );
static const int MaxParts = 8;
struct Part {
uint start;
uint end; // exclusive
bool isReading;
AsyncFileReader* reader;
} m_parts[MaxParts];
uint m_numparts;
uint GetFirstPart(uint lsn);
void FindParts();
public:
MultipartFileReader(AsyncFileReader* firstPart);
virtual ~MultipartFileReader(void);
virtual bool Open(const wxString& fileName);
virtual int ReadSync(void* pBuffer, uint sector, uint count);
virtual void BeginRead(void* pBuffer, uint sector, uint count);
virtual int FinishRead(void);
virtual void CancelRead(void);
virtual void Close(void);
virtual uint GetBlockCount(void) const;
virtual void SetBlockSize(uint bytes);
static AsyncFileReader* DetectMultipart(AsyncFileReader* reader);
};
class BlockdumpFileReader : public AsyncFileReader
{
DeclareNoncopyableObject( BlockdumpFileReader );
wxFileInputStream* m_file;
// total number of blocks in the ISO image (including all parts)
u32 m_blocks;
s32 m_blockofs;
// index table
ScopedArray<u32> m_dtable;
int m_dtablesize;
int m_lresult;
public:
BlockdumpFileReader(void);
virtual ~BlockdumpFileReader(void);
virtual bool Open(const wxString& fileName);
virtual int ReadSync(void* pBuffer, uint sector, uint count);
virtual void BeginRead(void* pBuffer, uint sector, uint count);
virtual int FinishRead(void);
virtual void CancelRead(void);
virtual void Close(void);
virtual uint GetBlockCount(void) const;
static bool DetectBlockdump(AsyncFileReader* reader);
int GetBlockOffset() { return m_blockofs; }
};

View File

@ -13,172 +13,172 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "AsyncFileReader.h"
#include "IopCommon.h"
#include "IsoFileFormats.h"
#include <errno.h>
enum isoFlags
{
ISOFLAGS_BLOCKDUMP_V2 = 0x0004,
ISOFLAGS_BLOCKDUMP_V3 = 0x0020
};
static const uint BlockDumpHeaderSize = 16;
bool BlockdumpFileReader::DetectBlockdump(AsyncFileReader* reader)
{
uint oldbs = reader->GetBlockSize();
reader->SetBlockSize(1);
char buf[4];
reader->ReadSync(buf, 0, 4);
bool isbd = (strncmp(buf, "BDV2", 4) == 0);
if(!isbd)
reader->SetBlockSize(oldbs);
return isbd;
}
BlockdumpFileReader::BlockdumpFileReader(void)
{
}
BlockdumpFileReader::~BlockdumpFileReader(void)
{
Close();
}
bool BlockdumpFileReader::Open(const wxString& fileName)
{
char buf[32];
m_filename = fileName;
m_file = new wxFileInputStream( m_filename );
m_file->SeekI(0);
m_file->Read(buf, 4);
if (strncmp(buf, "BDV2", 4) != 0)
{
return false;
}
//m_flags = ISOFLAGS_BLOCKDUMP_V2;
m_file->Read(&m_blocksize, sizeof(m_blocksize));
m_file->Read(&m_blocks, sizeof(m_blocks));
m_file->Read(&m_blockofs, sizeof(m_blockofs));
wxFileOffset flen = m_file->GetLength();
static const wxFileOffset datalen = flen - BlockDumpHeaderSize;
pxAssert( (datalen % (m_blocksize + 4)) == 0);
m_dtablesize = datalen / (m_blocksize + 4);
m_dtable = new u32[m_dtablesize];
m_file->SeekI(BlockDumpHeaderSize);
ScopedPtr<u8> buffer;
u32 bs = 1024*1024;
u32 off = 0;
u32 has = 0;
int i = 0;
buffer = new u8[bs];
do {
m_file->Read(buffer, bs);
has = m_file->LastRead();
while (i < m_dtablesize && off < has)
{
m_dtable[i++] = *(u32*)(buffer + off);
off += 4;
off += m_blocksize;
}
off -= has;
} while(has == bs);
return true;
}
int BlockdumpFileReader::ReadSync(void* pBuffer, uint lsn, uint count)
{
u8* dst = (u8*)pBuffer;
// Console.WriteLn("_isoReadBlockD %u, blocksize=%u, blockofs=%u\n", lsn, iso->blocksize, iso->blockofs);
while(count > 0)
{
bool ok = false;
for (int i = 0; i < m_dtablesize; ++i)
{
if (m_dtable[i] != lsn)
continue;
// We store the LSN (u32) along with each block inside of blockdumps, so the
// seek position ends up being based on (m_blocksize + 4) instead of just m_blocksize.
#ifdef PCSX2_DEBUG
u32 check_lsn;
m_file->SeekI( BlockDumpHeaderSize + (i * (m_blocksize + 4)) );
m_file->Read( &check_lsn, sizeof(check_lsn) );
pxAssert( check_lsn == lsn );
#else
m_file->SeekI( BlockDumpHeaderSize + (i * (m_blocksize + 4)) + 4 );
#endif
m_file->Read( dst, m_blocksize );
ok = true;
break;
}
if(!ok)
{
Console.WriteLn("Block %u not found in dump", lsn);
return -1;
}
count--;
lsn++;
dst += m_blocksize;
}
return 0;
}
void BlockdumpFileReader::BeginRead(void* pBuffer, uint sector, uint count)
{
m_lresult = ReadSync(pBuffer, sector, count);
}
int BlockdumpFileReader::FinishRead(void)
{
return m_lresult;
}
void BlockdumpFileReader::CancelRead(void)
{
}
void BlockdumpFileReader::Close(void)
{
if(m_file)
{
delete m_file;
m_file = NULL;
}
}
uint BlockdumpFileReader::GetBlockCount(void) const
{
return m_blocks;
}
#include "PrecompiledHeader.h"
#include "AsyncFileReader.h"
#include "IopCommon.h"
#include "IsoFileFormats.h"
#include <errno.h>
enum isoFlags
{
ISOFLAGS_BLOCKDUMP_V2 = 0x0004,
ISOFLAGS_BLOCKDUMP_V3 = 0x0020
};
static const uint BlockDumpHeaderSize = 16;
bool BlockdumpFileReader::DetectBlockdump(AsyncFileReader* reader)
{
uint oldbs = reader->GetBlockSize();
reader->SetBlockSize(1);
char buf[4];
reader->ReadSync(buf, 0, 4);
bool isbd = (strncmp(buf, "BDV2", 4) == 0);
if(!isbd)
reader->SetBlockSize(oldbs);
return isbd;
}
BlockdumpFileReader::BlockdumpFileReader(void)
{
}
BlockdumpFileReader::~BlockdumpFileReader(void)
{
Close();
}
bool BlockdumpFileReader::Open(const wxString& fileName)
{
char buf[32];
m_filename = fileName;
m_file = new wxFileInputStream( m_filename );
m_file->SeekI(0);
m_file->Read(buf, 4);
if (strncmp(buf, "BDV2", 4) != 0)
{
return false;
}
//m_flags = ISOFLAGS_BLOCKDUMP_V2;
m_file->Read(&m_blocksize, sizeof(m_blocksize));
m_file->Read(&m_blocks, sizeof(m_blocks));
m_file->Read(&m_blockofs, sizeof(m_blockofs));
wxFileOffset flen = m_file->GetLength();
static const wxFileOffset datalen = flen - BlockDumpHeaderSize;
pxAssert( (datalen % (m_blocksize + 4)) == 0);
m_dtablesize = datalen / (m_blocksize + 4);
m_dtable = new u32[m_dtablesize];
m_file->SeekI(BlockDumpHeaderSize);
ScopedPtr<u8> buffer;
u32 bs = 1024*1024;
u32 off = 0;
u32 has = 0;
int i = 0;
buffer = new u8[bs];
do {
m_file->Read(buffer, bs);
has = m_file->LastRead();
while (i < m_dtablesize && off < has)
{
m_dtable[i++] = *(u32*)(buffer + off);
off += 4;
off += m_blocksize;
}
off -= has;
} while(has == bs);
return true;
}
int BlockdumpFileReader::ReadSync(void* pBuffer, uint lsn, uint count)
{
u8* dst = (u8*)pBuffer;
// Console.WriteLn("_isoReadBlockD %u, blocksize=%u, blockofs=%u\n", lsn, iso->blocksize, iso->blockofs);
while(count > 0)
{
bool ok = false;
for (int i = 0; i < m_dtablesize; ++i)
{
if (m_dtable[i] != lsn)
continue;
// We store the LSN (u32) along with each block inside of blockdumps, so the
// seek position ends up being based on (m_blocksize + 4) instead of just m_blocksize.
#ifdef PCSX2_DEBUG
u32 check_lsn;
m_file->SeekI( BlockDumpHeaderSize + (i * (m_blocksize + 4)) );
m_file->Read( &check_lsn, sizeof(check_lsn) );
pxAssert( check_lsn == lsn );
#else
m_file->SeekI( BlockDumpHeaderSize + (i * (m_blocksize + 4)) + 4 );
#endif
m_file->Read( dst, m_blocksize );
ok = true;
break;
}
if(!ok)
{
Console.WriteLn("Block %u not found in dump", lsn);
return -1;
}
count--;
lsn++;
dst += m_blocksize;
}
return 0;
}
void BlockdumpFileReader::BeginRead(void* pBuffer, uint sector, uint count)
{
m_lresult = ReadSync(pBuffer, sector, count);
}
int BlockdumpFileReader::FinishRead(void)
{
return m_lresult;
}
void BlockdumpFileReader::CancelRead(void)
{
}
void BlockdumpFileReader::Close(void)
{
if(m_file)
{
delete m_file;
m_file = NULL;
}
}
uint BlockdumpFileReader::GetBlockCount(void) const
{
return m_blocks;
}