src/platform_winrt.cpp
author Martin Ahrnbom <m.ahrnbom@outlook.com>
Sun, 29 Mar 2015 07:03:30 +0200
changeset 1356 8de68968fcd0
child 1359 e06676e2c6b4
permissions -rw-r--r--
Added support for WinRT 8.1 Universal Apps. Hopefully this will work on Win10 as well... Only time will tell! Here's what's changed: 1. Added a platform_winrt.cpp file. It's based on platform_windows.c but has some WinRT-specific changes. 2. Changed physfs_platforms.h to define PHYSFS_PLATFORM_WINRT when running on WinRT. PHYSFS_PLATFORM_WINDOWS should also be defined, as WinRT behaves a lot like "normal" Windows and this flag is tested against in multiple parts of the PhysFS source code. 3. Changed platform_windows.c to not be used when PHYSFS_PLATFORM_WINRT is defined. 4. In order to work on Windows ARM devices, I had to change in physfs_internal.h, to include _M_ARM as a flag for running on ARM as "ARM" and "__arm__" aren't defined when running on a Windows ARM device. What I've tested: * Setting up a "sane folder configuration" * Reading and writing files * Mounting zip files * Using seek & tell * Checking file length All of these work fine. I couldn't get the actual test software to run on WinRT, but it seems like eveyrthing's working. I've tested these things on my Windows 8.1 computer, as well as my Lumia 920 which is currently running Windows 8.1.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1356
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     1
/*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     2
* Windows Runtime support routines for PhysicsFS.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     3
*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     4
* Please see the file LICENSE.txt in the source's root directory.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     5
*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     6
*  This file is based on "platform_windows.c" by Ryan C. Gordon and Gregory S. Read.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     7
*  Windows Runtime-specific additions and changes are made by Martin "T-Bone" Ahrnbom. 
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     8
*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
     9
* Instructions for setting up PhysFS in a WinRT Universal 8.1 app in Visual Studio 2013:
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    10
* (hopefully these instructions will be somewhat valid with Windows 10 Apps as well...)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    11
*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    12
*  1. In Visual Studio 2013 (or later?), hit File -> New -> Project...
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    13
*  2. On the left, navigate to Templates -> Visual C++ -> Store Apps -> Universal Apps
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    14
*  3. In the middle of the window, select "DLL (Universal Apps)"
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    15
*  4. Near the bottom, give the project a name (like PhysFS-WinRT) and choose a location
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    16
*  5. In the Solution Explorer (to the right typically), delete all .cpp and .h files in
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    17
*     PhysFS-WinRT.Shared except targetver.h.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    18
*  6. In Windows Explorer, find the "src" folder of the PhysFS source code. Select all files
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    19
* 	  in the folder (ignore the "lzma" folder, we're not including 7Zip support because it's messy to compile).
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    20
*	  Drag and drop all of the source files onto PhysFS-WinRT-Shared in Visual Studio.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    21
*  7. In Windows Explorer, find the file called "physfs.h". Copy this file into a folder of its own somewhere.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    22
*	  I suggest naming that folder "include". This will be your "include" folder for any projects using PhysFS.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    23
*  8. In the Solution Explorer, right click on PhysFS-WinRT.Windows and select Properties. Make sure that "Configuration" is set to 
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    24
*     "All Configurations" and "Platform" is set to "All Platforms" near the top of the window.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    25
*  9. On the left, select "Precompiled Headers". Change "Precompiled Header" from "Use (/Yu)" to "Not Using Precompiled Headers".
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    26
* 10. On the left, navigate to Configuration Properties -> C/C++ -> Preprocessor. In Preprocessor Definitions, add "_CRT_SECURE_NO_WARNINGS"
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    27
* 11. Hit the OK button.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    28
* 12. Repeat steps 8-11 but for PhysFS-WinRT.WindowsPhone.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    29
* 13. In the Solution Explorer, find "platform_winrt.cpp" in PhysFS-WinRT.Shared. Right click on it and select "Properties". 
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    30
* 14. On the left, navigate to Configuration Properties -> C/C++ -> General. On the right, change "Consume Windows Runtime Extensions"
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    31
*	  from "No" to "Yes (/ZW)". Hit "OK".
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    32
* 15. Near the top of the Visual Studio window, select BUILD -> Batch Build... Hit "Select All", and then "Build".
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    33
* 16. Now you have a bunch of .dll and .lib files, as well as an include folder that you can use in your projects!
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    34
* 17. ???
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    35
* 18. Profit!
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    36
*/
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    37
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    38
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    39
#define __PHYSICSFS_INTERNAL__
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    40
#include "physfs_platforms.h"
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    41
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    42
#ifdef PHYSFS_PLATFORM_WINRT
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    43
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    44
#include "physfs_internal.h"
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    45
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    46
#include <windows.h>
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    47
#include <errno.h>
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    48
#include <ctype.h>
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    49
#include <time.h>
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    50
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    51
#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    52
#define HIGHORDER_UINT64(pos) ((PHYSFS_uint32) ((pos >> 32) & 0xFFFFFFFF))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    53
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    54
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    55
/*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    56
* Users without the platform SDK don't have this defined.  The original docs
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    57
*  for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    58
*  work as desired.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    59
*/
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    60
#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    61
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    62
/* just in case... */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    63
#define PHYSFS_INVALID_FILE_ATTRIBUTES   0xFFFFFFFF
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    64
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    65
/* Not defined before the Vista SDK. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    66
#define PHYSFS_IO_REPARSE_TAG_SYMLINK    0xA000000C
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    67
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    68
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    69
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    70
    if (str == NULL) \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    71
        w_assignto = NULL; \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    72
			    else { \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    73
        const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) + 1) * 2); \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    74
        w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    75
        if (w_assignto != NULL) \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    76
            PHYSFS_utf8ToUtf16(str, (PHYSFS_uint16 *) w_assignto, len); \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    77
			    } \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    78
} \
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    79
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    80
/* Note this counts WCHARs, not codepoints! */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    81
static PHYSFS_uint64 wStrLen(const WCHAR *wstr)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    82
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    83
	PHYSFS_uint64 len = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    84
	while (*(wstr++))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    85
		len++;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    86
	return len;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    87
} /* wStrLen */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    88
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    89
/* !!! FIXME: do we really need readonly? If not, do we need this struct? */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    90
typedef struct
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    91
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    92
	HANDLE handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    93
	int readonly;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    94
} WinApiFile;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    95
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    96
static HANDLE detectCDThreadHandle = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    97
static HWND detectCDHwnd = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    98
static volatile int initialDiscDetectionComplete = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
    99
