Serious cleanup and update of Windows RT support.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 24 Jul 2017 03:29:33 -0400
changeset 1518 a6ac19814d53
parent 1517 571cdd19f992
child 1519 3edf28828371
Serious cleanup and update of Windows RT support. This compiles for WinRT, but isn't otherwise tested at all yet.
CMakeLists.txt
docs/INSTALL.txt
src/physfs_internal.h
src/physfs_platform_windows.c
src/physfs_platform_winrt.cpp
src/physfs_platforms.h
--- a/CMakeLists.txt	Mon Jul 24 02:37:22 2017 -0400
+++ b/CMakeLists.txt	Mon Jul 24 03:29:33 2017 -0400
@@ -42,12 +42,16 @@
 if(HAIKU)
     # We add this explicitly, since we don't want CMake to think this
     #  is a C++ project unless we're on Haiku.
-    set(PHYSFS_HAIKU_SRCS src/physfs_platform_haiku.cpp)
+    set(PHYSFS_CPP_SRCS src/physfs_platform_haiku.cpp)
     find_library(BE_LIBRARY be)
     find_library(ROOT_LIBRARY root)
     set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY})
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
+    set(PHYSFS_CPP_SRCS src/physfs_platform_winrt.cpp)
+endif()
+
 if(UNIX AND NOT WINDOWS AND NOT APPLE)  # (MingW and such might be UNIX _and_ WINDOWS!)
     find_library(PTHREAD_LIBRARY pthread)
     if(PTHREAD_LIBRARY)
@@ -80,7 +84,7 @@
     src/physfs_archiver_slb.c
     src/physfs_archiver_iso9660.c
     src/physfs_archiver_vdf.c
-    ${PHYSFS_HAIKU_SRCS}
+    ${PHYSFS_CPP_SRCS}
 )
 
 
--- a/docs/INSTALL.txt	Mon Jul 24 02:37:22 2017 -0400
+++ b/docs/INSTALL.txt	Mon Jul 24 03:29:33 2017 -0400
@@ -26,8 +26,12 @@
 directory to whatever you use to build your program and compile it along with
 everything else, and you're done. It should compile with any reasonable
 ANSI C compiler, should build cleanly even with excessive compiler warnings
-enabled, needs no extra configuration, and allows static linking. If this
-works for your specific project, you can stop reading now.
+enabled, needs no extra configuration, and allows static linking.
+WinRT and Haiku need C++ compilers for their system APIs, but if you aren't on
+these platforms and don't have a C++ compiler, don't build the .cpp files.
+Everything you need is in the .c sources.
+
+If this all worked for your specific project, you can stop reading now.
 
 
 
@@ -75,18 +79,27 @@
 PhysicsFS will only link directly against system libraries that have existed
  since Windows NT 3.51. If there's a newer API we want to use, we try to
  dynamically load it at runtime and fallback to a reasonable behaviour when
- we can't find it. Note that OSes based on Windows 95 _should_
+ we can't find it. Note that Windows 98 and later _should_
  work if you use the Microsoft Layer for Unicode (UNICOWS.DLL) to provide
  some missing system APIs, but this is no longer tested as of PhysicsFS 2.1.0.
  PhysicsFS 2.0.x is known to work with Windows 95 without UNICOWS.DLL.
 
 PhysicsFS works on 32-bit and 64-bit Windows. There is no 16-bit Windows
- support at all. Windows RT (Windows Phone, UWP) is covered below.
+ support at all. Windows RT is covered below.
 
 
 Windows RT:
 
-This supposedly works, but isn't tested recently.
+Windows RT (Windows Phone, Windows Store, UWP) 8.0 and later are supported.
+Make sure you include both physfs_platform_windows.c _and_
+physfs_platform_winrt.cpp in your build, and that the C++ file has
+"Consume Windows Runtime Extension" set to "Yes" in its Visual Studio
+properties (from the command line, you want to compile this file with the
+"/ZW" compiler switch). CMake can, in theory, generate a project file for
+WinRT if you pick a recent Visual Studio target, choose manual cross-compile
+options, and set the system name to "WindowsPhone" or "WindowsStore" and the
+correct OS version (8.0 or later).
+
 
 
 PocketPC/WindowsCE:
--- a/src/physfs_internal.h	Mon Jul 24 02:37:22 2017 -0400
+++ b/src/physfs_internal.h	Mon Jul 24 03:29:33 2017 -0400
@@ -98,6 +98,12 @@
 #define snprintf __PHYSFS_msvc_snprintf
 #endif
 
+/* Some simple wrappers around WinRT C++ interfaces we can call from C. */
+#ifdef PHYSFS_PLATFORM_WINRT
+const void *__PHYSFS_winrtCalcBaseDir(void);
+const void *__PHYSFS_winrtCalcPrefDir(void);
+#endif
+
 /*
  * Interface for small allocations. If you need a little scratch space for
  *  a throwaway buffer or string, use this. It will make small allocations
--- a/src/physfs_platform_windows.c	Mon Jul 24 02:37:22 2017 -0400
+++ b/src/physfs_platform_windows.c	Mon Jul 24 03:29:33 2017 -0400
@@ -10,7 +10,6 @@
 #include "physfs_internal.h"
 
 #ifdef PHYSFS_PLATFORM_WINDOWS
-#ifndef PHYSFS_PLATFORM_WINRT
 
 /* Forcibly disable UNICODE macro, since we manage this ourselves. */
 #ifdef UNICODE
@@ -22,9 +21,16 @@
 
 #define WIN32_LEAN_AND_MEAN 1
 #include <windows.h>
+
+#ifndef PHYSFS_PLATFORM_WINRT
 #include <userenv.h>
 #include <shlobj.h>
+#endif
+
+#if !defined(PHYSFS_NO_CDROM_SUPPORT)
 #include <dbt.h>
+#endif
+
 #include <errno.h>
 #include <ctype.h>
 #include <time.h>
@@ -34,9 +40,6 @@
 #endif
 #define allocator __PHYSFS_AllocatorHooks
 
