Use newer file system calls when in Windows 8+ to allow compilation as WinRT asembly

This commit is contained in:
Alberto Fustinoni 2016-10-23 12:32:16 +09:00
parent 97aaa0f979
commit deffe83fd0

View File

@ -51,10 +51,22 @@ namespace
{
const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
if(!path.wstr().empty())
return CreateFileW(path.wstr().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
else if(!path.str().empty())
return CreateFileA(path.str().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(!path.wstr().empty())
{
#if (_WIN32_WINNT >= 0x0602)
return CreateFile2(path.wstr().c_str(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
#else
return CreateFileW(path.wstr().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
#endif
}
else if(!path.str().empty())
{
#if (_WIN32_WINNT >= 0x0602)
return CreateFile2(path.toString().toCWString(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
#else
return CreateFileA(path.str().c_str(), access, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
#endif
}
else
return InvalidFileHandle;
}
@ -437,7 +449,13 @@ long FileStream::length()
#ifdef _WIN32
SetLastError(NO_ERROR);
#if (_WIN32_WINNT >= 0x0602)
LARGE_INTEGER fSize;
GetFileSizeEx(d->file, &fSize);
LONGLONG fileSize = fSize.QuadPart;
#else
const DWORD fileSize = GetFileSize(d->file, NULL);
#endif
if(GetLastError() == NO_ERROR) {
return static_cast<long>(fileSize);
}