15namespace fs = std::filesystem;
26 fs::path fullPath = fs::path(
prefix) /
exe;
27 return fullPath.string();
46 const char* home = std::getenv(
"HOME");
51 std::string nativePath = (fs::path(home) /
".local" /
"share" /
"lutris" /
"games").
string();
52 if (fs::exists(nativePath))
56 std::string flatpakPath =
57 (fs::path(home) /
".var" /
"app" /
"net.lutris.Lutris" /
"data" /
"lutris" /
"games")
59 if (fs::exists(flatpakPath))
68 const char* home = std::getenv(
"HOME");
71 return (fs::path(home) /
".local" /
"share" /
"lutris" /
"runners").string();
77 if (gamesDir.empty() || !fs::exists(gamesDir))
86 exePath = fs::canonical(executablePath);
90 exePath = executablePath;
92 std::string exePathStr = exePath.string();
94 Logger::info(
"[LutrisConfig] Searching for config matching: {}", exePathStr);
99 for (
const auto& entry : fs::directory_iterator(gamesDir))
101 if (!entry.is_regular_file())
104 std::string filename = entry.path().filename().string();
105 if (filename.size() < 4 || filename.substr(filename.size() - 4) !=
".yml")
114 if (configExe.empty())
118 fs::path configExePath;
121 configExePath = fs::canonical(configExe);
125 configExePath = configExe;
129 if (configExePath == exePath)
131 Logger::info(
"[LutrisConfig] Found matching config: {}", entry.path().string());
132 return entry.path().string();
136 catch (
const std::exception& e)
138 Logger::warn(
"[LutrisConfig] Error searching configs: {}", e.what());
148 std::ifstream file(configPath);
151 Logger::warn(
"[LutrisConfig] Failed to open config: {}", configPath);
156 bool inEnvSection =
false;
157 bool inOverridesSection =
false;
170 Section section = Section::Root;
173 std::string* continuationTarget =
nullptr;
174 int continuationIndent = 0;
176 while (std::getline(file, line))
179 std::string trimmedLine = trim(line);
180 if (trimmedLine.empty() || trimmedLine[0] ==
'#')
183 int indent = countIndent(line);
188 if (continuationTarget !=
nullptr && indent > continuationIndent)
192 *continuationTarget +=
" " + trimmedLine;
198 continuationTarget =
nullptr;
199 continuationIndent = 0;
205 section = Section::Root;
206 inEnvSection =
false;
207 inOverridesSection =
false;
209 if (trimmedLine ==
"game:")
211 section = Section::Game;
213 else if (trimmedLine ==
"system:")
215 section = Section::System;
217 else if (trimmedLine ==
"wine:")
219 section = Section::Wine;
227 if (
auto v1 = extractYamlValue(trimmedLine,
"name"); !v1.empty())
229 else if (
auto v2 = extractYamlValue(trimmedLine,
"slug"); !v2.empty())
231 else if (
auto v3 = extractYamlValue(trimmedLine,
"game_slug"); !v3.empty())
235 else if (indent == 2)
238 if (section == Section::Game)
240 if (
auto v1 = extractYamlValue(trimmedLine,
"exe"); !v1.empty())
244 continuationTarget = &config.
exe;
245 continuationIndent = indent;
247 else if (
auto v2 = extractYamlValue(trimmedLine,
"prefix"); !v2.empty())
249 else if (
auto v3 = extractYamlValue(trimmedLine,
"arch"); !v3.empty())
251 else if (
auto v4 = extractYamlValue(trimmedLine,
"args"); !v4.empty())
256 continuationIndent = indent;
258 else if (
auto v5 = extractYamlValue(trimmedLine,
"working_dir"); !v5.empty())
262 continuationIndent = indent;
265 else if (section == Section::System)
267 if (trimmedLine ==
"env:")
273 inEnvSection =
false;
277 if (
auto value = extractYamlValue(trimmedLine,
"exclude_processes");
282 bool inQuotes =
false;
287 inQuotes = !inQuotes;
289 else if (c ==
' ' && !inQuotes)
291 if (!current.empty())
302 if (!current.empty())
309 else if (section == Section::Wine)
311 if (
auto v1 = extractYamlValue(trimmedLine,
"version"); !v1.empty())
313 else if (
auto v2 = extractYamlValue(trimmedLine,
"custom_wine_path"); !v2.empty())
315 else if (trimmedLine ==
"overrides:")
317 inOverridesSection =
true;
321 inOverridesSection =
false;
325 else if (indent == 4)
328 if (section == Section::System && inEnvSection)
331 size_t colonPos = trimmedLine.find(
':');
332 if (colonPos != std::string::npos)
334 std::string key = trim(trimmedLine.substr(0, colonPos));
335 std::string value = trim(trimmedLine.substr(colonPos + 1));
336 value = unquote(value);
340 if (!config.
prefix.empty())
343 while ((pos = value.find(
"$GAMEDIR", pos)) != std::string::npos)
345 value.replace(pos, 8, config.
prefix);
346 pos += config.
prefix.size();
356 else if (section == Section::Wine && inOverridesSection)
359 size_t colonPos = trimmedLine.find(
':');
360 if (colonPos != std::string::npos)
362 std::string dll = trim(trimmedLine.substr(0, colonPos));
363 std::string
override = trim(trimmedLine.substr(colonPos + 1));
364 override = unquote(
override);
383 Logger::info(
"[LutrisConfig] Parsed config for: {} (prefix: {}, exe: {})", config.
name,
388 Logger::info(
"[LutrisConfig] Environment variables: {}",
397 Logger::debug(
"[LutrisConfig] Invalid config (name: {}, prefix: {}, exe: {})", config.
name,
404std::string LutrisConfigParser::readWineRunnerConfig()
407 if (runnersDir.empty())
410 fs::path wineConfigPath = fs::path(runnersDir) /
"wine.yml";
411 if (!fs::exists(wineConfigPath))
414 std::ifstream file(wineConfigPath);
419 bool inWineSection =
false;
421 while (std::getline(file, line))
423 std::string trimmedLine = trim(line);
424 if (trimmedLine.empty() || trimmedLine[0] ==
'#')
427 int indent = countIndent(line);
429 if (indent == 0 && trimmedLine ==
"wine:")
431 inWineSection =
true;
434 else if (indent == 0)
436 inWineSection =
false;
439 if (inWineSection && indent == 2)
441 std::string value = extractYamlValue(trimmedLine,
"custom_wine_path");
444 Logger::info(
"[LutrisConfig] Found custom wine path in runner config: {}", value);
453std::string LutrisConfigParser::extractYamlValue(
const std::string& line,
const std::string& key,
456 std::string trimmedLine = trim(line);
459 std::string keyPattern = key +
":";
460 if (trimmedLine.find(keyPattern) != 0)
464 std::string value = trimmedLine.substr(keyPattern.size());
466 value = unquote(value);
471int LutrisConfigParser::countIndent(
const std::string& line)
484std::string LutrisConfigParser::trim(
const std::string& str)
486 size_t first = str.find_first_not_of(
" \t\r\n");
487 if (first == std::string::npos)
489 size_t last = str.find_last_not_of(
" \t\r\n");
490 return str.substr(first, last - first + 1);
493std::string LutrisConfigParser::unquote(
const std::string& str)
498 char first = str.front();
499 char last = str.back();
501 if ((first ==
'"' && last ==
'"') || (first ==
'\'' && last ==
'\''))
503 return str.substr(1, str.size() - 2);
Complete representation of a game in the library.
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
static std::string findConfigForExecutable(const std::string &executablePath)
Find Lutris config file for a given executable.
static std::string getGamesDirectory()
Get the Lutris games directory.
static std::string getRunnersDirectory()
Get the Lutris runners directory.
static LutrisGameConfig parseConfigFile(const std::string &configPath)
Parse a Lutris game config file.
@ Wine
Windows game via Wine compatibility layer.
Parsed configuration for a Lutris-managed game.
std::string workingDir
Working directory (optional).
std::string gameSlug
Game slug from lutris.net.
std::string name
Game display name.
std::string getFullExecutablePath() const
Get the full path to the executable.
std::map< std::string, std::string > dllOverrides
std::string prefix
Wine prefix path.
std::map< std::string, std::string > environmentVariables
std::string exe
Relative path to executable (from prefix).
std::vector< std::string > excludeProcesses
std::string wineVersion
Wine version name (e.g., "Proton - Experimental").
std::string slug
Game slug (unique identifier).
std::string arguments
Command line arguments (optional).
bool isValid() const
Check if config is valid and usable.
std::string arch
Wine architecture: "win32" or "win64".
std::string winePath
Full path to wine executable.
std::string customWinePath
Custom wine path from runner config.
std::string getEffectiveWinePath() const
Get the effective wine path to use.