16std::filesystem::path SteamPaths::cachedSteamRoot_;
17std::filesystem::path SteamPaths::cachedHomeDir_;
18bool SteamPaths::cacheInitialized_ =
false;
19std::mutex SteamPaths::cacheMutex_;
27 std::lock_guard<std::mutex> lock(cacheMutex_);
29 if (!cachedHomeDir_.empty())
31 return cachedHomeDir_;
34 const char* home = std::getenv(
"HOME");
35 if (!home || home[0] ==
'\0')
40 cachedHomeDir_ = std::filesystem::path(home);
41 return cachedHomeDir_;
46 std::vector<std::filesystem::path> roots;
55 if (isValidSteamRoot(standardPath))
57 roots.push_back(standardPath);
62 if (isValidSteamRoot(alt1) && alt1 != standardPath)
64 roots.push_back(alt1);
68 if (isValidSteamRoot(alt2) && alt2 != standardPath && alt2 != alt1)
70 roots.push_back(alt2);
75 if (isValidSteamRoot(flatpakPath))
77 roots.push_back(flatpakPath);
82 if (isValidSteamRoot(snapPath))
84 roots.push_back(snapPath);
92 std::unique_lock<std::mutex> lock(cacheMutex_);
94 if (cacheInitialized_)
96 return cachedSteamRoot_;
105 if (!cacheInitialized_)
108 cachedSteamRoot_ = roots[0];
109 cacheInitialized_ =
true;
112 return cachedSteamRoot_;
122 if (steamRoot.empty())
133 if (userDataDir.empty())
144 if (steamRoot.empty())
155 if (steamRoot.empty())
170 if (steamRoot.empty())
186 std::string filename =
198 const std::string& installDir)
209 std::vector<std::filesystem::path> paths;
213 if (!steamRoot.empty())
216 if (std::filesystem::exists(userCompatTools))
218 paths.push_back(userCompatTools);
228 std::filesystem::path flatpakCompatTools =
230 if (std::filesystem::exists(flatpakCompatTools))
232 paths.push_back(flatpakCompatTools);
243 std::filesystem::path snapCompatTools =
245 if (std::filesystem::exists(snapCompatTools))
247 paths.push_back(snapCompatTools);
254 if (std::filesystem::exists(systemPath1))
256 paths.push_back(systemPath1);
260 if (std::filesystem::exists(systemPath2))
262 paths.push_back(systemPath2);
270 std::vector<std::filesystem::path> paths;
278 for (
const auto& root : roots)
280 std::filesystem::path commonDir =
282 if (std::filesystem::exists(commonDir))
284 paths.push_back(commonDir);
318 return !steamRoot.empty();
327 std::lock_guard<std::mutex> lock(cacheMutex_);
328 cachedSteamRoot_.clear();
329 cachedHomeDir_.clear();
330 cacheInitialized_ =
false;
335 std::lock_guard<std::mutex> lock(cacheMutex_);
336 return cacheInitialized_;
343bool SteamPaths::isValidSteamRoot(
const std::filesystem::path& path)
345 if (!std::filesystem::exists(path))
352 return std::filesystem::exists(steamapps) && std::filesystem::is_directory(steamapps);
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.
constexpr const char * APPMANIFEST_PREFIX
Prefix for game manifest files.
constexpr const char * STEAM_ROOT_PATH
Primary Steam installation directory.
constexpr const char * STEAM_ROOT_ALT1
Alternative Steam installation (symlink).
constexpr const char * SNAP_STEAM_PATH
Snap Steam installation path.
constexpr const char * COMPATDATA_DIR
Directory containing Proton compatibility data.
constexpr const char * SYSTEM_COMPAT_TOOLS_PATH1
System compatibility tools directory (distro-provided).
constexpr const char * STEAM_ROOT_ALT2
Alternative Steam installation (legacy).
constexpr const char * SYSTEM_COMPAT_TOOLS_PATH2
Alternative system compatibility tools directory.
constexpr const char * LOGIN_USERS_VDF
File containing user login information.
constexpr const char * LIBRARY_FOLDERS_VDF
File containing library folder paths.
constexpr const char * CONFIG_DIR
Directory containing global Steam configuration.
constexpr const char * LOCAL_CONFIG_VDF
File containing per-user game settings (launch options, playtime).
constexpr const char * COMMON_DIR
Directory containing installed games (within steamapps).
constexpr const char * COMPAT_TOOLS_DIR
Directory containing compatibility tools.
constexpr const char * CONFIG_VDF
File containing global Steam configuration (Proton mappings).
constexpr const char * FLATPAK_STEAM_PATH
Flatpak Steam installation path.
constexpr const char * STEAMAPPS_DIR
Directory containing installed games.
constexpr const char * USERDATA_DIR
Directory containing user-specific data.