]> granicus.if.org Git - taglib/commitdiff
Use newer file system calls when in Windows 8+ to allow compilation as WinRT asembly
authorAlberto Fustinoni <alberto@aftnet.net>
Sun, 23 Oct 2016 03:32:16 +0000 (12:32 +0900)
committerAlberto Fustinoni <alberto@aftnet.net>
Sun, 23 Oct 2016 03:32:16 +0000 (12:32 +0900)
taglib/toolkit/tfilestream.cpp

index 5205bae0b6c610bef0edd0e9288e216032d2a82f..54f7ffe9ef64384ff367665ddabdaf0decf8c392 100644 (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);
   }