src/platform_winrt.cpp
author Ryan C. Gordon <icculus@icculus.org>
Sun, 19 Apr 2015 23:26:02 -0400
changeset 1359 e06676e2c6b4
parent 1356 8de68968fcd0
child 1360 aa4787e50cc9
permissions -rw-r--r--
dos2unix'd platform_winrt.cpp
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
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    38
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    39
#define __PHYSICSFS_INTERNAL__
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    40
#include "physfs_platforms.h"
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    41
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    42
#ifdef PHYSFS_PLATFORM_WINRT
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
#include "physfs_internal.h"
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 <windows.h>
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    47
#include <errno.h>
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    48
#include <ctype.h>
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    49
#include <time.h>
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    50
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    51
#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    52
#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
    53
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    54
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
* 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
    57
*  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
    58
*  work as desired.
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    59
*/
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    60
#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
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
/* just in case... */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    63
#define PHYSFS_INVALID_FILE_ATTRIBUTES   0xFFFFFFFF
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    64
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    65
/* Not defined before the Vista SDK. */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    66
#define PHYSFS_IO_REPARSE_TAG_SYMLINK    0xA000000C
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    67
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    68
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    69
#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
    70
    if (str == NULL) \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    71
        w_assignto = NULL; \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    72
			    else { \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    73
        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
    74
        w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    75
        if (w_assignto != NULL) \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    76
            PHYSFS_utf8ToUtf16(str, (PHYSFS_uint16 *) w_assignto, len); \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    77
			    } \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    78
} \
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    79
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    80
/* Note this counts WCHARs, not codepoints! */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    81
static PHYSFS_uint64 wStrLen(const WCHAR *wstr)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    82
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    83
	PHYSFS_uint64 len = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    84
	while (*(wstr++))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    85
		len++;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    86
	return len;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    87
} /* wStrLen */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    88
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    89
/* !!! 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
    90
typedef struct
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    91
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    92
	HANDLE handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    93
	int readonly;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    94
} WinApiFile;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    95
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    96
static HANDLE detectCDThreadHandle = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    97
static HWND detectCDHwnd = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    98
static volatile int initialDiscDetectionComplete = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
    99
static volatile DWORD drivesWithMediaBitmap = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   100
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   101
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   102
static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err)
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
	/*
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   105
	* 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
   106
	*  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
   107
	*  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
   108
	*  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
   109
	*  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
   110
	*  important values or misinterpret others.
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   111
	*
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   112
	* 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
   113
	*/
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   114
	switch (err)
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
	case ERROR_SUCCESS: return PHYSFS_ERR_OK;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   117
	case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   118
	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
   119
	case ERROR_NOT_READY: return PHYSFS_ERR_IO;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   120
	case ERROR_CRC: return PHYSFS_ERR_IO;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   121
	case ERROR_SEEK: return PHYSFS_ERR_IO;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   122
	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
   123
	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
   124
	case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   125
	case ERROR_READ_FAULT: return PHYSFS_ERR_IO;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   126
	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
   127
		/* !!! FIXME: ?? case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   128
	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
   129
	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
   130
	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
   131
	case ERROR_DIRECTORY: return PHYSFS_ERR_BAD_FILENAME;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   132
	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
   133
	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
   134
	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
   135
	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
   136
	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
   137
	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
   138
		/* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NOT_FOUND; */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   139
		/* !!! 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
   140
	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
   141
	case ERROR_LOCK_VIOLATION: return PHYSFS_ERR_BUSY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   142
	case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_BUSY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   143
	case ERROR_CURRENT_DIRECTORY: return PHYSFS_ERR_BUSY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   144
	case ERROR_DRIVE_LOCKED: return PHYSFS_ERR_BUSY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   145
	case ERROR_PATH_BUSY: return PHYSFS_ERR_BUSY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   146
	case ERROR_BUSY: return PHYSFS_ERR_BUSY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   147
	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
   148
	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
   149
	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
   150
	default: return PHYSFS_ERR_OS_ERROR;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   151
	} /* switch */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   152
} /* errcodeFromWinApiError */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   153
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   154
static inline PHYSFS_ErrorCode errcodeFromWinApi(void)
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
	return errcodeFromWinApiError(GetLastError());
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   157
} /* errcodeFromWinApi */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   158
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   159
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   160
typedef BOOL(WINAPI *fnSTEM)(DWORD, LPDWORD b);
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
static DWORD pollDiscDrives(void)
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
	// We don't do discs
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   165
	return 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   166
} /* pollDiscDrives */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   167
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   168
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   169
static LRESULT CALLBACK detectCDWndProc(HWND hwnd, UINT msg,
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   170
	WPARAM wp, LPARAM lparam)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   171
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   172
	return FALSE;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   173
} /* detectCDWndProc */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   174
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   175
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   176
static DWORD WINAPI detectCDThread(LPVOID lpParameter)
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
	return 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   179
} /* detectCDThread */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   180
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   181
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   182
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
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
	return;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   185
} /* __PHYSFS_platformDetectAvailableCDs */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   186
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   187
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   188
static char *unicodeToUtf8Heap(const WCHAR *w_str)
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
	char *retval = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   191
	if (w_str != NULL)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   192
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   193
		void *ptr = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   194
		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
   195
		retval = (char*)allocator.Malloc(len);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   196
		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
   197
		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
   198
		ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   199
		if (ptr != NULL)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   200
			retval = (char *)ptr;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   201
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   202
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   203
} /* unicodeToUtf8Heap */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   204
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   205
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
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
	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
   208
	wchar_t path2[1024];
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   209
	wcscpy_s(path2, path);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   210
	wcscat_s(path2, L"\\");
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   211
	return unicodeToUtf8Heap(path2);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   212
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   213
} /* __PHYSFS_platformCalcBaseDir */
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
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   216
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
   217
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   218
	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
   219
	wchar_t path2[1024];
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   220
	wcscpy_s(path2, path);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   221
	wcscat_s(path2, L"\\");
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   222
	return unicodeToUtf8Heap(path2);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   223
} /* __PHYSFS_platformCalcPrefDir */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   224
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   225
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   226
char *__PHYSFS_platformCalcUserDir(void)
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
	return __PHYSFS_platformCalcPrefDir(NULL, NULL);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   229
} /* __PHYSFS_platformCalcUserDir */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   230
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   231
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   232
void *__PHYSFS_platformGetThreadID(void)
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
	return ((void *)((size_t)GetCurrentThreadId()));
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   235
} /* __PHYSFS_platformGetThreadID */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   236
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   237
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   238
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
   239
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   240
	return ((attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   241
		(tag == PHYSFS_IO_REPARSE_TAG_SYMLINK));
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   242
} /* isSymlinkAttrs */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   243
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   244
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   245
void __PHYSFS_platformEnumerateFiles(const char *dirname,
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   246
	PHYSFS_EnumFilesCallback callback,
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   247
	const char *origdir,
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   248
	void *callbackdata)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   249
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   250
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   251
	HANDLE dir = INVALID_HANDLE_VALUE;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   252
	WIN32_FIND_DATAW entw;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   253
	size_t len = strlen(dirname);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   254
	char *searchPath = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   255
	WCHAR *wSearchPath = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   256
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   257
	/* 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
   258
	searchPath = (char *)__PHYSFS_smallAlloc(len + 3);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   259
	if (searchPath == NULL)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   260
		return;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   261
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   262
	/* Copy current dirname */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   263
	strcpy(searchPath, dirname);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   264
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   265
	/* 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
   266
	if (searchPath[len - 1] != '\\')
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   267
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   268
		searchPath[len++] = '\\';
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   269
		searchPath[len] = '\0';
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   270
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   271
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   272
	/* Append the "*" to the end of the string */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   273
	strcat(searchPath, "*");
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   274
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   275
	UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   276
	if (!wSearchPath)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   277
		return;  /* oh well. */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   278
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   279
	//dir = FindFirstFileW(wSearchPath, &entw);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   280
	dir = FindFirstFileExW(wSearchPath, FindExInfoStandard, &entw, FindExSearchNameMatch, NULL, 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   281
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   282
	__PHYSFS_smallFree(wSearchPath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   283
	__PHYSFS_smallFree(searchPath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   284
	if (dir == INVALID_HANDLE_VALUE)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   285
		return;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   286
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   287
	do
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
		const DWORD attr = entw.dwFileAttributes;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   290
		const DWORD tag = entw.dwReserved0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   291
		const WCHAR *fn = entw.cFileName;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   292
		char *utf8;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   293
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   294
		if ((fn[0] == '.') && (fn[1] == '\0'))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   295
			continue;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   296
		if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\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
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   299
		utf8 = unicodeToUtf8Heap(fn);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   300
		if (utf8 != NULL)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   301
		{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   302
			callback(callbackdata, origdir, utf8);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   303
			allocator.Free(utf8);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   304
		} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   305
	} while (FindNextFileW(dir, &entw) != 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   306
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   307
	FindClose(dir);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   308
} /* __PHYSFS_platformEnumerateFiles */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   309
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   310
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   311
int __PHYSFS_platformMkDir(const char *path)
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
	WCHAR *wpath;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   314
	DWORD rc;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   315
	UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   316
	rc = CreateDirectoryW(wpath, NULL);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   317
	__PHYSFS_smallFree(wpath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   318
	BAIL_IF_MACRO(rc == 0, errcodeFromWinApi(), 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   319
	return 1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   320
} /* __PHYSFS_platformMkDir */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   321
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   322
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   323
int __PHYSFS_platformInit(void)
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
	return 1;  /* It's all good */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   326
} /* __PHYSFS_platformInit */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   327
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   328
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   329
int __PHYSFS_platformDeinit(void)
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
	return 1; /* It's all good */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   332
} /* __PHYSFS_platformDeinit */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   333
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   334
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   335
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
   336
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   337
	HANDLE fileh;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   338
	WinApiFile *retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   339
	WCHAR *wfname;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   340
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   341
	UTF8_TO_UNICODE_STACK_MACRO(wfname, fname);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   342
	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
   343
	//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
   344
	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
   345
	__PHYSFS_smallFree(wfname);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   346
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   347
	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
   348
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   349
	retval = (WinApiFile *)allocator.Malloc(sizeof(WinApiFile));
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   350
	if (!retval)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   351
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   352
		CloseHandle(fileh);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   353
		BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   354
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   355
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   356
	retval->readonly = rdonly;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   357
	retval->handle = fileh;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   358
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   359
} /* doOpen */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   360
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   361
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   362
void *__PHYSFS_platformOpenRead(const char *filename)
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
	return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   365
} /* __PHYSFS_platformOpenRead */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   366
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   367
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   368
void *__PHYSFS_platformOpenWrite(const char *filename)
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
	return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   371
} /* __PHYSFS_platformOpenWrite */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   372
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   373
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   374
void *__PHYSFS_platformOpenAppend(const char *filename)
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 *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   377
	if (retval != NULL)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   378
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   379
		HANDLE h = ((WinApiFile *)retval)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   380
		//DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   381
		const LARGE_INTEGER zero = { 0 };
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   382
		DWORD rc = SetFilePointerEx(h, zero, NULL, FILE_END);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   383
		if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   384
		{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   385
			const PHYSFS_ErrorCode err = errcodeFromWinApi();
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   386
			CloseHandle(h);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   387
			allocator.Free(retval);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   388
			BAIL_MACRO(err, NULL);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   389
		} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   390
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   391
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   392
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   393
} /* __PHYSFS_platformOpenAppend */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   394
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   395
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   396
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
   397
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   398
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   399
	PHYSFS_sint64 totalRead = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   400
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   401
	if (!__PHYSFS_ui64FitsAddressSpace(len))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   402
		BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   403
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   404
	while (len > 0)
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
		const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   407
		DWORD numRead = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   408
		if (!ReadFile(Handle, buf, thislen, &numRead, NULL))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   409
			BAIL_MACRO(errcodeFromWinApi(), -1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   410
		len -= (PHYSFS_uint64)numRead;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   411
		totalRead += (PHYSFS_sint64)numRead;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   412
		if (numRead != thislen)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   413
			break;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   414
	} /* while */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   415
	
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   416
	return totalRead;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   417
} /* __PHYSFS_platformRead */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   418
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   419
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   420
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
   421
	PHYSFS_uint64 len)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   422
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   423
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   424
	PHYSFS_sint64 totalWritten = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   425
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   426
	if (!__PHYSFS_ui64FitsAddressSpace(len))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   427
		BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   428
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   429
	while (len > 0)
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
		const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD)len;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   432
		DWORD numWritten = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   433
		if (!WriteFile(Handle, buffer, thislen, &numWritten, NULL))
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   434
			BAIL_MACRO(errcodeFromWinApi(), -1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   435
		len -= (PHYSFS_uint64)numWritten;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   436
		totalWritten += (PHYSFS_sint64)numWritten;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   437
		if (numWritten != thislen)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   438
			break;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   439
	} /* while */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   440
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   441
	return totalWritten;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   442
} /* __PHYSFS_platformWrite */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   443
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   444
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   445
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
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
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   448
	BOOL rc;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   449
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   450
	LARGE_INTEGER li;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   451
	li.LowPart = LOWORDER_UINT64(pos);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   452
	li.HighPart = HIGHORDER_UINT64(pos);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   453
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   454
	rc = SetFilePointerEx(Handle, li, NULL, FILE_BEGIN);
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
	if (!rc && (GetLastError() != NO_ERROR))
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
		BAIL_MACRO(errcodeFromWinApi(), 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   459
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   460
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   461
	return 1;  /* No error occured */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   462
} /* __PHYSFS_platformSeek */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   463
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   464
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   465
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
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
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   468
	PHYSFS_sint64 retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   469
	BOOL rc;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   470
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   471
	LARGE_INTEGER zero;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   472
	zero.QuadPart = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   473
	LARGE_INTEGER out;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   474
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   475
	rc = SetFilePointerEx(Handle, zero, &out, FILE_CURRENT);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   476
	if (!rc)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   477
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   478
		BAIL_MACRO(errcodeFromWinApi(), -1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   479
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   480
	else
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   481
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   482
		retval = out.QuadPart;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   483
		assert(retval >= 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   484
	} /* else */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   485
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   486
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   487
} /* __PHYSFS_platformTell */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   488
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   489
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   490
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
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
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   493
	PHYSFS_sint64 retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   494
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   495
	FILE_STANDARD_INFO file_info = { 0 };
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   496
	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
   497
	if (res) {
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   498
		retval = file_info.EndOfFile.QuadPart;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   499
		assert(retval >= 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   500
	}
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   501
	else {
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   502
		PHYSFS_setErrorCode(PHYSFS_ERR_NOT_FOUND);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   503
	}
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   504
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
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   507
} /* __PHYSFS_platformFileLength */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   508
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   509
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   510
int __PHYSFS_platformFlush(void *opaque)
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
	WinApiFile *fh = ((WinApiFile *)opaque);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   513
	if (!fh->readonly)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   514
		BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), errcodeFromWinApi(), 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   515
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   516
	return 1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   517
} /* __PHYSFS_platformFlush */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   518
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   519
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   520
void __PHYSFS_platformClose(void *opaque)
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
	HANDLE Handle = ((WinApiFile *)opaque)->handle;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   523
	(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
   524
	allocator.Free(opaque);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   525
} /* __PHYSFS_platformClose */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   526
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   527
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   528
static int doPlatformDelete(LPWSTR wpath)
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
	//const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   531
	int isdir = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   532
	WIN32_FILE_ATTRIBUTE_DATA file_info;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   533
	const BOOL res = GetFileAttributesEx(wpath, GetFileExInfoStandard, &file_info);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   534
	if (res) {
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   535
		isdir = (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   536
	}
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   537
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   538
	const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   539
	BAIL_IF_MACRO(!rc, errcodeFromWinApi(), 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   540
	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
   541
} /* doPlatformDelete */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   542
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   543
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   544
int __PHYSFS_platformDelete(const char *path)
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 retval = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   547
	LPWSTR wpath = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   548
	UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   549
	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
   550
	retval = doPlatformDelete(wpath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   551
	__PHYSFS_smallFree(wpath);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   552
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   553
} /* __PHYSFS_platformDelete */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   554
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   555
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   556
void *__PHYSFS_platformCreateMutex(void)
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
	LPCRITICAL_SECTION lpcs;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   559
	lpcs = (LPCRITICAL_SECTION)allocator.Malloc(sizeof(CRITICAL_SECTION));
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   560
	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
   561
	//InitializeCriticalSection(lpcs);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   562
	InitializeCriticalSectionEx(lpcs, 2000, 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   563
	return lpcs;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   564
} /* __PHYSFS_platformCreateMutex */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   565
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   566
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   567
void __PHYSFS_platformDestroyMutex(void *mutex)
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
	DeleteCriticalSection((LPCRITICAL_SECTION)mutex);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   570
	allocator.Free(mutex);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   571
} /* __PHYSFS_platformDestroyMutex */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   572
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   573
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   574
int __PHYSFS_platformGrabMutex(void *mutex)
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
	EnterCriticalSection((LPCRITICAL_SECTION)mutex);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   577
	return 1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   578
} /* __PHYSFS_platformGrabMutex */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   579
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   580
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   581
void __PHYSFS_platformReleaseMutex(void *mutex)
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
	LeaveCriticalSection((LPCRITICAL_SECTION)mutex);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   584
} /* __PHYSFS_platformReleaseMutex */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   585
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   586
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   587
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
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
	SYSTEMTIME st_utc;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   590
	SYSTEMTIME st_localtz;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   591
	TIME_ZONE_INFORMATION tzi;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   592
	DWORD tzid;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   593
	PHYSFS_sint64 retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   594
	struct tm tm;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   595
	BOOL rc;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   596
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   597
	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
   598
	tzid = GetTimeZoneInformation(&tzi);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   599
	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
   600
	rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   601
	BAIL_IF_MACRO(!rc, errcodeFromWinApi(), -1);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   602
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   603
	/* Convert to a format that mktime() can grok... */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   604
	tm.tm_sec = st_localtz.wSecond;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   605
	tm.tm_min = st_localtz.wMinute;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   606
	tm.tm_hour = st_localtz.wHour;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   607
	tm.tm_mday = st_localtz.wDay;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   608
	tm.tm_mon = st_localtz.wMonth - 1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   609
	tm.tm_year = st_localtz.wYear - 1900;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   610
	tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   611
	tm.tm_yday = -1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   612
	tm.tm_isdst = -1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   613
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   614
	/* Convert to a format PhysicsFS can grok... */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   615
	retval = (PHYSFS_sint64)mktime(&tm);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   616
	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
   617
	return retval;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   618
} /* FileTimeToPhysfsTime */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   619
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   620
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   621
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
   622
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   623
	WIN32_FILE_ATTRIBUTE_DATA winstat;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   624
	WCHAR *wstr = NULL;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   625
	DWORD err = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   626
	BOOL rc = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   627
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   628
	UTF8_TO_UNICODE_STACK_MACRO(wstr, filename);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   629
	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
   630
	rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   631
	err = (!rc) ? GetLastError() : 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   632
	__PHYSFS_smallFree(wstr);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   633
	BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   634
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   635
	st->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   636
	st->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   637
	st->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   638
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   639
	if (winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
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
		st->filetype = PHYSFS_FILETYPE_DIRECTORY;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   642
		st->filesize = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   643
	} /* if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   644
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   645
	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
   646
	{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   647
		/* !!! FIXME: what are reparse points? */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   648
		st->filetype = PHYSFS_FILETYPE_OTHER;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   649
		/* !!! FIXME: don't rely on this */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   650
		st->filesize = 0;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   651
	} /* else if */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   652
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   653
	/* !!! FIXME: check for symlinks on Vista. */
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
	else
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
		st->filetype = PHYSFS_FILETYPE_REGULAR;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   658
		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
   659
	} /* else */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   660
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   661
	st->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
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
	return 1;
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   664
} /* __PHYSFS_platformStat */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   665
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   666
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   667
/* !!! FIXME: Don't use C runtime for allocators? */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   668
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   669
{
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   670
	return 0;  /* just use malloc() and friends. */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   671
} /* __PHYSFS_platformSetDefaultAllocator */
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   672
e06676e2c6b4 dos2unix'd platform_winrt.cpp
Ryan C. Gordon <icculus@icculus.org>
parents: 1356
diff changeset
   673
1356
8de68968fcd0 Added support for WinRT 8.1 Universal Apps.
Martin Ahrnbom <m.ahrnbom@outlook.com>
parents:
diff changeset
   674
#endif /* PHYSFS_PLATFORM_WINRT */