static volatile DWORD drivesWithMediaBitmap = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   100
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   101
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   102
static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   103
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   104
	/*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   105
	* win32 error codes are sort of a tricky thing; Microsoft intentionally
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   106
	*  doesn't list which ones a given API might trigger, there are several
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   107
	*  with overlapping and unclear meanings...and there's 16 thousand of
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   108
	*  them in Windows 7. It looks like the ones we care about are in the
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   109
	*  first 500, but I can't say this list is perfect; we might miss
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   110
	*  important values or misinterpret others.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   111
	*
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   112
	* Don't treat this list as anything other than a work in progress.
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   113
	*/
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   114
	switch (err)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   115
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   116
	case ERROR_SUCCESS: return PHYSFS_ERR_OK;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   117
	case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   118
	case ERROR_NETWORK_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   119
	case ERROR_NOT_READY: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   120
	case ERROR_CRC: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   121
	case ERROR_SEEK: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   122
	case ERROR_SECTOR_NOT_FOUND: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   123
	case ERROR_NOT_DOS_DISK: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   124
	case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   125
	case ERROR_READ_FAULT: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   126
	case ERROR_DEV_NOT_EXIST: return PHYSFS_ERR_IO;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   127
		/* !!! FIXME: ?? case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   128
	case ERROR_BUFFER_OVERFLOW: return PHYSFS_ERR_BAD_FILENAME;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   129
	case ERROR_INVALID_NAME: return PHYSFS_ERR_BAD_FILENAME;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   130
	case ERROR_BAD_PATHNAME: return PHYSFS_ERR_BAD_FILENAME;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   131
	case ERROR_DIRECTORY: return PHYSFS_ERR_BAD_FILENAME;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   132
	case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NOT_FOUND;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   133
	case ERROR_PATH_NOT_FOUND: return PHYSFS_ERR_NOT_FOUND;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   134
	case ERROR_DELETE_PENDING: return PHYSFS_ERR_NOT_FOUND;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   135
	case ERROR_INVALID_DRIVE: return PHYSFS_ERR_NOT_FOUND;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   136
	case ERROR_HANDLE_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   137
	case ERROR_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   138
		/* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NOT_FOUND; */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   139
		/* !!! FIXME: ?? case EISDIR: return PHYSFS_ERR_NOT_A_FILE; */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   140
	case ERROR_WRITE_PROTECT: return PHYSFS_ERR_READ_ONLY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   141
	case ERROR_LOCK_VIOLATION: return PHYSFS_ERR_BUSY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   142
	case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_BUSY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   143
	case ERROR_CURRENT_DIRECTORY: return PHYSFS_ERR_BUSY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   144
	case ERROR_DRIVE_LOCKED: return PHYSFS_ERR_BUSY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   145
	case ERROR_PATH_BUSY: return PHYSFS_ERR_BUSY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   146
	case ERROR_BUSY: return PHYSFS_ERR_BUSY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   147
	case ERROR_NOT_ENOUGH_MEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   148
	case ERROR_OUTOFMEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   149
	case ERROR_DIR_NOT_EMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   150
	default: return PHYSFS_ERR_OS_ERROR;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   151
	} /* switch */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   152
} /* errcodeFromWinApiError */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   153
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   154
static inline PHYSFS_ErrorCode errcodeFromWinApi(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   155
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   156
	return errcodeFromWinApiError(GetLastError());
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   157
} /* errcodeFromWinApi */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   158
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   159
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   160
typedef BOOL(WINAPI *fnSTEM)(DWORD, LPDWORD b);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   161
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   162
static DWORD pollDiscDrives(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   163
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   164
	// We don't do discs
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   165
	return 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   166
} /* pollDiscDrives */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   167
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   168
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   169
static LRESULT CALLBACK detectCDWndProc(HWND hwnd, UINT msg,
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   170
	WPARAM wp, LPARAM lparam)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   171
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   172
	return FALSE;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   173
} /* detectCDWndProc */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   174
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   175
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   176
static DWORD WINAPI detectCDThread(LPVOID lpParameter)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   177
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   178
	return 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   179
} /* detectCDThread */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   180
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   181
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   182
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   183
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   184
	return;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   185
} /* __PHYSFS_platformDetectAvailableCDs */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   186
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   187
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   188
static char *unicodeToUtf8Heap(const WCHAR *w_str)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   189
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   190
	char *retval = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   191
	if (w_str != NULL)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   192
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   193
		void *ptr = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   194
		const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   195
		retval = (char*)allocator.Malloc(len);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   196
		BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   197
		PHYSFS_utf8FromUtf16((const PHYSFS_uint16 *)w_str, retval, len);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   198
		ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   199
		if (ptr != NULL)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   200
			retval = (char *)ptr;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   201
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   202
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   203
} /* unicodeToUtf8Heap */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   204
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   205
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   206
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   207
	const wchar_t* path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   208
	wchar_t path2[1024];
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   209
	wcscpy_s(path2, path);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   210
	wcscat_s(path2, L"\\");
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   211
	return unicodeToUtf8Heap(path2);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   212
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   213
} /* __PHYSFS_platformCalcBaseDir */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   214
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   215
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   216
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   217
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   218
	const wchar_t* path = Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data();
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   219
	wchar_t path2[1024];
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   220
	wcscpy_s(path2, path);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   221
	wcscat_s(path2, L"\\");
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   222
	return unicodeToUtf8Heap(path2);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   223
} /* __PHYSFS_platformCalcPrefDir */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   224
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   225
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   226
char *__PHYSFS_platformCalcUserDir(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   227
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   228
	return __PHYSFS_platformCalcPrefDir(NULL, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   229
} /* __PHYSFS_platformCalcUserDir */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   230
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   231
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   232
void *__PHYSFS_platformGetThreadID(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   233
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   234
	return ((void *)((size_t)GetCurrentThreadId()));
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   235
} /* __PHYSFS_platformGetThreadID */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   236
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   237
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   238
static int isSymlinkAttrs(const DWORD attr, const DWORD tag)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   239
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   240
	return ((attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   241
		(tag == PHYSFS_IO_REPARSE_TAG_SYMLINK));
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   242
} /* isSymlinkAttrs */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   243
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   244
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   245
void __PHYSFS_platformEnumerateFiles(const char *dirname,
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   246
	PHYSFS_EnumFilesCallback callback,
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   247
	const char *origdir,
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   248
	void *callbackdata)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   249
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   250
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   251
	HANDLE dir = INVALID_HANDLE_VALUE;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   252
	WIN32_FIND_DATAW entw;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   253
	size_t len = strlen(dirname);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   254
	char *searchPath = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   255
	WCHAR *wSearchPath = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   256
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   257
	/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   258
	searchPath = (char *)__PHYSFS_smallAlloc(len + 3);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   259
	if (searchPath == NULL)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   260
		return;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   261
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   262
	/* Copy current dirname */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   263
	strcpy(searchPath, dirname);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   264
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   265
	/* if there's no '\\' at the end of the path, stick one in there. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   266
	if (searchPath[len - 1] != '\\')
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   267
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   268
		searchPath[len++] = '\\';
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   269
		searchPath[len] = '\0';
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   270
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   271
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   272
	/* Append the "*" to the end of the string */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   273
	strcat(searchPath, "*");
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   274
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   275
	UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   276
	if (!wSearchPath)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   277
		return;  /* oh well. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   278
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   279
	//dir = FindFirstFileW(wSearchPath, &entw);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   280
	dir = FindFirstFileExW(wSearchPath, FindExInfoStandard, &entw, FindExSearchNameMatch, NULL, 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   281
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   282
	__PHYSFS_smallFree(wSearchPath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   283
	__PHYSFS_smallFree(searchPath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   284
	if (dir == INVALID_HANDLE_VALUE)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   285
		return;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   286
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   287
	do
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   288
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   289
		const DWORD attr = entw.dwFileAttributes;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   290
		const DWORD tag = entw.dwReserved0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   291
		const WCHAR *fn = entw.cFileName;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   292
		char *utf8;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   293
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   294
		if ((fn[0] == '.') && (fn[1] == '\0'))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   295
			continue;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   296
		if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   297
			continue;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   298
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   299
		utf8 = unicodeToUtf8Heap(fn);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   300
		if (utf8 != NULL)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   301
		{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   302
			callback(callbackdata, origdir, utf8);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   303
			allocator.Free(utf8);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   304
		} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   305
	} while (FindNextFileW(dir, &entw) != 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   306
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   307
	FindClose(dir);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   308
} /* __PHYSFS_platformEnumerateFiles */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   309
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   310
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   311
int __PHYSFS_platformMkDir(const char *path)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   312
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   313
	WCHAR *wpath;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   314
	DWORD rc;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   315
	UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   316
	rc = CreateDirectoryW(wpath, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   317
	__PHYSFS_smallFree(wpath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   318
	BAIL_IF_MACRO(rc == 0, errcodeFromWinApi(), 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   319
	return 1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   320
} /* __PHYSFS_platformMkDir */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   321
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   322
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   323
int __PHYSFS_platformInit(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   324
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   325
	return 1;  /* It's all good */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   326
} /* __PHYSFS_platformInit */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   327
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   328
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   329
int __PHYSFS_platformDeinit(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   330
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   331
	return 1; /* It's all good */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   332
} /* __PHYSFS_platformDeinit */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   333
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   334
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   335
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   336
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   337
	HANDLE fileh;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   338
	WinApiFile *retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   339
	WCHAR *wfname;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   340
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   341
	UTF8_TO_UNICODE_STACK_MACRO(wfname, fname);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   342
	BAIL_IF_MACRO(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   343
	//fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   344
	fileh = CreateFile2(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, creation, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   345
	__PHYSFS_smallFree(wfname);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   346
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   347
	BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE, errcodeFromWinApi(), NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   348
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   349
	retval = (WinApiFile *)allocator.Malloc(sizeof(WinApiFile));
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   350
	if (!retval)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   351
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   352
		CloseHandle(fileh);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   353
		BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   354
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   355
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   356
	retval->readonly = rdonly;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   357
	retval->handle = fileh;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   358
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   359
} /* doOpen */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   360
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   361
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   362
void *__PHYSFS_platformOpenRead(const char *filename)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   363
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   364
	return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   365
} /* __PHYSFS_platformOpenRead */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   366
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   367
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   368
void *__PHYSFS_platformOpenWrite(const char *filename)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   369
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   370
	return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   371
} /* __PHYSFS_platformOpenWrite */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   372
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   373
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   374
void *__PHYSFS_platformOpenAppend(const char *filename)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   375
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   376
	void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   377
	if (retval != NULL)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   378
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   379
		HANDLE h = ((WinApiFile *)retval)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   380
		//DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   381
		const LARGE_INTEGER zero = { 0 };
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   382
		DWORD rc = SetFilePointerEx(h, zero, NULL, FILE_END);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   383
		if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   384
		{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   385
			const PHYSFS_ErrorCode err = errcodeFromWinApi();
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   386
			CloseHandle(h);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   387
			allocator.Free(retval);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   388
			BAIL_MACRO(err, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   389
		} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   390
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   391
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   392
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   393
} /* __PHYSFS_platformOpenAppend */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   394
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   395
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   396
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   397
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   398
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   399
	PHYSFS_sint64 totalRead = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   400
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   401
	if (!__PHYSFS_ui64FitsAddressSpace(len))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   402
		BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   403
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   404
	while (len > 0)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   405
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   406
		const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   407
		DWORD numRead = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   408
		if (!ReadFile(Handle, buf, thislen, &numRead, NULL))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   409
			BAIL_MACRO(errcodeFromWinApi(), -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   410
		len -= (PHYSFS_uint64)numRead;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   411
		totalRead += (PHYSFS_sint64)numRead;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   412
		if (numRead != thislen)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   413
			break;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   414
	} /* while */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   415
	
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   416
	return totalRead;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   417
} /* __PHYSFS_platformRead */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   418
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   419
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   420
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   421
	PHYSFS_uint64 len)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   422
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   423
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   424
	PHYSFS_sint64 totalWritten = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   425
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   426
	if (!__PHYSFS_ui64FitsAddressSpace(len))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   427
		BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   428
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   429
	while (len > 0)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   430
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   431
		const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   432
		DWORD numWritten = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   433
		if (!WriteFile(Handle, buffer, thislen, &numWritten, NULL))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   434
			BAIL_MACRO(errcodeFromWinApi(), -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   435
		len -= (PHYSFS_uint64)numWritten;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   436
		totalWritten += (PHYSFS_sint64)numWritten;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   437
		if (numWritten != thislen)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   438
			break;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   439
	} /* while */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   440
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   441
	return totalWritten;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   442
} /* __PHYSFS_platformWrite */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   443
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   444
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   445
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   446
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   447
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   448
	BOOL rc;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   449
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   450
	LARGE_INTEGER li;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   451
	li.LowPart = LOWORDER_UINT64(pos);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   452
	li.HighPart = HIGHORDER_UINT64(pos);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   453
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   454
	rc = SetFilePointerEx(Handle, li, NULL, FILE_BEGIN);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   455
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   456
	if (!rc && (GetLastError() != NO_ERROR))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   457
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   458
		BAIL_MACRO(errcodeFromWinApi(), 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   459
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   460
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   461
	return 1;  /* No error occured */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   462
} /* __PHYSFS_platformSeek */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   463
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   464
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   465
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   466
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   467
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   468
	PHYSFS_sint64 retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   469
	BOOL rc;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   470
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   471
	LARGE_INTEGER zero;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   472
	zero.QuadPart = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   473
	LARGE_INTEGER out;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   474
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   475
	rc = SetFilePointerEx(Handle, zero, &out, FILE_CURRENT);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   476
	if (!rc)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   477
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   478
		BAIL_MACRO(errcodeFromWinApi(), -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   479
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   480
	else
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   481
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   482
		retval = out.QuadPart;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   483
		assert(retval >= 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   484
	} /* else */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   485
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   486
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   487
} /* __PHYSFS_platformTell */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   488
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   489
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   490
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   491
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   492
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   493
	PHYSFS_sint64 retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   494
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   495
	FILE_STANDARD_INFO file_info = { 0 };
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   496
	const BOOL res = GetFileInformationByHandleEx(Handle, FileStandardInfo, &file_info, sizeof(file_info));
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   497
	if (res) {
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   498
		retval = file_info.EndOfFile.QuadPart;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   499
		assert(retval >= 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   500
	}
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   501
	else {
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   502
		PHYSFS_setErrorCode(PHYSFS_ERR_NOT_FOUND);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   503
	}
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   504
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   505
	
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   506
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   507
} /* __PHYSFS_platformFileLength */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   508
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   509
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   510
int __PHYSFS_platformFlush(void *opaque)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   511
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   512
	WinApiFile *fh = ((WinApiFile *)opaque);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   513
	if (!fh->readonly)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   514
		BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), errcodeFromWinApi(), 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   515
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   516
	return 1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   517
} /* __PHYSFS_platformFlush */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   518
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   519
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   520
void __PHYSFS_platformClose(void *opaque)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   521
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   522
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   523
	(void)CloseHandle(Handle); /* ignore errors. You should have flushed! */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   524
	allocator.Free(opaque);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   525
} /* __PHYSFS_platformClose */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   526
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   527
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   528
static int doPlatformDelete(LPWSTR wpath)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   529
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   530
	//const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   531
	int isdir = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   532
	WIN32_FILE_ATTRIBUTE_DATA file_info;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   533
	const BOOL res = GetFileAttributesEx(wpath, GetFileExInfoStandard, &file_info);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   534
	if (res) {
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   535
		isdir = (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   536
	}
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   537
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   538
	const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   539
	BAIL_IF_MACRO(!rc, errcodeFromWinApi(), 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   540
	return 1;   /* if you made it here, it worked. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   541
} /* doPlatformDelete */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   542
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   543
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   544
int __PHYSFS_platformDelete(const char *path)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   545
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   546
	int retval = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   547
	LPWSTR wpath = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   548
	UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   549
	BAIL_IF_MACRO(!wpath, PHYSFS_ERR_OUT_OF_MEMORY, 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   550
	retval = doPlatformDelete(wpath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   551
	__PHYSFS_smallFree(wpath);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   552
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   553
} /* __PHYSFS_platformDelete */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   554
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   555
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   556
void *__PHYSFS_platformCreateMutex(void)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   557
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   558
	LPCRITICAL_SECTION lpcs;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   559
	lpcs = (LPCRITICAL_SECTION)allocator.Malloc(sizeof(CRITICAL_SECTION));
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   560
	BAIL_IF_MACRO(!lpcs, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   561
	//InitializeCriticalSection(lpcs);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   562
	InitializeCriticalSectionEx(lpcs, 2000, 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   563
	return lpcs;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   564
} /* __PHYSFS_platformCreateMutex */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   565
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   566
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   567
void __PHYSFS_platformDestroyMutex(void *mutex)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   568
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   569
	DeleteCriticalSection((LPCRITICAL_SECTION)mutex);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   570
	allocator.Free(mutex);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   571
} /* __PHYSFS_platformDestroyMutex */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   572
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   573
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   574
int __PHYSFS_platformGrabMutex(void *mutex)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   575
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   576
	EnterCriticalSection((LPCRITICAL_SECTION)mutex);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   577
	return 1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   578
} /* __PHYSFS_platformGrabMutex */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   579
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   580
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   581
void __PHYSFS_platformReleaseMutex(void *mutex)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   582
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   583
	LeaveCriticalSection((LPCRITICAL_SECTION)mutex);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   584
} /* __PHYSFS_platformReleaseMutex */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   585
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   586
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   587
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   588
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   589
	SYSTEMTIME st_utc;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   590
	SYSTEMTIME st_localtz;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   591
	TIME_ZONE_INFORMATION tzi;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   592
	DWORD tzid;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   593
	PHYSFS_sint64 retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   594
	struct tm tm;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   595
	BOOL rc;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   596
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   597
	BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), errcodeFromWinApi(), -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   598
	tzid = GetTimeZoneInformation(&tzi);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   599
	BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, errcodeFromWinApi(), -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   600
	rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   601
	BAIL_IF_MACRO(!rc, errcodeFromWinApi(), -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   602
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   603
	/* Convert to a format that mktime() can grok... */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   604
	tm.tm_sec = st_localtz.wSecond;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   605
	tm.tm_min = st_localtz.wMinute;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   606
	tm.tm_hour = st_localtz.wHour;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   607
	tm.tm_mday = st_localtz.wDay;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   608
	tm.tm_mon = st_localtz.wMonth - 1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   609
	tm.tm_year = st_localtz.wYear - 1900;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   610
	tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   611
	tm.tm_yday = -1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   612
	tm.tm_isdst = -1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   613
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   614
	/* Convert to a format PhysicsFS can grok... */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   615
	retval = (PHYSFS_sint64)mktime(&tm);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   616
	BAIL_IF_MACRO(retval == -1, PHYSFS_ERR_OS_ERROR, -1);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   617
	return retval;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   618
} /* FileTimeToPhysfsTime */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   619
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   620
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   621
int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   622
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   623
	WIN32_FILE_ATTRIBUTE_DATA winstat;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   624
	WCHAR *wstr = NULL;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   625
	DWORD err = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   626
	BOOL rc = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   627
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   628
	UTF8_TO_UNICODE_STACK_MACRO(wstr, filename);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   629
	BAIL_IF_MACRO(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   630
	rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   631
	err = (!rc) ? GetLastError() : 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   632
	__PHYSFS_smallFree(wstr);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   633
	BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   634
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   635
	st->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   636
	st->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   637
	st->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   638
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   639
	if (winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   640
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   641
		st->filetype = PHYSFS_FILETYPE_DIRECTORY;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   642
		st->filesize = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   643
	} /* if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   644
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   645
	else if (winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE))
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   646
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   647
		/* !!! FIXME: what are reparse points? */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   648
		st->filetype = PHYSFS_FILETYPE_OTHER;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   649
		/* !!! FIXME: don't rely on this */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   650
		st->filesize = 0;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   651
	} /* else if */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   652
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   653
	/* !!! FIXME: check for symlinks on Vista. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   654
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   655
	else
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   656
	{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   657
		st->filetype = PHYSFS_FILETYPE_REGULAR;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   658
		st->filesize = (((PHYSFS_uint64)winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   659
	} /* else */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   660
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   661
	st->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   662
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   663
	return 1;
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   664
} /* __PHYSFS_platformStat */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   665
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   666
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   667
/* !!! FIXME: Don't use C runtime for allocators? */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   668
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   669
{
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   670
	return 0;  /* just use malloc() and friends. */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   671
} /* __PHYSFS_platformSetDefaultAllocator */
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   672
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   673
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   674
#endif /* PHYSFS_PLATFORM_WINRT */