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