Merge pull request #761 from albertofustinoni/master

WinRT compatibility
This commit is contained in:
Tsuda Kageyu
2016-10-24 22:06:35 +09:00
committed by GitHub

View File

@ -50,13 +50,17 @@ namespace
FileHandle openFile(const FileName &path, bool readOnly)
{
const DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
return CreateFile2(path.toString().toCWString(), access, FILE_SHARE_READ, OPEN_EXISTING, NULL);
#else
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);
else
return InvalidFileHandle;
#endif
}
void closeFile(FileHandle file)
@ -437,7 +441,13 @@ long FileStream::length()
#ifdef _WIN32
SetLastError(NO_ERROR);
#if defined(_WIN32_WINNT) && (_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);
}