From cb1ebef6dfa154d7c5845c4c276f744bd821faaf Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Sun, 29 Sep 2024 12:37:14 +0200 Subject: [PATCH] Look for Steam in a few more places on Linux --- Quake/steam.c | 16 ++++++++++++++++ Quake/steam.h | 1 + Quake/sys_sdl_unix.c | 16 ++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Quake/steam.c b/Quake/steam.c index 5de737476..e79abf256 100644 --- a/Quake/steam.c +++ b/Quake/steam.c @@ -293,6 +293,22 @@ static void ACF_OnManifestProperty (vdbcontext_t *ctx, const char *key, const ch parser->result = value; } +/* +======================== +Steam_IsValidPath + +Returns true if the given path contains a valid Steam install +(based on the existence of a config/libraryfolders.vdf file) +======================== +*/ +qboolean Steam_IsValidPath (const char *path) +{ + char libpath[MAX_OSPATH]; + if ((size_t) q_snprintf (libpath, sizeof (libpath), "%s/config/libraryfolders.vdf", path) >= sizeof (libpath)) + return false; + return Sys_FileType (libpath) == FS_ENT_FILE; +} + /* ======================== Steam_ReadLibFolders diff --git a/Quake/steam.h b/Quake/steam.h index a7e7d1ba8..eb9925097 100644 --- a/Quake/steam.h +++ b/Quake/steam.h @@ -38,6 +38,7 @@ typedef struct steamgame_s { char library[MAX_OSPATH]; } steamgame_t; +qboolean Steam_IsValidPath (const char *path); qboolean Steam_FindGame (steamgame_t *game, int appid); qboolean Steam_ResolvePath (char *path, size_t pathsize, const steamgame_t *game); diff --git a/Quake/sys_sdl_unix.c b/Quake/sys_sdl_unix.c index fbab74106..68bcb7614 100644 --- a/Quake/sys_sdl_unix.c +++ b/Quake/sys_sdl_unix.c @@ -309,10 +309,8 @@ static int Sys_NumCPUs (void) qboolean Sys_GetSteamDir (char *path, size_t pathsize) { - const char STEAM_DIR[] = ".steam/steam"; - const char *home_dir = NULL; + const char *home_dir = NULL; struct passwd *pwent; - struct stat st; pwent = getpwuid( getuid() ); if (pwent == NULL) @@ -324,10 +322,16 @@ qboolean Sys_GetSteamDir (char *path, size_t pathsize) if (home_dir == NULL) return false; - if ((size_t) q_snprintf (path, pathsize, "%s/%s", home_dir, STEAM_DIR) >= pathsize) - return false; + if ((size_t) q_snprintf (path, pathsize, "%s/.steam/steam", home_dir) < pathsize && Steam_IsValidPath (path)) + return true; + if ((size_t) q_snprintf (path, pathsize, "%s/.local/share/Steam", home_dir) < pathsize && Steam_IsValidPath (path)) + return true; + if ((size_t) q_snprintf (path, pathsize, "%s/.var/app/com.valvesoftware.Steam/.steam/steam", home_dir) < pathsize && Steam_IsValidPath (path)) + return true; + if ((size_t) q_snprintf (path, pathsize, "%s/.var/app/com.valvesoftware.Steam/.local/share/Steam", home_dir) < pathsize && Steam_IsValidPath (path)) + return true; - return stat (path, &st) == 0 && S_ISDIR (st.st_mode); + return false; } qboolean Sys_GetSteamQuakeUserDir (char *path, size_t pathsize, const char *library)