From: divverent Date: Tue, 8 Jan 2008 09:50:19 +0000 (+0000) Subject: make it use APPDATA right X-Git-Tag: xonotic-v0.1.0preview~2571 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e34cc10e2d07a5fb56002c3e4bb9cf871925b99b;p=xonotic%2Fdarkplaces.git make it use APPDATA right git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7935 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/fs.c b/fs.c index 759f29e3..2454bea3 100644 --- a/fs.c +++ b/fs.c @@ -30,6 +30,7 @@ #ifdef WIN32 # include # include +# include #else # include # include @@ -1013,8 +1014,12 @@ FS_AddGameHierarchy void FS_AddGameHierarchy (const char *dir) { int i; - const char *homedir; char userdir[MAX_QPATH]; +#ifdef WIN32 + TCHAR appdata[MAX_PATH + 1]; +#else + const char *homedir; +#endif // Add the common game directory FS_AddGameDirectory (va("%s%s/", fs_basedir, dir)); @@ -1023,18 +1028,27 @@ void FS_AddGameHierarchy (const char *dir) // Add the personal game directory #ifdef WIN32 - homedir = getenv ("APPDATA"); - dpsnprintf(userdir, sizeof(userdir), "%s/%s/", homedir, gameuserdirname); + if(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, appdata) == S_OK) + dpsnprintf(userdir, sizeof(userdir), "%s/%s/", appdata, gameuserdirname); #else homedir = getenv ("HOME"); - dpsnprintf(userdir, sizeof(userdir), "%s/.%s/", homedir, gameuserdirname); + if(homedir) + dpsnprintf(userdir, sizeof(userdir), "%s/.%s/", homedir, gameuserdirname); #endif #ifdef WIN32 - if(!COM_CheckParm("-appdata")) // TODO make this the default when fs_basedir isn't writable -#else - if(COM_CheckParm("-nohome")) + if(!COM_CheckParm("-appdata")) + { + int fd = open (va("%s%s/config.cfg", fs_basedir, dir), O_WRONLY | O_CREAT | O_APPEND, 0666); + if(fd >= 0) + { + close(fd); + *userdir = 0; // we have write access to the game dir, so let's use it + } + } #endif + + if(COM_CheckParm("-nohome")) *userdir = 0; if((i = COM_CheckParm("-userdir")) && i < com_argc - 1)