misc/libphysfs/platform_windows.c
author nemo
Sat, 28 Dec 2013 11:01:28 -0500
branch0.9.20
changeset 9863 7ef319ac69f8
parent 8524 a65e9bcf0a03
child 10017 de822cd3df3a
permissions -rw-r--r--
Delete Application
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     1
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     2
 * Windows support routines for PhysicsFS.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     3
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     5
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon, and made sane by Gregory S. Read.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     7
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     8
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     9
#define __PHYSICSFS_INTERNAL__
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    10
#include "physfs_platforms.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    11
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    12
#ifdef PHYSFS_PLATFORM_WINDOWS
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    13
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    14
/* Forcibly disable UNICODE macro, since we manage this ourselves. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    15
#ifdef UNICODE
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    16
#undef UNICODE
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    17
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    18
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    19
#define WIN32_LEAN_AND_MEAN 1
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    20
#include <windows.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    21
#include <userenv.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    22
#include <shlobj.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    23
#include <dbt.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    24
#include <errno.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    25
#include <ctype.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    26
#include <time.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    27
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    28
#include "physfs_internal.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    29
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    30
#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
#define HIGHORDER_UINT64(pos) ((PHYSFS_uint32) ((pos >> 32) & 0xFFFFFFFF))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    32
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    33
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
 * Users without the platform SDK don't have this defined.  The original docs
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    35
 *  for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    36
 *  work as desired.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    37
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    38
#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    39
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    40
/* just in case... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    41
#define PHYSFS_INVALID_FILE_ATTRIBUTES   0xFFFFFFFF
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    42
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    43
/* Not defined before the Vista SDK. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    44
#define PHYSFS_IO_REPARSE_TAG_SYMLINK    0xA000000C
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    45
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    46
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    47
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
    if (str == NULL) \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    49
        w_assignto = NULL; \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
    else { \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
        const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) + 1) * 2); \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
        w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    53
        if (w_assignto != NULL) \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    54
            PHYSFS_utf8ToUtf16(str, (PHYSFS_uint16 *) w_assignto, len); \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    55
    } \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    56
} \
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    57
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    58
/* Note this counts WCHARs, not codepoints! */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    59
static PHYSFS_uint64 wStrLen(const WCHAR *wstr)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    61
    PHYSFS_uint64 len = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    62
    while (*(wstr++))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    63
        len++;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
    return len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    65
} /* wStrLen */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    66
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    67
static char *unicodeToUtf8Heap(const WCHAR *w_str)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    68
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    69
    char *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    70
    if (w_str != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    71
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    72
        void *ptr = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    73
        const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    74
        retval = allocator.Malloc(len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    75
        BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    76
        PHYSFS_utf8FromUtf16((const PHYSFS_uint16 *) w_str, retval, len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    77
        ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    78
        if (ptr != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    79
            retval = (char *) ptr;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    80
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    81
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    82
} /* unicodeToUtf8Heap */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    83
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    84
/* !!! FIXME: do we really need readonly? If not, do we need this struct? */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    85
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    87
    HANDLE handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    88
    int readonly;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    89
} WinApiFile;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    90
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    91
static HANDLE detectCDThreadHandle = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    92
static HWND detectCDHwnd = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    93
static volatile int initialDiscDetectionComplete = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    94
static volatile DWORD drivesWithMediaBitmap = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    95
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    96
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    97
static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    98
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    99
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   100
     * win32 error codes are sort of a tricky thing; Microsoft intentionally
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   101
     *  doesn't list which ones a given API might trigger, there are several
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   102
     *  with overlapping and unclear meanings...and there's 16 thousand of
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   103
     *  them in Windows 7. It looks like the ones we care about are in the
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   104
     *  first 500, but I can't say this list is perfect; we might miss
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   105
     *  important values or misinterpret others.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   106
     *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   107
     * Don't treat this list as anything other than a work in progress.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   108
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   109
    switch (err)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   110
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   111
        case ERROR_SUCCESS: return PHYSFS_ERR_OK;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   112
        case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   113
        case ERROR_NETWORK_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   114
        case ERROR_NOT_READY: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   115
        case ERROR_CRC: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   116
        case ERROR_SEEK: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   117
        case ERROR_SECTOR_NOT_FOUND: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   118
        case ERROR_NOT_DOS_DISK: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   119
        case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   120
        case ERROR_READ_FAULT: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   121
        case ERROR_DEV_NOT_EXIST: return PHYSFS_ERR_IO;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   122
        /* !!! FIXME: ?? case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   123
        case ERROR_BUFFER_OVERFLOW: return PHYSFS_ERR_BAD_FILENAME;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   124
        case ERROR_INVALID_NAME: return PHYSFS_ERR_BAD_FILENAME;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   125
        case ERROR_BAD_PATHNAME: return PHYSFS_ERR_BAD_FILENAME;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   126
        case ERROR_DIRECTORY: return PHYSFS_ERR_BAD_FILENAME;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   127
        case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   128
        case ERROR_PATH_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   129
        case ERROR_DELETE_PENDING: return PHYSFS_ERR_NO_SUCH_PATH;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   130
        case ERROR_INVALID_DRIVE: return PHYSFS_ERR_NO_SUCH_PATH;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   131
        case ERROR_HANDLE_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   132
        case ERROR_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   133
        /* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NO_SUCH_PATH; */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   134
        /* !!! FIXME: ?? case EISDIR: return PHYSFS_ERR_NOT_A_FILE; */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   135
        case ERROR_WRITE_PROTECT: return PHYSFS_ERR_READ_ONLY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   136
        case ERROR_LOCK_VIOLATION: return PHYSFS_ERR_BUSY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   137
        case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_BUSY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   138
        case ERROR_CURRENT_DIRECTORY: return PHYSFS_ERR_BUSY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   139
        case ERROR_DRIVE_LOCKED: return PHYSFS_ERR_BUSY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   140
        case ERROR_PATH_BUSY: return PHYSFS_ERR_BUSY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   141
        case ERROR_BUSY: return PHYSFS_ERR_BUSY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   142
        case ERROR_NOT_ENOUGH_MEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   143
        case ERROR_OUTOFMEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   144
        case ERROR_DIR_NOT_EMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   145
        default: return PHYSFS_ERR_OS_ERROR;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   146
    } /* switch */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   147
} /* errcodeFromWinApiError */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   148
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   149
static inline PHYSFS_ErrorCode errcodeFromWinApi(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   150
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   151
    return errcodeFromWinApiError(GetLastError());
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   152
} /* errcodeFromWinApi */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   153
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   154
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   155
typedef BOOL (WINAPI *fnSTEM)(DWORD, LPDWORD b);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   156
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   157
static DWORD pollDiscDrives(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   158
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   159
    /* Try to use SetThreadErrorMode(), which showed up in Windows 7. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   160
    HANDLE lib = LoadLibraryA("kernel32.dll");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   161
    fnSTEM stem = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   162
    char drive[4] = { 'x', ':', '\\', '\0' };
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   163
    DWORD oldErrorMode = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   164
    DWORD drives = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   165
    DWORD i;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   166
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   167
    if (lib)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   168
        stem = (fnSTEM) GetProcAddress(lib, "SetThreadErrorMode");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   169
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   170
    if (stem)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   171
        stem(SEM_FAILCRITICALERRORS, &oldErrorMode);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   172
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   173
        oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   174
    
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   175
    /* Do detection. This may block if a disc is spinning up. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   176
    for (i = 'A'; i <= 'Z'; i++)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   177
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   178
        DWORD tmp = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   179
        drive[0] = (char) i;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   180
        if (GetDriveTypeA(drive) != DRIVE_CDROM)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   181
            continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   182
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   183
        /* If this function succeeds, there's media in the drive */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   184
        if (GetVolumeInformationA(drive, NULL, 0, NULL, NULL, &tmp, NULL, 0))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   185
            drives |= (1 << (i - 'A'));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   186
    } /* for */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   187
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   188
    if (stem)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   189
        stem(oldErrorMode, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   190
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   191
        SetErrorMode(oldErrorMode);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   192
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   193
    if (lib)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   194
        FreeLibrary(lib);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   195
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   196
    return drives;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   197
} /* pollDiscDrives */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   198
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   199
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   200
static LRESULT CALLBACK detectCDWndProc(HWND hwnd, UINT msg,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   201
                                        WPARAM wp, LPARAM lparam)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   202
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   203
    PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR) lparam;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   204
    PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME) lparam;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   205
    const int removed = (wp == DBT_DEVICEREMOVECOMPLETE);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   206
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   207
    if (msg == WM_DESTROY)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   208
        return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   209
    else if ((msg != WM_DEVICECHANGE) ||
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   210
             ((wp != DBT_DEVICEARRIVAL) && (wp != DBT_DEVICEREMOVECOMPLETE)) ||
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   211
             (lpdb->dbch_devicetype != DBT_DEVTYP_VOLUME) ||
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   212
             ((lpdbv->dbcv_flags & DBTF_MEDIA) == 0))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   213
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   214
        return DefWindowProcW(hwnd, msg, wp, lparam);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   215
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   216
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   217
    if (removed)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   218
        drivesWithMediaBitmap &= ~lpdbv->dbcv_unitmask;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   219
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   220
        drivesWithMediaBitmap |= lpdbv->dbcv_unitmask;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   221
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   222
    return TRUE;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   223
} /* detectCDWndProc */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   224
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   225
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   226
static DWORD WINAPI detectCDThread(LPVOID lpParameter)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   227
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   228
    const char *classname = "PhysicsFSDetectCDCatcher";
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   229
    const char *winname = "PhysicsFSDetectCDMsgWindow";
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   230
    HINSTANCE hInstance = GetModuleHandleW(NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   231
    ATOM class_atom = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   232
    WNDCLASSEXA wce;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   233
    MSG msg;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   234
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   235
    memset(&wce, '\0', sizeof (wce));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   236
    wce.cbSize = sizeof (wce);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   237
    wce.lpfnWndProc = detectCDWndProc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   238
    wce.lpszClassName = classname;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   239
    wce.hInstance = hInstance;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   240
    class_atom = RegisterClassExA(&wce);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   241
    if (class_atom == 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   242
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   243
        initialDiscDetectionComplete = 1;  /* let main thread go on. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   244
        return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   245
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   246
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   247
    detectCDHwnd = CreateWindowExA(0, classname, winname, WS_OVERLAPPEDWINDOW,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   248
                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   249
                        CW_USEDEFAULT, HWND_DESKTOP, NULL, hInstance, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   250
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   251
    if (detectCDHwnd == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   252
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   253
        initialDiscDetectionComplete = 1;  /* let main thread go on. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   254
        UnregisterClassA(classname, hInstance);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   255
        return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   256
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   257
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   258
    /* We'll get events when discs come and go from now on. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   259
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   260
    /* Do initial detection, possibly blocking awhile... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   261
    drivesWithMediaBitmap = pollDiscDrives();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   262
    initialDiscDetectionComplete = 1;  /* let main thread go on. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   263
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   264
    do
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   265
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   266
        const BOOL rc = GetMessageW(&msg, detectCDHwnd, 0, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   267
        if ((rc == 0) || (rc == -1))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   268
            break;  /* don't care if WM_QUIT or error break this loop. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   269
        TranslateMessage(&msg);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   270
        DispatchMessageW(&msg);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   271
    } while (1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   272
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   273
    /* we've been asked to quit. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   274
    DestroyWindow(detectCDHwnd);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   275
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   276
    do
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   277
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   278
        const BOOL rc = GetMessage(&msg, detectCDHwnd, 0, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   279
        if ((rc == 0) || (rc == -1))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   280
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   281
        TranslateMessage(&msg);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   282
        DispatchMessageW(&msg);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   283
    } while (1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   284
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   285
    UnregisterClassA(classname, hInstance);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   286
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   287
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   288
} /* detectCDThread */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   289
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   290
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   291
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   292
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   293
    char drive_str[4] = { 'x', ':', '\\', '\0' };
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   294
    DWORD drives = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   295
    DWORD i;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   296
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   297
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   298
     * If you poll a drive while a user is inserting a disc, the OS will
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   299
     *  block this thread until the drive has spun up. So we swallow the risk
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   300
     *  once for initial detection, and spin a thread that will get device
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   301
     *  events thereafter, for apps that use this interface to poll for
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   302
     *  disc insertion.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   303
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   304
    if (!detectCDThreadHandle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   305
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   306
        initialDiscDetectionComplete = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   307
        detectCDThreadHandle = CreateThread(NULL,0,detectCDThread,NULL,0,NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   308
        if (detectCDThreadHandle == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   309
            return;  /* oh well. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   310
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   311
        while (!initialDiscDetectionComplete)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   312
            Sleep(50);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   313
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   314
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   315
    drives = drivesWithMediaBitmap; /* whatever the thread has seen, we take. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   316
    for (i = 'A'; i <= 'Z'; i++)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   317
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   318
        if (drives & (1 << (i - 'A')))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   319
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   320
            drive_str[0] = (char) i;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   321
            cb(data, drive_str);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   322
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   323
    } /* for */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   324
} /* __PHYSFS_platformDetectAvailableCDs */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   325
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   326
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   327
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   328
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   329
    DWORD buflen = 64;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   330
    LPWSTR modpath = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   331
    char *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   332
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   333
    while (1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   334
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   335
        DWORD rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   336
        void *ptr;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   337
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   338
        if ( (ptr = allocator.Realloc(modpath, buflen*sizeof(WCHAR))) == NULL )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   339
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   340
            allocator.Free(modpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   341
            BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   342
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   343
        modpath = (LPWSTR) ptr;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   344
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   345
        rc = GetModuleFileNameW(NULL, modpath, buflen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   346
        if (rc == 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   347
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   348
            allocator.Free(modpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   349
            BAIL_MACRO(errcodeFromWinApi(), NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   350
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   351
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   352
        if (rc < buflen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   353
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   354
            buflen = rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   355
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   356
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   357
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   358
        buflen *= 2;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   359
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   360
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   361
    if (buflen > 0)  /* just in case... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   362
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   363
        WCHAR *ptr = (modpath + buflen) - 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   364
        while (ptr != modpath)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   365
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   366
            if (*ptr == '\\')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   367
                break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   368
            ptr--;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   369
        } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   370
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   371
        if ((ptr == modpath) && (*ptr != '\\'))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   372
            __PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR);  /* oh well. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   373
        else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   374
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   375
            *(ptr+1) = '\0';  /* chop off filename. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   376
            retval = unicodeToUtf8Heap(modpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   377
        } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   378
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   379
    allocator.Free(modpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   380
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   381
    return retval;   /* w00t. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   382
} /* __PHYSFS_platformCalcBaseDir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   383
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   384
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   385
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   386
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   387
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   388
     * Vista and later has a new API for this, but SHGetFolderPath works there,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   389
     *  and apparently just wraps the new API. This is the new way to do it:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   390
     *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   391
     *     SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   392
     *                          NULL, &wszPath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   393
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   394
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   395
    WCHAR path[MAX_PATH];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   396
    char *utf8 = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   397
    size_t len = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   398
    char *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   399
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   400
    if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   401
                                   NULL, 0, path)))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   402
        BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   403
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   404
    utf8 = unicodeToUtf8Heap(path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   405
    BAIL_IF_MACRO(!utf8, ERRPASS, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   406
    len = strlen(utf8) + strlen(org) + strlen(app) + 4;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   407
    retval = allocator.Malloc(len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   408
    if (!retval)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   409
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   410
        allocator.Free(utf8);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   411
        BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   412
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   413
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   414
    sprintf(retval, "%s\\%s\\%s\\", utf8, org, app);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   415
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   416
} /* __PHYSFS_platformCalcPrefDir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   417
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   418
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   419
char *__PHYSFS_platformCalcUserDir(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   420
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   421
    typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   422
    fnGetUserProfDirW pGetDir = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   423
    HANDLE lib = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   424
    HANDLE accessToken = NULL;       /* Security handle to process */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   425
    char *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   426
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   427
    lib = LoadLibraryA("userenv.dll");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   428
    BAIL_IF_MACRO(!lib, errcodeFromWinApi(), NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   429
    pGetDir=(fnGetUserProfDirW) GetProcAddress(lib,"GetUserProfileDirectoryW");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   430
    GOTO_IF_MACRO(!pGetDir, errcodeFromWinApi(), done);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   431
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   432
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   433
        GOTO_MACRO(errcodeFromWinApi(), done);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   434
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   435
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   436
        DWORD psize = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   437
        WCHAR dummy = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   438
        LPWSTR wstr = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   439
        BOOL rc = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   440
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   441
        /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   442
         * Should fail. Will write the size of the profile path in
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   443
         *  psize. Also note that the second parameter can't be
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   444
         *  NULL or the function fails.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   445
         */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   446
    	rc = pGetDir(accessToken, &dummy, &psize);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   447
        assert(!rc);  /* !!! FIXME: handle this gracefully. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   448
        (void) rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   449
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   450
        /* Allocate memory for the profile directory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   451
        wstr = (LPWSTR) __PHYSFS_smallAlloc((psize + 1) * sizeof (WCHAR));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   452
        if (wstr != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   453
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   454
            if (pGetDir(accessToken, wstr, &psize))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   455
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   456
                /* Make sure it ends in a dirsep. We allocated +1 for this. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   457
                if (wstr[psize - 2] != '\\')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   458
                {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   459
                    wstr[psize - 1] = '\\';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   460
                    wstr[psize - 0] = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   461
                } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   462
                retval = unicodeToUtf8Heap(wstr);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   463
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   464
            __PHYSFS_smallFree(wstr);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   465
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   466
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   467
        CloseHandle(accessToken);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   468
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   469
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   470
done:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   471
    FreeLibrary(lib);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   472
    return retval;  /* We made it: hit the showers. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   473
} /* __PHYSFS_platformCalcUserDir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   474
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   475
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   476
void *__PHYSFS_platformGetThreadID(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   477
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   478
    return ( (void *) ((size_t) GetCurrentThreadId()) );
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   479
} /* __PHYSFS_platformGetThreadID */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   480
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   481
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   482
static int isSymlinkAttrs(const DWORD attr, const DWORD tag)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   483
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   484
    return ( (attr & FILE_ATTRIBUTE_REPARSE_POINT) && 
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   485
             (tag == PHYSFS_IO_REPARSE_TAG_SYMLINK) );
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   486
} /* isSymlinkAttrs */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   487
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   488
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   489
void __PHYSFS_platformEnumerateFiles(const char *dirname,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   490
                                     int omitSymLinks,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   491
                                     PHYSFS_EnumFilesCallback callback,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   492
                                     const char *origdir,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   493
                                     void *callbackdata)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   494
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   495
    HANDLE dir = INVALID_HANDLE_VALUE;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   496
    WIN32_FIND_DATAW entw;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   497
    size_t len = strlen(dirname);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   498
    char *searchPath = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   499
    WCHAR *wSearchPath = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   500
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   501
    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   502
    searchPath = (char *) __PHYSFS_smallAlloc(len + 3);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   503
    if (searchPath == NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   504
        return;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   505
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   506
    /* Copy current dirname */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   507
    strcpy(searchPath, dirname);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   508
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   509
    /* if there's no '\\' at the end of the path, stick one in there. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   510
    if (searchPath[len - 1] != '\\')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   511
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   512
        searchPath[len++] = '\\';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   513
        searchPath[len] = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   514
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   515
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   516
    /* Append the "*" to the end of the string */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   517
    strcat(searchPath, "*");
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   518
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   519
    UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   520
    if (!wSearchPath)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   521
        return;  /* oh well. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   522
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   523
    dir = FindFirstFileW(wSearchPath, &entw);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   524
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   525
    __PHYSFS_smallFree(wSearchPath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   526
    __PHYSFS_smallFree(searchPath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   527
    if (dir == INVALID_HANDLE_VALUE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   528
        return;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   529
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   530
    do
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   531
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   532
        const DWORD attr = entw.dwFileAttributes;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   533
        const DWORD tag = entw.dwReserved0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   534
        const WCHAR *fn = entw.cFileName;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   535
        char *utf8;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   536
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   537
        if ((fn[0] == '.') && (fn[1] == '\0'))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   538
            continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   539
        if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   540
            continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   541
        if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   542
            continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   543
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   544
        utf8 = unicodeToUtf8Heap(fn);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   545
        if (utf8 != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   546
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   547
            callback(callbackdata, origdir, utf8);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   548
            allocator.Free(utf8);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   549
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   550
    } while (FindNextFileW(dir, &entw) != 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   551
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   552
    FindClose(dir);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   553
} /* __PHYSFS_platformEnumerateFiles */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   554
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   555
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   556
int __PHYSFS_platformMkDir(const char *path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   557
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   558
    WCHAR *wpath;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   559
    DWORD rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   560
    UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   561
    rc = CreateDirectoryW(wpath, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   562
    __PHYSFS_smallFree(wpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   563
    BAIL_IF_MACRO(rc == 0, errcodeFromWinApi(), 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   564
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   565
} /* __PHYSFS_platformMkDir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   566
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   567
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   568
int __PHYSFS_platformInit(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   569
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   570
    return 1;  /* It's all good */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   571
} /* __PHYSFS_platformInit */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   572
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   573
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   574
int __PHYSFS_platformDeinit(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   575
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   576
    if (detectCDThreadHandle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   577
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   578
        if (detectCDHwnd)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   579
            PostMessageW(detectCDHwnd, WM_QUIT, 0, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   580
        CloseHandle(detectCDThreadHandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   581
        detectCDThreadHandle = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   582
        initialDiscDetectionComplete = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   583
        drivesWithMediaBitmap = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   584
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   585
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   586
    return 1; /* It's all good */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   587
} /* __PHYSFS_platformDeinit */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   588
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   589
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   590
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   591
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   592
    HANDLE fileh;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   593
    WinApiFile *retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   594
    WCHAR *wfname;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   595
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   596
    UTF8_TO_UNICODE_STACK_MACRO(wfname, fname);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   597
    BAIL_IF_MACRO(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   598
    fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   599
                             NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   600
    __PHYSFS_smallFree(wfname);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   601
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   602
    BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE,errcodeFromWinApi(), NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   603
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   604
    retval = (WinApiFile *) allocator.Malloc(sizeof (WinApiFile));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   605
    if (!retval)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   606
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   607
        CloseHandle(fileh);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   608
        BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   609
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   610
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   611
    retval->readonly = rdonly;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   612
    retval->handle = fileh;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   613
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   614
} /* doOpen */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   615
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   616
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   617
void *__PHYSFS_platformOpenRead(const char *filename)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   618
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   619
    return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   620
} /* __PHYSFS_platformOpenRead */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   621
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   622
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   623
void *__PHYSFS_platformOpenWrite(const char *filename)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   624
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   625
    return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   626
} /* __PHYSFS_platformOpenWrite */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   627
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   628
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   629
void *__PHYSFS_platformOpenAppend(const char *filename)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   630
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   631
    void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   632
    if (retval != NULL)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   633
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   634
        HANDLE h = ((WinApiFile *) retval)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   635
        DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   636
        if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   637
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   638
            const PHYSFS_ErrorCode err = errcodeFromWinApi();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   639
            CloseHandle(h);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   640
            allocator.Free(retval);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   641
            BAIL_MACRO(err, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   642
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   643
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   644
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   645
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   646
} /* __PHYSFS_platformOpenAppend */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   647
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   648
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   649
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   650
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   651
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   652
    PHYSFS_sint64 totalRead = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   653
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   654
    if (!__PHYSFS_ui64FitsAddressSpace(len))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   655
        BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   656
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   657
    while (len > 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   658
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   659
        const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD) len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   660
        DWORD numRead = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   661
        if (!ReadFile(Handle, buf, thislen, &numRead, NULL))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   662
            BAIL_MACRO(errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   663
        len -= (PHYSFS_uint64) numRead;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   664
        totalRead += (PHYSFS_sint64) numRead;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   665
        if (numRead != thislen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   666
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   667
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   668
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   669
    return totalRead;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   670
} /* __PHYSFS_platformRead */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   671
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   672
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   673
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   674
                                     PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   675
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   676
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   677
    PHYSFS_sint64 totalWritten = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   678
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   679
    if (!__PHYSFS_ui64FitsAddressSpace(len))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   680
        BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   681
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   682
    while (len > 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   683
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   684
        const DWORD thislen = (len > 0xFFFFFFFF) ? 0xFFFFFFFF : (DWORD) len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   685
        DWORD numWritten = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   686
        if (!WriteFile(Handle, buffer, thislen, &numWritten, NULL))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   687
            BAIL_MACRO(errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   688
        len -= (PHYSFS_uint64) numWritten;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   689
        totalWritten += (PHYSFS_sint64) numWritten;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   690
        if (numWritten != thislen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   691
            break;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   692
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   693
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   694
    return totalWritten;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   695
} /* __PHYSFS_platformWrite */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   696
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   697
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   698
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   699
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   700
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   701
    LONG HighOrderPos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   702
    PLONG pHighOrderPos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   703
    DWORD rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   704
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   705
    /* Get the high order 32-bits of the position */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   706
    HighOrderPos = HIGHORDER_UINT64(pos);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   707
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   708
    /*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   709
     * MSDN: "If you do not need the high-order 32 bits, this
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   710
     *         pointer must be set to NULL."
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   711
     */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   712
    pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   713
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   714
    /* Move pointer "pos" count from start of file */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   715
    rc = SetFilePointer(Handle, LOWORDER_UINT64(pos),
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   716
                        pHighOrderPos, FILE_BEGIN);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   717
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   718
    if ( (rc == PHYSFS_INVALID_SET_FILE_POINTER) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   719
         (GetLastError() != NO_ERROR) )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   720
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   721
        BAIL_MACRO(errcodeFromWinApi(), 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   722
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   723
    
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   724
    return 1;  /* No error occured */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   725
} /* __PHYSFS_platformSeek */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   726
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   727
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   728
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   729
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   730
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   731
    LONG HighPos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   732
    DWORD LowPos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   733
    PHYSFS_sint64 retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   734
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   735
    /* Get current position */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   736
    LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   737
    if ( (LowPos == PHYSFS_INVALID_SET_FILE_POINTER) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   738
         (GetLastError() != NO_ERROR) )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   739
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   740
        BAIL_MACRO(errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   741
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   742
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   743
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   744
        /* Combine the high/low order to create the 64-bit position value */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   745
        retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   746
        assert(retval >= 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   747
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   748
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   749
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   750
} /* __PHYSFS_platformTell */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   751
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   752
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   753
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   754
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   755
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   756
    DWORD SizeHigh;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   757
    DWORD SizeLow;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   758
    PHYSFS_sint64 retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   759
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   760
    SizeLow = GetFileSize(Handle, &SizeHigh);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   761
    if ( (SizeLow == PHYSFS_INVALID_SET_FILE_POINTER) &&
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   762
         (GetLastError() != NO_ERROR) )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   763
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   764
        BAIL_MACRO(errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   765
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   766
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   767
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   768
        /* Combine the high/low order to create the 64-bit position value */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   769
        retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   770
        assert(retval >= 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   771
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   772
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   773
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   774
} /* __PHYSFS_platformFileLength */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   775
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   776
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   777
int __PHYSFS_platformFlush(void *opaque)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   778
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   779
    WinApiFile *fh = ((WinApiFile *) opaque);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   780
    if (!fh->readonly)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   781
        BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), errcodeFromWinApi(), 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   782
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   783
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   784
} /* __PHYSFS_platformFlush */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   785
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   786
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   787
void __PHYSFS_platformClose(void *opaque)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   788
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   789
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   790
    (void) CloseHandle(Handle); /* ignore errors. You should have flushed! */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   791
    allocator.Free(opaque);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   792
} /* __PHYSFS_platformClose */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   793
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   794
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   795
static int doPlatformDelete(LPWSTR wpath)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   796
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   797
    const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   798
    const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   799
    BAIL_IF_MACRO(!rc, errcodeFromWinApi(), 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   800
    return 1;   /* if you made it here, it worked. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   801
} /* doPlatformDelete */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   802
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   803
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   804
int __PHYSFS_platformDelete(const char *path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   805
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   806
    int retval = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   807
    LPWSTR wpath = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   808
    UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   809
    BAIL_IF_MACRO(!wpath, PHYSFS_ERR_OUT_OF_MEMORY, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   810
    retval = doPlatformDelete(wpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   811
    __PHYSFS_smallFree(wpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   812
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   813
} /* __PHYSFS_platformDelete */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   814
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   815
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   816
void *__PHYSFS_platformCreateMutex(void)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   817
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   818
    LPCRITICAL_SECTION lpcs;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   819
    lpcs = (LPCRITICAL_SECTION) allocator.Malloc(sizeof (CRITICAL_SECTION));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   820
    BAIL_IF_MACRO(!lpcs, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   821
    InitializeCriticalSection(lpcs);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   822
    return lpcs;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   823
} /* __PHYSFS_platformCreateMutex */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   824
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   825
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   826
void __PHYSFS_platformDestroyMutex(void *mutex)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   827
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   828
    DeleteCriticalSection((LPCRITICAL_SECTION) mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   829
    allocator.Free(mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   830
} /* __PHYSFS_platformDestroyMutex */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   831
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   832
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   833
int __PHYSFS_platformGrabMutex(void *mutex)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   834
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   835
    EnterCriticalSection((LPCRITICAL_SECTION) mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   836
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   837
} /* __PHYSFS_platformGrabMutex */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   838
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   839
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   840
void __PHYSFS_platformReleaseMutex(void *mutex)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   841
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   842
    LeaveCriticalSection((LPCRITICAL_SECTION) mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   843
} /* __PHYSFS_platformReleaseMutex */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   844
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   845
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   846
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   847
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   848
    SYSTEMTIME st_utc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   849
    SYSTEMTIME st_localtz;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   850
    TIME_ZONE_INFORMATION tzi;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   851
    DWORD tzid;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   852
    PHYSFS_sint64 retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   853
    struct tm tm;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   854
    BOOL rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   855
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   856
    BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   857
    tzid = GetTimeZoneInformation(&tzi);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   858
    BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   859
    rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   860
    BAIL_IF_MACRO(!rc, errcodeFromWinApi(), -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   861
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   862
    /* Convert to a format that mktime() can grok... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   863
    tm.tm_sec = st_localtz.wSecond;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   864
    tm.tm_min = st_localtz.wMinute;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   865
    tm.tm_hour = st_localtz.wHour;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   866
    tm.tm_mday = st_localtz.wDay;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   867
    tm.tm_mon = st_localtz.wMonth - 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   868
    tm.tm_year = st_localtz.wYear - 1900;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   869
    tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   870
    tm.tm_yday = -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   871
    tm.tm_isdst = -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   872
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   873
    /* Convert to a format PhysicsFS can grok... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   874
    retval = (PHYSFS_sint64) mktime(&tm);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   875
    BAIL_IF_MACRO(retval == -1, PHYSFS_ERR_OS_ERROR, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   876
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   877
} /* FileTimeToPhysfsTime */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   878
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   879
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   880
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   881
    WIN32_FILE_ATTRIBUTE_DATA winstat;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   882
    WCHAR *wstr = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   883
    DWORD err = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   884
    BOOL rc = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   885
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   886
    UTF8_TO_UNICODE_STACK_MACRO(wstr, filename);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   887
    BAIL_IF_MACRO(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   888
    rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   889
    err = (!rc) ? GetLastError() : 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   890
    *exists = ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   891
    __PHYSFS_smallFree(wstr);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   892
    BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   893
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   894
    stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   895
    stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   896
    stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   897
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   898
    if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   899
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   900
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   901
        stat->filesize = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   902
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   903
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   904
    else if(winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   905
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   906
        /* !!! FIXME: what are reparse points? */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   907
        stat->filetype = PHYSFS_FILETYPE_OTHER;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   908
        /* !!! FIXME: don't rely on this */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   909
        stat->filesize = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   910
    } /* else if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   911
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   912
    /* !!! FIXME: check for symlinks on Vista. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   913
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   914
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   915
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   916
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   917
        stat->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   918
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   919
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   920
    stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   921
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   922
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   923
} /* __PHYSFS_platformStat */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   924
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   925
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   926
/* !!! FIXME: Don't use C runtime for allocators? */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   927
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   928
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   929
    return 0;  /* just use malloc() and friends. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   930
} /* __PHYSFS_platformSetDefaultAllocator */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   931
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   932
#endif  /* PHYSFS_PLATFORM_WINDOWS */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   933
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   934
/* end of windows.c ... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   935
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   936