-#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF))
-#define HIGHORDER_UINT64(pos) ((PHYSFS_uint32) ((pos >> 32) & 0xFFFFFFFF))
-
 /*
  * Users without the platform SDK don't have this defined.  The original docs
  *  for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
@@ -96,10 +99,83 @@
     int readonly;
 } WinApiFile;
 
-static HANDLE detectCDThreadHandle = NULL;
-static HWND detectCDHwnd = 0;
-static volatile int initialDiscDetectionComplete = 0;
-static volatile DWORD drivesWithMediaBitmap = 0;
+
+/* Some older APIs aren't in WinRT (only the "Ex" version, etc).
+   Since non-WinRT might not have the "Ex" version, we tapdance to use
+   the perfectly-fine-and-available-even-on-Win95 API on non-WinRT targets. */
+
+static inline HANDLE winFindFirstFileW(const WCHAR *path, LPWIN32_FIND_DATAW d)
+{
+    #ifdef PHYSFS_PLATFORM_WINRT
+    return FindFirstFileExW(path, FindExInfoStandard, d,
+                            FindExSearchNameMatch, NULL, 0);
+    #else
+    return FindFirstFileW(path, d);
+    #endif
+} /* winFindFirstFileW */
+
+static inline BOOL winInitializeCriticalSection(LPCRITICAL_SECTION lpcs)
+{
+    #ifdef PHYSFS_PLATFORM_WINRT
+    return InitializeCriticalSectionEx(lpcs, 2000, 0);
+    #else
+    InitializeCriticalSection(lpcs);
+    return TRUE;
+    #endif
+} /* winInitializeCriticalSection */
+
+static inline HANDLE winCreateFileW(const WCHAR *wfname, const DWORD mode,
+                                    const DWORD creation)
+{
+    const DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE;
+    #ifdef PHYSFS_PLATFORM_WINRT
+    return CreateFile2(wfname, mode, share, creation, NULL);
+    #else
+    return CreateFileW(wfname, mode, share, NULL, creation,
+                       FILE_ATTRIBUTE_NORMAL, NULL);
+    #endif
+} /* winCreateFileW */
+
+static BOOL winSetFilePointer(HANDLE h, const PHYSFS_sint64 pos,
+                              PHYSFS_sint64 *_newpos, const DWORD whence)
+{
+    #ifdef PHYSFS_PLATFORM_WINRT
+    LARGE_INTEGER lipos;
+    LARGE_INTEGER linewpos;
+    BOOL rc;
+    lipos.QuadPart = (LONGLONG) pos;
+    rc = SetFilePointerEx(h, lipos, &linewpos, whence);
+    if (_newpos)
+        *_newpos = (PHYSFS_sint64) linewpos.QuadPart;
+    return rc;
+    #else
+    const LONG low = (LONG) (pos & 0xFFFFFFFF);
+    LONG high = (LONG) ((pos >> 32) & 0xFFFFFFFF);
+    const DWORD rc = SetFilePointer(h, low, &high, whence);
+    /* 0xFFFFFFFF could be valid, so you have to check GetLastError too! */
+    if (_newpos)
+        *_newpos = ((PHYSFS_sint64) rc) | (((PHYSFS_sint64) high) << 32);
+    if ((rc == PHYSFS_INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
+        return FALSE;
+    return TRUE;
+    #endif
+} /* winSetFilePointer */
+
+static PHYSFS_sint64 winGetFileSize(HANDLE h)
+{
+    #ifdef PHYSFS_PLATFORM_WINRT
+    FILE_STANDARD_INFO info;
+    const BOOL rc = GetFileInformationByHandleEx(h, FileStandardInfo,
+                                                 &info, sizeof (info));
+    return rc ? (PHYSFS_sint64) info.EndOfFile.QuadPart : -1;
+    #else
+    DWORD high = 0;
+    const DWORD rc = GetFileSize(h, &high);
+    if ((rc == PHYSFS_INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
+        return -1;
+    return (PHYSFS_sint64) ((((PHYSFS_uint64) high) << 32) | rc);
+    #endif
+} /* winGetFileSize */
 
 
 static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err)
@@ -160,6 +236,15 @@
 } /* errcodeFromWinApi */
 
 
+#if defined(PHYSFS_NO_CDROM_SUPPORT)
+#define detectAvailableCDs(cb, data)
+#define deinitCDThread()
+#else
+static HANDLE detectCDThreadHandle = NULL;
+static HWND detectCDHwnd = 0;
+static volatile int initialDiscDetectionComplete = 0;
+static volatile DWORD drivesWithMediaBitmap = 0;
+
 typedef BOOL (WINAPI *fnSTEM)(DWORD, LPDWORD b);
 
 static DWORD pollDiscDrives(void)
@@ -267,6 +352,7 @@
 
     /* Do initial detection, possibly blocking awhile... */
     drivesWithMediaBitmap = pollDiscDrives();
+    /* !!! FIXME: atomic operation, please. */
     initialDiscDetectionComplete = 1;  /* let main thread go on. */
 
     do
@@ -281,6 +367,7 @@
     /* we've been asked to quit. */
     DestroyWindow(detectCDHwnd);
 
+    /* !!! FIXME: why is this here? Was this a copy/paste error? */
     do
     {
         const BOOL rc = GetMessage(&msg, detectCDHwnd, 0, 0);
@@ -295,8 +382,7 @@
     return 0;
 } /* detectCDThread */
 
-
-void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
+static void detectAvailableCDs(PHYSFS_StringCallback cb, void *data)
 {
     char drive_str[4] = { 'x', ':', '\\', '\0' };
     DWORD drives = 0;
@@ -329,14 +415,59 @@
             cb(data, drive_str);
         } /* if */
     } /* for */
+} /* detectAvailableCDs */
+
+static void deinitCDThread(void)
+{
+    if (detectCDThreadHandle)
+    {
+        if (detectCDHwnd)
+            PostMessageW(detectCDHwnd, WM_QUIT, 0, 0);
+        CloseHandle(detectCDThreadHandle);
+        detectCDThreadHandle = NULL;
+        initialDiscDetectionComplete = 0;
+        drivesWithMediaBitmap = 0;
+    } /* if */
+} /* deinitCDThread */
+#endif
+
+
+void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
+{
+    detectAvailableCDs(cb, data);
 } /* __PHYSFS_platformDetectAvailableCDs */
 
