Core/Win32: Fix file opening in ReadWrite mode

Former-commit-id: 58feae9f282529b8067fae52e81d29bdada154f9
This commit is contained in:
Lynix 2015-11-30 12:50:55 +01:00
parent 1e5cad5b24
commit 9b0e903e31
1 changed files with 13 additions and 23 deletions

View File

@ -56,40 +56,30 @@ namespace Nz
bool FileImpl::Open(const String& filePath, UInt32 mode)
{
DWORD access;
DWORD access = 0;
DWORD shareMode = FILE_SHARE_READ;
DWORD openMode;
DWORD openMode = 0;
if (mode & OpenMode_ReadOnly)
{
access = GENERIC_READ;
openMode = OPEN_EXISTING;
access |= GENERIC_READ;
if ((mode & OpenMode_WriteOnly) == 0)
openMode |= OPEN_EXISTING;
}
else if (mode & OpenMode_ReadWrite)
if (mode & OpenMode_WriteOnly)
{
if (mode & OpenMode_Append)
access = FILE_APPEND_DATA;
access |= FILE_APPEND_DATA;
else
access = GENERIC_READ | GENERIC_WRITE;
access |= GENERIC_WRITE;
if (mode & OpenMode_Truncate)
openMode = CREATE_ALWAYS;
openMode |= CREATE_ALWAYS;
else
openMode = OPEN_ALWAYS;
openMode |= OPEN_ALWAYS;
}
else if (mode & OpenMode_WriteOnly)
{
if (mode & OpenMode_Append)
access = FILE_APPEND_DATA;
else
access = GENERIC_WRITE;
if (mode & OpenMode_Truncate)
openMode = CREATE_ALWAYS;
else
openMode = OPEN_ALWAYS;
}
else
return false;
if ((mode & OpenMode_Lock) == 0)
shareMode |= FILE_SHARE_WRITE;