501
|
1 |
/*
|
|
2 |
* Skeleton platform-dependent support routines for PhysicsFS.
|
|
3 |
*
|
|
4 |
* Please see the file LICENSE in the source's root directory.
|
|
5 |
*
|
|
6 |
* This file written by Ryan C. Gordon.
|
|
7 |
*/
|
|
8 |
|
|
9 |
#if HAVE_CONFIG_H
|
|
10 |
# include <config.h>
|
|
11 |
#endif
|
|
12 |
|
|
13 |
#include <stdio.h>
|
|
14 |
#include <windows.h>
|
|
15 |
|
|
16 |
#define __PHYSICSFS_INTERNAL__
|
|
17 |
#include "physfs_internal.h"
|
|
18 |
|
|
19 |
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
|
20 |
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
|
|
21 |
typedef struct
|
|
22 |
{
|
|
23 |
HANDLE handle;
|
|
24 |
int readonly;
|
|
25 |
} winCEfile;
|
|
26 |
|
|
27 |
|
|
28 |
const char *__PHYSFS_platformDirSeparator = "\\";
|
|
29 |
|
|
30 |
/*
|
|
31 |
* Figure out what the last failing Win32 API call was, and
|
|
32 |
* generate a human-readable string for the error message.
|
|
33 |
*
|
|
34 |
* The return value is a static buffer that is overwritten with
|
|
35 |
* each call to this function.
|
|
36 |
*/
|
|
37 |
static const char *win32strerror(void)
|
|
38 |
{
|
|
39 |
static TCHAR msgbuf[255];
|
|
40 |
TCHAR *ptr = msgbuf;
|
|
41 |
|
|
42 |
FormatMessage(
|
|
43 |
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
44 |
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
45 |
NULL,
|
|
46 |
GetLastError(),
|
|
47 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
|
|
48 |
msgbuf,
|
|
49 |
sizeof (msgbuf) / sizeof (TCHAR),
|
|
50 |
NULL
|
|
51 |
);
|
|
52 |
|
|
53 |
/* chop off newlines. */
|
|
54 |
for (ptr = msgbuf; *ptr; ptr++)
|
|
55 |
{
|
|
56 |
if ((*ptr == '\n') || (*ptr == '\r'))
|
|
57 |
{
|
|
58 |
*ptr = ' ';
|
|
59 |
break;
|
|
60 |
} /* if */
|
|
61 |
} /* for */
|
|
62 |
|
|
63 |
return((const char *) msgbuf);
|
|
64 |
} /* win32strerror */
|
|
65 |
|
|
66 |
|
|
67 |
static char *UnicodeToAsc(const wchar_t *w_str)
|
|
68 |
{
|
|
69 |
char *str=NULL;
|
|
70 |
|
|
71 |
if(w_str!=NULL)
|
|
72 |
{
|
|
73 |
int len=wcslen(w_str)+1;
|
|
74 |
str=(char *)malloc(len);
|
|
75 |
|
|
76 |
if(WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL)==0)
|
|
77 |
{ //Conversion failed
|
|
78 |
free(str);
|
|
79 |
return NULL;
|
|
80 |
}
|
|
81 |
else
|
|
82 |
{ //Conversion successful
|
|
83 |
return(str);
|
|
84 |
}
|
|
85 |
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{ //Given NULL string
|
|
89 |
return NULL;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
static wchar_t *AscToUnicode(const char *str)
|
|
94 |
{
|
|
95 |
wchar_t *w_str=NULL;
|
|
96 |
if(str!=NULL)
|
|
97 |
{
|
|
98 |
int len=strlen(str)+1;
|
|
99 |
w_str=(wchar_t *)malloc(sizeof(wchar_t)*len);
|
|
100 |
if(MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len)==0)
|
|
101 |
{
|
|
102 |
free(w_str);
|
|
103 |
return NULL;
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
return(w_str);
|
|
108 |
}
|
|
109 |
}
|
|
110 |
else
|
|
111 |
{
|
|
112 |
return NULL;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
|
|
117 |
int __PHYSFS_platformInit(void)
|
|
118 |
{
|
|
119 |
return(1); /* always succeed. */
|
|
120 |
} /* __PHYSFS_platformInit */
|
|
121 |
|
|
122 |
|
|
123 |
int __PHYSFS_platformDeinit(void)
|
|
124 |
{
|
|
125 |
return(1); /* always succeed. */
|
|
126 |
} /* __PHYSFS_platformDeinit */
|
|
127 |
|
|
128 |
|
|
129 |
char **__PHYSFS_platformDetectAvailableCDs(void)
|
|
130 |
{
|
|
131 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
|
|
132 |
} /* __PHYSFS_platformDetectAvailableCDs */
|
|
133 |
|
|
134 |
|
|
135 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
|
136 |
{
|
|
137 |
return("\\");
|
|
138 |
// BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
|
|
139 |
} /* __PHYSFS_platformCalcBaseDir */
|
|
140 |
|
|
141 |
|
|
142 |
char *__PHYSFS_platformGetUserName(void)
|
|
143 |
{
|
|
144 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
|
|
145 |
} /* __PHYSFS_platformGetUserName */
|
|
146 |
|
|
147 |
|
|
148 |
char *__PHYSFS_platformGetUserDir(void)
|
|
149 |
{
|
|
150 |
return("\\");
|
|
151 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
|
|
152 |
} /* __PHYSFS_platformGetUserDir */
|
|
153 |
|
|
154 |
|
|
155 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
|
|
156 |
{
|
|
157 |
return(1); /* single threaded. */
|
|
158 |
} /* __PHYSFS_platformGetThreadID */
|
|
159 |
|
|
160 |
|
|
161 |
int __PHYSFS_platformStricmp(const char *x, const char *y)
|
|
162 |
{
|
|
163 |
const char *p1 = x, *p2 = y;
|
|
164 |
int r = 0;
|
|
165 |
|
|
166 |
while((*p1) && (*p2) && (toupper(*p1++) == toupper(*p2++))) ++r;
|
|
167 |
|
|
168 |
r = (!((*p1) || (*p2)) ? (0) : ((toupper(*p1) > toupper(*p2)) ?
|
|
169 |
(r + 1) : -(r + 1)));
|
|
170 |
|
|
171 |
return(r);
|
|
172 |
|
|
173 |
} /* __PHYSFS_platformStricmp */
|
|
174 |
|
|
175 |
|
|
176 |
int __PHYSFS_platformExists(const char *fname)
|
|
177 |
{
|
|
178 |
int retval=0;
|
|
179 |
|
|
180 |
wchar_t *w_fname=AscToUnicode(fname);
|
|
181 |
|
|
182 |
if(w_fname!=NULL)
|
|
183 |
{
|
|
184 |
retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
|
|
185 |
free(w_fname);
|
|
186 |
}
|
|
187 |
|
|
188 |
return(retval);
|
|
189 |
} /* __PHYSFS_platformExists */
|
|
190 |
|
|
191 |
|
|
192 |
int __PHYSFS_platformIsSymLink(const char *fname)
|
|
193 |
{
|
|
194 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
|
|
195 |
} /* __PHYSFS_platformIsSymlink */
|
|
196 |
|
|
197 |
|
|
198 |
int __PHYSFS_platformIsDirectory(const char *fname)
|
|
199 |
{
|
|
200 |
int retval=0;
|
|
201 |
|
|
202 |
wchar_t *w_fname=AscToUnicode(fname);
|
|
203 |
|
|
204 |
if(w_fname!=NULL)
|
|
205 |
{
|
|
206 |
retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
|
|
207 |
free(w_fname);
|
|
208 |
}
|
|
209 |
|
|
210 |
return(retval);
|
|
211 |
} /* __PHYSFS_platformIsDirectory */
|
|
212 |
|
|
213 |
|
|
214 |
char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
|
215 |
const char *dirName,
|
|
216 |
const char *append)
|
|
217 |
{
|
|
218 |
int len = ((prepend) ? strlen(prepend) : 0) +
|
|
219 |
((append) ? strlen(append) : 0) +
|
|
220 |
strlen(dirName) + 1;
|
|
221 |
char *retval = malloc(len);
|
|
222 |
char *p;
|
|
223 |
|
|
224 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
|
225 |
|
|
226 |
if (prepend)
|
|
227 |
strcpy(retval, prepend);
|
|
228 |
else
|
|
229 |
retval[0] = '\0';
|
|
230 |
|
|
231 |
strcat(retval, dirName);
|
|
232 |
|
|
233 |
if (append)
|
|
234 |
strcat(retval, append);
|
|
235 |
|
|
236 |
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
|
|
237 |
*p = '\\';
|
|
238 |
|
|
239 |
return(retval);
|
|
240 |
} /* __PHYSFS_platformCvtToDependent */
|
|
241 |
|
|
242 |
|
|
243 |
void __PHYSFS_platformTimeslice(void)
|
|
244 |
{
|
|
245 |
Sleep(10);
|
|
246 |
} /* __PHYSFS_platformTimeslice */
|
|
247 |
|
|
248 |
|
|
249 |
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
|
250 |
int omitSymLinks)
|
|
251 |
{
|
|
252 |
LinkedStringList *retval = NULL;
|
|
253 |
LinkedStringList *l = NULL;
|
|
254 |
LinkedStringList *prev = NULL;
|
|
255 |
HANDLE dir;
|
|
256 |
WIN32_FIND_DATA ent;
|
|
257 |
char *SearchPath;
|
|
258 |
wchar_t *w_SearchPath;
|
|
259 |
size_t len = strlen(dirname);
|
|
260 |
|
|
261 |
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
|
|
262 |
SearchPath = (char *) alloca(len + 3);
|
|
263 |
BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);
|
|
264 |
|
|
265 |
/* Copy current dirname */
|
|
266 |
strcpy(SearchPath, dirname);
|
|
267 |
|
|
268 |
/* if there's no '\\' at the end of the path, stick one in there. */
|
|
269 |
if (SearchPath[len - 1] != '\\')
|
|
270 |
{
|
|
271 |
SearchPath[len++] = '\\';
|
|
272 |
SearchPath[len] = '\0';
|
|
273 |
} /* if */
|
|
274 |
|
|
275 |
/* Append the "*" to the end of the string */
|
|
276 |
strcat(SearchPath, "*");
|
|
277 |
|
|
278 |
w_SearchPath=AscToUnicode(SearchPath);
|
|
279 |
|
|
280 |
dir = FindFirstFile(w_SearchPath, &ent);
|
|
281 |
free(w_SearchPath);
|
|
282 |
free(SearchPath);
|
|
283 |
|
|
284 |
if(dir == INVALID_HANDLE_VALUE)
|
|
285 |
{
|
|
286 |
return NULL;
|
|
287 |
}
|
|
288 |
|
|
289 |
do
|
|
290 |
{
|
|
291 |
if (wcscmp(ent.cFileName, L".") == 0)
|
|
292 |
continue;
|
|
293 |
|
|
294 |
if (wcscmp(ent.cFileName, L"..") == 0)
|
|
295 |
continue;
|
|
296 |
|
|
297 |
l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
|
|
298 |
if (l == NULL)
|
|
299 |
break;
|
|
300 |
|
|
301 |
l->str=UnicodeToAsc(ent.cFileName);
|
|
302 |
|
|
303 |
if (l->str == NULL)
|
|
304 |
{
|
|
305 |
free(l);
|
|
306 |
break;
|
|
307 |
}
|
|
308 |
|
|
309 |
|
|
310 |
if (retval == NULL)
|
|
311 |
retval = l;
|
|
312 |
else
|
|
313 |
prev->next = l;
|
|
314 |
|
|
315 |
prev = l;
|
|
316 |
l->next = NULL;
|
|
317 |
} while (FindNextFile(dir, &ent) != 0);
|
|
318 |
|
|
319 |
FindClose(dir);
|
|
320 |
return(retval);
|
|
321 |
} /* __PHYSFS_platformEnumerateFiles */
|
|
322 |
|
|
323 |
|
|
324 |
char *__PHYSFS_platformCurrentDir(void)
|
|
325 |
{
|
|
326 |
return("\\");
|
|
327 |
} /* __PHYSFS_platformCurrentDir */
|
|
328 |
|
|
329 |
|
|
330 |
char *__PHYSFS_platformRealPath(const char *path)
|
|
331 |
{
|
|
332 |
char *retval=(char *)malloc(strlen(path)+1);
|
|
333 |
|
|
334 |
strcpy(retval,path);
|
|
335 |
|
|
336 |
return(retval);
|
|
337 |
|
|
338 |
} /* __PHYSFS_platformRealPath */
|
|
339 |
|
|
340 |
|
|
341 |
int __PHYSFS_platformMkDir(const char *path)
|
|
342 |
{
|
|
343 |
wchar_t *w_path = AscToUnicode(path);
|
|
344 |
if(w_path!=NULL)
|
|
345 |
{
|
|
346 |
DWORD rc = CreateDirectory(w_path, NULL);
|
|
347 |
free(w_path);
|
|
348 |
if(rc==0)
|
|
349 |
{
|
|
350 |
return(0);
|
|
351 |
}
|
|
352 |
return(1);
|
|
353 |
}
|
|
354 |
else
|
|
355 |
{
|
|
356 |
return(0);
|
|
357 |
}
|
|
358 |
} /* __PHYSFS_platformMkDir */
|
|
359 |
|
|
360 |
|
|
361 |
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
|
|
362 |
{
|
|
363 |
HANDLE fileHandle;
|
|
364 |
winCEfile *retval;
|
|
365 |
wchar_t *w_fname=AscToUnicode(fname);
|
|
366 |
|
|
367 |
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
|
|
368 |
creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
369 |
|
|
370 |
free(w_fname);
|
|
371 |
|
|
372 |
if(fileHandle==INVALID_HANDLE_VALUE)
|
|
373 |
{
|
|
374 |
return NULL;
|
|
375 |
}
|
|
376 |
|
|
377 |
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
|
|
378 |
|
|
379 |
retval = malloc(sizeof (winCEfile));
|
|
380 |
if (retval == NULL)
|
|
381 |
{
|
|
382 |
CloseHandle(fileHandle);
|
|
383 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
|
384 |
} /* if */
|
|
385 |
|
|
386 |
retval->readonly = rdonly;
|
|
387 |
retval->handle = fileHandle;
|
|
388 |
return(retval);
|
|
389 |
} /* doOpen */
|
|
390 |
|
|
391 |
|
|
392 |
void *__PHYSFS_platformOpenRead(const char *filename)
|
|
393 |
{
|
|
394 |
return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1));
|
|
395 |
} /* __PHYSFS_platformOpenRead */
|
|
396 |
|
|
397 |
|
|
398 |
void *__PHYSFS_platformOpenWrite(const char *filename)
|
|
399 |
{
|
|
400 |
return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0));
|
|
401 |
} /* __PHYSFS_platformOpenWrite */
|
|
402 |
|
|
403 |
|
|
404 |
void *__PHYSFS_platformOpenAppend(const char *filename)
|
|
405 |
{
|
|
406 |
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
|
|
407 |
if (retval != NULL)
|
|
408 |
{
|
|
409 |
HANDLE h = ((winCEfile *) retval)->handle;
|
|
410 |
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
|
|
411 |
{
|
|
412 |
const char *err = win32strerror();
|
|
413 |
CloseHandle(h);
|
|
414 |
free(retval);
|
|
415 |
BAIL_MACRO(err, NULL);
|
|
416 |
} /* if */
|
|
417 |
} /* if */
|
|
418 |
|
|
419 |
return(retval);
|
|
420 |
|
|
421 |
} /* __PHYSFS_platformOpenAppend */
|
|
422 |
|
|
423 |
|
|
424 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
|
|
425 |
PHYSFS_uint32 size, PHYSFS_uint32 count)
|
|
426 |
{
|
|
427 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle;
|
|
428 |
DWORD CountOfBytesRead;
|
|
429 |
PHYSFS_sint64 retval;
|
|
430 |
|
|
431 |
/* Read data from the file */
|
|
432 |
/*!!! - uint32 might be a greater # than DWORD */
|
|
433 |
if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
|
|
434 |
{
|
|
435 |
retval=-1;
|
|
436 |
} /* if */
|
|
437 |
else
|
|
438 |
{
|
|
439 |
/* Return the number of "objects" read. */
|
|
440 |
/* !!! - What if not the right amount of bytes was read to make an object? */
|
|
441 |
retval = CountOfBytesRead / size;
|
|
442 |
} /* else */
|
|
443 |
|
|
444 |
return(retval);
|
|
445 |
|
|
446 |
} /* __PHYSFS_platformRead */
|
|
447 |
|
|
448 |
|
|
449 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
|
|
450 |
PHYSFS_uint32 size, PHYSFS_uint32 count)
|
|
451 |
{
|
|
452 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle;
|
|
453 |
DWORD CountOfBytesWritten;
|
|
454 |
PHYSFS_sint64 retval;
|
|
455 |
|
|
456 |
/* Read data from the file */
|
|
457 |
/*!!! - uint32 might be a greater # than DWORD */
|
|
458 |
if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL))
|
|
459 |
{
|
|
460 |
retval=-1;
|
|
461 |
} /* if */
|
|
462 |
else
|
|
463 |
{
|
|
464 |
/* Return the number of "objects" read. */
|
|
465 |
/*!!! - What if not the right number of bytes was written? */
|
|
466 |
retval = CountOfBytesWritten / size;
|
|
467 |
} /* else */
|
|
468 |
|
|
469 |
return(retval);
|
|
470 |
|
|
471 |
} /* __PHYSFS_platformWrite */
|
|
472 |
|
|
473 |
|
|
474 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
|
|
475 |
{
|
|
476 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle;
|
|
477 |
DWORD HighOrderPos;
|
|
478 |
DWORD rc;
|
|
479 |
|
|
480 |
/* Get the high order 32-bits of the position */
|
|
481 |
//HighOrderPos = HIGHORDER_UINT64(pos);
|
|
482 |
HighOrderPos = (unsigned long)(pos>>32);
|
|
483 |
|
|
484 |
/*!!! SetFilePointer needs a signed 64-bit value. */
|
|
485 |
/* Move pointer "pos" count from start of file */
|
|
486 |
rc = SetFilePointer(FileHandle, (unsigned long)(pos&0x00000000ffffffff),
|
|
487 |
&HighOrderPos, FILE_BEGIN);
|
|
488 |
|
|
489 |
if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
|
490 |
{
|
|
491 |
BAIL_MACRO(win32strerror(), 0);
|
|
492 |
}
|
|
493 |
|
|
494 |
return(1); /* No error occured */
|
|
495 |
} /* __PHYSFS_platformSeek */
|
|
496 |
|
|
497 |
|
|
498 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
|
|
499 |
{
|
|
500 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle;
|
|
501 |
DWORD HighPos = 0;
|
|
502 |
DWORD LowPos;
|
|
503 |
PHYSFS_sint64 retval;
|
|
504 |
|
|
505 |
/* Get current position */
|
|
506 |
LowPos = SetFilePointer(FileHandle, 0, &HighPos, FILE_CURRENT);
|
|
507 |
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
|
508 |
{
|
|
509 |
BAIL_MACRO(win32strerror(), 0);
|
|
510 |
} /* if */
|
|
511 |
else
|
|
512 |
{
|
|
513 |
/* Combine the high/low order to create the 64-bit position value */
|
|
514 |
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
|
|
515 |
//assert(retval >= 0);
|
|
516 |
} /* else */
|
|
517 |
|
|
518 |
return(retval);
|
|
519 |
} /* __PHYSFS_platformTell */
|
|
520 |
|
|
521 |
|
|
522 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
|
|
523 |
{
|
|
524 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle;
|
|
525 |
DWORD SizeHigh;
|
|
526 |
DWORD SizeLow;
|
|
527 |
PHYSFS_sint64 retval;
|
|
528 |
|
|
529 |
SizeLow = GetFileSize(FileHandle, &SizeHigh);
|
|
530 |
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
|
531 |
{
|
|
532 |
BAIL_MACRO(win32strerror(), -1);
|
|
533 |
} /* if */
|
|
534 |
else
|
|
535 |
{
|
|
536 |
/* Combine the high/low order to create the 64-bit position value */
|
|
537 |
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
|
|
538 |
//assert(retval >= 0);
|
|
539 |
} /* else */
|
|
540 |
|
|
541 |
return(retval);
|
|
542 |
} /* __PHYSFS_platformFileLength */
|
|
543 |
|
|
544 |
|
|
545 |
int __PHYSFS_platformEOF(void *opaque)
|
|
546 |
{
|
|
547 |
PHYSFS_sint64 FilePosition;
|
|
548 |
int retval = 0;
|
|
549 |
|
|
550 |
/* Get the current position in the file */
|
|
551 |
if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
|
|
552 |
{
|
|
553 |
/* Non-zero if EOF is equal to the file length */
|
|
554 |
retval = FilePosition == __PHYSFS_platformFileLength(opaque);
|
|
555 |
} /* if */
|
|
556 |
|
|
557 |
return(retval);
|
|
558 |
} /* __PHYSFS_platformEOF */
|
|
559 |
|
|
560 |
|
|
561 |
int __PHYSFS_platformFlush(void *opaque)
|
|
562 |
{
|
|
563 |
winCEfile *fh = ((winCEfile *) opaque);
|
|
564 |
if (!fh->readonly)
|
|
565 |
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
|
|
566 |
|
|
567 |
return(1);
|
|
568 |
} /* __PHYSFS_platformFlush */
|
|
569 |
|
|
570 |
|
|
571 |
int __PHYSFS_platformClose(void *opaque)
|
|
572 |
{
|
|
573 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle;
|
|
574 |
BAIL_IF_MACRO(!CloseHandle(FileHandle), win32strerror(), 0);
|
|
575 |
free(opaque);
|
|
576 |
return(1);
|
|
577 |
} /* __PHYSFS_platformClose */
|
|
578 |
|
|
579 |
|
|
580 |
int __PHYSFS_platformDelete(const char *path)
|
|
581 |
{
|
|
582 |
wchar_t *w_path=AscToUnicode(path);
|
|
583 |
|
|
584 |
/* If filename is a folder */
|
|
585 |
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
|
|
586 |
{
|
|
587 |
int retval=!RemoveDirectory(w_path);
|
|
588 |
free(w_path);
|
|
589 |
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
|
590 |
} /* if */
|
|
591 |
else
|
|
592 |
{
|
|
593 |
int retval=!DeleteFile(w_path);
|
|
594 |
free(w_path);
|
|
595 |
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
|
596 |
} /* else */
|
|
597 |
|
|
598 |
return(1); /* if you got here, it worked. */
|
|
599 |
} /* __PHYSFS_platformDelete */
|
|
600 |
|
|
601 |
|
|
602 |
void *__PHYSFS_platformCreateMutex(void)
|
|
603 |
{
|
|
604 |
return((void *) CreateMutex(NULL, FALSE, NULL));
|
|
605 |
} /* __PHYSFS_platformCreateMutex */
|
|
606 |
|
|
607 |
|
|
608 |
void __PHYSFS_platformDestroyMutex(void *mutex)
|
|
609 |
{
|
|
610 |
CloseHandle((HANDLE) mutex);
|
|
611 |
} /* __PHYSFS_platformDestroyMutex */
|
|
612 |
|
|
613 |
|
|
614 |
int __PHYSFS_platformGrabMutex(void *mutex)
|
|
615 |
{
|
|
616 |
return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
|
|
617 |
} /* __PHYSFS_platformGrabMutex */
|
|
618 |
|
|
619 |
|
|
620 |
void __PHYSFS_platformReleaseMutex(void *mutex)
|
|
621 |
{
|
|
622 |
ReleaseMutex((HANDLE) mutex);
|
|
623 |
} /* __PHYSFS_platformReleaseMutex */
|
|
624 |
|
|
625 |
|
|
626 |
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
|
627 |
{
|
|
628 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
|
|
629 |
} /* __PHYSFS_platformGetLastModTime */
|
|
630 |
|
|
631 |
/* end of skeleton.c ... */
|
|
632 |
|