+#ifdef PHYSFS_PLATFORM_WINRT
+static char *calcDirAppendSep(const WCHAR *wdir)
+{
+    size_t len;
+    void *ptr;
+    char *retval;
+    BAIL_IF(!wdir, errcodeFromWinApi(), NULL);
+    retval = unicodeToUtf8Heap(wdir);
+    BAIL_IF_ERRPASS(!retval, NULL);
+    len = strlen(retval);
+    ptr = allocator.Realloc(retval, len + 2);
+    if (!ptr)
+    {
+        allocator.Free(retval);
+        BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
+    } /* if */
+    retval = (char *) ptr;
+    retval[len] = '\\';
+    retval[len+1] = '\0';
+    return retval;
+} /* calcDirAppendSep */
+#endif
 
 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
 {
+#ifdef PHYSFS_PLATFORM_WINRT
+    return calcDirAppendSep((const WCHAR *) __PHYSFS_winrtCalcBaseDir());
+#else
+    char *retval = NULL;
     DWORD buflen = 64;
     LPWSTR modpath = NULL;
-    char *retval = NULL;
 
     while (1)
     {
@@ -387,11 +518,15 @@
     allocator.Free(modpath);
 
     return retval;   /* w00t. */
+#endif
 } /* __PHYSFS_platformCalcBaseDir */
 
 
 char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
 {
+#ifdef PHYSFS_PLATFORM_WINRT
+    return calcDirAppendSep((const WCHAR *) __PHYSFS_winrtCalcPrefDir());
+#else
     /*
      * Vista and later has a new API for this, but SHGetFolderPath works there,
      *  and apparently just wraps the new API. This is the new way to do it:
@@ -422,11 +557,15 @@
     snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
     allocator.Free(utf8);
     return retval;
+#endif
 } /* __PHYSFS_platformCalcPrefDir */
 
 
 char *__PHYSFS_platformCalcUserDir(void)
 {
+#ifdef PHYSFS_PLATFORM_WINRT
+    return calcDirAppendSep((const WCHAR *) __PHYSFS_winrtCalcPrefDir());
+#else
     typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);
     fnGetUserProfDirW pGetDir = NULL;
     HANDLE lib = NULL;
@@ -452,7 +591,7 @@
          *  psize. Also note that the second parameter can't be
          *  NULL or the function fails.
          */
-    	rc = pGetDir(accessToken, &dummy, &psize);
+        rc = pGetDir(accessToken, &dummy, &psize);
         assert(!rc);  /* !!! FIXME: handle this gracefully. */
         (void) rc;
 
@@ -479,14 +618,29 @@
 done:
     FreeLibrary(lib);
     return retval;  /* We made it: hit the showers. */
+#endif
 } /* __PHYSFS_platformCalcUserDir */
 
 
+int __PHYSFS_platformInit(void)
+{
+    return 1;  /* It's all good */
+} /* __PHYSFS_platformInit */
+
+
+int __PHYSFS_platformDeinit(void)
+{
+    deinitCDThread();
+    return 1; /* It's all good */
+} /* __PHYSFS_platformDeinit */
+
+
 void *__PHYSFS_platformGetThreadID(void)
 {
     return ( (void *) ((size_t) GetCurrentThreadId()) );
 } /* __PHYSFS_platformGetThreadID */
 
+
 void __PHYSFS_platformEnumerateFiles(const char *dirname,
                                      PHYSFS_EnumFilesCallback callback,
                                      const char *origdir,
@@ -520,7 +674,7 @@
     if (!wSearchPath)
         return;  /* oh well. */
 
-    dir = FindFirstFileW(wSearchPath, &entw);
+    dir = winFindFirstFileW(wSearchPath, &entw);
 
     __PHYSFS_smallFree(wSearchPath);
     __PHYSFS_smallFree(searchPath);
@@ -561,28 +715,6 @@
 } /* __PHYSFS_platformMkDir */
 
 
-int __PHYSFS_platformInit(void)
-{
-    return 1;  /* It's all good */
-} /* __PHYSFS_platformInit */
-
-
-int __PHYSFS_platformDeinit(void)
-{
-    if (detectCDThreadHandle)
-    {
-        if (detectCDHwnd)
-            PostMessageW(detectCDHwnd, WM_QUIT, 0, 0);
-        CloseHandle(detectCDThreadHandle);
-        detectCDThreadHandle = NULL;
-        initialDiscDetectionComplete = 0;
-        drivesWithMediaBitmap = 0;
-    } /* if */
-
-    return 1; /* It's all good */
-} /* __PHYSFS_platformDeinit */
-
-
 static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
 {
     HANDLE fileh;
@@ -591,11 +723,11 @@
 
     UTF8_TO_UNICODE_STACK(wfname, fname);
     BAIL_IF(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-    fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE,
-                             NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
+
+    fileh = winCreateFileW(wfname, mode, creation);
     __PHYSFS_smallFree(wfname);
 
-    BAIL_IF(fileh == INVALID_HANDLE_VALUE,errcodeFromWinApi(), NULL);
+    BAIL_IF(fileh == INVALID_HANDLE_VALUE, errcodeFromWinApi(), NULL);
 
     retval = (WinApiFile *) allocator.Malloc(sizeof (WinApiFile));
     if (!retval)
@@ -628,8 +760,7 @@
     if (retval != NULL)
     {
         HANDLE h = ((WinApiFile *) retval)->handle;
-        DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
-        if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
+        if (!winSetFilePointer(h, 0, NULL, FILE_END))
         {
             const PHYSFS_ErrorCode err = errcodeFromWinApi();
             CloseHandle(h);
@@ -693,79 +824,27 @@
 
 int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
 {
-    HANDLE Handle = ((WinApiFile *) opaque)->handle;
-    LONG HighOrderPos;
-    PLONG pHighOrderPos;
-    DWORD rc;
-
-    /* Get the high order 32-bits of the position */
-    HighOrderPos = HIGHORDER_UINT64(pos);
-
-    /*
-     * MSDN: "If you do not need the high-order 32 bits, this
-     *         pointer must be set to NULL."
-     */
-    pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
-
-    /* Move pointer "pos" count from start of file */
-    rc = SetFilePointer(Handle, LOWORDER_UINT64(pos),
-                        pHighOrderPos, FILE_BEGIN);
-
-    if ( (rc == PHYSFS_INVALID_SET_FILE_POINTER) &&
-         (GetLastError() != NO_ERROR) )
-    {
-        BAIL(errcodeFromWinApi(), 0);
-    } /* if */
-    
+    HANDLE h = ((WinApiFile *) opaque)->handle;
+    const PHYSFS_sint64 spos = (PHYSFS_sint64) pos;
+    BAIL_IF(winSetFilePointer(h,spos,NULL,FILE_BEGIN), errcodeFromWinApi(), 0);
     return 1;  /* No error occured */
 } /* __PHYSFS_platformSeek */
 
 
 PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
 {
-    HANDLE Handle = ((WinApiFile *) opaque)->handle;
-    LONG HighPos = 0;
-    DWORD LowPos;
-    PHYSFS_sint64 retval;
-
-    /* Get current position */
-    LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
-    if ( (LowPos == PHYSFS_INVALID_SET_FILE_POINTER) &&
-         (GetLastError() != NO_ERROR) )
-    {
-        BAIL(errcodeFromWinApi(), -1);
-    } /* if */
-    else
-    {
-        /* Combine the high/low order to create the 64-bit position value */
-        retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
-        assert(retval >= 0);
-    } /* else */
-
-    return retval;
+    HANDLE h = ((WinApiFile *) opaque)->handle;
+    PHYSFS_sint64 pos = 0;
+    BAIL_IF(winSetFilePointer(h,0,&pos,FILE_CURRENT), errcodeFromWinApi(), -1);
+    return pos;
 } /* __PHYSFS_platformTell */
 
 
 PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
 {
-    HANDLE Handle = ((WinApiFile *) opaque)->handle;
-    DWORD SizeHigh;
-    DWORD SizeLow;
-    PHYSFS_sint64 retval;
-
-    SizeLow = GetFileSize(Handle, &SizeHigh);
-    if ( (SizeLow == PHYSFS_INVALID_SET_FILE_POINTER) &&
-         (GetLastError() != NO_ERROR) )
-    {
-        BAIL(errcodeFromWinApi(), -1);
-    } /* if */
-    else
-    {
-        /* Combine the high/low order to create the 64-bit position value */
-        retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
-        assert(retval >= 0);
-    } /* else */
-
+    HANDLE h = ((WinApiFile *) opaque)->handle;
+    const PHYSFS_sint64 retval = winGetFileSize(h);
+    BAIL_IF(retval < 0, errcodeFromWinApi(), -1);
     return retval;
 } /* __PHYSFS_platformFileLength */
 
@@ -790,9 +869,15 @@
 
 static int doPlatformDelete(LPWSTR wpath)
 {
-    const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY);
-    const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
-    BAIL_IF(!rc, errcodeFromWinApi(), 0);
+    WIN32_FILE_ATTRIBUTE_DATA info;
+    if (!GetFileAttributesExW(wpath, GetFileExInfoStandard, &info))
+        BAIL(errcodeFromWinApi(), 0);
+    else
+    {
+        const int isdir = (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+        const BOOL rc = isdir ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
+        BAIL_IF(!rc, errcodeFromWinApi(), 0);
+    } /* else */
     return 1;   /* if you made it here, it worked. */
 } /* doPlatformDelete */
 
@@ -814,7 +899,13 @@
     LPCRITICAL_SECTION lpcs;
     lpcs = (LPCRITICAL_SECTION) allocator.Malloc(sizeof (CRITICAL_SECTION));
     BAIL_IF(!lpcs, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-    InitializeCriticalSection(lpcs);
+
+    if (!winInitializeCriticalSection(lpcs))
+    {
+        allocator.Free(lpcs);
+        BAIL(errcodeFromWinApi(), NULL);
+    } /* if */
+
     return lpcs;
 } /* __PHYSFS_platformCreateMutex */
 
@@ -888,7 +979,7 @@
     if ((attr & PHYSFS_FILE_ATTRIBUTE_REPARSE_POINT) == 0)
         return 0;  /* not a reparse point? Definitely not a symlink. */
 
-    h = FindFirstFileW(wpath, &w32dw);
+    h = winFindFirstFileW(wpath, &w32dw);
     if (h == INVALID_HANDLE_VALUE)
         return 0;  /* ...maybe the file just vanished...? */
 
@@ -952,7 +1043,6 @@
 } /* __PHYSFS_platformStat */
 
 #endif  /* PHYSFS_PLATFORM_WINDOWS */
-#endif  /* PHYSFS_PLATFORM_WINRT */
 
 /* end of physfs_platform_windows.c ... */
 
--- a/src/physfs_platform_winrt.cpp	Mon Jul 24 02:37:22 2017 -0400
+++ b/src/physfs_platform_winrt.cpp	Mon Jul 24 03:29:33 2017 -0400
@@ -1,42 +1,16 @@
 /*
-* Windows Runtime support routines for PhysicsFS.
-*
-* Please see the file LICENSE.txt in the source's root directory.
-*
-*  This file is based on "physfs_platform_windows.c" by Ryan C. Gordon and Gregory S. Read.
-*  Windows Runtime-specific additions and changes are made by Martin "T-Bone" Ahrnbom. 
-*
-* Instructions for setting up PhysFS in a WinRT Universal 8.1 app in Visual Studio 2013:
-* (hopefully these instructions will be somewhat valid with Windows 10 Apps as well...)
-*
-*  1. In Visual Studio 2013 (or later?), hit File -> New -> Project...
-*  2. On the left, navigate to Templates -> Visual C++ -> Store Apps -> Universal Apps
-*  3. In the middle of the window, select "DLL (Universal Apps)"
-*  4. Near the bottom, give the project a name (like PhysFS-WinRT) and choose a location
-*  5. In the Solution Explorer (to the right typically), delete all .cpp and .h files in
-*     PhysFS-WinRT.Shared except targetver.h.
-*  6. In Windows Explorer, find the "src" folder of the PhysFS source code. Select all files
-* 	  in the folder.
-*	  Drag and drop all of the source files onto PhysFS-WinRT-Shared in Visual Studio.
-*  7. In Windows Explorer, find the file called "physfs.h". Copy this file into a folder of its own somewhere.
-*	  I suggest naming that folder "include". This will be your "include" folder for any projects using PhysFS.
-*  8. In the Solution Explorer, right click on PhysFS-WinRT.Windows and select Properties. Make sure that "Configuration" is set to 
-*     "All Configurations" and "Platform" is set to "All Platforms" near the top of the window.
-*  9. On the left, select "Precompiled Headers". Change "Precompiled Header" from "Use (/Yu)" to "Not Using Precompiled Headers".
-* 10. On the left, navigate to Configuration Properties -> C/C++ -> Preprocessor. In Preprocessor Definitions, add "_CRT_SECURE_NO_WARNINGS"
-* 11. Hit the OK button.
-* 12. Repeat steps 8-11 but for PhysFS-WinRT.WindowsPhone.
-* 13. In the Solution Explorer, find "physfs_platform_winrt.cpp" in PhysFS-WinRT.Shared. Right click on it and select "Properties".
-* 14. On the left, navigate to Configuration Properties -> C/C++ -> General. On the right, change "Consume Windows Runtime Extensions"
-*	  from "No" to "Yes (/ZW)". Hit "OK".
-* 15. Near the top of the Visual Studio window, select BUILD -> Batch Build... Hit "Select All", and then "Build".
-* 16. Now you have a bunch of .dll and .lib files, as well as an include folder that you can use in your projects!
-* 17. ???
-* 18. Profit!
-*/
+ * Windows Runtime (WinRT) support routines for PhysicsFS.
+ *
+ * Please see the file LICENSE.txt in the source's root directory.
+ *
+ *  This file originally written by Martin "T-Bone" Ahrnbom, but was mostly
+ *  merged into physfs_platform_windows.c by Ryan C. Gordon (so please harass
+ *  Ryan about bugs and not Martin).
+ */
 
-/* !!! FIXME: remove the tabstops from this file. */
-/* !!! FIXME: maybe just merge this back into platform_windows.c? */
+/* (There used to be instructions on how to make a WinRT project, but at
+   this point, either CMake will do it for you or you should just drop
+   PhysicsFS's sources into your existing project. --ryan.) */
 
 #define __PHYSICSFS_INTERNAL__
 #include "physfs_platforms.h"
@@ -45,625 +19,21 @@
 
 #include "physfs_internal.h"
 
-#include <windows.h>
-#include <errno.h>
-#include <ctype.h>
-#include <time.h>
-
-#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF))
-#define HIGHORDER_UINT64(pos) ((PHYSFS_uint32) ((pos >> 32) & 0xFFFFFFFF))
-
-
-/*
-* Users without the platform SDK don't have this defined.  The original docs
-*  for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
-*  work as desired.
-*/
-#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
-
-/* just in case... */
-#define PHYSFS_INVALID_FILE_ATTRIBUTES   0xFFFFFFFF
-
-/* Not defined before the Vista SDK. */
-#define PHYSFS_IO_REPARSE_TAG_SYMLINK    0xA000000C
-
-
-#define UTF8_TO_UNICODE_STACK(w_assignto, str) { \
-    if (str == NULL) \
-        w_assignto = NULL; \
-    else { \
-        const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) + 1) * 2); \
-        w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \
-        if (w_assignto != NULL) \
-            PHYSFS_utf8ToUtf16(str, (PHYSFS_uint16 *) w_assignto, len); \
-    } \
-} \
-
-/* Note this counts WCHARs, not codepoints! */
-static PHYSFS_uint64 wStrLen(const WCHAR *wstr)
-{
-	PHYSFS_uint64 len = 0;
-	while (*(wstr++))
-		len++;
-	return len;
-} /* wStrLen */
-
-/* !!! FIXME: do we really need readonly? If not, do we need this struct? */
-typedef struct
-{
-	HANDLE handle;
-	int readonly;
-} WinApiFile;
-
-static HANDLE detectCDThreadHandle = NULL;
-static HWND detectCDHwnd = 0;
-static volatile int initialDiscDetectionComplete = 0;
-static volatile DWORD drivesWithMediaBitmap = 0;
-
-
-static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err)
-{
-	/*
-	* win32 error codes are sort of a tricky thing; Microsoft intentionally
-	*  doesn't list which ones a given API might trigger, there are several
-	*  with overlapping and unclear meanings...and there's 16 thousand of
-	*  them in Windows 7. It looks like the ones we care about are in the
-	*  first 500, but I can't say this list is perfect; we might miss
-	*  important values or misinterpret others.
-	*
-	* Don't treat this list as anything other than a work in progress.
-	*/
-	switch (err)
-	{
-	case ERROR_SUCCESS: return PHYSFS_ERR_OK;
-	case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
-	case ERROR_NETWORK_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
-	case ERROR_NOT_READY: return PHYSFS_ERR_IO;
-	case ERROR_CRC: return PHYSFS_ERR_IO;
-	case ERROR_SEEK: return PHYSFS_ERR_IO;
-	case ERROR_SECTOR_NOT_FOUND: return PHYSFS_ERR_IO;
-	case ERROR_NOT_DOS_DISK: return PHYSFS_ERR_IO;
-	case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO;
-	case ERROR_READ_FAULT: return PHYSFS_ERR_IO;
-	case ERROR_DEV_NOT_EXIST: return PHYSFS_ERR_IO;
-		/* !!! FIXME: ?? case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; */
-	case ERROR_BUFFER_OVERFLOW: return PHYSFS_ERR_BAD_FILENAME;
-	case ERROR_INVALID_NAME: return PHYSFS_ERR_BAD_FILENAME;
-	case ERROR_BAD_PATHNAME: return PHYSFS_ERR_BAD_FILENAME;
-	case ERROR_DIRECTORY: return PHYSFS_ERR_BAD_FILENAME;
-	case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NOT_FOUND;
-	case ERROR_PATH_NOT_FOUND: return PHYSFS_ERR_NOT_FOUND;
-	case ERROR_DELETE_PENDING: return PHYSFS_ERR_NOT_FOUND;
-	case ERROR_INVALID_DRIVE: return PHYSFS_ERR_NOT_FOUND;
-	case ERROR_HANDLE_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
-	case ERROR_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
-		/* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NOT_FOUND; */
-		/* !!! FIXME: ?? case EISDIR: return PHYSFS_ERR_NOT_A_FILE; */
-	case ERROR_WRITE_PROTECT: return PHYSFS_ERR_READ_ONLY;
-	case ERROR_LOCK_VIOLATION: return PHYSFS_ERR_BUSY;
-	case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_BUSY;
-	case ERROR_CURRENT_DIRECTORY: return PHYSFS_ERR_BUSY;
-	case ERROR_DRIVE_LOCKED: return PHYSFS_ERR_BUSY;
-	case ERROR_PATH_BUSY: return PHYSFS_ERR_BUSY;
-	case ERROR_BUSY: return PHYSFS_ERR_BUSY;
-	case ERROR_NOT_ENOUGH_MEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
-	case ERROR_OUTOFMEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
-	case ERROR_DIR_NOT_EMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY;
-	default: return PHYSFS_ERR_OS_ERROR;
-	} /* switch */
-} /* errcodeFromWinApiError */
-
-static inline PHYSFS_ErrorCode errcodeFromWinApi(void)
-{
-	return errcodeFromWinApiError(GetLastError());
-} /* errcodeFromWinApi */
-
-
-typedef BOOL(WINAPI *fnSTEM)(DWORD, LPDWORD b);
-
-static DWORD pollDiscDrives(void)
-{
-	// We don't do discs
-	return 0;
-} /* pollDiscDrives */
-
-
-static LRESULT CALLBACK detectCDWndProc(HWND hwnd, UINT msg,
-	WPARAM wp, LPARAM lparam)
-{
-	return FALSE;
-} /* detectCDWndProc */
-
-
-static DWORD WINAPI detectCDThread(LPVOID lpParameter)
-{
-	return 0;
-} /* detectCDThread */
-
-
-void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
-{
-	return;
-} /* __PHYSFS_platformDetectAvailableCDs */
-
+/* !!! FIXME: maybe clean out the "allocator" macro, eventually. */
+#undef allocator  /* apparently Windows 10 SDK conflicts here. */
 
