Skip to content

Latest commit

 

History

History
828 lines (662 loc) · 23.3 KB

platform_windows.c

File metadata and controls

828 lines (662 loc) · 23.3 KB
 
Aug 23, 2001
Aug 23, 2001
1
/*
Mar 11, 2007
Mar 11, 2007
2
* Windows support routines for PhysicsFS.
Aug 23, 2001
Aug 23, 2001
3
*
Mar 11, 2007
Mar 11, 2007
4
* Please see the file LICENSE.txt in the source's root directory.
Aug 23, 2001
Aug 23, 2001
5
*
Apr 13, 2002
Apr 13, 2002
6
* This file written by Ryan C. Gordon, and made sane by Gregory S. Read.
Aug 23, 2001
Aug 23, 2001
7
8
*/
Mar 11, 2007
Mar 11, 2007
9
10
11
12
#define __PHYSICSFS_INTERNAL__
#include "physfs_platforms.h"
#ifdef PHYSFS_PLATFORM_WINDOWS
Jul 10, 2002
Jul 10, 2002
13
Mar 10, 2012
Mar 10, 2012
14
/* Forcibly disable UNICODE macro, since we manage this ourselves. */
Mar 26, 2007
Mar 26, 2007
15
16
17
18
#ifdef UNICODE
#undef UNICODE
#endif
Mar 10, 2012
Mar 10, 2012
19
#define WIN32_LEAN_AND_MEAN 1
Aug 23, 2001
Aug 23, 2001
20
#include <windows.h>
Mar 10, 2012
Mar 10, 2012
21
#include <userenv.h>
Jun 29, 2002
Jun 29, 2002
22
#include <errno.h>
Aug 29, 2001
Aug 29, 2001
23
#include <ctype.h>
Jun 7, 2002
Jun 7, 2002
24
#include <time.h>
May 6, 2002
May 6, 2002
25
Aug 23, 2001
Aug 23, 2001
26
27
#include "physfs_internal.h"
Oct 1, 2007
Oct 1, 2007
28
29
#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF))
#define HIGHORDER_UINT64(pos) ((PHYSFS_uint32) ((pos >> 32) & 0xFFFFFFFF))
Apr 3, 2002
Apr 3, 2002
30
Mar 25, 2007
Mar 25, 2007
31
32
33
34
35
36
/*
* Users without the platform SDK don't have this defined. The original docs
* for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
* work as desired.
*/
#define PHYSFS_INVALID_SET_FILE_POINTER 0xFFFFFFFF
Mar 25, 2007
Mar 25, 2007
37
Mar 25, 2007
Mar 25, 2007
38
39
/* just in case... */
#define PHYSFS_INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
Jun 29, 2002
Jun 29, 2002
40
Apr 1, 2007
Apr 1, 2007
41
42
43
44
/* Not defined before the Vista SDK. */
#define PHYSFS_IO_REPARSE_TAG_SYMLINK 0xA000000C
Mar 25, 2007
Mar 25, 2007
45
46
47
48
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
if (str == NULL) \
w_assignto = NULL; \
else { \
Jan 22, 2008
Jan 22, 2008
49
const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) + 1) * 2); \
Mar 26, 2007
Mar 26, 2007
50
51
52
w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \
if (w_assignto != NULL) \
PHYSFS_utf8ToUcs2(str, (PHYSFS_uint16 *) w_assignto, len); \
Mar 25, 2007
Mar 25, 2007
53
54
} \
} \
Jun 29, 2002
Jun 29, 2002
55
Mar 10, 2012
Mar 10, 2012
56
57
58
59
60
#ifndef _MSC_VER
#define _snprintf snprintf
#endif
/* !!! FIXME: this is wrong for UTF-16. */
Mar 26, 2007
Mar 26, 2007
61
62
63
64
65
static PHYSFS_uint64 wStrLen(const WCHAR *wstr)
{
PHYSFS_uint64 len = 0;
while (*(wstr++))
len++;
Jan 28, 2010
Jan 28, 2010
66
return len;
Mar 26, 2007
Mar 26, 2007
67
68
69
70
71
72
73
74
75
76
77
} /* wStrLen */
static char *unicodeToUtf8Heap(const WCHAR *w_str)
{
char *retval = NULL;
if (w_str != NULL)
{
void *ptr = NULL;
const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1;
retval = allocator.Malloc(len);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
Mar 10, 2012
Mar 10, 2012
78
/* !!! FIXME: utf-16. */
Mar 26, 2007
Mar 26, 2007
79
80
81
82
83
PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) w_str, retval, len);
ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */
if (ptr != NULL)
retval = (char *) ptr;
} /* if */
Jan 28, 2010
Jan 28, 2010
84
return retval;
Mar 26, 2007
Mar 26, 2007
85
86
} /* unicodeToUtf8Heap */
Mar 10, 2012
Mar 10, 2012
87
/* !!! FIXME: do we really need readonly? If not, do we need this struct? */
Jun 29, 2002
Jun 29, 2002
88
89
90
91
typedef struct
{
HANDLE handle;
int readonly;
Mar 26, 2007
Mar 26, 2007
92
} WinApiFile;
Aug 23, 2001
Aug 23, 2001
93
Mar 26, 2007
Mar 26, 2007
94
Mar 10, 2012
Mar 10, 2012
95
const char *__PHYSFS_platformDirSeparator = "\\";
Mar 26, 2007
Mar 26, 2007
96
static char *userDir = NULL;
Mar 25, 2007
Mar 25, 2007
97
static HANDLE libUserEnv = NULL;
Mar 26, 2007
Mar 26, 2007
98
99
Jun 10, 2002
Jun 10, 2002
100
/*
Mar 26, 2007
Mar 26, 2007
101
* Figure out what the last failing Windows API call was, and
Jun 10, 2002
Jun 10, 2002
102
103
104
105
106
* generate a human-readable string for the error message.
*
* The return value is a static buffer that is overwritten with
* each call to this function.
*/
Mar 10, 2012
Mar 10, 2012
107
static const char *winApiStrErrorByNum(const DWORD err)
Jun 10, 2002
Jun 10, 2002
108
{
Mar 26, 2007
Mar 26, 2007
109
110
111
static char utf8buf[255];
WCHAR msgbuf[255];
WCHAR *ptr;
Mar 10, 2012
Mar 10, 2012
112
113
114
DWORD rc = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
Mar 26, 2007
Mar 26, 2007
115
116
msgbuf, __PHYSFS_ARRAYLEN(msgbuf),
NULL);
Jun 10, 2002
Jun 10, 2002
117
Feb 13, 2008
Feb 13, 2008
118
119
120
if (rc == 0)
msgbuf[0] = '\0'; /* oh well. */
Mar 25, 2007
Mar 25, 2007
121
/* chop off newlines. */
Jun 29, 2002
Jun 29, 2002
122
123
124
125
for (ptr = msgbuf; *ptr; ptr++)
{
if ((*ptr == '\n') || (*ptr == '\r'))
{
Mar 26, 2007
Mar 26, 2007
126
*ptr = '\0';
Jun 29, 2002
Jun 29, 2002
127
128
129
130
break;
} /* if */
} /* for */
Mar 26, 2007
Mar 26, 2007
131
132
/* may truncate, but oh well. */
PHYSFS_utf8FromUcs2((PHYSFS_uint16 *) msgbuf, utf8buf, sizeof (utf8buf));
Jan 28, 2010
Jan 28, 2010
133
return ((const char *) utf8buf);
Mar 10, 2012
Mar 10, 2012
134
} /* winApiStrErrorByNum */
Jun 10, 2002
Jun 10, 2002
135
Mar 10, 2012
Mar 10, 2012
136
static inline const char *winApiStrError(void)
Jun 7, 2002
Jun 7, 2002
137
{
Mar 10, 2012
Mar 10, 2012
138
139
return winApiStrErrorByNum(GetLastError());
} /* winApiStrError */
Jun 7, 2002
Jun 7, 2002
140
141
/*
Jun 29, 2002
Jun 29, 2002
142
143
144
145
* On success, module-scope variable (userDir) will have a pointer to
* a malloc()'d string of the user's profile dir, and a non-zero value is
* returned. If we can't determine the profile dir, (userDir) will
* be NULL, and zero is returned.
Jun 7, 2002
Jun 7, 2002
146
*/
Jun 29, 2002
Jun 29, 2002
147
static int determineUserDir(void)
Jun 7, 2002
Jun 7, 2002
148
{
Mar 10, 2012
Mar 10, 2012
149
150
151
152
153
typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);
fnGetUserProfDirW pGetDir = NULL;
HANDLE accessToken = NULL; /* Security handle to process */
Mar 25, 2007
Mar 25, 2007
154
if (userDir != NULL)
Jan 28, 2010
Jan 28, 2010
155
return 1; /* already good to go. */
Jun 10, 2002
Jun 10, 2002
156
Mar 10, 2012
Mar 10, 2012
157
158
159
160
161
162
163
pGetDir = (fnGetUserProfDirW)
GetProcAddress(libUserEnv, "GetUserProfileDirectoryW");
BAIL_IF_MACRO(pGetDir == NULL, winApiStrError(), 0);
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken))
BAIL_MACRO(winApiStrError(), 0);
else
Jun 29, 2002
Jun 29, 2002
164
{
Mar 10, 2012
Mar 10, 2012
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
DWORD psize = 0;
WCHAR dummy = 0;
LPWSTR wstr = NULL;
BOOL rc = 0;
/*
* Should fail. Will write the size of the profile path in
* psize. Also note that the second parameter can't be
* NULL or the function fails.
*/
rc = pGetDir(accessToken, &dummy, &psize);
assert(!rc); /* !!! FIXME: handle this gracefully. */
(void) rc;
/* Allocate memory for the profile directory */
wstr = (LPWSTR) __PHYSFS_smallAlloc(psize * sizeof (WCHAR));
if (wstr != NULL)
Jun 29, 2002
Jun 29, 2002
182
{
Mar 10, 2012
Mar 10, 2012
183
184
185
if (pGetDir(accessToken, wstr, &psize))
userDir = unicodeToUtf8Heap(wstr);
__PHYSFS_smallFree(wstr);
Jun 29, 2002
Jun 29, 2002
186
} /* if */
Jun 10, 2002
Jun 10, 2002
187
Mar 25, 2007
Mar 25, 2007
188
CloseHandle(accessToken);
Jun 10, 2002
Jun 10, 2002
189
190
} /* if */
Jan 28, 2010
Jan 28, 2010
191
return 1; /* We made it: hit the showers. */
Jun 29, 2002
Jun 29, 2002
192
} /* determineUserDir */
Jun 10, 2002
Jun 10, 2002
193
Jun 7, 2002
Jun 7, 2002
194
Jul 14, 2002
Jul 14, 2002
195
static BOOL mediaInDrive(const char *drive)
Jun 7, 2002
Jun 7, 2002
196
{
Jun 29, 2002
Jun 29, 2002
197
UINT oldErrorMode;
Jul 14, 2002
Jul 14, 2002
198
199
DWORD tmp;
BOOL retval;
Jun 7, 2002
Jun 7, 2002
200
Dec 8, 2003
Dec 8, 2003
201
/* Prevent windows warning message appearing when checking media size */
Mar 10, 2012
Mar 10, 2012
202
/* !!! FIXME: Windows 7 offers SetThreadErrorMode(). */
Jun 29, 2002
Jun 29, 2002
203
oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
Jun 7, 2002
Jun 7, 2002
204
205
/* If this function succeeds, there's media in the drive */
Mar 26, 2007
Mar 26, 2007
206
retval = GetVolumeInformationA(drive, NULL, 0, NULL, NULL, &tmp, NULL, 0);
Jun 7, 2002
Jun 7, 2002
207
208
/* Revert back to old windows error handler */
Jun 29, 2002
Jun 29, 2002
209
210
SetErrorMode(oldErrorMode);
Jan 28, 2010
Jan 28, 2010
211
return retval;
Jun 29, 2002
Jun 29, 2002
212
} /* mediaInDrive */
Jun 7, 2002
Jun 7, 2002
213
Mar 10, 2012
Mar 10, 2012
214
215
216
217
/*
* !!! FIXME: move this to a thread? This function hangs if you call it while
* !!! FIXME: a drive is spinning up right after inserting a disc.
*/
Sep 29, 2004
Sep 29, 2004
218
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
Aug 23, 2001
Aug 23, 2001
219
{
Mar 25, 2007
Mar 25, 2007
220
221
/* !!! FIXME: Can CD drives be non-drive letter paths? */
/* !!! FIXME: (so can they be Unicode paths?) */
Aug 23, 2001
Aug 23, 2001
222
char drive_str[4] = "x:\\";
Sep 29, 2004
Sep 29, 2004
223
224
char ch;
for (ch = 'A'; ch <= 'Z'; ch++)
Aug 23, 2001
Aug 23, 2001
225
{
Sep 29, 2004
Sep 29, 2004
226
drive_str[0] = ch;
Mar 10, 2012
Mar 10, 2012
227
if (GetDriveTypeA(drive_str) == DRIVE_CDROM && mediaInDrive(drive_str))
Sep 29, 2004
Sep 29, 2004
228
cb(data, drive_str);
Aug 23, 2001
Aug 23, 2001
229
} /* for */
Sep 29, 2004
Sep 29, 2004
230
} /* __PHYSFS_platformDetectAvailableCDs */
Aug 23, 2001
Aug 23, 2001
231
232
Oct 9, 2001
Oct 9, 2001
233
234
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
Mar 10, 2012
Mar 10, 2012
235
236
237
DWORD buflen = 64;
LPWSTR modpath = NULL;
char *retval = NULL;
Oct 9, 2001
Oct 9, 2001
238
Mar 10, 2012
Mar 10, 2012
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
while (1)
{
DWORD rc;
void *ptr;
if ( (ptr = allocator.Realloc(modpath, buflen*sizeof(WCHAR))) == NULL )
{
allocator.Free(modpath);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
} /* if */
modpath = (LPWSTR) ptr;
rc = GetModuleFileNameW(NULL, modpath, buflen);
if (rc == 0)
{
allocator.Free(modpath);
BAIL_MACRO(winApiStrError(), NULL);
} /* if */
if (rc < buflen)
{
buflen = rc;
break;
} /* if */
buflen *= 2;
} /* while */
if (buflen > 0) /* just in case... */
{
WCHAR *ptr = (modpath + buflen) - 1;
while (ptr != modpath)
{
if (*ptr == '\\')
break;
ptr--;
} /* while */
if ((ptr == modpath) && (*ptr != '\\'))
__PHYSFS_setError(ERR_GETMODFN_NO_DIR);
else
{
*(ptr + 1) = '\0'; /* chop off filename. */
retval = unicodeToUtf8Heap(modpath);
} /* else */
} /* else */
allocator.Free(modpath);
return retval; /* w00t. */
Aug 23, 2001
Aug 23, 2001
288
289
290
291
292
} /* __PHYSFS_platformCalcBaseDir */
char *__PHYSFS_platformGetUserName(void)
{
Aug 23, 2001
Aug 23, 2001
293
DWORD bufsize = 0;
Mar 26, 2007
Mar 26, 2007
294
295
char *retval = NULL;
Mar 10, 2012
Mar 10, 2012
296
if (GetUserNameW(NULL, &bufsize) == 0) /* This SHOULD fail. */
Mar 25, 2007
Mar 25, 2007
297
{
Mar 26, 2007
Mar 26, 2007
298
299
LPWSTR wbuf = (LPWSTR) __PHYSFS_smallAlloc(bufsize * sizeof (WCHAR));
BAIL_IF_MACRO(wbuf == NULL, ERR_OUT_OF_MEMORY, NULL);
Mar 10, 2012
Mar 10, 2012
300
if (GetUserNameW(wbuf, &bufsize) == 0) /* ?! */
Mar 26, 2007
Mar 26, 2007
301
302
303
304
__PHYSFS_setError(winApiStrError());
else
retval = unicodeToUtf8Heap(wbuf);
__PHYSFS_smallFree(wbuf);
Mar 25, 2007
Mar 25, 2007
305
306
} /* if */
Jan 28, 2010
Jan 28, 2010
307
return retval;
Aug 23, 2001
Aug 23, 2001
308
309
310
311
312
} /* __PHYSFS_platformGetUserName */
char *__PHYSFS_platformGetUserDir(void)
{
Mar 14, 2005
Mar 14, 2005
313
char *retval = (char *) allocator.Malloc(strlen(userDir) + 1);
Jun 10, 2002
Jun 10, 2002
314
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
Jun 29, 2002
Jun 29, 2002
315
strcpy(retval, userDir); /* calculated at init time. */
Jan 28, 2010
Jan 28, 2010
316
return retval;
Aug 23, 2001
Aug 23, 2001
317
318
319
} /* __PHYSFS_platformGetUserDir */
Sep 6, 2009
Sep 6, 2009
320
void *__PHYSFS_platformGetThreadID(void)
Aug 23, 2001
Aug 23, 2001
321
{
Jan 28, 2010
Jan 28, 2010
322
return ( (void *) ((size_t) GetCurrentThreadId()) );
Aug 23, 2001
Aug 23, 2001
323
324
325
} /* __PHYSFS_platformGetThreadID */
Apr 1, 2007
Apr 1, 2007
326
static int isSymlinkAttrs(const DWORD attr, const DWORD tag)
Mar 31, 2007
Mar 31, 2007
327
{
Apr 1, 2007
Apr 1, 2007
328
329
return ( (attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
(tag == PHYSFS_IO_REPARSE_TAG_SYMLINK) );
Mar 31, 2007
Mar 31, 2007
330
331
332
} /* isSymlinkAttrs */
Aug 23, 2001
Aug 23, 2001
333
334
335
336
char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append)
{
Mar 10, 2012
Mar 10, 2012
337
const size_t len = ((prepend) ? strlen(prepend) : 0) +
Aug 23, 2001
Aug 23, 2001
338
339
((append) ? strlen(append) : 0) +
strlen(dirName) + 1;
Mar 14, 2005
Mar 14, 2005
340
char *retval = (char *) allocator.Malloc(len);
Aug 23, 2001
Aug 23, 2001
341
char *p;
Aug 23, 2001
Aug 23, 2001
342
343
344
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
Mar 10, 2012
Mar 10, 2012
345
346
_snprintf(retval, len, "%s%s%s",
prepend ? prepend : "", dirName, append ? append : "");
Aug 23, 2001
Aug 23, 2001
347
348
349
350
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
*p = '\\';
Jan 28, 2010
Jan 28, 2010
351
return retval;
Aug 23, 2001
Aug 23, 2001
352
353
354
} /* __PHYSFS_platformCvtToDependent */
Sep 29, 2004
Sep 29, 2004
355
356
void __PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks,
Sep 18, 2005
Sep 18, 2005
357
358
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
359
void *callbackdata)
Aug 23, 2001
Aug 23, 2001
360
{
Mar 26, 2007
Mar 26, 2007
361
362
HANDLE dir = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW entw;
Jun 8, 2002
Jun 8, 2002
363
size_t len = strlen(dirname);
Mar 26, 2007
Mar 26, 2007
364
365
char *searchPath = NULL;
WCHAR *wSearchPath = NULL;
Jun 7, 2002
Jun 7, 2002
366
Jun 8, 2002
Jun 8, 2002
367
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
Mar 26, 2007
Mar 26, 2007
368
369
searchPath = (char *) __PHYSFS_smallAlloc(len + 3);
if (searchPath == NULL)
Sep 29, 2004
Sep 29, 2004
370
return;
Jun 10, 2002
Jun 10, 2002
371
Jun 7, 2002
Jun 7, 2002
372
/* Copy current dirname */
Mar 26, 2007
Mar 26, 2007
373
strcpy(searchPath, dirname);
Jun 8, 2002
Jun 8, 2002
374
375
/* if there's no '\\' at the end of the path, stick one in there. */
Mar 26, 2007
Mar 26, 2007
376
if (searchPath[len - 1] != '\\')
Jun 8, 2002
Jun 8, 2002
377
{
Mar 26, 2007
Mar 26, 2007
378
379
searchPath[len++] = '\\';
searchPath[len] = '\0';
Jun 8, 2002
Jun 8, 2002
380
381
} /* if */
Jun 7, 2002
Jun 7, 2002
382
/* Append the "*" to the end of the string */
Mar 26, 2007
Mar 26, 2007
383
strcat(searchPath, "*");
Aug 23, 2001
Aug 23, 2001
384
Mar 26, 2007
Mar 26, 2007
385
386
387
UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath);
if (wSearchPath == NULL)
return; /* oh well. */
Aug 23, 2001
Aug 23, 2001
388
Mar 10, 2012
Mar 10, 2012
389
dir = FindFirstFileW(wSearchPath, &entw);
Aug 23, 2001
Aug 23, 2001
390
Mar 26, 2007
Mar 26, 2007
391
392
393
394
__PHYSFS_smallFree(wSearchPath);
__PHYSFS_smallFree(searchPath);
if (dir == INVALID_HANDLE_VALUE)
return;
Aug 23, 2001
Aug 23, 2001
395
Mar 10, 2012
Mar 10, 2012
396
do
Mar 26, 2007
Mar 26, 2007
397
{
Mar 10, 2012
Mar 10, 2012
398
399
400
401
const DWORD attr = entw.dwFileAttributes;
const DWORD tag = entw.dwReserved0;
const WCHAR *fn = entw.cFileName;
char *utf8;
Mar 25, 2007
Mar 25, 2007
402
Mar 10, 2012
Mar 10, 2012
403
404
405
406
407
408
409
410
411
if ((fn[0] == '.') && (fn[1] == '\0'))
continue;
if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
continue;
if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
continue;
utf8 = unicodeToUtf8Heap(fn);
if (utf8 != NULL)
Mar 26, 2007
Mar 26, 2007
412
{
Mar 10, 2012
Mar 10, 2012
413
414
415
416
callback(callbackdata, origdir, utf8);
allocator.Free(utf8);
} /* if */
} while (FindNextFileW(dir, &entw) != 0);
Aug 23, 2001
Aug 23, 2001
417
418
419
420
421
422
423
FindClose(dir);
} /* __PHYSFS_platformEnumerateFiles */
char *__PHYSFS_platformCurrentDir(void)
{
Mar 26, 2007
Mar 26, 2007
424
425
char *retval = NULL;
WCHAR *wbuf = NULL;
Aug 23, 2001
Aug 23, 2001
426
427
DWORD buflen = 0;
Mar 10, 2012
Mar 10, 2012
428
buflen = GetCurrentDirectoryW(buflen, NULL);
Mar 26, 2007
Mar 26, 2007
429
430
wbuf = (WCHAR *) __PHYSFS_smallAlloc((buflen + 2) * sizeof (WCHAR));
BAIL_IF_MACRO(wbuf == NULL, ERR_OUT_OF_MEMORY, NULL);
Mar 10, 2012
Mar 10, 2012
431
GetCurrentDirectoryW(buflen, wbuf);
Sep 1, 2001
Sep 1, 2001
432
Mar 26, 2007
Mar 26, 2007
433
if (wbuf[buflen - 2] == '\\')
Mar 10, 2012
Mar 10, 2012
434
wbuf[buflen - 1] = '\0'; /* just in case... */
Mar 26, 2007
Mar 26, 2007
435
436
437
438
439
else
{
wbuf[buflen - 1] = '\\';
wbuf[buflen] = '\0';
} /* else */
Sep 1, 2001
Sep 1, 2001
440
Mar 26, 2007
Mar 26, 2007
441
442
retval = unicodeToUtf8Heap(wbuf);
__PHYSFS_smallFree(wbuf);
Jan 28, 2010
Jan 28, 2010
443
return retval;
Aug 23, 2001
Aug 23, 2001
444
445
446
} /* __PHYSFS_platformCurrentDir */
Sep 1, 2001
Sep 1, 2001
447
/* this could probably use a cleanup. */
Aug 23, 2001
Aug 23, 2001
448
449
char *__PHYSFS_platformRealPath(const char *path)
{
Mar 10, 2012
Mar 10, 2012
450
451
452
453
454
/*
* At this point, we only use this for the user and base dir,
* and we already know those are RealPath'd by the OS for us.
*/
char *retval = (char *) allocator.Malloc(strlen(path) + 1);
Sep 1, 2001
Sep 1, 2001
455
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
Mar 10, 2012
Mar 10, 2012
456
strcpy(retval, path);
Jan 28, 2010
Jan 28, 2010
457
return retval;
Aug 23, 2001
Aug 23, 2001
458
459
460
461
462
} /* __PHYSFS_platformRealPath */
int __PHYSFS_platformMkDir(const char *path)
{
Mar 26, 2007
Mar 26, 2007
463
464
465
WCHAR *wpath;
DWORD rc;
UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
Mar 10, 2012
Mar 10, 2012
466
rc = CreateDirectoryW(wpath, NULL);
Mar 26, 2007
Mar 26, 2007
467
468
__PHYSFS_smallFree(wpath);
BAIL_IF_MACRO(rc == 0, winApiStrError(), 0);
Jan 28, 2010
Jan 28, 2010
469
return 1;
Aug 23, 2001
Aug 23, 2001
470
471
} /* __PHYSFS_platformMkDir */
Jun 10, 2002
Jun 10, 2002
472
Jun 29, 2002
Jun 29, 2002
473
474
int __PHYSFS_platformInit(void)
{
Mar 10, 2012
Mar 10, 2012
475
476
477
478
libUserEnv = LoadLibraryA("userenv.dll");
BAIL_IF_MACRO(libUserEnv == NULL, winApiStrError(), 0);
/* !!! FIXME: why do we precalculate this? */
Jun 29, 2002
Jun 29, 2002
479
BAIL_IF_MACRO(!determineUserDir(), NULL, 0);
Jan 28, 2010
Jan 28, 2010
480
return 1; /* It's all good */
Jun 29, 2002
Jun 29, 2002
481
} /* __PHYSFS_platformInit */
Mar 24, 2002
Mar 24, 2002
482
483
484
485
int __PHYSFS_platformDeinit(void)
{
Mar 10, 2012
Mar 10, 2012
486
487
488
if (libUserEnv)
FreeLibrary(libUserEnv);
libUserEnv = NULL;
Mar 25, 2007
Mar 25, 2007
489
490
allocator.Free(userDir);
userDir = NULL;
Jan 28, 2010
Jan 28, 2010
491
return 1; /* It's all good */
Jun 29, 2002
Jun 29, 2002
492
493
494
495
496
} /* __PHYSFS_platformDeinit */
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
{
Mar 10, 2012
Mar 10, 2012
497
HANDLE fileh;
Mar 26, 2007
Mar 26, 2007
498
499
WinApiFile *retval;
WCHAR *wfname;
Jun 29, 2002
Jun 29, 2002
500
Mar 26, 2007
Mar 26, 2007
501
502
UTF8_TO_UNICODE_STACK_MACRO(wfname, fname);
BAIL_IF_MACRO(wfname == NULL, ERR_OUT_OF_MEMORY, NULL);
Mar 10, 2012
Mar 10, 2012
503
504
fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
Mar 26, 2007
Mar 26, 2007
505
__PHYSFS_smallFree(wfname);
Jun 29, 2002
Jun 29, 2002
506
Mar 10, 2012
Mar 10, 2012
507
BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE,winApiStrError(), NULL);
Jun 29, 2002
Jun 29, 2002
508
Mar 26, 2007
Mar 26, 2007
509
retval = (WinApiFile *) allocator.Malloc(sizeof (WinApiFile));
Jun 29, 2002
Jun 29, 2002
510
if (retval == NULL)
Jun 10, 2002
Jun 10, 2002
511
{
Mar 10, 2012
Mar 10, 2012
512
CloseHandle(fileh);
Jun 29, 2002
Jun 29, 2002
513
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
Jun 10, 2002
Jun 10, 2002
514
} /* if */
Mar 24, 2002
Mar 24, 2002
515
Jun 29, 2002
Jun 29, 2002
516
retval->readonly = rdonly;
Mar 10, 2012
Mar 10, 2012
517
retval->handle = fileh;
Jan 28, 2010
Jan 28, 2010
518
return retval;
Jun 29, 2002
Jun 29, 2002
519
520
} /* doOpen */
Mar 24, 2002
Mar 24, 2002
521
Apr 3, 2002
Apr 3, 2002
522
523
void *__PHYSFS_platformOpenRead(const char *filename)
{
Jan 28, 2010
Jan 28, 2010
524
return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
Jun 29, 2002
Jun 29, 2002
525
} /* __PHYSFS_platformOpenRead */
Apr 3, 2002
Apr 3, 2002
526
527
528
529
void *__PHYSFS_platformOpenWrite(const char *filename)
{
Jan 28, 2010
Jan 28, 2010
530
return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
Jun 29, 2002
Jun 29, 2002
531
} /* __PHYSFS_platformOpenWrite */
Apr 3, 2002
Apr 3, 2002
532
533
534
535
void *__PHYSFS_platformOpenAppend(const char *filename)
{
Jun 29, 2002
Jun 29, 2002
536
537
538
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
if (retval != NULL)
{
Mar 26, 2007
Mar 26, 2007
539
HANDLE h = ((WinApiFile *) retval)->handle;
Dec 8, 2003
Dec 8, 2003
540
541
DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
Jun 29, 2002
Jun 29, 2002
542
{
Mar 26, 2007
Mar 26, 2007
543
const char *err = winApiStrError();
Jun 29, 2002
Jun 29, 2002
544
CloseHandle(h);
Mar 14, 2005
Mar 14, 2005
545
allocator.Free(retval);
Jun 29, 2002
Jun 29, 2002
546
547
548
549
BAIL_MACRO(err, NULL);
} /* if */
} /* if */
Jan 28, 2010
Jan 28, 2010
550
return retval;
Jun 29, 2002
Jun 29, 2002
551
} /* __PHYSFS_platformOpenAppend */
Apr 3, 2002
Apr 3, 2002
552
553
Jan 21, 2011
Jan 21, 2011
554
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */
Aug 21, 2010
Aug 21, 2010
555
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
Apr 3, 2002
Apr 3, 2002
556
{
Mar 26, 2007
Mar 26, 2007
557
HANDLE Handle = ((WinApiFile *) opaque)->handle;
Aug 21, 2010
Aug 21, 2010
558
DWORD CountOfBytesRead = 0;
Apr 3, 2002
Apr 3, 2002
559
Aug 21, 2010
Aug 21, 2010
560
BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
Apr 3, 2002
Apr 3, 2002
561
Aug 21, 2010
Aug 21, 2010
562
563
564
if(!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL))
BAIL_MACRO(winApiStrError(), -1);
return (PHYSFS_sint64) CountOfBytesRead;
Jun 29, 2002
Jun 29, 2002
565
566
} /* __PHYSFS_platformRead */
Apr 3, 2002
Apr 3, 2002
567
Jan 21, 2011
Jan 21, 2011
568
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */
Jun 29, 2002
Jun 29, 2002
569
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
Jan 21, 2011
Jan 21, 2011
570
PHYSFS_uint64 len)
Apr 3, 2002
Apr 3, 2002
571
{
Mar 26, 2007
Mar 26, 2007
572
HANDLE Handle = ((WinApiFile *) opaque)->handle;
Aug 21, 2010
Aug 21, 2010
573
DWORD CountOfBytesWritten = 0;
Apr 3, 2002
Apr 3, 2002
574
Aug 21, 2010
Aug 21, 2010
575
BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
Apr 3, 2002
Apr 3, 2002
576
Aug 21, 2010
Aug 21, 2010
577
578
579
if(!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL))
BAIL_MACRO(winApiStrError(), -1);
return (PHYSFS_sint64) CountOfBytesWritten;
Jun 29, 2002
Jun 29, 2002
580
581
} /* __PHYSFS_platformWrite */
Apr 3, 2002
Apr 3, 2002
582
583
584
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
{
Mar 26, 2007
Mar 26, 2007
585
HANDLE Handle = ((WinApiFile *) opaque)->handle;
Mar 9, 2008
Mar 9, 2008
586
587
LONG HighOrderPos;
PLONG pHighOrderPos;
Jun 29, 2002
Jun 29, 2002
588
DWORD rc;
Apr 3, 2002
Apr 3, 2002
589
590
591
592
/* Get the high order 32-bits of the position */
HighOrderPos = HIGHORDER_UINT64(pos);
Dec 8, 2003
Dec 8, 2003
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*
* MSDN: "If you do not need the high-order 32 bits, this
* pointer must be set to NULL."
*/
pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
/*
* !!! FIXME: MSDN: "Windows Me/98/95: If the pointer
* !!! FIXME: lpDistanceToMoveHigh is not NULL, then it must
* !!! FIXME: point to either 0, INVALID_SET_FILE_POINTER, or
* !!! FIXME: the sign extension of the value of lDistanceToMove.
* !!! FIXME: Any other value will be rejected."
*/
Apr 3, 2002
Apr 3, 2002
607
/* Move pointer "pos" count from start of file */
Sep 26, 2004
Sep 26, 2004
608
rc = SetFilePointer(Handle, LOWORDER_UINT64(pos),
Dec 8, 2003
Dec 8, 2003
609
pHighOrderPos, FILE_BEGIN);
Apr 3, 2002
Apr 3, 2002
610
Dec 8, 2003
Dec 8, 2003
611
612
613
if ( (rc == PHYSFS_INVALID_SET_FILE_POINTER) &&
(GetLastError() != NO_ERROR) )
{
Mar 26, 2007
Mar 26, 2007
614
BAIL_MACRO(winApiStrError(), 0);
Dec 8, 2003
Dec 8, 2003
615
616
} /* if */
Jan 28, 2010
Jan 28, 2010
617
return 1; /* No error occured */
Jun 29, 2002
Jun 29, 2002
618
} /* __PHYSFS_platformSeek */
Apr 3, 2002
Apr 3, 2002
619
620
621
622
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
{
Mar 26, 2007
Mar 26, 2007
623
HANDLE Handle = ((WinApiFile *) opaque)->handle;
Mar 9, 2008
Mar 9, 2008
624
LONG HighPos = 0;
Jun 29, 2002
Jun 29, 2002
625
DWORD LowPos;
Apr 3, 2002
Apr 3, 2002
626
627
628
PHYSFS_sint64 retval;
/* Get current position */
Sep 26, 2004
Sep 26, 2004
629
LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
Dec 8, 2003
Dec 8, 2003
630
631
if ( (LowPos == PHYSFS_INVALID_SET_FILE_POINTER) &&
(GetLastError() != NO_ERROR) )
Apr 3, 2002
Apr 3, 2002
632
{
Aug 1, 2011
Aug 1, 2011
633
BAIL_MACRO(winApiStrError(), -1);
Jun 29, 2002
Jun 29, 2002
634
} /* if */
May 8, 2002
May 8, 2002
635
636
637
else
{
/* Combine the high/low order to create the 64-bit position value */
Jun 29, 2002
Jun 29, 2002
638
639
640
641
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
assert(retval >= 0);
} /* else */
Jan 28, 2010
Jan 28, 2010
642
return retval;
Jun 29, 2002
Jun 29, 2002
643
} /* __PHYSFS_platformTell */
Apr 3, 2002
Apr 3, 2002
644
645
Jun 29, 2002
Jun 29, 2002
646
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
Apr 3, 2002
Apr 3, 2002
647
{
Mar 26, 2007
Mar 26, 2007
648
HANDLE Handle = ((WinApiFile *) opaque)->handle;
Jun 29, 2002
Jun 29, 2002
649
650
DWORD SizeHigh;
DWORD SizeLow;
Apr 3, 2002
Apr 3, 2002
651
652
PHYSFS_sint64 retval;
Sep 26, 2004
Sep 26, 2004
653
SizeLow = GetFileSize(Handle, &SizeHigh);
Dec 8, 2003
Dec 8, 2003
654
655
if ( (SizeLow == PHYSFS_INVALID_SET_FILE_POINTER) &&
(GetLastError() != NO_ERROR) )
Apr 3, 2002
Apr 3, 2002
656
{
Mar 26, 2007
Mar 26, 2007
657
BAIL_MACRO(winApiStrError(), -1);
Jun 10, 2002
Jun 10, 2002
658
} /* if */
May 8, 2002
May 8, 2002
659
660
661
else
{
/* Combine the high/low order to create the 64-bit position value */
Jun 29, 2002
Jun 29, 2002
662
663
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
assert(retval >= 0);
Jun 10, 2002
Jun 10, 2002
664
} /* else */
Apr 3, 2002
Apr 3, 2002
665
Jan 28, 2010
Jan 28, 2010
666
return retval;
Jun 29, 2002
Jun 29, 2002
667
668
} /* __PHYSFS_platformFileLength */
Apr 3, 2002
Apr 3, 2002
669
670
671
int __PHYSFS_platformFlush(void *opaque)
{
Mar 26, 2007
Mar 26, 2007
672
WinApiFile *fh = ((WinApiFile *) opaque);
Jun 29, 2002
Jun 29, 2002
673
if (!fh->readonly)
Mar 26, 2007
Mar 26, 2007
674
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), winApiStrError(), 0);
Apr 3, 2002
Apr 3, 2002
675
Jan 28, 2010
Jan 28, 2010
676
return 1;
Jun 29, 2002
Jun 29, 2002
677
} /* __PHYSFS_platformFlush */
Apr 3, 2002
Apr 3, 2002
678
679
Aug 30, 2010
Aug 30, 2010
680
void __PHYSFS_platformClose(void *opaque)
Apr 3, 2002
Apr 3, 2002
681
{
Mar 26, 2007
Mar 26, 2007
682
HANDLE Handle = ((WinApiFile *) opaque)->handle;
Aug 30, 2010
Aug 30, 2010
683
(void) CloseHandle(Handle); /* ignore errors. You should have flushed! */
Mar 14, 2005
Mar 14, 2005
684
allocator.Free(opaque);
Jun 29, 2002
Jun 29, 2002
685
} /* __PHYSFS_platformClose */
Apr 3, 2002
Apr 3, 2002
686
687
Mar 26, 2007
Mar 26, 2007
688
static int doPlatformDelete(LPWSTR wpath)
Apr 3, 2002
Apr 3, 2002
689
{
Mar 10, 2012
Mar 10, 2012
690
691
692
const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY);
const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
BAIL_IF_MACRO(!rc, winApiStrError(), 0);
Jan 28, 2010
Jan 28, 2010
693
return 1; /* if you made it here, it worked. */
Mar 26, 2007
Mar 26, 2007
694
695
696
697
698
699
} /* doPlatformDelete */
int __PHYSFS_platformDelete(const char *path)
{
int retval = 0;
Mar 10, 2012
Mar 10, 2012
700
LPWSTR wpath = NULL;
Mar 26, 2007
Mar 26, 2007
701
702
703
704
UTF8_TO_UNICODE_STACK_MACRO(wpath, path);
BAIL_IF_MACRO(wpath == NULL, ERR_OUT_OF_MEMORY, 0);
retval = doPlatformDelete(wpath);
__PHYSFS_smallFree(wpath);
Jan 28, 2010
Jan 28, 2010
705
return retval;
Jun 29, 2002
Jun 29, 2002
706
} /* __PHYSFS_platformDelete */
Apr 3, 2002
Apr 3, 2002
707
708
Mar 24, 2007
Mar 24, 2007
709
710
711
712
713
/*
* !!! FIXME: why aren't we using Critical Sections instead of Mutexes?
* !!! FIXME: mutexes on Windows are for cross-process sync. CritSects are
* !!! FIXME: mutexes for threads in a single process and are faster.
*/
Apr 3, 2002
Apr 3, 2002
714
715
void *__PHYSFS_platformCreateMutex(void)
{
Jan 28, 2010
Jan 28, 2010
716
return ((void *) CreateMutex(NULL, FALSE, NULL));
Jun 29, 2002
Jun 29, 2002
717
718
} /* __PHYSFS_platformCreateMutex */
Apr 3, 2002
Apr 3, 2002
719
720
721
void __PHYSFS_platformDestroyMutex(void *mutex)
{
Jun 29, 2002
Jun 29, 2002
722
723
724
CloseHandle((HANDLE) mutex);
} /* __PHYSFS_platformDestroyMutex */
Apr 3, 2002
Apr 3, 2002
725
726
727
int __PHYSFS_platformGrabMutex(void *mutex)
{
Jan 28, 2010
Jan 28, 2010
728
return (WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
Jun 29, 2002
Jun 29, 2002
729
} /* __PHYSFS_platformGrabMutex */
Apr 3, 2002
Apr 3, 2002
730
731
732
733
void __PHYSFS_platformReleaseMutex(void *mutex)
{
Jun 29, 2002
Jun 29, 2002
734
735
736
ReleaseMutex((HANDLE) mutex);
} /* __PHYSFS_platformReleaseMutex */
Apr 3, 2002
Apr 3, 2002
737
Jun 29, 2002
Jun 29, 2002
738
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
Jun 10, 2002
Jun 10, 2002
739
740
741
{
SYSTEMTIME st_utc;
SYSTEMTIME st_localtz;
Jun 29, 2002
Jun 29, 2002
742
743
744
TIME_ZONE_INFORMATION tzi;
DWORD tzid;
PHYSFS_sint64 retval;
Jun 10, 2002
Jun 10, 2002
745
struct tm tm;
Mar 10, 2012
Mar 10, 2012
746
BOOL rc;
Jun 10, 2002
Jun 10, 2002
747
Mar 26, 2007
Mar 26, 2007
748
BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), winApiStrError(), -1);
Jun 29, 2002
Jun 29, 2002
749
tzid = GetTimeZoneInformation(&tzi);
Mar 26, 2007
Mar 26, 2007
750
BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, winApiStrError(), -1);
Mar 10, 2012
Mar 10, 2012
751
752
rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz);
BAIL_IF_MACRO(!rc, winApiStrError(), -1);
Jun 29, 2002
Jun 29, 2002
753
754
/* Convert to a format that mktime() can grok... */
Jun 10, 2002
Jun 10, 2002
755
756
757
758
759
760
tm.tm_sec = st_localtz.wSecond;
tm.tm_min = st_localtz.wMinute;
tm.tm_hour = st_localtz.wHour;
tm.tm_mday = st_localtz.wDay;
tm.tm_mon = st_localtz.wMonth - 1;
tm.tm_year = st_localtz.wYear - 1900;
Jun 29, 2002
Jun 29, 2002
761
tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
Jun 10, 2002
Jun 10, 2002
762
763
tm.tm_yday = -1;
tm.tm_isdst = -1;
Jun 29, 2002
Jun 29, 2002
764
765
766
767
/* Convert to a format PhysicsFS can grok... */
retval = (PHYSFS_sint64) mktime(&tm);
BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
Jan 28, 2010
Jan 28, 2010
768
return retval;
Jun 29, 2002
Jun 29, 2002
769
770
} /* FileTimeToPhysfsTime */
Mar 10, 2012
Mar 10, 2012
771
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
Feb 15, 2010
Feb 15, 2010
772
773
774
{
WIN32_FILE_ATTRIBUTE_DATA winstat;
WCHAR *wstr = NULL;
Mar 10, 2012
Mar 10, 2012
775
DWORD err = 0;
Feb 15, 2010
Feb 15, 2010
776
777
778
BOOL rc = 0;
UTF8_TO_UNICODE_STACK_MACRO(wstr, filename);
Mar 10, 2012
Mar 10, 2012
779
780
781
782
BAIL_IF_MACRO(wstr == NULL, ERR_OUT_OF_MEMORY, 0);
rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
err = (!rc) ? GetLastError() : 0;
*exists = ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND));
Feb 15, 2010
Feb 15, 2010
783
__PHYSFS_smallFree(wstr);
Mar 10, 2012
Mar 10, 2012
784
BAIL_IF_MACRO(!rc, winApiStrErrorByNum(err), 0);
Feb 15, 2010
Feb 15, 2010
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
stat->filesize = 0;
} /* if */
else if(winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE))
{
/* !!! FIXME: what are reparse points? */
stat->filetype = PHYSFS_FILETYPE_OTHER;
/* !!! FIXME: don't rely on this */
stat->filesize = 0;
} /* else if */
/* !!! FIXME: check for symlinks on Vista. */
else
{
stat->filetype = PHYSFS_FILETYPE_REGULAR;
Feb 18, 2010
Feb 18, 2010
809
stat->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
Feb 15, 2010
Feb 15, 2010
810
811
812
813
} /* else */
stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
Aug 21, 2010
Aug 21, 2010
814
return 1;
Feb 15, 2010
Feb 15, 2010
815
816
817
} /* __PHYSFS_platformStat */
Mar 14, 2005
Mar 14, 2005
818
/* !!! FIXME: Don't use C runtime for allocators? */
Mar 20, 2007
Mar 20, 2007
819
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
Mar 14, 2005
Mar 14, 2005
820
{
Jan 28, 2010
Jan 28, 2010
821
return 0; /* just use malloc() and friends. */
Mar 20, 2007
Mar 20, 2007
822
} /* __PHYSFS_platformSetDefaultAllocator */
Mar 14, 2005
Mar 14, 2005
823
Mar 11, 2007
Mar 11, 2007
824
#endif /* PHYSFS_PLATFORM_WINDOWS */
Jul 10, 2002
Jul 10, 2002
825
Mar 8, 2007
Mar 8, 2007
826
/* end of windows.c ... */