platform/win32.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 11 Jun 2002 08:49:53 +0000
changeset 283 c966316c8998
parent 275 42f0e962abbb
child 310 f8bca4a93fd5
permissions -rw-r--r--
Updated.
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
/*
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
     2
 * Win32 support routines for PhysicsFS.
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
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
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
     9
#if HAVE_CONFIG_H
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
    10
#  include <config.h>
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
    11
#endif
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
    12
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <windows.h>
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <stdio.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    15
#include <stdlib.h>
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    16
#include <ctype.h>
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
    17
#include <time.h>
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    18
#include <assert.h>
210
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    19
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#define __PHYSICSFS_INTERNAL__
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include "physfs_internal.h"
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    23
#define LOWORDER_UINT64(pos)       (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    24
#define HIGHORDER_UINT64(pos)      (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    25
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
const char *__PHYSFS_platformDirSeparator = "\\";
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    28
static int runningNT = 0;               /* TRUE if NT derived OS */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    29
static OSVERSIONINFO OSVersionInfo;     /* Information about the OS */
210
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    30
static char *ProfileDirectory = NULL;   /* User profile folder */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    31
210
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    32
/* Users without the platform SDK don't have this defined.  The original docs
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    33
   for SetFilePointer() just said to compare with 0xFFFFFFF, so this should
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    34
   work as desired */
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    35
#ifndef INVALID_SET_FILE_POINTER
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    36
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
f5507414f7b7 -Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents: 198
diff changeset
    37
#endif
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
    39
/*
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    40
 * 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
    41
 *  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
    42
 *
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    43
 * 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
    44
 *  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
    45
 */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
static const char *win32strerror(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    48
    static TCHAR msgbuf[255];
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    FormatMessage(
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        FORMAT_MESSAGE_FROM_SYSTEM |
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        FORMAT_MESSAGE_IGNORE_INSERTS,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        NULL,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
        GetLastError(),
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    55
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    56
        msgbuf,
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    57
        sizeof (msgbuf) / sizeof (TCHAR),
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
        NULL 
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    );
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    61
    return((const char *) msgbuf);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
} /* win32strerror */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    65
/*
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    66
 * Uninitialize any NT specific stuff done in doNTInit().
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    67
 *
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    68
 * Return zero if there was a catastrophic failure and non-zero otherwise.
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    69
 */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    70
static int doNTDeinit(void)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    71
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    72
    /* nothing NT-specific to deinit at this point. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    73
    return 1;  /* It's all good */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    74
} /* doNTDeinit */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    75
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    76
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    77
typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) (
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    78
      HANDLE hToken,
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    79
      LPTSTR lpProfileDir,
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    80
      LPDWORD lpcchSize);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    81
   
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    82
/*
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    83
 * Initialize any NT specific stuff.  This includes any OS based on NT.
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    84
 *
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    85
 * Return zero if there was a catastrophic failure and non-zero otherwise.
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    86
 */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    87
