author | Ryan C. Gordon <icculus@icculus.org> |
Mon, 01 Aug 2011 17:52:51 -0400 | |
branch | stable-2.0 |
changeset 1178 | dec7e09cb3d9 |
parent 1175 | e55bbdb69dfd |
child 1294 | 184697ee7a77 |
permissions | -rw-r--r-- |
501 | 1 |
/* |
810 | 2 |
* PocketPC support routines for PhysicsFS. |
501 | 3 |
* |
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
4 |
* Please see the file LICENSE.txt in the source's root directory. |
501 | 5 |
* |
6 |
* This file written by Ryan C. Gordon. |
|
7 |
*/ |
|
8 |
||
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
9 |
#define __PHYSICSFS_INTERNAL__ |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
10 |
#include "physfs_platforms.h" |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
11 |
|
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
12 |
#ifdef PHYSFS_PLATFORM_POCKETPC |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
13 |
|
501 | 14 |
#include <stdio.h> |
15 |
#include <windows.h> |
|
16 |
||
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 |
||
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
67 |
|
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
68 |
/* !!! FIXME: need to check all of these for NULLs. */ |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
69 |
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
70 |
if (str == NULL) \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
71 |
w_assignto = NULL; \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
72 |
else { \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
73 |
const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
74 |
w_assignto = (char *) __PHYSFS_smallAlloc(len); \ |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
75 |
PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
76 |
} \ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
77 |
} \ |
501 | 78 |
|
79 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
80 |
static char *getExePath() |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
81 |
{ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
82 |
DWORD buflen; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
83 |
int success = 0; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
84 |
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
|
85 |
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
|
86 |
char *charretval; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
87 |
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
|
88 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
89 |
retval[0] = _T('\0'); |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
90 |
/* !!! FIXME: don't preallocate here? */ |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
91 |
/* !!! FIXME: use smallAlloc? */ |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
92 |
buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1); |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
93 |
if (buflen <= 0) |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
94 |
__PHYSFS_setError(win32strerror()); |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
95 |
else |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
96 |
{ |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
97 |
retval[buflen] = '\0'; /* does API always null-terminate this? */ |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
98 |
ptr = retval+buflen; |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
99 |
while( ptr != retval ) |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
100 |
{ |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
101 |
if( *ptr != _T('\\') ) |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
102 |
*ptr-- = _T('\0'); |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
103 |
else |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
104 |
break; |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
105 |
} /* while */ |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
106 |
success = 1; |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
107 |
} /* else */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
108 |
|
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
109 |
if (!success) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
110 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
111 |
allocator.Free(retval); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
112 |
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
|
113 |
} /* if */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
114 |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
115 |
buflen = (buflen * 4) + 1; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
116 |
charretval = (char *) allocator.Malloc(buflen); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
117 |
if (charretval != NULL) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
118 |
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) retval, charretval, buflen); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
119 |
allocator.Free(retval); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
120 |
return(charretval); /* w00t. */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
121 |
} /* getExePath */ |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
122 |
|
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
123 |
|
501 | 124 |
int __PHYSFS_platformInit(void) |
125 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
126 |
userDir = getExePath(); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
127 |
BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */ |
501 | 128 |
return(1); /* always succeed. */ |
129 |
} /* __PHYSFS_platformInit */ |
|
130 |
||
131 |
||
132 |
int __PHYSFS_platformDeinit(void) |
|
133 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
134 |
allocator.Free(userDir); |
501 | 135 |
return(1); /* always succeed. */ |
136 |
} /* __PHYSFS_platformDeinit */ |
|
137 |
||
138 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
139 |
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) |
501 | 140 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
141 |
/* no-op on this platform. */ |
501 | 142 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
143 |
||
144 |
||
145 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
146 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
147 |
return(getExePath()); |
501 | 148 |
} /* __PHYSFS_platformCalcBaseDir */ |
149 |
||
150 |
||
151 |
char *__PHYSFS_platformGetUserName(void) |
|
152 |
{ |
|
153 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
|
154 |
} /* __PHYSFS_platformGetUserName */ |
|
155 |
||
156 |
||
157 |
char *__PHYSFS_platformGetUserDir(void) |
|
158 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
159 |
return userDir; |
501 | 160 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); |
161 |
} /* __PHYSFS_platformGetUserDir */ |
|
162 |
||
163 |
||
164 |
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) |
|
165 |
{ |
|
166 |
return(1); /* single threaded. */ |
|
167 |
} /* __PHYSFS_platformGetThreadID */ |
|
168 |
||
169 |
||
170 |
int __PHYSFS_platformExists(const char *fname) |
|
171 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
172 |
int retval = 0; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
173 |
wchar_t *w_fname = NULL; |
501 | 174 |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
175 |
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
176 |
if (w_fname != NULL) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
177 |
retval = (GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
178 |
__PHYSFS_smallFree(w_fname); |
501 | 179 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
180 |
return(retval); |
501 | 181 |
} /* __PHYSFS_platformExists */ |
182 |
||
183 |
||
184 |
int __PHYSFS_platformIsSymLink(const char *fname) |
|
185 |
{ |
|
186 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0); |
|
187 |
} /* __PHYSFS_platformIsSymlink */ |
|
188 |
||
189 |
||
190 |
int __PHYSFS_platformIsDirectory(const char *fname) |
|
191 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
192 |
int retval = 0; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
193 |
wchar_t *w_fname = NULL; |
501 | 194 |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
195 |
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
196 |
if (w_fname != NULL) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
197 |
retval = ((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
198 |
__PHYSFS_smallFree(w_fname); |
501 | 199 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
200 |
return(retval); |
501 | 201 |
} /* __PHYSFS_platformIsDirectory */ |
202 |
||
203 |
||
204 |
char *__PHYSFS_platformCvtToDependent(const char *prepend, |
|
205 |
const char *dirName, |
|
206 |
const char *append) |
|
207 |
{ |
|
208 |
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
|
209 |
((append) ? strlen(append) : 0) + |
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
210 |
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
|
211 |
char *retval = (char *) allocator.Malloc(len); |
501 | 212 |
char *p; |
213 |
||
214 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
|
215 |
||
216 |
if (prepend) |
|
217 |
strcpy(retval, prepend); |
|
218 |
else |
|
219 |
retval[0] = '\0'; |
|
220 |
||
221 |
strcat(retval, dirName); |
|
222 |
||
223 |
if (append) |
|
224 |
strcat(retval, append); |
|
225 |
||
226 |
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/')) |
|
227 |
*p = '\\'; |
|
228 |
||
229 |
return(retval); |
|
230 |
} /* __PHYSFS_platformCvtToDependent */ |
|
231 |
||
232 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
233 |
static int doEnumCallback(const wchar_t *w_fname) |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
234 |
{ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
235 |
const PHYSFS_uint64 len = (PHYSFS_uint64) ((wcslen(w_fname) * 4) + 1); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
236 |
char *str = (char *) __PHYSFS_smallAlloc(len); |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
237 |
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) w_fname, str, len); |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
238 |
callback(callbackdata, origdir, str); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
239 |
__PHYSFS_smallFree(str); |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
240 |
return 1; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
241 |
} /* doEnumCallback */ |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
242 |
|
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
243 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
244 |
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
|
245 |
int omitSymLinks, |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
246 |
PHYSFS_EnumFilesCallback callback, |
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
247 |
const char *origdir, |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
248 |
void *callbackdata) |
501 | 249 |
{ |
250 |
HANDLE dir; |
|
251 |
WIN32_FIND_DATA ent; |
|
252 |
char *SearchPath; |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
253 |
wchar_t *w_SearchPath; |
501 | 254 |
size_t len = strlen(dirname); |
255 |
||
256 |
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */ |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
257 |
SearchPath = (char *) __PHYSFS_smallAlloc(len + 3); |
578
bff1af8455ca
Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
258 |
BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL); |
501 | 259 |
|
260 |
/* Copy current dirname */ |
|
261 |
strcpy(SearchPath, dirname); |
|
262 |
||
263 |
/* if there's no '\\' at the end of the path, stick one in there. */ |
|
264 |
if (SearchPath[len - 1] != '\\') |
|
265 |
{ |
|
266 |
SearchPath[len++] = '\\'; |
|
267 |
SearchPath[len] = '\0'; |
|
268 |
} /* if */ |
|
269 |
||
270 |
/* Append the "*" to the end of the string */ |
|
271 |
strcat(SearchPath, "*"); |
|
272 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
273 |
UTF8_TO_UNICODE_STACK_MACRO(w_SearchPath, SearchPath); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
274 |
__PHYSFS_smallFree(SearchPath); |
501 | 275 |
dir = FindFirstFile(w_SearchPath, &ent); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
276 |
__PHYSFS_smallFree(w_SearchPath); |
501 | 277 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
278 |
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
|
279 |
return; |
501 | 280 |
|
281 |
do |
|
282 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
283 |
const char *str = NULL; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
284 |
|
501 | 285 |
if (wcscmp(ent.cFileName, L".") == 0) |
286 |
continue; |
|
287 |
||
288 |
if (wcscmp(ent.cFileName, L"..") == 0) |
|
289 |
continue; |
|
290 |
||
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
291 |
if (!doEnumCallback(ent.cFileName)) |
501 | 292 |
break; |
293 |
} while (FindNextFile(dir, &ent) != 0); |
|
294 |
||
295 |
FindClose(dir); |
|
296 |
} /* __PHYSFS_platformEnumerateFiles */ |
|
297 |
||
298 |
||
299 |
char *__PHYSFS_platformCurrentDir(void) |
|
300 |
{ |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
301 |
return("\\"); |
501 | 302 |
} /* __PHYSFS_platformCurrentDir */ |
303 |
||
304 |
||
305 |
char *__PHYSFS_platformRealPath(const char *path) |
|
306 |
{ |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
307 |
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
|
308 |
strcpy(retval,path); |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
309 |
return(retval); |
501 | 310 |
} /* __PHYSFS_platformRealPath */ |
311 |
||
312 |
||
313 |
int __PHYSFS_platformMkDir(const char *path) |
|
314 |
{ |
|
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
315 |
int retval = 0; |
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
316 |
wchar_t *w_path = NULL; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
317 |
UTF8_TO_UNICODE_STACK_MACRO(w_path, path); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
318 |
if (w_path != NULL) |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
319 |
{ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
320 |
retval = CreateDirectory(w_path, NULL); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
321 |
__PHYSFS_smallFree(w_fname); |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
322 |
} /* if */ |
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
323 |
return(retval); |
501 | 324 |
} /* __PHYSFS_platformMkDir */ |
325 |
||
326 |
||
327 |
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly) |
|
328 |
{ |
|
329 |
HANDLE fileHandle; |
|
330 |
winCEfile *retval; |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
331 |
wchar_t *w_fname = NULL; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
332 |
|
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
333 |
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname); |
1068
a94dfe3d3121
Backport of Windows file sharing fix from default branch.
Ryan C. Gordon <icculus@icculus.org>
parents:
853
diff
changeset
|
334 |
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, |
a94dfe3d3121
Backport of Windows file sharing fix from default branch.
Ryan C. Gordon <icculus@icculus.org>
parents:
853
diff
changeset
|
335 |
NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
336 |
__PHYSFS_smallFree(w_fname); |
501 | 337 |
|
338 |
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL); |
|
339 |
||
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
340 |
retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile)); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
341 |
if (retval == NULL) |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
342 |
{ |
792
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
343 |
CloseHandle(fileHandle); |
4c278733e281
Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents:
763
diff
changeset
|
344 |
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
345 |
} /* if */ |
501 | 346 |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
347 |
retval->readonly = rdonly; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
348 |
retval->handle = fileHandle; |
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
349 |
return(retval); |
501 | 350 |
} /* doOpen */ |
351 |
||
352 |
||
353 |
void *__PHYSFS_platformOpenRead(const char *filename) |
|
354 |
{ |
|
355 |
return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1)); |
|
356 |
} /* __PHYSFS_platformOpenRead */ |
|
357 |
||
358 |
||
359 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
|
360 |
{ |
|
361 |
return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0)); |
|
362 |
} /* __PHYSFS_platformOpenWrite */ |
|
363 |
||
364 |
||
365 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
|
366 |
{ |
|
367 |
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0); |
|
368 |
if (retval != NULL) |
|
369 |
{ |
|
370 |
HANDLE h = ((winCEfile *) retval)->handle; |
|
371 |
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) |
|
372 |
{ |
|
373 |
const char *err = win32strerror(); |
|
374 |
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
|
375 |
allocator.Free(retval); |
501 | 376 |
BAIL_MACRO(err, NULL); |
377 |
} /* if */ |
|
378 |
} /* if */ |
|
379 |
||
380 |
return(retval); |
|
381 |
||
382 |
} /* __PHYSFS_platformOpenAppend */ |
|
383 |
||
384 |
||
385 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, |
|
386 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
387 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
388 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 389 |
DWORD CountOfBytesRead; |
390 |
PHYSFS_sint64 retval; |
|
391 |
||
392 |
/* Read data from the file */ |
|
393 |
/*!!! - 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
|
394 |
if (!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL)) |
501 | 395 |
{ |
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
396 |
retval = -1; |
501 | 397 |
} /* if */ |
398 |
else |
|
399 |
{ |
|
400 |
/* Return the number of "objects" read. */ |
|
401 |
/* !!! - What if not the right amount of bytes was read to make an object? */ |
|
402 |
retval = CountOfBytesRead / size; |
|
403 |
} /* else */ |
|
404 |
||
405 |
return(retval); |
|
406 |
||
407 |
} /* __PHYSFS_platformRead */ |
|
408 |
||
409 |
||
410 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
|
411 |
PHYSFS_uint32 size, PHYSFS_uint32 count) |
|
412 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
413 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 414 |
DWORD CountOfBytesWritten; |
415 |
PHYSFS_sint64 retval; |
|
416 |
||
417 |
/* Read data from the file */ |
|
418 |
/*!!! - 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
|
419 |
if (!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL)) |
501 | 420 |
{ |
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
421 |
retval = -1; |
501 | 422 |
} /* if */ |
423 |
else |
|
424 |
{ |
|
425 |
/* Return the number of "objects" read. */ |
|
426 |
/*!!! - What if not the right number of bytes was written? */ |
|
427 |
retval = CountOfBytesWritten / size; |
|
428 |
} /* else */ |
|
429 |
||
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
430 |
return(retval); |
501 | 431 |
|
432 |
} /* __PHYSFS_platformWrite */ |
|
433 |
||
434 |
||
435 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
|
436 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
437 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 438 |
DWORD HighOrderPos; |
439 |
DWORD rc; |
|
440 |
||
441 |
/* Get the high order 32-bits of the position */ |
|
442 |
//HighOrderPos = HIGHORDER_UINT64(pos); |
|
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
443 |
HighOrderPos = (unsigned long)(pos>>32); |
501 | 444 |
|
445 |
/*!!! SetFilePointer needs a signed 64-bit value. */ |
|
446 |
/* 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
|
447 |
rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff), |
501 | 448 |
&HighOrderPos, FILE_BEGIN); |
449 |
||
450 |
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
|
451 |
{ |
501 | 452 |
BAIL_MACRO(win32strerror(), 0); |
566
1e640d4acab9
PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents:
501
diff
changeset
|
453 |
} |
501 | 454 |
|
455 |
return(1); /* No error occured */ |
|
456 |
} /* __PHYSFS_platformSeek */ |
|
457 |
||
458 |
||
459 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
|
460 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
461 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 462 |
DWORD HighPos = 0; |
463 |
DWORD LowPos; |
|
464 |
PHYSFS_sint64 retval; |
|
465 |
||
466 |
/* 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
|
467 |
LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT); |
501 | 468 |
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
469 |
{ |
|
1178
dec7e09cb3d9
Fixed some __PHYSFS_platformTell() things in stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents:
1175
diff
changeset
|
470 |
BAIL_MACRO(win32strerror(), -1); |
501 | 471 |
} /* if */ |
472 |
else |
|
473 |
{ |
|
474 |
/* Combine the high/low order to create the 64-bit position value */ |
|
475 |
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos; |
|
476 |
//assert(retval >= 0); |
|
477 |
} /* else */ |
|
478 |
||
479 |
return(retval); |
|
480 |
} /* __PHYSFS_platformTell */ |
|
481 |
||
482 |
||
483 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
|
484 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
485 |
HANDLE Handle = ((winCEfile *) opaque)->handle; |
501 | 486 |
DWORD SizeHigh; |
487 |
DWORD SizeLow; |
|
488 |
PHYSFS_sint64 retval; |
|
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 |
SizeLow = GetFileSize(Handle, &SizeHigh); |
501 | 491 |
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR)) |
492 |
{ |
|
493 |
BAIL_MACRO(win32strerror(), -1); |
|
494 |
} /* if */ |
|
495 |
else |
|
496 |
{ |
|
497 |
/* Combine the high/low order to create the 64-bit position value */ |
|
498 |
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow; |
|
499 |
//assert(retval >= 0); |
|
500 |
} /* else */ |
|
501 |
||
502 |
return(retval); |
|
503 |
} /* __PHYSFS_platformFileLength */ |
|
504 |
||
505 |
||
506 |
int __PHYSFS_platformEOF(void *opaque) |
|
507 |
{ |
|
1175
e55bbdb69dfd
Fixed Windows/PocketPC __PHYSFS_platformEOF() for zero-length files.
Ryan C. Gordon <icculus@icculus.org>
parents:
1068
diff
changeset
|
508 |
const PHYSFS_sint64 FileLength = __PHYSFS_platformFileLength(opaque); |
501 | 509 |
PHYSFS_sint64 FilePosition; |
510 |
int retval = 0; |
|
511 |
||
1175
e55bbdb69dfd
Fixed Windows/PocketPC __PHYSFS_platformEOF() for zero-length files.
Ryan C. Gordon <icculus@icculus.org>
parents:
1068
diff
changeset
|
512 |
if (FileLength == 0) |
e55bbdb69dfd
Fixed Windows/PocketPC __PHYSFS_platformEOF() for zero-length files.
Ryan C. Gordon <icculus@icculus.org>
parents:
1068
diff
changeset
|
513 |
return 1; /* we're definitely at EOF. */ |
e55bbdb69dfd
Fixed Windows/PocketPC __PHYSFS_platformEOF() for zero-length files.
Ryan C. Gordon <icculus@icculus.org>
parents:
1068
diff
changeset
|
514 |
|
501 | 515 |
/* Get the current position in the file */ |
1178
dec7e09cb3d9
Fixed some __PHYSFS_platformTell() things in stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents:
1175
diff
changeset
|
516 |
if ((FilePosition = __PHYSFS_platformTell(opaque)) != -1) |
501 | 517 |
{ |
518 |
/* Non-zero if EOF is equal to the file length */ |
|
1175
e55bbdb69dfd
Fixed Windows/PocketPC __PHYSFS_platformEOF() for zero-length files.
Ryan C. Gordon <icculus@icculus.org>
parents:
1068
diff
changeset
|
519 |
retval = (FilePosition == FileLength); |
501 | 520 |
} /* if */ |
521 |
||
522 |
return(retval); |
|
523 |
} /* __PHYSFS_platformEOF */ |
|
524 |
||
525 |
||
526 |
int __PHYSFS_platformFlush(void *opaque) |
|
527 |
{ |
|
528 |
winCEfile *fh = ((winCEfile *) opaque); |
|
529 |
if (!fh->readonly) |
|
530 |
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0); |
|
531 |
||
532 |
return(1); |
|
533 |
} /* __PHYSFS_platformFlush */ |
|
534 |
||
535 |
||
536 |
int __PHYSFS_platformClose(void *opaque) |
|
537 |
{ |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
538 |
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
|
539 |
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
|
540 |
allocator.Free(opaque); |
501 | 541 |
return(1); |
542 |
} /* __PHYSFS_platformClose */ |
|
543 |
||
544 |
||
545 |
int __PHYSFS_platformDelete(const char *path) |
|
546 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
547 |
wchar_t *w_path = NULL; |
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
548 |
UTF8_TO_UNICODE_STACK_MACRO(w_path, path); |
501 | 549 |
|
550 |
/* If filename is a folder */ |
|
551 |
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY) |
|
552 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
553 |
int retval = !RemoveDirectory(w_path); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
554 |
__PHYSFS_smallFree(w_path); |
501 | 555 |
BAIL_IF_MACRO(retval, win32strerror(), 0); |
556 |
} /* if */ |
|
557 |
else |
|
558 |
{ |
|
793
c75c9498c001
Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
792
diff
changeset
|
559 |
int retval = !DeleteFile(w_path); |
852
9467e96abdf1
Replaced some Malloc and all the alloca() calls with __PHYSFS_smallAlloc(),
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
560 |
__PHYSFS_smallFree(w_path); |
501 | 561 |
BAIL_IF_MACRO(retval, win32strerror(), 0); |
562 |
} /* else */ |
|
563 |
||
564 |
return(1); /* if you got here, it worked. */ |
|
565 |
} /* __PHYSFS_platformDelete */ |
|
566 |
||
567 |
||
853
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
568 |
/* |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
569 |
* !!! FIXME: why aren't we using Critical Sections instead of Mutexes? |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
570 |
* !!! FIXME: mutexes on Windows are for cross-process sync. CritSects are |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
571 |
* !!! FIXME: mutexes for threads in a single process and are faster. |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
572 |
*/ |
501 | 573 |
void *__PHYSFS_platformCreateMutex(void) |
574 |
{ |
|
575 |
return((void *) CreateMutex(NULL, FALSE, NULL)); |
|
576 |
} /* __PHYSFS_platformCreateMutex */ |
|
577 |
||
578 |
||
579 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
580 |
{ |
|
581 |
CloseHandle((HANDLE) mutex); |
|
582 |
} /* __PHYSFS_platformDestroyMutex */ |
|
583 |
||
584 |
||
585 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
586 |
{ |
|
587 |
return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED); |
|
588 |
} /* __PHYSFS_platformGrabMutex */ |
|
589 |
||
590 |
||
591 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
592 |
{ |
|
593 |
ReleaseMutex((HANDLE) mutex); |
|
594 |
} /* __PHYSFS_platformReleaseMutex */ |
|
595 |
||
596 |
||
597 |
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) |
|
598 |
{ |
|
599 |
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1); |
|
600 |
} /* __PHYSFS_platformGetLastModTime */ |
|
601 |
||
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
602 |
|
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
603 |
/* !!! FIXME: Don't use C runtime for allocators? */ |
845
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
604 |
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) |
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 |
{ |
845
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
606 |
return(0); /* just use malloc() and friends. */ |
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
607 |
} /* __PHYSFS_platformSetDefaultAllocator */ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
608 |
|
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
609 |
#endif /* PHYSFS_PLATFORM_POCKETPC */ |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
610 |
|
673
983fb6750fdd
Fixed incorrect comment.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
611 |
/* end of pocketpc.c ... */ |
501 | 612 |