This commit is contained in:
Reece Wilson 2023-09-13 04:01:02 +01:00
parent f177b67e1f
commit fe8ef28930
2 changed files with 63 additions and 39 deletions

View File

@ -313,48 +313,32 @@ namespace Aurora
attrs.nLength = sizeof(attrs);
attrs.bInheritHandle = bInherit ? TRUE : FALSE;
if ((dwFlags & 0x4ffff7) &&
(!pCreateFile2))
bool bSpecialFlags = (dwFlags & 0x4ffff7);
bool bSpecialAttrs = (dwAttributes & 0xFFB00008);
if (!pCreateFile2)
{
if (bSpecialFlags)
{
SysPushErrorFeatureMissing("Do not use Windows8+ attributes/flags under Win32Open");
return INVALID_HANDLE_VALUE;
}
if ((dwAttributes & 0xFFB00008) &&
(!pCreateFile2))
if (bSpecialAttrs)
{
SysPushErrorFeatureMissing("Do not use Windows8+ attributes/flags under Win32Open");
return INVALID_HANDLE_VALUE;
}
}
if (!dwAttributes)
{
dwAttributes = FILE_ATTRIBUTE_NORMAL;
}
if (pCreateFile2)
{
_CREATEFILE2_EXTENDED_PARAMETERS params {};
if (::wcscmp(lpFileName, L"CONIN$") == 0 ||
::wcscmp(lpFileName, L"CONOUT$") == 0 ||
::wcscmp(lpFileName, L"CONERR$") == 0)
{
lpFileName = L"CON";
}
params.dwSize = sizeof(_CREATEFILE2_EXTENDED_PARAMETERS);
params.dwFileFlags = dwFlags;
params.dwFileAttributes = dwAttributes;
params.lpSecurityAttributes = &attrs;
return pCreateFile2(lpFileName,
dwDesiredAccess,
dwShareMode,
dwCreationDisposition,
&params);
}
else if (pCreateFileW)
if (pCreateFileW &&
!bSpecialFlags &&
!bSpecialAttrs)
{
return pCreateFileW(lpFileName,
dwDesiredAccess,
@ -364,9 +348,50 @@ namespace Aurora
dwFlags | dwAttributes,
NULL);
}
if (pCreateFile2)
{
_CREATEFILE2_EXTENDED_PARAMETERS params {};
bool bWrite {};
HANDLE hHandle {};
params.dwSize = sizeof(_CREATEFILE2_EXTENDED_PARAMETERS);
params.dwFileFlags = dwFlags;
params.dwFileAttributes = dwAttributes;
params.lpSecurityAttributes = &attrs;
if ((bWrite = (::wcscmp(lpFileName, L"CONIN$") == 0))||
::wcscmp(lpFileName, L"CONOUT$") == 0 ||
::wcscmp(lpFileName, L"CONERR$") == 0)
{
if (bWrite)
{
dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
}
else
{
dwDesiredAccess = GENERIC_READ;
}
if ((hHandle = pCreateFile2(lpFileName,
dwDesiredAccess,
dwShareMode,
dwCreationDisposition,
&params)) != INVALID_HANDLE_VALUE)
{
return hHandle;
}
lpFileName = L"CON";
}
return pCreateFile2(lpFileName,
dwDesiredAccess,
dwShareMode,
dwCreationDisposition,
&params);
}
return INVALID_HANDLE_VALUE;
}
}
}

View File

@ -51,11 +51,10 @@ namespace Aurora::IO
#if defined(AURORA_PLATFORM_WIN32)
GetStdHandle(STD_INPUT_HANDLE);
#else
Win32Open(L"CONIN$",
GENERIC_READ,
FILE_SHARE_READ,
false,
bSharing,
OPEN_EXISTING,
0,
0);
@ -79,7 +78,7 @@ namespace Aurora::IO
Win32Open(bError ? L"CONERR$" : L"CONOUT$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
false,
bSharing,
OPEN_EXISTING,
0,
0);