game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
lutris_config.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// lutris_config.h
4// ==============================================================================
5// Lutris game configuration parser
6// ==============================================================================
7// This file provides functionality for reading and parsing Lutris game
8// configuration files (YAML format). It extracts the necessary settings
9// to launch games with the same configuration as Lutris.
10//
11// ## Configuration Locations
12// - Game configs: ~/.local/share/lutris/games/*.yml
13// - Runner config: ~/.local/share/lutris/runners/wine.yml
14// - System config: ~/.local/share/lutris/system.yml
15//
16// ## Parsed Settings
17// - Wine prefix path
18// - Wine executable path
19// - Environment variables
20// - Wine architecture (win32/win64)
21// ==============================================================================
22
23#pragma once
24
25#include <map>
26#include <string>
27#include <vector>
28
29// ==============================================================================
30// Lutris Game Configuration
31// ==============================================================================
32
33/**
34 * @struct LutrisGameConfig
35 * @brief Parsed configuration for a Lutris-managed game
36 *
37 * Contains all the settings needed to launch a game the same way
38 * Lutris would launch it.
39 */
41{
42 // Game identification
43 std::string name; ///< Game display name
44 std::string slug; ///< Game slug (unique identifier)
45 std::string gameSlug; ///< Game slug from lutris.net
46
47 // Executable settings
48 std::string exe; ///< Relative path to executable (from prefix)
49 std::string prefix; ///< Wine prefix path
50 std::string arch; ///< Wine architecture: "win32" or "win64"
51 std::string workingDir; ///< Working directory (optional)
52 std::string arguments; ///< Command line arguments (optional)
53
54 // Wine configuration
55 std::string wineVersion; ///< Wine version name (e.g., "Proton - Experimental")
56 std::string winePath; ///< Full path to wine executable
57 std::string customWinePath; ///< Custom wine path from runner config
58
59 // Environment variables from system section
60 std::map<std::string, std::string> environmentVariables;
61
62 // DLL overrides from wine.overrides section
63 std::map<std::string, std::string> dllOverrides;
64
65 // Processes to exclude when tracking (launcher helper processes)
66 std::vector<std::string> excludeProcesses;
67
68 /**
69 * @brief Check if config is valid and usable
70 * @return True if the config has minimum required fields
71 */
72 bool isValid() const
73 {
74 return !prefix.empty() && !exe.empty();
75 }
76
77 /**
78 * @brief Get the full path to the executable
79 * @return Full path (prefix + exe) or empty string if invalid
80 */
81 std::string getFullExecutablePath() const;
82
83 /**
84 * @brief Get the effective wine path to use
85 * @return Wine path from config, custom path, or empty for system default
86 */
87 std::string getEffectiveWinePath() const;
88};
89
90// ==============================================================================
91// Lutris Configuration Parser
92// ==============================================================================
93
94/**
95 * @class LutrisConfigParser
96 * @brief Parser for Lutris game configuration files
97 *
98 * Provides static methods for finding and parsing Lutris game configs.
99 * Uses a simple YAML parser that handles the subset of YAML used by Lutris.
100 */
102{
103 public:
104 /**
105 * @brief Find Lutris config file for a given executable
106 * @param executablePath Full path to the game executable
107 * @return Path to the Lutris config file, or empty string if not found
108 *
109 * Searches through all Lutris game configs to find one that matches
110 * the given executable path.
111 */
112 static std::string findConfigForExecutable(const std::string& executablePath);
113
114 /**
115 * @brief Parse a Lutris game config file
116 * @param configPath Path to the .yml config file
117 * @return Parsed configuration (check isValid() for success)
118 *
119 * Parses the YAML config file and extracts relevant settings.
120 * Also reads runner config for wine path if using custom wine.
121 */
122 static LutrisGameConfig parseConfigFile(const std::string& configPath);
123
124 /**
125 * @brief Get the Lutris games directory
126 * @return Path to ~/.local/share/lutris/games/
127 */
128 static std::string getGamesDirectory();
129
130 /**
131 * @brief Get the Lutris runners directory
132 * @return Path to ~/.local/share/lutris/runners/
133 */
134 static std::string getRunnersDirectory();
135
136 private:
137 /**
138 * @brief Simple YAML key extraction
139 * @param line YAML line to parse
140 * @param key Key to look for
141 * @param indent Expected indentation level (spaces)
142 * @return Value if key matches, empty string otherwise
143 *
144 * This is a simple line-by-line parser that handles:
145 * - key: value
146 * - key: "quoted value"
147 * - key: 'quoted value'
148 */
149 static std::string extractYamlValue(const std::string& line, const std::string& key,
150 int indent = 0);
151
152 /**
153 * @brief Count leading spaces in a string
154 * @param line Line to check
155 * @return Number of leading spaces
156 */
157 static int countIndent(const std::string& line);
158
159 /**
160 * @brief Trim whitespace from a string
161 * @param str String to trim
162 * @return Trimmed string
163 */
164 static std::string trim(const std::string& str);
165
166 /**
167 * @brief Remove quotes from a string value
168 * @param str String to unquote
169 * @return String with leading/trailing quotes removed
170 */
171 static std::string unquote(const std::string& str);
172
173 /**
174 * @brief Read the wine runner config for custom wine path
175 * @return Custom wine path, or empty string if not configured
176 */
177 static std::string readWineRunnerConfig();
178};
Parser for Lutris game configuration files.
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.
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.