game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
installation_executor.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// installation_executor.h
4// ==============================================================================
5// Installation executor for Lutris installer scripts
6// ==============================================================================
7// Executes Lutris installer scripts step-by-step with progress tracking.
8// Handles file downloads, extraction, Wine prefix setup, and configuration.
9// ==============================================================================
10
11#pragma once
12
14
15#include <atomic>
16#include <cstdint>
17#include <functional>
18#include <map>
19#include <mutex>
20#include <string>
21#include <vector>
22
23// ==============================================================================
24// Installation State
25// ==============================================================================
26
27enum class InstallState
28{
30 Preparing, // Creating directories, resolving variables
31 DownloadingFiles, // Downloading installer files
32 ExtractingFiles, // Extracting archives
33 ExecutingSteps, // Running installation steps
34 ConfiguringWine, // Wine prefix setup, winetricks
35 Finalizing, // Creating shortcuts, saving config
39};
40
41// ==============================================================================
42// Installation Progress
43// ==============================================================================
44
46{
48 std::string stateDescription;
49
50 // Overall progress
51 int currentStep = 0;
52 int totalSteps = 0;
54
55 // Current operation details
56 std::string currentOperation;
58
59 // Download progress (when downloading)
60 uint64_t bytesDownloaded = 0;
61 uint64_t totalBytes = 0;
63 std::string currentFileName;
64
65 // Time estimates
66 int estimatedSecondsRemaining = -1; // -1 = unknown
67
68 // Log messages
69 std::vector<std::string> logMessages;
70 std::vector<std::string> warnings;
71 std::string errorMessage;
72};
73
74// ==============================================================================
75// Installation Configuration
76// ==============================================================================
77
79{
80 // Installation paths
81 std::string installPath; // Where to install the game (GAMEDIR)
82 std::string winePrefixPath; // Wine prefix location (can be inside installPath)
83 std::string downloadCachePath; // Where to store downloaded files
84
85 // Wine configuration
86 std::string wineVersion; // Which wine/proton to use (empty = system default)
87 std::string wineArch; // "win32" or "win64" (empty = from script)
88
89 // Options
91 bool createMenuEntry = false;
92 bool keepDownloadedFiles = true; // Keep files after install for reinstall
94
95 // Custom variable overrides
96 std::map<std::string, std::string> customVariables;
97};
98
99// ==============================================================================
100// Installation Result
101// ==============================================================================
102
104{
105 bool success = false;
106
107 // Paths
108 std::string installPath;
109 std::string executablePath; // Full path to main executable
110 std::string winePrefixPath;
111
112 // Game configuration (for creating Game object)
113 std::string gameName;
114 std::string gameSlug;
115 std::string runner; // "wine", "linux", "steam"
116 std::string arguments;
117 std::string workingDir;
118 std::map<std::string, std::string> environmentVariables;
119 std::map<std::string, std::string> dllOverrides;
120
121 // Status
122 std::string errorMessage;
123 std::vector<std::string> warnings;
124 std::vector<std::string> logMessages;
125
126 // Statistics
130};
131
132// ==============================================================================
133// Installation Executor
134// ==============================================================================
135
136/**
137 * @class InstallationExecutor
138 * @brief Executes Lutris installer scripts
139 *
140 * This class handles the complete installation process:
141 * 1. Prepare: Create directories, resolve variables
142 * 2. Download: Fetch required files with progress
143 * 3. Extract: Unpack archives
144 * 4. Install: Execute installation steps (copy, move, execute, etc.)
145 * 5. Configure: Set up Wine prefix, registry, etc.
146 * 6. Finalize: Create shortcuts, save configuration
147 */
149{
150 public:
151 using ProgressCallback = std::function<void(const InstallProgress&)>;
152 using CompletionCallback = std::function<void(const InstallResult&)>;
153 using LogCallback = std::function<void(const std::string&)>;
154
155 // =========================================================================
156 // Installation
157 // =========================================================================
158
159 /**
160 * @brief Execute an installation (blocking)
161 * @param script Lutris installer script
162 * @param config Installation configuration
163 * @param progressCallback Called with progress updates
164 * @return Installation result
165 */
166 static InstallResult install(const LutrisInstallerScript& script, const InstallConfig& config,
167 const ProgressCallback& progressCallback = nullptr);
168
169 /**
170 * @brief Execute an installation asynchronously
171 * @param script Lutris installer script
172 * @param config Installation configuration
173 * @param onComplete Called when installation finishes
174 * @param onProgress Called with progress updates
175 */
176 static void installAsync(const LutrisInstallerScript& script, const InstallConfig& config,
177 const CompletionCallback& onComplete,
178 const ProgressCallback& onProgress = nullptr);
179
180 // =========================================================================
181 // Control
182 // =========================================================================
183
184 /**
185 * @brief Cancel current installation
186 */
187 static void cancel();
188
189 /**
190 * @brief Check if an installation is in progress
191 */
192 static bool isInstalling();
193
194 /**
195 * @brief Get current installation state
196 */
198
199 /**
200 * @brief Get current progress
201 */
203
204 // =========================================================================
205 // Validation
206 // =========================================================================
207
208 /**
209 * @brief Validate that an installation can proceed
210 * @param script Installer script to validate
211 * @param config Installation config
212 * @return List of errors (empty if valid)
213 */
214 static std::vector<std::string> validate(const LutrisInstallerScript& script,
215 const InstallConfig& config);
216
217 /**
218 * @brief Calculate required disk space
219 * @param script Installer script
220 * @return Estimated bytes needed
221 */
222 static uint64_t estimateRequiredSpace(const LutrisInstallerScript& script);
223
224 /**
225 * @brief Get available disk space at path
226 * @param path Directory path
227 * @return Available bytes
228 */
229 static uint64_t getAvailableSpace(const std::string& path);
230
231 private:
232 // Phase executors
233 static bool executePrepare(const LutrisInstallerScript& script, InstallConfig& config,
234 InstallResult& result, std::map<std::string, std::string>& variables,
235 const ProgressCallback& progress);
236
237 static bool executeDownloads(const LutrisInstallerScript& script, const InstallConfig& config,
238 InstallResult& result,
239 std::map<std::string, std::string>& variables,
240 const ProgressCallback& progress);
241
242 static bool executeSteps(const LutrisInstallerScript& script, const InstallConfig& config,
243 InstallResult& result, std::map<std::string, std::string>& variables,
244 const ProgressCallback& progress);
245
246 static bool executeFinalize(const LutrisInstallerScript& script, const InstallConfig& config,
247 InstallResult& result,
248 std::map<std::string, std::string>& variables,
249 const ProgressCallback& progress);
250
251 // Step executors
252 static bool executeStep(const LutrisInstallStep& step,
253 std::map<std::string, std::string>& variables, InstallResult& result);
254
255 static bool stepExtract(const LutrisInstallStep& step,
256 std::map<std::string, std::string>& variables, InstallResult& result);
257
258 static bool stepCopy(const LutrisInstallStep& step,
259 std::map<std::string, std::string>& variables, InstallResult& result);
260
261 static bool stepMove(const LutrisInstallStep& step,
262 std::map<std::string, std::string>& variables, InstallResult& result);
263
264 static bool stepExecute(const LutrisInstallStep& step,
265 std::map<std::string, std::string>& variables, InstallResult& result);
266
267 static bool stepWriteFile(const LutrisInstallStep& step,
268 std::map<std::string, std::string>& variables, InstallResult& result);
269
270 static bool stepTask(const LutrisInstallStep& step,
271 std::map<std::string, std::string>& variables, InstallResult& result);
272
273 static bool stepChmodx(const LutrisInstallStep& step,
274 std::map<std::string, std::string>& variables, InstallResult& result);
275
276 static bool stepDelete(const LutrisInstallStep& step,
277 std::map<std::string, std::string>& variables, InstallResult& result);
278
279 static bool stepRename(const LutrisInstallStep& step,
280 std::map<std::string, std::string>& variables, InstallResult& result);
281
282 // Wine management
283 static bool createWinePrefix(const std::string& prefixPath, const std::string& arch,
284 const std::string& wineVersion, InstallResult& result);
285
286 static bool runWinetricks(const std::string& prefixPath, const std::string& wineVersion,
287 const std::vector<std::string>& verbs, InstallResult& result);
288
289 static bool setWineRegistry(const std::string& prefixPath, const std::string& wineVersion,
290 const std::string& path, const std::string& key,
291 const std::string& value, const std::string& type,
292 InstallResult& result);
293
294 // Desktop integration
295 static bool createDesktopShortcut(const InstallResult& result);
296 static bool createMenuEntry(const InstallResult& result);
297
298 // Variable handling
299 static std::map<std::string, std::string> buildVariables(const LutrisInstallerScript& script,
300 const InstallConfig& config);
301
302 static std::string substituteVariables(const std::string& input,
303 const std::map<std::string, std::string>& variables);
304
305 static std::string expandPath(const std::string& path);
306
307 // Utility
308 static void updateProgress(InstallProgress& progress, const ProgressCallback& callback);
309
310 static void addLogMessage(InstallProgress& progress, InstallResult& result,
311 const std::string& message);
312
313 static void addWarning(InstallProgress& progress, InstallResult& result,
314 const std::string& warning);
315
316 static int runCommand(const std::string& command, std::string& output);
317
318 static std::string getWinePath(const std::string& version);
319
320 // State
321 static std::atomic<InstallState> currentState_;
322 static std::atomic<bool> cancelRequested_;
323 static InstallProgress currentProgress_;
324 static std::mutex progressMutex_;
325};
Executes Lutris installer scripts.
std::function< void(const InstallProgress &)> ProgressCallback
std::function< void(const std::string &)> LogCallback
static bool isInstalling()
Check if an installation is in progress.
static InstallState getCurrentState()
Get current installation state.
std::function< void(const InstallResult &)> CompletionCallback
static uint64_t getAvailableSpace(const std::string &path)
Get available disk space at path.
static uint64_t estimateRequiredSpace(const LutrisInstallerScript &script)
Calculate required disk space.
static std::vector< std::string > validate(const LutrisInstallerScript &script, const InstallConfig &config)
Validate that an installation can proceed.
static InstallProgress getCurrentProgress()
Get current progress.
static void cancel()
Cancel current installation.
static void installAsync(const LutrisInstallerScript &script, const InstallConfig &config, const CompletionCallback &onComplete, const ProgressCallback &onProgress=nullptr)
Execute an installation asynchronously.
static InstallResult install(const LutrisInstallerScript &script, const InstallConfig &config, const ProgressCallback &progressCallback=nullptr)
Execute an installation (blocking).
std::string downloadCachePath
std::string winePrefixPath
std::map< std::string, std::string > customVariables
std::vector< std::string > logMessages
std::vector< std::string > warnings
std::vector< std::string > warnings
std::map< std::string, std::string > dllOverrides
std::map< std::string, std::string > environmentVariables
std::vector< std::string > logMessages