Skip to content

Commit

Permalink
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 22, 2012
1 parent 6296148 commit 43367c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/physfs.c
Expand Up @@ -1380,8 +1380,8 @@ void PHYSFS_getCdRomDirsCallback(PHYSFS_StringCallback callback, void *data)
const char *PHYSFS_getPrefDir(const char *org, const char *app)
{
const char dirsep = __PHYSFS_platformDirSeparator;
char *ptr = NULL;
PHYSFS_Stat statbuf;
char *ptr = NULL;
int exists = 0;

BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0);
Expand All @@ -1394,7 +1394,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
prefDir = __PHYSFS_platformCalcPrefDir(org, app);
BAIL_IF_MACRO(!prefDir, ERRPASS, NULL);

#if !PHYSFS_PLATFORM_WINDOWS /* Windows guarantees the dir exists here. */
if (__PHYSFS_platformStat(prefDir, &exists, &statbuf))
return prefDir;

Expand All @@ -1410,7 +1409,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
allocator.Free(prefDir);
prefDir = NULL;
} /* if */
#endif

return prefDir;
} /* PHYSFS_getPrefDir */
Expand Down
28 changes: 23 additions & 5 deletions src/platform_windows.c
Expand Up @@ -443,17 +443,35 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)

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:
// SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
// NULL, &wszPath);
/*
* 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:
*
* SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
* NULL, &wszPath);
*/

WCHAR path[MAX_PATH];
char *utf8 = NULL;
size_t len = 0;
char *retval = NULL;

if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, 0, path)))
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 */


Expand Down

0 comments on commit 43367c0

Please sign in to comment.