author | Ryan C. Gordon <icculus@icculus.org> |
Fri, 19 Dec 2003 01:49:12 +0000 | |
changeset 612 | 03b07cbd1bc7 |
parent 596 | 381b6ca0dd85 |
child 651 | cbe4ea4c7e8e |
child 675 | 6b25ff23fa66 |
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 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
70 |
char *str=NULL; |
501 | 71 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
72 |
if(w_str!=NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
73 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
74 |
int len=wcslen(w_str)+1; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
75 |
str=(char *)malloc(len); |
501 | 76 |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
77 |
if(WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL)==0) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
78 |
{ //Conversion failed |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
79 |
free(str); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
80 |
return NULL; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
81 |
} |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
82 |
else |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
83 |
{ //Conversion successful |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
84 |
return(str); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
85 |
} |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
86 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
87 |
} |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
88 |
else |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
89 |
{ //Given NULL string |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
90 |
return NULL; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
91 |
} |
501 | 92 |
} |
93 |
||
94 |
static wchar_t *AscToUnicode(const char *str) |
|
95 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
96 |
wchar_t *w_str=NULL; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
97 |
if(str!=NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
98 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
99 |
int len=strlen(str)+1; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
100 |
w_str=(wchar_t *)malloc(sizeof(wchar_t)*len); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
101 |
if(MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len)==0) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
102 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
103 |
free(w_str); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
104 |
return NULL; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
105 |
} |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
106 |
else |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
107 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
108 |
return(w_str); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
109 |
} |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
110 |
} |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
111 |
else |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
112 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
113 |
return NULL; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
114 |
} |
501 | 115 |
} |
116 |
||
117 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
118 |
static char *getExePath() |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
119 |
{ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
120 |
DWORD buflen; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
121 |
int success = 0; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
122 |
TCHAR *ptr = NULL; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
123 |
TCHAR *retval = (TCHAR *) malloc(sizeof (TCHAR) * (MAX_PATH + 1)); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
124 |
char *charretval; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
125 |
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
|
126 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
127 |
retval[0] = _T('\0'); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
128 |
buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
129 |
if (buflen <= 0) { |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
130 |
__PHYSFS_setError(win32strerror()); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
131 |
} else { |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
132 |
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
|
133 |
ptr = retval+buflen; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
134 |
while( ptr != retval ) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
135 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
136 |
if( *ptr != _T('\\') ) { |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
137 |
*ptr-- = _T('\0'); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
138 |
} else { |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
139 |
break; |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
140 |
} |
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 |
success = 1; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
143 |
} /* else */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
144 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
145 |
if (!success) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
146 |
{ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
147 |
free(retval); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
148 |
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
|
149 |
} /* if */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
150 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
151 |
/* free up the bytes we didn't actually use. */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
152 |
ptr = (TCHAR *) realloc(retval, sizeof(TCHAR) * _tcslen(retval) + 1); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
153 |
if (ptr != NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
154 |
retval = ptr; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
155 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
156 |
charretval = UnicodeToAsc(retval); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
157 |
free(retval); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
158 |
if(charretval == NULL) { |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
159 |
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
|
160 |
} |
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 |
return(charretval); /* w00t. */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
163 |
} /* getExePath */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
164 |
|
501 | 165 |
int __PHYSFS_platformInit(void) |
166 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
167 |
userDir = getExePath(); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
168 |
BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */ |
501 | 169 |
return(1); /* always succeed. */ |
170 |
} /* __PHYSFS_platformInit */ |
|
171 |
||
172 |
||
173 |
int __PHYSFS_platformDeinit(void) |
|
174 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
175 |
free(userDir); |
501 | 176 |
return(1); /* always succeed. */ |
177 |
} /* __PHYSFS_platformDeinit */ |
|
178 |
||
179 |
||
180 |
char **__PHYSFS_platformDetectAvailableCDs(void) |
|
181 |
{ |
|
182 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
|
183 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
|
184 |
||
185 |
||
186 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
187 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
188 |
return(getExePath()); |
501 | 189 |
} /* __PHYSFS_platformCalcBaseDir */ |
190 |
||
191 |
||
192 |
char *__PHYSFS_platformGetUserName(void) |
|
193 |
{ |
|
194 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
|
195 |
} /* __PHYSFS_platformGetUserName */ |
|
196 |
||
197 |
||
198 |
char *__PHYSFS_platformGetUserDir(void) |
|
199 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
200 |
return userDir; |
501 | 201 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
202 |
} /* __PHYSFS_platformGetUserDir */ |
|
203 |
||
204 |
||
205 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
|
206 |
{ |
|
207 |
return(1); /* single threaded. */ |
|
208 |
} /* __PHYSFS_platformGetThreadID */ |
|
209 |
||
210 |
||
211 |
int __PHYSFS_platformStricmp(const char *x, const char *y) |
|
212 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
213 |
return(_stricmp(x, y)); |
596
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
214 |
} /* __PHYSFS_platformStricmp */ |
501 | 215 |
|
596
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
216 |
|
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
217 |
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
|
218 |
{ |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
219 |
return(_strnicmp(x, y, (int) len)); |
381b6ca0dd85
Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents:
578
diff
changeset
|
220 |
} /* __PHYSFS_platformStrnicmp */ |
501 | 221 |
|
222 |
||
223 |
int __PHYSFS_platformExists(const char *fname) |
|
224 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
225 |
int retval=0; |
501 | 226 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
227 |
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
|
228 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
229 |
if(w_fname!=NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
230 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
231 |
retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
232 |
free(w_fname); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
233 |
} |
501 | 234 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
235 |
return(retval); |
501 | 236 |
} /* __PHYSFS_platformExists */ |
237 |
||
238 |
||
239 |
int __PHYSFS_platformIsSymLink(const char *fname) |
|
240 |
{ |
|
241 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0); |
|
242 |
} /* __PHYSFS_platformIsSymlink */ |
|
243 |
||
244 |
||
245 |
int __PHYSFS_platformIsDirectory(const char *fname) |
|
246 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
247 |
int retval=0; |
501 | 248 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
249 |
wchar_t *w_fname=AscToUnicode(fname); |
501 | 250 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
251 |
if(w_fname!=NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
252 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
253 |
retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
254 |
free(w_fname); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
255 |
} |
501 | 256 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
257 |
return(retval); |
501 | 258 |
} /* __PHYSFS_platformIsDirectory */ |
259 |
||
260 |
||
261 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
|
262 |
const char *dirName, |
|
263 |
const char *append) |
|
264 |
{ |
|
265 |
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
|
266 |
((append) ? strlen(append) : 0) + |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
267 |
strlen(dirName) + 1; |
501 | 268 |
char *retval = malloc(len); |
269 |
char *p; |
|
270 |
||
271 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
272 |
||
273 |
if (prepend) |
|
274 |
strcpy(retval, prepend); |
|
275 |
else |
|
276 |
retval[0] = '\0'; |
|
277 |
||
278 |
strcat(retval, dirName); |
|
279 |
||
280 |
if (append) |
|
281 |
strcat(retval, append); |
|
282 |
||
283 |
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/')) |
|
284 |
*p = '\\'; |
|
285 |
||
286 |
return(retval); |
|
287 |
} /* __PHYSFS_platformCvtToDependent */ |
|
288 |
||
289 |
||
290 |
void __PHYSFS_platformTimeslice(void) |
|
291 |
{ |
|
292 |
Sleep(10); |
|
293 |
} /* __PHYSFS_platformTimeslice */ |
|
294 |
||
295 |
||
296 |
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname, |
|
297 |
int omitSymLinks) |
|
298 |
{ |
|
299 |
LinkedStringList *retval = NULL; |
|
300 |
LinkedStringList *l = NULL; |
|
301 |
LinkedStringList *prev = NULL; |
|
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); |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
328 |
free(w_SearchPath); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
329 |
free(SearchPath); |
501 | 330 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
331 |
if(dir == INVALID_HANDLE_VALUE) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
332 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
333 |
return NULL; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
334 |
} |
501 | 335 |
|
336 |
do |
|
337 |
{ |
|
338 |
if (wcscmp(ent.cFileName, L".") == 0) |
|
339 |
continue; |
|
340 |
||
341 |
if (wcscmp(ent.cFileName, L"..") == 0) |
|
342 |
continue; |
|
343 |
||
344 |
l = (LinkedStringList *) malloc(sizeof (LinkedStringList)); |
|
345 |
if (l == NULL) |
|
346 |
break; |
|
347 |
||
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
348 |
l->str=UnicodeToAsc(ent.cFileName); |
501 | 349 |
|
350 |
if (l->str == NULL) |
|
351 |
{ |
|
352 |
free(l); |
|
353 |
break; |
|
354 |
} |
|
355 |
||
356 |
||
357 |
if (retval == NULL) |
|
358 |
retval = l; |
|
359 |
else |
|
360 |
prev->next = l; |
|
361 |
||
362 |
prev = l; |
|
363 |
l->next = NULL; |
|
364 |
} while (FindNextFile(dir, &ent) != 0); |
|
365 |
||
366 |
FindClose(dir); |
|
367 |
return(retval); |
|
368 |
} /* __PHYSFS_platformEnumerateFiles */ |
|
369 |
||
370 |
||
371 |
char *__PHYSFS_platformCurrentDir(void) |
|
372 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
373 |
return("\\"); |
501 | 374 |
} /* __PHYSFS_platformCurrentDir */ |
375 |
||
376 |
||
377 |
char *__PHYSFS_platformRealPath(const char *path) |
|
378 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
379 |
char *retval=(char *)malloc(strlen(path)+1); |
501 | 380 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
381 |
strcpy(retval,path); |
501 | 382 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
383 |
return(retval); |
501 | 384 |
|
385 |
} /* __PHYSFS_platformRealPath */ |
|
386 |
||
387 |
||
388 |
int __PHYSFS_platformMkDir(const char *path) |
|
389 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
390 |
wchar_t *w_path = AscToUnicode(path); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
391 |
if(w_path!=NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
392 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
393 |
DWORD rc = CreateDirectory(w_path, NULL); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
394 |
free(w_path); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
395 |
if(rc==0) |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
396 |
{ |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
397 |
return(0); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
398 |
} |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
399 |
return(1); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
400 |
} |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
401 |
else |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
402 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
403 |
return(0); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
404 |
} |
501 | 405 |
} /* __PHYSFS_platformMkDir */ |
406 |
||
407 |
||
408 |
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly) |
|
409 |
{ |
|
410 |
HANDLE fileHandle; |
|
411 |
winCEfile *retval; |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
412 |
wchar_t *w_fname=AscToUnicode(fname); |
501 | 413 |
|
414 |
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL, |
|
415 |
creation, FILE_ATTRIBUTE_NORMAL, NULL); |
|
416 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
417 |
free(w_fname); |
501 | 418 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
419 |
if(fileHandle==INVALID_HANDLE_VALUE) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
420 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
421 |
return NULL; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
422 |
} |
501 | 423 |
|
424 |
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL); |
|
425 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
426 |
retval = malloc(sizeof (winCEfile)); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
427 |
if (retval == NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
428 |
{ |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
429 |
CloseHandle(fileHandle); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
430 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
431 |
} /* if */ |
501 | 432 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
433 |
retval->readonly = rdonly; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
434 |
retval->handle = fileHandle; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
435 |
return(retval); |
501 | 436 |
} /* doOpen */ |
437 |
||
438 |
||
439 |
void *__PHYSFS_platformOpenRead(const char *filename) |
|
440 |
{ |
|
441 |
return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1)); |
|
442 |
} /* __PHYSFS_platformOpenRead */ |
|
443 |
||
444 |
||
445 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
|
446 |
{ |
|
447 |
return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0)); |
|
448 |
} /* __PHYSFS_platformOpenWrite */ |
|
449 |
||
450 |
||
451 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
|
452 |
{ |
|
453 |
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0); |
|
454 |
if (retval != NULL) |
|
455 |
{ |
|
456 |
HANDLE h = ((winCEfile *) retval)->handle; |
|
457 |
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) |
|
458 |
{ |
|
459 |
const char *err = win32strerror(); |
|
460 |
CloseHandle(h); |
|
461 |
free(retval); |
|
462 |
BAIL_MACRO(err, NULL); |
|
463 |
} /* if */ |
|
464 |
} /* if */ |
|
465 |
||
466 |
return(retval); |
|
467 |
||
468 |
} /* __PHYSFS_platformOpenAppend */ |
|
469 |
||
470 |
||
471 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
|
472 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
473 |
{ |
|
474 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle; |
|
475 |
DWORD CountOfBytesRead; |
|
476 |
PHYSFS_sint64 retval; |
|
477 |
||
478 |
/* Read data from the file */ |
|
479 |
/*!!! - uint32 might be a greater # than DWORD */ |
|
480 |
if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL)) |
|
481 |
{ |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
482 |
retval=-1; |
501 | 483 |
} /* if */ |
484 |
else |
|
485 |
{ |
|
486 |
/* Return the number of "objects" read. */ |
|
487 |
/* !!! - What if not the right amount of bytes was read to make an object? */ |
|
488 |
retval = CountOfBytesRead / size; |
|
489 |
} /* else */ |
|
490 |
||
491 |
return(retval); |
|
492 |
||
493 |
} /* __PHYSFS_platformRead */ |
|
494 |
||
495 |
||
496 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
|
497 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
498 |
{ |
|
499 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle; |
|
500 |
DWORD CountOfBytesWritten; |
|
501 |
PHYSFS_sint64 retval; |
|
502 |
||
503 |
/* Read data from the file */ |
|
504 |
/*!!! - uint32 might be a greater # than DWORD */ |
|
505 |
if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL)) |
|
506 |
{ |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
507 |
retval=-1; |
501 | 508 |
} /* if */ |
509 |
else |
|
510 |
{ |
|
511 |
/* Return the number of "objects" read. */ |
|
512 |
/*!!! - What if not the right number of bytes was written? */ |
|
513 |
retval = CountOfBytesWritten / size; |
|
514 |
} /* else */ |
|
515 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
516 |
return(retval); |
501 | 517 |
|
518 |
} /* __PHYSFS_platformWrite */ |
|
519 |
||
520 |
||
521 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
|
522 |
{ |
|
523 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle; |
|
524 |
DWORD HighOrderPos; |
|
525 |
DWORD rc; |
|
526 |
||
527 |
/* Get the high order 32-bits of the position */ |
|
528 |
//HighOrderPos = HIGHORDER_UINT64(pos); |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
529 |
HighOrderPos = (unsigned long)(pos>>32); |
501 | 530 |
|
531 |
/*!!! SetFilePointer needs a signed 64-bit value. */ |
|
532 |
/* Move pointer "pos" count from start of file */ |
|
533 |
rc = SetFilePointer(FileHandle, (unsigned long)(pos&0x00000000ffffffff), |
|
534 |
&HighOrderPos, FILE_BEGIN); |
|
535 |
||
536 |
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
|
537 |
{ |
501 | 538 |
BAIL_MACRO(win32strerror(), 0); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
539 |
} |
501 | 540 |
|
541 |
return(1); /* No error occured */ |
|
542 |
} /* __PHYSFS_platformSeek */ |
|
543 |
||
544 |
||
545 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
|
546 |
{ |
|
547 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle; |
|
548 |
DWORD HighPos = 0; |
|
549 |
DWORD LowPos; |
|
550 |
PHYSFS_sint64 retval; |
|
551 |
||
552 |
/* Get current position */ |
|
553 |
LowPos = SetFilePointer(FileHandle, 0, &HighPos, FILE_CURRENT); |
|
554 |
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
|
555 |
{ |
|
556 |
BAIL_MACRO(win32strerror(), 0); |
|
557 |
} /* if */ |
|
558 |
else |
|
559 |
{ |
|
560 |
/* Combine the high/low order to create the 64-bit position value */ |
|
561 |
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos; |
|
562 |
//assert(retval >= 0); |
|
563 |
} /* else */ |
|
564 |
||
565 |
return(retval); |
|
566 |
} /* __PHYSFS_platformTell */ |
|
567 |
||
568 |
||
569 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
|
570 |
{ |
|
571 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle; |
|
572 |
DWORD SizeHigh; |
|
573 |
DWORD SizeLow; |
|
574 |
PHYSFS_sint64 retval; |
|
575 |
||
576 |
SizeLow = GetFileSize(FileHandle, &SizeHigh); |
|
577 |
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
|
578 |
{ |
|
579 |
BAIL_MACRO(win32strerror(), -1); |
|
580 |
} /* if */ |
|
581 |
else |
|
582 |
{ |
|
583 |
/* Combine the high/low order to create the 64-bit position value */ |
|
584 |
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow; |
|
585 |
//assert(retval >= 0); |
|
586 |
} /* else */ |
|
587 |
||
588 |
return(retval); |
|
589 |
} /* __PHYSFS_platformFileLength */ |
|
590 |
||
591 |
||
592 |
int __PHYSFS_platformEOF(void *opaque) |
|
593 |
{ |
|
594 |
PHYSFS_sint64 FilePosition; |
|
595 |
int retval = 0; |
|
596 |
||
597 |
/* Get the current position in the file */ |
|
598 |
if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0) |
|
599 |
{ |
|
600 |
/* Non-zero if EOF is equal to the file length */ |
|
601 |
retval = FilePosition == __PHYSFS_platformFileLength(opaque); |
|
602 |
} /* if */ |
|
603 |
||
604 |
return(retval); |
|
605 |
} /* __PHYSFS_platformEOF */ |
|
606 |
||
607 |
||
608 |
int __PHYSFS_platformFlush(void *opaque) |
|
609 |
{ |
|
610 |
winCEfile *fh = ((winCEfile *) opaque); |
|
611 |
if (!fh->readonly) |
|
612 |
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0); |
|
613 |
||
614 |
return(1); |
|
615 |
} /* __PHYSFS_platformFlush */ |
|
616 |
||
617 |
||
618 |
int __PHYSFS_platformClose(void *opaque) |
|
619 |
{ |
|
620 |
HANDLE FileHandle = ((winCEfile *) opaque)->handle; |
|
621 |
BAIL_IF_MACRO(!CloseHandle(FileHandle), win32strerror(), 0); |
|
622 |
free(opaque); |
|
623 |
return(1); |
|
624 |
} /* __PHYSFS_platformClose */ |
|
625 |
||
626 |
||
627 |
int __PHYSFS_platformDelete(const char *path) |
|
628 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
629 |
wchar_t *w_path=AscToUnicode(path); |
501 | 630 |
|
631 |
/* If filename is a folder */ |
|
632 |
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY) |
|
633 |
{ |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
634 |
int retval=!RemoveDirectory(w_path); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
635 |
free(w_path); |
501 | 636 |
BAIL_IF_MACRO(retval, win32strerror(), 0); |
637 |
} /* if */ |
|
638 |
else |
|
639 |
{ |
|
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
640 |
int retval=!DeleteFile(w_path); |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
641 |
free(w_path); |
501 | 642 |
BAIL_IF_MACRO(retval, win32strerror(), 0); |
643 |
} /* else */ |
|
644 |
||
645 |
return(1); /* if you got here, it worked. */ |
|
646 |
} /* __PHYSFS_platformDelete */ |
|
647 |
||
648 |
||
649 |
void *__PHYSFS_platformCreateMutex(void) |
|
650 |
{ |
|
651 |
return((void *) CreateMutex(NULL, FALSE, NULL)); |
|
652 |
} /* __PHYSFS_platformCreateMutex */ |
|
653 |
||
654 |
||
655 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
656 |
{ |
|
657 |
CloseHandle((HANDLE) mutex); |
|
658 |
} /* __PHYSFS_platformDestroyMutex */ |
|
659 |
||
660 |
||
661 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
662 |
{ |
|
663 |
return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED); |
|
664 |
} /* __PHYSFS_platformGrabMutex */ |
|
665 |
||
666 |
||
667 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
668 |
{ |
|
669 |
ReleaseMutex((HANDLE) mutex); |
|
670 |
} /* __PHYSFS_platformReleaseMutex */ |
|
671 |
||
672 |
||
673 |
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) |
|
674 |
{ |
|
675 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1); |
|
676 |
} /* __PHYSFS_platformGetLastModTime */ |
|
677 |
||
678 |
/* end of skeleton.c ... */ |
|
679 |