From deffe83fd04f7d6fa2ef496b02efb7563d5dea02 Mon Sep 17 00:00:00 2001 From: Alberto Fustinoni Date: Sun, 23 Oct 2016 12:32:16 +0900 Subject: [PATCH] Use newer file system calls when in Windows 8+ to allow compilation as WinRT asembly --- taglib/toolkit/tfilestream.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 5205bae0..54f7ffe9 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -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(fileSize); } -- 2.40.0