[Project64] Get File Class.cpp to use standard types

This commit is contained in:
zilmar 2015-11-11 17:47:22 +11:00
parent 866d18a97b
commit 4b150ded03
2 changed files with 13 additions and 22 deletions

View File

@ -82,13 +82,12 @@ bool CFile::Open(const char * lpszFileName, uint32_t nOpenFlags)
ULONG dwCreateFlag = 0;
if (nOpenFlags & modeCreate)
{
if (nOpenFlags & modeNoTruncate)
dwCreateFlag = OPEN_ALWAYS;
else
dwCreateFlag = CREATE_ALWAYS;
dwCreateFlag = nOpenFlags & modeNoTruncate == 0 ? OPEN_ALWAYS : CREATE_ALWAYS;
}
else
{
dwCreateFlag = OPEN_EXISTING;
}
// attempt file creation
HANDLE hFile = ::CreateFile(lpszFileName, dwAccess, dwShareMode, &sa, dwCreateFlag, FILE_ATTRIBUTE_NORMAL, NULL);
@ -140,19 +139,15 @@ bool CFile::Flush()
return ::FlushFileBuffers(m_hFile) != 0;
}
bool CFile::Write(const void* lpBuf, size_t nCount)
bool CFile::Write(const void* lpBuf, uint32_t nCount)
{
if (nCount == 0)
{
return true; // avoid Win32 "null-write" option
}
if (nCount > ULONG_MAX)
{
nCount = ULONG_MAX; /* Or should we loop WriteFile() every 2 GB? */
}
DWORD nWritten = 0;
if (!::WriteFile(m_hFile, lpBuf, (DWORD)nCount, &nWritten, NULL))
ULONG nWritten = 0;
if (!::WriteFile(m_hFile, lpBuf, nCount, &nWritten, NULL))
{
return false;
}
@ -165,23 +160,19 @@ bool CFile::Write(const void* lpBuf, size_t nCount)
return true;
}
size_t CFile::Read(void* lpBuf, size_t nCount)
uint32_t CFile::Read(void* lpBuf, uint32_t nCount)
{
if (nCount == 0)
{
return 0; // avoid Win32 "null-read"
}
if (nCount > ULONG_MAX)
{
nCount = ULONG_MAX; /* Or should we loop ReadFile() every 2 GB? */
}
DWORD dwRead = 0;
if (!::ReadFile(m_hFile, lpBuf, (DWORD)nCount, &dwRead, NULL))
if (!::ReadFile(m_hFile, lpBuf, nCount, &dwRead, NULL))
{
return 0;
}
return (dwRead);
return (uint32_t)dwRead;
}
long CFile::Seek(long lOff, SeekPosition nFrom)

View File

@ -40,8 +40,8 @@ public:
virtual bool SetLength(uint32_t dwNewLen) = 0;
virtual uint32_t GetLength() const = 0;
virtual size_t Read(void* lpBuf, size_t nCount) = 0;
virtual bool Write(const void* lpBuf, size_t nCount) = 0;
virtual uint32_t Read(void* lpBuf, uint32_t nCount) = 0;
virtual bool Write(const void* lpBuf, uint32_t nCount) = 0;
virtual bool Flush() = 0;
virtual bool Close() = 0;
@ -78,8 +78,8 @@ public:
virtual bool SetLength(uint32_t dwNewLen);
virtual uint32_t GetLength() const;
virtual size_t Read(void* lpBuf, size_t nCount);
virtual bool Write(const void* lpBuf, size_t nCount);
virtual uint32_t Read(void* lpBuf, uint32_t nCount);
virtual bool Write(const void* lpBuf, uint32_t nCount);
virtual bool Flush();
virtual bool Close();