Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Flatpak use XDG_DATA_HOME and tell users to copy missing pk3s there #685

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions code/qcommon/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,8 @@ static void FS_CheckPak0( void )
const char *pakBasename;
qboolean founddemo = qfalse;
unsigned int foundPak = 0, foundTA = 0;
qboolean installHome = qfalse;
char *installPath;

for( path = fs_searchpaths; path; path = path->next )
{
Expand Down Expand Up @@ -3658,6 +3660,21 @@ static void FS_CheckPak0( void )
}
}

#ifdef __linux__
{
const char *p;

// Users can't write to the default Flatpak fs_basepath
if( ( p = getenv( "FLATPAK_ID" ) ) != NULL && *p != '\0' )
installHome = qtrue;
}
#endif

if(installHome)
installPath = fs_homepath->string;
else
installPath = fs_basepath->string;

if(!com_standalone->integer && (foundPak & ((1<<NUM_ID_PAKS)-1)) != ((1<<NUM_ID_PAKS)-1))
{
char errorText[MAX_STRING_CHARS] = "";
Expand All @@ -3669,18 +3686,27 @@ static void FS_CheckPak0( void )

Q_strcat(errorText, sizeof(errorText),
va(" from the \"%s\" directory in your Quake 3 install or CD-ROM to:\n\n"
"%s%c%s%c\n\n", BASEGAME, fs_basepath->string, PATH_SEP, BASEGAME, PATH_SEP));
"%s%c%s%c\n\n", BASEGAME, installPath, PATH_SEP, BASEGAME, PATH_SEP));

Q_strcat(errorText, sizeof(errorText),
"Quake 3 must be purchased to legitimately obtain pak0. "
"Quake 3 1.32 point release files (pak1 through pak8) "
"are freely available at:\n\n"
"https://ioquake3.org/extras/patch-data/\n\n");

Q_strcat(errorText, sizeof(errorText),
va("Also check that your ioq3 executable is in "
"the correct place and that every file "
"in the \"%s\" directory is present and readable", BASEGAME));
if(installHome)
{
Q_strcat(errorText, sizeof(errorText),
va("Also check that every file "
"in the \"%s\" directory is present and readable", BASEGAME));
}
else
{
Q_strcat(errorText, sizeof(errorText),
va("Also check that your ioq3 executable is in "
"the correct place and that every file "
"in the \"%s\" directory is present and readable", BASEGAME));
}

Com_Error(ERR_FATAL, "%s", errorText);
}
Expand All @@ -3697,18 +3723,27 @@ static void FS_CheckPak0( void )

Q_strcat(errorText, sizeof(errorText),
va(" from the \"%s\" directory in your Quake 3 Team Arena install or CD-ROM to:\n\n"
"%s%c%s%c\n\n", BASETA, fs_basepath->string, PATH_SEP, BASETA, PATH_SEP));
"%s%c%s%c\n\n", BASETA, installPath, PATH_SEP, BASETA, PATH_SEP));

Q_strcat(errorText, sizeof(errorText),
"Quake 3 Team Arena must be purchased to legitimately obtain pak0. "
"Quake 3 Team Arena point release files (pak1 through pak3) "
"are freely available at:\n\n"
"https://ioquake3.org/extras/patch-data/\n\n");

Q_strcat(errorText, sizeof(errorText),
va("Also check that your ioq3 executable is in "
"the correct place and that every file "
"in the \"%s\" directory is present and readable", BASETA));
if(installHome)
{
Q_strcat(errorText, sizeof(errorText),
va("Also check that every file "
"in the \"%s\" directory is present and readable", BASETA));
}
else
{
Q_strcat(errorText, sizeof(errorText),
va("Also check that your ioq3 executable is in "
"the correct place and that every file "
"in the \"%s\" directory is present and readable", BASETA));
}

Com_Error(ERR_FATAL, "%s", errorText);
}
Expand Down
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