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