Skip to content

Commit

Permalink
Look for Steam in a few more places on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Sep 29, 2024
1 parent 575ade3 commit cb1ebef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
16 changes: 16 additions & 0 deletions Quake/steam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Quake/steam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 10 additions & 6 deletions Quake/sys_sdl_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit cb1ebef

Please sign in to comment.