From 118a533cbfc63be54dce73d18ac257cf946155b1 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 21 Jan 2024 14:23:52 -0600 Subject: [PATCH] Use XDG_DATA_HOME for Flatpak Use XDG_DATA_HOME for Flatpak so that fs_homepath is accessible without special permissions/handling. This changes the home path for Flatpak from ~/.q3a/ to ~/.var/app/org.ioquake3.ioquake3/data/q3a/. --- code/sys/sys_unix.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/code/sys/sys_unix.c b/code/sys/sys_unix.c index db29e8f0..07de6500 100644 --- a/code/sys/sys_unix.c +++ b/code/sys/sys_unix.c @@ -65,10 +65,11 @@ char *Sys_DefaultHomePath(void) if( !*homePath && com_homepath != NULL ) { +#ifdef __APPLE__ if( ( p = getenv( "HOME" ) ) != NULL ) { Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP); -#ifdef __APPLE__ + Q_strcat(homePath, sizeof(homePath), "Library/Application Support/"); @@ -76,13 +77,44 @@ char *Sys_DefaultHomePath(void) Q_strcat(homePath, sizeof(homePath), com_homepath->string); else Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_MACOSX); + } #else + if( ( p = getenv( "FLATPAK_ID" ) ) != NULL && *p != '\0' ) + { + if( ( p = getenv( "XDG_DATA_HOME" ) ) != NULL && *p != '\0' ) + { + Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP); + } + else if( ( p = getenv( "HOME" ) ) != NULL && *p != '\0' ) + { + Com_sprintf(homePath, sizeof(homePath), "%s%c.local%cshare%c", p, PATH_SEP, PATH_SEP, PATH_SEP); + } + + if( *homePath ) + { + char *dir; + + if(com_homepath->string[0]) + dir = com_homepath->string; + else + dir = HOMEPATH_NAME_UNIX; + + if(dir[0] == '.' && dir[1] != '\0') + dir++; + + Q_strcat(homePath, sizeof(homePath), dir); + } + } + else if( ( p = getenv( "HOME" ) ) != NULL ) + { + Com_sprintf(homePath, sizeof(homePath), "%s%c", p, PATH_SEP); + if(com_homepath->string[0]) Q_strcat(homePath, sizeof(homePath), com_homepath->string); else Q_strcat(homePath, sizeof(homePath), HOMEPATH_NAME_UNIX); -#endif } +#endif } return homePath;