-static char *unicodeToUtf8Heap(const WCHAR *w_str)
-{
-	char *retval = NULL;
-	if (w_str != NULL)
-	{
-		void *ptr = NULL;
-		const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1;
-		retval = (char*)allocator.Malloc(len);
-		BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-		PHYSFS_utf8FromUtf16((const PHYSFS_uint16 *)w_str, retval, len);
-		ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */
-		if (ptr != NULL)
-			retval = (char *)ptr;
-	} /* if */
-	return retval;
-} /* unicodeToUtf8Heap */
-
-char *__PHYSFS_platformCalcBaseDir(const char *argv0)
-{
-	const wchar_t* path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
-	wchar_t path2[1024];
-	wcscpy_s(path2, path);
-	wcscat_s(path2, L"\\");
-	return unicodeToUtf8Heap(path2);
-
-} /* __PHYSFS_platformCalcBaseDir */
-
-
-char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
-{
-	const wchar_t* path = Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data();
-	wchar_t path2[1024];
-	wcscpy_s(path2, path);
-	wcscat_s(path2, L"\\");
-	return unicodeToUtf8Heap(path2);
-} /* __PHYSFS_platformCalcPrefDir */
-
-
-char *__PHYSFS_platformCalcUserDir(void)
-{
-	return __PHYSFS_platformCalcPrefDir(NULL, NULL);
-} /* __PHYSFS_platformCalcUserDir */
-
-
-void *__PHYSFS_platformGetThreadID(void)
-{
-	return ((void *)((size_t)GetCurrentThreadId()));
-} /* __PHYSFS_platformGetThreadID */
-
-
-static int isSymlinkAttrs(const DWORD attr, const DWORD tag)
-{
-	return ((attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
-		(tag == PHYSFS_IO_REPARSE_TAG_SYMLINK));
-} /* isSymlinkAttrs */
-
-
-void __PHYSFS_platformEnumerateFiles(const char *dirname,
-	PHYSFS_EnumFilesCallback callback,
-	const char *origdir,
-	void *callbackdata)
-{
-
-	HANDLE dir = INVALID_HANDLE_VALUE;
-	WIN32_FIND_DATAW entw;
-	size_t len = strlen(dirname);
-	char *searchPath = NULL;
-	WCHAR *wSearchPath = NULL;
-
-	/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
-	searchPath = (char *)__PHYSFS_smallAlloc(len + 3);
-	if (searchPath == NULL)
-		return;
-
-	/* Copy current dirname */
-	strcpy(searchPath, dirname);
-
-	/* if there's no '\\' at the end of the path, stick one in there. */
-	if (searchPath[len - 1] != '\\')
-	{
-		searchPath[len++] = '\\';
-		searchPath[len] = '\0';
-	} /* if */
-
-	/* Append the "*" to the end of the string */
-	strcat(searchPath, "*");
-
-	UTF8_TO_UNICODE_STACK(wSearchPath, searchPath);
-	if (!wSearchPath)
-		return;  /* oh well. */
-
-	//dir = FindFirstFileW(wSearchPath, &entw);
-	dir = FindFirstFileExW(wSearchPath, FindExInfoStandard, &entw, FindExSearchNameMatch, NULL, 0);
-
-	__PHYSFS_smallFree(wSearchPath);
-	__PHYSFS_smallFree(searchPath);
-	if (dir == INVALID_HANDLE_VALUE)
-		return;
-
-	do
-	{
-		const DWORD attr = entw.dwFileAttributes;
-		const DWORD tag = entw.dwReserved0;
-		const WCHAR *fn = entw.cFileName;
-		char *utf8;
-
-		if ((fn[0] == '.') && (fn[1] == '\0'))
-			continue;
-		if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
-			continue;
-
-		utf8 = unicodeToUtf8Heap(fn);
-		if (utf8 != NULL)
-		{
-			callback(callbackdata, origdir, utf8);
-			allocator.Free(utf8);
-		} /* if */
-	} while (FindNextFileW(dir, &entw) != 0);
-
-	FindClose(dir);
-} /* __PHYSFS_platformEnumerateFiles */
-
-
-int __PHYSFS_platformMkDir(const char *path)
-{
-	WCHAR *wpath;
-	DWORD rc;
-	UTF8_TO_UNICODE_STACK(wpath, path);
-	rc = CreateDirectoryW(wpath, NULL);
-	__PHYSFS_smallFree(wpath);
-	BAIL_IF(rc == 0, errcodeFromWinApi(), 0);
-	return 1;
-} /* __PHYSFS_platformMkDir */
-
-
-int __PHYSFS_platformInit(void)
-{
-	return 1;  /* It's all good */
-} /* __PHYSFS_platformInit */
-
-
-int __PHYSFS_platformDeinit(void)
-{
-	return 1; /* It's all good */
-} /* __PHYSFS_platformDeinit */
-
-
-static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
-{
-	HANDLE fileh;
-	WinApiFile *retval;
-	WCHAR *wfname;
-
-	UTF8_TO_UNICODE_STACK(wfname, fname);
-	BAIL_IF(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-	//fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
-	fileh = CreateFile2(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, creation, NULL);
-	__PHYSFS_smallFree(wfname);
-
-	BAIL_IF(fileh == INVALID_HANDLE_VALUE, errcodeFromWinApi(), NULL);
-
-	retval = (WinApiFile *)allocator.Malloc(sizeof(WinApiFile));
-	if (!retval)
-	{
-		CloseHandle(fileh);
-		BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-	} /* if */
+#include <windows.h>
 
-	retval->readonly = rdonly;
-	retval->handle = fileh;
-	return retval;
-} /* doOpen */
-
-
-void *__PHYSFS_platformOpenRead(const char *filename)
-{
-	return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
-} /* __PHYSFS_platformOpenRead */
-
-
-void *__PHYSFS_platformOpenWrite(const char *filename)
-{
-	return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
-} /* __PHYSFS_platformOpenWrite */
-
-
-void *__PHYSFS_platformOpenAppend(const char *filename)
-{
-	void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
-	if (retval != NULL)
-	{
-		HANDLE h = ((WinApiFile *)retval)->handle;
-		//DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
-		const LARGE_INTEGER zero = { 0 };
-		DWORD rc = SetFilePointerEx(h, zero, NULL, FILE_END);
-		if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
-		{
-			const PHYSFS_ErrorCode err = errcodeFromWinApi();
-			CloseHandle(h);
-			allocator.Free(retval);
-			BAIL(err, NULL);
-		} /* if */
-	} /* if */
-
-	return retval;
-} /* __PHYSFS_platformOpenAppend */
-
-
-PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
-{
-	HANDLE Handle = ((WinApiFile *)opaque)->handle;
-	PHYSFS_sint64 totalRead = 0;
-
-	if (!__PHYSFS_ui64FitsAddressSpace(len))
-		BAIL(PHYSFS_ERR_INVALID_ARGUMENT, -1);
-
-	while (len > 0)
-	{
-		const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len;
-		DWORD numRead = 0;
-		if (!ReadFile(Handle, buf, thislen, &numRead, NULL))
-			BAIL(errcodeFromWinApi(), -1);
-		len -= (PHYSFS_uint64)numRead;
-		totalRead += (PHYSFS_sint64)numRead;
-		if (numRead != thislen)
-			break;
-	} /* while */
-	
-	return totalRead;
-} /* __PHYSFS_platformRead */
-
-
-PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
-	PHYSFS_uint64 len)
+const void *__PHYSFS_winrtCalcBaseDir(void)
 {
-	HANDLE Handle = ((WinApiFile *)opaque)->handle;
-	PHYSFS_sint64 totalWritten = 0;
-
-	if (!__PHYSFS_ui64FitsAddressSpace(len))
-		BAIL(PHYSFS_ERR_INVALID_ARGUMENT, -1);
-
-	while (len > 0)
-	{
-		const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len;
-		DWORD numWritten = 0;
-		if (!WriteFile(Handle, buffer, thislen, &numWritten, NULL))
-			BAIL(errcodeFromWinApi(), -1);
-		len -= (PHYSFS_uint64)numWritten;
-		totalWritten += (PHYSFS_sint64)numWritten;
-		if (numWritten != thislen)
-			break;
-	} /* while */
-
-	return totalWritten;
-} /* __PHYSFS_platformWrite */
-
-
-int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
-{
-	HANDLE Handle = ((WinApiFile *)opaque)->handle;
-	BOOL rc;
-
-	LARGE_INTEGER li;
-	li.LowPart = LOWORDER_UINT64(pos);
-	li.HighPart = HIGHORDER_UINT64(pos);
-
-	rc = SetFilePointerEx(Handle, li, NULL, FILE_BEGIN);
-
-	if (!rc && (GetLastError() != NO_ERROR))
-	{
-		BAIL(errcodeFromWinApi(), 0);
-	} /* if */
-
-	return 1;  /* No error occured */
-} /* __PHYSFS_platformSeek */
-
-
-PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
-{
-	HANDLE Handle = ((WinApiFile *)opaque)->handle;
-	PHYSFS_sint64 retval;
-	BOOL rc;
-
-	LARGE_INTEGER zero;
-	zero.QuadPart = 0;
-	LARGE_INTEGER out;
-
-	rc = SetFilePointerEx(Handle, zero, &out, FILE_CURRENT);
-	if (!rc)
-	{
-		BAIL(errcodeFromWinApi(), -1);
-	} /* if */
-	else
-	{
-		retval = out.QuadPart;
-		assert(retval >= 0);
-	} /* else */
-
-	return retval;
-} /* __PHYSFS_platformTell */
-
-
-PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
-{
-	HANDLE Handle = ((WinApiFile *)opaque)->handle;
-	PHYSFS_sint64 retval;
-
-	FILE_STANDARD_INFO file_info = { 0 };
-	const BOOL res = GetFileInformationByHandleEx(Handle, FileStandardInfo, &file_info, sizeof(file_info));
-	if (res) {
-		retval = file_info.EndOfFile.QuadPart;
-		assert(retval >= 0);
-	}
-	else {
-		PHYSFS_setErrorCode(PHYSFS_ERR_NOT_FOUND);
-	}
-
-	
-	return retval;
-} /* __PHYSFS_platformFileLength */
-
+    return Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
+} /* __PHYSFS_winrtCalcBaseDir */
 
