game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
wine_dependency_manager.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// wine_dependency_manager.h
4// ==============================================================================
5// Wine dependency and component installation manager
6// ==============================================================================
7// Provides functionality for managing Wine prefix dependencies:
8// - Winetricks integration for installing Windows components
9// - Protontricks support for Steam Proton prefixes
10// - DLL override management
11// - Visual C++ redistributable installation
12// - DirectX component installation
13// - .NET Framework installation
14//
15// ## About Wine Dependencies
16// Windows games often require specific runtime libraries and components
17// that aren't included in Wine by default. This service provides a unified
18// interface for installing these dependencies.
19//
20// ## Thread Safety
21// All public methods are thread-safe.
22// ==============================================================================
23
24#pragma once
25
26#include <chrono>
27#include <filesystem>
28#include <functional>
29#include <future>
30#include <memory>
31#include <optional>
32#include <string>
33#include <vector>
34
35// ==============================================================================
36// Data Structures
37// ==============================================================================
38
39/**
40 * @enum DependencyCategory
41 * @brief Categories of Wine dependencies
42 */
44{
45 Redistributable, ///< VC++ redistributables, .NET, etc.
46 DirectX, ///< DirectX components
47 Font, ///< Windows fonts
48 Library, ///< DLLs and libraries
49 Setting, ///< Wine settings/tweaks
50 Game, ///< Game-specific fixes
51 Other ///< Miscellaneous
52};
53
54/**
55 * @struct WineDependency
56 * @brief Information about a Wine dependency/component
57 */
59{
60 std::string id; ///< Winetricks verb (e.g., "vcrun2019")
61 std::string name; ///< Human-readable name
62 std::string description; ///< Description of what it installs
64 std::vector<std::string> aliases; ///< Alternative names
65
66 // Installation info
67 bool isInstalled = false; ///< Whether installed in current prefix
68 std::string installedVersion;
69
70 // Requirements
71 std::vector<std::string> dependencies; ///< Other verbs this depends on
72 std::vector<std::string> conflicts; ///< Verbs this conflicts with
73 bool requires64bit = false; ///< Requires 64-bit prefix
74
75 // Metadata
76 std::string downloadUrl; ///< Direct download URL if known
77 int64_t downloadSize = 0; ///< Approximate download size
78 std::string publisher; ///< Microsoft, etc.
79};
80
81/**
82 * @struct DependencyInstallProgress
83 * @brief Progress information during dependency installation
84 */
86{
98
100 std::string currentVerb; ///< Current verb being installed
101 std::string currentStep; ///< Current step description
103 int verbsTotal = 0;
105 std::string errorMessage;
106
107 std::string getStateStr() const;
108};
109
110/**
111 * @struct PrefixDependencyStatus
112 * @brief Status of dependencies in a Wine prefix
113 */
115{
116 std::filesystem::path prefixPath;
117 std::string architecture; ///< "win32" or "win64"
118 std::vector<std::string> installedVerbs;
119 std::vector<std::string> missingRecommended;
120 std::chrono::system_clock::time_point lastScanned;
121};
122
123/**
124 * @struct DLLOverride
125 * @brief DLL override configuration
126 */
128{
129 std::string dllName;
130 std::string mode; ///< "native", "builtin", "native,builtin", etc.
131 bool isActive = true;
132};
133
134// ==============================================================================
135// WineDependencyManager Class
136// ==============================================================================
137
138/**
139 * @class WineDependencyManager
140 * @brief Service for managing Wine prefix dependencies
141 *
142 * Provides methods for installing and managing Windows components
143 * in Wine prefixes using winetricks or protontricks.
144 *
145 * ## Prerequisites
146 * - winetricks installed for Wine prefixes
147 * - protontricks installed for Proton prefixes (optional)
148 *
149 * ## Usage Example
150 * @code
151 * WineDependencyManager manager;
152 *
153 * // Install Visual C++ 2019 redistributable
154 * manager.installDependency(prefixPath, "vcrun2019", [](const auto& p) {
155 * std::cout << p.currentStep << std::endl;
156 * });
157 *
158 * // Install multiple dependencies
159 * manager.installDependencies(prefixPath, {"vcrun2019", "dxvk"});
160 * @endcode
161 */
163{
164 public:
165 using ProgressCallback = std::function<void(const DependencyInstallProgress&)>;
166
169
170 // ==========================================================================
171 // Availability Check
172 // ==========================================================================
173
174 /**
175 * @brief Check if winetricks is available
176 */
177 static bool isWinetricksAvailable();
178
179 /**
180 * @brief Check if protontricks is available
181 */
182 static bool isProtontricksAvailable();
183
184 /**
185 * @brief Get winetricks version
186 */
187 static std::string getWinetricksVersion();
188
189 /**
190 * @brief Get protontricks version
191 */
192 static std::string getProtontricksVersion();
193
194 // ==========================================================================
195 // Dependency Information
196 // ==========================================================================
197
198 /**
199 * @brief Get all available dependencies
200 * @return Vector of all known dependencies
201 */
202 std::vector<WineDependency> getAllDependencies() const;
203
204 /**
205 * @brief Get dependencies by category
206 * @param category Category to filter by
207 * @return Vector of dependencies in that category
208 */
209 std::vector<WineDependency> getDependenciesByCategory(DependencyCategory category) const;
210
211 /**
212 * @brief Get dependency info by ID
213 * @param verbId Winetricks verb ID
214 * @return Dependency info if found
215 */
216 std::optional<WineDependency> getDependencyInfo(const std::string& verbId) const;
217
218 /**
219 * @brief Search for dependencies
220 * @param query Search query
221 * @return Matching dependencies
222 */
223 std::vector<WineDependency> searchDependencies(const std::string& query) const;
224
225 /**
226 * @brief Get recommended dependencies for common game requirements
227 * @return List of commonly needed dependency IDs
228 */
229 std::vector<std::string> getRecommendedDependencies() const;
230
231 // ==========================================================================
232 // Prefix Analysis
233 // ==========================================================================
234
235 /**
236 * @brief Scan a prefix for installed dependencies
237 * @param prefixPath Path to Wine prefix
238 * @return Status of dependencies in prefix
239 */
240 PrefixDependencyStatus scanPrefix(const std::filesystem::path& prefixPath) const;
241
242 /**
243 * @brief Check if a specific dependency is installed
244 * @param prefixPath Path to Wine prefix
245 * @param verbId Winetricks verb ID
246 * @return True if installed
247 */
248 bool isDependencyInstalled(const std::filesystem::path& prefixPath,
249 const std::string& verbId) const;
250
251 /**
252 * @brief Get missing dependencies for a game
253 * @param prefixPath Path to Wine prefix
254 * @param requiredVerbs List of required verb IDs
255 * @return List of missing verb IDs
256 */
257 std::vector<std::string>
258 getMissingDependencies(const std::filesystem::path& prefixPath,
259 const std::vector<std::string>& requiredVerbs) const;
260
261 // ==========================================================================
262 // Installation
263 // ==========================================================================
264
265 /**
266 * @brief Install a single dependency
267 * @param prefixPath Path to Wine prefix
268 * @param verbId Winetricks verb ID
269 * @param progressCallback Progress updates
270 * @return True on success
271 */
272 bool installDependency(const std::filesystem::path& prefixPath, const std::string& verbId,
273 const ProgressCallback& progressCallback = nullptr);
274
275 /**
276 * @brief Install a dependency asynchronously
277 */
278 std::future<bool> installDependencyAsync(const std::filesystem::path& prefixPath,
279 const std::string& verbId,
280 const ProgressCallback& progressCallback = nullptr);
281
282 /**
283 * @brief Install multiple dependencies
284 * @param prefixPath Path to Wine prefix
285 * @param verbIds List of verb IDs to install
286 * @param progressCallback Progress updates
287 * @return Number of successfully installed dependencies
288 */
289 int installDependencies(const std::filesystem::path& prefixPath,
290 const std::vector<std::string>& verbIds,
291 const ProgressCallback& progressCallback = nullptr);
292
293 /**
294 * @brief Install dependencies for a Steam/Proton game
295 * @param steamAppId Steam app ID
296 * @param verbIds List of verb IDs to install
297 * @param progressCallback Progress updates
298 * @return True on success
299 */
300 bool installForSteamGame(uint32_t steamAppId, const std::vector<std::string>& verbIds,
301 const ProgressCallback& progressCallback = nullptr);
302
303 // ==========================================================================
304 // DLL Override Management
305 // ==========================================================================
306
307 /**
308 * @brief Get DLL overrides for a prefix
309 * @param prefixPath Path to Wine prefix
310 * @return List of DLL overrides
311 */
312 std::vector<DLLOverride> getDLLOverrides(const std::filesystem::path& prefixPath) const;
313
314 /**
315 * @brief Set a DLL override
316 * @param prefixPath Path to Wine prefix
317 * @param dllName DLL name (without .dll extension)
318 * @param mode Override mode
319 * @return True on success
320 */
321 bool setDLLOverride(const std::filesystem::path& prefixPath, const std::string& dllName,
322 const std::string& mode);
323
324 /**
325 * @brief Remove a DLL override
326 * @param prefixPath Path to Wine prefix
327 * @param dllName DLL name
328 * @return True on success
329 */
330 bool removeDLLOverride(const std::filesystem::path& prefixPath, const std::string& dllName);
331
332 // ==========================================================================
333 // Quick Install Presets
334 // ==========================================================================
335
336 /**
337 * @brief Install common gaming dependencies
338 * @param prefixPath Path to Wine prefix
339 * @param progressCallback Progress updates
340 * @return True on success
341 *
342 * Installs: vcrun2019, dxvk, corefonts
343 */
344 bool installGamingPreset(const std::filesystem::path& prefixPath,
345 const ProgressCallback& progressCallback = nullptr);
346
347 /**
348 * @brief Install DirectX dependencies
349 * @param prefixPath Path to Wine prefix
350 * @param progressCallback Progress updates
351 * @return True on success
352 */
353 bool installDirectXPreset(const std::filesystem::path& prefixPath,
354 const ProgressCallback& progressCallback = nullptr);
355
356 /**
357 * @brief Install .NET Framework
358 * @param prefixPath Path to Wine prefix
359 * @param version .NET version (e.g., "48" for 4.8)
360 * @param progressCallback Progress updates
361 * @return True on success
362 */
363 bool installDotNet(const std::filesystem::path& prefixPath, const std::string& version = "48",
364 const ProgressCallback& progressCallback = nullptr);
365
366 // ==========================================================================
367 // Configuration
368 // ==========================================================================
369
370 /**
371 * @brief Set custom Wine binary path
372 * @param winePath Path to Wine binary
373 */
374 void setWinePath(const std::filesystem::path& winePath);
375
376 /**
377 * @brief Set winetricks path
378 * @param path Path to winetricks script
379 */
380 void setWinetricksPath(const std::filesystem::path& path);
381
382 /**
383 * @brief Enable/disable GUI mode for winetricks
384 * @param enabled Whether to show winetricks GUI
385 */
386 void setGuiMode(bool enabled);
387
388 /**
389 * @brief Cancel ongoing operation
390 */
391 void cancelOperation();
392
393 // ==========================================================================
394 // Utility
395 // ==========================================================================
396
397 /**
398 * @brief Update winetricks to latest version
399 * @return True on success
400 */
401 bool updateWinetricks();
402
403 /**
404 * @brief Clear winetricks cache
405 */
406 void clearCache();
407
408 /**
409 * @brief Get winetricks cache directory
410 */
411 std::filesystem::path getCacheDirectory() const;
412
413 private:
414 struct Impl;
415 std::unique_ptr<Impl> impl_;
416
417 // Internal helpers
418 bool runWinetricks(const std::filesystem::path& prefixPath,
419 const std::vector<std::string>& args, const ProgressCallback& callback);
420
421 bool runProtontricks(uint32_t appId, const std::vector<std::string>& args,
422 const ProgressCallback& callback);
423
424 void initializeDependencyDatabase();
425 std::vector<std::string> parseInstalledFromLog(const std::filesystem::path& prefixPath) const;
426};
427
428/**
429 * @brief Get human-readable category name
430 */
431std::string dependencyCategoryName(DependencyCategory category);
Complete representation of a game in the library.
Definition game.h:767
bool installDotNet(const std::filesystem::path &prefixPath, const std::string &version="48", const ProgressCallback &progressCallback=nullptr)
Install .NET Framework.
bool updateWinetricks()
Update winetricks to latest version.
static std::string getProtontricksVersion()
Get protontricks version.
std::vector< WineDependency > searchDependencies(const std::string &query) const
Search for dependencies.
static bool isProtontricksAvailable()
Check if protontricks is available.
bool setDLLOverride(const std::filesystem::path &prefixPath, const std::string &dllName, const std::string &mode)
Set a DLL override.
int installDependencies(const std::filesystem::path &prefixPath, const std::vector< std::string > &verbIds, const ProgressCallback &progressCallback=nullptr)
Install multiple dependencies.
std::function< void(const DependencyInstallProgress &)> ProgressCallback
bool isDependencyInstalled(const std::filesystem::path &prefixPath, const std::string &verbId) const
Check if a specific dependency is installed.
PrefixDependencyStatus scanPrefix(const std::filesystem::path &prefixPath) const
Scan a prefix for installed dependencies.
bool installGamingPreset(const std::filesystem::path &prefixPath, const ProgressCallback &progressCallback=nullptr)
Install common gaming dependencies.
static bool isWinetricksAvailable()
Check if winetricks is available.
void cancelOperation()
Cancel ongoing operation.
std::vector< DLLOverride > getDLLOverrides(const std::filesystem::path &prefixPath) const
Get DLL overrides for a prefix.
bool removeDLLOverride(const std::filesystem::path &prefixPath, const std::string &dllName)
Remove a DLL override.
std::vector< WineDependency > getDependenciesByCategory(DependencyCategory category) const
Get dependencies by category.
std::vector< WineDependency > getAllDependencies() const
Get all available dependencies.
bool installDependency(const std::filesystem::path &prefixPath, const std::string &verbId, const ProgressCallback &progressCallback=nullptr)
Install a single dependency.
static std::string getWinetricksVersion()
Get winetricks version.
void setGuiMode(bool enabled)
Enable/disable GUI mode for winetricks.
void setWinePath(const std::filesystem::path &winePath)
Set custom Wine binary path.
bool installDirectXPreset(const std::filesystem::path &prefixPath, const ProgressCallback &progressCallback=nullptr)
Install DirectX dependencies.
std::vector< std::string > getMissingDependencies(const std::filesystem::path &prefixPath, const std::vector< std::string > &requiredVerbs) const
Get missing dependencies for a game.
void clearCache()
Clear winetricks cache.
std::future< bool > installDependencyAsync(const std::filesystem::path &prefixPath, const std::string &verbId, const ProgressCallback &progressCallback=nullptr)
Install a dependency asynchronously.
bool installForSteamGame(uint32_t steamAppId, const std::vector< std::string > &verbIds, const ProgressCallback &progressCallback=nullptr)
Install dependencies for a Steam/Proton game.
void setWinetricksPath(const std::filesystem::path &path)
Set winetricks path.
std::vector< std::string > getRecommendedDependencies() const
Get recommended dependencies for common game requirements.
std::filesystem::path getCacheDirectory() const
Get winetricks cache directory.
std::optional< WineDependency > getDependencyInfo(const std::string &verbId) const
Get dependency info by ID.
DLL override configuration.
std::string mode
"native", "builtin", "native,builtin", etc.
Progress information during dependency installation.
std::string currentStep
Current step description.
std::string currentVerb
Current verb being installed.
Status of dependencies in a Wine prefix.
std::filesystem::path prefixPath
std::chrono::system_clock::time_point lastScanned
std::vector< std::string > missingRecommended
std::string architecture
"win32" or "win64"
std::vector< std::string > installedVerbs
Information about a Wine dependency/component.
std::string publisher
Microsoft, etc.
std::string id
Winetricks verb (e.g., "vcrun2019").
std::string description
Description of what it installs.
std::string name
Human-readable name.
std::vector< std::string > conflicts
Verbs this conflicts with.
int64_t downloadSize
Approximate download size.
bool isInstalled
Whether installed in current prefix.
std::vector< std::string > aliases
Alternative names.
bool requires64bit
Requires 64-bit prefix.
std::vector< std::string > dependencies
Other verbs this depends on.
std::string downloadUrl
Direct download URL if known.
DependencyCategory category
std::string dependencyCategoryName(DependencyCategory category)
Get human-readable category name.
DependencyCategory
Categories of Wine dependencies.
@ Library
DLLs and libraries.
@ Setting
Wine settings/tweaks.
@ DirectX
DirectX components.
@ Redistributable
VC++ redistributables, .NET, etc.