Skip to content

Latest commit

 

History

History
682 lines (528 loc) · 18.4 KB

platform_pocketpc.c

File metadata and controls

682 lines (528 loc) · 18.4 KB
 
Nov 22, 2002
Nov 22, 2002
1
/*
Mar 11, 2007
Mar 11, 2007
2
* PocketPC support routines for PhysicsFS.
Nov 22, 2002
Nov 22, 2002
3
*
Mar 11, 2007
Mar 11, 2007
4
* Please see the file LICENSE.txt in the source's root directory.
Nov 22, 2002
Nov 22, 2002
5
6
7
8
*
* This file written by Ryan C. Gordon.
*/
Mar 11, 2007
Mar 11, 2007
9
10
11
12
13
#define __PHYSICSFS_INTERNAL__
#include "physfs_platforms.h"
#ifdef PHYSFS_PLATFORM_POCKETPC
Nov 22, 2002
Nov 22, 2002
14
15
16
17
18
#include <stdio.h>
#include <windows.h>
#include "physfs_internal.h"
Jul 20, 2003
Jul 20, 2003
19
20
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
Nov 22, 2002
Nov 22, 2002
21
22
23
24
25
26
27
28
typedef struct
{
HANDLE handle;
int readonly;
} winCEfile;
const char *__PHYSFS_platformDirSeparator = "\\";
May 18, 2003
May 18, 2003
29
static char *userDir = NULL;
Nov 22, 2002
Nov 22, 2002
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Figure out what the last failing Win32 API call was, and
* 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.
*/
static const char *win32strerror(void)
{
static TCHAR msgbuf[255];
TCHAR *ptr = msgbuf;
FormatMessage(
Jul 20, 2003
Jul 20, 2003
44
45
46
47
48
49
50
51
52
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
msgbuf,
sizeof (msgbuf) / sizeof (TCHAR),
NULL
);
May 18, 2003
May 18, 2003
53
54
/* chop off newlines. */
Nov 22, 2002
Nov 22, 2002
55
56
57
58
59
60
61
62
63
for (ptr = msgbuf; *ptr; ptr++)
{
if ((*ptr == '\n') || (*ptr == '\r'))
{
*ptr = ' ';
break;
} /* if */
} /* for */
Jan 28, 2010
Jan 28, 2010
64
return ((const char *) msgbuf);
Nov 22, 2002
Nov 22, 2002
65
66
} /* win32strerror */
Mar 24, 2007
Mar 24, 2007
67
68
/* !!! FIXME: need to check all of these for NULLs. */
Mar 9, 2007
Mar 9, 2007
69
70
71
72
73
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
if (str == NULL) \
w_assignto = NULL; \
else { \
const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \
Mar 24, 2007
Mar 24, 2007
74
w_assignto = (char *) __PHYSFS_smallAlloc(len); \
Mar 9, 2007
Mar 9, 2007
75
76
77
PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \
} \
} \
Nov 22, 2002
Nov 22, 2002
78
79
May 18, 2003
May 18, 2003
80
81
82
83
84
static char *getExePath()
{
DWORD buflen;
int success = 0;
TCHAR *ptr = NULL;
Mar 14, 2005
Mar 14, 2005
85
TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
May 18, 2003
May 18, 2003
86
87
88
89
char *charretval;
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
retval[0] = _T('\0');
Mar 9, 2007
Mar 9, 2007
90
/* !!! FIXME: don't preallocate here? */
Mar 24, 2007
Mar 24, 2007
91
/* !!! FIXME: use smallAlloc? */
May 18, 2003
May 18, 2003
92
buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
Mar 8, 2007
Mar 8, 2007
93
if (buflen <= 0)
May 18, 2003
May 18, 2003
94
__PHYSFS_setError(win32strerror());
Mar 8, 2007
Mar 8, 2007
95
else
Jul 20, 2003
Jul 20, 2003
96
{
Mar 8, 2007
Mar 8, 2007
97
98
99
100
101
102
103
104
105
106
retval[buflen] = '\0'; /* does API always null-terminate this? */
ptr = retval+buflen;
while( ptr != retval )
{
if( *ptr != _T('\\') )
*ptr-- = _T('\0');
else
break;
} /* while */
success = 1;
May 18, 2003
May 18, 2003
107
108
109
110
} /* else */
if (!success)
{
Mar 14, 2005
Mar 14, 2005
111
allocator.Free(retval);
Jan 28, 2010
Jan 28, 2010
112
return NULL; /* physfs error message will be set, above. */
May 18, 2003
May 18, 2003
113
114
} /* if */
Mar 9, 2007
Mar 9, 2007
115
116
117
118
buflen = (buflen * 4) + 1;
charretval = (char *) allocator.Malloc(buflen);
if (charretval != NULL)
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) retval, charretval, buflen);
Mar 14, 2005
Mar 14, 2005
119
allocator.Free(retval);
Jan 28, 2010
Jan 28, 2010
120
return charretval; /* w00t. */
May 18, 2003
May 18, 2003
121
122
} /* getExePath */
Mar 8, 2007
Mar 8, 2007
123
Nov 22, 2002
Nov 22, 2002
124
125
int __PHYSFS_platformInit(void)
{
May 18, 2003
May 18, 2003
126
127
userDir = getExePath();
BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
Jan 28, 2010
Jan 28, 2010
128
return 1; /* always succeed. */
Nov 22, 2002
Nov 22, 2002
129
130
131
132
133
} /* __PHYSFS_platformInit */
int __PHYSFS_platformDeinit(void)
{
Mar 14, 2005
Mar 14, 2005
134
allocator.Free(userDir);
Jan 28, 2010
Jan 28, 2010
135
return 1; /* always succeed. */
Nov 22, 2002
Nov 22, 2002
136
137
138
} /* __PHYSFS_platformDeinit */
Sep 29, 2004
Sep 29, 2004
139
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
Nov 22, 2002
Nov 22, 2002
140
{
Sep 29, 2004
Sep 29, 2004
141
/* no-op on this platform. */
Nov 22, 2002
Nov 22, 2002
142
143
144
145
146
} /* __PHYSFS_platformDetectAvailableCDs */
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
Jan 28, 2010
Jan 28, 2010
147
return getExePath();
Nov 22, 2002
Nov 22, 2002
148
149
150
151
152
153
154
155
156
157
158
} /* __PHYSFS_platformCalcBaseDir */
char *__PHYSFS_platformGetUserName(void)
{
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
} /* __PHYSFS_platformGetUserName */
char *__PHYSFS_platformGetUserDir(void)
{
May 18, 2003
May 18, 2003
159
return userDir;
Nov 22, 2002
Nov 22, 2002
160
161
162
163
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
} /* __PHYSFS_platformGetUserDir */
Sep 6, 2009
Sep 6, 2009
164
void *__PHYSFS_platformGetThreadID(void)
Nov 22, 2002
Nov 22, 2002
165
{
Jan 28, 2010
Jan 28, 2010
166
return ((void *)1); /* single threaded. */ /* !!! FIXME: is this true? */
Nov 22, 2002
Nov 22, 2002
167
168
169
170
171
} /* __PHYSFS_platformGetThreadID */
int __PHYSFS_platformExists(const char *fname)
{
Mar 9, 2007
Mar 9, 2007
172
173
int retval = 0;
wchar_t *w_fname = NULL;
Nov 22, 2002
Nov 22, 2002
174
Mar 9, 2007
Mar 9, 2007
175
176
177
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
if (w_fname != NULL)
retval = (GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
Mar 24, 2007
Mar 24, 2007
178
__PHYSFS_smallFree(w_fname);
Nov 22, 2002
Nov 22, 2002
179
Jan 28, 2010
Jan 28, 2010
180
return retval;
Nov 22, 2002
Nov 22, 2002
181
182
183
184
185
186
187
188
189
190
191
} /* __PHYSFS_platformExists */
int __PHYSFS_platformIsSymLink(const char *fname)
{
BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
} /* __PHYSFS_platformIsSymlink */
int __PHYSFS_platformIsDirectory(const char *fname)
{
Mar 9, 2007
Mar 9, 2007
192
193
int retval = 0;
wchar_t *w_fname = NULL;
Nov 22, 2002
Nov 22, 2002
194
Mar 9, 2007
Mar 9, 2007
195
196
197
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
if (w_fname != NULL)
retval = ((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
Mar 24, 2007
Mar 24, 2007
198
__PHYSFS_smallFree(w_fname);
Nov 22, 2002
Nov 22, 2002
199
Jan 28, 2010
Jan 28, 2010
200
return retval;
Nov 22, 2002
Nov 22, 2002
201
202
203
204
205
206
207
208
} /* __PHYSFS_platformIsDirectory */
char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append)
{
int len = ((prepend) ? strlen(prepend) : 0) +
Jul 20, 2003
Jul 20, 2003
209
210
((append) ? strlen(append) : 0) +
strlen(dirName) + 1;
Mar 14, 2005
Mar 14, 2005
211
char *retval = (char *) allocator.Malloc(len);
Nov 22, 2002
Nov 22, 2002
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
char *p;
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
if (prepend)
strcpy(retval, prepend);
else
retval[0] = '\0';
strcat(retval, dirName);
if (append)
strcat(retval, append);
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
*p = '\\';
Jan 28, 2010
Jan 28, 2010
229
return retval;
Nov 22, 2002
Nov 22, 2002
230
231
232
} /* __PHYSFS_platformCvtToDependent */
Mar 9, 2007
Mar 9, 2007
233
234
235
static int doEnumCallback(const wchar_t *w_fname)
{
const PHYSFS_uint64 len = (PHYSFS_uint64) ((wcslen(w_fname) * 4) + 1);
Mar 24, 2007
Mar 24, 2007
236
char *str = (char *) __PHYSFS_smallAlloc(len);
Mar 9, 2007
Mar 9, 2007
237
238
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) w_fname, str, len);
callback(callbackdata, origdir, str);
Mar 24, 2007
Mar 24, 2007
239
__PHYSFS_smallFree(str);
Mar 9, 2007
Mar 9, 2007
240
241
242
243
return 1;
} /* doEnumCallback */
Sep 29, 2004
Sep 29, 2004
244
245
void __PHYSFS_platformEnumerateFiles(const char *dirname,
int omitSymLinks,
Sep 18, 2005
Sep 18, 2005
246
247
PHYSFS_EnumFilesCallback callback,
const char *origdir,
Sep 29, 2004
Sep 29, 2004
248
void *callbackdata)
Nov 22, 2002
Nov 22, 2002
249
250
251
252
{
HANDLE dir;
WIN32_FIND_DATA ent;
char *SearchPath;
May 18, 2003
May 18, 2003
253
wchar_t *w_SearchPath;
Nov 22, 2002
Nov 22, 2002
254
255
256
size_t len = strlen(dirname);
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
Mar 24, 2007
Mar 24, 2007
257
SearchPath = (char *) __PHYSFS_smallAlloc(len + 3);
Jul 20, 2003
Jul 20, 2003
258
BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);
Nov 22, 2002
Nov 22, 2002
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/* Copy current dirname */
strcpy(SearchPath, dirname);
/* if there's no '\\' at the end of the path, stick one in there. */
if (SearchPath[len - 1] != '\\')
{
SearchPath[len++] = '\\';
SearchPath[len] = '\0';
} /* if */
/* Append the "*" to the end of the string */
strcat(SearchPath, "*");
Mar 9, 2007
Mar 9, 2007
273
UTF8_TO_UNICODE_STACK_MACRO(w_SearchPath, SearchPath);
Mar 24, 2007
Mar 24, 2007
274
__PHYSFS_smallFree(SearchPath);
Nov 22, 2002
Nov 22, 2002
275
dir = FindFirstFile(w_SearchPath, &ent);
Mar 24, 2007
Mar 24, 2007
276
__PHYSFS_smallFree(w_SearchPath);
Nov 22, 2002
Nov 22, 2002
277
Sep 29, 2004
Sep 29, 2004
278
279
if (dir == INVALID_HANDLE_VALUE)
return;
Nov 22, 2002
Nov 22, 2002
280
281
282
do
{
Mar 9, 2007
Mar 9, 2007
283
const char *str = NULL;
Sep 29, 2004
Sep 29, 2004
284
Nov 22, 2002
Nov 22, 2002
285
286
287
288
289
290
if (wcscmp(ent.cFileName, L".") == 0)
continue;
if (wcscmp(ent.cFileName, L"..") == 0)
continue;
Mar 9, 2007
Mar 9, 2007
291
if (!doEnumCallback(ent.cFileName))
Nov 22, 2002
Nov 22, 2002
292
293
294
295
296
297
298
299
300
break;
} while (FindNextFile(dir, &ent) != 0);
FindClose(dir);
} /* __PHYSFS_platformEnumerateFiles */
char *__PHYSFS_platformCurrentDir(void)
{
Jan 28, 2010
Jan 28, 2010
301
return "\\";
Nov 22, 2002
Nov 22, 2002
302
303
304
305
306
} /* __PHYSFS_platformCurrentDir */
char *__PHYSFS_platformRealPath(const char *path)
{
Mar 14, 2005
Mar 14, 2005
307
char *retval = (char *) allocator.Malloc(strlen(path) + 1);
May 18, 2003
May 18, 2003
308
strcpy(retval,path);
Jan 28, 2010
Jan 28, 2010
309
return retval;
Nov 22, 2002
Nov 22, 2002
310
311
312
313
314
} /* __PHYSFS_platformRealPath */
int __PHYSFS_platformMkDir(const char *path)
{
Mar 24, 2007
Mar 24, 2007
315
int retval = 0;
Mar 9, 2007
Mar 9, 2007
316
317
wchar_t *w_path = NULL;
UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
Mar 24, 2007
Mar 24, 2007
318
319
320
321
322
if (w_path != NULL)
{
retval = CreateDirectory(w_path, NULL);
__PHYSFS_smallFree(w_fname);
} /* if */
Jan 28, 2010
Jan 28, 2010
323
return retval;
Nov 22, 2002
Nov 22, 2002
324
325
326
327
328
329
330
} /* __PHYSFS_platformMkDir */
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
{
HANDLE fileHandle;
winCEfile *retval;
Mar 9, 2007
Mar 9, 2007
331
332
333
wchar_t *w_fname = NULL;
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
Mar 17, 2010
Mar 17, 2010
334
335
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
Mar 24, 2007
Mar 24, 2007
336
__PHYSFS_smallFree(w_fname);
Nov 22, 2002
Nov 22, 2002
337
338
339
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
Mar 14, 2005
Mar 14, 2005
340
retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
May 18, 2003
May 18, 2003
341
342
if (retval == NULL)
{
Mar 8, 2007
Mar 8, 2007
343
344
CloseHandle(fileHandle);
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
May 18, 2003
May 18, 2003
345
} /* if */
Nov 22, 2002
Nov 22, 2002
346
May 18, 2003
May 18, 2003
347
348
retval->readonly = rdonly;
retval->handle = fileHandle;
Jan 28, 2010
Jan 28, 2010
349
return retval;
Nov 22, 2002
Nov 22, 2002
350
351
352
353
354
} /* doOpen */
void *__PHYSFS_platformOpenRead(const char *filename)
{
Jan 28, 2010
Jan 28, 2010
355
return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1);
Nov 22, 2002
Nov 22, 2002
356
357
358
359
360
} /* __PHYSFS_platformOpenRead */
void *__PHYSFS_platformOpenWrite(const char *filename)
{
Jan 28, 2010
Jan 28, 2010
361
return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0);
Nov 22, 2002
Nov 22, 2002
362
363
364
365
366
367
368
369
370
371
372
373
374
} /* __PHYSFS_platformOpenWrite */
void *__PHYSFS_platformOpenAppend(const char *filename)
{
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
if (retval != NULL)
{
HANDLE h = ((winCEfile *) retval)->handle;
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
{
const char *err = win32strerror();
CloseHandle(h);
Mar 14, 2005
Mar 14, 2005
375
allocator.Free(retval);
Nov 22, 2002
Nov 22, 2002
376
377
378
379
BAIL_MACRO(err, NULL);
} /* if */
} /* if */
Jan 28, 2010
Jan 28, 2010
380
return retval;
Nov 22, 2002
Nov 22, 2002
381
382
383
384
} /* __PHYSFS_platformOpenAppend */
Aug 21, 2010
Aug 21, 2010
385
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
Nov 22, 2002
Nov 22, 2002
386
{
Sep 26, 2004
Sep 26, 2004
387
HANDLE Handle = ((winCEfile *) opaque)->handle;
Aug 21, 2010
Aug 21, 2010
388
DWORD CountOfBytesRead = 0;
Nov 22, 2002
Nov 22, 2002
389
Aug 21, 2010
Aug 21, 2010
390
BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
Nov 22, 2002
Nov 22, 2002
391
Aug 21, 2010
Aug 21, 2010
392
393
394
if (!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL))
return -1; /* !!! FIXME: set an error string? */
return (PHYSFS_sint64) CountOfBytesRead;
Nov 22, 2002
Nov 22, 2002
395
396
397
398
} /* __PHYSFS_platformRead */
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
Aug 21, 2010
Aug 21, 2010
399
PHYSFS_uint64 len)
Nov 22, 2002
Nov 22, 2002
400
{
Sep 26, 2004
Sep 26, 2004
401
HANDLE Handle = ((winCEfile *) opaque)->handle;
Aug 21, 2010
Aug 21, 2010
402
DWORD CountOfBytesWritten = 0;
Nov 22, 2002
Nov 22, 2002
403
Aug 21, 2010
Aug 21, 2010
404
BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1);
Nov 22, 2002
Nov 22, 2002
405
Aug 21, 2010
Aug 21, 2010
406
407
408
if (!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL))
return -1;
return PHYSFS_sint64) CountOfBytesWritten;
Nov 22, 2002
Nov 22, 2002
409
410
411
412
413
} /* __PHYSFS_platformWrite */
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
{
Sep 26, 2004
Sep 26, 2004
414
HANDLE Handle = ((winCEfile *) opaque)->handle;
Nov 22, 2002
Nov 22, 2002
415
416
417
418
419
DWORD HighOrderPos;
DWORD rc;
/* Get the high order 32-bits of the position */
//HighOrderPos = HIGHORDER_UINT64(pos);
May 18, 2003
May 18, 2003
420
HighOrderPos = (unsigned long)(pos>>32);
Nov 22, 2002
Nov 22, 2002
421
422
423
/*!!! SetFilePointer needs a signed 64-bit value. */
/* Move pointer "pos" count from start of file */
Sep 26, 2004
Sep 26, 2004
424
rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff),
Nov 22, 2002
Nov 22, 2002
425
426
427
&HighOrderPos, FILE_BEGIN);
if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
May 18, 2003
May 18, 2003
428
{
Nov 22, 2002
Nov 22, 2002
429
BAIL_MACRO(win32strerror(), 0);
May 18, 2003
May 18, 2003
430
}
Nov 22, 2002
Nov 22, 2002
431
Jan 28, 2010
Jan 28, 2010
432
return 1; /* No error occured */
Nov 22, 2002
Nov 22, 2002
433
434
435
436
437
} /* __PHYSFS_platformSeek */
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
{
Sep 26, 2004
Sep 26, 2004
438
HANDLE Handle = ((winCEfile *) opaque)->handle;
Nov 22, 2002
Nov 22, 2002
439
440
441
442
443
DWORD HighPos = 0;
DWORD LowPos;
PHYSFS_sint64 retval;
/* Get current position */
Sep 26, 2004
Sep 26, 2004
444
LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
Nov 22, 2002
Nov 22, 2002
445
446
447
448
449
450
451
452
453
454
455
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
{
BAIL_MACRO(win32strerror(), 0);
} /* if */
else
{
/* Combine the high/low order to create the 64-bit position value */
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
//assert(retval >= 0);
} /* else */
Jan 28, 2010
Jan 28, 2010
456
return retval;
Nov 22, 2002
Nov 22, 2002
457
458
459
460
461
} /* __PHYSFS_platformTell */
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
{
Sep 26, 2004
Sep 26, 2004
462
HANDLE Handle = ((winCEfile *) opaque)->handle;
Nov 22, 2002
Nov 22, 2002
463
464
465
466
DWORD SizeHigh;
DWORD SizeLow;
PHYSFS_sint64 retval;
Sep 26, 2004
Sep 26, 2004
467
SizeLow = GetFileSize(Handle, &SizeHigh);
Nov 22, 2002
Nov 22, 2002
468
469
470
471
472
473
474
475
476
477
478
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
{
BAIL_MACRO(win32strerror(), -1);
} /* if */
else
{
/* Combine the high/low order to create the 64-bit position value */
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
//assert(retval >= 0);
} /* else */
Jan 28, 2010
Jan 28, 2010
479
return retval;
Nov 22, 2002
Nov 22, 2002
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
} /* __PHYSFS_platformFileLength */
int __PHYSFS_platformEOF(void *opaque)
{
PHYSFS_sint64 FilePosition;
int retval = 0;
/* Get the current position in the file */
if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
{
/* Non-zero if EOF is equal to the file length */
retval = FilePosition == __PHYSFS_platformFileLength(opaque);
} /* if */
Jan 28, 2010
Jan 28, 2010
495
return retval;
Nov 22, 2002
Nov 22, 2002
496
497
498
499
500
501
502
503
504
} /* __PHYSFS_platformEOF */
int __PHYSFS_platformFlush(void *opaque)
{
winCEfile *fh = ((winCEfile *) opaque);
if (!fh->readonly)
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
Jan 28, 2010
Jan 28, 2010
505
return 1;
Nov 22, 2002
Nov 22, 2002
506
507
508
509
510
} /* __PHYSFS_platformFlush */
int __PHYSFS_platformClose(void *opaque)
{
Sep 26, 2004
Sep 26, 2004
511
512
HANDLE Handle = ((winCEfile *) opaque)->handle;
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
Mar 14, 2005
Mar 14, 2005
513
allocator.Free(opaque);
Jan 28, 2010
Jan 28, 2010
514
return 1;
Nov 22, 2002
Nov 22, 2002
515
516
517
518
519
} /* __PHYSFS_platformClose */
int __PHYSFS_platformDelete(const char *path)
{
Mar 9, 2007
Mar 9, 2007
520
521
wchar_t *w_path = NULL;
UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
Nov 22, 2002
Nov 22, 2002
522
523
524
525
/* If filename is a folder */
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
{
Mar 9, 2007
Mar 9, 2007
526
int retval = !RemoveDirectory(w_path);
Mar 24, 2007
Mar 24, 2007
527
__PHYSFS_smallFree(w_path);
Nov 22, 2002
Nov 22, 2002
528
529
530
531
BAIL_IF_MACRO(retval, win32strerror(), 0);
} /* if */
else
{
Mar 9, 2007
Mar 9, 2007
532
int retval = !DeleteFile(w_path);
Mar 24, 2007
Mar 24, 2007
533
__PHYSFS_smallFree(w_path);
Nov 22, 2002
Nov 22, 2002
534
535
536
BAIL_IF_MACRO(retval, win32strerror(), 0);
} /* else */
Jan 28, 2010
Jan 28, 2010
537
return 1; /* if you got here, it worked. */
Nov 22, 2002
Nov 22, 2002
538
539
540
} /* __PHYSFS_platformDelete */
Feb 15, 2010
Feb 15, 2010
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/* Shamelessly copied from platform_windows.c */
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
{
SYSTEMTIME st_utc;
SYSTEMTIME st_localtz;
TIME_ZONE_INFORMATION tzi;
DWORD tzid;
PHYSFS_sint64 retval;
struct tm tm;
BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), winApiStrError(), -1);
tzid = GetTimeZoneInformation(&tzi);
BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, winApiStrError(), -1);
/* (This API is unsupported and fails on non-NT systems. */
if (!SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz))
{
/* do it by hand. Grumble... */
ULARGE_INTEGER ui64;
FILETIME new_ft;
ui64.LowPart = ft->dwLowDateTime;
ui64.HighPart = ft->dwHighDateTime;
if (tzid == TIME_ZONE_ID_STANDARD)
tzi.Bias += tzi.StandardBias;
else if (tzid == TIME_ZONE_ID_DAYLIGHT)
tzi.Bias += tzi.DaylightBias;
/* convert from minutes to 100-nanosecond increments... */
ui64.QuadPart -= (((LONGLONG) tzi.Bias) * (600000000));
/* Move it back into a FILETIME structure... */
new_ft.dwLowDateTime = ui64.LowPart;
new_ft.dwHighDateTime = ui64.HighPart;
/* Convert to something human-readable... */
if (!FileTimeToSystemTime(&new_ft, &st_localtz))
BAIL_MACRO(winApiStrError(), -1);
} /* if */
/* Convert to a format that mktime() can grok... */
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;
tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
tm.tm_yday = -1;
tm.tm_isdst = -1;
/* Convert to a format PhysicsFS can grok... */
retval = (PHYSFS_sint64) mktime(&tm);
BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
return retval;
} /* FileTimeToPhysfsTime */
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
{
WIN32_FIND_DATA winstat;
const HANDLE searchhandle = FindFirstFile(filename, &winstat);
if (searchhandle == INVALID_HANDLE_VALUE) /* call failed? */
{
/* !!! FIXME: FindFirstFile() doesn't set errno. Use GetLastError()?. */
if (errno == ERROR_FILE_NOT_FOUND)
{
*exists = 0;
return 0;
} /* if */
Aug 21, 2010
Aug 21, 2010
612
BAIL_MACRO(win32strerror, 0);
Feb 15, 2010
Feb 15, 2010
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
} /* if */
FindClose(searchhandle); /* close handle, not needed anymore */
*exists = 1;
if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
else if (winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_ROMMODULE))
stat->filetype = PHYSFS_FILETYPE_OTHER;
else
stat->filetype = PHYSFS_FILETYPE_OTHER; /* !!! FIXME: _REGULAR? */
if (stat->filetype == PHYSFS_FILETYPE_REGULAR)
stat->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
stat->readonly = ((winstat.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_INROM)) != 0);
Aug 21, 2010
Aug 21, 2010
634
return 1;
Feb 15, 2010
Feb 15, 2010
635
636
637
} /* __PHYSFS_platformStat */
Mar 24, 2007
Mar 24, 2007
638
639
640
641
642
/*
* !!! 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.
*/
Nov 22, 2002
Nov 22, 2002
643
644
void *__PHYSFS_platformCreateMutex(void)
{
Feb 15, 2010
Feb 15, 2010
645
return ((void *) CreateMutex(NULL, FALSE, NULL));
Nov 22, 2002
Nov 22, 2002
646
647
648
649
650
651
652
653
654
655
656
} /* __PHYSFS_platformCreateMutex */
void __PHYSFS_platformDestroyMutex(void *mutex)
{
CloseHandle((HANDLE) mutex);
} /* __PHYSFS_platformDestroyMutex */
int __PHYSFS_platformGrabMutex(void *mutex)
{
Jan 28, 2010
Jan 28, 2010
657
return (WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
Nov 22, 2002
Nov 22, 2002
658
659
660
661
662
663
664
665
666
667
668
669
670
671
} /* __PHYSFS_platformGrabMutex */
void __PHYSFS_platformReleaseMutex(void *mutex)
{
ReleaseMutex((HANDLE) mutex);
} /* __PHYSFS_platformReleaseMutex */
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
} /* __PHYSFS_platformGetLastModTime */
Mar 14, 2005
Mar 14, 2005
672
673
/* !!! FIXME: Don't use C runtime for allocators? */
Mar 20, 2007
Mar 20, 2007
674
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
Mar 14, 2005
Mar 14, 2005
675
{
Jan 28, 2010
Jan 28, 2010
676
return 0; /* just use malloc() and friends. */
Mar 20, 2007
Mar 20, 2007
677
} /* __PHYSFS_platformSetDefaultAllocator */
Mar 14, 2005
Mar 14, 2005
678
Mar 11, 2007
Mar 11, 2007
679
680
#endif /* PHYSFS_PLATFORM_POCKETPC */
Feb 15, 2005
Feb 15, 2005
681
/* end of pocketpc.c ... */