static int doNTInit(void)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    88
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    89
    DWORD pathsize = 0;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    90
    char dummy[1];
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    91
    BOOL rc = 0;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    92
    HANDLE ProcessHandle = NULL;     /* Current process handle */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    93
    HANDLE AccessTokenHandle = NULL; /* Security handle to process */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    94
    LPFNGETUSERPROFILEDIR GetUserProfileDirectory = NULL;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    95
    HMODULE lib = NULL;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    96
    const char *err = NULL;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    97
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    98
    /* Hooray for spaghetti code! */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
    99
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   100
    lib = LoadLibrary("userenv.dll");
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   101
    if (!lib)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   102
        goto ntinit_failed;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   103
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   104
    /* !!! FIXME: Handle Unicode? */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   105
    GetUserProfileDirectory = (LPFNGETUSERPROFILEDIR)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   106
                              GetProcAddress(lib, "GetUserProfileDirectoryA");
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   107
    if (!GetUserProfileDirectory)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   108
        goto ntinit_failed;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   109
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   110
    /* Create a process handle associated with the current process ID */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   111
    ProcessHandle = GetCurrentProcess();
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   112
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   113
    /* Create a process access token handle */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   114
    if(!OpenProcessToken(ProcessHandle, TOKEN_QUERY, &AccessTokenHandle))
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   115
        goto ntinit_failed; /* we need that token to get the profile dir. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   116
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   117
    /* Should fail.  Will write the size of the profile path in pathsize */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   118
    /* Second parameter can't be NULL or the function fails. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   119
    rc = GetUserProfileDirectory(AccessTokenHandle, dummy, &pathsize);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   120
    assert(!rc);  /* success?! */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   121
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   122
    /* Allocate memory for the profile directory */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   123
    ProfileDirectory = (char *) malloc(pathsize);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   124
    if (ProfileDirectory == NULL)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   125
    {
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   126
        err = ERR_OUT_OF_MEMORY;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   127
        goto ntinit_failed;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   128
    } /* if */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   129
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   130
    /* Try to get the profile directory */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   131
    if(!GetUserProfileDirectory(AccessTokenHandle, ProfileDirectory, &pathsize))
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   132
        goto ntinit_failed;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   133
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   134
    goto ntinit_succeeded;  /* We made it: hit the showers. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   135
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   136
ntinit_failed:
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   137
    if (err == NULL) /* set an error string if we haven't yet. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   138
        __PHYSFS_setError(win32strerror());
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   139
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   140
    if (ProfileDirectory != NULL)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   141
    {
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   142
        free(ProfileDirectory);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   143
        ProfileDirectory = NULL;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   144
    } /* if */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   145
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   146
    /* drop through and clean up the rest of the stuff... */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   147
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   148
ntinit_succeeded:
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   149
    if (lib != NULL)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   150
        FreeLibrary(lib);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   151
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   152
    if (AccessTokenHandle != NULL)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   153
        CloseHandle(AccessTokenHandle);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   154
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   155
    return ((err == NULL) ? 1 : 0);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   156
} /* doNTInit */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   157
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   158
static BOOL MediaInDrive(const char *DriveLetter)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   159
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   160
    UINT OldErrorMode;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   161
    DWORD DummyValue;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   162
    BOOL ReturnValue;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   163
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   164
    /* Prevent windows warning message to appear when checking media size */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   165
    OldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   166
    
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   167
    /* If this function succeeds, there's media in the drive */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   168
    ReturnValue = GetDiskFreeSpace(DriveLetter, &DummyValue, &DummyValue, &DummyValue, &DummyValue);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   169
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   170
    /* Revert back to old windows error handler */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   171
    SetErrorMode(OldErrorMode);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   172
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   173
    return ReturnValue;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   174
} /* MediaInDrive */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   175
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
char **__PHYSFS_platformDetectAvailableCDs(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    char **retval = (char **) malloc(sizeof (char *));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    int cd_count = 1;  /* We count the NULL entry. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    char drive_str[4] = "x:\\";
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    for (drive_str[0] = 'A'; drive_str[0] <= 'Z'; drive_str[0]++)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
    {
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   184
        if (GetDriveType(drive_str) == DRIVE_CDROM && MediaInDrive(drive_str))
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
            char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
            if (tmp)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
            {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
                retval = tmp;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
                retval[cd_count-1] = (char *) malloc(4);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
                if (retval[cd_count-1])
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
                {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
                    strcpy(retval[cd_count-1], drive_str);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
                    cd_count++;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
                } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
            } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    } /* for */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    retval[cd_count - 1] = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
} /* __PHYSFS_detectAvailableCDs */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
127
0d54a1a087d2 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
   205
