src/platform_windows.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 20 Mar 2012 15:38:12 -0400
changeset 1240 22d4d1bd4e21
parent 1237 6d8b32355a28
child 1242 1e6db80d2393
permissions -rw-r--r--
Reworked the error reporting API. Now we use error codes instead of strings. This is based on work originally done by Christoph Nelles.
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>
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    22
#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
    23
#include <errno.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    24
#include <ctype.h>
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
    25
#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
    26
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include "physfs_internal.h"
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
908
662ca06432ef Mingw32 fix for 64-bit literals.
Ryan C. Gordon <icculus@icculus.org>
parents: 906
diff changeset
    29
#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
    30
#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
    31
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    32
/*
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    33
 * 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
    34
 *  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
    35
 *  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
    36
 */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    37
#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    39
/* just in case... */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    40
#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
    41
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
    42
/* 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
    43
#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
    44
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
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    46
#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
    47
    if (str == NULL) \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    48
        w_assignto = NULL; \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    49
    else { \
915
1445c55cdbe6 Fixed allocation size when converting from UTF-8 to UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
    50
        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
    51
        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
    52
        if (w_assignto != NULL) \
1237
6d8b32355a28 Use UTF-16 on Windows, not UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1226
diff changeset
    53
            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
    54
    } \
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
1237
6d8b32355a28 Use UTF-16 on Windows, not UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents: 1226
diff changeset
    57
/* 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
    58
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
    59
{
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
    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
    61
    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
    62
        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
    63
    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
    64
} /* 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
    65
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
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
    67
{
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
    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
    69
    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
    70
    {
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
        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
    72
        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
    73
        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
    74
        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
    75
        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
    76
        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
    77
        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
    78
            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
    79
    } /* 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
    80
    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
    81
} /* 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
    82
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    83
/* !!! 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
    84
typedef struct
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    85
{
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    86
    HANDLE handle;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    87
    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
    88
} WinApiFile;
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    89
864
ce0fcbbba8a3 Man, I knew I would need getOSInfo() as soon as I deleted it!
Ryan C. Gordon <icculus@icculus.org>
parents: 862
diff changeset
    90
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
    91
static char *userDir = NULL;
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    92
static HANDLE libUserEnv = NULL;
1217
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 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
    94
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
    95
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
    96
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
    97
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
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
    99
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
   100
{
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
    /*
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
     * 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
   103
     *  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
   104
     *  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
   105
     *  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
   106
     *  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
   107
     *  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
   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
     * 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
   110
     */
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
    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
   112
    {
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
   113
        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
   114
        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
   115
        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
   116
        case ERROR_DISK_RESOURCES_EXHAUSTED: 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
   117
        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
   118
        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
   119
        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
   120
        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
   121
        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
   122
        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
   123
        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
   124
        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
   125
        case ERROR_DATA_CHECKSUM_ERROR: 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
   126
        /* !!! 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
   127
        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
   128
        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
   129
        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
   130
        case ERROR_DIRECTORY: 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
   131
        case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH;
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_PATH_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH;
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1237
diff changeset
   133
        case ERROR_DELETE_PENDING: return PHYSFS_ERR_NO_SUCH_PATH;
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
        case ERROR_INVALID_DRIVE: return PHYSFS_ERR_NO_SUCH_PATH;
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_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
   136
        case ERROR_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
   137
        /* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NO_SUCH_PATH; */
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
        /* !!! 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
   139
        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
   140
        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
   141
        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
   142
        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
   143
        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
   144
        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
   145
        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
   146
        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
   147
        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
   148
        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
   149
        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
   150
    } /* 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
   151
} /* errcodeFromWinApiError */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   152
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
   153
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
   154
{
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1237
diff changeset
   155
    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
   156
} /* errcodeFromWinApi */
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   157
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
   158
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   160
/*
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   161
 * On success, module-scope variable (userDir) will have a pointer to
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   162
 *  a malloc()'d string of the user's profile dir, and a non-zero value is
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   163
 *  returned. If we can't determine the profile dir, (userDir) will
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   164
 *  be NULL, and zero is returned.
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   165
 */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   166
static int determineUserDir(void)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   167
{
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   168
    typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   169
    fnGetUserProfDirW pGetDir = NULL;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   171
    HANDLE accessToken = NULL;       /* Security handle to process */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   172
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   173
    if (userDir != NULL)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   174
        return 1;  /* already good to go. */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   175
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   176
    pGetDir = (fnGetUserProfDirW)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   177
        GetProcAddress(libUserEnv, "GetUserProfileDirectoryW");
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
   178
    BAIL_IF_MACRO(pGetDir == NULL, errcodeFromWinApi(), 0);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   179
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   180
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken))
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
   181
        BAIL_MACRO(errcodeFromWinApi(), 0);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   182
    else
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   183
    {
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   184
        DWORD psize = 0;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   185
        WCHAR dummy = 0;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   186
        LPWSTR wstr = NULL;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   187
        BOOL rc = 0;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   188
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   189
        /*
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   190
         * Should fail. Will write the size of the profile path in
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   191
         *  psize. Also note that the second parameter can't be
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   192
         *  NULL or the function fails.
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   193
         */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   194
    	rc = pGetDir(accessToken, &dummy, &psize);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   195
        assert(!rc);  /* !!! FIXME: handle this gracefully. */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   196
        (void) rc;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   197
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   198
        /* Allocate memory for the profile directory */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   199
        wstr = (LPWSTR) __PHYSFS_smallAlloc(psize * sizeof (WCHAR));
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   200
        if (wstr != NULL)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   201
        {
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   202
            if (pGetDir(accessToken, wstr, &psize))
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   203
                userDir = unicodeToUtf8Heap(wstr);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   204
            __PHYSFS_smallFree(wstr);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   205
        } /* if */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   206
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   207
        CloseHandle(accessToken);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   208
    } /* if */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   209
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   210
    return 1;  /* We made it: hit the showers. */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   211
} /* determineUserDir */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   212
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   213
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   214
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
   215
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   216
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
   217
{
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   218
    /* 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
   219
    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
   220
    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
   221
    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
   222
    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
   223
    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
   224
    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
   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
    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
   227
        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
   228
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   229
    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
   230
        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
   231
    else
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   232
        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
   233
    
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   234
    /* 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
   235
    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
   236
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   237
        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
   238
        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
   239
        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
   240
            continue;
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   241
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   242
        /* 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
   243
        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
   244
            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
   245
    } /* for */
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
    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
   248
        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
   249
    else
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   250
        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
   251
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   252
    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
   253
        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
   254
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 drives;
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   256
} /* pollDiscDrives */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   257
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   258
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   259
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
   260
                                        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
   261
{
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   262
    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
   263
    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
   264
    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
   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
    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
   267
        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
   268
    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
   269
             ((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
   270
             (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
   271
             ((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
   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
        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
   274
    } /* 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
   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
    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
   277
        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
   278
    else
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   279
        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
   280
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   281
    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
   282
} /* detectCDWndProc */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   283
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   284
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   285
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
   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
    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
   288
    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
   289
    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
   290
    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
   291
    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
   292
    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
   293
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   294
    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
   295
    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
   296
    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
   297
    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
   298
    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
   299
    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
   300
    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
   301
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   302
        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
   303
        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
   304
    } /* if */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   305
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   306
    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
   307
                        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
   308
                        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
   309
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   310
    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
   311
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   312
        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
   313
        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
   314
        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
   315
    } /* if */
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   316
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   317
    /* 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
   318
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   319
    /* 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
   320
    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
   321
    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
   322
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   323
    do
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   324
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   325
        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
   326
        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
   327
            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
   328
        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
   329
        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
   330
    } 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
   331
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   332
    /* 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
   333
    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
   334
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   335
    do
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   336
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   337
        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
   338
        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
   339
            break;
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   340
        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
   341
        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
   342
    } 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
   343
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   344
    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
   345
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   346
    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
   347
} /* detectCDThread */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   348
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   349
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   350
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
   351
{
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   352
    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
   353
    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
   354
    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
   355
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   356
    /*
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   357
     * 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
   358
     *  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
   359
     *  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
   360
     *  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
   361
     *  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
   362
     */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   363
    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
   364
    {
1217
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   365
        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
   366
        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
   367
        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
   368
            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
   369
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   370
        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
   371
            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
   372
    } /* if */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   373
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   374
    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
   375
    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
   376
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   377
        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
   378
        {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   379
            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
   380
            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
   381
        } /* if */
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   382
    } /* for */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   383
} /* __PHYSFS_platformDetectAvailableCDs */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   384
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   385
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   386
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
   387
{
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   388
    DWORD buflen = 64;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   389
    LPWSTR modpath = NULL;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   390
    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
   391
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   392
    while (1)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   393
    {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   394
        DWORD rc;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   395
        void *ptr;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   396
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   397
        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
   398
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   399
            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
   400
            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
   401
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   402
        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
   403
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   404
        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
   405
        if (rc == 0)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   406
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   407
            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
   408
            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
   409
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   410
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   411
        if (rc < buflen)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   412
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   413
            buflen = rc;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   414
            break;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   415
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   416
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   417
        buflen *= 2;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   418
    } /* while */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   419
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   420
    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
   421
    {
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   422
        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
   423
        while (ptr != modpath)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   424
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   425
            if (*ptr == '\\')
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   426
                break;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   427
            ptr--;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   428
        } /* while */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   429
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   430
        if ((ptr == modpath) && (*ptr != '\\'))
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   431
            __PHYSFS_setError(ERR_GETMODFN_NO_DIR);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   432
        else
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   433
        {
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   434
            *(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
   435
            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
   436
        } /* else */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   437
    } /* else */
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   438
    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
   439
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
   440
    return retval;   /* w00t. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
} /* __PHYSFS_platformCalcBaseDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
char *__PHYSFS_platformGetUserName(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   446
    DWORD bufsize = 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
   447
    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
   448
    
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   449
    if (GetUserNameW(NULL, &bufsize) == 0)  /* This SHOULD fail. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
    {
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
   451
        LPWSTR wbuf = (LPWSTR) __PHYSFS_smallAlloc(bufsize * sizeof (WCHAR));
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
   452
        BAIL_IF_MACRO(!wbuf, 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
   453
        if (GetUserNameW(wbuf, &bufsize) == 0)  /* ?! */
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
   454
            __PHYSFS_setError(errcodeFromWinApi());
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
   455
        else
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
   456
            retval = unicodeToUtf8Heap(wbuf);
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
   457
        __PHYSFS_smallFree(wbuf);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
    } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
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
   460
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
} /* __PHYSFS_platformGetUserName */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   466
    char *retval = (char *) allocator.Malloc(strlen(userDir) + 1);
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
   467
    BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   468
    strcpy(retval, userDir); /* calculated at init time. */
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
   469
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
1012
f254870dd7dd Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   473
void *__PHYSFS_platformGetThreadID(void)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
{
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
   475
    return ( (void *) ((size_t) GetCurrentThreadId()) );
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
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
   479
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
   480
{
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
   481
    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
   482
             (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
   483
} /* isSymlinkAttrs */
ad804f24633f Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents: 864
diff changeset
   484
ad804f24633f Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents: 864
diff changeset
   485
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   486
void __PHYSFS_platformEnumerateFiles(const char *dirname,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   487
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   488
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   489
                                     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
   490
                                     void *callbackdata)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
{
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
   492
    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
   493
    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
   494
    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
   495
    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
   496
    WCHAR *wSearchPath = NULL;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
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
   498
    /* 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
   499
    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
   500
    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
   501
        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
   502
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   503
    /* 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
   504
    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
   505
0f47386615f0 Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   506
    /* 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
   507
    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
   508
    {
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
        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
   510
        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
   511
    } /* 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
   512
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   513
    /* 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
   514
    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
   515
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
    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
   517
    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
   518
        return;  /* oh well. */
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   519
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   520
    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
   521
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
   522
    __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
   523
    __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
   524
    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
   525
        return;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   527
    do
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
        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
   530
        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
   531
        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
   532
        char *utf8;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   534
        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
   535
            continue;
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] == '.') && (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
   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 ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
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
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   567
    libUserEnv = LoadLibraryA("userenv.dll");
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
   568
    BAIL_IF_MACRO(libUserEnv == NULL, errcodeFromWinApi(), 0);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   569
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   570
    /* !!! FIXME: why do we precalculate this? */
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
   571
    BAIL_IF_MACRO(!determineUserDir(), ERRPASS, 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
   572
    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
   573
} /* __PHYSFS_platformInit */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   574
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   575
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   576
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
   577
{
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
   578
    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
   579
    {
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   580
        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
   581
            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
   582
        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
   583
        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
   584
        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
   585
        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
   586
    } /* if */
e38ffad216e8 Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   587
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   588
    if (libUserEnv)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   589
        FreeLibrary(libUserEnv);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   590
    libUserEnv = NULL;
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   591
    allocator.Free(userDir);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   592
    userDir = NULL;
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
   593
    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
   594
} /* __PHYSFS_platformDeinit */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   595
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   596
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   597
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
   598
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   599
    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
   600
    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
   601
    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
   602
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
   603
    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
   604
    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
   605
    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
   606
                             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
   607
    __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
   608
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
   609
    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
   610
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
   611
    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
   612
    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
   613
    {
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   614
        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
   615
        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
   616
    } /* if */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   617
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   618
    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
   619
    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
   620
    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
   621
} /* doOpen */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   622
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   623
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   624
void *__PHYSFS_platformOpenRead(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   625
{
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
   626
    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
   627
} /* __PHYSFS_platformOpenRead */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   628
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   629
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   630
void *__PHYSFS_platformOpenWrite(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   631
{
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
   632
    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
   633
} /* __PHYSFS_platformOpenWrite */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   634
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   635
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   636
void *__PHYSFS_platformOpenAppend(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   637
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   638
    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
   639
    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
   640
    {
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
   641
        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
   642
        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
   643
        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
   644
        {
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
   645
            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
   646
            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
   647
            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
   648
            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
   649
        } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   650
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   651
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
   652
    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
   653
} /* __PHYSFS_platformOpenAppend */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   654
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   655
1135
3b71a0c08665 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   656
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   657
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
   658
{
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
   659
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   660
    DWORD CountOfBytesRead = 0;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   661
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
   662
    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
   663
        BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1237
diff changeset
   664
    else if(!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL))
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1237
diff changeset
   665
        BAIL_MACRO(errcodeFromWinApi(), -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
   666
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   667
    return (PHYSFS_sint64) CountOfBytesRead;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   668
} /* __PHYSFS_platformRead */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   669
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   670
1135
3b71a0c08665 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   671
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */
310
f8bca4a93fd5 Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 275
diff changeset
   672
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
   673
                                     PHYSFS_uint64 len)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   674
{
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
   675
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   676
    DWORD CountOfBytesWritten = 0;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   677
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
   678
    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
   679
        BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1);
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1237
diff changeset
   680
    else if(!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL))
22d4d1bd4e21 Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 1237
diff changeset
   681
        BAIL_MACRO(errcodeFromWinApi(), -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
   682
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   683
    return (PHYSFS_sint64) CountOfBytesWritten;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   684
} /* __PHYSFS_platformWrite */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   685
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   686
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   687
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   688
{
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
   689
    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
   690
    LONG HighOrderPos;
45ad625f03bc Fixed compiler warnings in win32 API calls (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   691
    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
   692
    DWORD rc;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   693
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   694
    /* Get the high order 32-bits of the position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   695
    HighOrderPos = HIGHORDER_UINT64(pos);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   696
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   697
    /*
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   698
     * 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
   699
     *         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
   700
     */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   701
    pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   702
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   703
    /*
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   704
     * !!! FIXME: MSDN: "Windows Me/98/95:  If the pointer
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   705
     * !!! FIXME:  lpDistanceToMoveHigh is not NULL, then it must
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   706
     * !!! FIXME:  point to either 0, INVALID_SET_FILE_POINTER, or
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   707
     * !!! FIXME:  the sign extension of the value of lDistanceToMove.
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   708
     * !!! FIXME:  Any other value will be rejected."
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   709
     */
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
853
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   813
/*
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   814
 * !!! FIXME: why aren't we using Critical Sections instead of Mutexes?
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   815
 * !!! FIXME:  mutexes on Windows are for cross-process sync. CritSects are
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   816
 * !!! FIXME:  mutexes for threads in a single process and are faster.
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   817
 */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   818
void *__PHYSFS_platformCreateMutex(void)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   819
{
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
   820
    return ((void *) CreateMutex(NULL, FALSE, NULL));
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   821
} /* __PHYSFS_platformCreateMutex */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   822
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   823
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   824
void __PHYSFS_platformDestroyMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   825
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   826
    CloseHandle((HANDLE) mutex);
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
{
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
   832
    return (WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   833
} /* __PHYSFS_platformGrabMutex */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   834
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
void __PHYSFS_platformReleaseMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   837
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   838
    ReleaseMutex((HANDLE) mutex);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   839
} /* __PHYSFS_platformReleaseMutex */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   840
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   841
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   842
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
   843
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   844
    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
   845
    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
   846
    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
   847
    DWORD tzid;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   848
    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
   849
    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
   850
    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
   851
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
   852
    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
   853
    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
   854
    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
   855
    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
   856
    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
   857
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   858
    /* 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
   859
    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
   860
    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
   861
    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
   862
    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
   863
    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
   864
    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
   865
    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
   866
    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
   867
    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
   868
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   869
    /* 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
   870
    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
   871
    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
   872
    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
   873
} /* FileTimeToPhysfsTime */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   874
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   875
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   876
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   877
    WIN32_FILE_ATTRIBUTE_DATA winstat;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   878
    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
   879
    DWORD err = 0;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   880
    BOOL rc = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   881
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   882
    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
   883
    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
   884
    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
   885
    err = (!rc) ? GetLastError() : 0;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   886
    *exists = ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND));
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   887
    __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
   888
    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
   889
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   890
    stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   891
    stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   892
    stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   893
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   894
    if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   895
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   896
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   897
        stat->filesize = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   898
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   899
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   900
    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
   901
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   902
        /* !!! FIXME: what are reparse points? */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   903
        stat->filetype = PHYSFS_FILETYPE_OTHER;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   904
        /* !!! FIXME: don't rely on this */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   905
        stat->filesize = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   906
    } /* else if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   907
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   908
    /* !!! FIXME: check for symlinks on Vista. */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   909
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   910
    else
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   911
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   912
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
1055
8974a4a352fd Patched to compile (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   913
        stat->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
   914
    } /* else */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   915
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   916
    stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   917
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   918
    return 1;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   919
} /* __PHYSFS_platformStat */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   920
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   921
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   922
/* !!! 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
   923
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
   924
{
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
   925
    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
   926
} /* __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
   927
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
   928
#endif  /* PHYSFS_PLATFORM_WINDOWS */
327
76e207c6b4a7 Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 313
diff changeset
   929
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
   930
/* end of windows.c ... */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   931
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
   932