game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
steam_paths.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// steam_paths.h
4// ==============================================================================
5// Centralized Steam path management and construction
6// ==============================================================================
7// This class provides a single point of access for all Steam-related filesystem
8// paths. It handles:
9// - Home directory resolution
10// - Multiple Steam installation detection (standard, Flatpak, Snap)
11// - Configuration file path construction
12// - Library and game directory paths
13// - Path caching for performance
14// - Special installation detection (Flatpak/Snap)
15// ==============================================================================
16
17#pragma once
18
19#include <filesystem>
20#include <mutex>
21#include <string>
22#include <vector>
23
24/**
25 * @class SteamPaths
26 * @brief Centralized management of all Steam-related filesystem paths
27 *
28 * Provides thread-safe, cached access to Steam paths across different
29 * installation types (standard, Flatpak, Snap).
30 *
31 * ## Thread Safety
32 * All methods are thread-safe. Internal caching uses mutex protection.
33 *
34 * ## Path Caching
35 * Steam root paths are cached on first access for performance. Call
36 * invalidateCache() if Steam is reinstalled or moved.
37 */
39{
40 public:
41 // ==========================================================================
42 // Core Directory Resolution
43 // ==========================================================================
44
45 /**
46 * @brief Get user's home directory
47 * @return Path to home directory, or empty path if HOME is unset
48 *
49 * Aligns with the rest of this API: failures yield empty paths/vectors
50 * rather than exceptions, and callers gate on the empty result.
51 */
52 static std::filesystem::path getHomeDirectory();
53
54 /**
55 * @brief Get all possible Steam installation directories
56 * @return Vector of Steam root paths (may be empty if Steam not installed)
57 *
58 * Checks in order:
59 * 1. ~/.local/share/Steam (standard)
60 * 2. ~/.steam/root (symlink)
61 * 3. ~/.steam/steam (legacy)
62 * 4. Flatpak: ~/.var/app/com.valvesoftware.Steam/.local/share/Steam
63 * 5. Snap: ~/snap/steam/common/.local/share/Steam
64 */
65 static std::vector<std::filesystem::path> getAllSteamRoots();
66
67 /**
68 * @brief Get primary Steam installation directory
69 * @return Path to Steam root (empty if Steam not found)
70 *
71 * Returns the first valid Steam installation found. Cached after first call.
72 */
73 static std::filesystem::path getPrimarySteamRoot();
74
75 // ==========================================================================
76 // Configuration Paths
77 // ==========================================================================
78
79 /**
80 * @brief Get Steam userdata directory
81 * @return Path to userdata directory (e.g., ~/.local/share/Steam/userdata)
82 */
83 static std::filesystem::path getUserDataDirectory();
84
85 /**
86 * @brief Get path to user's localconfig.vdf
87 * @param userId Steam user ID (as string)
88 * @return Path to localconfig.vdf for specified user
89 *
90 * Example: ~/.local/share/Steam/userdata/12345678/config/localconfig.vdf
91 */
92 static std::filesystem::path getLocalConfigPath(const std::string& userId);
93
94 /**
95 * @brief Get path to global config.vdf
96 * @return Path to Steam's global configuration file
97 *
98 * Example: ~/.local/share/Steam/config/config.vdf
99 */
100 static std::filesystem::path getConfigPath();
101
102 /**
103 * @brief Get path to loginusers.vdf
104 * @return Path to Steam's user login information file
105 */
106 static std::filesystem::path getLoginUsersPath();
107
108 // ==========================================================================
109 // Library & Game Paths
110 // ==========================================================================
111
112 /**
113 * @brief Get path to libraryfolders.vdf
114 * @return Path to library folders configuration file
115 *
116 * Example: ~/.local/share/Steam/steamapps/libraryfolders.vdf
117 */
118 static std::filesystem::path getLibraryFoldersPath();
119
120 /**
121 * @brief Get steamapps directory for a library
122 * @param libraryRoot Root directory of a Steam library
123 * @return Path to steamapps directory within that library
124 */
125 static std::filesystem::path getSteamAppsPath(const std::filesystem::path& libraryRoot);
126
127 /**
128 * @brief Get path to an appmanifest file
129 * @param libraryRoot Root directory of Steam library
130 * @param appId Steam App ID
131 * @return Path to `appmanifest_{AppID}.acf` file
132 */
133 static std::filesystem::path getAppManifestPath(const std::filesystem::path& libraryRoot,
134 uint32_t appId);
135
136 /**
137 * @brief Get path to game's compatdata directory (Proton prefix)
138 * @param libraryRoot Root directory of Steam library
139 * @param appId Steam App ID
140 * @return Path to `compatdata/{AppID}` directory
141 */
142 static std::filesystem::path getCompatDataPath(const std::filesystem::path& libraryRoot,
143 uint32_t appId);
144
145 /**
146 * @brief Get path to game's installation directory
147 * @param libraryRoot Root directory of Steam library
148 * @param installDir Install directory name from appmanifest (e.g., "Half-Life 2")
149 * @return Path to game installation (e.g., .../steamapps/common/Half-Life 2)
150 */
151 static std::filesystem::path getGameInstallPath(const std::filesystem::path& libraryRoot,
152 const std::string& installDir);
153
154 // ==========================================================================
155 // Compatibility Tools Paths
156 // ==========================================================================
157
158 /**
159 * @brief Get all compatibility tools directories
160 * @return Vector of paths where Proton/compatibility tools can be found
161 *
162 * Returns paths in priority order:
163 * 1. User-installed: ~/.local/share/Steam/compatibilitytools.d
164 * 2. Flatpak: ~/.var/app/.../compatibilitytools.d
165 * 3. Snap: ~/snap/steam/.../compatibilitytools.d
166 * 4. System-wide: /usr/share/steam/compatibilitytools.d
167 * 5. System-wide alt: /opt/steam/compatibilitytools.d
168 */
169 static std::vector<std::filesystem::path> getCompatToolsPaths();
170
171 /**
172 * @brief Get paths where official Proton versions are installed
173 * @return Vector of steamapps/common directories from all libraries
174 *
175 * Official Proton versions are in steamapps/common/Proton* directories.
176 */
177 static std::vector<std::filesystem::path> getProtonInstallPaths();
178
179 // ==========================================================================
180 // Installation Type Detection
181 // ==========================================================================
182
183 /**
184 * @brief Check if Steam is installed via Flatpak
185 * @return True if Flatpak Steam installation exists
186 */
187 static bool isFlatpakSteam();
188
189 /**
190 * @brief Check if Steam is installed via Snap
191 * @return True if Snap Steam installation exists
192 */
193 static bool isSnapSteam();
194
195 /**
196 * @brief Check if Steam is installed (any method)
197 * @return True if any Steam installation found
198 */
199 static bool isSteamInstalled();
200
201 // ==========================================================================
202 // Cache Management
203 // ==========================================================================
204
205 /**
206 * @brief Invalidate cached paths
207 *
208 * Call this if Steam is reinstalled, moved, or switched between
209 * Flatpak/Snap/native installations.
210 */
211 static void invalidateCache();
212
213 /**
214 * @brief Check if path cache is initialized
215 * @return True if cache has been populated
216 */
217 static bool isCacheValid();
218
219 private:
220 // ==========================================================================
221 // Internal State
222 // ==========================================================================
223
224 static std::filesystem::path cachedSteamRoot_;
225 static std::filesystem::path cachedHomeDir_;
226 static bool cacheInitialized_;
227 static std::mutex cacheMutex_;
228
229 /**
230 * @brief Initialize cached paths (called automatically on first access)
231 */
232 static void initializeCache();
233
234 /**
235 * @brief Check if a path is a valid Steam installation
236 * @param path Path to check
237 * @return True if path contains a valid Steam installation
238 */
239 static bool isValidSteamRoot(const std::filesystem::path& path);
240};
Centralized management of all Steam-related filesystem paths.
Definition steam_paths.h:39
static bool isCacheValid()
Check if path cache is initialized.
static std::vector< std::filesystem::path > getCompatToolsPaths()
Get all compatibility tools directories.
static std::filesystem::path getGameInstallPath(const std::filesystem::path &libraryRoot, const std::string &installDir)
Get path to game's installation directory.
static std::filesystem::path getLocalConfigPath(const std::string &userId)
Get path to user's localconfig.vdf.
static std::filesystem::path getAppManifestPath(const std::filesystem::path &libraryRoot, uint32_t appId)
Get path to an appmanifest file.
static std::filesystem::path getConfigPath()
Get path to global config.vdf.
static std::filesystem::path getHomeDirectory()
Get user's home directory.
static std::filesystem::path getUserDataDirectory()
Get Steam userdata directory.
static std::vector< std::filesystem::path > getAllSteamRoots()
Get all possible Steam installation directories.
static std::filesystem::path getCompatDataPath(const std::filesystem::path &libraryRoot, uint32_t appId)
Get path to game's compatdata directory (Proton prefix).
static bool isFlatpakSteam()
Check if Steam is installed via Flatpak.
static void invalidateCache()
Invalidate cached paths.
static std::filesystem::path getPrimarySteamRoot()
Get primary Steam installation directory.
static std::vector< std::filesystem::path > getProtonInstallPaths()
Get paths where official Proton versions are installed.
static bool isSteamInstalled()
Check if Steam is installed (any method).
static std::filesystem::path getLoginUsersPath()
Get path to loginusers.vdf.
static std::filesystem::path getSteamAppsPath(const std::filesystem::path &libraryRoot)
Get steamapps directory for a library.
static std::filesystem::path getLibraryFoldersPath()
Get path to libraryfolders.vdf.
static bool isSnapSteam()
Check if Steam is installed via Snap.