static char *getExePath(const char *argv0)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
{
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   207
    char *filepart = 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
   208
    char *retval;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   209
	DWORD buflen;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   210
		
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   211
	retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   212
	BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   213
    buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   214
	if (buflen == 0)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   215
    {
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   216
        const char *err = win32strerror();
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   217
        free(retval);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   218
        BAIL_MACRO(err, NULL);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   219
    } /* if */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   220
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   221
    retval[buflen] = '\0';  /* does API always null-terminate the string? */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   222
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   223
        /* make sure the string was not truncated. */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   224
    if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") == 0)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   225
    {
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   226
        char *ptr = strrchr(retval, '\\');
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   227
        if (ptr != NULL)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   228
        {
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   229
            *(ptr + 1) = '\0';  /* chop off filename. */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   230
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   231
            /* free up the bytes we didn't actually use. */            
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   232
            ptr = (char *) realloc(retval, strlen(retval) + 1);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   233
            if (ptr != NULL)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   234
			    retval = ptr;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   235
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   236
            return(retval);
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   237
        } /* if */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   238
    } /* if */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   239
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   240
    /* if any part of the previous approach failed, try SearchPath()... */
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   241
    buflen = SearchPath(NULL, argv0, NULL, buflen, NULL, NULL);
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   242
    retval = (char *) realloc(retval, buflen);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   244
    SearchPath(NULL, argv0, NULL, buflen, retval, &filepart);
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   245
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
    return(retval);
111
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   247
} /* getExePath */
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   248
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   249
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   250
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   251
{
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   252
    if (strchr(argv0, '\\') != NULL)   /* default behaviour can handle this. */
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   253
        return(NULL);
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   254
127
0d54a1a087d2 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
   255
    return(getExePath(argv0));
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
} /* __PHYSFS_platformCalcBaseDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
char *__PHYSFS_platformGetUserName(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   261
    DWORD bufsize = 0;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    LPTSTR retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    if (GetUserName(NULL, &bufsize) == 0)  /* This SHOULD fail. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
        retval = (LPTSTR) malloc(bufsize);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
        BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
        if (GetUserName(retval, &bufsize) == 0)  /* ?! */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
        {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   270
            __PHYSFS_setError(win32strerror());
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
            free(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
            retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
} /* __PHYSFS_platformGetUserName */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
{
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   282
    char *retval = (char *) malloc(strlen(ProfileDirectory) + 1);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   283
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   284
    strcpy(retval, ProfileDirectory); /* calculated at init time. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   285
	return retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   289
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
{
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   291
    return((PHYSFS_uint64)GetCurrentThreadId());
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   295
/* ...make this Cygwin AND Visual C friendly... */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
int __PHYSFS_platformStricmp(const char *x, const char *y)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
{
195
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   298
#if (defined _MSC_VER)
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   299
    return(stricmp(x, y));
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   300
#else
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   301
    int ux, uy;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   302
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   303
    do
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   304
    {
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   305
        ux = toupper((int) *x);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   306
        uy = toupper((int) *y);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   307
        if (ux > uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   308
            return(1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   309
        else if (ux < uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   310
            return(-1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   311
        x++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   312
        y++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   313
    } while ((ux) && (uy));
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   314
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   315
    return(0);
195
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   316
#endif
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
} /* __PHYSFS_platformStricmp */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
int __PHYSFS_platformExists(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
    return(GetFileAttributes(fname) != 0xffffffff);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
} /* __PHYSFS_platformExists */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
int __PHYSFS_platformIsSymLink(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
    return(0);  /* no symlinks on win32. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
} /* __PHYSFS_platformIsSymlink */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
int __PHYSFS_platformIsDirectory(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    return((GetFileAttributes(fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
} /* __PHYSFS_platformIsDirectory */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
char *__PHYSFS_platformCvtToDependent(const char *prepend,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
                                      const char *dirName,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
                                      const char *append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
    int len = ((prepend) ? strlen(prepend) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
              ((append) ? strlen(append) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
              strlen(dirName) + 1;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
    char *retval = malloc(len);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   346
    char *p;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
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
    if (prepend)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
        strcpy(retval, prepend);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
        retval[0] = '\0';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
    strcat(retval, dirName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
    if (append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
        strcat(retval, append);
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
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
        *p = '\\';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
} /* __PHYSFS_platformCvtToDependent */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
void __PHYSFS_platformTimeslice(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
    Sleep(10);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
} /* __PHYSFS_platformTimeslice */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
                                                  int omitSymLinks)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
    LinkedStringList *retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
    LinkedStringList *l = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    LinkedStringList *prev = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    HANDLE dir;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    WIN32_FIND_DATA ent;
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   382
    char *SearchPath;
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
   383
    size_t len = strlen(dirname);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
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
   385
    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   386
    SearchPath = (char *) _alloca(len + 3);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   387
    BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   388
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   389
    /* Copy current dirname */
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   390
    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
   391
0f47386615f0 Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
   392
    /* 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
   393
    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
   394
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   395
        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
   396
        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
   397
    } /* 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
   398
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   399
    /* 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
   400
    strcat(SearchPath, "*");
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   401
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   402
    dir = FindFirstFile(SearchPath, &ent);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
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
   405
    do
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
        if (strcmp(ent.cFileName, ".") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
        if (strcmp(ent.cFileName, "..") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
        if (l == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
        l->str = (char *) malloc(strlen(ent.cFileName) + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
        if (l->str == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
            free(l);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
        strcpy(l->str, ent.cFileName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
        if (retval == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
            retval = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
        else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
            prev->next = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
        prev = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
        l->next = NULL;
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
   433
    } while (FindNextFile(dir, &ent) != 0);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    FindClose(dir);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
} /* __PHYSFS_platformEnumerateFiles */
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
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
char *__PHYSFS_platformCurrentDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   442
    LPTSTR retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   445
    buflen = GetCurrentDirectory(buflen, NULL);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   446
    retval = (LPTSTR) malloc(sizeof (TCHAR) * (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
   447
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   448
    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
   449
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   450
    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
   451
        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
   452
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
} /* __PHYSFS_platformCurrentDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   457
/* this could probably use a cleanup. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
char *__PHYSFS_platformRealPath(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
{
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   460
    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
   461
    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
   462
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   463
    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
   464
    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
   465
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   466
    retval = (char *) malloc(MAX_PATH);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   467
    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
   468
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   469
        /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   470
         * 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
   471
         *  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
   472
         */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   473
    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
   474
        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
   475
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   476
    else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   477
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   478
        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
   479
        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
   480
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   481
            free(retval);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   482
            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
   483
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   484
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   485
        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
   486
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   487
            /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   488
             * 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
   489
             *  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
   490
             *  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
   491
             */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   492
            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
   493
                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
   494
            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
   495
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   496
                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
   497
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   498
                    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
   499
                    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
   500
                } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   501
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   502
                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
   503
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   504
                    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
   505
                    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
   506
                    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
   507
                    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
   508
                } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   509
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   510
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   511
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   512
        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
   513
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   514
            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
   515
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   516
                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
   517
                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
   518
                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
   519
            } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   520
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   521
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   522
                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
   523
                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
   524
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   525
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   526
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   527
        free(currentDir);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   528
    } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   529
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   530
    /* (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
   531
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   532
    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
   533
    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
   534
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   535
            /* it's a "." entry that doesn't end the string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   536
        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
   537
            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
   538
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   539
            /* it's a "." entry that ends the string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   540
        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
   541
            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
   542
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   543
            /* it's 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
   544
        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
   545
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   546
            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
   547
            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
   548
                prevEntry--;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   549
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   550
            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
   551
                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
   552
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   553
            {
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 (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
   555
                    *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
   556
                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
   557
                    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
   558
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   559
                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
   560
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   561
        } /* 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
   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
        else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   564
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   565
            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
   566
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   567
    } /* while */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   568
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   569
        /* shrink the retval's memory block if possible... */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   570
    p = (char *) realloc(retval, strlen(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
   571
    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
   572
        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
   573
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   574
    return(retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
} /* __PHYSFS_platformRealPath */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
int __PHYSFS_platformMkDir(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   580
    DWORD rc = CreateDirectory(path, NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
    BAIL_IF_MACRO(rc == 0, win32strerror(), 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
    return(1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
} /* __PHYSFS_platformMkDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   585
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   586
/* 
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   587
 * Get OS info and save it.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   588
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   589
 * 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
   590
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   591
int getOSInfo(void)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   592
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   593
    /* Get OS info */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   594
    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
   595
    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
   596
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   597
    /* Set to TRUE if we are runnign a WinNT based OS 4.0 or greater */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   598
    runningNT = (OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   599
        (OSVersionInfo.dwMajorVersion > 3);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   600
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   601
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   602
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   603
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   604
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
   605
{
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   606
    BAIL_IF_MACRO(!getOSInfo(), NULL, 0);
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   607
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   608
    /* If running an NT system (NT/Win2k/XP, etc...) */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   609
    if(runningNT)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   610
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   611
        BAIL_IF_MACRO(!doNTInit(), NULL, 0);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   612
    } /* if */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   613
    else
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   614
    {
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   615
        /* Profile directory is the exe path on 95/98/ME systems. */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   616
    	ProfileDirectory = getExePath(NULL);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   617
        BAIL_IF_MACRO(ProfileDirectory == NULL, win32strerror(), 0);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   618
    } /* else */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   619
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   620
    return 1;  /* It's all good */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   621
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   622
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   623
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
   624
{
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   625
    if (runningNT)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   626
    {
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   627
        BAIL_IF_MACRO(!doNTDeinit(), NULL, 0);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   628
    } /* if */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   629
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   630
    if (ProfileDirectory != NULL)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   631
    {
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   632
        free(ProfileDirectory);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   633
        ProfileDirectory = NULL;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   634
    } /* if */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   635
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   636
    return 1; /* It's all good */
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   637
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   638
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   639
void *__PHYSFS_platformOpenRead(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   640
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   641
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   642
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   643
    /* Open an existing file for read only. File can be opened by others
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   644
       who request read access on the file only. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   645
    FileHandle = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   646
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   647
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   648
    BAIL_IF_MACRO(FileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   649
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   650
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   651
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   652
void *__PHYSFS_platformOpenWrite(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   653
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   654
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   655
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   656
    /* Open an existing file for write only.  File can be opened by others
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   657
       who request read access to the file only */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   658
    FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   659
        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
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
    BAIL_IF_MACRO(FileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   662
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   663
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   664
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   665
void *__PHYSFS_platformOpenAppend(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   666
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   667
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   668
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   669
    /* Open an existing file for appending only.  File can be opened by others
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   670
       who request read access to the file only. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   671
    FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, 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
   672
        OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   673
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   674
    BAIL_IF_MACRO(FileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   675
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   676
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   677
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   678
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   679
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   680
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   681
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   682
    DWORD CountOfBytesRead;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   683
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   684
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   685
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   686
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   687
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   688
    /* Read data from the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   689
    /*!!! - uint32 might be a greater # than DWORD */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   690
    if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   691
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   692
        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
   693
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   694
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   695
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   696
        /* Return the number of "objects" read. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   697
        /* !!! - What if not the right amount of bytes was read to make an object? */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   698
        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
   699
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   700
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   701
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   702
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   703
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   704
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   705
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   706
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   707
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   708
    DWORD CountOfBytesWritten;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   709
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   710
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   711
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   712
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   713
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   714
    /* Read data from the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   715
    /*!!! - uint32 might be a greater # than DWORD */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   716
    if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   717
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   718
        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
   719
    } /* if */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   720
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   721
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   722
        /* Return the number of "objects" read. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   723
        /*!!! - What if not the right number of bytes was written? */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   724
        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
   725
    } /* else */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   726
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   727
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   728
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   729
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   730
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   731
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   732
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   733
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   734
    DWORD HighOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   735
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   736
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   737
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   738
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   739
    /* Get the high order 32-bits of the position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   740
    HighOrderPos = HIGHORDER_UINT64(pos);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   741
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   742
    /*!!! SetFilePointer needs a signed 64-bit value. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   743
    /* Move pointer "pos" count from start of file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   744
    if((SetFilePointer(FileHandle, LOWORDER_UINT64(pos), &HighOrderPos, FILE_BEGIN)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   745
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   746
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   747
        /* An error occured.  Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   748
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   749
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   750
        retval = 0;
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
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   753
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   754
        /* No error occured */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   755
        retval = 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   756
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   757
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   758
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   759
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   760
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   761
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   762
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   763
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   764
    DWORD HighOrderPos = 0; 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   765
    DWORD LowOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   766
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   767
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   768
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   769
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   770
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   771
    /* Get current position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   772
    if(((LowOrderPos = SetFilePointer(FileHandle, 0, &HighOrderPos, FILE_CURRENT))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   773
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   774
    {
211
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   775
        /* Set the error to GetLastError */
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   776
        __PHYSFS_setError(win32strerror());
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   777
        /* We errored out */
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   778
        retval = 0;
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   779
    }
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   780
    else
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   781
    {
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   782
        /* Combine the high/low order to create the 64-bit position value */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   783
        retval = HighOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   784
        retval = retval << 32;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   785
        retval |= LowOrderPos;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   788
    /*!!! Can't find a file pointer routine?!?!?!!?!?*/
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   789
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   790
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   791
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   792
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   793
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   794
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   795
    DWORD FileSizeHigh;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   796
    DWORD FileSizeLow;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   797
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   798
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   799
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   800
    FileHandle = (HANDLE)handle;
211
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   801
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   802
    /* Get the file size.  Condition evaluates to TRUE if an error occured */
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   803
    if(((FileSizeLow = GetFileSize(FileHandle, &FileSizeHigh))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   804
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   805
    {
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   806
        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
   807
    } /* 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
   808
    else
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   809
    {
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   810
        /* Combine the high/low order to create the 64-bit position value */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   811
        retval = FileSizeHigh;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   812
        retval = retval << 32;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   813
        retval |= FileSizeLow;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   816
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   817
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   818
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   819
int __PHYSFS_platformEOF(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   820
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   821
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   822
    PHYSFS_sint64 FilePosition;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   823
    int retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   824
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   825
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   826
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   827
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   828
    /* Get the current position in the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   829
    if((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   830
    {
211
e9a1d8b11e85 -Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents: 210
diff changeset
   831
        /* 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
   832
        retval = FilePosition == __PHYSFS_platformFileLength(opaque);
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   833
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   834
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   835
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   836
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   837
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   838
int __PHYSFS_platformFlush(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   839
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   840
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   841
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   842
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   843
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   844
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   845
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   846
    /* Close the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   847
    if(!(retval = FlushFileBuffers(FileHandle)))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   848
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   849
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   850
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   851
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   852
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   853
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   854
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   855
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   856
int __PHYSFS_platformClose(void *opaque)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   859
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   860
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   861
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   862
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   863
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   864
    /* Close the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   865
    if(!(retval = CloseHandle(FileHandle)))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   866
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   867
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   868
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   869
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   870
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   871
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   872
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   873
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   874
int __PHYSFS_platformDelete(const char *path)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   875
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   876
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   877
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   878
    /* If filename is a folder */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   879
    if(GetFileAttributes(path) == FILE_ATTRIBUTE_DIRECTORY)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   880
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   881
        retval = RemoveDirectory(path);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   882
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   883
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   884
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   885
        retval = DeleteFile(path);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   886
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   887
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   888
    if(!retval)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   889
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   890
            /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   891
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   892
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   893
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   894
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   895
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   896
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   897
void *__PHYSFS_platformCreateMutex(void)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   898
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   899
    return (void *)CreateMutex(NULL, FALSE, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   900
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   901
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   902
void __PHYSFS_platformDestroyMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   903
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   904
    CloseHandle((HANDLE)mutex);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   905
}
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_platformGrabMutex(void *mutex)
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
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   910
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   911
    if(WaitForSingleObject((HANDLE)mutex, INFINITE) == WAIT_FAILED)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   912
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   913
        /* Our wait failed for some unknown 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
   914
        retval = 0;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   915
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   916
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   917
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   918
        /* 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
   919
        retval = 1;
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   920
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   921
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   922
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   923
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   924
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   925
void __PHYSFS_platformReleaseMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   926
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   927
    ReleaseMutex((HANDLE)mutex);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   928
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   929
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   930
static time_t FileTimeToTimeT(FILETIME *ft)
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   931
{
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   932
    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
   933
    SYSTEMTIME st_localtz;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   934
    TIME_ZONE_INFORMATION TimeZoneInfo;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   935
    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
   936
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   937
    FileTimeToSystemTime(ft, &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
   938
    GetTimeZoneInformation(&TimeZoneInfo);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   939
    SystemTimeToTzSpecificLocalTime(&TimeZoneInfo, &st_utc, &st_localtz);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   940
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   941
    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
   942
    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
   943
    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
   944
    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
   945
    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
   946
    tm.tm_year = st_localtz.wYear - 1900;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   947
    tm.tm_wday = st_localtz.wDayOfWeek;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   948
    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
   949
    tm.tm_isdst = -1;
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   950
    return mktime(&tm);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   951
} /* FileTimeToTimeT */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   952
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   953
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
   954
{
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   955
    WIN32_FILE_ATTRIBUTE_DATA AttributeData;
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   956
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   957
    GetFileAttributesEx(fname, GetFileExInfoStandard, &AttributeData);
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   958
    /* 0 return value indicates an error or not supported */
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   959
    if(AttributeData.ftLastWriteTime.dwHighDateTime == 0 &&
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   960
        AttributeData.ftLastWriteTime.dwLowDateTime == 0)
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   961
    {
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   962
        /* Return error */
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   963
        BAIL_MACRO(win32strerror(), -1);
262
2d332d53c263 -Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents: 240
diff changeset
   964
    }
275
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   965
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   966
    /* Return UNIX time_t version of last write time */
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   967
    return (PHYSFS_sint64)FileTimeToTimeT(&AttributeData.ftLastWriteTime);
42f0e962abbb Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents: 268
diff changeset
   968
    /*return (PHYSFS_sint64)FileTimeToTimeT(&AttributeData.ftCreationTime);*/
240
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   969
} /* __PHYSFS_platformGetLastModTime */
052041af9001 Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
Ryan C. Gordon <icculus@icculus.org>
parents: 214
diff changeset
   970
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   971
/* end of win32.c ... */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   972