platform/windows.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 25 Mar 2007 06:26:53 +0000
changeset 859 7702965ac1f4
parent 858 969e69b2822f
child 861 9b405bf6a95d
permissions -rw-r--r--
Reworked getExePath() to remove some FIXMEs and respect Unicode.
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
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <windows.h>
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <stdio.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    16
#include <stdlib.h>
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    17
#include <string.h>
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    18
#include <errno.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    19
#include <ctype.h>
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
    20
#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
    21
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#include "physfs_internal.h"
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    24
#define LOWORDER_UINT64(pos) (PHYSFS_uint32) \
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    25
    (pos & 0x00000000FFFFFFFF)
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    26
#define HIGHORDER_UINT64(pos) (PHYSFS_uint32) \
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    27
    (((pos & 0xFFFFFFFF00000000) >> 32) & 0x00000000FFFFFFFF)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    28
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    29
/*
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    30
 * 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
    31
 *  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
    32
 *  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
    33
 */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    34
#define PHYSFS_INVALID_SET_FILE_POINTER  0xFFFFFFFF
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
    36
/* just in case... */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    37
#define PHYSFS_INVALID_FILE_ATTRIBUTES   0xFFFFFFFF
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    38
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    39
#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
    40
    if (str == NULL) \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    41
        w_assignto = NULL; \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    42
    else { \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    43
        const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    44
        w_assignto = (char *) __PHYSFS_smallAlloc(len); \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    45
        PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    46
    } \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    47
} \
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    48
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    49
typedef struct
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    50
{
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    51
    HANDLE handle;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    52
    int readonly;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    53
} win32file;
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
const char *__PHYSFS_platformDirSeparator = "\\";
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    56
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    57
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    58
/* pointers for APIs that may not exist on some Windows versions... */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    59
static HANDLE libKernel32 = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    60
static HANDLE libUserEnv = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    61
static HANDLE libAdvApi32 = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    62
static DWORD (WINAPI *pGetModuleFileNameA)(HMODULE, LPCH, DWORD);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    63
static DWORD (WINAPI *pGetModuleFileNameW)(HMODULE, LPWCH, DWORD);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    64
static BOOL (WINAPI *pGetUserProfileDirectoryW)(HANDLE, LPWSTR, LPDWORD);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    65
static BOOL (WINAPI *pGetUserNameW)(LPWSTR, LPDWORD);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    66
static DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    67
static HANDLE (WINAPI *pFindFirstFileW)(LPCWSTR, LPWIN32_FIND_DATAW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    68
static BOOL (WINAPI *pFindNextFileW)(HANDLE, LPWIN32_FIND_DATAW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    69
static DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD, LPWSTR);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    70
static BOOL (WINAPI *pDeleteFileW)(LPCWSTR);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    71
static BOOL (WINAPI *pRemoveDirectoryW)(LPCWSTR);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    72
static BOOL (WINAPI *pCreateDirectoryW)(LPCWSTR, LPSECURITY_ATTRIBUTES);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    73
static BOOL (WINAPI *pGetFileAttributesExA)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    74
    (LPCSTR, GET_FILEEX_INFO_LEVELS, LPVOID);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    75
static BOOL (WINAPI *pGetFileAttributesExW)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    76
    (LPCWSTR, GET_FILEEX_INFO_LEVELS, LPVOID);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    77
static DWORD (WINAPI *pFormatMessageW)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    78
    (DWORD, LPCVOID, DWORD, DWORD, LPWSTR, DWORD, va_list *);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    79
static DWORD (WINAPI *pSearchPathW)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    80
    (LPCWSTR, LPCWSTR, LPCWSTR, DWORD, LPWSTR, LPWSTR *);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    81
static HANDLE (WINAPI *pCreateFileW)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    82
    (LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    83
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    84
static char *userDir = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    85
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    86
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    87
/* A blatant abuse of pointer casting... */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    88
static void symLookup(HMODULE dll, void **addr, const char *sym)
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
    *addr = GetProcAddress(dll, sym);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    91
} /* symLookup */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    92
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    93
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    94
static int findApiSymbols(void)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    95
{
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    96
    HMODULE dll = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    97
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    98
    #define LOOKUP(x) { symLookup(dll, (void **) &p##x, #x); }
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
    99
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   100
    dll = libUserEnv = LoadLibrary("userenv.dll");
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   101
    if (dll != NULL)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   102
        LOOKUP(GetUserProfileDirectoryW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   103
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   104
    /* !!! FIXME: what do they call advapi32.dll on Win64? */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   105
    dll = libAdvApi32 = LoadLibrary("advapi32.dll");
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   106
    if (dll != NULL)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   107
        LOOKUP(GetUserNameW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   108
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   109
    /* !!! FIXME: what do they call kernel32.dll on Win64? */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   110
    dll = libKernel32 = LoadLibrary("kernel32.dll");
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   111
    if (dll != NULL)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   112
    {
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   113
        LOOKUP(GetModuleFileNameA);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   114
        LOOKUP(GetModuleFileNameW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   115
        LOOKUP(FormatMessageW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   116
        LOOKUP(FindFirstFileW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   117
        LOOKUP(FindNextFileW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   118
        LOOKUP(GetFileAttributesW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   119
        LOOKUP(GetFileAttributesExA);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   120
        LOOKUP(GetFileAttributesExW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   121
        LOOKUP(GetCurrentDirectoryW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   122
        LOOKUP(CreateDirectoryW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   123
        LOOKUP(RemoveDirectoryW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   124
        LOOKUP(CreateFileW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   125
        LOOKUP(DeleteFileW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   126
        LOOKUP(SearchPathW);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   127
    } /* if */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   128
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   129
    #undef LOOKUP
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   130
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   131
    return(1);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   132
} /* findApiSymbols */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   133
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   134
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   135
/*
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   136
 * Figure out what the last failing Win32 API call was, and
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   137
 *  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
   138
 *
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   139
 * 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
   140
 *  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
   141
 */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
static const char *win32strerror(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   144
    static TCHAR msgbuf[255];
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   145
    TCHAR *ptr = msgbuf;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   147
    /* !!! FIXME: unicode version. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    FormatMessage(
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        FORMAT_MESSAGE_FROM_SYSTEM |
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        FORMAT_MESSAGE_IGNORE_INSERTS,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        NULL,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
        GetLastError(),
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   153
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   154
        msgbuf,
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   155
        sizeof (msgbuf) / sizeof (TCHAR),
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
        NULL 
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    );
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   159
    /* 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
   160
    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
   161
    {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   162
        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
   163
        {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   164
            *ptr = ' ';
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   165
            break;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   166
        } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   167
    } /* for */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   168
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   169
    /* !!! FIXME: convert to UTF-8. */
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   170
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   171
    return((const char *) msgbuf);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
} /* win32strerror */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   175
static char *getExePath(void)
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   176
{
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   177
    DWORD buflen = 64;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   178
    int success = 0;
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   179
    LPWSTR modpath = NULL;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   180
    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
   181
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   182
    while (1)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   183
    {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   184
        DWORD rc;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   185
        void *ptr;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   186
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   187
        if ( !(ptr = allocator.Realloc(modpath, buflen*sizeof(WCHAR))) )
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   188
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   189
            allocator.Free(modpath);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   190
            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
   191
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   192
        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
   193
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   194
        rc = pGetModuleFileNameW(NULL, modpath, buflen);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   195
        if (rc == 0)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   196
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   197
            allocator.Free(modpath);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   198
            BAIL_MACRO(win32strerror(), NULL);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   199
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   200
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   201
        if (rc < buflen)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   202
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   203
            buflen = rc;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   204
            break;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   205
        } /* if */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   206
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   207
        buflen *= 2;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   208
    } /* while */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   209
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   210
    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
   211
    {
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   212
        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
   213
        while (ptr != modpath)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   214
        {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   215
            if (*ptr == '\\')
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   216
                break;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   217
            ptr--;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   218
        } /* while */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   219
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   220
        if ((ptr == modpath) && (*ptr != '\\'))
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   221
            __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
   222
        else
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   223
        {
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   224
            *(ptr + 1) = '\0';  /* chop off filename. */
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   225
            retval = (char *) allocator.Malloc(buflen * 6);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   226
            if (retval == NULL)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   227
                __PHYSFS_setError(ERR_OUT_OF_MEMORY);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   228
            else
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   229
                PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) modpath, retval, buflen * 6);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   230
        } /* else */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   231
    } /* else */
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   232
    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
   233
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   234
    /* free up the bytes we didn't actually use. */
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   235
    if (retval != NULL)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   236
    {
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   237
        void *ptr = allocator.Realloc(retval, strlen(retval) + 1);
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   238
        if (ptr != NULL)
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   239
            retval = (char *) ptr;
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   240
    } /* if */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   241
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   242
    return(retval);   /* w00t. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   243
} /* getExePath */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   244
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   245
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   246
/*
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   247
 * Try to make use of GetUserProfileDirectoryW(), which isn't available on
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   248
 *  some common variants of Win32. If we can't use this, we just punt and
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   249
 *  use the physfs base dir for the user dir, too.
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   250
 *
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   251
 * On success, module-scope variable (userDir) will have a pointer to
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   252
 *  a malloc()'d string of the user's profile dir, and a non-zero value is
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   253
 *  returned. If we can't determine the profile dir, (userDir) will
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   254
 *  be NULL, and zero is returned.
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   255
 */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   256
static int determineUserDir(void)
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   257
{
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   258
    if (userDir != NULL)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   259
        return(1);  /* already good to go. */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   260
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   261
    /*
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   262
     * GetUserProfileDirectoryW() is only available on NT 4.0 and later.
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   263
     *  This means Win95/98/ME (and CE?) users have to do without, so for
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   264
     *  them, we'll default to the base directory when we can't get the
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   265
     *  function pointer. Since this is originally an NT API, we don't
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   266
	 *  offer a non-Unicode fallback.
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   267
     */
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   268
    if (pGetUserProfileDirectoryW != NULL)
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   269
    {
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   270
        HANDLE accessToken = NULL;       /* Security handle to process */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   271
        HANDLE processHandle = GetCurrentProcess();
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   272
        if (OpenProcessToken(processHandle, TOKEN_QUERY, &accessToken))
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   273
        {
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   274
            DWORD psize = 0;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   275
            WCHAR dummy = 0;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   276
            LPWSTR wstr = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   277
            BOOL rc = 0;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   278
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   279
            /*
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   280
             * Should fail. Will write the size of the profile path in
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   281
             *  psize. Also note that the second parameter can't be
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   282
             *  NULL or the function fails.
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   283
             */	
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   284
    		rc = pGetUserProfileDirectoryW(accessToken, &dummy, &psize);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   285
            assert(!rc);  /* !!! FIXME: handle this gracefully. */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   286
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   287
            /* Allocate memory for the profile directory */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   288
            wstr = (LPWSTR) __PHYSFS_smallAlloc(psize * sizeof (WCHAR));
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   289
            if (wstr != NULL)
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   290
            {
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   291
                if (pGetUserProfileDirectoryW(accessToken, wstr, &psize))
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   292
                {
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   293
                    const PHYSFS_uint64 buflen = psize * 6;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   294
                    userDir = (char *) allocator.Malloc(buflen);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   295
                    if (userDir != NULL)  
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   296
                        PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) wstr, userDir, buflen);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   297
                    /* !!! FIXME: shrink allocation... */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   298
                } /* if */
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   299
                __PHYSFS_smallFree(wstr);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   300
            } /* else */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   301
        } /* if */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   302
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   303
        CloseHandle(accessToken);
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   304
    } /* if */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   305
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   306
    if (userDir == NULL)  /* couldn't get profile for some reason. */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   307
    {
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   308
        /* Might just be a non-NT system; resort to the basedir. */
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   309
        userDir = getExePath();
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   310
        BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* STILL failed?! */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   311
    } /* if */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   312
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   313
    return(1);  /* We made it: hit the showers. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   314
} /* determineUserDir */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   315
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   316
338
4f6d300bf1d7 Changed CD-ROM detection code to be compatible with Windows NT 3.x.
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   317
static BOOL mediaInDrive(const char *drive)
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   318
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   319
    UINT oldErrorMode;
338
4f6d300bf1d7 Changed CD-ROM detection code to be compatible with Windows NT 3.x.
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   320
    DWORD tmp;
4f6d300bf1d7 Changed CD-ROM detection code to be compatible with Windows NT 3.x.
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   321
    BOOL 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
   322
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   323
    /* Prevent windows warning message appearing when checking media size */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   324
    oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   325
    
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   326
    /* If this function succeeds, there's media in the drive */
338
4f6d300bf1d7 Changed CD-ROM detection code to be compatible with Windows NT 3.x.
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   327
    retval = GetVolumeInformation(drive, NULL, 0, NULL, NULL, &tmp, NULL, 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
   328
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   329
    /* Revert back to old windows error handler */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   330
    SetErrorMode(oldErrorMode);
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   331
338
4f6d300bf1d7 Changed CD-ROM detection code to be compatible with Windows NT 3.x.
Ryan C. Gordon <icculus@icculus.org>
parents: 335
diff changeset
   332
    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
   333
} /* mediaInDrive */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   334
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   335
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   336
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
{
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   338
    /* !!! FIXME: Can CD drives be non-drive letter paths? */
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   339
    /* !!! FIXME:  (so can they be Unicode paths?) */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
    char drive_str[4] = "x:\\";
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   341
    char ch;
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   342
    for (ch = 'A'; ch <= 'Z'; ch++)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   344
        drive_str[0] = ch;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   345
        if (GetDriveType(drive_str) == DRIVE_CDROM && mediaInDrive(drive_str))
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   346
            cb(data, drive_str);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    } /* for */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   348
} /* __PHYSFS_platformDetectAvailableCDs */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
111
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   351
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   352
{
568
58a750d64f91 Fixed crash if PHYSFS_init(NULL) is used...
Ryan C. Gordon <icculus@icculus.org>
parents: 516
diff changeset
   353
    if ((argv0 != NULL) && (strchr(argv0, '\\') != NULL))
58a750d64f91 Fixed crash if PHYSFS_init(NULL) is used...
Ryan C. Gordon <icculus@icculus.org>
parents: 516
diff changeset
   354
        return(NULL); /* default behaviour can handle this. */
111
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   355
859
7702965ac1f4 Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   356
    return(getExePath());
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
} /* __PHYSFS_platformCalcBaseDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
char *__PHYSFS_platformGetUserName(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   362
    DWORD bufsize = 0;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
    LPTSTR retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   365
    /* !!! FIXME: unicode version. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
    if (GetUserName(NULL, &bufsize) == 0)  /* This SHOULD fail. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   368
        retval = (LPTSTR) allocator.Malloc(bufsize);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
        BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   370
        /* !!! FIXME: unicode version. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
        if (GetUserName(retval, &bufsize) == 0)  /* ?! */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
        {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   373
            __PHYSFS_setError(win32strerror());
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   374
            allocator.Free(retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
            retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
    } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   379
    if (retval != NULL)
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   380
    {
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   381
        /* !!! FIXME: convert to UTF-8. */
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   382
    } /* if */
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   383
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
} /* __PHYSFS_platformGetUserName */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   390
    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
   391
    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
   392
    strcpy(retval, userDir); /* calculated at init time. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   393
    return(retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   397
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   399
    return((PHYSFS_uint64) GetCurrentThreadId());
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
int __PHYSFS_platformExists(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
{
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   405
    BAIL_IF_MACRO
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   406
    (
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   407
        /* !!! FIXME: unicode version. */
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   408
        GetFileAttributes(fname) == PHYSFS_INVALID_FILE_ATTRIBUTES,
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   409
        win32strerror(), 0
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   410
    );
467
99664d9842cb Bunch of tedious corrections, optimizations, and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 448
diff changeset
   411
    return(1);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
} /* __PHYSFS_platformExists */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
int __PHYSFS_platformIsSymLink(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
{
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   417
    /* !!! FIXME: Vista has symlinks. Recheck this. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    return(0);  /* no symlinks on win32. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
} /* __PHYSFS_platformIsSymlink */
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
int __PHYSFS_platformIsDirectory(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
{
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   424
    /* !!! FIXME: unicode version. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    return((GetFileAttributes(fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
} /* __PHYSFS_platformIsDirectory */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
char *__PHYSFS_platformCvtToDependent(const char *prepend,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
                                      const char *dirName,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
                                      const char *append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    int len = ((prepend) ? strlen(prepend) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
              ((append) ? strlen(append) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
              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
   436
    char *retval = (char *) allocator.Malloc(len);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   437
    char *p;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
    if (prepend)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
        strcpy(retval, prepend);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
        retval[0] = '\0';
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
    strcat(retval, dirName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
    if (append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
        strcat(retval, append);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
        *p = '\\';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
} /* __PHYSFS_platformCvtToDependent */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   458
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
   459
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   460
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   461
                                     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
   462
                                     void *callbackdata)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
    HANDLE dir;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
    WIN32_FIND_DATA ent;
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   466
    size_t len = strlen(dirname);
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   467
    char *SearchPath;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
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
   469
    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
852
9467e96abdf1 Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   470
    SearchPath = (char *) __PHYSFS_smallAlloc(len + 3);
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   471
    if (SearchPath == NULL)
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   472
        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
   473
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   474
    /* Copy current dirname */
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   475
    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
   476
0f47386615f0 Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   477
    /* if there's no '\\' at the end of the path, stick one in there. */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   478
    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
   479
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   480
        SearchPath[len++] = '\\';
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   481
        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
   482
    } /* 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
   483
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   484
    /* Append the "*" to the end of the string */
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   485
    strcat(SearchPath, "*");
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   486
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   487
    /* !!! FIXME: unicode version. */
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   488
    dir = FindFirstFile(SearchPath, &ent);
852
9467e96abdf1 Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   489
    __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
   490
    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
   491
        return;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
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
   493
    do
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    {
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   495
        /* !!! FIXME: unicode version. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
        if (strcmp(ent.cFileName, ".") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   499
        /* !!! FIXME: unicode version. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
        if (strcmp(ent.cFileName, "..") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 748
diff changeset
   503
        callback(callbackdata, origdir, ent.cFileName);
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   504
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   505
        /* !!! FIXME: unicode version. */
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
   506
    } while (FindNextFile(dir, &ent) != 0);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
    FindClose(dir);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
} /* __PHYSFS_platformEnumerateFiles */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
char *__PHYSFS_platformCurrentDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   514
    LPTSTR retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   517
    /* !!! FIXME: unicode version. */
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   518
    buflen = GetCurrentDirectory(buflen, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   519
    retval = (LPTSTR) allocator.Malloc(sizeof (TCHAR) * (buflen + 2));
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   520
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   521
    /* !!! FIXME: unicode version. */
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   522
    GetCurrentDirectory(buflen, retval);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   523
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   524
    if (retval[buflen - 2] != '\\')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   525
        strcat(retval, "\\");
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   526
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
} /* __PHYSFS_platformCurrentDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   531
/* this could probably use a cleanup. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
char *__PHYSFS_platformRealPath(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
{
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   534
    /* this function should be UTF-8 clean. */
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   535
    char *retval = NULL;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   536
    char *p = NULL;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   537
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   538
    BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   539
    BAIL_IF_MACRO(*path == '\0', ERR_INVALID_ARGUMENT, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   540
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   541
    retval = (char *) allocator.Malloc(MAX_PATH);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   542
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   543
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   544
        /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   545
         * If in \\server\path format, it's already an absolute path.
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   546
         *  We'll need to check for "." and ".." dirs, though, just in case.
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   547
         */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   548
    if ((path[0] == '\\') && (path[1] == '\\'))
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   549
        strcpy(retval, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   550
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   551
    else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   552
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   553
        char *currentDir = __PHYSFS_platformCurrentDir();
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   554
        if (currentDir == NULL)
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   555
        {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   556
            allocator.Free(retval);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   557
            BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   558
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   559
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   560
        if (path[1] == ':')   /* drive letter specified? */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   561
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   562
            /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   563
             * Apparently, "D:mypath" is the same as "D:\\mypath" if
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   564
             *  D: is not the current drive. However, if D: is the
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   565
             *  current drive, then "D:mypath" is a relative path. Ugh.
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   566
             */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   567
            if (path[2] == '\\')  /* maybe an absolute path? */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   568
                strcpy(retval, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   569
            else  /* definitely an absolute path. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   570
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   571
                if (path[0] == currentDir[0]) /* current drive; relative. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   572
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   573
                    strcpy(retval, currentDir);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   574
                    strcat(retval, path + 2);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   575
                } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   576
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   577
                else  /* not current drive; absolute. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   578
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   579
                    retval[0] = path[0];
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   580
                    retval[1] = ':';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   581
                    retval[2] = '\\';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   582
                    strcpy(retval + 3, path + 2);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   583
                } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   584
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   585
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   586
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   587
        else  /* no drive letter specified. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   588
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   589
            if (path[0] == '\\')  /* absolute path. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   590
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   591
                retval[0] = currentDir[0];
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   592
                retval[1] = ':';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   593
                strcpy(retval + 2, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   594
            } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   595
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   596
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   597
                strcpy(retval, currentDir);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   598
                strcat(retval, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   599
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   600
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   601
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   602
        allocator.Free(currentDir);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   603
    } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   604
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   605
    /* (whew.) Ok, now take out "." and ".." path entries... */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   606
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   607
    p = retval;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   608
    while ( (p = strstr(p, "\\.")) != NULL)
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   609
    {
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   610
        /* it's a "." entry that doesn't end the string. */
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   611
        if (p[2] == '\\')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   612
            memmove(p + 1, p + 3, strlen(p + 3) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   613
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   614
        /* it's a "." entry that ends the string. */
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   615
        else if (p[2] == '\0')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   616
            p[0] = '\0';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   617
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   618
        /* it's a ".." entry. */
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   619
        else if (p[2] == '.')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   620
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   621
            char *prevEntry = p - 1;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   622
            while ((prevEntry != retval) && (*prevEntry != '\\'))
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   623
                prevEntry--;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   624
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   625
            if (prevEntry == retval)  /* make it look like a "." entry. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   626
                memmove(p + 1, p + 2, strlen(p + 2) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   627
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   628
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   629
                if (p[3] != '\0') /* doesn't end string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   630
                    *prevEntry = '\0';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   631
                else /* ends string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   632
                    memmove(prevEntry + 1, p + 4, strlen(p + 4) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   633
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   634
                p = prevEntry;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   635
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   636
        } /* else if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   637
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   638
        else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   639
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   640
            p++;  /* look past current char. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   641
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   642
    } /* while */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   643
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   644
    /* shrink the retval's memory block if possible... */
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   645
    p = (char *) allocator.Realloc(retval, strlen(retval) + 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
   646
    if (p != NULL)
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   647
        retval = p;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   648
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   649
    return(retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
} /* __PHYSFS_platformRealPath */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
int __PHYSFS_platformMkDir(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
{
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   655
    /* !!! FIXME: unicode version. */
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   656
    DWORD rc = CreateDirectory(path, NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
    BAIL_IF_MACRO(rc == 0, win32strerror(), 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
    return(1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
} /* __PHYSFS_platformMkDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   661
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   662
/*
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   663
 * Get OS info and save the important parts.
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   664
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   665
 * Returns non-zero if successful, otherwise it returns zero on failure.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   666
 */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   667
static int getOSInfo(void)
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   668
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   669
#if 0  /* we don't actually use this at the moment, but may in the future. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   670
    OSVERSIONINFO OSVersionInfo;     /* Information about the OS */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   671
    OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   672
    BAIL_IF_MACRO(!GetVersionEx(&OSVersionInfo), win32strerror(), 0);
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   673
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   674
    /* Set to TRUE if we are runnign a WinNT based OS 4.0 or greater */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   675
    runningNT = ((OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   676
                 (OSVersionInfo.dwMajorVersion >= 4));
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   677
#endif
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   678
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   679
    return(1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   680
} /* getOSInfo */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   681
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   682
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   683
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
   684
{
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   685
    BAIL_IF_MACRO(!findApiSymbols(), NULL, 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
   686
    BAIL_IF_MACRO(!getOSInfo(), NULL, 0);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   687
    BAIL_IF_MACRO(!determineUserDir(), NULL, 0);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   688
    return(1);  /* It's all good */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   689
} /* __PHYSFS_platformInit */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   690
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   691
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   692
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
   693
{
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   694
    HANDLE *libs[] = { &libKernel32, &libUserEnv, &libAdvApi32, NULL };
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   695
    int i;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   696
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   697
    allocator.Free(userDir);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   698
    userDir = NULL;
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   699
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   700
    for (i = 0; libs[i] != NULL; i++)
313
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
   701
    {
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   702
        const HANDLE lib = *(libs[i]);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   703
        if (lib)
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   704
            FreeLibrary(lib);
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   705
        *(libs[i]) = NULL;
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
   706
    } /* for */
313
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
   707
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   708
    return(1); /* It's all good */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   709
} /* __PHYSFS_platformDeinit */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   710
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   711
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   712
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
   713
{
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   714
    HANDLE fileHandle;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   715
    win32file *retval;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   716
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   717
    /* !!! FIXME: unicode version. */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   718
    fileHandle = CreateFile(fname, mode, FILE_SHARE_READ, NULL,
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   719
                            creation, FILE_ATTRIBUTE_NORMAL, NULL);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   720
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   721
    BAIL_IF_MACRO
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   722
    (
615
53f0d8be2b39 Fixed search-and-replace fuckup (thanks, Brian!).
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   723
        fileHandle == INVALID_HANDLE_VALUE,
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   724
        win32strerror(), NULL
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   725
    );
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   726
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   727
    retval = (win32file *) allocator.Malloc(sizeof (win32file));
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   728
    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
   729
    {
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   730
        CloseHandle(fileHandle);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   731
        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
   732
    } /* if */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
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
    retval->readonly = rdonly;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   735
    retval->handle = fileHandle;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   736
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   737
} /* doOpen */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   738
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   739
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   740
void *__PHYSFS_platformOpenRead(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   741
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   742
    return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1));
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   743
} /* __PHYSFS_platformOpenRead */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   744
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   745
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   746
void *__PHYSFS_platformOpenWrite(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   747
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   748
    return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0));
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   749
} /* __PHYSFS_platformOpenWrite */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   750
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   751
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   752
void *__PHYSFS_platformOpenAppend(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   753
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   754
    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
   755
    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
   756
    {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   757
        HANDLE h = ((win32file *) retval)->handle;
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   758
        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
   759
        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
   760
        {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   761
            const char *err = win32strerror();
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   762
            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
   763
            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
   764
            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
   765
        } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   766
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   767
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   768
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   769
} /* __PHYSFS_platformOpenAppend */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   770
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   771
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   772
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   773
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   774
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   775
    HANDLE Handle = ((win32file *) opaque)->handle;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   776
    DWORD CountOfBytesRead;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   777
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   778
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   779
    /* Read data from the file */
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 327
diff changeset
   780
    /* !!! FIXME: uint32 might be a greater # than DWORD */
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   781
    if(!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL))
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   782
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   783
        BAIL_MACRO(win32strerror(), -1);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   784
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   785
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   786
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   787
        /* Return the number of "objects" read. */
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 327
diff changeset
   788
        /* !!! FIXME: What if not the right amount of bytes was read to make an object? */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   789
        retval = CountOfBytesRead / size;
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   790
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   791
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   792
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   793
} /* __PHYSFS_platformRead */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   794
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   795
310
f8bca4a93fd5 Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents: 275
diff changeset
   796
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   797
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   798
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   799
    HANDLE Handle = ((win32file *) opaque)->handle;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   800
    DWORD CountOfBytesWritten;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   801
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   802
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   803
    /* Read data from the file */
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 327
diff changeset
   804
    /* !!! FIXME: uint32 might be a greater # than DWORD */
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   805
    if(!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL))
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   806
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   807
        BAIL_MACRO(win32strerror(), -1);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   808
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   809
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   810
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   811
        /* Return the number of "objects" read. */
335
1d4720c018c3 FIXME cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 327
diff changeset
   812
        /* !!! FIXME: What if not the right number of bytes was written? */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   813
        retval = CountOfBytesWritten / size;
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   814
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   815
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   816
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   817
} /* __PHYSFS_platformWrite */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   818
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   819
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   820
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   821
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   822
    HANDLE Handle = ((win32file *) opaque)->handle;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   823
    DWORD HighOrderPos;
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   824
    DWORD *pHighOrderPos;
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   825
    DWORD rc;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   826
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   827
    /* Get the high order 32-bits of the position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   828
    HighOrderPos = HIGHORDER_UINT64(pos);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   829
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   830
    /*
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   831
     * 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
   832
     *         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
   833
     */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   834
    pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   835
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   836
    /*
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   837
     * !!! 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
   838
     * !!! 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
   839
     * !!! 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
   840
     * !!! 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
   841
     * !!! 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
   842
     */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   843
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   844
    /* 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
   845
    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
   846
                        pHighOrderPos, FILE_BEGIN);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   847
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   848
    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
   849
         (GetLastError() != NO_ERROR) )
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   850
    {
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   851
        BAIL_MACRO(win32strerror(), 0);
606
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   852
    } /* if */
70cf47819dd2 Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   853
    
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   854
    return(1);  /* No error occured */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   855
} /* __PHYSFS_platformSeek */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   856
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   857
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   858
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   859
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   860
    HANDLE Handle = ((win32file *) 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
   861
    DWORD HighPos = 0;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   862
    DWORD LowPos;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   863
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   864
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   865
    /* 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
   866
    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
   867
    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
   868
         (GetLastError() != NO_ERROR) )
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   869
    {
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   870
        BAIL_MACRO(win32strerror(), 0);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   871
    } /* 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
   872
    else
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   873
    {
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   874
        /* 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
   875
        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
   876
        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
   877
    } /* else */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   878
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   879
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   880
} /* __PHYSFS_platformTell */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   881
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   882
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   883
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   884
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   885
    HANDLE Handle = ((win32file *) 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
   886
    DWORD SizeHigh;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   887
    DWORD SizeLow;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   888
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   889
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   890
    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
   891
    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
   892
         (GetLastError() != NO_ERROR) )
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   893
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   894
        BAIL_MACRO(win32strerror(), -1);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   895
    } /* 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
   896
    else
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   897
    {
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   898
        /* 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
   899
        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
   900
        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
   901
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   902
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   903
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   904
} /* __PHYSFS_platformFileLength */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   905
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   906
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   907
int __PHYSFS_platformEOF(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   908
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   909
    PHYSFS_sint64 FilePosition;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   910
    int retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   911
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   912
    /* Get the current position in the file */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   913
    if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   914
    {
211
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   915
        /* Non-zero if EOF is equal to the file length */
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   916
        retval = FilePosition == __PHYSFS_platformFileLength(opaque);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   917
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   918
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   919
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   920
} /* __PHYSFS_platformEOF */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   921
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   922
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   923
int __PHYSFS_platformFlush(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   924
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   925
    win32file *fh = ((win32file *) opaque);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   926
    if (!fh->readonly)
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   927
        BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   928
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   929
    return(1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   930
} /* __PHYSFS_platformFlush */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   931
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   932
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   933
int __PHYSFS_platformClose(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   934
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   935
    HANDLE Handle = ((win32file *) opaque)->handle;
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 615
diff changeset
   936
    BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   937
    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
   938
    return(1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   939
} /* __PHYSFS_platformClose */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   940
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   941
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   942
int __PHYSFS_platformDelete(const char *path)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   943
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   944
    /* If filename is a folder */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   945
    if (GetFileAttributes(path) == FILE_ATTRIBUTE_DIRECTORY)
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   946
    {
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   947
        /* !!! FIXME: unicode version. */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   948
        BAIL_IF_MACRO(!RemoveDirectory(path), win32strerror(), 0);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   949
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   950
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   951
    {
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
   952
        /* !!! FIXME: unicode version. */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   953
        BAIL_IF_MACRO(!DeleteFile(path), win32strerror(), 0);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   954
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   955
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   956
    return(1);  /* if you got here, it worked. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   957
} /* __PHYSFS_platformDelete */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   958
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   959
853
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   960
/*
8df352657911 Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 852
diff changeset
   961
 * !!! 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
   962
 * !!! 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
   963
 * !!! 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
   964
 */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   965
void *__PHYSFS_platformCreateMutex(void)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   966
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   967
    return((void *) CreateMutex(NULL, FALSE, NULL));
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   968
} /* __PHYSFS_platformCreateMutex */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   969
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   970
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   971
void __PHYSFS_platformDestroyMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   972
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   973
    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
   974
} /* __PHYSFS_platformDestroyMutex */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   975
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   976
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   977
int __PHYSFS_platformGrabMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   978
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   979
    return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   980
} /* __PHYSFS_platformGrabMutex */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   981
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   982
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   983
void __PHYSFS_platformReleaseMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   984
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   985
    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
   986
} /* __PHYSFS_platformReleaseMutex */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   987
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   988
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   989
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
   990
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   991
    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
   992
    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
   993
    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
   994
    DWORD tzid;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   995
    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
   996
    struct tm tm;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   997
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   998
    BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), win32strerror(), -1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
   999
    tzid = GetTimeZoneInformation(&tzi);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1000
    BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, win32strerror(), -1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1001
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1002
        /* (This API is unsupported and fails on non-NT systems. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1003
    if (!SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz))
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1004
    {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1005
        /* do it by hand. Grumble... */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1006
        ULARGE_INTEGER ui64;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1007
        FILETIME new_ft;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1008
        ui64.LowPart = ft->dwLowDateTime;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1009
        ui64.HighPart = ft->dwHighDateTime;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1010
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1011
        if (tzid == TIME_ZONE_ID_STANDARD)
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1012
            tzi.Bias += tzi.StandardBias;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1013
        else if (tzid == TIME_ZONE_ID_DAYLIGHT)
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1014
            tzi.Bias += tzi.DaylightBias;
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
  1015
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1016
        /* convert from minutes to 100-nanosecond increments... */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1017
        #if 0 /* For compilers that puke on 64-bit math. */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1018
            /* goddamn this is inefficient... */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1019
            while (tzi.Bias > 0)
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1020
            {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1021
                DWORD tmp = ui64.LowPart - 60000000;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1022
                if ((ui64.LowPart < tmp) && (tmp > 60000000))
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1023
                    ui64.HighPart--;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1024
                ui64.LowPart = tmp;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1025
                tzi.Bias--;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1026
            } /* while */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1027
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1028
            while (tzi.Bias < 0)
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1029
            {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1030
                DWORD tmp = ui64.LowPart + 60000000;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1031
                if ((ui64.LowPart > tmp) && (tmp < 60000000))
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1032
                    ui64.HighPart++;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1033
                ui64.LowPart = tmp;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1034
                tzi.Bias++;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1035
            } /* while */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1036
        #else
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1037
            ui64.QuadPart -= (((LONGLONG) tzi.Bias) * (600000000));
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1038
        #endif
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1039
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1040
        /* Move it back into a FILETIME structure... */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1041
        new_ft.dwLowDateTime = ui64.LowPart;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1042
        new_ft.dwHighDateTime = ui64.HighPart;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1043
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1044
        /* Convert to something human-readable... */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1045
        if (!FileTimeToSystemTime(&new_ft, &st_localtz))
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1046
            BAIL_MACRO(win32strerror(), -1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1047
    } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1048
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1049
    /* 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
  1050
    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
  1051
    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
  1052
    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
  1053
    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
  1054
    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
  1055
    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
  1056
    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
  1057
    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
  1058
    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
  1059
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1060
    /* 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
  1061
    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
  1062
    BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1063
    return(retval);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1064
} /* FileTimeToPhysfsTime */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1065
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
  1066
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
  1067
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
  1068
{
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1069
    PHYSFS_sint64 retval = -1;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1070
    WIN32_FILE_ATTRIBUTE_DATA attrData;
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1071
    memset(&attrData, '\0', sizeof (attrData));
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
  1072
313
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1073
    /* GetFileAttributesEx didn't show up until Win98 and NT4. */
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
  1074
    if (pGetFileAttributesExA != NULL)
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
  1075
    {
856
8b8b8f67afdb Pushed a bunch of FIXMEs into the Windows platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 853
diff changeset
  1076
        /* !!! FIXME: unicode version. */
858
969e69b2822f Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 856
diff changeset
  1077
        if (pGetFileAttributesExA(fname, GetFileExInfoStandard, &attrData))
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1078
        {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1079
            /* 0 return value indicates an error or not supported */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1080
            if ( (attrData.ftLastWriteTime.dwHighDateTime != 0) ||
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1081
                 (attrData.ftLastWriteTime.dwLowDateTime != 0) )
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1082
            {
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1083
                retval = FileTimeToPhysfsTime(&attrData.ftLastWriteTime);
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1084
            } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1085
        } /* if */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1086
    } /* if */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
  1087
313
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1088
    /* GetFileTime() has been in the Win32 API since the start. */
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1089
    if (retval == -1)  /* try a fallback... */
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1090
    {
313
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1091
        FILETIME ft;
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1092
        BOOL rc;
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1093
        const char *err;
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1094
        win32file *f = (win32file *) __PHYSFS_platformOpenRead(fname);
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1095
        BAIL_IF_MACRO(f == NULL, NULL, -1)
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1096
        rc = GetFileTime(f->handle, NULL, NULL, &ft);
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1097
        err = win32strerror();
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1098
        CloseHandle(f->handle);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
  1099
        allocator.Free(f);
313
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1100
        BAIL_IF_MACRO(!rc, err, -1);
fccebd616595 Clean up dynamically loaded libraries at deinit, have a lastmodtime fallback.
Ryan C. Gordon <icculus@icculus.org>
parents: 312
diff changeset
  1101
        retval = FileTimeToPhysfsTime(&ft);
312
4996c48861db _LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents: 310
diff changeset
  1102
    } /* if */
4996c48861db _LOTS_ of cleanu