make userdir handling vital, use XDG standard directories
parent
242a51027b
commit
40264fdea9
|
@ -169,8 +169,6 @@ add_executable(quake WIN32
|
||||||
target_compile_definitions(
|
target_compile_definitions(
|
||||||
quake
|
quake
|
||||||
PUBLIC
|
PUBLIC
|
||||||
-DDO_USERDIRS=1
|
|
||||||
-DUSE_SDL2=1
|
|
||||||
-DUSE_CODEC_FLAC=1
|
-DUSE_CODEC_FLAC=1
|
||||||
-DUSE_CODEC_VORBIS=1
|
-DUSE_CODEC_VORBIS=1
|
||||||
-DUSE_CODEC_OPUS=1
|
-DUSE_CODEC_OPUS=1
|
||||||
|
|
|
@ -34,9 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef DO_USERDIRS
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
|
@ -228,42 +226,49 @@ static int Sys_NumCPUs (void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char cwd[MAX_OSPATH];
|
static char const *Sys_GetHomeDir(void)
|
||||||
#ifdef DO_USERDIRS
|
{
|
||||||
static char userdir[MAX_OSPATH];
|
struct passwd *pwent;
|
||||||
|
|
||||||
|
pwent = getpwuid(getuid());
|
||||||
|
|
||||||
|
if(pwent == NULL)
|
||||||
|
{
|
||||||
|
perror("getpwuid");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pwent->pw_dir ? pwent->pw_dir : getenv("HOME");
|
||||||
|
}
|
||||||
|
|
||||||
|
static char const *Sys_GetUserDir(void)
|
||||||
|
{
|
||||||
|
static char user_dir[MAX_OSPATH];
|
||||||
|
static char app_name[] = "AGWQuake";
|
||||||
|
|
||||||
|
size_t n;
|
||||||
|
char const *home_dir;
|
||||||
|
|
||||||
#ifdef PLATFORM_OSX
|
#ifdef PLATFORM_OSX
|
||||||
#define SYS_USERDIR "Library/Application Support/QuakeSpasm"
|
if(!(home_dir = Sys_GetHomeDir()))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
q_snprintf(user_dir, sizeof(user_dir), "%s/Library/Application Support/%s", home_dir, app_name);
|
||||||
#else
|
#else
|
||||||
#define SYS_USERDIR ".quakespasm"
|
char const *system_dir;
|
||||||
|
|
||||||
|
if((system_dir = getenv("XDG_DATA_HOME")))
|
||||||
|
q_snprintf(user_dir, sizeof(user_dir), "%s/%s/%s", home_dir, system_dir, app_name);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!(home_dir = Sys_GetHomeDir()))
|
||||||
|
return NULL;
|
||||||
|
q_snprintf(user_dir, sizeof(user_dir), "%s/.local/share/%s", home_dir, app_name);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void Sys_GetUserdir (char *dst, size_t dstsize)
|
return user_dir;
|
||||||
{
|
|
||||||
size_t n;
|
|
||||||
const char *home_dir = NULL;
|
|
||||||
struct passwd *pwent;
|
|
||||||
|
|
||||||
pwent = getpwuid( getuid() );
|
|
||||||
if (pwent == NULL)
|
|
||||||
perror("getpwuid");
|
|
||||||
else
|
|
||||||
home_dir = pwent->pw_dir;
|
|
||||||
if (home_dir == NULL)
|
|
||||||
home_dir = getenv("HOME");
|
|
||||||
if (home_dir == NULL)
|
|
||||||
Sys_Error ("Couldn't determine userspace directory");
|
|
||||||
|
|
||||||
/* what would be a maximum path for a file in the user's directory...
|
|
||||||
* $HOME/SYS_USERDIR/game_dir/dirname1/dirname2/dirname3/filename.ext
|
|
||||||
* still fits in the MAX_OSPATH == 256 definition, but just in case :
|
|
||||||
*/
|
|
||||||
n = strlen(home_dir) + strlen(SYS_USERDIR) + 50;
|
|
||||||
if (n >= dstsize)
|
|
||||||
Sys_Error ("Insufficient array size for userspace directory");
|
|
||||||
|
|
||||||
q_snprintf (dst, dstsize, "%s/%s", home_dir, SYS_USERDIR);
|
|
||||||
}
|
}
|
||||||
#endif /* DO_USERDIRS */
|
|
||||||
|
|
||||||
#ifdef PLATFORM_OSX
|
#ifdef PLATFORM_OSX
|
||||||
static char *OSX_StripAppBundle (char *dir)
|
static char *OSX_StripAppBundle (char *dir)
|
||||||
|
@ -327,18 +332,25 @@ static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
||||||
|
|
||||||
void Sys_Init (void)
|
void Sys_Init (void)
|
||||||
{
|
{
|
||||||
memset (cwd, 0, sizeof(cwd));
|
static char cwd[MAX_OSPATH];
|
||||||
|
|
||||||
|
char const *user_dir;
|
||||||
|
|
||||||
|
/* set base dir to current directory */
|
||||||
|
memset(cwd, 0, sizeof(cwd));
|
||||||
Sys_GetBasedir(host_parms->argv[0], cwd, sizeof(cwd));
|
Sys_GetBasedir(host_parms->argv[0], cwd, sizeof(cwd));
|
||||||
host_parms->basedir = cwd;
|
host_parms->basedir = cwd;
|
||||||
#ifndef DO_USERDIRS
|
|
||||||
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
|
/* check for user directory, or use base dir */
|
||||||
#else
|
if((user_dir = Sys_GetUserDir()))
|
||||||
memset (userdir, 0, sizeof(userdir));
|
{
|
||||||
Sys_GetUserdir(userdir, sizeof(userdir));
|
Sys_mkdir(user_dir);
|
||||||
Sys_mkdir (userdir);
|
host_parms->userdir = user_dir;
|
||||||
host_parms->userdir = userdir;
|
}
|
||||||
#endif
|
else
|
||||||
host_parms->numcpus = Sys_NumCPUs ();
|
host_parms->userdir = host_parms->basedir;
|
||||||
|
|
||||||
|
host_parms->numcpus = Sys_NumCPUs();
|
||||||
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue