21 std::optional<std::filesystem::path> findSteamRoot()
const override
23 auto paths = Paths::create();
24 std::filesystem::path home = paths->getHomeDir();
27 std::vector<std::filesystem::path> candidates = {
28 home /
".local" /
"share" /
"Steam",
29 home /
".steam" /
"root",
30 home /
".steam" /
"steam",
31 home /
".steam" /
"debian-installation",
33 home /
".var" /
"app" /
"com.valvesoftware.Steam" /
".local" /
"share" /
"Steam",
34 home /
".var" /
"app" /
"com.valvesoftware.Steam" /
".steam" /
"steam",
36 home /
"snap" /
"steam" /
"common" /
".local" /
"share" /
"Steam",
39 for (
const auto& path : candidates)
41 if (std::filesystem::exists(path /
"steam.sh") ||
42 std::filesystem::exists(path /
"steamapps"))
47 return std::filesystem::canonical(path);
59 std::vector<SteamLibraryFolder> getLibraryFolders()
const override
61 std::vector<SteamLibraryFolder> folders;
63 auto steamRoot = findSteamRoot();
68 SteamLibraryFolder mainFolder;
69 mainFolder.path = *steamRoot;
70 mainFolder.label =
"Main";
71 folders.push_back(mainFolder);
74 std::filesystem::path vdfPath = *steamRoot /
"steamapps" /
"libraryfolders.vdf";
75 if (!std::filesystem::exists(vdfPath))
78 vdfPath = *steamRoot /
"config" /
"libraryfolders.vdf";
81 if (std::filesystem::exists(vdfPath))
83 std::ifstream file(vdfPath);
84 std::string content((std::istreambuf_iterator<char>(file)),
85 std::istreambuf_iterator<char>());
88 std::regex pathRegex(R
"re("path"\s+"([^"]+)")re");
90 std::string::const_iterator searchStart(content.cbegin());
92 while (std::regex_search(searchStart, content.cend(), match, pathRegex))
94 std::filesystem::path libPath = match[1].str();
95 if (std::filesystem::exists(libPath) && libPath != *steamRoot)
97 SteamLibraryFolder folder;
98 folder.path = libPath;
99 folder.label = libPath.filename().string();
100 folders.push_back(folder);
102 searchStart = match.suffix().first;
109 std::vector<std::filesystem::path> getCompatToolsDirs()
const override
111 std::vector<std::filesystem::path> dirs;
113 auto steamRoot = findSteamRoot();
114 auto paths = Paths::create();
115 std::filesystem::path home = paths->getHomeDir();
120 dirs.push_back(*steamRoot /
"steamapps" /
"common" /
"Proton - Experimental");
121 dirs.push_back(*steamRoot /
"steamapps" /
"common");
122 dirs.push_back(*steamRoot /
"compatibilitytools.d");
126 dirs.push_back(home /
".steam" /
"root" /
"compatibilitytools.d");
127 dirs.push_back(home /
".local" /
"share" /
"Steam" /
"compatibilitytools.d");
130 dirs.push_back(
"/usr/share/steam/compatibilitytools.d");
131 dirs.push_back(
"/opt/steam/compatibilitytools.d");
134 std::vector<std::filesystem::path> existing;
135 for (
const auto& dir : dirs)
137 if (std::filesystem::exists(dir))
139 existing.push_back(dir);
146 std::optional<std::filesystem::path> findGameInstall(uint32_t appId)
const override
148 auto libraries = getLibraryFolders();
150 for (
const auto& lib : libraries)
153 std::filesystem::path manifestPath =
154 lib.path /
"steamapps" / (
"appmanifest_" + std::to_string(appId) +
".acf");
156 if (std::filesystem::exists(manifestPath))
159 std::ifstream file(manifestPath);
160 std::string content((std::istreambuf_iterator<char>(file)),
161 std::istreambuf_iterator<char>());
163 std::regex installDirRegex(R
"re("installdir"\s+"([^"]+)")re");
165 if (std::regex_search(content, match, installDirRegex))
167 return lib.path /
"steamapps" /
"common" / match[1].str();
175 bool isSteamRunning()
const override
177 auto pm = ProcessManager::create();
178 auto procs = pm->findByName(
"steam");
179 return !procs.empty();
182 bool startSteam(
bool silent)
const override
184 auto pm = ProcessManager::create();
186 std::string command =
"steam";
189 command +=
" -silent";
192 auto pid = pm->launchShell(command);
193 return pid.has_value();
196 bool shutdownSteam()
const override
198 auto pm = ProcessManager::create();
199 auto result = pm->executeAndCapture(
"steam -shutdown", 5000);
200 return result.first == 0;
203 bool launchGame(uint32_t appId)
const override
205 auto pm = ProcessManager::create();
206 std::string command =
"steam steam://rungameid/" + std::to_string(appId);
207 auto pid = pm->launchShell(command);
208 return pid.has_value();
211 bool launchGameWithArgs(uint32_t appId,
const std::string& args)
const override
213 auto pm = ProcessManager::create();
214 std::string command =
"steam -applaunch " + std::to_string(appId);
218 std::istringstream argStream(args);
220 while (argStream >> arg)
225 auto pid = pm->launchShell(command);
226 return pid.has_value();
229 std::optional<std::filesystem::path> getSteamExecutable()
const override
232 auto pm = ProcessManager::create();
233 auto result = pm->executeAndCapture(
"which steam", 1000);
234 if (result.first == 0 && !result.second.empty())
237 std::string path = result.second;
238 while (!path.empty() && (path.back() ==
'\n' || path.back() ==
'\r'))
242 if (std::filesystem::exists(path))
249 std::vector<std::filesystem::path> candidates = {
252 "/usr/local/bin/steam",
255 for (
const auto& path : candidates)
257 if (std::filesystem::exists(path))
264 auto steamRoot = findSteamRoot();
265 if (steamRoot && std::filesystem::exists(*steamRoot /
"steam.sh"))
267 return *steamRoot /
"steam.sh";
273 bool isSteamInstalled()
const override
275 return findSteamRoot().has_value() || getSteamExecutable().has_value();
282 return std::make_unique<LinuxSteamFinder>();
static std::string escapeArg(const std::string &arg)
Escape a string for safe use as a shell argument.