Man, I knew I would need getOSInfo() as soon as I deleted it!

Apparently Win9x has the Unicode entry points, they just don't work, so
 only do a real lookup on NT-based platforms, and just force the
 fallbacks on 95/98/ME systems.
This commit is contained in:
Ryan C. Gordon 2007-03-26 07:51:57 +00:00
parent c771a650ce
commit 49c576280d
1 changed files with 44 additions and 17 deletions

View File

@ -104,7 +104,9 @@ typedef struct
int readonly; int readonly;
} WinApiFile; } WinApiFile;
static char *userDir = NULL; static char *userDir = NULL;
static int osHasUnicode = 0;
/* pointers for APIs that may not exist on some Windows versions... */ /* pointers for APIs that may not exist on some Windows versions... */
@ -263,37 +265,46 @@ static int findApiSymbols(void)
{ {
HMODULE dll = NULL; HMODULE dll = NULL;
#define LOOKUP_NOFALLBACK(x) { symLookup(dll, (void **) &p##x, #x); } #define LOOKUP_NOFALLBACK(x, reallyLook) { \
#define LOOKUP(x) { \ if (reallyLook) \
if (!symLookup(dll, (void **) &p##x, #x)) \ symLookup(dll, (void **) &p##x, #x); \
else \
p##x = NULL; \
}
#define LOOKUP(x, reallyLook) { \
if ((!reallyLook) || (!symLookup(dll, (void **) &p##x, #x))) \
p##x = fallback##x; \ p##x = fallback##x; \
} }
/* Apparently Win9x HAS the Unicode entry points, they just don't WORK. */
/* ...so don't look them up unless we're on NT+. (see osHasUnicode.) */
dll = libUserEnv = LoadLibraryA("userenv.dll"); dll = libUserEnv = LoadLibraryA("userenv.dll");
if (dll != NULL) if (dll != NULL)
LOOKUP_NOFALLBACK(GetUserProfileDirectoryW); LOOKUP_NOFALLBACK(GetUserProfileDirectoryW, osHasUnicode);
/* !!! FIXME: what do they call advapi32.dll on Win64? */ /* !!! FIXME: what do they call advapi32.dll on Win64? */
dll = libAdvApi32 = LoadLibraryA("advapi32.dll"); dll = libAdvApi32 = LoadLibraryA("advapi32.dll");
if (dll != NULL) if (dll != NULL)
LOOKUP(GetUserNameW); LOOKUP(GetUserNameW, osHasUnicode);
/* !!! FIXME: what do they call kernel32.dll on Win64? */ /* !!! FIXME: what do they call kernel32.dll on Win64? */
dll = libKernel32 = LoadLibraryA("kernel32.dll"); dll = libKernel32 = LoadLibraryA("kernel32.dll");
if (dll != NULL) if (dll != NULL)
{ {
LOOKUP_NOFALLBACK(GetFileAttributesExA); LOOKUP_NOFALLBACK(GetFileAttributesExA, 1);
LOOKUP_NOFALLBACK(GetFileAttributesExW); LOOKUP_NOFALLBACK(GetFileAttributesExW, osHasUnicode);
LOOKUP(GetModuleFileNameW); LOOKUP_NOFALLBACK(FindFirstFileW, osHasUnicode);
LOOKUP(FormatMessageW); LOOKUP_NOFALLBACK(FindNextFileW, osHasUnicode);
LOOKUP_NOFALLBACK(FindFirstFileW); LOOKUP(GetModuleFileNameW, osHasUnicode);
LOOKUP_NOFALLBACK(FindNextFileW); LOOKUP(FormatMessageW, osHasUnicode);
LOOKUP(GetFileAttributesW); LOOKUP(GetFileAttributesW, osHasUnicode);
LOOKUP(GetCurrentDirectoryW); LOOKUP(GetCurrentDirectoryW, osHasUnicode);
LOOKUP(CreateDirectoryW); LOOKUP(CreateDirectoryW, osHasUnicode);
LOOKUP(RemoveDirectoryW); LOOKUP(RemoveDirectoryW, osHasUnicode);
LOOKUP(CreateFileW); LOOKUP(CreateFileW, osHasUnicode);
LOOKUP(DeleteFileW); LOOKUP(DeleteFileW, osHasUnicode);
} /* if */ } /* if */
#undef LOOKUP_NOFALLBACK #undef LOOKUP_NOFALLBACK
@ -873,8 +884,24 @@ int __PHYSFS_platformMkDir(const char *path)
} /* __PHYSFS_platformMkDir */ } /* __PHYSFS_platformMkDir */
/*
* Get OS info and save the important parts.
*
* Returns non-zero if successful, otherwise it returns zero on failure.
*/
static int getOSInfo(void)
{
OSVERSIONINFO osVerInfo; /* Information about the OS */
osVerInfo.dwOSVersionInfoSize = sizeof(osVerInfo);
BAIL_IF_MACRO(!GetVersionEx(&osVerInfo), winApiStrError(), 0);
osHasUnicode = (osVerInfo.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS);
return(1);
} /* getOSInfo */
int __PHYSFS_platformInit(void) int __PHYSFS_platformInit(void)
{ {
BAIL_IF_MACRO(!getOSInfo(), NULL, 0);
BAIL_IF_MACRO(!findApiSymbols(), NULL, 0); BAIL_IF_MACRO(!findApiSymbols(), NULL, 0);
BAIL_IF_MACRO(!determineUserDir(), NULL, 0); BAIL_IF_MACRO(!determineUserDir(), NULL, 0);
return(1); /* It's all good */ return(1); /* It's all good */