-int __PHYSFS_platformFlush(void *opaque)
-{
-	WinApiFile *fh = ((WinApiFile *)opaque);
-	if (!fh->readonly)
-		BAIL_IF(!FlushFileBuffers(fh->handle), errcodeFromWinApi(), 0);
-
-	return 1;
-} /* __PHYSFS_platformFlush */
-
-
-void __PHYSFS_platformClose(void *opaque)
-{
-	HANDLE Handle = ((WinApiFile *)opaque)->handle;
-	(void)CloseHandle(Handle); /* ignore errors. You should have flushed! */
-	allocator.Free(opaque);
-} /* __PHYSFS_platformClose */
-
-
-static int doPlatformDelete(LPWSTR wpath)
-{
-	//const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY);
-	int isdir = 0;
-	WIN32_FILE_ATTRIBUTE_DATA file_info;
-	const BOOL res = GetFileAttributesEx(wpath, GetFileExInfoStandard, &file_info);
-	if (res) {
-		isdir = (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
-	}
-
-	const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
-	BAIL_IF(!rc, errcodeFromWinApi(), 0);
-	return 1;   /* if you made it here, it worked. */
-} /* doPlatformDelete */
-
-
-int __PHYSFS_platformDelete(const char *path)
+const void *__PHYSFS_winrtCalcPrefDir(void)
 {
-	int retval = 0;
-	LPWSTR wpath = NULL;
-	UTF8_TO_UNICODE_STACK(wpath, path);
-	BAIL_IF(!wpath, PHYSFS_ERR_OUT_OF_MEMORY, 0);
-	retval = doPlatformDelete(wpath);
-	__PHYSFS_smallFree(wpath);
-	return retval;
-} /* __PHYSFS_platformDelete */
-
-
-void *__PHYSFS_platformCreateMutex(void)
-{
-	LPCRITICAL_SECTION lpcs;
-	lpcs = (LPCRITICAL_SECTION)allocator.Malloc(sizeof(CRITICAL_SECTION));
-	BAIL_IF(!lpcs, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-	//InitializeCriticalSection(lpcs);
-	InitializeCriticalSectionEx(lpcs, 2000, 0);
-	return lpcs;
-} /* __PHYSFS_platformCreateMutex */
-
-
-void __PHYSFS_platformDestroyMutex(void *mutex)
-{
-	DeleteCriticalSection((LPCRITICAL_SECTION)mutex);
-	allocator.Free(mutex);
-} /* __PHYSFS_platformDestroyMutex */
-
-
-int __PHYSFS_platformGrabMutex(void *mutex)
-{
-	EnterCriticalSection((LPCRITICAL_SECTION)mutex);
-	return 1;
-} /* __PHYSFS_platformGrabMutex */
-
-
-void __PHYSFS_platformReleaseMutex(void *mutex)
-{
-	LeaveCriticalSection((LPCRITICAL_SECTION)mutex);
-} /* __PHYSFS_platformReleaseMutex */
-
+    return Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data();
+} /* __PHYSFS_winrtCalcBaseDir */
 
-static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
-{
-	SYSTEMTIME st_utc;
-	SYSTEMTIME st_localtz;
-	TIME_ZONE_INFORMATION tzi;
-	DWORD tzid;
-	PHYSFS_sint64 retval;
-	struct tm tm;
-	BOOL rc;
-
-	BAIL_IF(!FileTimeToSystemTime(ft, &st_utc), errcodeFromWinApi(), -1);
-	tzid = GetTimeZoneInformation(&tzi);
-	BAIL_IF(tzid == TIME_ZONE_ID_INVALID, errcodeFromWinApi(), -1);
-	rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
-	BAIL_IF(!rc, errcodeFromWinApi(), -1);
-
-	/* Convert to a format that mktime() can grok... */
-	tm.tm_sec = st_localtz.wSecond;
-	tm.tm_min = st_localtz.wMinute;
-	tm.tm_hour = st_localtz.wHour;
-	tm.tm_mday = st_localtz.wDay;
-	tm.tm_mon = st_localtz.wMonth - 1;
-	tm.tm_year = st_localtz.wYear - 1900;
-	tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
-	tm.tm_yday = -1;
-	tm.tm_isdst = -1;
-
-	/* Convert to a format PhysicsFS can grok... */
-	retval = (PHYSFS_sint64)mktime(&tm);
-	BAIL_IF(retval == -1, PHYSFS_ERR_OS_ERROR, -1);
-	return retval;
-} /* FileTimeToPhysfsTime */
-
-
-int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st)
-{
-	WIN32_FILE_ATTRIBUTE_DATA winstat;
-	WCHAR *wstr = NULL;
-	DWORD err = 0;
-	BOOL rc = 0;
-
-	UTF8_TO_UNICODE_STACK(wstr, filename);
-	BAIL_IF(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0);
-	rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
-	err = (!rc) ? GetLastError() : 0;
-	__PHYSFS_smallFree(wstr);
-	BAIL_IF(!rc, errcodeFromWinApiError(err), 0);
-
-	st->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
-	st->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
-	st->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
-
-	if (winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-	{
-		st->filetype = PHYSFS_FILETYPE_DIRECTORY;
-		st->filesize = 0;
-	} /* if */
-
-	else if (winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE))
-	{
-		/* !!! FIXME: what are reparse points? */
-		st->filetype = PHYSFS_FILETYPE_OTHER;
-		/* !!! FIXME: don't rely on this */
-		st->filesize = 0;
-	} /* else if */
-
-	/* !!! FIXME: check for symlinks on Vista. */
-
-	else
-	{
-		st->filetype = PHYSFS_FILETYPE_REGULAR;
-		st->filesize = (((PHYSFS_uint64)winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
-	} /* else */
-
-	st->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
-
-	return 1;
-} /* __PHYSFS_platformStat */
 
 #endif /* PHYSFS_PLATFORM_WINRT */
 
--- a/src/physfs_platforms.h	Mon Jul 24 02:37:22 2017 -0400
+++ b/src/physfs_platforms.h	Mon Jul 24 03:29:33 2017 -0400
@@ -19,10 +19,15 @@
 #  error BeOS support was dropped since PhysicsFS 2.1. Sorry. Try Haiku!
 #elif (defined _WIN32_WCE) || (defined _WIN64_WCE)
 #  error PocketPC support was dropped since PhysicsFS 2.1. Sorry. Try WinRT!
-#elif ((defined WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
-#   define PHYSFS_NO_CDROM_SUPPORT 1
-#   define PHYSFS_PLATFORM_WINRT 1
-#   define PHYSFS_PLATFORM_WINDOWS 1
+#elif (defined(_MSC_VER) && (_MSC_VER >= 1700) && !_USING_V110_SDK71_)	/* _MSC_VER==1700 for MSVC 2012 */
+#  include <winapifamily.h>
+#  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+#    define PHYSFS_NO_CDROM_SUPPORT 1
+#    define PHYSFS_PLATFORM_WINRT 1
+#    define PHYSFS_PLATFORM_WINDOWS 1
+#  else
+#    define PHYSFS_PLATFORM_WINDOWS 1
+#  endif
 #elif (((defined _WIN32) || (defined _WIN64)) && (!defined __CYGWIN__))
 #  define PHYSFS_PLATFORM_WINDOWS 1
 #elif defined(__OS2__) || defined(OS2)