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

View File

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