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