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