src/platform_windows.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 10 Mar 2012 03:07:30 -0500
changeset 1198 4cdb856021dd
parent 1180 b463fbb66af9
child 1208 3edcb015089a
permissions -rw-r--r--
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups. This brings the minimum required OS up to Windows XP, which is around 11 years old at this point.
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>
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    22
#include <errno.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    23
#include <ctype.h>
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
    24
#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
    25
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include "physfs_internal.h"
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
908
662ca06432ef Mingw32 fix for 64-bit literals.
Ryan C. Gordon <icculus@icculus.org>
parents: 906
diff changeset
    28
#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
    29
#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
    30
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    31
/*
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    32
 * 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
    33
 *  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
    34
 *  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
    35
 */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    36
#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    38
/* just in case... */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    39
#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
    40
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
    41
/* 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
    42
#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
    43
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
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    45
#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
    46
    if (str == NULL) \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    47
        w_assignto = NULL; \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    48
    else { \
915
1445c55cdbe6 Fixed allocation size when converting from UTF-8 to UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
    49
        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
    50
        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
    51
        if (w_assignto != 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
    52
            PHYSFS_utf8ToUcs2(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
    53
    } \
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
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    56
#ifndef _MSC_VER
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    57
#define _snprintf snprintf
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    58
#endif
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    59
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    60
/* !!! FIXME: this is wrong for UTF-16. */
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
    61
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
    62
{
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
    63
    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
    64
    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
    65
        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
    66
    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
    67
} /* 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
    68
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
    69
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
    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
    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
    72
    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
    73
    {
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
    74
        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
    75
        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
    76
        retval = allocator.Malloc(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
    77
        BAIL_IF_MACRO(retval == NULL, 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
    78
        /* !!! FIXME: utf-16. */
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
    79
        PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) w_str, retval, 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
    80
        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
    81
        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
    82
            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
    83
    } /* 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
    84
    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
    85
} /* 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
    86
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    87
/* !!! 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
    88
typedef struct
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    89
{
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    90
    HANDLE handle;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    91
    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
    92
} WinApiFile;
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    93
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
    94
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
    95
const char *__PHYSFS_platformDirSeparator = "\\";
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
    96
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
    97
static HANDLE libUserEnv = 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
    98
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
    99
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   100
/*
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
   101
 * Figure out what the last failing Windows API call was, and
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   102
 *  generate a human-readable string for the error message.
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   103
 *
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   104
 * The return value is a static buffer that is overwritten with
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   105
 *  each call to this function.
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   106
 */
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   107
static const char *winApiStrErrorByNum(const DWORD err)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
{
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
   109
    static char utf8buf[255];
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
   110
    WCHAR msgbuf[255];
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
   111
    WCHAR *ptr;
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   112
    DWORD rc = FormatMessageW(
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   113
                    FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   114
                    NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
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
   115
                    msgbuf, __PHYSFS_ARRAYLEN(msgbuf),
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
   116
                    NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
926
0b5b2af3200d Minor Windows fix (thanks, fydo!).
Ryan C. Gordon <icculus@icculus.org>
parents: 915
diff changeset
   118
    if (rc == 0)
0b5b2af3200d Minor Windows fix (thanks, fydo!).
Ryan C. Gordon <icculus@icculus.org>
parents: 915
diff changeset
   119
        msgbuf[0] = '\0';  /* oh well. */
0b5b2af3200d Minor Windows fix (thanks, fydo!).
Ryan C. Gordon <icculus@icculus.org>
parents: 915
diff changeset
   120
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   121
    /* chop off newlines. */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   122
    for (ptr = msgbuf; *ptr; ptr++)
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   123
    {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   124
        if ((*ptr == '\n') || (*ptr == '\r'))
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   125
        {
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
   126
            *ptr = '\0';
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   127
            break;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   128
        } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   129
    } /* for */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   130
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
   131
    /* may truncate, but oh well. */
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
   132
    PHYSFS_utf8FromUcs2((PHYSFS_uint16 *) msgbuf, utf8buf, sizeof (utf8buf));
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
   133
    return ((const char *) utf8buf);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   134
} /* winApiStrErrorByNum */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   135
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   136
static inline const char *winApiStrError(void)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   137
{
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   138
    return winApiStrErrorByNum(GetLastError());
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
   139
} /* winApiStrError */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   141
/*
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   142
 * 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
   143
 *  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
   144
 *  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
   145
 *  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
   146
 */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   147
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
   148
{
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   149
    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
   150
    fnGetUserProfDirW pGetDir = NULL;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   152
    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
   153
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   154
    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
   155
        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
   156
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   157
    pGetDir = (fnGetUserProfDirW)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   158
        GetProcAddress(libUserEnv, "GetUserProfileDirectoryW");
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   159
    BAIL_IF_MACRO(pGetDir == NULL, winApiStrError(), 0);
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
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken))
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   162
        BAIL_MACRO(winApiStrError(), 0);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   163
    else
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   164
    {
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   165
        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
   166
        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
   167
        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
   168
        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
   169
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   170
        /*
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   171
         * 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
   172
         *  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
   173
         *  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
   174
         */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   175
    	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
   176
        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
   177
        (void) rc;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   178
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   179
        /* 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
   180
        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
   181
        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
   182
        {
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   183
            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
   184
                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
   185
            __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
   186
        } /* if */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   187
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   188
        CloseHandle(accessToken);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   189
    } /* if */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   190
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   191
    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
   192
} /* determineUserDir */
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
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   195
static BOOL mediaInDrive(const char *drive)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   196
{
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   197
    UINT oldErrorMode;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   198
    DWORD tmp;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   199
    BOOL retval;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   200
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   201
    /* Prevent windows warning message appearing when checking media size */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   202
    /* !!! FIXME: Windows 7 offers SetThreadErrorMode(). */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   203
    oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   204
    
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   205
    /* If this function succeeds, there's media in the drive */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   206
    retval = GetVolumeInformationA(drive, NULL, 0, NULL, NULL, &tmp, NULL, 0);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   207
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   208
    /* Revert back to old windows error handler */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   209
    SetErrorMode(oldErrorMode);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   210
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   211
    return retval;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   212
} /* mediaInDrive */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   213
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   214
/*
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   215
 * !!! FIXME: move this to a thread? This function hangs if you call it while
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   216
 * !!! FIXME:  a drive is spinning up right after inserting a disc.
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   217
 */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   218
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
   219
{
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   220
    /* !!! FIXME: Can CD drives be non-drive letter paths? */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   221
    /* !!! FIXME:  (so can they be Unicode paths?) */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   222
    char drive_str[4] = "x:\\";
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   223
    char ch;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   224
    for (ch = 'A'; ch <= 'Z'; ch++)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   225
    {
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   226
        drive_str[0] = ch;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   227
        if (GetDriveTypeA(drive_str) == DRIVE_CDROM && mediaInDrive(drive_str))
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   228
            cb(data, drive_str);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   229
    } /* for */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   230
} /* __PHYSFS_platformDetectAvailableCDs */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   231
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   232
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   233
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
   234
{
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   235
    DWORD buflen = 64;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   236
    LPWSTR modpath = NULL;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   237
    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
   238
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   239
    while (1)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   240
    {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   241
        DWORD rc;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   242
        void *ptr;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   243
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   244
        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
   245
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   246
            allocator.Free(modpath);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   247
            BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   248
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   249
        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
   250
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   251
        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
   252
        if (rc == 0)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   253
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   254
            allocator.Free(modpath);
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
   255
            BAIL_MACRO(winApiStrError(), NULL);
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   256
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   257
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   258
        if (rc < buflen)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   259
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   260
            buflen = rc;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   261
            break;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   262
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   263
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   264
        buflen *= 2;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   265
    } /* while */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   266
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   267
    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
   268
    {
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   269
        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
   270
        while (ptr != modpath)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   271
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   272
            if (*ptr == '\\')
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   273
                break;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   274
            ptr--;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   275
        } /* while */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   276
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   277
        if ((ptr == modpath) && (*ptr != '\\'))
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   278
            __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
   279
        else
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   280
        {
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   281
            *(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
   282
            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
   283
        } /* else */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   284
    } /* else */
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   285
    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
   286
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
   287
    return retval;   /* w00t. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
} /* __PHYSFS_platformCalcBaseDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
char *__PHYSFS_platformGetUserName(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   293
    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
   294
    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
   295
    
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   296
    if (GetUserNameW(NULL, &bufsize) == 0)  /* This SHOULD fail. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    {
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
   298
        LPWSTR wbuf = (LPWSTR) __PHYSFS_smallAlloc(bufsize * sizeof (WCHAR));
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
   299
        BAIL_IF_MACRO(wbuf == NULL, 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
   300
        if (GetUserNameW(wbuf, &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
   301
            __PHYSFS_setError(winApiStrError());
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
   302
        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
   303
            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
   304
        __PHYSFS_smallFree(wbuf);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
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
   307
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
} /* __PHYSFS_platformGetUserName */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   313
    char *retval = (char *) allocator.Malloc(strlen(userDir) + 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
   314
    BAIL_IF_MACRO(retval == NULL, 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
   315
    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
   316
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
1012
f254870dd7dd Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   320
void *__PHYSFS_platformGetThreadID(void)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
{
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
   322
    return ( (void *) ((size_t) GetCurrentThreadId()) );
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
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
   326
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
   327
{
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
   328
    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
   329
             (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
   330
} /* isSymlinkAttrs */
ad804f24633f Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents: 864
diff changeset
   331
ad804f24633f Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents: 864
diff changeset
   332
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
char *__PHYSFS_platformCvtToDependent(const char *prepend,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
                                      const char *dirName,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
                                      const char *append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   337
    const int len = ((prepend) ? strlen(prepend) : 0) +
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
              ((append) ? strlen(append) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
              strlen(dirName) + 1;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   340
    char *retval = (char *) allocator.Malloc(len);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   341
    char *p;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   345
    _snprintf(retval, len, "%s%s%s",
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   346
              prepend ? prepend : "", dirName, append ? append : "");
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
        *p = '\\';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
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
   351
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
} /* __PHYSFS_platformCvtToDependent */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   355
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
   356
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   357
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   358
                                     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
   359
                                     void *callbackdata)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
{
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
   361
    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
   362
    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
   363
    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
   364
    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
   365
    WCHAR *wSearchPath = NULL;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
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
   367
    /* 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
   368
    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
   369
    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
   370
        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
   371
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   372
    /* 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
   373
    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
   374
0f47386615f0 Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   375
    /* 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
   376
    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
   377
    {
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
   378
        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
   379
        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
   380
    } /* 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
   381
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   382
    /* 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
   383
    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
   384
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
   385
    UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, 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
   386
    if (wSearchPath == 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
   387
        return;  /* oh well. */
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   388
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   389
    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
   390
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
   391
    __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
   392
    __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
   393
    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
   394
        return;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   396
    do
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    {
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   398
        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
   399
        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
   400
        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
   401
        char *utf8;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   403
        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
   404
            continue;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   405
        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
   406
            continue;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   407
        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
   408
            continue;
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   409
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   410
        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
   411
        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
   412
        {
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   413
            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
   414
            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
   415
        } /* if */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   416
    } while (FindNextFileW(dir, &entw) != 0);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    FindClose(dir);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
} /* __PHYSFS_platformEnumerateFiles */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
char *__PHYSFS_platformCurrentDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
{
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
   424
    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
   425
    WCHAR *wbuf = NULL;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   428
    buflen = GetCurrentDirectoryW(buflen, 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
   429
    wbuf = (WCHAR *) __PHYSFS_smallAlloc((buflen + 2) * sizeof (WCHAR));
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
   430
    BAIL_IF_MACRO(wbuf == NULL, 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
   431
    GetCurrentDirectoryW(buflen, wbuf);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   432
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
   433
    if (wbuf[buflen - 2] == '\\')
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   434
        wbuf[buflen - 1] = '\0';  /* just in case... */
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
    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
   436
    {
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
   437
        wbuf[buflen - 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
   438
        wbuf[buflen] = '\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
   439
    } /* else */
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   440
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
   441
    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
   442
    __PHYSFS_smallFree(wbuf);
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
   443
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
} /* __PHYSFS_platformCurrentDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   447
/* this could probably use a cleanup. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
char *__PHYSFS_platformRealPath(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   450
    /*
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   451
     * At this point, we only use this for the user and base dir,
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   452
     *  and we already know those are RealPath'd by the OS for us.
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   453
     */
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   454
    char *retval = (char *) allocator.Malloc(strlen(path) + 1);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   455
    BAIL_IF_MACRO(retval == NULL, 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
   456
    strcpy(retval, path);
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
   457
    return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
} /* __PHYSFS_platformRealPath */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
int __PHYSFS_platformMkDir(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
{
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
   463
    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
   464
    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
   465
    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
   466
    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
   467
    __PHYSFS_smallFree(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
   468
    BAIL_IF_MACRO(rc == 0, winApiStrError(), 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
   469
    return 1;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
} /* __PHYSFS_platformMkDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   472
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   473
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
   474
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   475
    libUserEnv = LoadLibraryA("userenv.dll");
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   476
    BAIL_IF_MACRO(libUserEnv == NULL, winApiStrError(), 0);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   477
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   478
    /* !!! FIXME: why do we precalculate this? */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   479
    BAIL_IF_MACRO(!determineUserDir(), NULL, 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
   480
    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
   481
} /* __PHYSFS_platformInit */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   482
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   483
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   484
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
   485
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   486
    if (libUserEnv)
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   487
        FreeLibrary(libUserEnv);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   488
    libUserEnv = NULL;
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   489
    allocator.Free(userDir);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   490
    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
   491
    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
   492
} /* __PHYSFS_platformDeinit */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   493
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   494
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   495
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
   496
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   497
    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
   498
    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
   499
    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
   500
861
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
   501
    UTF8_TO_UNICODE_STACK_MACRO(wfname, fname);
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
   502
    BAIL_IF_MACRO(wfname == NULL, 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
   503
    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
   504
                             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
   505
    __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
   506
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   507
    BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE,winApiStrError(), NULL);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
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
    retval = (WinApiFile *) allocator.Malloc(sizeof (WinApiFile));
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   510
    if (retval == 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
   511
    {
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   512
        CloseHandle(fileh);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   513
        BAIL_MACRO(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
   514
    } /* if */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   515
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   516
    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
   517
    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
   518
    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
   519
} /* doOpen */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   520
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   521
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   522
void *__PHYSFS_platformOpenRead(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   523
{
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
   524
    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
   525
} /* __PHYSFS_platformOpenRead */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   526
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   527
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   528
void *__PHYSFS_platformOpenWrite(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   529
{
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
   530
    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
   531
} /* __PHYSFS_platformOpenWrite */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   532
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   533
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   534
void *__PHYSFS_platformOpenAppend(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   535
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   536
    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
   537
    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
   538
    {
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
   539
        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
   540
        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
   541
        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
   542
        {
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
            const char *err = winApiStrError();
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   544
            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
   545
            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
   546
            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
   547
        } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   548
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   549
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
   550
    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
   551
} /* __PHYSFS_platformOpenAppend */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   552
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   553
1135
3b71a0c08665 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   554
/* !!! 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
   555
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
   556
{
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
   557
    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
   558
    DWORD CountOfBytesRead = 0;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   559
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   560
    BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   561
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   562
    if(!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, 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
   563
        BAIL_MACRO(winApiStrError(), -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
   564
    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
   565
} /* __PHYSFS_platformRead */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   566
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   567
1135
3b71a0c08665 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 1129
diff changeset
   568
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */
310
f8bca4a93fd5 Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 275
diff changeset
   569
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
   570
                                     PHYSFS_uint64 len)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   571
{
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
   572
    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
   573
    DWORD CountOfBytesWritten = 0;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   574
1098
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   575
    BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   576
4e86cec1143f Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1067
diff changeset
   577
    if(!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, 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
   578
        BAIL_MACRO(winApiStrError(), -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
   579
    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
   580
} /* __PHYSFS_platformWrite */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   581
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   582
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   583
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   584
{
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
   585
    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
   586
    LONG HighOrderPos;
45ad625f03bc Fixed compiler warnings in win32 API calls (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents: 926
diff changeset
   587
    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
   588
    DWORD rc;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   589
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   590
    /* Get the high order 32-bits of the position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   591
    HighOrderPos = HIGHORDER_UINT64(pos);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   592
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   593
    /*
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   594
     * 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
   595
     *         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
   596
     */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   597
    pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   598
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   599
    /*
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   600
     * !!! 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
   601
     * !!! 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
   602
     * !!! 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
   603
     * !!! 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
   604
     * !!! 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
   605
     */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   606
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   607
    /* 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
   608
    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
   609
                        pHighOrderPos, FILE_BEGIN);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   610
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   611
    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
   612
         (GetLastError() != NO_ERROR) )
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   613
    {
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
   614
        BAIL_MACRO(winApiStrError(), 0);
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   615
    } /* if */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   616
    
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
   617
    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
   618
} /* __PHYSFS_platformSeek */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   619
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   620
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   621
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   622
{
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
   623
    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
   624
    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
   625
    DWORD LowPos;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   626
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   627
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   628
    /* 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
   629
    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
   630
    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
   631
         (GetLastError() != NO_ERROR) )
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   632
    {
1180
b463fbb66af9 Corrected __PHYSFS_platformTell()'s return value to be correct.
Ryan C. Gordon <icculus@icculus.org>
parents: 1176
diff changeset
   633
        BAIL_MACRO(winApiStrError(), -1);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   634
    } /* 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
   635
    else
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   636
    {
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   637
        /* 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
   638
        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
   639
        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
   640
    } /* else */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   641
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 1012
diff changeset
   642
    return retval;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   643
} /* __PHYSFS_platformTell */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   644
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   645
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   646
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   647
{
861
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
   648
    HANDLE Handle = ((WinApiFile *) opaque)->handle;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   649
    DWORD SizeHigh;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   650
    DWORD SizeLow;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   651
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   652
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   653
    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
   654
    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
   655
         (GetLastError() != NO_ERROR) )
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   656
    {
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
   657
        BAIL_MACRO(winApiStrError(), -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
   658
    } /* 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
   659
    else
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   660
    {
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   661
        /* 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
   662
        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
   663
        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
   664
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   665
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
   666
    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
   667
} /* __PHYSFS_platformFileLength */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   668
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   669
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   670
int __PHYSFS_platformFlush(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   671
{
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
   672
    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
   673
    if (!fh->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
   674
        BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), winApiStrError(), 0);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   675
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
   676
    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
   677
} /* __PHYSFS_platformFlush */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   678
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   679
1118
2e09fc635fdd Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents: 1115
diff changeset
   680
void __PHYSFS_platformClose(void *opaque)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   681
{
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
   682
    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
   683
    (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
   684
    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
   685
} /* __PHYSFS_platformClose */
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
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
   688
static int doPlatformDelete(LPWSTR wpath)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   689
{
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   690
    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
   691
    const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   692
    BAIL_IF_MACRO(!rc, winApiStrError(), 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
   693
    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
   694
} /* 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
   695
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
   696
9b405bf6a95d Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents: 859
diff changeset
   697
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
   698
{
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
   699
    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
   700
    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
   701
    UTF8_TO_UNICODE_STACK_MACRO(wpath, 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
   702
    BAIL_IF_MACRO(wpath == NULL, ERR_OUT_OF_MEMORY, 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
   703
    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
   704
    __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
   705
    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
   706
} /* __PHYSFS_platformDelete */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   707
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   708
853
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   709
/*
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   710
 * !!! 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
   711
 * !!! 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
   712
 * !!! 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
   713
 */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   714
void *__PHYSFS_platformCreateMutex(void)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   715
{
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
   716
    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
   717
} /* __PHYSFS_platformCreateMutex */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   718
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   719
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   720
void __PHYSFS_platformDestroyMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   721
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   722
    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
   723
} /* __PHYSFS_platformDestroyMutex */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   724
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   725
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   726
int __PHYSFS_platformGrabMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   727
{
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
   728
    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
   729
} /* __PHYSFS_platformGrabMutex */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   730
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
void __PHYSFS_platformReleaseMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   733
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   734
    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
   735
} /* __PHYSFS_platformReleaseMutex */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   736
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   737
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   738
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
   739
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   740
    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
   741
    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
   742
    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
   743
    DWORD tzid;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   744
    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
   745
    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
   746
    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
   747
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
   748
    BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), winApiStrError(), -1);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   749
    tzid = GetTimeZoneInformation(&tzi);
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
   750
    BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, winApiStrError(), -1);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   751
    rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   752
    BAIL_IF_MACRO(!rc, winApiStrError(), -1);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   753
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   754
    /* 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
   755
    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
   756
    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
   757
    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
   758
    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
   759
    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
   760
    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
   761
    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
   762
    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
   763
    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
   764
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   765
    /* 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
   766
    retval = (PHYSFS_sint64) mktime(&tm);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   767
    BAIL_IF_MACRO(retval == -1, strerror(errno), -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
   768
    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
   769
} /* FileTimeToPhysfsTime */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   770
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   771
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
   772
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   773
    WIN32_FILE_ATTRIBUTE_DATA winstat;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   774
    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
   775
    DWORD err = 0;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   776
    BOOL rc = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   777
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   778
    UTF8_TO_UNICODE_STACK_MACRO(wstr, filename);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   779
    BAIL_IF_MACRO(wstr == NULL, ERR_OUT_OF_MEMORY, 0);
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   780
    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
   781
    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
   782
    *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
   783
    __PHYSFS_smallFree(wstr);
1198
4cdb856021dd Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 1180
diff changeset
   784
    BAIL_IF_MACRO(!rc, winApiStrErrorByNum(err), 0);
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   785
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   786
    stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   787
    stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   788
    stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   789
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   790
    if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   791
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   792
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   793
        stat->filesize = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   794
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   795
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   796
    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
   797
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   798
        /* !!! FIXME: what are reparse points? */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   799
        stat->filetype = PHYSFS_FILETYPE_OTHER;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   800
        /* !!! FIXME: don't rely on this */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   801
        stat->filesize = 0;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   802
    } /* else if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   803
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   804
    /* !!! FIXME: check for symlinks on Vista. */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   805
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   806
    else
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   807
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   808
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
1055
8974a4a352fd Patched to compile (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   809
        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
   810
    } /* else */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   811
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   812
    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
   813
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   814
    return 1;
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   815
} /* __PHYSFS_platformStat */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   816
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1053
diff changeset
   817
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   818
/* !!! 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
   819
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
   820
{
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
   821
    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
   822
} /* __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
   823
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
   824
#endif  /* PHYSFS_PLATFORM_WINDOWS */
327
76e207c6b4a7 Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 313
diff changeset
   825
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
   826
/* end of windows.c ... */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   827
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
   828