Skip to content

Commit

Permalink
Use XDG_DATA_HOME for Flatpak
Browse files Browse the repository at this point in the history
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/.
  • Loading branch information
zturtleman committed Aug 29, 2024
1 parent 7112bfb commit 118a533
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions code/sys/sys_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,56 @@ 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/");

if(com_homepath->string[0])
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;
Expand Down

0 comments on commit 118a533

Please sign in to comment.