Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().

This commit is contained in:
Ryan C. Gordon 2012-03-21 23:52:44 -04:00
parent 629614838a
commit 43367c0c29
2 changed files with 24 additions and 8 deletions

View File

@ -1380,8 +1380,8 @@ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback callback, void *data)
const char *PHYSFS_getPrefDir(const char *org, const char *app) const char *PHYSFS_getPrefDir(const char *org, const char *app)
{ {
const char dirsep = __PHYSFS_platformDirSeparator; const char dirsep = __PHYSFS_platformDirSeparator;
char *ptr = NULL;
PHYSFS_Stat statbuf; PHYSFS_Stat statbuf;
char *ptr = NULL;
int exists = 0; int exists = 0;
BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0); BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0);
@ -1394,7 +1394,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
prefDir = __PHYSFS_platformCalcPrefDir(org, app); prefDir = __PHYSFS_platformCalcPrefDir(org, app);
BAIL_IF_MACRO(!prefDir, ERRPASS, NULL); BAIL_IF_MACRO(!prefDir, ERRPASS, NULL);
#if !PHYSFS_PLATFORM_WINDOWS /* Windows guarantees the dir exists here. */
if (__PHYSFS_platformStat(prefDir, &exists, &statbuf)) if (__PHYSFS_platformStat(prefDir, &exists, &statbuf))
return prefDir; return prefDir;
@ -1410,7 +1409,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
allocator.Free(prefDir); allocator.Free(prefDir);
prefDir = NULL; prefDir = NULL;
} /* if */ } /* if */
#endif
return prefDir; return prefDir;
} /* PHYSFS_getPrefDir */ } /* PHYSFS_getPrefDir */

View File

@ -443,17 +443,35 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app) char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
{ {
// Vista and later has a new API for this, but SHGetFolderPath works there, /*
// and apparently just wraps the new API. This is the new way to do it: * Vista and later has a new API for this, but SHGetFolderPath works there,
// SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, * and apparently just wraps the new API. This is the new way to do it:
// NULL, &wszPath); *
* SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
* NULL, &wszPath);
*/
WCHAR path[MAX_PATH]; WCHAR path[MAX_PATH];
char *utf8 = NULL;
size_t len = 0;
char *retval = NULL;
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, 0, path))) NULL, 0, path)))
BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL); BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL);
return unicodeToUtf8Heap(path); utf8 = unicodeToUtf8Heap(path);
BAIL_IF_MACRO(!utf8, ERRPASS, NULL);
len = strlen(utf8) + strlen(org) + strlen(app) + 3;
retval = allocator.Malloc(len);
if (!retval)
{
allocator.Free(utf8);
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
} /* if */
sprintf(retval, "%s\\%s\\%s", utf8, org, app);
return retval;
} /* __PHYSFS_platformCalcPrefDir */ } /* __PHYSFS_platformCalcPrefDir */