2002-11-22 07:17:59 +01:00
|
|
|
/*
|
2007-03-11 11:12:39 +01:00
|
|
|
* PocketPC support routines for PhysicsFS.
|
2002-11-22 07:17:59 +01:00
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2002-11-22 07:17:59 +01:00
|
|
|
*
|
|
|
|
* This file written by Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
2007-03-11 23:50:53 +01:00
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_platforms.h"
|
|
|
|
|
|
|
|
#ifdef PHYSFS_PLATFORM_POCKETPC
|
|
|
|
|
2002-11-22 07:17:59 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
2003-07-20 23:08:24 +02:00
|
|
|
#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
|
|
|
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
|
2002-11-22 07:17:59 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
int readonly;
|
|
|
|
} winCEfile;
|
|
|
|
|
|
|
|
|
|
|
|
const char *__PHYSFS_platformDirSeparator = "\\";
|
2003-05-18 09:52:28 +02:00
|
|
|
static char *userDir = NULL;
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out what the last failing Win32 API call was, and
|
|
|
|
* generate a human-readable string for the error message.
|
|
|
|
*
|
|
|
|
* The return value is a static buffer that is overwritten with
|
|
|
|
* each call to this function.
|
|
|
|
*/
|
|
|
|
static const char *win32strerror(void)
|
|
|
|
{
|
|
|
|
static TCHAR msgbuf[255];
|
|
|
|
TCHAR *ptr = msgbuf;
|
|
|
|
|
|
|
|
FormatMessage(
|
2003-07-20 23:08:24 +02:00
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
|
|
|
|
msgbuf,
|
|
|
|
sizeof (msgbuf) / sizeof (TCHAR),
|
|
|
|
NULL
|
|
|
|
);
|
2003-05-18 09:52:28 +02:00
|
|
|
|
|
|
|
/* chop off newlines. */
|
2002-11-22 07:17:59 +01:00
|
|
|
for (ptr = msgbuf; *ptr; ptr++)
|
|
|
|
{
|
|
|
|
if ((*ptr == '\n') || (*ptr == '\r'))
|
|
|
|
{
|
|
|
|
*ptr = ' ';
|
|
|
|
break;
|
|
|
|
} /* if */
|
|
|
|
} /* for */
|
|
|
|
|
|
|
|
return((const char *) msgbuf);
|
|
|
|
} /* win32strerror */
|
|
|
|
|
2007-03-24 04:54:58 +01:00
|
|
|
|
|
|
|
/* !!! FIXME: need to check all of these for NULLs. */
|
2007-03-09 09:15:47 +01:00
|
|
|
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
|
|
|
|
if (str == NULL) \
|
|
|
|
w_assignto = NULL; \
|
|
|
|
else { \
|
|
|
|
const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \
|
2007-03-24 04:54:58 +01:00
|
|
|
w_assignto = (char *) __PHYSFS_smallAlloc(len); \
|
2007-03-09 09:15:47 +01:00
|
|
|
PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \
|
|
|
|
} \
|
|
|
|
} \
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
|
2003-05-18 09:52:28 +02:00
|
|
|
static char *getExePath()
|
|
|
|
{
|
|
|
|
DWORD buflen;
|
|
|
|
int success = 0;
|
|
|
|
TCHAR *ptr = NULL;
|
2005-03-14 12:49:30 +01:00
|
|
|
TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
|
2003-05-18 09:52:28 +02:00
|
|
|
char *charretval;
|
|
|
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
|
|
|
|
|
|
|
retval[0] = _T('\0');
|
2007-03-09 09:15:47 +01:00
|
|
|
/* !!! FIXME: don't preallocate here? */
|
2007-03-24 04:54:58 +01:00
|
|
|
/* !!! FIXME: use smallAlloc? */
|
2003-05-18 09:52:28 +02:00
|
|
|
buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
|
2007-03-08 23:37:51 +01:00
|
|
|
if (buflen <= 0)
|
2003-05-18 09:52:28 +02:00
|
|
|
__PHYSFS_setError(win32strerror());
|
2007-03-08 23:37:51 +01:00
|
|
|
else
|
2003-07-20 23:08:24 +02:00
|
|
|
{
|
2007-03-08 23:37:51 +01:00
|
|
|
retval[buflen] = '\0'; /* does API always null-terminate this? */
|
|
|
|
ptr = retval+buflen;
|
|
|
|
while( ptr != retval )
|
|
|
|
{
|
|
|
|
if( *ptr != _T('\\') )
|
|
|
|
*ptr-- = _T('\0');
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} /* while */
|
|
|
|
success = 1;
|
2003-05-18 09:52:28 +02:00
|
|
|
} /* else */
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(retval);
|
2003-05-18 09:52:28 +02:00
|
|
|
return(NULL); /* physfs error message will be set, above. */
|
|
|
|
} /* if */
|
|
|
|
|
2007-03-09 09:15:47 +01:00
|
|
|
buflen = (buflen * 4) + 1;
|
|
|
|
charretval = (char *) allocator.Malloc(buflen);
|
|
|
|
if (charretval != NULL)
|
|
|
|
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) retval, charretval, buflen);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(retval);
|
2003-05-18 09:52:28 +02:00
|
|
|
return(charretval); /* w00t. */
|
|
|
|
} /* getExePath */
|
|
|
|
|
2007-03-08 23:37:51 +01:00
|
|
|
|
2002-11-22 07:17:59 +01:00
|
|
|
int __PHYSFS_platformInit(void)
|
|
|
|
{
|
2003-05-18 09:52:28 +02:00
|
|
|
userDir = getExePath();
|
|
|
|
BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
|
2002-11-22 07:17:59 +01:00
|
|
|
return(1); /* always succeed. */
|
|
|
|
} /* __PHYSFS_platformInit */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformDeinit(void)
|
|
|
|
{
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(userDir);
|
2002-11-22 07:17:59 +01:00
|
|
|
return(1); /* always succeed. */
|
|
|
|
} /* __PHYSFS_platformDeinit */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
|
2002-11-22 07:17:59 +01:00
|
|
|
{
|
2004-09-29 08:09:29 +02:00
|
|
|
/* no-op on this platform. */
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformDetectAvailableCDs */
|
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
|
|
|
{
|
2003-05-18 09:52:28 +02:00
|
|
|
return(getExePath());
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformCalcBaseDir */
|
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformGetUserName(void)
|
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
|
|
|
|
} /* __PHYSFS_platformGetUserName */
|
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformGetUserDir(void)
|
|
|
|
{
|
2003-05-18 09:52:28 +02:00
|
|
|
return userDir;
|
2002-11-22 07:17:59 +01:00
|
|
|
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
|
|
|
|
} /* __PHYSFS_platformGetUserDir */
|
|
|
|
|
|
|
|
|
|
|
|
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
|
|
|
|
{
|
|
|
|
return(1); /* single threaded. */
|
|
|
|
} /* __PHYSFS_platformGetThreadID */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformExists(const char *fname)
|
|
|
|
{
|
2007-03-09 09:15:47 +01:00
|
|
|
int retval = 0;
|
|
|
|
wchar_t *w_fname = NULL;
|
2002-11-22 07:17:59 +01:00
|
|
|
|
2007-03-09 09:15:47 +01:00
|
|
|
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
|
|
|
|
if (w_fname != NULL)
|
|
|
|
retval = (GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(w_fname);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
2003-05-18 09:52:28 +02:00
|
|
|
return(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformExists */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformIsSymLink(const char *fname)
|
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
|
|
|
|
} /* __PHYSFS_platformIsSymlink */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformIsDirectory(const char *fname)
|
|
|
|
{
|
2007-03-09 09:15:47 +01:00
|
|
|
int retval = 0;
|
|
|
|
wchar_t *w_fname = NULL;
|
2002-11-22 07:17:59 +01:00
|
|
|
|
2007-03-09 09:15:47 +01:00
|
|
|
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
|
|
|
|
if (w_fname != NULL)
|
|
|
|
retval = ((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(w_fname);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
2003-05-18 09:52:28 +02:00
|
|
|
return(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformIsDirectory */
|
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
|
|
|
const char *dirName,
|
|
|
|
const char *append)
|
|
|
|
{
|
|
|
|
int len = ((prepend) ? strlen(prepend) : 0) +
|
2003-07-20 23:08:24 +02:00
|
|
|
((append) ? strlen(append) : 0) +
|
|
|
|
strlen(dirName) + 1;
|
2005-03-14 12:49:30 +01:00
|
|
|
char *retval = (char *) allocator.Malloc(len);
|
2002-11-22 07:17:59 +01:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
|
|
|
|
|
|
|
if (prepend)
|
|
|
|
strcpy(retval, prepend);
|
|
|
|
else
|
|
|
|
retval[0] = '\0';
|
|
|
|
|
|
|
|
strcat(retval, dirName);
|
|
|
|
|
|
|
|
if (append)
|
|
|
|
strcat(retval, append);
|
|
|
|
|
|
|
|
for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
|
|
|
|
*p = '\\';
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} /* __PHYSFS_platformCvtToDependent */
|
|
|
|
|
|
|
|
|
2007-03-09 09:15:47 +01:00
|
|
|
static int doEnumCallback(const wchar_t *w_fname)
|
|
|
|
{
|
|
|
|
const PHYSFS_uint64 len = (PHYSFS_uint64) ((wcslen(w_fname) * 4) + 1);
|
2007-03-24 04:54:58 +01:00
|
|
|
char *str = (char *) __PHYSFS_smallAlloc(len);
|
2007-03-09 09:15:47 +01:00
|
|
|
PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) w_fname, str, len);
|
|
|
|
callback(callbackdata, origdir, str);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(str);
|
2007-03-09 09:15:47 +01:00
|
|
|
return 1;
|
|
|
|
} /* doEnumCallback */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
|
|
|
int omitSymLinks,
|
2005-09-18 23:44:42 +02:00
|
|
|
PHYSFS_EnumFilesCallback callback,
|
|
|
|
const char *origdir,
|
2004-09-29 08:09:29 +02:00
|
|
|
void *callbackdata)
|
2002-11-22 07:17:59 +01:00
|
|
|
{
|
|
|
|
HANDLE dir;
|
|
|
|
WIN32_FIND_DATA ent;
|
|
|
|
char *SearchPath;
|
2003-05-18 09:52:28 +02:00
|
|
|
wchar_t *w_SearchPath;
|
2002-11-22 07:17:59 +01:00
|
|
|
size_t len = strlen(dirname);
|
|
|
|
|
|
|
|
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
|
2007-03-24 04:54:58 +01:00
|
|
|
SearchPath = (char *) __PHYSFS_smallAlloc(len + 3);
|
2003-07-20 23:08:24 +02:00
|
|
|
BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
/* Copy current dirname */
|
|
|
|
strcpy(SearchPath, dirname);
|
|
|
|
|
|
|
|
/* if there's no '\\' at the end of the path, stick one in there. */
|
|
|
|
if (SearchPath[len - 1] != '\\')
|
|
|
|
{
|
|
|
|
SearchPath[len++] = '\\';
|
|
|
|
SearchPath[len] = '\0';
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
/* Append the "*" to the end of the string */
|
|
|
|
strcat(SearchPath, "*");
|
|
|
|
|
2007-03-09 09:15:47 +01:00
|
|
|
UTF8_TO_UNICODE_STACK_MACRO(w_SearchPath, SearchPath);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(SearchPath);
|
2002-11-22 07:17:59 +01:00
|
|
|
dir = FindFirstFile(w_SearchPath, &ent);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(w_SearchPath);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
if (dir == INVALID_HANDLE_VALUE)
|
|
|
|
return;
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2007-03-09 09:15:47 +01:00
|
|
|
const char *str = NULL;
|
2004-09-29 08:09:29 +02:00
|
|
|
|
2002-11-22 07:17:59 +01:00
|
|
|
if (wcscmp(ent.cFileName, L".") == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wcscmp(ent.cFileName, L"..") == 0)
|
|
|
|
continue;
|
|
|
|
|
2007-03-09 09:15:47 +01:00
|
|
|
if (!doEnumCallback(ent.cFileName))
|
2002-11-22 07:17:59 +01:00
|
|
|
break;
|
|
|
|
} while (FindNextFile(dir, &ent) != 0);
|
|
|
|
|
|
|
|
FindClose(dir);
|
|
|
|
} /* __PHYSFS_platformEnumerateFiles */
|
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformCurrentDir(void)
|
|
|
|
{
|
2003-05-18 09:52:28 +02:00
|
|
|
return("\\");
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformCurrentDir */
|
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformRealPath(const char *path)
|
|
|
|
{
|
2005-03-14 12:49:30 +01:00
|
|
|
char *retval = (char *) allocator.Malloc(strlen(path) + 1);
|
2003-05-18 09:52:28 +02:00
|
|
|
strcpy(retval,path);
|
|
|
|
return(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformRealPath */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformMkDir(const char *path)
|
|
|
|
{
|
2007-03-24 04:54:58 +01:00
|
|
|
int retval = 0;
|
2007-03-09 09:15:47 +01:00
|
|
|
wchar_t *w_path = NULL;
|
|
|
|
UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
|
2007-03-24 04:54:58 +01:00
|
|
|
if (w_path != NULL)
|
|
|
|
{
|
|
|
|
retval = CreateDirectory(w_path, NULL);
|
|
|
|
__PHYSFS_smallFree(w_fname);
|
|
|
|
} /* if */
|
|
|
|
return(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* __PHYSFS_platformMkDir */
|
|
|
|
|
|
|
|
|
|
|
|
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
|
|
|
|
{
|
|
|
|
HANDLE fileHandle;
|
|
|
|
winCEfile *retval;
|
2007-03-09 09:15:47 +01:00
|
|
|
wchar_t *w_fname = NULL;
|
|
|
|
|
|
|
|
UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
|
2010-03-17 22:11:21 +01:00
|
|
|
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(w_fname);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
|
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
|
2003-05-18 09:52:28 +02:00
|
|
|
if (retval == NULL)
|
|
|
|
{
|
2007-03-08 23:37:51 +01:00
|
|
|
CloseHandle(fileHandle);
|
|
|
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
2003-05-18 09:52:28 +02:00
|
|
|
} /* if */
|
2002-11-22 07:17:59 +01:00
|
|
|
|
2003-05-18 09:52:28 +02:00
|
|
|
retval->readonly = rdonly;
|
|
|
|
retval->handle = fileHandle;
|
|
|
|
return(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* doOpen */
|
|
|
|
|
|
|
|
|
|
|
|
void *__PHYSFS_platformOpenRead(const char *filename)
|
|
|
|
{
|
|
|
|
return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1));
|
|
|
|
} /* __PHYSFS_platformOpenRead */
|
|
|
|
|
|
|
|
|
|
|
|
void *__PHYSFS_platformOpenWrite(const char *filename)
|
|
|
|
{
|
|
|
|
return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0));
|
|
|
|
} /* __PHYSFS_platformOpenWrite */
|
|
|
|
|
|
|
|
|
|
|
|
void *__PHYSFS_platformOpenAppend(const char *filename)
|
|
|
|
{
|
|
|
|
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
|
|
|
|
if (retval != NULL)
|
|
|
|
{
|
|
|
|
HANDLE h = ((winCEfile *) retval)->handle;
|
|
|
|
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
|
|
|
|
{
|
|
|
|
const char *err = win32strerror();
|
|
|
|
CloseHandle(h);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
BAIL_MACRO(err, NULL);
|
|
|
|
} /* if */
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
|
|
|
|
} /* __PHYSFS_platformOpenAppend */
|
|
|
|
|
|
|
|
|
|
|
|
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
|
|
|
|
PHYSFS_uint32 size, PHYSFS_uint32 count)
|
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
2002-11-22 07:17:59 +01:00
|
|
|
DWORD CountOfBytesRead;
|
|
|
|
PHYSFS_sint64 retval;
|
|
|
|
|
|
|
|
/* Read data from the file */
|
|
|
|
/*!!! - uint32 might be a greater # than DWORD */
|
2004-09-26 15:03:00 +02:00
|
|
|
if (!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL))
|
2002-11-22 07:17:59 +01:00
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
retval = -1;
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* if */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Return the number of "objects" read. */
|
|
|
|
/* !!! - What if not the right amount of bytes was read to make an object? */
|
|
|
|
retval = CountOfBytesRead / size;
|
|
|
|
} /* else */
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
|
|
|
|
} /* __PHYSFS_platformRead */
|
|
|
|
|
|
|
|
|
|
|
|
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
|
|
|
|
PHYSFS_uint32 size, PHYSFS_uint32 count)
|
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
2002-11-22 07:17:59 +01:00
|
|
|
DWORD CountOfBytesWritten;
|
|
|
|
PHYSFS_sint64 retval;
|
|
|
|
|
|
|
|
/* Read data from the file */
|
|
|
|
/*!!! - uint32 might be a greater # than DWORD */
|
2004-09-26 15:03:00 +02:00
|
|
|
if (!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL))
|
2002-11-22 07:17:59 +01:00
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
retval = -1;
|
2002-11-22 07:17:59 +01:00
|
|
|
} /* if */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Return the number of "objects" read. */
|
|
|
|
/*!!! - What if not the right number of bytes was written? */
|
|
|
|
retval = CountOfBytesWritten / size;
|
|
|
|
} /* else */
|
|
|
|
|
2003-05-18 09:52:28 +02:00
|
|
|
return(retval);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
} /* __PHYSFS_platformWrite */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
|
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
2002-11-22 07:17:59 +01:00
|
|
|
DWORD HighOrderPos;
|
|
|
|
DWORD rc;
|
|
|
|
|
|
|
|
/* Get the high order 32-bits of the position */
|
|
|
|
//HighOrderPos = HIGHORDER_UINT64(pos);
|
2003-05-18 09:52:28 +02:00
|
|
|
HighOrderPos = (unsigned long)(pos>>32);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
/*!!! SetFilePointer needs a signed 64-bit value. */
|
|
|
|
/* Move pointer "pos" count from start of file */
|
2004-09-26 15:03:00 +02:00
|
|
|
rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff),
|
2002-11-22 07:17:59 +01:00
|
|
|
&HighOrderPos, FILE_BEGIN);
|
|
|
|
|
|
|
|
if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
2003-05-18 09:52:28 +02:00
|
|
|
{
|
2002-11-22 07:17:59 +01:00
|
|
|
BAIL_MACRO(win32strerror(), 0);
|
2003-05-18 09:52:28 +02:00
|
|
|
}
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
return(1); /* No error occured */
|
|
|
|
} /* __PHYSFS_platformSeek */
|
|
|
|
|
|
|
|
|
|
|
|
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
|
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
2002-11-22 07:17:59 +01:00
|
|
|
DWORD HighPos = 0;
|
|
|
|
DWORD LowPos;
|
|
|
|
PHYSFS_sint64 retval;
|
|
|
|
|
|
|
|
/* Get current position */
|
2004-09-26 15:03:00 +02:00
|
|
|
LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
|
2002-11-22 07:17:59 +01:00
|
|
|
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
|
|
|
{
|
|
|
|
BAIL_MACRO(win32strerror(), 0);
|
|
|
|
} /* if */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Combine the high/low order to create the 64-bit position value */
|
|
|
|
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
|
|
|
|
//assert(retval >= 0);
|
|
|
|
} /* else */
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} /* __PHYSFS_platformTell */
|
|
|
|
|
|
|
|
|
|
|
|
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
|
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
2002-11-22 07:17:59 +01:00
|
|
|
DWORD SizeHigh;
|
|
|
|
DWORD SizeLow;
|
|
|
|
PHYSFS_sint64 retval;
|
|
|
|
|
2004-09-26 15:03:00 +02:00
|
|
|
SizeLow = GetFileSize(Handle, &SizeHigh);
|
2002-11-22 07:17:59 +01:00
|
|
|
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
|
|
|
{
|
|
|
|
BAIL_MACRO(win32strerror(), -1);
|
|
|
|
} /* if */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Combine the high/low order to create the 64-bit position value */
|
|
|
|
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
|
|
|
|
//assert(retval >= 0);
|
|
|
|
} /* else */
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} /* __PHYSFS_platformFileLength */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformEOF(void *opaque)
|
|
|
|
{
|
|
|
|
PHYSFS_sint64 FilePosition;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
/* Get the current position in the file */
|
|
|
|
if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
|
|
|
|
{
|
|
|
|
/* Non-zero if EOF is equal to the file length */
|
|
|
|
retval = FilePosition == __PHYSFS_platformFileLength(opaque);
|
|
|
|
} /* if */
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
} /* __PHYSFS_platformEOF */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformFlush(void *opaque)
|
|
|
|
{
|
|
|
|
winCEfile *fh = ((winCEfile *) opaque);
|
|
|
|
if (!fh->readonly)
|
|
|
|
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
} /* __PHYSFS_platformFlush */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformClose(void *opaque)
|
|
|
|
{
|
2004-09-26 15:03:00 +02:00
|
|
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
|
|
|
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
|
2005-03-14 12:49:30 +01:00
|
|
|
allocator.Free(opaque);
|
2002-11-22 07:17:59 +01:00
|
|
|
return(1);
|
|
|
|
} /* __PHYSFS_platformClose */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformDelete(const char *path)
|
|
|
|
{
|
2007-03-09 09:15:47 +01:00
|
|
|
wchar_t *w_path = NULL;
|
|
|
|
UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
|
2002-11-22 07:17:59 +01:00
|
|
|
|
|
|
|
/* If filename is a folder */
|
|
|
|
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
{
|
2007-03-09 09:15:47 +01:00
|
|
|
int retval = !RemoveDirectory(w_path);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(w_path);
|
2002-11-22 07:17:59 +01:00
|
|
|
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
|
|
|
} /* if */
|
|
|
|
else
|
|
|
|
{
|
2007-03-09 09:15:47 +01:00
|
|
|
int retval = !DeleteFile(w_path);
|
2007-03-24 04:54:58 +01:00
|
|
|
__PHYSFS_smallFree(w_path);
|
2002-11-22 07:17:59 +01:00
|
|
|
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
|
|
|
} /* else */
|
|
|
|
|
|
|
|
return(1); /* if you got here, it worked. */
|
|
|
|
} /* __PHYSFS_platformDelete */
|
|
|
|
|
|
|
|
|
2007-03-24 06:13:54 +01:00
|
|
|
/*
|
|
|
|
* !!! FIXME: why aren't we using Critical Sections instead of Mutexes?
|
|
|
|
* !!! FIXME: mutexes on Windows are for cross-process sync. CritSects are
|
|
|
|
* !!! FIXME: mutexes for threads in a single process and are faster.
|
|
|
|
*/
|
2002-11-22 07:17:59 +01:00
|
|
|
void *__PHYSFS_platformCreateMutex(void)
|
|
|
|
{
|
|
|
|
return((void *) CreateMutex(NULL, FALSE, NULL));
|
|
|
|
} /* __PHYSFS_platformCreateMutex */
|
|
|
|
|
|
|
|
|
|
|
|
void __PHYSFS_platformDestroyMutex(void *mutex)
|
|
|
|
{
|
|
|
|
CloseHandle((HANDLE) mutex);
|
|
|
|
} /* __PHYSFS_platformDestroyMutex */
|
|
|
|
|
|
|
|
|
|
|
|
int __PHYSFS_platformGrabMutex(void *mutex)
|
|
|
|
{
|
|
|
|
return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
|
|
|
|
} /* __PHYSFS_platformGrabMutex */
|
|
|
|
|
|
|
|
|
|
|
|
void __PHYSFS_platformReleaseMutex(void *mutex)
|
|
|
|
{
|
|
|
|
ReleaseMutex((HANDLE) mutex);
|
|
|
|
} /* __PHYSFS_platformReleaseMutex */
|
|
|
|
|
|
|
|
|
|
|
|
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
|
|
|
{
|
|
|
|
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
|
|
|
|
} /* __PHYSFS_platformGetLastModTime */
|
|
|
|
|
2005-03-14 12:49:30 +01:00
|
|
|
|
|
|
|
/* !!! FIXME: Don't use C runtime for allocators? */
|
2007-03-20 19:33:56 +01:00
|
|
|
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
|
2005-03-14 12:49:30 +01:00
|
|
|
{
|
2007-03-20 19:33:56 +01:00
|
|
|
return(0); /* just use malloc() and friends. */
|
|
|
|
} /* __PHYSFS_platformSetDefaultAllocator */
|
2005-03-14 12:49:30 +01:00
|
|
|
|
2007-03-11 23:50:53 +01:00
|
|
|
#endif /* PHYSFS_PLATFORM_POCKETPC */
|
|
|
|
|
2005-02-15 23:25:03 +01:00
|
|
|
/* end of pocketpc.c ... */
|
2002-11-22 07:17:59 +01:00
|
|
|
|