Cleaned up some FIXMEs.
This commit is contained in:
parent
59c6310e92
commit
b1d4afcbd3
|
@ -98,8 +98,10 @@ static PHYSFS_Io *doOpen(dvoid *opaque, const char *name,
|
||||||
io = __PHYSFS_createNativeIo(f, mode);
|
io = __PHYSFS_createNativeIo(f, mode);
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
{
|
{
|
||||||
PHYSFS_Stat statbuf; /* !!! FIXME: this changes the error message. */
|
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
|
||||||
|
PHYSFS_Stat statbuf;
|
||||||
__PHYSFS_platformStat(f, fileExists, &statbuf);
|
__PHYSFS_platformStat(f, fileExists, &statbuf);
|
||||||
|
__PHYSFS_setError(err);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1104,7 +1104,7 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)
|
||||||
|
|
||||||
static char *calculateUserDir(void)
|
static char *calculateUserDir(void)
|
||||||
{
|
{
|
||||||
char *retval = __PHYSFS_platformGetUserDir();
|
char *retval = __PHYSFS_platformCalcUserDir();
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
const char dirsep = __PHYSFS_platformDirSeparator;
|
const char dirsep = __PHYSFS_platformDirSeparator;
|
||||||
|
|
|
@ -633,12 +633,12 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0);
|
||||||
*/
|
*/
|
||||||
char *__PHYSFS_platformGetUserName(void);
|
char *__PHYSFS_platformGetUserName(void);
|
||||||
|
|
||||||
/* !!! FIXME: should this be CalcUserDir, to match CalcBaseDir?
|
/*
|
||||||
* Get the platform-specific user dir.
|
* Get the platform-specific user dir.
|
||||||
* Caller will allocator.Free() the retval if it's not NULL. If it's NULL,
|
* Caller will allocator.Free() the retval if it's not NULL. If it's NULL,
|
||||||
* the userdir will default to basedir/username.
|
* the userdir will default to basedir/username.
|
||||||
*/
|
*/
|
||||||
char *__PHYSFS_platformGetUserDir(void);
|
char *__PHYSFS_platformCalcUserDir(void);
|
||||||
|
|
||||||
|
|
||||||
/* This is the cached version from PHYSFS_init(). This is a fast call. */
|
/* This is the cached version from PHYSFS_init(). This is a fast call. */
|
||||||
|
|
|
@ -123,7 +123,7 @@ char *__PHYSFS_platformGetUserName(void)
|
||||||
} /* __PHYSFS_platformGetUserName */
|
} /* __PHYSFS_platformGetUserName */
|
||||||
|
|
||||||
|
|
||||||
char *__PHYSFS_platformGetUserDir(void)
|
char *__PHYSFS_platformCalcUserDir(void)
|
||||||
{
|
{
|
||||||
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
|
char *retval = __PHYSFS_platformCopyEnvironmentVariable("HOME");
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ char *__PHYSFS_platformGetUserDir(void)
|
||||||
retval = getUserDirByUID();
|
retval = getUserDirByUID();
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* __PHYSFS_platformGetUserDir */
|
} /* __PHYSFS_platformCalcUserDir */
|
||||||
|
|
||||||
|
|
||||||
void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
|
|
|
@ -88,10 +88,6 @@ typedef struct
|
||||||
int readonly;
|
int readonly;
|
||||||
} WinApiFile;
|
} WinApiFile;
|
||||||
|
|
||||||
|
|
||||||
/* !!! FIXME: we cache userDir in physfs.c during PHYSFS_init(), too. */
|
|
||||||
static char *userDir = NULL;
|
|
||||||
static HANDLE libUserEnv = NULL;
|
|
||||||
static HANDLE detectCDThreadHandle = NULL;
|
static HANDLE detectCDThreadHandle = NULL;
|
||||||
static HWND detectCDHwnd = 0;
|
static HWND detectCDHwnd = 0;
|
||||||
static volatile int initialDiscDetectionComplete = 0;
|
static volatile int initialDiscDetectionComplete = 0;
|
||||||
|
@ -156,61 +152,6 @@ static inline PHYSFS_ErrorCode errcodeFromWinApi(void)
|
||||||
} /* errcodeFromWinApi */
|
} /* errcodeFromWinApi */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* On success, module-scope variable (userDir) will have a pointer to
|
|
||||||
* a malloc()'d string of the user's profile dir, and a non-zero value is
|
|
||||||
* returned. If we can't determine the profile dir, (userDir) will
|
|
||||||
* be NULL, and zero is returned.
|
|
||||||
*/
|
|
||||||
static int determineUserDir(void)
|
|
||||||
{
|
|
||||||
typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);
|
|
||||||
fnGetUserProfDirW pGetDir = NULL;
|
|
||||||
|
|
||||||
HANDLE accessToken = NULL; /* Security handle to process */
|
|
||||||
|
|
||||||
if (userDir != NULL)
|
|
||||||
return 1; /* already good to go. */
|
|
||||||
|
|
||||||
pGetDir = (fnGetUserProfDirW)
|
|
||||||
GetProcAddress(libUserEnv, "GetUserProfileDirectoryW");
|
|
||||||
BAIL_IF_MACRO(pGetDir == NULL, errcodeFromWinApi(), 0);
|
|
||||||
|
|
||||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken))
|
|
||||||
BAIL_MACRO(errcodeFromWinApi(), 0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DWORD psize = 0;
|
|
||||||
WCHAR dummy = 0;
|
|
||||||
LPWSTR wstr = NULL;
|
|
||||||
BOOL rc = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Should fail. Will write the size of the profile path in
|
|
||||||
* psize. Also note that the second parameter can't be
|
|
||||||
* NULL or the function fails.
|
|
||||||
*/
|
|
||||||
rc = pGetDir(accessToken, &dummy, &psize);
|
|
||||||
assert(!rc); /* !!! FIXME: handle this gracefully. */
|
|
||||||
(void) rc;
|
|
||||||
|
|
||||||
/* Allocate memory for the profile directory */
|
|
||||||
wstr = (LPWSTR) __PHYSFS_smallAlloc(psize * sizeof (WCHAR));
|
|
||||||
if (wstr != NULL)
|
|
||||||
{
|
|
||||||
if (pGetDir(accessToken, wstr, &psize))
|
|
||||||
userDir = unicodeToUtf8Heap(wstr);
|
|
||||||
__PHYSFS_smallFree(wstr);
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
CloseHandle(accessToken);
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
return 1; /* We made it: hit the showers. */
|
|
||||||
} /* determineUserDir */
|
|
||||||
|
|
||||||
|
|
||||||
typedef BOOL (WINAPI *fnSTEM)(DWORD, LPDWORD b);
|
typedef BOOL (WINAPI *fnSTEM)(DWORD, LPDWORD b);
|
||||||
|
|
||||||
static DWORD pollDiscDrives(void)
|
static DWORD pollDiscDrives(void)
|
||||||
|
@ -495,13 +436,53 @@ char *__PHYSFS_platformGetUserName(void)
|
||||||
} /* __PHYSFS_platformGetUserName */
|
} /* __PHYSFS_platformGetUserName */
|
||||||
|
|
||||||
|
|
||||||
char *__PHYSFS_platformGetUserDir(void)
|
char *__PHYSFS_platformCalcUserDir(void)
|
||||||
{
|
{
|
||||||
char *retval = (char *) allocator.Malloc(strlen(userDir) + 1);
|
typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD);
|
||||||
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
fnGetUserProfDirW pGetDir = NULL;
|
||||||
strcpy(retval, userDir); /* calculated at init time. */
|
HANDLE lib = NULL;
|
||||||
return retval;
|
HANDLE accessToken = NULL; /* Security handle to process */
|
||||||
} /* __PHYSFS_platformGetUserDir */
|
char *retval = NULL;
|
||||||
|
|
||||||
|
lib = LoadLibraryA("userenv.dll");
|
||||||
|
BAIL_IF_MACRO(!lib, errcodeFromWinApi(), NULL);
|
||||||
|
pGetDir=(fnGetUserProfDirW) GetProcAddress(lib,"GetUserProfileDirectoryW");
|
||||||
|
GOTO_IF_MACRO(!pGetDir, errcodeFromWinApi(), done);
|
||||||
|
|
||||||
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken))
|
||||||
|
GOTO_MACRO(errcodeFromWinApi(), done);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DWORD psize = 0;
|
||||||
|
WCHAR dummy = 0;
|
||||||
|
LPWSTR wstr = NULL;
|
||||||
|
BOOL rc = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Should fail. Will write the size of the profile path in
|
||||||
|
* psize. Also note that the second parameter can't be
|
||||||
|
* NULL or the function fails.
|
||||||
|
*/
|
||||||
|
rc = pGetDir(accessToken, &dummy, &psize);
|
||||||
|
assert(!rc); /* !!! FIXME: handle this gracefully. */
|
||||||
|
(void) rc;
|
||||||
|
|
||||||
|
/* Allocate memory for the profile directory */
|
||||||
|
wstr = (LPWSTR) __PHYSFS_smallAlloc(psize * sizeof (WCHAR));
|
||||||
|
if (wstr != NULL)
|
||||||
|
{
|
||||||
|
if (pGetDir(accessToken, wstr, &psize))
|
||||||
|
retval = unicodeToUtf8Heap(wstr);
|
||||||
|
__PHYSFS_smallFree(wstr);
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
CloseHandle(accessToken);
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
done:
|
||||||
|
FreeLibrary(lib);
|
||||||
|
return retval; /* We made it: hit the showers. */
|
||||||
|
} /* __PHYSFS_platformCalcUserDir */
|
||||||
|
|
||||||
|
|
||||||
void *__PHYSFS_platformGetThreadID(void)
|
void *__PHYSFS_platformGetThreadID(void)
|
||||||
|
@ -598,11 +579,6 @@ int __PHYSFS_platformMkDir(const char *path)
|
||||||
|
|
||||||
int __PHYSFS_platformInit(void)
|
int __PHYSFS_platformInit(void)
|
||||||
{
|
{
|
||||||
libUserEnv = LoadLibraryA("userenv.dll");
|
|
||||||
BAIL_IF_MACRO(libUserEnv == NULL, errcodeFromWinApi(), 0);
|
|
||||||
|
|
||||||
/* !!! FIXME: why do we precalculate this? */
|
|
||||||
BAIL_IF_MACRO(!determineUserDir(), ERRPASS, 0);
|
|
||||||
return 1; /* It's all good */
|
return 1; /* It's all good */
|
||||||
} /* __PHYSFS_platformInit */
|
} /* __PHYSFS_platformInit */
|
||||||
|
|
||||||
|
@ -619,11 +595,6 @@ int __PHYSFS_platformDeinit(void)
|
||||||
drivesWithMediaBitmap = 0;
|
drivesWithMediaBitmap = 0;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (libUserEnv)
|
|
||||||
FreeLibrary(libUserEnv);
|
|
||||||
libUserEnv = NULL;
|
|
||||||
allocator.Free(userDir);
|
|
||||||
userDir = NULL;
|
|
||||||
return 1; /* It's all good */
|
return 1; /* It's all good */
|
||||||
} /* __PHYSFS_platformDeinit */
|
} /* __PHYSFS_platformDeinit */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue